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