drivers/char/nvram.c
Source file repositories/reference/linux-study-clean/drivers/char/nvram.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/nvram.c- Extension
.c- Size
- 13830 bytes
- Lines
- 547
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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.
- 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/module.hlinux/nvram.hlinux/types.hlinux/errno.hlinux/miscdevice.hlinux/ioport.hlinux/fcntl.hlinux/mc146818rtc.hlinux/init.hlinux/proc_fs.hlinux/seq_file.hlinux/slab.hlinux/spinlock.hlinux/io.hlinux/uaccess.hlinux/mutex.hlinux/pagemap.hasm/nvram.h
Detected Declarations
function writingfunction pc_nvram_read_bytefunction __nvram_write_bytefunction pc_nvram_write_bytefunction __nvram_check_checksumfunction __nvram_set_checksumfunction pc_nvram_set_checksumfunction pc_nvram_initializefunction pc_nvram_get_sizefunction pc_nvram_readfunction pc_nvram_writefunction nvram_misc_llseekfunction nvram_misc_readfunction nvram_misc_writefunction nvram_misc_ioctlfunction nvram_misc_openfunction nvram_misc_releasefunction pc_nvram_proc_readfunction nvram_proc_readfunction nvram_module_initfunction nvram_module_exitmodule init nvram_module_initexport arch_nvram_ops
Annotated Snippet
static const struct file_operations nvram_misc_fops = {
.owner = THIS_MODULE,
.llseek = nvram_misc_llseek,
.read = nvram_misc_read,
.write = nvram_misc_write,
.unlocked_ioctl = nvram_misc_ioctl,
.open = nvram_misc_open,
.release = nvram_misc_release,
};
static struct miscdevice nvram_misc = {
NVRAM_MINOR,
"nvram",
&nvram_misc_fops,
};
static int __init nvram_module_init(void)
{
int ret;
nvram_size = nvram_get_size();
if (nvram_size < 0)
return nvram_size;
ret = misc_register(&nvram_misc);
if (ret) {
pr_err("nvram: can't misc_register on minor=%d\n", NVRAM_MINOR);
return ret;
}
#if defined(CONFIG_X86) && defined(CONFIG_PROC_FS)
if (!proc_create_single("driver/nvram", 0, NULL, nvram_proc_read)) {
pr_err("nvram: can't create /proc/driver/nvram\n");
misc_deregister(&nvram_misc);
return -ENOMEM;
}
#endif
pr_info("Non-volatile memory driver v" NVRAM_VERSION "\n");
return 0;
}
static void __exit nvram_module_exit(void)
{
#if defined(CONFIG_X86) && defined(CONFIG_PROC_FS)
remove_proc_entry("driver/nvram", NULL);
#endif
misc_deregister(&nvram_misc);
}
module_init(nvram_module_init);
module_exit(nvram_module_exit);
MODULE_DESCRIPTION("CMOS/NV-RAM driver for Linux");
MODULE_LICENSE("GPL");
MODULE_ALIAS_MISCDEV(NVRAM_MINOR);
MODULE_ALIAS("devname:nvram");
Annotation
- Immediate include surface: `linux/module.h`, `linux/nvram.h`, `linux/types.h`, `linux/errno.h`, `linux/miscdevice.h`, `linux/ioport.h`, `linux/fcntl.h`, `linux/mc146818rtc.h`.
- Detected declarations: `function writing`, `function pc_nvram_read_byte`, `function __nvram_write_byte`, `function pc_nvram_write_byte`, `function __nvram_check_checksum`, `function __nvram_set_checksum`, `function pc_nvram_set_checksum`, `function pc_nvram_initialize`, `function pc_nvram_get_size`, `function pc_nvram_read`.
- Atlas domain: Driver Families / drivers/char.
- 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.