blob: 074d73a475a3d45c6cb73cd25eb7ab717e54c1a2 [file] [log] [blame]
Jordan Crouse7249f792008-03-20 00:11:05 +00001/*
Jordan Crouse7249f792008-03-20 00:11:05 +00002 *
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 Crouse7249f792008-03-20 00:11:05 +000013 */
14
Jordan Crouse7249f792008-03-20 00:11:05 +000015#include "coreinfo.h"
Philip Prindevillefe2f6b02011-12-23 17:22:05 -070016#include <coreboot_tables.h>
Jordan Crouse7249f792008-03-20 00:11:05 +000017
Julius Wernereab2a292019-03-05 16:55:15 -080018#if CONFIG(MODULE_COREBOOT)
Uwe Hermannab5b3e02008-03-31 20:30:18 +000019
Jordan Crouse7249f792008-03-20 00:11:05 +000020#define MAX_MEMORY_COUNT 5
21
22static 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 Hermann3a406fe2008-03-20 01:11:28 +000032
Jordan Crouse7249f792008-03-20 00:11:05 +000033 struct cb_serial serial;
34 struct cb_console console;
35} cb_info;
36
37static int tables_good = 0;
38
Jacob Garber609305f2019-06-28 11:03:31 -060039static int coreboot_module_redraw(WINDOW *win)
Jordan Crouse7249f792008-03-20 00:11:05 +000040{
41 int row = 2;
42 int i;
43
Martin Rothe81ce042017-06-03 20:00:36 -060044 print_module_title(win, "coreboot Tables");
Jordan Crouse7249f792008-03-20 00:11:05 +000045
46 if (tables_good) {
Martin Rothe81ce042017-06-03 20:00:36 -060047 mvwprintw(win, row++, 1, "No coreboot tables were found");
Jordan Crouse7249f792008-03-20 00:11:05 +000048 return 0;
49 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +000050
Uwe Hermanna0c00932008-03-27 20:46:49 +000051 mvwprintw(win, row++, 1, "Vendor: %s", cb_info.vendor);
52 mvwprintw(win, row++, 1, "Part: %s", cb_info.part);
Jordan Crouse7249f792008-03-20 00:11:05 +000053
Uwe Hermanna0c00932008-03-27 20:46:49 +000054 mvwprintw(win, row++, 1, "Version: %s%s",
Uwe Hermann3a406fe2008-03-20 01:11:28 +000055 cb_info.strings[CB_TAG_VERSION - 0x4],
56 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
Jordan Crouse7249f792008-03-20 00:11:05 +000057
Uwe Hermanna0c00932008-03-27 20:46:49 +000058 mvwprintw(win, row++, 1, "Built: %s (%s@%s.%s)",
Jordan Crouse7249f792008-03-20 00:11:05 +000059 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 Hermanna0c00932008-03-27 20:46:49 +000065 mvwprintw(win, row++, 1, "Serial Port I/O base: 0x%x",
QingPei Wang45945cf2011-11-22 15:24:12 +080066 cb_info.serial.baseaddr);
Jordan Crouse7249f792008-03-20 00:11:05 +000067 }
68
69 if (cb_info.console.tag != 0x0) {
Uwe Hermanna0c00932008-03-27 20:46:49 +000070 mvwprintw(win, row++, 1, "Default Output Console: ");
Uwe Hermann3a406fe2008-03-20 01:11:28 +000071
72 switch (cb_info.console.type) {
Jordan Crouse7249f792008-03-20 00:11:05 +000073 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 Hermanna0c00932008-03-27 20:46:49 +000095 mvwprintw(win, row++, 1, "-- Memory Map --");
Jordan Crouse7249f792008-03-20 00:11:05 +000096
Uwe Hermann3a406fe2008-03-20 01:11:28 +000097 for (i = 0; i < cb_info.mem_count; i++) {
98 switch (cb_info.range[i].type) {
Jordan Crouse7249f792008-03-20 00:11:05 +000099 case CB_MEM_RAM:
Uwe Hermanna0c00932008-03-27 20:46:49 +0000100 mvwprintw(win, row++, 3, " RAM: ");
Jordan Crouse7249f792008-03-20 00:11:05 +0000101 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000102 case CB_MEM_RESERVED:
Uwe Hermanna0c00932008-03-27 20:46:49 +0000103 mvwprintw(win, row++, 3, "Reserved: ");
Jordan Crouse7249f792008-03-20 00:11:05 +0000104 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000105 case CB_MEM_TABLE:
Uwe Hermanna0c00932008-03-27 20:46:49 +0000106 mvwprintw(win, row++, 3, " Table: ");
Jordan Crouse7249f792008-03-20 00:11:05 +0000107 }
108
109 wprintw(win, "%16.16llx - %16.16llx",
Philip Prindeville46404d72011-12-23 17:09:02 -0700110 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 Crouse7249f792008-03-20 00:11:05 +0000113 }
Uwe Hermann35845a22008-03-20 20:05:22 +0000114
115 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000116}
117
118static void parse_memory(unsigned char *ptr)
119{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000120 struct cb_memory *mem = (struct cb_memory *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000121 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000122 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
Jordan Crouse7249f792008-03-20 00:11:05 +0000123 int i;
124
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000125 for (i = 0; i < max; i++) {
126 struct cb_memory_range *range =
127 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
Jordan Crouse7249f792008-03-20 00:11:05 +0000128
129 memcpy(&cb_info.range[i], range, sizeof(*range));
130 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000131
Jordan Crouse7249f792008-03-20 00:11:05 +0000132 cb_info.mem_count = max;
133 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
134}
135
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000136static void parse_mainboard(unsigned char *ptr)
Jordan Crouse7249f792008-03-20 00:11:05 +0000137{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000138 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000139
Alexandru Gagniuc811d6612012-08-15 06:36:00 -0500140 strncpy(cb_info.vendor, cb_mb_vendor_string(mb), sizeof(cb_info.vendor) - 1);
Philip Prindeville68299ee2011-12-23 18:45:33 -0700141 strncpy(cb_info.part, cb_mb_part_string(mb), sizeof(cb_info.part) - 1);
Jordan Crouse7249f792008-03-20 00:11:05 +0000142}
143
144static void parse_strings(unsigned char *ptr)
145{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000146 struct cb_string *string = (struct cb_string *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000147 int index = string->tag - CB_TAG_VERSION;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000148
Uwe Hermann35845a22008-03-20 20:05:22 +0000149 strncpy(cb_info.strings[index], (const char *)string->string, 63);
Jordan Crouse7249f792008-03-20 00:11:05 +0000150 cb_info.strings[index][63] = 0;
151}
152
153static void parse_serial(unsigned char *ptr)
154{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000155 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000156 sizeof(struct cb_serial));
157}
158
159static void parse_console(unsigned char *ptr)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000160{
161 memcpy(&cb_info.console, (struct cb_console *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000162 sizeof(struct cb_console));
163}
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000164
Jordan Crouse7249f792008-03-20 00:11:05 +0000165static int parse_header(void *addr, int len)
166{
167 struct cb_header *header;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000168 unsigned char *ptr = (unsigned char *)addr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000169 int i;
170
171 for (i = 0; i < len; i += 16, ptr += 16) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000172 header = (struct cb_header *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000173
Uwe Hermann35845a22008-03-20 20:05:22 +0000174 if (!strncmp((const char *)header->signature, "LBIO", 4))
Jordan Crouse7249f792008-03-20 00:11:05 +0000175 break;
176 }
177
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000178 /* We walked the entire space and didn't find anything. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000179 if (i >= len)
180 return -1;
181
182 if (!header->table_bytes)
183 return 0;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000184
185 /* FIXME: Check the checksum. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000186
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700187 if (cb_checksum(header, sizeof(*header)))
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000188 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000189
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700190 if (cb_checksum((ptr + sizeof(*header)), header->table_bytes)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000191 != header->table_checksum)
192 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000193
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000194 /* Now, walk the tables. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000195 ptr += header->header_bytes;
196
Jacob Garbera711e9c2019-06-28 10:58:56 -0600197 for (u32 j = 0; j < header->table_entries; j++) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000198 struct cb_record *rec = (struct cb_record *)ptr;
199
200 switch (rec->tag) {
Myles Watson44163f72009-08-24 15:25:11 +0000201 case CB_TAG_FORWARD:
202 return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1);
203 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000204 case CB_TAG_MEMORY:
205 parse_memory(ptr);
206 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000207 case CB_TAG_MAINBOARD:
208 parse_mainboard(ptr);
209 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000210 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 Crouse7249f792008-03-20 00:11:05 +0000222 case CB_TAG_SERIAL:
223 parse_serial(ptr);
224 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000225 case CB_TAG_CONSOLE:
226 parse_console(ptr);
227 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000228 default:
229 break;
230 }
231
232 ptr += rec->size;
233 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000234
Jordan Crouse7249f792008-03-20 00:11:05 +0000235 return 1;
236}
237
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000238static int coreboot_module_init(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000239{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000240 int ret = parse_header((void *)0x00000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000241
242 if (ret != 1)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000243 ret = parse_header((void *)0xf0000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000244
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000245 /* Return error if we couldn't find it at either address. */
246 tables_good = (ret == 1) ? 0 : -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000247 return tables_good;
248}
249
Jordan Crouse7249f792008-03-20 00:11:05 +0000250struct coreinfo_module coreboot_module = {
Martin Rothe81ce042017-06-03 20:00:36 -0600251 .name = "coreboot",
Jordan Crouse7249f792008-03-20 00:11:05 +0000252 .init = coreboot_module_init,
253 .redraw = coreboot_module_redraw,
254};
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000255
256#else
257
258struct coreinfo_module coreboot_module = {
259};
260
261#endif