blob: dd5ce366fb7473ffb78f4cdc51358d72b94f2cf9 [file] [log] [blame]
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +00001/*
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +00002 *
3 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000013 */
14
15#include <multiboot_tables.h>
16#include "coreinfo.h"
17
Julius Wernereab2a292019-03-05 16:55:15 -080018#if CONFIG(MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000019
20#define MAX_MEMORY_COUNT 10
21
22static struct {
23 int mem_count;
24
25 struct {
26 u64 start;
27 u64 size;
28 int type;
29 } range[MAX_MEMORY_COUNT];
30} cb_info;
31
32static int tables_good = 0;
33
Jacob Garber609305f2019-06-28 11:03:31 -060034static int multiboot_module_redraw(WINDOW *win)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000035{
36 int row = 2;
37 int i;
38
39 print_module_title(win, "Multiboot Tables");
40
41 if (tables_good == 0) {
42 mvwprintw(win, row++, 1, "No multiboot tables were found");
43 return 0;
44 }
45
46 row++;
47 mvwprintw(win, row++, 1, "-- Memory Map --");
48
49 for (i = 0; i < cb_info.mem_count; i++) {
50
51 if (cb_info.range[i].type == 1)
52 mvwprintw(win, row++, 3, " RAM: ");
53 else
54 mvwprintw(win, row++, 3, "Reserved: ");
55
56 wprintw(win, "%16.16llx - %16.16llx",
57 cb_info.range[i].start,
58 cb_info.range[i].start + cb_info.range[i].size - 1);
59 }
60
61 return 0;
62}
63
64static void parse_memory(struct multiboot_header *table)
65{
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100066 u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
67 u8 *ptr = start;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000068 int i = 0;
69
70 cb_info.mem_count = 0;
71
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100072 while(ptr < (start + table->mmap_length)) {
73 struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000074
75 cb_info.range[i].start = mmap->addr;
76 cb_info.range[i].size = mmap->length;
77 cb_info.range[i].type = mmap->type;
78
79 if (++cb_info.mem_count == MAX_MEMORY_COUNT)
80 return;
81
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100082 ptr += (mmap->size + sizeof(mmap->size));
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000083 i++;
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100084 }
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000085}
86
87static void parse_header(unsigned long addr)
88{
89 struct multiboot_header *table = (struct multiboot_header *) addr;
90
91 if (table->flags & MULTIBOOT_FLAGS_MMAP)
92 parse_memory(table);
93}
94
95static int multiboot_module_init(void)
96{
97 unsigned long mbaddr;
98 tables_good = sysinfo_have_multiboot(&mbaddr);
99
100 parse_header(mbaddr);
101
102 return tables_good ? 0 : -1;
103}
104
105struct coreinfo_module multiboot_module = {
106 .name = "Multiboot",
107 .init = multiboot_module_init,
108 .redraw = multiboot_module_redraw,
109};
110
111#else
112
113struct coreinfo_module multiboot_module = {
114};
115
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +1000116#endif /* CONFIG_MODULE_MULTIBOOT */