x86: rename two e820 related functions
[linux-3.10.git] / arch / x86 / kernel / efi.c
index cbdf9ba..473c89f 100644 (file)
@@ -54,7 +54,7 @@ EXPORT_SYMBOL(efi);
 
 struct efi_memory_map memmap;
 
-struct efi efi_phys __initdata;
+static struct efi efi_phys __initdata;
 static efi_system_table_t efi_systab __initdata;
 
 static int __init setup_noefi(char *arg)
@@ -213,6 +213,48 @@ unsigned long efi_get_time(void)
                      eft.minute, eft.second);
 }
 
+/*
+ * Tell the kernel about the EFI memory map.  This might include
+ * more than the max 128 entries that can fit in the e820 legacy
+ * (zeropage) memory map.
+ */
+
+static void __init add_efi_memmap(void)
+{
+       void *p;
+
+       for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
+               efi_memory_desc_t *md = p;
+               unsigned long long start = md->phys_addr;
+               unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
+               int e820_type;
+
+               if (md->attribute & EFI_MEMORY_WB)
+                       e820_type = E820_RAM;
+               else
+                       e820_type = E820_RESERVED;
+               e820_add_region(start, size, e820_type);
+       }
+       sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+}
+
+void __init efi_reserve_early(void)
+{
+       unsigned long pmap;
+
+       pmap = boot_params.efi_info.efi_memmap;
+#ifdef CONFIG_X86_64
+       pmap += (__u64)boot_params.efi_info.efi_memmap_hi << 32;
+#endif
+       memmap.phys_map = (void *)pmap;
+       memmap.nr_map = boot_params.efi_info.efi_memmap_size /
+               boot_params.efi_info.efi_memdesc_size;
+       memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
+       memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
+       reserve_early(pmap, pmap + memmap.nr_map * memmap.desc_size,
+                     "EFI memmap");
+}
+
 #if EFI_DEBUG
 static void __init print_efi_memmap(void)
 {
@@ -242,21 +284,11 @@ void __init efi_init(void)
        int i = 0;
        void *tmp;
 
-#ifdef CONFIG_X86_32
        efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab;
-       memmap.phys_map = (void *)boot_params.efi_info.efi_memmap;
-#else
-       efi_phys.systab = (efi_system_table_t *)
-               (boot_params.efi_info.efi_systab |
-                ((__u64)boot_params.efi_info.efi_systab_hi<<32));
-       memmap.phys_map = (void *)
-               (boot_params.efi_info.efi_memmap |
-                ((__u64)boot_params.efi_info.efi_memmap_hi<<32));
+#ifdef CONFIG_X86_64
+       efi_phys.systab = (void *)efi_phys.systab +
+               ((__u64)boot_params.efi_info.efi_systab_hi<<32);
 #endif
-       memmap.nr_map = boot_params.efi_info.efi_memmap_size /
-               boot_params.efi_info.efi_memdesc_size;
-       memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
-       memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
 
        efi.systab = early_ioremap((unsigned long)efi_phys.systab,
                                   sizeof(efi_system_table_t));
@@ -370,6 +402,7 @@ void __init efi_init(void)
        if (memmap.desc_size != sizeof(efi_memory_desc_t))
                printk(KERN_WARNING "Kernel-defined memdesc"
                       "doesn't match the one from EFI!\n");
+       add_efi_memmap();
 
        /* Setup for EFI runtime service */
        reboot_type = BOOT_EFI;
@@ -383,6 +416,7 @@ static void __init runtime_code_page_mkexec(void)
 {
        efi_memory_desc_t *md;
        void *p;
+       u64 addr, npages;
 
        /* Make EFI runtime service code area executable */
        for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
@@ -391,7 +425,10 @@ static void __init runtime_code_page_mkexec(void)
                if (md->type != EFI_RUNTIME_SERVICES_CODE)
                        continue;
 
-               set_memory_x(md->virt_addr, md->num_pages << EFI_PAGE_SHIFT);
+               addr = md->virt_addr;
+               npages = md->num_pages;
+               memrange_efi_to_native(&addr, &npages);
+               set_memory_x(addr, npages);
        }
 }
 
@@ -408,7 +445,7 @@ void __init efi_enter_virtual_mode(void)
        efi_memory_desc_t *md;
        efi_status_t status;
        unsigned long size;
-       u64 end, systab;
+       u64 end, systab, addr, npages;
        void *p, *va;
 
        efi.systab = NULL;
@@ -420,7 +457,7 @@ void __init efi_enter_virtual_mode(void)
                size = md->num_pages << EFI_PAGE_SHIFT;
                end = md->phys_addr + size;
 
-               if ((end >> PAGE_SHIFT) <= max_pfn_mapped)
+               if (PFN_UP(end) <= max_pfn_mapped)
                        va = __va(md->phys_addr);
                else
                        va = efi_ioremap(md->phys_addr, size);
@@ -433,8 +470,12 @@ void __init efi_enter_virtual_mode(void)
                        continue;
                }
 
-               if (!(md->attribute & EFI_MEMORY_WB))
-                       set_memory_uc(md->virt_addr, size);
+               if (!(md->attribute & EFI_MEMORY_WB)) {
+                       addr = md->virt_addr;
+                       npages = md->num_pages;
+                       memrange_efi_to_native(&addr, &npages);
+                       set_memory_uc(addr, npages);
+               }
 
                systab = (u64) (unsigned long) efi_phys.systab;
                if (md->phys_addr <= systab && systab < end) {