在kernel commandline中加入efi=debug 就可以看到bios 占用的memory
efi=debug的解析函数如下:
static int __init parse_efi_cmdline(char *str)
{
if (!str) {
pr_warn("need at least one option\n");
return -EINVAL;
}
if (parse_option_str(str, "debug"))
set_bit(EFI_DBG, &efi.flags);
if (parse_option_str(str, "noruntime"))
disable_runtime = true;
return 0;
}
early_param("efi", parse_efi_cmdline);
efi_init->reserve_regions
static __init void reserve_regions(void)
{
efi_memory_desc_t *md;
u64 paddr, npages, size;
//是否使能了debug flag就dump bios占用的memory
if (efi_enabled(EFI_DBG))
pr_info("Processing EFI memory map:\n");
/*
* Discard memblocks discovered so far: if there are any at this
* point, they originate from memory nodes in the DT, and UEFI
* uses its own memory map instead.
*/
memblock_dump_all();
memblock_remove(0, (phys_addr_t)ULLONG_MAX);
//
可见bios的memory信息是保存在efi.memmap 变量中
#define for_each_efi_memory_desc(md) \
for_each_efi_memory_desc_in_map(&efi.memmap, md)
//
for_each_efi_memory_desc(md) {
paddr = md->phys_addr;
npages = md->num_pages;
if (efi_enabled(EFI_DBG)) {
char buf[64];
pr_info(" 0x%012llx-0x%012llx %s\n",
paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
efi_md_typeattr_format(buf, sizeof(buf), md));
}
memrange_efi_to_native(&paddr, &npages);
size = npages << PAGE_SHIFT;
if (is_memory(md)) {
early_init_dt_add_memory_arch(paddr, size);
if (!is_usable_memory(md))
memblock_mark_nomap(paddr, size);
}
}
}
实际可以打印的log如下:
[ 0.000000] Processing EFI memory map:
[ 0.000000] 0x000000000000-0x00000007ffff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000000080000-0x00000102ffff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000001030000-0x00001fdfffff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00001fe00000-0x00001fe0ffff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00001fe10000-0x00002def7fff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002def8000-0x00002ee9efff [Loader Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002ee9f000-0x00002fbfffff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002fc00000-0x00002fc1ffff [Boot Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002fc20000-0x0000305dbfff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x0000305dc000-0x000031453fff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000031454000-0x00003147efff [Loader Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00003147f000-0x000031682fff [Boot Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000031683000-0x000039683fff [Boot Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000039684000-0x0000396effff [Boot Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x0000396f0000-0x00003973ffff [Runtime Data |RUN| | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x000039740000-0x00003978ffff [Runtime Code |RUN| | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x000039790000-0x0000397dffff [ACPI Reclaim Memory| | | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x0000397e0000-0x0000397effff [ACPI Memory NVS | | | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x0000397f0000-0x00003983ffff [ACPI Reclaim Memory| | | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x000039840000-0x0000398bffff [Runtime Data |RUN| | | | | | |WB|WT|WC|UC]*
efi=debug的解析函数如下:
static int __init parse_efi_cmdline(char *str)
{
if (!str) {
pr_warn("need at least one option\n");
return -EINVAL;
}
if (parse_option_str(str, "debug"))
set_bit(EFI_DBG, &efi.flags);
if (parse_option_str(str, "noruntime"))
disable_runtime = true;
return 0;
}
early_param("efi", parse_efi_cmdline);
efi_init->reserve_regions
static __init void reserve_regions(void)
{
efi_memory_desc_t *md;
u64 paddr, npages, size;
//是否使能了debug flag就dump bios占用的memory
if (efi_enabled(EFI_DBG))
pr_info("Processing EFI memory map:\n");
/*
* Discard memblocks discovered so far: if there are any at this
* point, they originate from memory nodes in the DT, and UEFI
* uses its own memory map instead.
*/
memblock_dump_all();
memblock_remove(0, (phys_addr_t)ULLONG_MAX);
//
可见bios的memory信息是保存在efi.memmap 变量中
#define for_each_efi_memory_desc(md) \
for_each_efi_memory_desc_in_map(&efi.memmap, md)
//
for_each_efi_memory_desc(md) {
paddr = md->phys_addr;
npages = md->num_pages;
if (efi_enabled(EFI_DBG)) {
char buf[64];
pr_info(" 0x%012llx-0x%012llx %s\n",
paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
efi_md_typeattr_format(buf, sizeof(buf), md));
}
memrange_efi_to_native(&paddr, &npages);
size = npages << PAGE_SHIFT;
if (is_memory(md)) {
early_init_dt_add_memory_arch(paddr, size);
if (!is_usable_memory(md))
memblock_mark_nomap(paddr, size);
}
}
}
实际可以打印的log如下:
[ 0.000000] Processing EFI memory map:
[ 0.000000] 0x000000000000-0x00000007ffff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000000080000-0x00000102ffff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000001030000-0x00001fdfffff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00001fe00000-0x00001fe0ffff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00001fe10000-0x00002def7fff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002def8000-0x00002ee9efff [Loader Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002ee9f000-0x00002fbfffff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002fc00000-0x00002fc1ffff [Boot Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00002fc20000-0x0000305dbfff [Conventional Memory| | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x0000305dc000-0x000031453fff [Loader Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000031454000-0x00003147efff [Loader Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x00003147f000-0x000031682fff [Boot Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000031683000-0x000039683fff [Boot Data | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x000039684000-0x0000396effff [Boot Code | | | | | | | |WB|WT|WC|UC]
[ 0.000000] 0x0000396f0000-0x00003973ffff [Runtime Data |RUN| | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x000039740000-0x00003978ffff [Runtime Code |RUN| | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x000039790000-0x0000397dffff [ACPI Reclaim Memory| | | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x0000397e0000-0x0000397effff [ACPI Memory NVS | | | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x0000397f0000-0x00003983ffff [ACPI Reclaim Memory| | | | | | | |WB|WT|WC|UC]*
[ 0.000000] 0x000039840000-0x0000398bffff [Runtime Data |RUN| | | | | | |WB|WT|WC|UC]*