]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - arch/x86/platform/efi/efi.c
x86/efi: Consolidate region mapping logic
[mirror_ubuntu-artful-kernel.git] / arch / x86 / platform / efi / efi.c
index 1fbb408e2e721837e7d28a9cdfdf59ffd96973d3..625ec729b4e85b25caa7b65dac9b9ab600f0aeeb 100644 (file)
@@ -745,6 +745,46 @@ static void *efi_map_next_entry(void *entry)
        return entry;
 }
 
+static bool should_map_region(efi_memory_desc_t *md)
+{
+       /*
+        * Runtime regions always require runtime mappings (obviously).
+        */
+       if (md->attribute & EFI_MEMORY_RUNTIME)
+               return true;
+
+       /*
+        * 32-bit EFI doesn't suffer from the bug that requires us to
+        * reserve boot services regions, and mixed mode support
+        * doesn't exist for 32-bit kernels.
+        */
+       if (IS_ENABLED(CONFIG_X86_32))
+               return false;
+
+       /*
+        * Map all of RAM so that we can access arguments in the 1:1
+        * mapping when making EFI runtime calls.
+        */
+       if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_is_native()) {
+               if (md->type == EFI_CONVENTIONAL_MEMORY ||
+                   md->type == EFI_LOADER_DATA ||
+                   md->type == EFI_LOADER_CODE)
+                       return true;
+       }
+
+       /*
+        * Map boot services regions as a workaround for buggy
+        * firmware that accesses them even when they shouldn't.
+        *
+        * See efi_{reserve,free}_boot_services().
+        */
+       if (md->type == EFI_BOOT_SERVICES_CODE ||
+           md->type == EFI_BOOT_SERVICES_DATA)
+               return true;
+
+       return false;
+}
+
 /*
  * Map the efi memory ranges of the runtime services and update new_mmap with
  * virtual addresses.
@@ -761,13 +801,9 @@ static void * __init efi_map_regions(int *count, int *pg_shift)
        p = NULL;
        while ((p = efi_map_next_entry(p))) {
                md = p;
-               if (!(md->attribute & EFI_MEMORY_RUNTIME)) {
-#ifdef CONFIG_X86_64
-                       if (md->type != EFI_BOOT_SERVICES_CODE &&
-                           md->type != EFI_BOOT_SERVICES_DATA)
-#endif
-                               continue;
-               }
+
+               if (!should_map_region(md))
+                       continue;
 
                efi_map_region(md);
                get_systab_virt_addr(md);