drivers/thermal/testing/zone.c
Source file repositories/reference/linux-study-clean/drivers/thermal/testing/zone.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thermal/testing/zone.c- Extension
.c- Size
- 10706 bytes
- Lines
- 448
- Domain
- Driver Families
- Bucket
- drivers/thermal
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/debugfs.hlinux/idr.hlinux/list.hlinux/thermal.hlinux/workqueue.hthermal_testing.h
Detected Declarations
struct tt_thermal_zonestruct tt_tripstruct tt_workfunction tt_int_getfunction tt_int_setfunction tt_zone_tz_temp_getfunction tt_zone_tz_temp_setfunction tt_zone_free_tripsfunction list_for_each_entry_safefunction tt_zone_freefunction tt_add_tz_work_fnfunction tt_add_tzfunction tt_del_tz_work_fnfunction tt_zone_unregister_tzfunction tt_del_tzfunction list_for_each_entryfunction tt_put_tt_zonefunction tt_zone_add_tripfunction tt_zone_get_tempfunction tt_zone_register_tzfunction tt_zone_regfunction tt_zone_unregfunction tt_zone_cleanupfunction list_for_each_entry_safe
Annotated Snippet
struct tt_thermal_zone {
struct list_head list_node;
struct list_head trips;
struct dentry *d_tt_zone;
struct thermal_zone_device *tz;
struct mutex lock;
struct ida ida;
int id;
int temp;
int tz_temp;
unsigned int num_trips;
unsigned int refcount;
};
DEFINE_GUARD(tt_zone, struct tt_thermal_zone *, mutex_lock(&_T->lock), mutex_unlock(&_T->lock))
/**
* struct tt_trip - Testing trip point template
*
* Represents a template of a trip point to be used for populating a trip point
* during the registration of a thermal zone based on a given zone template.
*
* @list_node: Node in the list of all trip templates in the zone template.
* @trip: Trip point data to use for thernal zone registration.
* @id: The ID of this trip template for the debugfs interface.
*/
struct tt_trip {
struct list_head list_node;
struct thermal_trip trip;
int id;
};
/*
* It is both questionable and potentially problematic from the sychnronization
* perspective to attempt to manipulate debugfs from within a debugfs file
* "write" operation, so auxiliary work items are used for that. The majority
* of zone-related command functions have a part that runs from a workqueue and
* make changes in debugs, among other things.
*/
struct tt_work {
struct work_struct work;
struct tt_thermal_zone *tt_zone;
struct tt_trip *tt_trip;
};
static inline struct tt_work *tt_work_of_work(struct work_struct *work)
{
return container_of(work, struct tt_work, work);
}
static LIST_HEAD(tt_thermal_zones);
static DEFINE_IDA(tt_thermal_zones_ida);
static DEFINE_MUTEX(tt_thermal_zones_lock);
static int tt_int_get(void *data, u64 *val)
{
*val = *(int *)data;
return 0;
}
static int tt_int_set(void *data, u64 val)
{
if ((int)val < THERMAL_TEMP_INVALID)
return -EINVAL;
*(int *)data = val;
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(tt_int_attr, tt_int_get, tt_int_set, "%lld\n");
DEFINE_DEBUGFS_ATTRIBUTE(tt_unsigned_int_attr, tt_int_get, tt_int_set, "%llu\n");
static int tt_zone_tz_temp_get(void *data, u64 *val)
{
struct tt_thermal_zone *tt_zone = data;
guard(tt_zone)(tt_zone);
if (!tt_zone->tz)
return -EBUSY;
*val = tt_zone->tz_temp;
return 0;
}
static int tt_zone_tz_temp_set(void *data, u64 val)
{
struct tt_thermal_zone *tt_zone = data;
guard(tt_zone)(tt_zone);
if (!tt_zone->tz)
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/idr.h`, `linux/list.h`, `linux/thermal.h`, `linux/workqueue.h`, `thermal_testing.h`.
- Detected declarations: `struct tt_thermal_zone`, `struct tt_trip`, `struct tt_work`, `function tt_int_get`, `function tt_int_set`, `function tt_zone_tz_temp_get`, `function tt_zone_tz_temp_set`, `function tt_zone_free_trips`, `function list_for_each_entry_safe`, `function tt_zone_free`.
- Atlas domain: Driver Families / drivers/thermal.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.