f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Robert Elliott <elliott@hpe.com>
f725e3
Date: Thu, 3 Dec 2015 11:38:36 -0600
f725e3
Subject: [PATCH] Translate UEFI persistent memory type
f725e3
MIME-Version: 1.0
f725e3
Content-Type: text/plain; charset=UTF-8
f725e3
Content-Transfer-Encoding: 8bit
f725e3
f725e3
Define
f725e3
* GRUB_EFI_PERSISTENT_MEMORY (UEFI memory map type 14) per UEFI 2.5
f725e3
* GRUB_MEMORY_PERSISTENT (E820 type 7) per ACPI 3.0
f725e3
* GRUB_MEMORY_PERSISTENT_LEGACY (E820 unofficial type 12) per ACPI 3.0
f725e3
f725e3
and translate GRUB_EFI_PERSISTENT_MEMORY to GRUB_MEMORY_PERSISTENT in
f725e3
grub_efi_mmap_iterate().
f725e3
f725e3
Includes
f725e3
* adding the E820 names to lsmmap
f725e3
* handling the E820 types in make_efi_memtype()
f725e3
f725e3
Suggested-by: Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>
f725e3
Suggested-by: Andrei Borzenkov <arvidjaar@gmail.com>
f725e3
(cherry picked from commit 76ce1de740f202985ffd7b2e980cf34c75a2dac3)
f725e3
f725e3
Resolves: rhbz#1288608
f725e3
---
f725e3
 grub-core/commands/lsmmap.c |  2 ++
f725e3
 grub-core/mmap/efi/mmap.c   | 12 ++++++++++++
f725e3
 include/grub/efi/api.h      |  1 +
f725e3
 include/grub/memory.h       |  2 ++
f725e3
 4 files changed, 17 insertions(+)
f725e3
f725e3
diff --git a/grub-core/commands/lsmmap.c b/grub-core/commands/lsmmap.c
f725e3
index 4b504fd28f8..816ee47d1ed 100644
f725e3
--- a/grub-core/commands/lsmmap.c
f725e3
+++ b/grub-core/commands/lsmmap.c
f725e3
@@ -37,6 +37,8 @@ static const char *names[] =
f725e3
        is required to save accross hibernations.  */
f725e3
     [GRUB_MEMORY_NVS] = N_("ACPI non-volatile storage RAM"),
f725e3
     [GRUB_MEMORY_BADRAM] = N_("faulty RAM (BadRAM)"),
f725e3
+    [GRUB_MEMORY_PERSISTENT] = N_("persistent RAM"),
f725e3
+    [GRUB_MEMORY_PERSISTENT_LEGACY] = N_("persistent RAM (legacy)"),
f725e3
     [GRUB_MEMORY_COREBOOT_TABLES] = N_("RAM holding coreboot tables"),
f725e3
     [GRUB_MEMORY_CODE] = N_("RAM holding firmware code")
f725e3
   };
f725e3
diff --git a/grub-core/mmap/efi/mmap.c b/grub-core/mmap/efi/mmap.c
f725e3
index 900a4d6598c..bd495a18481 100644
f725e3
--- a/grub-core/mmap/efi/mmap.c
f725e3
+++ b/grub-core/mmap/efi/mmap.c
f725e3
@@ -118,6 +118,11 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data,
f725e3
 		GRUB_MEMORY_NVS, hook_data);
f725e3
 	  break;
f725e3
 
f725e3
+	case GRUB_EFI_PERSISTENT_MEMORY:
f725e3
+	  hook (desc->physical_start, desc->num_pages * 4096,
f725e3
+		GRUB_MEMORY_PERSISTENT, hook_data);
f725e3
+	break;
f725e3
+
f725e3
 	default:
f725e3
 	  grub_printf ("Unknown memory type %d, considering reserved\n",
f725e3
 		       desc->type);
f725e3
@@ -147,6 +152,13 @@ make_efi_memtype (int type)
f725e3
       /* No way to remove a chunk of memory from EFI mmap.
f725e3
 	 So mark it as unusable. */
f725e3
     case GRUB_MEMORY_HOLE:
f725e3
+    /*
f725e3
+     * AllocatePages() does not support GRUB_EFI_PERSISTENT_MEMORY,
f725e3
+     * so no translation for GRUB_MEMORY_PERSISTENT or
f725e3
+     * GRUB_MEMORY_PERSISTENT_LEGACY.
f725e3
+     */
f725e3
+    case GRUB_MEMORY_PERSISTENT:
f725e3
+    case GRUB_MEMORY_PERSISTENT_LEGACY:
f725e3
     case GRUB_MEMORY_RESERVED:
f725e3
       return GRUB_EFI_UNUSABLE_MEMORY;
f725e3
 
f725e3
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
f725e3
index 029ee92f5d0..551d93e50a3 100644
f725e3
--- a/include/grub/efi/api.h
f725e3
+++ b/include/grub/efi/api.h
f725e3
@@ -431,6 +431,7 @@ enum grub_efi_memory_type
f725e3
     GRUB_EFI_MEMORY_MAPPED_IO,
f725e3
     GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE,
f725e3
     GRUB_EFI_PAL_CODE,
f725e3
+    GRUB_EFI_PERSISTENT_MEMORY,
f725e3
     GRUB_EFI_MAX_MEMORY_TYPE
f725e3
   };
f725e3
 typedef enum grub_efi_memory_type grub_efi_memory_type_t;
f725e3
diff --git a/include/grub/memory.h b/include/grub/memory.h
f725e3
index 083cfb6802e..6da114a1bdc 100644
f725e3
--- a/include/grub/memory.h
f725e3
+++ b/include/grub/memory.h
f725e3
@@ -30,6 +30,8 @@ typedef enum grub_memory_type
f725e3
     GRUB_MEMORY_ACPI = 3,
f725e3
     GRUB_MEMORY_NVS = 4,
f725e3
     GRUB_MEMORY_BADRAM = 5,
f725e3
+    GRUB_MEMORY_PERSISTENT = 7,
f725e3
+    GRUB_MEMORY_PERSISTENT_LEGACY = 12,
f725e3
     GRUB_MEMORY_COREBOOT_TABLES = 16,
f725e3
     GRUB_MEMORY_CODE = 20,
f725e3
     /* This one is special: it's used internally but is never reported