drivers/firmware/efi/libstub/efi-stub.c
Source file repositories/reference/linux-study-clean/drivers/firmware/efi/libstub/efi-stub.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/efi/libstub/efi-stub.c- Extension
.c- Size
- 7737 bytes
- Lines
- 281
- 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.
- 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/efi.hlinux/sysfb.hasm/efi.hefistub.h
Detected Declarations
function free_primary_displayfunction install_memreserve_tablefunction get_supported_rt_servicesfunction efi_handle_cmdlinefunction efi_stub_commonfunction efi_allocate_virtmapfunction efi_get_virtmap
Annotated Snippet
if (status != EFI_SUCCESS) {
efi_err("Failed to parse EFI load options\n");
return status;
}
}
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
cmdline[0] == 0) {
status = efi_parse_options(CONFIG_CMDLINE);
if (status != EFI_SUCCESS) {
efi_err("Failed to parse built-in command line\n");
return status;
}
}
*cmdline_ptr = no_free_ptr(cmdline);
return EFI_SUCCESS;
}
efi_status_t efi_stub_common(efi_handle_t handle,
efi_loaded_image_t *image,
unsigned long image_addr,
char *cmdline_ptr)
{
struct sysfb_display_info *dpy;
efi_status_t status;
status = check_platform_features();
if (status != EFI_SUCCESS)
return status;
dpy = setup_primary_display();
efi_retrieve_eventlog();
/* Ask the firmware to clear memory on unclean shutdown */
efi_enable_reset_attack_mitigation();
efi_load_initrd(image, ULONG_MAX, efi_get_max_initrd_addr(image_addr),
NULL);
efi_random_get_seed();
/* force efi_novamap if SetVirtualAddressMap() is unsupported */
efi_novamap |= !(get_supported_rt_services() &
EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP);
install_memreserve_table();
status = efi_boot_kernel(handle, image, image_addr, cmdline_ptr);
free_primary_display(dpy);
return status;
}
/*
* efi_allocate_virtmap() - create a pool allocation for the virtmap
*
* Create an allocation that is of sufficient size to hold all the memory
* descriptors that will be passed to SetVirtualAddressMap() to inform the
* firmware about the virtual mapping that will be used under the OS to call
* into the firmware.
*/
efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
unsigned long *desc_size, u32 *desc_ver)
{
unsigned long size, mmap_key;
efi_status_t status;
/*
* Use the size of the current memory map as an upper bound for the
* size of the buffer we need to pass to SetVirtualAddressMap() to
* cover all EFI_MEMORY_RUNTIME regions.
*/
size = 0;
status = efi_bs_call(get_memory_map, &size, NULL, &mmap_key, desc_size,
desc_ver);
if (status != EFI_BUFFER_TOO_SMALL)
return EFI_LOAD_ERROR;
return efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
(void **)virtmap);
}
/*
* efi_get_virtmap() - create a virtual mapping for the EFI memory map
*
* This function populates the virt_addr fields of all memory region descriptors
Annotation
- Immediate include surface: `linux/efi.h`, `linux/sysfb.h`, `asm/efi.h`, `efistub.h`.
- Detected declarations: `function free_primary_display`, `function install_memreserve_table`, `function get_supported_rt_services`, `function efi_handle_cmdline`, `function efi_stub_common`, `function efi_allocate_virtmap`, `function efi_get_virtmap`.
- Atlas domain: Driver Families / drivers/firmware.
- 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.