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

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