From 898de6111ad79519afe04794df8e09c41500807d Mon Sep 17 00:00:00 2001 From: Mathias Krause Date: Sun, 12 Feb 2017 13:50:48 +0100 Subject: 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 Reviewed-on: https://review.coreboot.org/18350 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- payloads/libpayload/arch/x86/multiboot.c | 55 +++++++++++++++++++------- payloads/libpayload/include/multiboot_tables.h | 1 + 2 files changed, 41 insertions(+), 15 deletions(-) (limited to 'payloads') 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); diff --git a/payloads/libpayload/include/multiboot_tables.h b/payloads/libpayload/include/multiboot_tables.h index ac27f8a766..3b42675071 100644 --- a/payloads/libpayload/include/multiboot_tables.h +++ b/payloads/libpayload/include/multiboot_tables.h @@ -35,6 +35,7 @@ #define MULTIBOOT_MAGIC 0x2BADB002UL #define MULTIBOOT_FLAGS_MMAP (1 << 6) #define MULTIBOOT_FLAGS_CMDLINE (1 << 2) +#define MULTIBOOT_FLAGS_MEMINFO (1 << 0) struct multiboot_header { u32 flags; u32 mem_lower; -- cgit v1.2.3