drivers/powercap/powercap_sys.c
Source file repositories/reference/linux-study-clean/drivers/powercap/powercap_sys.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/powercap/powercap_sys.c- Extension
.c- Size
- 18997 bytes
- Lines
- 685
- Domain
- Driver Families
- Bucket
- drivers/powercap
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/module.hlinux/device.hlinux/err.hlinux/kstrtox.hlinux/slab.hlinux/powercap.h
Detected Declarations
struct powercap_constraint_attrfunction show_constraint_namefunction create_constraint_attributefunction free_constraint_attributesfunction seed_constraint_attributesfunction create_constraintsfunction control_type_validfunction list_for_each_entryfunction name_showfunction create_power_zone_common_attributesfunction powercap_releasefunction enabled_showfunction enabled_storefunction powercap_unregister_zonefunction powercap_unregister_control_typefunction powercap_initmodule init powercap_initexport powercap_register_zoneexport powercap_unregister_zoneexport powercap_register_control_typeexport powercap_unregister_control_type
Annotated Snippet
struct powercap_constraint_attr {
struct device_attribute power_limit_attr;
struct device_attribute time_window_attr;
struct device_attribute max_power_attr;
struct device_attribute min_power_attr;
struct device_attribute max_time_window_attr;
struct device_attribute min_time_window_attr;
struct device_attribute name_attr;
};
static struct powercap_constraint_attr
constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
/* A list of powercap control_types */
static LIST_HEAD(powercap_cntrl_list);
/* Mutex to protect list of powercap control_types */
static DEFINE_MUTEX(powercap_cntrl_list_lock);
#define POWERCAP_CONSTRAINT_NAME_LEN 30 /* Some limit to avoid overflow */
static ssize_t show_constraint_name(struct device *dev,
struct device_attribute *dev_attr,
char *buf)
{
const char *name;
struct powercap_zone *power_zone = to_powercap_zone(dev);
int id;
ssize_t len = -ENODATA;
struct powercap_zone_constraint *pconst;
if (sscanf(dev_attr->attr.name, "constraint_%d_", &id) != 1)
return -EINVAL;
if (id >= power_zone->const_id_cnt)
return -EINVAL;
pconst = &power_zone->constraints[id];
if (pconst && pconst->ops && pconst->ops->get_name) {
name = pconst->ops->get_name(power_zone, id);
if (name) {
len = sysfs_emit(buf, "%.*s\n",
POWERCAP_CONSTRAINT_NAME_LEN - 1, name);
}
}
return len;
}
static int create_constraint_attribute(int id, const char *name,
int mode,
struct device_attribute *dev_attr,
ssize_t (*show)(struct device *,
struct device_attribute *, char *),
ssize_t (*store)(struct device *,
struct device_attribute *,
const char *, size_t)
)
{
dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
id, name);
if (!dev_attr->attr.name)
return -ENOMEM;
dev_attr->attr.mode = mode;
dev_attr->show = show;
dev_attr->store = store;
return 0;
}
static void free_constraint_attributes(void)
{
int i;
for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
kfree(constraint_attrs[i].power_limit_attr.attr.name);
kfree(constraint_attrs[i].time_window_attr.attr.name);
kfree(constraint_attrs[i].name_attr.attr.name);
kfree(constraint_attrs[i].max_power_attr.attr.name);
kfree(constraint_attrs[i].min_power_attr.attr.name);
kfree(constraint_attrs[i].max_time_window_attr.attr.name);
kfree(constraint_attrs[i].min_time_window_attr.attr.name);
}
}
static int seed_constraint_attributes(void)
{
int i;
int ret;
for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
ret = create_constraint_attribute(i, "power_limit_uw",
Annotation
- Immediate include surface: `linux/module.h`, `linux/device.h`, `linux/err.h`, `linux/kstrtox.h`, `linux/slab.h`, `linux/powercap.h`.
- Detected declarations: `struct powercap_constraint_attr`, `function show_constraint_name`, `function create_constraint_attribute`, `function free_constraint_attributes`, `function seed_constraint_attributes`, `function create_constraints`, `function control_type_valid`, `function list_for_each_entry`, `function name_show`, `function create_power_zone_common_attributes`.
- Atlas domain: Driver Families / drivers/powercap.
- Implementation status: integration 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.