
From: Simon Glass <sjg@chromium.org> It is sometimes useful to display the memory type in logs, etc. Add a function to convert it to a string, which is more user-friendly than a number. Signed-off-by: Simon Glass <sjg@chromium.org> --- include/efi.h | 7 +++++++ lib/efi/memory.c | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/efi.h b/include/efi.h index e95bb2e7d96..e558c1f6a38 100644 --- a/include/efi.h +++ b/include/efi.h @@ -745,6 +745,13 @@ static inline bool efi_mem_is_boot_services(int type) type == EFI_BOOT_SERVICES_DATA; } +/** + * efi_mem_type_name() - Get the name of a memory type + * + * Return: Name, or "<invalid>" if the type is not known + */ +const char *efi_mem_type_name(enum efi_memory_type type); + /** * efi_dump_mem_table() - Dump out the EFI memory map * diff --git a/lib/efi/memory.c b/lib/efi/memory.c index 2e9aa2df5e9..a646f9852e8 100644 --- a/lib/efi/memory.c +++ b/lib/efi/memory.c @@ -58,6 +58,11 @@ static struct attr_info { { EFI_MEMORY_RUNTIME, "needs runtime mapping" } }; +const char *efi_mem_type_name(enum efi_memory_type type) +{ + return type < ARRAY_SIZE(type_name) ? type_name[type] : "<invalid>"; +} + void efi_dump_mem_table(struct efi_mem_desc *desc, int size, int desc_size, bool skip_bs) { @@ -76,7 +81,6 @@ void efi_dump_mem_table(struct efi_mem_desc *desc, int size, int desc_size, addr = 0; for (upto = 0; desc < end; upto++, desc = efi_get_next_mem_desc(desc, desc_size)) { - const char *name; u64 size; if (skip_bs && efi_mem_is_boot_services(desc->type)) @@ -87,11 +91,9 @@ void efi_dump_mem_table(struct efi_mem_desc *desc, int size, int desc_size, } size = desc->num_pages << EFI_PAGE_SHIFT; - name = desc->type < ARRAY_SIZE(type_name) ? - type_name[desc->type] : "<invalid>"; printf("%2d %x:%-12s %010llx %010llx %010llx ", upto, - desc->type, name, desc->physical_start, - desc->virtual_start, size); + desc->type, efi_mem_type_name(desc->type), + desc->physical_start, desc->virtual_start, size); if (desc->attribute & EFI_MEMORY_RUNTIME) putc('r'); printf("%llx", desc->attribute & ~EFI_MEMORY_RUNTIME); -- 2.43.0