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 | |
Jianjun Wang | b2537bd | 2022-04-08 16:57:28 +0800 | [diff] [blame] | 97 | wprintw(win, "%16.16llx - %16.16llx", cb_info.range[i].start, |
| 98 | cb_info.range[i].start + cb_info.range[i].size - 1); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 99 | } |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 100 | |
| 101 | return 0; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static void parse_memory(unsigned char *ptr) |
| 105 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 106 | struct cb_memory *mem = (struct cb_memory *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 107 | int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 108 | ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 109 | int i; |
| 110 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 111 | for (i = 0; i < max; i++) { |
| 112 | struct cb_memory_range *range = |
| 113 | (struct cb_memory_range *)MEM_RANGE_PTR(mem, i); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 114 | |
| 115 | memcpy(&cb_info.range[i], range, sizeof(*range)); |
| 116 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 117 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 118 | cb_info.mem_count = max; |
| 119 | cb_info.mem_actual = MEM_RANGE_COUNT(mem); |
| 120 | } |
| 121 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 122 | static void parse_mainboard(unsigned char *ptr) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 123 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 124 | struct cb_mainboard *mb = (struct cb_mainboard *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 125 | |
Alexandru Gagniuc | 811d661 | 2012-08-15 06:36:00 -0500 | [diff] [blame] | 126 | 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] | 127 | 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] | 128 | } |
| 129 | |
| 130 | static void parse_strings(unsigned char *ptr) |
| 131 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 132 | struct cb_string *string = (struct cb_string *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 133 | int index = string->tag - CB_TAG_VERSION; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 134 | |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 135 | strncpy(cb_info.strings[index], (const char *)string->string, 63); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 136 | cb_info.strings[index][63] = 0; |
| 137 | } |
| 138 | |
| 139 | static void parse_serial(unsigned char *ptr) |
| 140 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 141 | memcpy(&cb_info.serial, (struct cb_serial *)ptr, |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 142 | sizeof(struct cb_serial)); |
| 143 | } |
| 144 | |
| 145 | static void parse_console(unsigned char *ptr) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 146 | { |
| 147 | memcpy(&cb_info.console, (struct cb_console *)ptr, |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 148 | sizeof(struct cb_console)); |
| 149 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 150 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 151 | static int parse_header(void *addr, int len) |
| 152 | { |
| 153 | struct cb_header *header; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 154 | unsigned char *ptr = (unsigned char *)addr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 155 | int i; |
| 156 | |
| 157 | for (i = 0; i < len; i += 16, ptr += 16) { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 158 | header = (struct cb_header *)ptr; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 159 | |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 160 | if (!strncmp((const char *)header->signature, "LBIO", 4)) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 161 | break; |
| 162 | } |
| 163 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 164 | /* We walked the entire space and didn't find anything. */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 165 | if (i >= len) |
| 166 | return -1; |
| 167 | |
| 168 | if (!header->table_bytes) |
| 169 | return 0; |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 170 | |
| 171 | /* FIXME: Check the checksum. */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 172 | |
Philip Prindeville | fe2f6b0 | 2011-12-23 17:22:05 -0700 | [diff] [blame] | 173 | if (cb_checksum(header, sizeof(*header))) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 174 | return -1; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 175 | |
Philip Prindeville | fe2f6b0 | 2011-12-23 17:22:05 -0700 | [diff] [blame] | 176 | if (cb_checksum((ptr + sizeof(*header)), header->table_bytes) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 177 | != header->table_checksum) |
| 178 | return -1; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 179 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 180 | /* Now, walk the tables. */ |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 181 | ptr += header->header_bytes; |
| 182 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 183 | for (u32 j = 0; j < header->table_entries; j++) { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 184 | struct cb_record *rec = (struct cb_record *)ptr; |
| 185 | |
| 186 | switch (rec->tag) { |
Myles Watson | 44163f7 | 2009-08-24 15:25:11 +0000 | [diff] [blame] | 187 | case CB_TAG_FORWARD: |
| 188 | return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 189 | case CB_TAG_MEMORY: |
| 190 | parse_memory(ptr); |
| 191 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 192 | case CB_TAG_MAINBOARD: |
| 193 | parse_mainboard(ptr); |
| 194 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 195 | case CB_TAG_VERSION: |
| 196 | case CB_TAG_EXTRA_VERSION: |
| 197 | case CB_TAG_BUILD: |
| 198 | case CB_TAG_COMPILE_TIME: |
| 199 | case CB_TAG_COMPILE_BY: |
| 200 | case CB_TAG_COMPILE_HOST: |
| 201 | case CB_TAG_COMPILE_DOMAIN: |
| 202 | case CB_TAG_COMPILER: |
| 203 | case CB_TAG_LINKER: |
| 204 | case CB_TAG_ASSEMBLER: |
| 205 | parse_strings(ptr); |
| 206 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 207 | case CB_TAG_SERIAL: |
| 208 | parse_serial(ptr); |
| 209 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 210 | case CB_TAG_CONSOLE: |
| 211 | parse_console(ptr); |
| 212 | break; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | ptr += rec->size; |
| 218 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 219 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 220 | return 1; |
| 221 | } |
| 222 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 223 | static int coreboot_module_init(void) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 224 | { |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 225 | int ret = parse_header((void *)0x00000, 0x1000); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 226 | |
| 227 | if (ret != 1) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 228 | ret = parse_header((void *)0xf0000, 0x1000); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 229 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 230 | /* Return error if we couldn't find it at either address. */ |
| 231 | tables_good = (ret == 1) ? 0 : -1; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 232 | return tables_good; |
| 233 | } |
| 234 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 235 | struct coreinfo_module coreboot_module = { |
Martin Roth | e81ce04 | 2017-06-03 20:00:36 -0600 | [diff] [blame] | 236 | .name = "coreboot", |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 237 | .init = coreboot_module_init, |
| 238 | .redraw = coreboot_module_redraw, |
| 239 | }; |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 240 | |
| 241 | #else |
| 242 | |
| 243 | struct coreinfo_module coreboot_module = { |
| 244 | }; |
| 245 | |
| 246 | #endif |