arch/powerpc/platforms/pseries/papr-indices.c
Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/pseries/papr-indices.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/platforms/pseries/papr-indices.c- Extension
.c- Size
- 13670 bytes
- Lines
- 489
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/build_bug.hlinux/file.hlinux/fs.hlinux/init.hlinux/lockdep.hlinux/kernel.hlinux/miscdevice.hlinux/signal.hlinux/slab.hlinux/string.hlinux/string_helpers.hlinux/uaccess.hasm/machdep.hasm/rtas-work-area.hasm/rtas.huapi/asm/papr-indices.hpapr-rtas-common.h
Detected Declarations
struct rtas_get_indices_paramsfunction rtas_ibm_get_indicesfunction indices_sequence_beginfunction indices_sequence_endfunction papr_rtas_blob_generatefunction readfunction papr_indices_create_handlefunction papr_dynamic_indice_buf_from_userfunction papr_dynamic_indicator_ioc_setfunction papr_dynamic_sensor_ioc_getfunction papr_indices_dev_ioctlfunction papr_indices_init
Annotated Snippet
static const struct file_operations papr_indices_handle_ops = {
.read = papr_indices_handle_read,
.llseek = papr_rtas_common_handle_seek,
.release = papr_rtas_common_handle_release,
};
/*
* papr_indices_create_handle() - Create a fd-based handle for reading
* indices data
* @ubuf: Input parameters to RTAS call such as whether sensor or indicator
* and indice type in user memory
*
* Handler for PAPR_INDICES_IOC_GET ioctl command. Validates @ubuf
* and instantiates an immutable indices "blob" for it. The blob is
* attached to a file descriptor for reading by user space. The memory
* backing the blob is freed when the file is released.
*
* The entire requested indices is retrieved by this call and all
* necessary RTAS interactions are performed before returning the fd
* to user space. This keeps the read handler simple and ensures that
* the kernel can prevent interleaving of ibm,get-indices call sequences.
*
* Return: The installed fd number if successful, -ve errno otherwise.
*/
static long papr_indices_create_handle(struct papr_indices_io_block __user *ubuf)
{
struct papr_rtas_sequence seq = {};
struct rtas_get_indices_params params = {};
int fd;
if (get_user(params.is_sensor, &ubuf->indices.is_sensor))
return -EFAULT;
if (get_user(params.indice_type, &ubuf->indices.indice_type))
return -EFAULT;
seq = (struct papr_rtas_sequence) {
.begin = indices_sequence_begin,
.end = indices_sequence_end,
.work = indices_sequence_fill_work_area,
};
seq.params = ¶ms;
fd = papr_rtas_setup_file_interface(&seq,
&papr_indices_handle_ops, "[papr-indices]");
return fd;
}
/*
* Create work area with the input parameters. This function is used
* for both ibm,set-dynamic-indicator and ibm,get-dynamic-sensor-state
* RTAS Calls.
*/
static struct rtas_work_area *
papr_dynamic_indice_buf_from_user(struct papr_indices_io_block __user *ubuf,
struct papr_indices_io_block *kbuf)
{
struct rtas_work_area *work_area;
u32 length;
__be32 len_be;
if (copy_from_user(kbuf, ubuf, sizeof(*kbuf)))
return ERR_PTR(-EFAULT);
if (!string_is_terminated(kbuf->dynamic_param.location_code_str,
ARRAY_SIZE(kbuf->dynamic_param.location_code_str)))
return ERR_PTR(-EINVAL);
/*
* The input data in the work area should be as follows:
* - 32-bit integer length of the location code string,
* including NULL.
* - Location code string, NULL terminated, identifying the
* token (sensor or indicator).
* PAPR 2.13 - R1–7.3.18–5 ibm,set-dynamic-indicator
* - R1–7.3.19–5 ibm,get-dynamic-sensor-state
*/
/*
* Length that user space passed should also include NULL
* terminator.
*/
length = strlen(kbuf->dynamic_param.location_code_str) + 1;
if (length > LOC_CODE_SIZE)
return ERR_PTR(-EINVAL);
len_be = cpu_to_be32(length);
work_area = rtas_work_area_alloc(LOC_CODE_SIZE + sizeof(u32));
Annotation
- Immediate include surface: `linux/build_bug.h`, `linux/file.h`, `linux/fs.h`, `linux/init.h`, `linux/lockdep.h`, `linux/kernel.h`, `linux/miscdevice.h`, `linux/signal.h`.
- Detected declarations: `struct rtas_get_indices_params`, `function rtas_ibm_get_indices`, `function indices_sequence_begin`, `function indices_sequence_end`, `function papr_rtas_blob_generate`, `function read`, `function papr_indices_create_handle`, `function papr_dynamic_indice_buf_from_user`, `function papr_dynamic_indicator_ioc_set`, `function papr_dynamic_sensor_ioc_get`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.