drivers/firmware/efi/memmap.c
Source file repositories/reference/linux-study-clean/drivers/firmware/efi/memmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/efi/memmap.c- Extension
.c- Size
- 4055 bytes
- Lines
- 149
- Domain
- Driver Families
- Bucket
- drivers/firmware
- 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/init.hlinux/kernel.hlinux/efi.hlinux/io.hlinux/memblock.hlinux/slab.hasm/early_ioremap.hasm/efi.h
Detected Declarations
function __efi_memmap_initfunction early_memremapfunction efi_memmap_unmapfunction ioremap_cache
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Common EFI memory map functions.
*/
#define pr_fmt(fmt) "efi: " fmt
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/efi.h>
#include <linux/io.h>
#include <linux/memblock.h>
#include <linux/slab.h>
#include <asm/early_ioremap.h>
#include <asm/efi.h>
/**
* __efi_memmap_init - Common code for mapping the EFI memory map
* @data: EFI memory map data
*
* This function takes care of figuring out which function to use to
* map the EFI memory map in efi.memmap based on how far into the boot
* we are.
*
* During bootup EFI_MEMMAP_LATE in data->flags should be clear since we
* only have access to the early_memremap*() functions as the vmalloc
* space isn't setup. Once the kernel is fully booted we can fallback
* to the more robust memremap*() API.
*
* Returns: zero on success, a negative error code on failure.
*/
int __init __efi_memmap_init(struct efi_memory_map_data *data)
{
struct efi_memory_map map;
phys_addr_t phys_map;
phys_map = data->phys_map;
if (data->flags & EFI_MEMMAP_LATE)
map.map = memremap(phys_map, data->size, MEMREMAP_WB);
else
map.map = early_memremap(phys_map, data->size);
if (!map.map) {
pr_err("Could not map the memory map! phys_map=%pa, size=0x%lx\n",
&phys_map, data->size);
return -ENOMEM;
}
map.phys_map = data->phys_map;
map.nr_map = data->size / data->desc_size;
map.map_end = map.map + data->size;
map.desc_version = data->desc_version;
map.desc_size = data->desc_size;
map.flags = data->flags;
set_bit(EFI_MEMMAP, &efi.flags);
efi.memmap = map;
return 0;
}
/**
* efi_memmap_init_early - Map the EFI memory map data structure
* @data: EFI memory map data
*
* Use early_memremap() to map the passed in EFI memory map and assign
* it to efi.memmap.
*
* Returns: zero on success, a negative error code on failure.
*/
int __init efi_memmap_init_early(struct efi_memory_map_data *data)
{
/* Cannot go backwards */
WARN_ON(efi.memmap.flags & EFI_MEMMAP_LATE);
data->flags = 0;
return __efi_memmap_init(data);
}
void __init efi_memmap_unmap(void)
{
if (!efi_enabled(EFI_MEMMAP))
return;
if (!(efi.memmap.flags & EFI_MEMMAP_LATE)) {
unsigned long size;
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/efi.h`, `linux/io.h`, `linux/memblock.h`, `linux/slab.h`, `asm/early_ioremap.h`, `asm/efi.h`.
- Detected declarations: `function __efi_memmap_init`, `function early_memremap`, `function efi_memmap_unmap`, `function ioremap_cache`.
- Atlas domain: Driver Families / drivers/firmware.
- 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.