nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0232-Replace-the-region-at-0-from-coreboot-tables-to-avai.patch

f96e0b
From 186c206f29e4ce0c6645c51dd477a8ce93952d51 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Mon, 25 Mar 2013 10:23:04 +0100
f96e0b
Subject: [PATCH 232/482] 	Replace the region at 0 from coreboot tables
f96e0b
 to available in BSD 	memory map.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                           |  5 +++++
f96e0b
 grub-core/commands/lsmmap.c         |  1 +
f96e0b
 grub-core/kern/i386/coreboot/mmap.c |  6 +++++-
f96e0b
 grub-core/loader/i386/bsd.c         | 13 +++++++++++--
f96e0b
 grub-core/mmap/mmap.c               |  1 +
f96e0b
 include/grub/memory.h               |  1 +
f96e0b
 6 files changed, 24 insertions(+), 3 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 981991b..8425aff 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,8 @@
f96e0b
+2013-03-25  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
+	Replace the region at 0 from coreboot tables to available in BSD
f96e0b
+	memory map.
f96e0b
+
f96e0b
 2013-03-24  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* util/grub.d/20_linux_xen.in: Automatically add no-real-mode edd=off on
f96e0b
diff --git a/grub-core/commands/lsmmap.c b/grub-core/commands/lsmmap.c
f96e0b
index c1a05d8..0d29855 100644
f96e0b
--- a/grub-core/commands/lsmmap.c
f96e0b
+++ b/grub-core/commands/lsmmap.c
f96e0b
@@ -37,6 +37,7 @@ static const char *names[] =
f96e0b
        is required to save accross hibernations.  */
f96e0b
     [GRUB_MEMORY_NVS] = N_("ACPI non-volatile storage RAM"),
f96e0b
     [GRUB_MEMORY_BADRAM] = N_("faulty RAM (BadRAM)"),
f96e0b
+    [GRUB_MEMORY_COREBOOT_TABLES] = N_("RAM holding coreboot tables"),
f96e0b
     [GRUB_MEMORY_CODE] = N_("RAM holding firmware code"),
f96e0b
     [GRUB_MEMORY_HOLE] = N_("Address range not associated with RAM")
f96e0b
   };
f96e0b
diff --git a/grub-core/kern/i386/coreboot/mmap.c b/grub-core/kern/i386/coreboot/mmap.c
f96e0b
index 6a14d29..0aade62 100644
f96e0b
--- a/grub-core/kern/i386/coreboot/mmap.c
f96e0b
+++ b/grub-core/kern/i386/coreboot/mmap.c
f96e0b
@@ -86,6 +86,8 @@ struct grub_machine_mmap_iterate_ctx
f96e0b
   void *hook_data;
f96e0b
 };
f96e0b
 
f96e0b
+#define GRUB_MACHINE_MEMORY_BADRAM 	5
f96e0b
+
f96e0b
 /* Helper for grub_machine_mmap_iterate.  */
f96e0b
 static int
f96e0b
 iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
f96e0b
@@ -105,7 +107,9 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
f96e0b
 		     /* Multiboot mmaps match with the coreboot mmap
f96e0b
 		        definition.  Therefore, we can just pass type
f96e0b
 		        through.  */
f96e0b
-		     mem_region->type, ctx->hook_data))
f96e0b
+		     (((mem_region->type <= GRUB_MACHINE_MEMORY_BADRAM) && (mem_region->type >= GRUB_MACHINE_MEMORY_AVAILABLE))
f96e0b
+		      || mem_region->type == GRUB_MEMORY_COREBOOT_TABLES) ? mem_region->type : GRUB_MEMORY_RESERVED,
f96e0b
+		     ctx->hook_data))
f96e0b
 	return 1;
f96e0b
 
f96e0b
       mem_region++;
f96e0b
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
f96e0b
index e89ec26..5fe586f 100644
f96e0b
--- a/grub-core/loader/i386/bsd.c
f96e0b
+++ b/grub-core/loader/i386/bsd.c
f96e0b
@@ -268,6 +268,7 @@ struct grub_e820_mmap
f96e0b
 #define GRUB_E820_ACPI       3
f96e0b
 #define GRUB_E820_NVS        4
f96e0b
 #define GRUB_E820_BADRAM     5
f96e0b
+#define GRUB_E820_COREBOOT_TABLES 0x10
f96e0b
 
f96e0b
 /* Context for generate_e820_mmap.  */
f96e0b
 struct generate_e820_mmap_ctx
f96e0b
@@ -299,13 +300,21 @@ generate_e820_mmap_iter (grub_uint64_t addr, grub_uint64_t size,
f96e0b
     case GRUB_MEMORY_NVS:
f96e0b
       ctx->cur.type = GRUB_E820_NVS;
f96e0b
       break;
f96e0b
-
f96e0b
+    case GRUB_MEMORY_COREBOOT_TABLES:
f96e0b
+      /* Nowadays the tables at 0 don't contain anything important but
f96e0b
+       *BSD needs the memory at 0 for own needs.
f96e0b
+       */
f96e0b
+      if (addr == 0)
f96e0b
+	ctx->cur.type = GRUB_E820_RAM;
f96e0b
+      else
f96e0b
+	ctx->cur.type = GRUB_E820_COREBOOT_TABLES;
f96e0b
+      break;
f96e0b
     default:
f96e0b
     case GRUB_MEMORY_CODE:
f96e0b
     case GRUB_MEMORY_RESERVED:
f96e0b
       ctx->cur.type = GRUB_E820_RESERVED;
f96e0b
       break;
f96e0b
-    }
f96e0b
+    }  
f96e0b
 
f96e0b
   /* Merge regions if possible. */
f96e0b
   if (ctx->count && ctx->cur.type == ctx->prev.type
f96e0b
diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c
f96e0b
index 40ffb2e..d8bd8d2 100644
f96e0b
--- a/grub-core/mmap/mmap.c
f96e0b
+++ b/grub-core/mmap/mmap.c
f96e0b
@@ -47,6 +47,7 @@ static const int priority[] =
f96e0b
   [GRUB_MEMORY_AVAILABLE] = 1,
f96e0b
   [GRUB_MEMORY_RESERVED] = 3,
f96e0b
   [GRUB_MEMORY_ACPI] = 2,
f96e0b
+  [GRUB_MEMORY_COREBOOT_TABLES] = 2,
f96e0b
   [GRUB_MEMORY_CODE] = 3,
f96e0b
   [GRUB_MEMORY_NVS] = 3,
f96e0b
   [GRUB_MEMORY_HOLE] = 4,
f96e0b
diff --git a/include/grub/memory.h b/include/grub/memory.h
f96e0b
index 3311fcb..0df8074 100644
f96e0b
--- a/include/grub/memory.h
f96e0b
+++ b/include/grub/memory.h
f96e0b
@@ -30,6 +30,7 @@ typedef enum grub_memory_type
f96e0b
     GRUB_MEMORY_ACPI = 3,
f96e0b
     GRUB_MEMORY_NVS = 4,
f96e0b
     GRUB_MEMORY_BADRAM = 5,
f96e0b
+    GRUB_MEMORY_COREBOOT_TABLES = 16,
f96e0b
     GRUB_MEMORY_CODE = 20,
f96e0b
     /* This one is special: it's used internally but is never reported
f96e0b
        by firmware. */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b