arch/powerpc/platforms/pseries/papr_platform_attributes.c
Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/pseries/papr_platform_attributes.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/platforms/pseries/papr_platform_attributes.c- Extension
.c- Size
- 8983 bytes
- Lines
- 364
- 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.
- 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
asm/hvcall.hasm/machdep.hasm/firmware.hpseries.h
Detected Declarations
struct energy_scale_attributestruct h_energy_scale_info_hdrstruct papr_attrstruct papr_groupfunction papr_get_attrfunction desc_showfunction val_showfunction val_desc_showfunction add_attrfunction add_attr_groupfunction papr_init
Annotated Snippet
struct energy_scale_attribute {
__be64 id;
__be64 val;
u8 desc[64];
u8 value_desc[64];
} __packed;
struct h_energy_scale_info_hdr {
__be64 num_attrs;
__be64 array_offset;
u8 data_header_version;
} __packed;
struct papr_attr {
u64 id;
struct kobj_attribute kobj_attr;
};
struct papr_group {
struct attribute_group pg;
struct papr_attr pgattrs[KOBJ_MAX_ATTRS];
};
static struct papr_group *papr_groups;
/* /sys/firmware/papr */
static struct kobject *papr_kobj;
/* /sys/firmware/papr/energy_scale_info */
static struct kobject *esi_kobj;
/*
* Energy modes can change dynamically hence making a new hcall each time the
* information needs to be retrieved
*/
static int papr_get_attr(u64 id, struct energy_scale_attribute *esi)
{
int esi_buf_size = ESI_HDR_SIZE + (CURR_MAX_ESI_ATTRS * ESI_ATTR_SIZE);
int ret, max_esi_attrs = CURR_MAX_ESI_ATTRS;
struct energy_scale_attribute *curr_esi;
struct h_energy_scale_info_hdr *hdr;
char *buf;
buf = kmalloc(esi_buf_size, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
retry:
ret = plpar_hcall_norets(H_GET_ENERGY_SCALE_INFO, ESI_FLAGS_SINGLE,
id, virt_to_phys(buf),
esi_buf_size);
/*
* If the hcall fails with not enough memory for either the
* header or data, attempt to allocate more
*/
if (ret == H_PARTIAL || ret == H_P4) {
char *temp_buf;
max_esi_attrs += 4;
esi_buf_size = ESI_HDR_SIZE + (CURR_MAX_ESI_ATTRS * max_esi_attrs);
temp_buf = krealloc(buf, esi_buf_size, GFP_KERNEL);
if (temp_buf) {
buf = temp_buf;
} else {
ret = -ENOMEM;
goto out_buf;
}
goto retry;
}
if (ret != H_SUCCESS) {
pr_warn("hcall failed: H_GET_ENERGY_SCALE_INFO");
ret = -EIO;
goto out_buf;
}
hdr = (struct h_energy_scale_info_hdr *) buf;
curr_esi = (struct energy_scale_attribute *)
(buf + be64_to_cpu(hdr->array_offset));
if (esi_buf_size <
be64_to_cpu(hdr->array_offset) + (be64_to_cpu(hdr->num_attrs)
* sizeof(struct energy_scale_attribute))) {
ret = -EIO;
goto out_buf;
}
*esi = *curr_esi;
Annotation
- Immediate include surface: `asm/hvcall.h`, `asm/machdep.h`, `asm/firmware.h`, `pseries.h`.
- Detected declarations: `struct energy_scale_attribute`, `struct h_energy_scale_info_hdr`, `struct papr_attr`, `struct papr_group`, `function papr_get_attr`, `function desc_show`, `function val_show`, `function val_desc_show`, `function add_attr`, `function add_attr_group`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: integration implementation candidate.
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.