summaryrefslogtreecommitdiff
path: root/payloads/libpayload/arch
diff options
context:
space:
mode:
authorMathias Krause <minipli@googlemail.com>2017-02-12 13:50:48 +0100
committerMartin Roth <martinroth@google.com>2017-02-17 18:20:38 +0100
commit898de6111ad79519afe04794df8e09c41500807d (patch)
tree393e24abc03a0b7b62332c8ac18a73fe67655f4c /payloads/libpayload/arch
parent2b194d97411bd86303e0fec3a2edae2a718466bc (diff)
libpayload: multiboot - support meminfo flag
Some simple implementation of the MultiBoot protocol may not pass a memory map (MULTIBOOT_FLAGS_MMAP missing in the flags) but just the two values for low and high memory, indicated by the MULTIBOOT_FLAGS_MEMINFO flag. Support those kind of boot loaders too, instead of falling back to the hard-coded values in lib_get_sysinfo(). Tested with a multiboot enhanced version of FILO. Change-Id: I22cf9e3ec0075aff040390bd177c5cd22d439b81 Signed-off-by: Mathias Krause <minipli@googlemail.com> Reviewed-on: https://review.coreboot.org/18350 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'payloads/libpayload/arch')
-rw-r--r--payloads/libpayload/arch/x86/multiboot.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/payloads/libpayload/arch/x86/multiboot.c b/payloads/libpayload/arch/x86/multiboot.c
index 5fff453c8d..1cd0295c47 100644
--- a/payloads/libpayload/arch/x86/multiboot.c
+++ b/payloads/libpayload/arch/x86/multiboot.c
@@ -34,8 +34,28 @@
extern unsigned long loader_eax;
extern unsigned long loader_ebx;
+static int mb_add_memrange(struct sysinfo_t *info, unsigned long long base,
+ unsigned long long size, unsigned int type)
+{
+ if (info->n_memranges >= SYSINFO_MAX_MEM_RANGES)
+ return -1;
+
+#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY)
+ /* 1 == normal RAM. Ignore everything else for now */
+ if (type != 1)
+ return 0;
+#endif
+
+ info->memrange[info->n_memranges].base = base;
+ info->memrange[info->n_memranges].size = size;
+ info->memrange[info->n_memranges].type = type;
+ info->n_memranges++;
+
+ return 0;
+}
+
static void mb_parse_mmap(struct multiboot_header *table,
- struct sysinfo_t *info)
+ struct sysinfo_t *info)
{
u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
u8 *ptr = start;
@@ -45,25 +65,28 @@ static void mb_parse_mmap(struct multiboot_header *table,
while(ptr < (start + table->mmap_length)) {
struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
-#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY)
- /* 1 == normal RAM. Ignore everything else for now */
-
- if (mmap->type == 1) {
-#endif
- info->memrange[info->n_memranges].base = mmap->addr;
- info->memrange[info->n_memranges].size = mmap->length;
- info->memrange[info->n_memranges].type = mmap->type;
-
- if (++info->n_memranges == SYSINFO_MAX_MEM_RANGES)
- return;
-#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY)
- }
-#endif
+ if (mb_add_memrange(info, mmap->addr, mmap->length, mmap->type))
+ return;
ptr += (mmap->size + sizeof(mmap->size));
}
}
+static void mb_parse_meminfo(struct multiboot_header *table,
+ struct sysinfo_t *info)
+{
+ unsigned long long mem_low = table->mem_lower;
+ unsigned long long mem_high = table->mem_higher;
+
+ info->n_memranges = 0;
+
+ if (mem_low)
+ mb_add_memrange(info, 0 * MiB, mem_low * KiB, 1);
+
+ if (mem_high)
+ mb_add_memrange(info, 1 * MiB, mem_high * KiB, 1);
+}
+
static void mb_parse_cmdline(struct multiboot_header *table)
{
extern int main_argc;
@@ -95,6 +118,8 @@ int get_multiboot_info(struct sysinfo_t *info)
if (table->flags & MULTIBOOT_FLAGS_MMAP)
mb_parse_mmap(table, info);
+ else if (table->flags & MULTIBOOT_FLAGS_MEMINFO)
+ mb_parse_meminfo(table, info);
if (table->flags & MULTIBOOT_FLAGS_CMDLINE)
mb_parse_cmdline(table);