Several functions (efi_mem_type, efi_mem_attributes, efi_lookup_mapped_addr) scan the memory map looking for the memory descriptor to which a given physical address belongs for various purposes.
The scan functionality is duplicated in all the three functions. The common functionality is consolidated into a single function that three functions mentioned above may call. When checking the validity of the validity of the memory map, use efi_enabled(), provided for this purpose. Signed-off-by: Ricardo Neri <ricardo.neri-calde...@linux.intel.com> --- arch/x86/platform/efi/efi.c | 21 ++++++++++++++++++++- include/linux/efi.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 850da94..782d617 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -900,8 +900,27 @@ void __init efi_enter_virtual_mode(void) } /* - * Convenience functions to obtain memory types and attributes + * Convenience functions to obtain memory descriptors, + * memory types and attributes */ +efi_memory_desc_t *efi_memory_descriptor(unsigned long phys_addr) +{ + efi_memory_desc_t *md; + void *p; + + if (!efi_enabled(EFI_MEMMAP)) + return NULL; + + for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { + md = p; + if ((md->phys_addr <= phys_addr) && + (phys_addr < (md->phys_addr + + (md->num_pages << EFI_PAGE_SHIFT)))) + return md; + } + return NULL; +} + u32 efi_mem_type(unsigned long phys_addr) { efi_memory_desc_t *md; diff --git a/include/linux/efi.h b/include/linux/efi.h index 45cb4ff..b36b588 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -866,6 +866,7 @@ static inline efi_status_t efi_query_variable_store(u32 attributes, unsigned lon extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr); extern int efi_config_init(efi_config_table_type_t *arch_tables); extern u64 efi_get_iobase (void); +extern efi_memory_desc_t *efi_memory_descriptor(unsigned long phys_addr); extern u32 efi_mem_type (unsigned long phys_addr); extern u64 efi_mem_attributes (unsigned long phys_addr); extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/