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