blob: 2ec9929b600838e397ff7d9683c34f2583ddaf53 [file] [log] [blame]
Jacob Garber07201d72020-09-08 12:25:44 -06001/* SPDX-License-Identifier: GPL-2.0-only */
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +00002
3#include <multiboot_tables.h>
4#include "coreinfo.h"
5
Julius Wernereab2a292019-03-05 16:55:15 -08006#if CONFIG(MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +00007
8#define MAX_MEMORY_COUNT 10
9
10static struct {
11 int mem_count;
12
13 struct {
14 u64 start;
15 u64 size;
16 int type;
17 } range[MAX_MEMORY_COUNT];
18} cb_info;
19
20static int tables_good = 0;
21
Jacob Garber609305f2019-06-28 11:03:31 -060022static int multiboot_module_redraw(WINDOW *win)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000023{
24 int row = 2;
25 int i;
26
27 print_module_title(win, "Multiboot Tables");
28
29 if (tables_good == 0) {
30 mvwprintw(win, row++, 1, "No multiboot tables were found");
31 return 0;
32 }
33
34 row++;
35 mvwprintw(win, row++, 1, "-- Memory Map --");
36
37 for (i = 0; i < cb_info.mem_count; i++) {
38
39 if (cb_info.range[i].type == 1)
40 mvwprintw(win, row++, 3, " RAM: ");
41 else
42 mvwprintw(win, row++, 3, "Reserved: ");
43
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);
47 }
48
49 return 0;
50}
51
52static void parse_memory(struct multiboot_header *table)
53{
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100054 u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
55 u8 *ptr = start;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000056 int i = 0;
57
58 cb_info.mem_count = 0;
59
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100060 while(ptr < (start + table->mmap_length)) {
61 struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000062
63 cb_info.range[i].start = mmap->addr;
64 cb_info.range[i].size = mmap->length;
65 cb_info.range[i].type = mmap->type;
66
67 if (++cb_info.mem_count == MAX_MEMORY_COUNT)
68 return;
69
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100070 ptr += (mmap->size + sizeof(mmap->size));
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000071 i++;
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100072 }
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000073}
74
75static void parse_header(unsigned long addr)
76{
77 struct multiboot_header *table = (struct multiboot_header *) addr;
78
79 if (table->flags & MULTIBOOT_FLAGS_MMAP)
80 parse_memory(table);
81}
82
83static int multiboot_module_init(void)
84{
85 unsigned long mbaddr;
86 tables_good = sysinfo_have_multiboot(&mbaddr);
87
88 parse_header(mbaddr);
89
90 return tables_good ? 0 : -1;
91}
92
93struct coreinfo_module multiboot_module = {
94 .name = "Multiboot",
95 .init = multiboot_module_init,
96 .redraw = multiboot_module_redraw,
97};
98
99#else
100
101struct coreinfo_module multiboot_module = {
102};
103
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +1000104#endif /* CONFIG_MODULE_MULTIBOOT */