blob: 164049dc2973fe0feb9cb1fbd6313f2d397be60d [file] [log] [blame]
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +00001/*
2 * This file is part of the coreinfo project.
3 *
4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <multiboot_tables.h>
21#include "coreinfo.h"
22
23#ifdef CONFIG_MODULE_MULTIBOOT
24
25#define MAX_MEMORY_COUNT 10
26
27static struct {
28 int mem_count;
29
30 struct {
31 u64 start;
32 u64 size;
33 int type;
34 } range[MAX_MEMORY_COUNT];
35} cb_info;
36
37static int tables_good = 0;
38
39int multiboot_module_redraw(WINDOW *win)
40{
41 int row = 2;
42 int i;
43
44 print_module_title(win, "Multiboot Tables");
45
46 if (tables_good == 0) {
47 mvwprintw(win, row++, 1, "No multiboot tables were found");
48 return 0;
49 }
50
51 row++;
52 mvwprintw(win, row++, 1, "-- Memory Map --");
53
54 for (i = 0; i < cb_info.mem_count; i++) {
55
56 if (cb_info.range[i].type == 1)
57 mvwprintw(win, row++, 3, " RAM: ");
58 else
59 mvwprintw(win, row++, 3, "Reserved: ");
60
61 wprintw(win, "%16.16llx - %16.16llx",
62 cb_info.range[i].start,
63 cb_info.range[i].start + cb_info.range[i].size - 1);
64 }
65
66 return 0;
67}
68
69static void parse_memory(struct multiboot_header *table)
70{
71 u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
72 u8 *ptr = start;
73 int i = 0;
74
75 cb_info.mem_count = 0;
76
77 while(ptr < (start + table->mmap_length)) {
78 struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
79
80 cb_info.range[i].start = mmap->addr;
81 cb_info.range[i].size = mmap->length;
82 cb_info.range[i].type = mmap->type;
83
84 if (++cb_info.mem_count == MAX_MEMORY_COUNT)
85 return;
86
87 ptr += (mmap->size + sizeof(mmap->size));
88 i++;
89 }
90}
91
92static void parse_header(unsigned long addr)
93{
94 struct multiboot_header *table = (struct multiboot_header *) addr;
95
96 if (table->flags & MULTIBOOT_FLAGS_MMAP)
97 parse_memory(table);
98}
99
100static int multiboot_module_init(void)
101{
102 unsigned long mbaddr;
103 tables_good = sysinfo_have_multiboot(&mbaddr);
104
105 parse_header(mbaddr);
106
107 return tables_good ? 0 : -1;
108}
109
110struct coreinfo_module multiboot_module = {
111 .name = "Multiboot",
112 .init = multiboot_module_init,
113 .redraw = multiboot_module_redraw,
114};
115
116#else
117
118struct coreinfo_module multiboot_module = {
119};
120
121#endif