arch/powerpc/platforms/powernv/opal-sensor-groups.c
Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/powernv/opal-sensor-groups.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/platforms/powernv/opal-sensor-groups.c- Extension
.c- Size
- 4994 bytes
- Lines
- 238
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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/of.hlinux/kobject.hlinux/slab.hasm/opal.h
Detected Declarations
struct sg_attrfunction sensor_group_enablefunction sg_storefunction add_attrfunction add_attr_groupfunction get_nr_attrsfunction opal_sensor_groups_initfunction for_each_child_of_nodeexport sensor_group_enable
Annotated Snippet
struct sg_attr {
u32 handle;
struct kobj_attribute attr;
};
static struct sensor_group {
char name[20];
struct attribute_group sg;
struct sg_attr *sgattrs;
} *sgs;
int sensor_group_enable(u32 handle, bool enable)
{
struct opal_msg msg;
int token, ret;
token = opal_async_get_token_interruptible();
if (token < 0)
return token;
ret = opal_sensor_group_enable(handle, token, enable);
if (ret == OPAL_ASYNC_COMPLETION) {
ret = opal_async_wait_response(token, &msg);
if (ret) {
pr_devel("Failed to wait for the async response\n");
ret = -EIO;
goto out;
}
ret = opal_error_code(opal_get_async_rc(msg));
} else {
ret = opal_error_code(ret);
}
out:
opal_async_release_token(token);
return ret;
}
EXPORT_SYMBOL_GPL(sensor_group_enable);
static ssize_t sg_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
struct sg_attr *sattr = container_of(attr, struct sg_attr, attr);
struct opal_msg msg;
u32 data;
int ret, token;
ret = kstrtoint(buf, 0, &data);
if (ret)
return ret;
if (data != 1)
return -EINVAL;
token = opal_async_get_token_interruptible();
if (token < 0) {
pr_devel("Failed to get token\n");
return token;
}
ret = mutex_lock_interruptible(&sg_mutex);
if (ret)
goto out_token;
ret = opal_sensor_group_clear(sattr->handle, token);
switch (ret) {
case OPAL_ASYNC_COMPLETION:
ret = opal_async_wait_response(token, &msg);
if (ret) {
pr_devel("Failed to wait for the async response\n");
ret = -EIO;
goto out;
}
ret = opal_error_code(opal_get_async_rc(msg));
if (!ret)
ret = count;
break;
case OPAL_SUCCESS:
ret = count;
break;
default:
ret = opal_error_code(ret);
}
out:
mutex_unlock(&sg_mutex);
out_token:
opal_async_release_token(token);
return ret;
}
Annotation
- Immediate include surface: `linux/of.h`, `linux/kobject.h`, `linux/slab.h`, `asm/opal.h`.
- Detected declarations: `struct sg_attr`, `function sensor_group_enable`, `function sg_store`, `function add_attr`, `function add_attr_group`, `function get_nr_attrs`, `function opal_sensor_groups_init`, `function for_each_child_of_node`, `export sensor_group_enable`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.