soc/intel/xeon_sp: Align resources to 4K
[coreboot2.git] / payloads / coreinfo / multiboot_module.c
blob2ec9929b600838e397ff7d9683c34f2583ddaf53
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <multiboot_tables.h>
4 #include "coreinfo.h"
6 #if CONFIG(MODULE_MULTIBOOT)
8 #define MAX_MEMORY_COUNT 10
10 static struct {
11 int mem_count;
13 struct {
14 u64 start;
15 u64 size;
16 int type;
17 } range[MAX_MEMORY_COUNT];
18 } cb_info;
20 static int tables_good = 0;
22 static int multiboot_module_redraw(WINDOW *win)
24 int row = 2;
25 int i;
27 print_module_title(win, "Multiboot Tables");
29 if (tables_good == 0) {
30 mvwprintw(win, row++, 1, "No multiboot tables were found");
31 return 0;
34 row++;
35 mvwprintw(win, row++, 1, "-- Memory Map --");
37 for (i = 0; i < cb_info.mem_count; i++) {
39 if (cb_info.range[i].type == 1)
40 mvwprintw(win, row++, 3, " RAM: ");
41 else
42 mvwprintw(win, row++, 3, "Reserved: ");
44 wprintw(win, "%16.16llx - %16.16llx",
45 cb_info.range[i].start,
46 cb_info.range[i].start + cb_info.range[i].size - 1);
49 return 0;
52 static void parse_memory(struct multiboot_header *table)
54 u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
55 u8 *ptr = start;
56 int i = 0;
58 cb_info.mem_count = 0;
60 while(ptr < (start + table->mmap_length)) {
61 struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
63 cb_info.range[i].start = mmap->addr;
64 cb_info.range[i].size = mmap->length;
65 cb_info.range[i].type = mmap->type;
67 if (++cb_info.mem_count == MAX_MEMORY_COUNT)
68 return;
70 ptr += (mmap->size + sizeof(mmap->size));
71 i++;
75 static void parse_header(unsigned long addr)
77 struct multiboot_header *table = (struct multiboot_header *) addr;
79 if (table->flags & MULTIBOOT_FLAGS_MMAP)
80 parse_memory(table);
83 static int multiboot_module_init(void)
85 unsigned long mbaddr;
86 tables_good = sysinfo_have_multiboot(&mbaddr);
88 parse_header(mbaddr);
90 return tables_good ? 0 : -1;
93 struct coreinfo_module multiboot_module = {
94 .name = "Multiboot",
95 .init = multiboot_module_init,
96 .redraw = multiboot_module_redraw,
99 #else
101 struct coreinfo_module multiboot_module = {
104 #endif /* CONFIG_MODULE_MULTIBOOT */