blob: 87032d5990792d9e6833ab5e855855154abce912 [file] [log] [blame]
Jacob Garber07201d72020-09-08 12:25:44 -06001/* SPDX-License-Identifier: GPL-2.0-only */
Jordan Crouse7249f792008-03-20 00:11:05 +00002
Jordan Crouse7249f792008-03-20 00:11:05 +00003#include "coreinfo.h"
Philip Prindevillefe2f6b02011-12-23 17:22:05 -07004#include <coreboot_tables.h>
Jordan Crouse7249f792008-03-20 00:11:05 +00005
Julius Wernereab2a292019-03-05 16:55:15 -08006#if CONFIG(MODULE_COREBOOT)
Uwe Hermannab5b3e02008-03-31 20:30:18 +00007
Jordan Crouse7249f792008-03-20 00:11:05 +00008#define MAX_MEMORY_COUNT 5
9
10static 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 Hermann3a406fe2008-03-20 01:11:28 +000020
Jordan Crouse7249f792008-03-20 00:11:05 +000021 struct cb_serial serial;
22 struct cb_console console;
23} cb_info;
24
25static int tables_good = 0;
26
Jacob Garber609305f2019-06-28 11:03:31 -060027static int coreboot_module_redraw(WINDOW *win)
Jordan Crouse7249f792008-03-20 00:11:05 +000028{
29 int row = 2;
30 int i;
31
Martin Rothe81ce042017-06-03 20:00:36 -060032 print_module_title(win, "coreboot Tables");
Jordan Crouse7249f792008-03-20 00:11:05 +000033
34 if (tables_good) {
Martin Rothe81ce042017-06-03 20:00:36 -060035 mvwprintw(win, row++, 1, "No coreboot tables were found");
Jordan Crouse7249f792008-03-20 00:11:05 +000036 return 0;
37 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +000038
Uwe Hermanna0c00932008-03-27 20:46:49 +000039 mvwprintw(win, row++, 1, "Vendor: %s", cb_info.vendor);
40 mvwprintw(win, row++, 1, "Part: %s", cb_info.part);
Jordan Crouse7249f792008-03-20 00:11:05 +000041
Uwe Hermanna0c00932008-03-27 20:46:49 +000042 mvwprintw(win, row++, 1, "Version: %s%s",
Uwe Hermann3a406fe2008-03-20 01:11:28 +000043 cb_info.strings[CB_TAG_VERSION - 0x4],
44 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
Jordan Crouse7249f792008-03-20 00:11:05 +000045
Uwe Hermanna0c00932008-03-27 20:46:49 +000046 mvwprintw(win, row++, 1, "Built: %s (%s@%s.%s)",
Jordan Crouse7249f792008-03-20 00:11:05 +000047 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 Hermanna0c00932008-03-27 20:46:49 +000053 mvwprintw(win, row++, 1, "Serial Port I/O base: 0x%x",
QingPei Wang45945cf2011-11-22 15:24:12 +080054 cb_info.serial.baseaddr);
Jordan Crouse7249f792008-03-20 00:11:05 +000055 }
56
57 if (cb_info.console.tag != 0x0) {
Uwe Hermanna0c00932008-03-27 20:46:49 +000058 mvwprintw(win, row++, 1, "Default Output Console: ");
Uwe Hermann3a406fe2008-03-20 01:11:28 +000059
60 switch (cb_info.console.type) {
Jordan Crouse7249f792008-03-20 00:11:05 +000061 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 Hermanna0c00932008-03-27 20:46:49 +000083 mvwprintw(win, row++, 1, "-- Memory Map --");
Jordan Crouse7249f792008-03-20 00:11:05 +000084
Uwe Hermann3a406fe2008-03-20 01:11:28 +000085 for (i = 0; i < cb_info.mem_count; i++) {
86 switch (cb_info.range[i].type) {
Jordan Crouse7249f792008-03-20 00:11:05 +000087 case CB_MEM_RAM:
Uwe Hermanna0c00932008-03-27 20:46:49 +000088 mvwprintw(win, row++, 3, " RAM: ");
Jordan Crouse7249f792008-03-20 00:11:05 +000089 break;
Jordan Crouse7249f792008-03-20 00:11:05 +000090 case CB_MEM_RESERVED:
Uwe Hermanna0c00932008-03-27 20:46:49 +000091 mvwprintw(win, row++, 3, "Reserved: ");
Jordan Crouse7249f792008-03-20 00:11:05 +000092 break;
Jordan Crouse7249f792008-03-20 00:11:05 +000093 case CB_MEM_TABLE:
Uwe Hermanna0c00932008-03-27 20:46:49 +000094 mvwprintw(win, row++, 3, " Table: ");
Jordan Crouse7249f792008-03-20 00:11:05 +000095 }
96
97 wprintw(win, "%16.16llx - %16.16llx",
Philip Prindeville46404d72011-12-23 17:09:02 -070098 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 Crouse7249f792008-03-20 00:11:05 +0000101 }
Uwe Hermann35845a22008-03-20 20:05:22 +0000102
103 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000104}
105
106static void parse_memory(unsigned char *ptr)
107{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000108 struct cb_memory *mem = (struct cb_memory *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000109 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000110 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
Jordan Crouse7249f792008-03-20 00:11:05 +0000111 int i;
112
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000113 for (i = 0; i < max; i++) {
114 struct cb_memory_range *range =
115 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
Jordan Crouse7249f792008-03-20 00:11:05 +0000116
117 memcpy(&cb_info.range[i], range, sizeof(*range));
118 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000119
Jordan Crouse7249f792008-03-20 00:11:05 +0000120 cb_info.mem_count = max;
121 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
122}
123
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000124static void parse_mainboard(unsigned char *ptr)
Jordan Crouse7249f792008-03-20 00:11:05 +0000125{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000126 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000127
Alexandru Gagniuc811d6612012-08-15 06:36:00 -0500128 strncpy(cb_info.vendor, cb_mb_vendor_string(mb), sizeof(cb_info.vendor) - 1);
Philip Prindeville68299ee2011-12-23 18:45:33 -0700129 strncpy(cb_info.part, cb_mb_part_string(mb), sizeof(cb_info.part) - 1);
Jordan Crouse7249f792008-03-20 00:11:05 +0000130}
131
132static void parse_strings(unsigned char *ptr)
133{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000134 struct cb_string *string = (struct cb_string *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000135 int index = string->tag - CB_TAG_VERSION;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000136
Uwe Hermann35845a22008-03-20 20:05:22 +0000137 strncpy(cb_info.strings[index], (const char *)string->string, 63);
Jordan Crouse7249f792008-03-20 00:11:05 +0000138 cb_info.strings[index][63] = 0;
139}
140
141static void parse_serial(unsigned char *ptr)
142{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000143 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000144 sizeof(struct cb_serial));
145}
146
147static void parse_console(unsigned char *ptr)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000148{
149 memcpy(&cb_info.console, (struct cb_console *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000150 sizeof(struct cb_console));
151}
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000152
Jordan Crouse7249f792008-03-20 00:11:05 +0000153static int parse_header(void *addr, int len)
154{
155 struct cb_header *header;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000156 unsigned char *ptr = (unsigned char *)addr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000157 int i;
158
159 for (i = 0; i < len; i += 16, ptr += 16) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000160 header = (struct cb_header *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000161
Uwe Hermann35845a22008-03-20 20:05:22 +0000162 if (!strncmp((const char *)header->signature, "LBIO", 4))
Jordan Crouse7249f792008-03-20 00:11:05 +0000163 break;
164 }
165
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000166 /* We walked the entire space and didn't find anything. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000167 if (i >= len)
168 return -1;
169
170 if (!header->table_bytes)
171 return 0;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000172
173 /* FIXME: Check the checksum. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000174
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700175 if (cb_checksum(header, sizeof(*header)))
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000176 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000177
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700178 if (cb_checksum((ptr + sizeof(*header)), header->table_bytes)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000179 != header->table_checksum)
180 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000181
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000182 /* Now, walk the tables. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000183 ptr += header->header_bytes;
184
Jacob Garbera711e9c2019-06-28 10:58:56 -0600185 for (u32 j = 0; j < header->table_entries; j++) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000186 struct cb_record *rec = (struct cb_record *)ptr;
187
188 switch (rec->tag) {
Myles Watson44163f72009-08-24 15:25:11 +0000189 case CB_TAG_FORWARD:
190 return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1);
191 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000192 case CB_TAG_MEMORY:
193 parse_memory(ptr);
194 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000195 case CB_TAG_MAINBOARD:
196 parse_mainboard(ptr);
197 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000198 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 Crouse7249f792008-03-20 00:11:05 +0000210 case CB_TAG_SERIAL:
211 parse_serial(ptr);
212 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000213 case CB_TAG_CONSOLE:
214 parse_console(ptr);
215 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000216 default:
217 break;
218 }
219
220 ptr += rec->size;
221 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000222
Jordan Crouse7249f792008-03-20 00:11:05 +0000223 return 1;
224}
225
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000226static int coreboot_module_init(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000227{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000228 int ret = parse_header((void *)0x00000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000229
230 if (ret != 1)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000231 ret = parse_header((void *)0xf0000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000232
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000233 /* Return error if we couldn't find it at either address. */
234 tables_good = (ret == 1) ? 0 : -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000235 return tables_good;
236}
237
Jordan Crouse7249f792008-03-20 00:11:05 +0000238struct coreinfo_module coreboot_module = {
Martin Rothe81ce042017-06-03 20:00:36 -0600239 .name = "coreboot",
Jordan Crouse7249f792008-03-20 00:11:05 +0000240 .init = coreboot_module_init,
241 .redraw = coreboot_module_redraw,
242};
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000243
244#else
245
246struct coreinfo_module coreboot_module = {
247};
248
249#endif