dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0193-lsefimmap-support-persistent-memory-and-other-UEFI-2.patch

f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Robert Elliott <elliott@hpe.com>
f725e3
Date: Thu, 17 Dec 2015 10:53:32 -0600
f725e3
Subject: [PATCH] lsefimmap: support persistent memory and other UEFI 2.5
f725e3
 features
f725e3
f725e3
This should accompany
f725e3
	76ce1de740 Translate UEFI persistent memory type
f725e3
f725e3
1. Add a string for the EfiPersistentMemory type 14 that was
f725e3
added in UEFI 2.5.
f725e3
f725e3
2. Decode the memory attributes that were added in UEFI 2.5:
f725e3
* NV (non-volatile)
f725e3
* MORE_RELIABLE (higher reliable, e.g., mirrored memory in a system
f725e3
  with partial memory mirroring)
f725e3
* RO (read-only)
f725e3
f725e3
3. Use proper IEC binary units (KiB, MiB, etc.) for power-of-two
f725e3
values rather than misusing SI power-of-ten units (KB, MB, etc.)
f725e3
f725e3
4. The lsmmap command only decodes memory ranges sizes up to GiB scale
f725e3
units.  Persistent memory ranges will reach into the TiB scale.
f725e3
Since 64-bit size field supports TiB, PiB, and EiB, decode all of
f725e3
them for completeness.
f725e3
f725e3
5. In the lsefimmap command, rewrite the print statements to
f725e3
* avoid rounding
f725e3
* avoid a big nested if/else tree.
f725e3
f725e3
For example: In the sixth entry below, the value of 309MB implies
f725e3
316416KB but is really reporting 316436KB.
f725e3
f725e3
Widen the size column to 6 digits to accommodate typical cases.
f725e3
The worst case value would require 14 digits; if that happens,
f725e3
let the columns get out of sync.
f725e3
f725e3
Old format:
f725e3
Type      Physical start  - end             #Pages     Size Attributes
f725e3
conv-mem  0000000000000000-0000000000092fff 00000093  588KB UC WC WT WB
f725e3
reserved  0000000000093000-0000000000093fff 00000001    4KB UC WC WT WB
f725e3
conv-mem  0000000000094000-000000000009ffff 0000000c   48KB UC WC WT WB
f725e3
conv-mem  0000000000100000-000000000fffffff 0000ff00  255MB UC WC WT WB
f725e3
BS-code   0000000010000000-0000000010048fff 00000049  292KB UC WC WT WB
f725e3
conv-mem  0000000010049000-000000002354dfff 00013505  309MB UC WC WT WB
f725e3
ldr-data  000000002354e000-000000003ecfffff 0001b7b2  439MB UC WC WT WB
f725e3
BS-data   000000003ed00000-000000003ed7ffff 00000080  512KB UC WC WT WB
f725e3
conv-mem  000000003ed80000-000000006af5ffff 0002c1e0  705MB UC WC WT WB
f725e3
reserved  000000006af60000-000000006b55ffff 00000600    6MB UC WC WT WB
f725e3
BS-data   000000006b560000-000000006b560fff 00000001    4KB UC WC WT WB
f725e3
RT-data   000000006b561000-000000006b5e1fff 00000081  516KB RT UC WC WT WB
f725e3
BS-data   000000006b5e2000-000000006ecfafff 00003719   55MB UC WC WT WB
f725e3
BS-code   000000006ecfb000-000000006ecfbfff 00000001    4KB UC WC WT WB
f725e3
conv-mem  000000006ecfc000-00000000711fafff 000024ff   36MB UC WC WT WB
f725e3
BS-data   00000000711fb000-000000007128dfff 00000093  588KB UC WC WT WB
f725e3
Unk 0d    0000000880000000-0000000e7fffffff 00600000   24GB UC WC WT WB NV
f725e3
reserved  0000001680000000-0000001c7fffffff 00600000   24GB UC WC WT WB NV
f725e3
f725e3
New format:
f725e3
Type      Physical start  - end             #Pages        Size Attributes
f725e3
conv-mem  0000000000000000-0000000000092fff 00000093    588KiB UC WC WT WB
f725e3
reserved  0000000000093000-0000000000093fff 00000001      4KiB UC WC WT WB
f725e3
conv-mem  0000000000094000-000000000009ffff 0000000c     48KiB UC WC WT WB
f725e3
conv-mem  0000000000100000-000000000fffffff 0000ff00    255MiB UC WC WT WB
f725e3
BS-code   0000000010000000-0000000010048fff 00000049    292KiB UC WC WT WB
f725e3
conv-mem  0000000010049000-000000002354dfff 00013505 316436KiB UC WC WT WB
f725e3
ldr-data  000000002354e000-000000003ecfffff 0001b7b2 450248KiB UC WC WT WB
f725e3
BS-data   000000003ed00000-000000003ed7ffff 00000080    512KiB UC WC WT WB
f725e3
conv-mem  000000003ed80000-000000006af5ffff 0002c1e0 722816KiB UC WC WT WB
f725e3
reserved  000000006af60000-000000006b55ffff 00000600      6MiB UC WC WT WB
f725e3
BS-data   000000006b560000-000000006b560fff 00000001      4KiB UC WC WT WB
f725e3
RT-data   000000006b561000-000000006b5e1fff 00000081    516KiB RT UC WC WT WB
f725e3
BS-data   000000006b5e2000-000000006ecfafff 00003719  56420KiB UC WC WT WB
f725e3
BS-code   000000006ecfb000-000000006ecfbfff 00000001      4KiB UC WC WT WB
f725e3
conv-mem  000000006ecfc000-0000000071222fff 00002527  38044KiB UC WC WT WB
f725e3
BS-data   0000000071223000-00000000712ddfff 000000bb    748KiB UC WC WT WB
f725e3
persist   0000000880000000-0000000e7fffffff 00600000     24GiB UC WC WT WB NV
f725e3
reserved  0000001680000000-0000001c7fffffff 00600000     24GiB UC WC WT WB NV
f725e3
f725e3
(cherry picked from commit c79c59f1295df8ea660f8a858f9532d76a5f67b7)
f725e3
f725e3
Resolves: rhbz#1288608
f725e3
---
f725e3
 grub-core/commands/efi/lsefimmap.c | 47 +++++++++++++++++++++++++-------------
f725e3
 include/grub/efi/api.h             |  3 +++
f725e3
 2 files changed, 34 insertions(+), 16 deletions(-)
f725e3
f725e3
diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c
f725e3
index 215b45bff80..c85ff7f366d 100644
f725e3
--- a/grub-core/commands/efi/lsefimmap.c
f725e3
+++ b/grub-core/commands/efi/lsefimmap.c
f725e3
@@ -51,7 +51,7 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
f725e3
 
f725e3
   grub_printf
f725e3
     ("Type      Physical start  - end             #Pages   "
f725e3
-     "  Size Attributes\n");
f725e3
+     "     Size Attributes\n");
f725e3
   memory_map_end = ADD_MEMORY_DESCRIPTOR (memory_map, map_size);
f725e3
   for (desc = memory_map;
f725e3
        desc < memory_map_end;
f725e3
@@ -74,7 +74,8 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
f725e3
 	  "ACPI-nvs",
f725e3
 	  "MMIO    ",
f725e3
 	  "IO-ports",
f725e3
-	  "PAL-code"
f725e3
+	  "PAL-code",
f725e3
+	  "persist ",
f725e3
 	};
f725e3
       if (desc->type < ARRAY_SIZE (types_str))
f725e3
 	grub_printf ("%s ", types_str[desc->type]);
f725e3
@@ -87,21 +88,29 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
f725e3
 		   desc->physical_start + (desc->num_pages << 12) - 1,
f725e3
 		   desc->num_pages);
f725e3
 
f725e3
-      size = desc->num_pages;
f725e3
-      size <<= (12 - 10);
f725e3
-      if (size < 1024)
f725e3
-	grub_printf (" %4" PRIuGRUB_UINT64_T "KB", size);
f725e3
+      size = desc->num_pages << 12;	/* 4 KiB page size */
f725e3
+      /*
f725e3
+       * Since size is a multiple of 4 KiB, no need to handle units
f725e3
+       * of just Bytes (which would use a mask of 0x3ff).
f725e3
+       *
f725e3
+       * 14 characters would support the largest possible number of 4 KiB
f725e3
+       * pages that are not a multiple of larger units (e.g., MiB):
f725e3
+       * 17592186044415 (0xffffff_fffff000), but that uses a lot of
f725e3
+       * whitespace for a rare case.  6 characters usually suffices;
f725e3
+       * columns will be off if not, but this is preferable to rounding.
f725e3
+       */
f725e3
+      if (size & 0xfffff)
f725e3
+	grub_printf (" %6" PRIuGRUB_UINT64_T "KiB", size >> 10);
f725e3
+      else if (size & 0x3fffffff)
f725e3
+	grub_printf (" %6" PRIuGRUB_UINT64_T "MiB", size >> 20);
f725e3
+      else if (size & 0xffffffffff)
f725e3
+	grub_printf (" %6" PRIuGRUB_UINT64_T "GiB", size >> 30);
f725e3
+      else if (size & 0x3ffffffffffff)
f725e3
+	grub_printf (" %6" PRIuGRUB_UINT64_T "TiB", size >> 40);
f725e3
+      else if (size & 0xfffffffffffffff)
f725e3
+	grub_printf (" %6" PRIuGRUB_UINT64_T "PiB", size >> 50);
f725e3
       else
f725e3
-	{
f725e3
-	  size /= 1024;
f725e3
-	  if (size < 1024)
f725e3
-	    grub_printf (" %4" PRIuGRUB_UINT64_T "MB", size);
f725e3
-	  else
f725e3
-	    {
f725e3
-	      size /= 1024;
f725e3
-	      grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size);
f725e3
-	    }
f725e3
-	}
f725e3
+	grub_printf (" %6" PRIuGRUB_UINT64_T "EiB", size >> 60);
f725e3
 
f725e3
       attr = desc->attribute;
f725e3
       if (attr & GRUB_EFI_MEMORY_RUNTIME)
f725e3
@@ -122,6 +131,12 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
f725e3
 	grub_printf (" RP");
f725e3
       if (attr & GRUB_EFI_MEMORY_XP)
f725e3
 	grub_printf (" XP");
f725e3
+      if (attr & GRUB_EFI_MEMORY_NV)
f725e3
+	grub_printf (" NV");
f725e3
+      if (attr & GRUB_EFI_MEMORY_MORE_RELIABLE)
f725e3
+	grub_printf (" MR");
f725e3
+      if (attr & GRUB_EFI_MEMORY_RO)
f725e3
+	grub_printf (" RO");
f725e3
 
f725e3
       grub_printf ("\n");
f725e3
     }
f725e3
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
f725e3
index 551d93e50a3..a6cce6e3395 100644
f725e3
--- a/include/grub/efi/api.h
f725e3
+++ b/include/grub/efi/api.h
f725e3
@@ -49,6 +49,9 @@
f725e3
 #define GRUB_EFI_MEMORY_WP	0x0000000000001000LL
f725e3
 #define GRUB_EFI_MEMORY_RP	0x0000000000002000LL
f725e3
 #define GRUB_EFI_MEMORY_XP	0x0000000000004000LL
f725e3
+#define GRUB_EFI_MEMORY_NV	0x0000000000008000LL
f725e3
+#define GRUB_EFI_MEMORY_MORE_RELIABLE	0x0000000000010000LL
f725e3
+#define GRUB_EFI_MEMORY_RO	0x0000000000020000LL
f725e3
 #define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000LL
f725e3
 
f725e3
 #define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL	0x00000001