Two hda_verb.h files: Add more comments.
[coreboot.git] / src / arch / i386 / boot / multiboot.c
1 /*
2  * support for Multiboot payloads
3  *
4  * Copyright (C) 2008 Robert Millan
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  */
20
21 #include <cpu/x86/multiboot.h>
22 #include <string.h>
23 #include <device/resource.h>
24 #include <console/console.h>
25 #include <boot/coreboot_tables.h>
26 #include <arch/coreboot_tables.h>
27
28 struct multiboot_info *mbi = NULL;
29
30 unsigned long write_multiboot_info(unsigned long rom_table_end)
31 {
32         static struct multiboot_mmap_entry *mb_mem;
33         struct lb_memory* coreboot_table;
34         int entries;
35         int i;
36
37         mbi = (struct multiboot_info *)rom_table_end;
38
39         memset(mbi, 0, sizeof(*mbi));
40         rom_table_end += sizeof(*mbi);
41
42         mbi->mmap_addr = (u32) rom_table_end;
43         mb_mem = (struct multiboot_mmap_entry *)rom_table_end;
44
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]);
48
49         if (coreboot_table == NULL || entries < 1) {
50             printk(BIOS_INFO, "%s: Cannot find coreboot table.\n", __func__);
51             return (unsigned long) mb_mem;
52         }
53
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) {
60             case LB_MEM_RAM:
61               mb_mem->type = MULTIBOOT_MEMORY_AVAILABLE;
62               break;
63             default: // anything other than usable RAM
64               mb_mem->type = MULTIBOOT_MEMORY_RESERVED;
65               break;
66           }
67           mb_mem->size = sizeof(*mb_mem) - sizeof(mb_mem->size);
68           mb_mem++;
69         }
70
71         mbi->mmap_length = ((u32) mb_mem) - mbi->mmap_addr;
72         mbi->flags |= MB_INFO_MEM_MAP;
73
74         printk(BIOS_INFO, "Multiboot Information structure has been written.\n");
75
76         return (unsigned long)mb_mem;
77 }