]> xenbits.xensource.com Git - xen.git/commitdiff
tools: hvmloader: split e820 support into its own code module.
authorIan Campbell <ian.campbell@citrix.com>
Tue, 12 Apr 2011 12:36:17 +0000 (13:36 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 12 Apr 2011 12:36:17 +0000 (13:36 +0100)
Pass the table address as a paramter to the build function and cause
it to return the number of entries. Pass both base and offset as
parameters to the dump function.

This adds a duplicated e820.h header to ROMBIOS. Since the e820 data
structure is well defined by existing BIOS implementations I think
this is OK and simplifies the cross talk between hvmloader and
ROMBIOS.

Reduces the cross talk between ROMBIOS and hvmloader.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
tools/firmware/hvmloader/Makefile
tools/firmware/hvmloader/config.h
tools/firmware/hvmloader/e820.c [new file with mode: 0644]
tools/firmware/hvmloader/e820.h
tools/firmware/hvmloader/hvmloader.c
tools/firmware/hvmloader/smbios.c
tools/firmware/hvmloader/util.c
tools/firmware/hvmloader/util.h
tools/firmware/rombios/32bit/pmm.c
tools/firmware/rombios/config.h
tools/firmware/rombios/e820.h [new file with mode: 0644]

index 669bf6d65380b16aa1ab0b7c39ac776b77c960eb..59cfed959e7adac835bd5e06187be7b3a588c36a 100644 (file)
@@ -30,6 +30,7 @@ CFLAGS += $(CFLAGS_xeninclude)
 
 SRCS  = hvmloader.c mp_tables.c util.c smbios.c 
 SRCS += 32bitbios_support.c smp.c cacheattr.c xenbus.c
+SRCS += e820.c
 ifeq ($(debug),y)
 SRCS += tests.c
 endif
index 1f8124e0c6823d60afa59f3092170e77a4e1d3e3..cac9f1078577e846b359ccd2b28445edd27002de 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __HVMLOADER_CONFIG_H__
 #define __HVMLOADER_CONFIG_H__
 
+#include <stdint.h>
+
 #define PAGE_SHIFT 12
 #define PAGE_SIZE  (1ul << PAGE_SHIFT)
 
@@ -28,6 +30,7 @@ extern unsigned long pci_mem_start, pci_mem_end;
 #define ROMBIOS_MAXOFFSET      0x0000FFFF
 #define ROMBIOS_END            (ROMBIOS_BEGIN + ROMBIOS_SIZE)
 
+#include "e820.h"
 #include "../rombios/config.h"
 
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
new file mode 100644 (file)
index 0000000..9ab5380
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * HVM e820 support.
+ *
+ * Leendert van Doorn, leendert@watson.ibm.com
+ * Copyright (c) 2005, International Business Machines Corporation.
+ * Copyright (c) 2006, Keir Fraser, XenSource Inc.
+ * Copyright (c) 2011, Citrix Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "config.h"
+#include "util.h"
+
+void dump_e820_table(struct e820entry *e820, unsigned int nr)
+{
+    uint64_t last_end = 0, start, end;
+    int i;
+
+    printf("E820 table:\n");
+
+    for ( i = 0; i < nr; i++ )
+    {
+        start = e820[i].addr;
+        end = e820[i].addr + e820[i].size;
+
+        if ( start < last_end )
+            printf(" OVERLAP!!\n");
+        else if ( start > last_end )
+            printf(" HOLE: %08x:%08x - %08x:%08x\n",
+                   (uint32_t)(last_end >> 32), (uint32_t)last_end,
+                   (uint32_t)(start >> 32), (uint32_t)start);
+
+        printf(" [%02d]: %08x:%08x - %08x:%08x: ", i,
+               (uint32_t)(start >> 32), (uint32_t)start,
+               (uint32_t)(end >> 32), (uint32_t)end);
+        switch ( e820[i].type )
+        {
+        case E820_RAM:
+            printf("RAM\n");
+            break;
+        case E820_RESERVED:
+            printf("RESERVED\n");
+            break;
+        case E820_ACPI:
+            printf("ACPI\n");
+            break;
+        case E820_NVS:
+            printf("NVS\n");
+            break;
+        default:
+            printf("UNKNOWN (%08x)\n", e820[i].type);
+            break;
+        }
+
+        last_end = end;
+    }
+}
+
+/* Create an E820 table based on memory parameters provided in hvm_info. */
+int build_e820_table(struct e820entry *e820)
+{
+    unsigned int nr = 0;
+
+    /* 0x0-0x9E000: Ordinary RAM. */
+    /* (Must be at least 512K to keep Windows happy) */
+    e820[nr].addr = 0x00000;
+    e820[nr].size = 0x9E000;
+    e820[nr].type = E820_RAM;
+    nr++;
+
+    /* 0x9E000-0x9FC00: Reserved for internal use. */
+    e820[nr].addr = 0x9E000;
+    e820[nr].size = 0x01C00;
+    e820[nr].type = E820_RESERVED;
+    nr++;
+
+    /* 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA). */
+    e820[nr].addr = 0x9FC00;
+    e820[nr].size = 0x400;
+    e820[nr].type = E820_RESERVED;
+    nr++;
+
+    /*
+     * Following regions are standard regions of the PC memory map.
+     * They are not covered by e820 regions. OSes will not use as RAM.
+     * 0xA0000-0xC0000: VGA memory-mapped I/O. Not covered by E820.
+     * 0xC0000-0xE0000: 16-bit devices, expansion ROMs (inc. vgabios).
+     * TODO: free pages which turn out to be unused.
+     */
+
+    /*
+     * 0xE0000-0x0F0000: PC-specific area. We place various tables here.
+     * 0xF0000-0x100000: System BIOS.
+     * TODO: free pages which turn out to be unused.
+     */
+    e820[nr].addr = 0xE0000;
+    e820[nr].size = 0x20000;
+    e820[nr].type = E820_RESERVED;
+    nr++;
+
+    /* Low RAM goes here. Reserve space for special pages. */
+    BUG_ON((hvm_info->low_mem_pgend << PAGE_SHIFT) < (2u << 20));
+    e820[nr].addr = 0x100000;
+    e820[nr].size = (hvm_info->low_mem_pgend << PAGE_SHIFT) - e820[nr].addr;
+    e820[nr].type = E820_RAM;
+    nr++;
+
+    /*
+     * Explicitly reserve space for special pages.
+     * This space starts at RESERVED_MEMBASE an extends to cover various
+     * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
+     */
+    e820[nr].addr = RESERVED_MEMBASE;
+    e820[nr].size = (uint32_t)-e820[nr].addr;
+    e820[nr].type = E820_RESERVED;
+    nr++;
+
+    if ( hvm_info->high_mem_pgend )
+    {
+        e820[nr].addr = ((uint64_t)1 << 32);
+        e820[nr].size =
+            ((uint64_t)hvm_info->high_mem_pgend << PAGE_SHIFT) - e820[nr].addr;
+        e820[nr].type = E820_RAM;
+        nr++;
+    }
+
+    return nr;
+}
+
index 940c8ed3949cb69f264f3baee50d3ed9324008a0..e9e4e337025c4f0d6a95e4df5fb65a50fda6d7f4 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef __HVMLOADER_E820_H__
 #define __HVMLOADER_E820_H__
 
-#include <xen/hvm/e820.h>
-
 /*
  * PC BIOS standard E820 types and structure.
  */
@@ -17,7 +15,4 @@ struct e820entry {
     uint32_t type;
 } __attribute__((packed));
 
-#define E820_NR ((uint16_t *)(E820_PHYSICAL_ADDRESS + E820_NR_OFFSET))
-#define E820    ((struct e820entry *)(E820_PHYSICAL_ADDRESS + E820_OFFSET))
-
 #endif /* __HVMLOADER_E820_H__ */
index 5ba71f6217bc12334006b78ffe342211fdd243a9..01e1da2a14e981581c03fc27d103dbb03dc31ea0 100644 (file)
@@ -27,7 +27,6 @@
 #include "config.h"
 #include "apic_regs.h"
 #include "pci_regs.h"
-#include "e820.h"
 #include "option_rom.h"
 #include <xen/version.h>
 #include <xen/hvm/params.h>
@@ -578,125 +577,6 @@ static void init_vm86_tss(void)
     printf("vm86 TSS at %08lx\n", virt_to_phys(tss));
 }
 
-static void dump_e820_table(void)
-{
-    struct e820entry *e820 = E820;
-    unsigned int nr = *E820_NR;
-    uint64_t last_end = 0, start, end;
-    int i;
-
-    printf("E820 table:\n");
-
-    for ( i = 0; i < nr; i++ )
-    {
-        start = e820[i].addr;
-        end = e820[i].addr + e820[i].size;
-
-        if ( start < last_end )
-            printf(" OVERLAP!!\n");
-        else if ( start > last_end )
-            printf(" HOLE: %08x:%08x - %08x:%08x\n",
-                   (uint32_t)(last_end >> 32), (uint32_t)last_end,
-                   (uint32_t)(start >> 32), (uint32_t)start);
-
-        printf(" [%02d]: %08x:%08x - %08x:%08x: ", i,
-               (uint32_t)(start >> 32), (uint32_t)start,
-               (uint32_t)(end >> 32), (uint32_t)end);
-        switch ( e820[i].type )
-        {
-        case E820_RAM:
-            printf("RAM\n");
-            break;
-        case E820_RESERVED:
-            printf("RESERVED\n");
-            break;
-        case E820_ACPI:
-            printf("ACPI\n");
-            break;
-        case E820_NVS:
-            printf("NVS\n");
-            break;
-        default:
-            printf("UNKNOWN (%08x)\n", e820[i].type);
-            break;
-        }
-
-        last_end = end;
-    }
-}
-
-/* Create an E820 table based on memory parameters provided in hvm_info. */
-static void build_e820_table(void)
-{
-    struct e820entry *e820 = E820;
-    unsigned int nr = 0;
-
-    /* 0x0-0x9E000: Ordinary RAM. */
-    /* (Must be at least 512K to keep Windows happy) */
-    e820[nr].addr = 0x00000;
-    e820[nr].size = 0x9E000;
-    e820[nr].type = E820_RAM;
-    nr++;
-
-    /* 0x9E000-0x9FC00: Reserved for internal use. */
-    e820[nr].addr = 0x9E000;
-    e820[nr].size = 0x01C00;
-    e820[nr].type = E820_RESERVED;
-    nr++;
-
-    /* 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA). */
-    e820[nr].addr = 0x9FC00;
-    e820[nr].size = 0x400;
-    e820[nr].type = E820_RESERVED;
-    nr++;
-
-    /*
-     * Following regions are standard regions of the PC memory map.
-     * They are not covered by e820 regions. OSes will not use as RAM.
-     * 0xA0000-0xC0000: VGA memory-mapped I/O. Not covered by E820.
-     * 0xC0000-0xE0000: 16-bit devices, expansion ROMs (inc. vgabios).
-     * TODO: free pages which turn out to be unused.
-     */
-
-    /*
-     * 0xE0000-0x0F0000: PC-specific area. We place various tables here.
-     * 0xF0000-0x100000: System BIOS.
-     * TODO: free pages which turn out to be unused.
-     */
-    e820[nr].addr = 0xE0000;
-    e820[nr].size = 0x20000;
-    e820[nr].type = E820_RESERVED;
-    nr++;
-
-    /* Low RAM goes here. Reserve space for special pages. */
-    BUG_ON((hvm_info->low_mem_pgend << PAGE_SHIFT) < (2u << 20));
-    e820[nr].addr = 0x100000;
-    e820[nr].size = (hvm_info->low_mem_pgend << PAGE_SHIFT) - e820[nr].addr;
-    e820[nr].type = E820_RAM;
-    nr++;
-
-    /*
-     * Explicitly reserve space for special pages.
-     * This space starts at RESERVED_MEMBASE an extends to cover various
-     * fixed hardware mappings (e.g., LAPIC, IOAPIC, default SVGA framebuffer).
-     */
-    e820[nr].addr = RESERVED_MEMBASE;
-    e820[nr].size = (uint32_t)-e820[nr].addr;
-    e820[nr].type = E820_RESERVED;
-    nr++;
-
-    if ( hvm_info->high_mem_pgend )
-    {
-        e820[nr].addr = ((uint64_t)1 << 32);
-        e820[nr].size =
-            ((uint64_t)hvm_info->high_mem_pgend << PAGE_SHIFT) - e820[nr].addr;
-        e820[nr].type = E820_RAM;
-        nr++;
-    }
-
-    *E820_NR = nr;
-}
-
 int main(void)
 {
     int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0;
@@ -802,8 +682,8 @@ int main(void)
                ROMBIOS_PHYSICAL_ADDRESS,
                ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1);
 
-    build_e820_table();
-    dump_e820_table();
+    *E820_NR = build_e820_table(E820);
+    dump_e820_table(E820, *E820_NR);
 
     bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_ADDRESS;
     memset(bios_info, 0, sizeof(*bios_info));
index 4718e1987fe074f266b258a6d7e653bcc85d80b0..9c102a5571e7d8e45ce646a9a68298bf36779989 100644 (file)
@@ -26,7 +26,6 @@
 #include "smbios_types.h"
 #include "util.h"
 #include "hypercall.h"
-#include "e820.h"
 
 static int
 write_smbios_tables(void *start,
index c58ea1071af3f3b19b435e104732a860bec50c1d..25c5f7a0407658ca2711b7e79ed676fe467459b2 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "util.h"
 #include "config.h"
-#include "e820.h"
 #include "hypercall.h"
 #include <stdint.h>
 #include <xen/xen.h>
index e2d7e01e965d1d103910f8025e87689f8343800e..313070a298711ee60e9bc2a01f2c17fa0f7247a5 100644 (file)
@@ -189,6 +189,10 @@ void create_mp_tables(void);
 int hvm_write_smbios_tables(void);
 void smp_initialise(void);
 
+#include "e820.h"
+int build_e820_table(struct e820entry *e820);
+void dump_e820_table(struct e820entry *e820, unsigned int nr);
+
 #ifndef NDEBUG
 void perform_tests(void);
 #else
index 3b2c5350bef18aa85eace7d1a45c7e2f7d8e616f..de7c3ca4054f2b3c92b479eedfc2eb8af45cc714 100644 (file)
@@ -66,7 +66,7 @@
 #include <stdint.h>
 #include <stddef.h>
 #include "config.h"
-#include <../hvmloader/e820.h>
+#include "e820.h"
 #include "util.h"
 
 #define DEBUG_PMM 0
index 4b501791a52c31341b6d6773cee1b6bd80824c94..12a2f91948841c6018ca74bcb5ffd75570f91db8 100644 (file)
@@ -18,6 +18,9 @@
 #define E820_NR_OFFSET                0x0
 #define E820_OFFSET                   0x8
 
+#define E820_NR ((uint16_t *)(E820_PHYSICAL_ADDRESS + E820_NR_OFFSET))
+#define E820    ((struct e820entry *)(E820_PHYSICAL_ADDRESS + E820_OFFSET))
+
 /* Xen Platform Device */
 #define XEN_PF_IOBASE   0x10
 #define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
diff --git a/tools/firmware/rombios/e820.h b/tools/firmware/rombios/e820.h
new file mode 100644 (file)
index 0000000..570c17e
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __ROMBIOS_E820_H__
+#define __ROMBIOS_E820_H__
+
+/*
+ * PC BIOS standard E820 types and structure.
+ */
+#define E820_RAM          1
+#define E820_RESERVED     2
+#define E820_ACPI         3
+#define E820_NVS          4
+
+struct e820entry {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t type;
+} __attribute__((packed));
+
+#endif /* __ROMBIOS_E820_H__ */