drivers/firmware/efi/efi.c
Source file repositories/reference/linux-study-clean/drivers/firmware/efi/efi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/efi/efi.c- Extension
.c- Size
- 31683 bytes
- Lines
- 1217
- Domain
- Driver Families
- Bucket
- drivers/firmware
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kobject.hlinux/module.hlinux/init.hlinux/debugfs.hlinux/device.hlinux/efi.hlinux/of.hlinux/initrd.hlinux/io.hlinux/kexec.hlinux/platform_device.hlinux/random.hlinux/reboot.hlinux/slab.hlinux/acpi.hlinux/ucs2_string.hlinux/memblock.hlinux/security.hlinux/notifier.hasm/early_ioremap.h
Detected Declarations
function setup_noefifunction efi_runtime_disabledfunction __efi_soft_reserve_enabledfunction parse_efi_cmdlinefunction systab_showfunction fw_platform_size_showfunction efi_attr_is_visiblefunction generic_ops_supportedfunction generic_ops_registerfunction generic_ops_unregisterfunction efivars_generic_ops_registerfunction efivars_generic_ops_unregisterfunction efivar_ssdt_setupfunction efivar_ssdt_loadfunction efivar_ssdt_loadfunction efi_debugfs_initfunction for_each_efi_memory_descfunction efi_debugfs_initfunction efisubsys_initfunction efi_find_mirrorfunction for_each_efi_memory_descfunction __efi_mem_desc_lookupfunction for_each_efi_memory_descfunction efi_mem_desc_endfunction efi_arch_mem_reservefunction match_config_tablefunction memblock_addfunction efi_config_parse_tablesfunction efi_systab_check_headerfunction map_fw_vendorfunction unmap_fw_vendorfunction efi_systab_report_headerfunction efi_md_typeattr_formatfunction efi_mem_attributesfunction efi_mem_typefunction efi_status_to_errfunction efi_memreserve_map_rootfunction efi_mem_reserve_iomemfunction efi_mem_reserve_persistentfunction efi_memreserve_root_initfunction update_efi_random_seedfunction register_update_efi_random_seedmodule init efisubsys_initexport efiexport efivar_ops_nhexport efivars_generic_ops_registerexport efivars_generic_ops_unregisterexport efi_mem_desc_lookup
Annotated Snippet
subsys_initcall(efisubsys_init);
void __init efi_find_mirror(void)
{
efi_memory_desc_t *md;
u64 mirror_size = 0, total_size = 0;
if (!efi_enabled(EFI_MEMMAP))
return;
for_each_efi_memory_desc(md) {
unsigned long long start = md->phys_addr;
unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
total_size += size;
if (md->attribute & EFI_MEMORY_MORE_RELIABLE) {
memblock_mark_mirror(start, size);
mirror_size += size;
}
}
if (mirror_size)
pr_info("Memory: %lldM/%lldM mirrored memory\n",
mirror_size>>20, total_size>>20);
}
/*
* Find the efi memory descriptor for a given physical address. Given a
* physical address, determine if it exists within an EFI Memory Map entry,
* and if so, populate the supplied memory descriptor with the appropriate
* data.
*/
int __efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md)
{
efi_memory_desc_t *md;
if (!efi_enabled(EFI_MEMMAP)) {
pr_err_once("EFI_MEMMAP is not enabled.\n");
return -EINVAL;
}
if (!out_md) {
pr_err_once("out_md is null.\n");
return -EINVAL;
}
for_each_efi_memory_desc(md) {
u64 size;
u64 end;
/* skip bogus entries (including empty ones) */
if ((md->phys_addr & (EFI_PAGE_SIZE - 1)) ||
(md->num_pages <= 0) ||
(md->num_pages > (U64_MAX - md->phys_addr) >> EFI_PAGE_SHIFT))
continue;
size = md->num_pages << EFI_PAGE_SHIFT;
end = md->phys_addr + size;
if (phys_addr >= md->phys_addr && phys_addr < end) {
memcpy(out_md, md, sizeof(*out_md));
return 0;
}
}
return -ENOENT;
}
extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md)
__weak __alias(__efi_mem_desc_lookup);
EXPORT_SYMBOL_GPL(efi_mem_desc_lookup);
/*
* Calculate the highest address of an efi memory descriptor.
*/
u64 __init efi_mem_desc_end(efi_memory_desc_t *md)
{
u64 size = md->num_pages << EFI_PAGE_SHIFT;
u64 end = md->phys_addr + size;
return end;
}
void __init __weak efi_arch_mem_reserve(phys_addr_t addr, u64 size) {}
/**
* efi_mem_reserve - Reserve an EFI memory region
* @addr: Physical address to reserve
* @size: Size of reservation
*
* Mark a region as reserved from general kernel allocation and
* prevent it being released by efi_free_boot_services().
*
* This function should be called drivers once they've parsed EFI
Annotation
- Immediate include surface: `linux/kobject.h`, `linux/module.h`, `linux/init.h`, `linux/debugfs.h`, `linux/device.h`, `linux/efi.h`, `linux/of.h`, `linux/initrd.h`.
- Detected declarations: `function setup_noefi`, `function efi_runtime_disabled`, `function __efi_soft_reserve_enabled`, `function parse_efi_cmdline`, `function systab_show`, `function fw_platform_size_show`, `function efi_attr_is_visible`, `function generic_ops_supported`, `function generic_ops_register`, `function generic_ops_unregister`.
- Atlas domain: Driver Families / drivers/firmware.
- Implementation status: integration 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.