arch/powerpc/platforms/powernv/opal-psr.c
Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/powernv/opal-psr.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/platforms/powernv/opal-psr.c- Extension
.c- Size
- 3660 bytes
- Lines
- 171
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- 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.hlinux/sysfs.hasm/opal.h
Detected Declarations
function psr_showfunction psr_storefunction opal_psr_initfunction for_each_child_of_node
Annotated Snippet
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 = sysfs_emit(buf, "%u\n", be32_to_cpu(psr));
break;
case OPAL_SUCCESS:
ret = sysfs_emit(buf, "%u\n", be32_to_cpu(psr));
break;
default:
ret = opal_error_code(ret);
}
out:
mutex_unlock(&psr_mutex);
out_token:
opal_async_release_token(token);
return ret;
}
static ssize_t psr_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
struct psr_attr *psr_attr = container_of(attr, struct psr_attr, attr);
struct opal_msg msg;
int psr, ret, token;
ret = kstrtoint(buf, 0, &psr);
if (ret)
return ret;
token = opal_async_get_token_interruptible();
if (token < 0) {
pr_devel("Failed to get token\n");
return token;
}
ret = mutex_lock_interruptible(&psr_mutex);
if (ret)
goto out_token;
ret = opal_set_power_shift_ratio(psr_attr->handle, token, psr);
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(&psr_mutex);
out_token:
opal_async_release_token(token);
return ret;
}
void __init opal_psr_init(void)
{
struct device_node *psr, *node;
int i = 0;
psr = of_find_compatible_node(NULL, NULL,
"ibm,opal-power-shift-ratio");
if (!psr) {
pr_devel("Power-shift-ratio node not found\n");
return;
}
psr_attrs = kzalloc_objs(*psr_attrs, of_get_child_count(psr));
if (!psr_attrs)
goto out_put_psr;
psr_kobj = kobject_create_and_add("psr", opal_kobj);
if (!psr_kobj) {
pr_warn("Failed to create psr kobject\n");
Annotation
- Immediate include surface: `linux/of.h`, `linux/kobject.h`, `linux/slab.h`, `linux/sysfs.h`, `asm/opal.h`.
- Detected declarations: `function psr_show`, `function psr_store`, `function opal_psr_init`, `function for_each_child_of_node`.
- Atlas domain: Architecture Layer / arch/powerpc.
- 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.