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