2 * support for Multiboot payloads
4 * Copyright (C) 2008 Robert Millan
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <cpu/x86/multiboot.h>
23 #include <device/resource.h>
24 #include <console/console.h>
25 #include <boot/coreboot_tables.h>
26 #include <arch/coreboot_tables.h>
28 struct multiboot_info *mbi = NULL;
30 unsigned long write_multiboot_info(unsigned long rom_table_end)
32 static struct multiboot_mmap_entry *mb_mem;
33 struct lb_memory* coreboot_table;
37 mbi = (struct multiboot_info *)rom_table_end;
39 memset(mbi, 0, sizeof(*mbi));
40 rom_table_end += sizeof(*mbi);
42 mbi->mmap_addr = (u32) rom_table_end;
43 mb_mem = (struct multiboot_mmap_entry *)rom_table_end;
45 /* copy regions from coreboot tables */
46 coreboot_table = get_lb_mem();
47 entries = (coreboot_table->size - sizeof(*coreboot_table))/sizeof(coreboot_table->map[0]);
49 if (coreboot_table == NULL || entries < 1) {
50 printk(BIOS_INFO, "%s: Cannot find coreboot table.\n", __func__);
51 return (unsigned long) mb_mem;
54 for (i = 0; i < entries; i++) {
55 uint64_t entry_start = unpack_lb64(coreboot_table->map[i].start);
56 uint64_t entry_size = unpack_lb64(coreboot_table->map[i].size);
57 mb_mem->addr = entry_start;
58 mb_mem->len = entry_size;
59 switch (coreboot_table->map[i].type) {
61 mb_mem->type = MULTIBOOT_MEMORY_AVAILABLE;
63 default: // anything other than usable RAM
64 mb_mem->type = MULTIBOOT_MEMORY_RESERVED;
67 mb_mem->size = sizeof(*mb_mem) - sizeof(mb_mem->size);
71 mbi->mmap_length = ((u32) mb_mem) - mbi->mmap_addr;
72 mbi->flags |= MB_INFO_MEM_MAP;
74 printk(BIOS_INFO, "Multiboot Information structure has been written.\n");
76 return (unsigned long)mb_mem;