blob: c038d624872432498528563da16a7497c351d184 [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
Jianjun Wangb2537bd2022-04-08 16:57:28 +080097 wprintw(win, "%16.16llx - %16.16llx", cb_info.range[i].start,
98 cb_info.range[i].start + cb_info.range[i].size - 1);
Jordan Crouse7249f792008-03-20 00:11:05 +000099 }
Uwe Hermann35845a22008-03-20 20:05:22 +0000100
101 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000102}
103
104static void parse_memory(unsigned char *ptr)
105{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000106 struct cb_memory *mem = (struct cb_memory *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000107 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000108 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
Jordan Crouse7249f792008-03-20 00:11:05 +0000109 int i;
110
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000111 for (i = 0; i < max; i++) {
112 struct cb_memory_range *range =
113 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
Jordan Crouse7249f792008-03-20 00:11:05 +0000114
115 memcpy(&cb_info.range[i], range, sizeof(*range));
116 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000117
Jordan Crouse7249f792008-03-20 00:11:05 +0000118 cb_info.mem_count = max;
119 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
120}
121
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000122static void parse_mainboard(unsigned char *ptr)
Jordan Crouse7249f792008-03-20 00:11:05 +0000123{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000124 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000125
Alexandru Gagniuc811d6612012-08-15 06:36:00 -0500126 strncpy(cb_info.vendor, cb_mb_vendor_string(mb), sizeof(cb_info.vendor) - 1);
Philip Prindeville68299ee2011-12-23 18:45:33 -0700127 strncpy(cb_info.part, cb_mb_part_string(mb), sizeof(cb_info.part) - 1);
Jordan Crouse7249f792008-03-20 00:11:05 +0000128}
129
130static void parse_strings(unsigned char *ptr)
131{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000132 struct cb_string *string = (struct cb_string *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000133 int index = string->tag - CB_TAG_VERSION;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000134
Uwe Hermann35845a22008-03-20 20:05:22 +0000135 strncpy(cb_info.strings[index], (const char *)string->string, 63);
Jordan Crouse7249f792008-03-20 00:11:05 +0000136 cb_info.strings[index][63] = 0;
137}
138
139static void parse_serial(unsigned char *ptr)
140{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000141 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000142 sizeof(struct cb_serial));
143}
144
145static void parse_console(unsigned char *ptr)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000146{
147 memcpy(&cb_info.console, (struct cb_console *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000148 sizeof(struct cb_console));
149}
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000150
Jordan Crouse7249f792008-03-20 00:11:05 +0000151static int parse_header(void *addr, int len)
152{
153 struct cb_header *header;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000154 unsigned char *ptr = (unsigned char *)addr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000155 int i;
156
157 for (i = 0; i < len; i += 16, ptr += 16) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000158 header = (struct cb_header *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000159
Uwe Hermann35845a22008-03-20 20:05:22 +0000160 if (!strncmp((const char *)header->signature, "LBIO", 4))
Jordan Crouse7249f792008-03-20 00:11:05 +0000161 break;
162 }
163
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000164 /* We walked the entire space and didn't find anything. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000165 if (i >= len)
166 return -1;
167
168 if (!header->table_bytes)
169 return 0;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000170
171 /* FIXME: Check the checksum. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000172
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700173 if (cb_checksum(header, sizeof(*header)))
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000174 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000175
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700176 if (cb_checksum((ptr + sizeof(*header)), header->table_bytes)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000177 != header->table_checksum)
178 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000179
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000180 /* Now, walk the tables. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000181 ptr += header->header_bytes;
182
Jacob Garbera711e9c2019-06-28 10:58:56 -0600183 for (u32 j = 0; j < header->table_entries; j++) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000184 struct cb_record *rec = (struct cb_record *)ptr;
185
186 switch (rec->tag) {
Myles Watson44163f72009-08-24 15:25:11 +0000187 case CB_TAG_FORWARD:
188 return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1);
Jordan Crouse7249f792008-03-20 00:11:05 +0000189 case CB_TAG_MEMORY:
190 parse_memory(ptr);
191 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000192 case CB_TAG_MAINBOARD:
193 parse_mainboard(ptr);
194 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000195 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 Crouse7249f792008-03-20 00:11:05 +0000207 case CB_TAG_SERIAL:
208 parse_serial(ptr);
209 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000210 case CB_TAG_CONSOLE:
211 parse_console(ptr);
212 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000213 default:
214 break;
215 }
216
217 ptr += rec->size;
218 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000219
Jordan Crouse7249f792008-03-20 00:11:05 +0000220 return 1;
221}
222
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000223static int coreboot_module_init(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000224{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000225 int ret = parse_header((void *)0x00000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000226
227 if (ret != 1)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000228 ret = parse_header((void *)0xf0000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000229
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000230 /* Return error if we couldn't find it at either address. */
231 tables_good = (ret == 1) ? 0 : -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000232 return tables_good;
233}
234
Jordan Crouse7249f792008-03-20 00:11:05 +0000235struct coreinfo_module coreboot_module = {
Martin Rothe81ce042017-06-03 20:00:36 -0600236 .name = "coreboot",
Jordan Crouse7249f792008-03-20 00:11:05 +0000237 .init = coreboot_module_init,
238 .redraw = coreboot_module_redraw,
239};
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000240
241#else
242
243struct coreinfo_module coreboot_module = {
244};
245
246#endif