arch/powerpc/sysdev/mmio_nvram.c
Source file repositories/reference/linux-study-clean/arch/powerpc/sysdev/mmio_nvram.c
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/sysdev/mmio_nvram.c- Extension
.c- Size
- 3177 bytes
- Lines
- 146
- 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/fs.hlinux/init.hlinux/kernel.hlinux/of_address.hlinux/spinlock.hlinux/types.hasm/machdep.hasm/nvram.h
Detected Declarations
function mmio_nvram_readfunction mmio_nvram_read_valfunction mmio_nvram_writefunction mmio_nvram_write_valfunction mmio_nvram_get_sizefunction mmio_nvram_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* memory mapped NVRAM
*
* (C) Copyright IBM Corp. 2005
*
* Authors : Utz Bacher <utz.bacher@de.ibm.com>
*/
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/of_address.h>
#include <linux/spinlock.h>
#include <linux/types.h>
#include <asm/machdep.h>
#include <asm/nvram.h>
static void __iomem *mmio_nvram_start;
static long mmio_nvram_len;
static DEFINE_SPINLOCK(mmio_nvram_lock);
static ssize_t mmio_nvram_read(char *buf, size_t count, loff_t *index)
{
unsigned long flags;
if (*index >= mmio_nvram_len)
return 0;
if (*index + count > mmio_nvram_len)
count = mmio_nvram_len - *index;
spin_lock_irqsave(&mmio_nvram_lock, flags);
memcpy_fromio(buf, mmio_nvram_start + *index, count);
spin_unlock_irqrestore(&mmio_nvram_lock, flags);
*index += count;
return count;
}
static unsigned char mmio_nvram_read_val(int addr)
{
unsigned long flags;
unsigned char val;
if (addr >= mmio_nvram_len)
return 0xff;
spin_lock_irqsave(&mmio_nvram_lock, flags);
val = ioread8(mmio_nvram_start + addr);
spin_unlock_irqrestore(&mmio_nvram_lock, flags);
return val;
}
static ssize_t mmio_nvram_write(char *buf, size_t count, loff_t *index)
{
unsigned long flags;
if (*index >= mmio_nvram_len)
return 0;
if (*index + count > mmio_nvram_len)
count = mmio_nvram_len - *index;
spin_lock_irqsave(&mmio_nvram_lock, flags);
memcpy_toio(mmio_nvram_start + *index, buf, count);
spin_unlock_irqrestore(&mmio_nvram_lock, flags);
*index += count;
return count;
}
static void mmio_nvram_write_val(int addr, unsigned char val)
{
unsigned long flags;
if (addr < mmio_nvram_len) {
spin_lock_irqsave(&mmio_nvram_lock, flags);
iowrite8(val, mmio_nvram_start + addr);
spin_unlock_irqrestore(&mmio_nvram_lock, flags);
}
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/init.h`, `linux/kernel.h`, `linux/of_address.h`, `linux/spinlock.h`, `linux/types.h`, `asm/machdep.h`, `asm/nvram.h`.
- Detected declarations: `function mmio_nvram_read`, `function mmio_nvram_read_val`, `function mmio_nvram_write`, `function mmio_nvram_write_val`, `function mmio_nvram_get_size`, `function mmio_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.