blob: 2fc60fabd49fa8c2e03f0e343c92aedf0d0b8b2a [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.
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000014 */
15
16#include <multiboot_tables.h>
17#include "coreinfo.h"
18
Stefan Reinauer04fb7a82015-06-29 16:08:39 -070019#if IS_ENABLED(CONFIG_MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000020
21#define MAX_MEMORY_COUNT 10
22
23static struct {
24 int mem_count;
25
26 struct {
27 u64 start;
28 u64 size;
29 int type;
30 } range[MAX_MEMORY_COUNT];
31} cb_info;
32
33static int tables_good = 0;
34
35int multiboot_module_redraw(WINDOW *win)
36{
37 int row = 2;
38 int i;
39
40 print_module_title(win, "Multiboot Tables");
41
42 if (tables_good == 0) {
43 mvwprintw(win, row++, 1, "No multiboot tables were found");
44 return 0;
45 }
46
47 row++;
48 mvwprintw(win, row++, 1, "-- Memory Map --");
49
50 for (i = 0; i < cb_info.mem_count; i++) {
51
52 if (cb_info.range[i].type == 1)
53 mvwprintw(win, row++, 3, " RAM: ");
54 else
55 mvwprintw(win, row++, 3, "Reserved: ");
56
57 wprintw(win, "%16.16llx - %16.16llx",
58 cb_info.range[i].start,
59 cb_info.range[i].start + cb_info.range[i].size - 1);
60 }
61
62 return 0;
63}
64
65static void parse_memory(struct multiboot_header *table)
66{
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100067 u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
68 u8 *ptr = start;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000069 int i = 0;
70
71 cb_info.mem_count = 0;
72
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100073 while(ptr < (start + table->mmap_length)) {
74 struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000075
76 cb_info.range[i].start = mmap->addr;
77 cb_info.range[i].size = mmap->length;
78 cb_info.range[i].type = mmap->type;
79
80 if (++cb_info.mem_count == MAX_MEMORY_COUNT)
81 return;
82
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100083 ptr += (mmap->size + sizeof(mmap->size));
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000084 i++;
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +100085 }
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000086}
87
88static void parse_header(unsigned long addr)
89{
90 struct multiboot_header *table = (struct multiboot_header *) addr;
91
92 if (table->flags & MULTIBOOT_FLAGS_MMAP)
93 parse_memory(table);
94}
95
96static int multiboot_module_init(void)
97{
98 unsigned long mbaddr;
99 tables_good = sysinfo_have_multiboot(&mbaddr);
100
101 parse_header(mbaddr);
102
103 return tables_good ? 0 : -1;
104}
105
106struct coreinfo_module multiboot_module = {
107 .name = "Multiboot",
108 .init = multiboot_module_init,
109 .redraw = multiboot_module_redraw,
110};
111
112#else
113
114struct coreinfo_module multiboot_module = {
115};
116
Edward O'Callaghan26c74fb2014-05-14 04:13:16 +1000117#endif /* CONFIG_MODULE_MULTIBOOT */