[SeaBIOS] [PATCH 02/15] e820: Rename memmap.c to e820map.c and use consistent "e820_" prefix

Kevin O'Connor kevin at koconnor.net
Thu Oct 1 04:01:22 CET 2015


Rename memmap.c to e820map.c as the code in that file only deals with
maintaining the e820 map.  Move all the e820 definitions to new file
e820map.h and use a consistent "e820_" prefix on all exported
functions.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 Makefile                    |  2 +-
 src/{memmap.c => e820map.c} |  8 ++++----
 src/{memmap.h => e820map.h} |  7 ++-----
 src/fw/coreboot.c           |  8 ++++----
 src/fw/csm.c                | 14 +++++++-------
 src/fw/paravirt.c           | 14 +++++++-------
 src/fw/pciinit.c            |  6 +++---
 src/fw/xen.c                |  9 +++++----
 src/hw/ramdisk.c            |  5 +++--
 src/malloc.c                | 11 ++++++-----
 src/memmap.h                | 28 +++-------------------------
 src/post.c                  |  6 +++---
 src/system.c                |  2 +-
 13 files changed, 49 insertions(+), 71 deletions(-)
 rename src/{memmap.c => e820map.c} (96%)
 copy src/{memmap.h => e820map.h} (77%)

diff --git a/Makefile b/Makefile
index 3a0d2e8..e5f28d4 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ SRCBOTH=misc.c stacks.c output.c string.c block.c cdrom.c disk.c mouse.c kbd.c \
     hw/blockcmd.c hw/floppy.c hw/ata.c hw/ramdisk.c \
     hw/lsi-scsi.c hw/esp-scsi.c hw/megasas.c
 SRC16=$(SRCBOTH)
-SRC32FLAT=$(SRCBOTH) post.c memmap.c malloc.c romfile.c x86.c optionroms.c \
+SRC32FLAT=$(SRCBOTH) post.c e820map.c malloc.c romfile.c x86.c optionroms.c \
     pmm.c font.c boot.c bootsplash.c jpeg.c bmp.c tcgbios.c sha1.c \
     hw/ahci.c hw/pvscsi.c hw/usb-xhci.c hw/usb-hub.c hw/sdcard.c \
     fw/coreboot.c fw/lzmadecode.c fw/multiboot.c fw/csm.c fw/biostables.c \
diff --git a/src/memmap.c b/src/e820map.c
similarity index 96%
rename from src/memmap.c
rename to src/e820map.c
index 8c0c38d..901ccdf 100644
--- a/src/memmap.c
+++ b/src/e820map.c
@@ -5,7 +5,7 @@
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
 #include "config.h" // BUILD_MAX_E820
-#include "memmap.h" // struct e820entry
+#include "e820map.h" // struct e820entry
 #include "output.h" // dprintf
 #include "string.h" // memmove
 
@@ -77,7 +77,7 @@ dump_map(void)
 // Add a new entry to the list.  This scans for overlaps and keeps the
 // list sorted.
 void
-add_e820(u64 start, u64 size, u32 type)
+e820_add(u64 start, u64 size, u32 type)
 {
     dprintf(8, "Add to e820 map: %08x %08x %d\n", (u32)start, (u32)size, type);
 
@@ -141,12 +141,12 @@ add_e820(u64 start, u64 size, u32 type)
 void
 e820_remove(u64 start, u64 size)
 {
-    add_e820(start, size, E820_HOLE);
+    e820_add(start, size, E820_HOLE);
 }
 
 // Report on final memory locations.
 void
-memmap_prepboot(void)
+e820_prepboot(void)
 {
     dump_map();
 }
diff --git a/src/memmap.h b/src/e820map.h
similarity index 77%
copy from src/memmap.h
copy to src/e820map.h
index e7d94ee..de8b523 100644
--- a/src/memmap.h
+++ b/src/e820map.h
@@ -15,12 +15,9 @@ struct e820entry {
     u32 type;
 };
 
-void add_e820(u64 start, u64 size, u32 type);
+void e820_add(u64 start, u64 size, u32 type);
 void e820_remove(u64 start, u64 size);
-void memmap_prepboot(void);
-
-// A typical OS page size
-#define PAGE_SIZE 4096
+void e820_prepboot(void);
 
 // e820 map storage
 extern struct e820entry e820_list[];
diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c
index b077fe1..a47f524 100644
--- a/src/fw/coreboot.c
+++ b/src/fw/coreboot.c
@@ -7,10 +7,10 @@
 #include "block.h" // MAXDESCSIZE
 #include "byteorder.h" // be32_to_cpu
 #include "config.h" // CONFIG_*
+#include "e820map.h" // e820_add
 #include "hw/pci.h" // pci_probe_devices
 #include "lzmadecode.h" // LzmaDecode
 #include "malloc.h" // free
-#include "memmap.h" // add_e820
 #include "output.h" // dprintf
 #include "paravirt.h" // PlatformRunningOn
 #include "romfile.h" // romfile_findprefix
@@ -184,12 +184,12 @@ coreboot_preinit(void)
         u32 type = m->type;
         if (type == CB_MEM_TABLE)
             type = E820_RESERVED;
-        add_e820(m->start, m->size, type);
+        e820_add(m->start, m->size, type);
     }
 
     // Ughh - coreboot likes to set a map at 0x0000-0x1000, but this
     // confuses grub.  So, override it.
-    add_e820(0, 16*1024, E820_RAM);
+    e820_add(0, 16*1024, E820_RAM);
 
     struct cb_cbmem_ref *cbref = find_cb_subtable(cbh, CB_TAG_CBMEM_CONSOLE);
     if (cbref) {
@@ -210,7 +210,7 @@ coreboot_preinit(void)
 fail:
     // No table found..  Use 16Megs as a dummy value.
     dprintf(1, "Unable to find coreboot table!\n");
-    add_e820(0, 16*1024*1024, E820_RAM);
+    e820_add(0, 16*1024*1024, E820_RAM);
     return;
 }
 
diff --git a/src/fw/csm.c b/src/fw/csm.c
index aee2f90..0467560 100644
--- a/src/fw/csm.c
+++ b/src/fw/csm.c
@@ -4,20 +4,20 @@
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
-#include "bregs.h"
+#include "bregs.h" // struct bregs
 #include "config.h" // CONFIG_*
+#include "e820map.h" // e820_add
 #include "farptr.h" // MAKE_FLATPTR
-#include "hw/pci.h"
-#include "hw/pic.h"
+#include "hw/pci.h" // pci_probe_devices
+#include "hw/pic.h" // pic_irqmask_read
 #include "malloc.h" // csm_malloc_preinit
-#include "memmap.h"
 #include "output.h" // dprintf
+#include "paravirt.h" // qemu_preinit
 #include "stacks.h" // wait_threads
 #include "std/acpi.h" // RSDP_SIGNATURE
 #include "std/bda.h" // struct bios_data_area_s
 #include "std/optionrom.h" // struct rom_header
 #include "util.h" // copy_smbios
-#include "paravirt.h" // qemu_preinit
 
 #define UINT8 u8
 #define UINT16 u16
@@ -147,11 +147,11 @@ handle_csm_0002(struct bregs *regs)
     struct e820entry *p = (void *)csm_compat_table.E820Pointer;
     int i;
     for (i=0; i < csm_compat_table.E820Length / sizeof(struct e820entry); i++)
-        add_e820(p[i].start, p[i].size, p[i].type);
+        e820_add(p[i].start, p[i].size, p[i].type);
 
     if (csm_init_table->HiPmmMemorySizeInBytes > BUILD_MAX_HIGHTABLE) {
         u32 hi_pmm_end = csm_init_table->HiPmmMemory + csm_init_table->HiPmmMemorySizeInBytes;
-        add_e820(hi_pmm_end - BUILD_MAX_HIGHTABLE, BUILD_MAX_HIGHTABLE, E820_RESERVED);
+        e820_add(hi_pmm_end - BUILD_MAX_HIGHTABLE, BUILD_MAX_HIGHTABLE, E820_RESERVED);
     }
 
     // For PCIBIOS 1ab10e
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c
index db22ae8..acb44b9 100644
--- a/src/fw/paravirt.c
+++ b/src/fw/paravirt.c
@@ -10,11 +10,11 @@
 
 #include "byteorder.h" // be32_to_cpu
 #include "config.h" // CONFIG_QEMU
+#include "e820map.h" // e820_add
 #include "hw/pci.h" // create_pirtable
 #include "hw/pci_regs.h" // PCI_DEVICE_ID
 #include "hw/rtc.h" // CMOS_*
 #include "malloc.h" // malloc_tmp
-#include "memmap.h" // add_e820
 #include "output.h" // dprintf
 #include "paravirt.h" // qemu_cfg_preinit
 #include "romfile.h" // romfile_loadint
@@ -114,10 +114,10 @@ qemu_preinit(void)
                | (rtc_read(CMOS_MEM_EXTMEM_HIGH) << 18))
               + 1 * 1024 * 1024);
     RamSize = rs;
-    add_e820(0, rs, E820_RAM);
+    e820_add(0, rs, E820_RAM);
 
     /* reserve 256KB BIOS area at the end of 4 GB */
-    add_e820(0xfffc0000, 256*1024, E820_RESERVED);
+    e820_add(0xfffc0000, 256*1024, E820_RESERVED);
 
     dprintf(1, "RamSize: 0x%08x [cmos]\n", RamSize);
 }
@@ -302,7 +302,7 @@ qemu_cfg_e820(void)
                 }
                 /* fall through */
             case E820_RESERVED:
-                add_e820(table[i].address, table[i].length, table[i].type);
+                e820_add(table[i].address, table[i].length, table[i].type);
                 break;
             default:
                 /*
@@ -324,13 +324,13 @@ qemu_cfg_e820(void)
         int i;
         for (i = 0; i < count32; i++) {
             qemu_cfg_read(&entry, sizeof(entry));
-            add_e820(entry.address, entry.length, entry.type);
+            e820_add(entry.address, entry.length, entry.type);
         }
     } else if (runningOnKVM()) {
         // Backwards compatibility - provide hard coded range.
         // 4 pages before the bios, 3 pages for vmx tss pages, the
         // other page for EPT real mode pagetable
-        add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+        e820_add(0xfffbc000, 4*4096, E820_RESERVED);
     }
 
     // Check for memory over 4Gig in cmos
@@ -338,7 +338,7 @@ qemu_cfg_e820(void)
                 | ((u32)rtc_read(CMOS_MEM_HIGHMEM_MID) << 24)
                 | ((u64)rtc_read(CMOS_MEM_HIGHMEM_HIGH) << 32));
     RamSizeOver4G = high;
-    add_e820(0x100000000ull, high, E820_RAM);
+    e820_add(0x100000000ull, high, E820_RAM);
     dprintf(1, "RamSizeOver4G: 0x%016llx [cmos]\n", RamSizeOver4G);
 }
 
diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index 3ad84ba..7b8aab7 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -9,13 +9,13 @@
 #include "config.h" // CONFIG_*
 #include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR
 #include "dev-piix.h" // PIIX_*
+#include "e820map.h" // e820_add
 #include "hw/ata.h" // PORT_ATA1_CMD_BASE
 #include "hw/pci.h" // pci_config_readl
 #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL
 #include "hw/pci_regs.h" // PCI_COMMAND
 #include "list.h" // struct hlist_node
 #include "malloc.h" // free
-#include "memmap.h" // add_e820
 #include "output.h" // dprintf
 #include "paravirt.h" // RamSize
 #include "romfile.h" // romfile_loadint
@@ -186,7 +186,7 @@ static void mch_isa_bridge_setup(struct pci_device *dev, void *arg)
     /* set root complex register block BAR */
     pci_config_writel(bdf, ICH9_LPC_RCBA,
                       ICH9_LPC_RCBA_ADDR | ICH9_LPC_RCBA_EN);
-    add_e820(ICH9_LPC_RCBA_ADDR, 16*1024, E820_RESERVED);
+    e820_add(ICH9_LPC_RCBA_ADDR, 16*1024, E820_RESERVED);
 
     acpi_pm1a_cnt = acpi_pm_base + 0x04;
     pmtimer_setup(acpi_pm_base + 0x08);
@@ -400,7 +400,7 @@ static void mch_mem_addr_setup(struct pci_device *dev, void *arg)
     pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR, 0);
     pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR + 4, upper);
     pci_config_writel(bdf, Q35_HOST_BRIDGE_PCIEXBAR, lower);
-    add_e820(addr, size, E820_RESERVED);
+    e820_add(addr, size, E820_RESERVED);
 
     /* setup pci i/o window (above mmconfig) */
     pcimem_start = addr + size;
diff --git a/src/fw/xen.c b/src/fw/xen.c
index dd8e8af..3f19ef2 100644
--- a/src/fw/xen.c
+++ b/src/fw/xen.c
@@ -4,16 +4,17 @@
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
-#include "config.h"
+#include "config.h" // CONFIG_XEN
+#include "e820map.h" // e820_add
 #include "hw/serialio.h" // DebugOutputPort
 #include "malloc.h" // memalign_high
-#include "memmap.h" // add_e820
+#include "memmap.h" // PAGE_SIZE
 #include "output.h" // dprintf
 #include "paravirt.h" // PlatformRunningOn
 #include "string.h" // memcpy
 #include "util.h" // copy_acpi_rsdp
 #include "x86.h" // cpuid
-#include "xen.h"
+#include "xen.h" // xen_extraversion_t
 
 #define INFO_PHYSICAL_ADDRESS 0x00001000
 
@@ -142,6 +143,6 @@ void xen_ramsize_preinit(void)
 
     for (i = 0; i < info->e820_nr; i++) {
         struct e820entry *e = &e820[i];
-        add_e820(e->start, e->size, e->type);
+        e820_add(e->start, e->size, e->type);
     }
 }
diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c
index 4cdf95f..adec1d1 100644
--- a/src/hw/ramdisk.c
+++ b/src/hw/ramdisk.c
@@ -7,8 +7,9 @@
 #include "biosvar.h" // GET_GLOBALFLAT
 #include "block.h" // struct drive_s
 #include "bregs.h" // struct bregs
+#include "e820map.h" // e820_add
 #include "malloc.h" // memalign_tmphigh
-#include "memmap.h" // add_e820
+#include "memmap.h" // PAGE_SIZE
 #include "output.h" // dprintf
 #include "romfile.h" // romfile_findprefix
 #include "stacks.h" // call16_int
@@ -41,7 +42,7 @@ ramdisk_setup(void)
         warn_noalloc();
         return;
     }
-    add_e820((u32)pos, size, E820_RESERVED);
+    e820_add((u32)pos, size, E820_RESERVED);
 
     // Copy image into ram.
     int ret = file->copy(file, pos, size);
diff --git a/src/malloc.c b/src/malloc.c
index 5c05a8a..efd09b3 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -6,9 +6,10 @@
 
 #include "biosvar.h" // GET_BDA
 #include "config.h" // BUILD_BIOS_ADDR
+#include "e820map.h" // struct e820entry
 #include "list.h" // hlist_node
 #include "malloc.h" // _malloc
-#include "memmap.h" // struct e820entry
+#include "memmap.h" // PAGE_SIZE
 #include "output.h" // dprintf
 #include "stacks.h" // wait_preempt
 #include "std/optionrom.h" // OPTION_ROM_ALIGN
@@ -399,7 +400,7 @@ malloc_preinit(void)
     e820_remove(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END);
 
     // Mark known areas as reserved.
-    add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
+    e820_add(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
     // Populate temp high ram
     u32 highram = 0;
@@ -427,7 +428,7 @@ malloc_preinit(void)
     if (highram) {
         addSpace(&ZoneHigh, (void*)highram
                  , (void*)highram + BUILD_MAX_HIGHTABLE);
-        add_e820(highram, BUILD_MAX_HIGHTABLE, E820_RESERVED);
+        e820_add(highram, BUILD_MAX_HIGHTABLE, E820_RESERVED);
     }
 }
 
@@ -521,7 +522,7 @@ malloc_prepboot(void)
 
     // Reserve more low-mem if needed.
     u32 endlow = GET_BDA(mem_size_kb)*1024;
-    add_e820(endlow, BUILD_LOWRAM_END-endlow, E820_RESERVED);
+    e820_add(endlow, BUILD_LOWRAM_END-endlow, E820_RESERVED);
 
     // Clear unused f-seg ram.
     struct allocinfo_s *info = findLast(&ZoneFSeg);
@@ -533,7 +534,7 @@ malloc_prepboot(void)
     info = findLast(&ZoneHigh);
     if (info) {
         u32 giveback = ALIGN_DOWN(info->allocend - info->dataend, PAGE_SIZE);
-        add_e820((u32)info->dataend, giveback, E820_RAM);
+        e820_add((u32)info->dataend, giveback, E820_RAM);
         dprintf(1, "Returned %d bytes of ZoneHigh\n", giveback);
     }
 
diff --git a/src/memmap.h b/src/memmap.h
index e7d94ee..c439982 100644
--- a/src/memmap.h
+++ b/src/memmap.h
@@ -1,29 +1,7 @@
-#ifndef __E820MAP_H
-#define __E820MAP_H
-
-#include "types.h" // u64
-
-#define E820_RAM          1
-#define E820_RESERVED     2
-#define E820_ACPI         3
-#define E820_NVS          4
-#define E820_UNUSABLE     5
-
-struct e820entry {
-    u64 start;
-    u64 size;
-    u32 type;
-};
-
-void add_e820(u64 start, u64 size, u32 type);
-void e820_remove(u64 start, u64 size);
-void memmap_prepboot(void);
+#ifndef __MEMMAP_H
+#define __MEMMAP_H
 
 // A typical OS page size
 #define PAGE_SIZE 4096
 
-// e820 map storage
-extern struct e820entry e820_list[];
-extern int e820_count;
-
-#endif // e820map.h
+#endif // memmap.h
diff --git a/src/post.c b/src/post.c
index e19b06c..89e6eff 100644
--- a/src/post.c
+++ b/src/post.c
@@ -8,6 +8,7 @@
 #include "biosvar.h" // SET_BDA
 #include "bregs.h" // struct bregs
 #include "config.h" // CONFIG_*
+#include "e820map.h" // e820_add
 #include "fw/paravirt.h" // qemu_cfg_preinit
 #include "fw/xen.h" // xen_preinit
 #include "hw/ahci.h" // ahci_setup
@@ -24,7 +25,6 @@
 #include "hw/virtio-blk.h" // virtio_blk_setup
 #include "hw/virtio-scsi.h" // virtio_scsi_setup
 #include "malloc.h" // malloc_init
-#include "memmap.h" // add_e820
 #include "output.h" // dprintf
 #include "string.h" // memset
 #include "util.h" // kbd_init
@@ -102,7 +102,7 @@ bda_init(void)
     memset(ebda, 0, sizeof(*ebda));
     ebda->size = esize;
 
-    add_e820((u32)ebda, BUILD_LOWRAM_END-(u32)ebda, E820_RESERVED);
+    e820_add((u32)ebda, BUILD_LOWRAM_END-(u32)ebda, E820_RESERVED);
 
     // Init extra stack
     StackPos = (void*)(&ExtraStack[BUILD_EXTRA_STACK_SIZE] - zonelow_base);
@@ -191,7 +191,7 @@ prepareboot(void)
     cdrom_prepboot();
     pmm_prepboot();
     malloc_prepboot();
-    memmap_prepboot();
+    e820_prepboot();
 
     HaveRunPost = 2;
 
diff --git a/src/system.c b/src/system.c
index 60a6fce..438e60e 100644
--- a/src/system.c
+++ b/src/system.c
@@ -7,9 +7,9 @@
 
 #include "biosvar.h" // GET_GLOBAL
 #include "bregs.h" // struct bregs
+#include "e820map.h" // E820_RAM
 #include "hw/pic.h" // pic_reset
 #include "malloc.h" // LegacyRamSize
-#include "memmap.h" // E820_RAM
 #include "output.h" // debug_enter
 #include "string.h" // memcpy_far
 #include "util.h" // handle_1553
-- 
2.4.3




More information about the SeaBIOS mailing list