drivers/acpi/nvs.c
Source file repositories/reference/linux-study-clean/drivers/acpi/nvs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/acpi/nvs.c- Extension
.c- Size
- 4637 bytes
- Lines
- 214
- Domain
- Driver Families
- Bucket
- drivers/acpi
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/io.hlinux/kernel.hlinux/list.hlinux/mm.hlinux/slab.hlinux/acpi.hinternal.h
Detected Declarations
struct nvs_regionstruct nvs_pagefunction suspend_nvs_registerfunction acpi_nvs_registerfunction acpi_nvs_for_each_regionfunction list_for_each_entryfunction suspend_nvs_registerfunction suspend_nvs_freefunction list_for_each_entryfunction suspend_nvs_allocfunction list_for_each_entryfunction suspend_nvs_savefunction list_for_each_entryfunction suspend_nvs_restore
Annotated Snippet
struct nvs_region {
__u64 phys_start;
__u64 size;
struct list_head node;
};
static LIST_HEAD(nvs_region_list);
#ifdef CONFIG_ACPI_SLEEP
static int suspend_nvs_register(unsigned long start, unsigned long size);
#else
static inline int suspend_nvs_register(unsigned long a, unsigned long b)
{
return 0;
}
#endif
int acpi_nvs_register(__u64 start, __u64 size)
{
struct nvs_region *region;
region = kmalloc_obj(*region);
if (!region)
return -ENOMEM;
region->phys_start = start;
region->size = size;
list_add_tail(®ion->node, &nvs_region_list);
return suspend_nvs_register(start, size);
}
int acpi_nvs_for_each_region(int (*func)(__u64 start, __u64 size, void *data),
void *data)
{
int rc;
struct nvs_region *region;
list_for_each_entry(region, &nvs_region_list, node) {
rc = func(region->phys_start, region->size, data);
if (rc)
return rc;
}
return 0;
}
#ifdef CONFIG_ACPI_SLEEP
/*
* Platforms, like ACPI, may want us to save some memory used by them during
* suspend and to restore the contents of this memory during the subsequent
* resume. The code below implements a mechanism allowing us to do that.
*/
struct nvs_page {
unsigned long phys_start;
unsigned int size;
void *kaddr;
void *data;
bool unmap;
struct list_head node;
};
static LIST_HEAD(nvs_list);
/**
* suspend_nvs_register - register platform NVS memory region to save
* @start: Physical address of the region.
* @size: Size of the region.
*
* The NVS region need not be page-aligned (both ends) and we arrange
* things so that the data from page-aligned addresses in this region will
* be copied into separate RAM pages.
*/
static int suspend_nvs_register(unsigned long start, unsigned long size)
{
struct nvs_page *entry, *next;
pr_info("Registering ACPI NVS region [mem %#010lx-%#010lx] (%ld bytes)\n",
start, start + size - 1, size);
while (size > 0) {
unsigned int nr_bytes;
entry = kzalloc_obj(struct nvs_page);
if (!entry)
goto Error;
list_add_tail(&entry->node, &nvs_list);
entry->phys_start = start;
Annotation
- Immediate include surface: `linux/io.h`, `linux/kernel.h`, `linux/list.h`, `linux/mm.h`, `linux/slab.h`, `linux/acpi.h`, `internal.h`.
- Detected declarations: `struct nvs_region`, `struct nvs_page`, `function suspend_nvs_register`, `function acpi_nvs_register`, `function acpi_nvs_for_each_region`, `function list_for_each_entry`, `function suspend_nvs_register`, `function suspend_nvs_free`, `function list_for_each_entry`, `function suspend_nvs_alloc`.
- Atlas domain: Driver Families / drivers/acpi.
- Implementation status: source 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.