drivers/hwmon/ibmpowernv.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ibmpowernv.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ibmpowernv.c- Extension
.c- Size
- 17202 bytes
- Lines
- 720
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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/init.hlinux/module.hlinux/kernel.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/of.hlinux/slab.hlinux/platform_device.hasm/opal.hlinux/err.hasm/cputhreads.hasm/smp.h
Detected Declarations
struct sensor_datastruct sensor_group_datastruct platform_dataenum sensorsfunction show_sensorfunction show_enablefunction store_enablefunction show_labelfunction get_logical_cpufunction make_sensor_labelfunction get_sensor_index_attrfunction get_sensor_typefunction get_sensor_hwmon_indexfunction init_sensor_group_datafunction for_each_child_of_nodefunction for_each_child_of_nodefunction for_each_child_of_nodefunction of_for_each_phandlefunction populate_attr_groupsfunction create_hwmon_attrfunction populate_sensorfunction create_device_attrsfunction ibmpowernv_probe
Annotated Snippet
struct sensor_data {
u32 id; /* An opaque id of the firmware for each sensor */
u32 hwmon_index;
u32 opal_index;
enum sensors type;
char label[MAX_LABEL_LEN];
char name[MAX_ATTR_LEN];
struct device_attribute dev_attr;
struct sensor_group_data *sgrp_data;
};
struct sensor_group_data {
struct mutex mutex;
u32 gid;
bool enable;
};
struct platform_data {
const struct attribute_group *attr_groups[MAX_SENSOR_TYPE + 1];
struct sensor_group_data *sgrp_data;
u32 sensors_count; /* Total count of sensors from each group */
u32 nr_sensor_groups; /* Total number of sensor groups */
};
static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
char *buf)
{
struct sensor_data *sdata = container_of(devattr, struct sensor_data,
dev_attr);
ssize_t ret;
u64 x;
if (sdata->sgrp_data && !sdata->sgrp_data->enable)
return -ENODATA;
ret = opal_get_sensor_data_u64(sdata->id, &x);
if (ret)
return ret;
/* Convert temperature to milli-degrees */
if (sdata->type == TEMP)
x *= 1000;
/* Convert power to micro-watts */
else if (sdata->type == POWER_INPUT)
x *= 1000000;
return sprintf(buf, "%llu\n", x);
}
static ssize_t show_enable(struct device *dev,
struct device_attribute *devattr, char *buf)
{
struct sensor_data *sdata = container_of(devattr, struct sensor_data,
dev_attr);
return sprintf(buf, "%u\n", sdata->sgrp_data->enable);
}
static ssize_t store_enable(struct device *dev,
struct device_attribute *devattr,
const char *buf, size_t count)
{
struct sensor_data *sdata = container_of(devattr, struct sensor_data,
dev_attr);
struct sensor_group_data *sgrp_data = sdata->sgrp_data;
int ret;
bool data;
ret = kstrtobool(buf, &data);
if (ret)
return ret;
ret = mutex_lock_interruptible(&sgrp_data->mutex);
if (ret)
return ret;
if (data != sgrp_data->enable) {
ret = sensor_group_enable(sgrp_data->gid, data);
if (!ret)
sgrp_data->enable = data;
}
if (!ret)
ret = count;
mutex_unlock(&sgrp_data->mutex);
return ret;
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/kernel.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/of.h`, `linux/slab.h`, `linux/platform_device.h`.
- Detected declarations: `struct sensor_data`, `struct sensor_group_data`, `struct platform_data`, `enum sensors`, `function show_sensor`, `function show_enable`, `function store_enable`, `function show_label`, `function get_logical_cpu`, `function make_sensor_label`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.