dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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