arch/powerpc/platforms/pseries/nvram.c
Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/pseries/nvram.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/platforms/pseries/nvram.c- Extension
.c- Size
- 5503 bytes
- Lines
- 242
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/errno.hlinux/init.hlinux/spinlock.hlinux/slab.hlinux/ctype.hlinux/uaccess.hlinux/of.hasm/nvram.hasm/rtas.hasm/machdep.h
Detected Declarations
function pSeries_nvram_readfunction pSeries_nvram_writefunction pSeries_nvram_get_sizefunction nvram_write_error_logfunction nvram_read_error_logfunction nvram_clear_error_logfunction clobbering_unread_rtas_eventfunction pseries_nvram_init_log_partitionsfunction pSeries_nvram_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* c 2001 PPC 64 Team, IBM Corp
*
* /dev/nvram driver for PPC64
*/
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/uaccess.h>
#include <linux/of.h>
#include <asm/nvram.h>
#include <asm/rtas.h>
#include <asm/machdep.h>
/* Max bytes to read/write in one go */
#define NVRW_CNT 0x20
static unsigned int nvram_size;
static int nvram_fetch, nvram_store;
static char nvram_buf[NVRW_CNT]; /* assume this is in the first 4GB */
static DEFINE_SPINLOCK(nvram_lock);
/* See clobbering_unread_rtas_event() */
#define NVRAM_RTAS_READ_TIMEOUT 5 /* seconds */
static time64_t last_unread_rtas_event; /* timestamp */
#ifdef CONFIG_PSTORE
time64_t last_rtas_event;
#endif
static ssize_t pSeries_nvram_read(char *buf, size_t count, loff_t *index)
{
unsigned int i;
unsigned long len;
int done;
unsigned long flags;
char *p = buf;
if (nvram_size == 0 || nvram_fetch == RTAS_UNKNOWN_SERVICE)
return -ENODEV;
if (*index >= nvram_size)
return 0;
i = *index;
if (i + count > nvram_size)
count = nvram_size - i;
spin_lock_irqsave(&nvram_lock, flags);
for (; count != 0; count -= len) {
len = count;
if (len > NVRW_CNT)
len = NVRW_CNT;
if ((rtas_call(nvram_fetch, 3, 2, &done, i, __pa(nvram_buf),
len) != 0) || len != done) {
spin_unlock_irqrestore(&nvram_lock, flags);
return -EIO;
}
memcpy(p, nvram_buf, len);
p += len;
i += len;
}
spin_unlock_irqrestore(&nvram_lock, flags);
*index = i;
return p - buf;
}
static ssize_t pSeries_nvram_write(char *buf, size_t count, loff_t *index)
{
unsigned int i;
unsigned long len;
int done;
unsigned long flags;
const char *p = buf;
if (nvram_size == 0 || nvram_store == RTAS_UNKNOWN_SERVICE)
return -ENODEV;
Annotation
- Immediate include surface: `linux/types.h`, `linux/errno.h`, `linux/init.h`, `linux/spinlock.h`, `linux/slab.h`, `linux/ctype.h`, `linux/uaccess.h`, `linux/of.h`.
- Detected declarations: `function pSeries_nvram_read`, `function pSeries_nvram_write`, `function pSeries_nvram_get_size`, `function nvram_write_error_log`, `function nvram_read_error_log`, `function nvram_clear_error_log`, `function clobbering_unread_rtas_event`, `function pseries_nvram_init_log_partitions`, `function pSeries_nvram_init`.
- 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.