Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 1 | /* |
| 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 Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <multiboot_tables.h> |
| 17 | #include "coreinfo.h" |
| 18 | |
Stefan Reinauer | 04fb7a8 | 2015-06-29 16:08:39 -0700 | [diff] [blame] | 19 | #if IS_ENABLED(CONFIG_MODULE_MULTIBOOT) |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 20 | |
| 21 | #define MAX_MEMORY_COUNT 10 |
| 22 | |
| 23 | static 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 | |
| 33 | static int tables_good = 0; |
| 34 | |
| 35 | int 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 | |
| 65 | static void parse_memory(struct multiboot_header *table) |
| 66 | { |
Edward O'Callaghan | 26c74fb | 2014-05-14 04:13:16 +1000 | [diff] [blame] | 67 | u8 *start = (u8 *) phys_to_virt(table->mmap_addr); |
| 68 | u8 *ptr = start; |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 69 | int i = 0; |
| 70 | |
| 71 | cb_info.mem_count = 0; |
| 72 | |
Edward O'Callaghan | 26c74fb | 2014-05-14 04:13:16 +1000 | [diff] [blame] | 73 | while(ptr < (start + table->mmap_length)) { |
| 74 | struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr; |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 75 | |
| 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'Callaghan | 26c74fb | 2014-05-14 04:13:16 +1000 | [diff] [blame] | 83 | ptr += (mmap->size + sizeof(mmap->size)); |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 84 | i++; |
Edward O'Callaghan | 26c74fb | 2014-05-14 04:13:16 +1000 | [diff] [blame] | 85 | } |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static 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 | |
| 96 | static 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 | |
| 106 | struct coreinfo_module multiboot_module = { |
| 107 | .name = "Multiboot", |
| 108 | .init = multiboot_module_init, |
| 109 | .redraw = multiboot_module_redraw, |
| 110 | }; |
| 111 | |
| 112 | #else |
| 113 | |
| 114 | struct coreinfo_module multiboot_module = { |
| 115 | }; |
| 116 | |
Edward O'Callaghan | 26c74fb | 2014-05-14 04:13:16 +1000 | [diff] [blame] | 117 | #endif /* CONFIG_MODULE_MULTIBOOT */ |