Jacob Garber | 07201d7 | 2020-09-08 12:25:44 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 2 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 3 | #include "coreinfo.h" |
Philip Prindeville | fe2f6b0 | 2011-12-23 17:22:05 -0700 | [diff] [blame] | 4 | #include <coreboot_tables.h> |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 5 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 6 | #if CONFIG(MODULE_COREBOOT) |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 7 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 8 | #define MAX_MEMORY_COUNT 5 |
| 9 | |
| 10 | static struct { |
| 11 | int mem_count; |
| 12 | int mem_actual; |
| 13 | |
| 14 | struct cb_memory_range range[MAX_MEMORY_COUNT]; |
| 15 | |
| 16 | char vendor[32]; |
| 17 | char part[32]; |
| 18 | |
| 19 | char strings[10][64]; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 20 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 21 | struct cb_serial serial; |
| 22 | struct cb_console console; |
| 23 | } cb_info; |
| 24 | |
| 25 | static int tables_good = 0; |
| 26 | |
Jacob Garber | 609305f | 2019-06-28 11:03:31 -0600 | [diff] [blame] | 27 | static int coreboot_module_redraw(WINDOW *win) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 28 | { |
| 29 | int row = 2; |
| 30 | int i; |
| 31 | |
Martin Roth | e81ce04 | 2017-06-03 20:00:36 -0600 | [diff] [blame] | 32 | print_module_title(win, "coreboot Tables"); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 33 | |
| 34 | if (tables_good) { |
Martin Roth | e81ce04 | 2017-06-03 20:00:36 -0600 | [diff] [blame] | 35 | mvwprintw(win, row++, 1, "No coreboot tables were found"); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 36 | return 0; |
| 37 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 38 | |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 39 | mvwprintw(win, row++, 1, "Vendor: %s", cb_info.vendor); |
| 40 | mvwprintw(win, row++, 1, "Part: %s", cb_info.part); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 41 | |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 42 | mvwprintw(win, row++, 1, "Version: %s%s", |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 43 | cb_info.strings[CB_TAG_VERSION - 0x4], |
| 44 | cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 45 | |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 46 | mvwprintw(win, row++, 1, "Built: %s (%s@%s.%s)", |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 47 | cb_info.strings[CB_TAG_BUILD - 0x4], |
| 48 | cb_info.strings[CB_TAG_COMPILE_BY - 0x04], |
| 49 | cb_info.strings[CB_TAG_COMPILE_HOST - 0x04], |
| 50 | cb_info.strings[CB_TAG_COMPILE_DOMAIN - 0x04]); |
| 51 | |
| 52 | if (cb_info.serial.tag != 0x0) { |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 53 | mvwprintw(win, row++, 1, "Serial Port I/O base: 0x%x", |
QingPei Wang | 45945cf | 2011-11-22 15:24:12 +0800 | [diff] [blame] | 54 | cb_info.serial.baseaddr); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | if (cb_info.console.tag != 0x0) { |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 58 | mvwprintw(win, row++, 1, "Default Output Console: "); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 59 | |
| 60 | switch (cb_info.console.type) { |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 61 | case CB_TAG_CONSOLE_SERIAL8250: |
| 62 | wprintw(win, "Serial Port"); |
| 63 | break; |
| 64 | case CB_TAG_CONSOLE_VGA: |
| 65 | wprintw(win, "VGA"); |
| 66 | break; |
| 67 | case CB_TAG_CONSOLE_BTEXT: |
| 68 | wprintw(win, "BTEXT"); |
| 69 | break; |
| 70 | case CB_TAG_CONSOLE_LOGBUF: |
| 71 | wprintw(win, "Log Buffer"); |
| 72 | break; |
| 73 | case CB_TAG_CONSOLE_SROM: |
| 74 | wprintw(win, "Serial ROM"); |
| 75 | break; |
| 76 | case CB_TAG_CONSOLE_EHCI: |
| 77 | wprintw(win, "USB Debug"); |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | row++; |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 83 | mvwprintw(win, row++, 1, "-- Memory Map --"); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 84 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 85 | for (i = 0; i < cb_info.mem_count; i++) { |
| 86 | switch (cb_info.range[i].type) { |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 87 | case CB_MEM_RAM: |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 88 | mvwprintw(win, row++, 3, " RAM: "); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 89 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 90 | case CB_MEM_RESERVED: |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 91 | mvwprintw(win, row++, 3, "Reserved: "); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 92 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 93 | case CB_MEM_TABLE: |
Uwe Hermann | a0c0093 | 2008-03-27 20:46:49 +0000 | [diff] [blame] | 94 | mvwprintw(win, row++, 3, " Table: "); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | wprintw(win, "%16.16llx - %16.16llx", |
Philip Prindeville | 46404d7 | 2011-12-23 17:09:02 -0700 | [diff] [blame] | 98 | cb_unpack64(cb_info.range[i].start), |
| 99 | cb_unpack64(cb_info.range[i].start) + |
| 100 | cb_unpack64(cb_info.range[i].size) - 1); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 101 | } |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 102 | |
| 103 | return 0; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void parse_memory(unsigned char *ptr) |
| 107 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 108 | struct cb_memory *mem = (struct cb_memory *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 109 | int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 110 | ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 111 | int i; |
| 112 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 113 | for (i = 0; i < max; i++) { |
| 114 | struct cb_memory_range *range = |
| 115 | (struct cb_memory_range *)MEM_RANGE_PTR(mem, i); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 116 | |
| 117 | memcpy(&cb_info.range[i], range, sizeof(*range)); |
| 118 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 119 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 120 | cb_info.mem_count = max; |
| 121 | cb_info.mem_actual = MEM_RANGE_COUNT(mem); |
| 122 | } |
| 123 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 124 | static void parse_mainboard(unsigned char *ptr) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 125 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 126 | struct cb_mainboard *mb = (struct cb_mainboard *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 127 | |
Alexandru Gagniuc | 811d661 | 2012-08-15 06:36:00 -0500 | [diff] [blame] | 128 | strncpy(cb_info.vendor, cb_mb_vendor_string(mb), sizeof(cb_info.vendor) - 1); |
Philip Prindeville | 68299ee | 2011-12-23 18:45:33 -0700 | [diff] [blame] | 129 | strncpy(cb_info.part, cb_mb_part_string(mb), sizeof(cb_info.part) - 1); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static void parse_strings(unsigned char *ptr) |
| 133 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 134 | struct cb_string *string = (struct cb_string *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 135 | int index = string->tag - CB_TAG_VERSION; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 136 | |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 137 | strncpy(cb_info.strings[index], (const char *)string->string, 63); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 138 | cb_info.strings[index][63] = 0; |
| 139 | } |
| 140 | |
| 141 | static void parse_serial(unsigned char *ptr) |
| 142 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 143 | memcpy(&cb_info.serial, (struct cb_serial *)ptr, |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 144 | sizeof(struct cb_serial)); |
| 145 | } |
| 146 | |
| 147 | static void parse_console(unsigned char *ptr) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 148 | { |
| 149 | memcpy(&cb_info.console, (struct cb_console *)ptr, |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 150 | sizeof(struct cb_console)); |
| 151 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 152 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 153 | static int parse_header(void *addr, int len) |
| 154 | { |
| 155 | struct cb_header *header; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 156 | unsigned char *ptr = (unsigned char *)addr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 157 | int i; |
| 158 | |
| 159 | for (i = 0; i < len; i += 16, ptr += 16) { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 160 | header = (struct cb_header *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 161 | |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 162 | if (!strncmp((const char *)header->signature, "LBIO", 4)) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 163 | break; |
| 164 | } |
| 165 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 166 | /* We walked the entire space and didn't find anything. */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 167 | if (i >= len) |
| 168 | return -1; |
| 169 | |
| 170 | if (!header->table_bytes) |
| 171 | return 0; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 172 | |
| 173 | /* FIXME: Check the checksum. */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 174 | |
Philip Prindeville | fe2f6b0 | 2011-12-23 17:22:05 -0700 | [diff] [blame] | 175 | if (cb_checksum(header, sizeof(*header))) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 176 | return -1; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 177 | |
Philip Prindeville | fe2f6b0 | 2011-12-23 17:22:05 -0700 | [diff] [blame] | 178 | if (cb_checksum((ptr + sizeof(*header)), header->table_bytes) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 179 | != header->table_checksum) |
| 180 | return -1; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 181 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 182 | /* Now, walk the tables. */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 183 | ptr += header->header_bytes; |
| 184 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 185 | for (u32 j = 0; j < header->table_entries; j++) { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 186 | struct cb_record *rec = (struct cb_record *)ptr; |
| 187 | |
| 188 | switch (rec->tag) { |
Myles Watson | 44163f7 | 2009-08-24 15:25:11 +0000 | [diff] [blame] | 189 | case CB_TAG_FORWARD: |
| 190 | return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1); |
| 191 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 192 | case CB_TAG_MEMORY: |
| 193 | parse_memory(ptr); |
| 194 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 195 | case CB_TAG_MAINBOARD: |
| 196 | parse_mainboard(ptr); |
| 197 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 198 | case CB_TAG_VERSION: |
| 199 | case CB_TAG_EXTRA_VERSION: |
| 200 | case CB_TAG_BUILD: |
| 201 | case CB_TAG_COMPILE_TIME: |
| 202 | case CB_TAG_COMPILE_BY: |
| 203 | case CB_TAG_COMPILE_HOST: |
| 204 | case CB_TAG_COMPILE_DOMAIN: |
| 205 | case CB_TAG_COMPILER: |
| 206 | case CB_TAG_LINKER: |
| 207 | case CB_TAG_ASSEMBLER: |
| 208 | parse_strings(ptr); |
| 209 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 210 | case CB_TAG_SERIAL: |
| 211 | parse_serial(ptr); |
| 212 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 213 | case CB_TAG_CONSOLE: |
| 214 | parse_console(ptr); |
| 215 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | ptr += rec->size; |
| 221 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 222 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 223 | return 1; |
| 224 | } |
| 225 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 226 | static int coreboot_module_init(void) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 227 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 228 | int ret = parse_header((void *)0x00000, 0x1000); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 229 | |
| 230 | if (ret != 1) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 231 | ret = parse_header((void *)0xf0000, 0x1000); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 232 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 233 | /* Return error if we couldn't find it at either address. */ |
| 234 | tables_good = (ret == 1) ? 0 : -1; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 235 | return tables_good; |
| 236 | } |
| 237 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 238 | struct coreinfo_module coreboot_module = { |
Martin Roth | e81ce04 | 2017-06-03 20:00:36 -0600 | [diff] [blame] | 239 | .name = "coreboot", |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 240 | .init = coreboot_module_init, |
| 241 | .redraw = coreboot_module_redraw, |
| 242 | }; |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 243 | |
| 244 | #else |
| 245 | |
| 246 | struct coreinfo_module coreboot_module = { |
| 247 | }; |
| 248 | |
| 249 | #endif |