blob: e5ba50f85121b36a3ac351d6418bdeea83b4ff3c [file] [log] [blame]
Jordan Crouse7249f792008-03-20 00:11:05 +00001/*
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
Jordan Crouse7249f792008-03-20 00:11:05 +000020#include "coreinfo.h"
Philip Prindevillefe2f6b02011-12-23 17:22:05 -070021#include <coreboot_tables.h>
Jordan Crouse7249f792008-03-20 00:11:05 +000022
Uwe Hermannab5b3e02008-03-31 20:30:18 +000023#ifdef CONFIG_MODULE_COREBOOT
24
Jordan Crouse7249f792008-03-20 00:11:05 +000025#define MAX_MEMORY_COUNT 5
26
27static struct {
28 int mem_count;
29 int mem_actual;
30
31 struct cb_memory_range range[MAX_MEMORY_COUNT];
32
33 char vendor[32];
34 char part[32];
35
36 char strings[10][64];
Uwe Hermann3a406fe2008-03-20 01:11:28 +000037
Jordan Crouse7249f792008-03-20 00:11:05 +000038 struct cb_serial serial;
39 struct cb_console console;
40} cb_info;
41
42static int tables_good = 0;
43
Uwe Hermann3a406fe2008-03-20 01:11:28 +000044int coreboot_module_redraw(WINDOW *win)
Jordan Crouse7249f792008-03-20 00:11:05 +000045{
46 int row = 2;
47 int i;
48
49 print_module_title(win, "Coreboot Tables");
50
51 if (tables_good) {
Uwe Hermanna0c00932008-03-27 20:46:49 +000052 mvwprintw(win, row++, 1, "No Coreboot tables were found");
Jordan Crouse7249f792008-03-20 00:11:05 +000053 return 0;
54 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +000055
Uwe Hermanna0c00932008-03-27 20:46:49 +000056 mvwprintw(win, row++, 1, "Vendor: %s", cb_info.vendor);
57 mvwprintw(win, row++, 1, "Part: %s", cb_info.part);
Jordan Crouse7249f792008-03-20 00:11:05 +000058
Uwe Hermanna0c00932008-03-27 20:46:49 +000059 mvwprintw(win, row++, 1, "Version: %s%s",
Uwe Hermann3a406fe2008-03-20 01:11:28 +000060 cb_info.strings[CB_TAG_VERSION - 0x4],
61 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
Jordan Crouse7249f792008-03-20 00:11:05 +000062
Uwe Hermanna0c00932008-03-27 20:46:49 +000063 mvwprintw(win, row++, 1, "Built: %s (%s@%s.%s)",
Jordan Crouse7249f792008-03-20 00:11:05 +000064 cb_info.strings[CB_TAG_BUILD - 0x4],
65 cb_info.strings[CB_TAG_COMPILE_BY - 0x04],
66 cb_info.strings[CB_TAG_COMPILE_HOST - 0x04],
67 cb_info.strings[CB_TAG_COMPILE_DOMAIN - 0x04]);
68
69 if (cb_info.serial.tag != 0x0) {
Uwe Hermanna0c00932008-03-27 20:46:49 +000070 mvwprintw(win, row++, 1, "Serial Port I/O base: 0x%x",
QingPei Wang45945cf2011-11-22 15:24:12 +080071 cb_info.serial.baseaddr);
Jordan Crouse7249f792008-03-20 00:11:05 +000072 }
73
74 if (cb_info.console.tag != 0x0) {
Uwe Hermanna0c00932008-03-27 20:46:49 +000075 mvwprintw(win, row++, 1, "Default Output Console: ");
Uwe Hermann3a406fe2008-03-20 01:11:28 +000076
77 switch (cb_info.console.type) {
Jordan Crouse7249f792008-03-20 00:11:05 +000078 case CB_TAG_CONSOLE_SERIAL8250:
79 wprintw(win, "Serial Port");
80 break;
81 case CB_TAG_CONSOLE_VGA:
82 wprintw(win, "VGA");
83 break;
84 case CB_TAG_CONSOLE_BTEXT:
85 wprintw(win, "BTEXT");
86 break;
87 case CB_TAG_CONSOLE_LOGBUF:
88 wprintw(win, "Log Buffer");
89 break;
90 case CB_TAG_CONSOLE_SROM:
91 wprintw(win, "Serial ROM");
92 break;
93 case CB_TAG_CONSOLE_EHCI:
94 wprintw(win, "USB Debug");
95 break;
96 }
97 }
98
99 row++;
Uwe Hermanna0c00932008-03-27 20:46:49 +0000100 mvwprintw(win, row++, 1, "-- Memory Map --");
Jordan Crouse7249f792008-03-20 00:11:05 +0000101
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000102 for (i = 0; i < cb_info.mem_count; i++) {
103 switch (cb_info.range[i].type) {
Jordan Crouse7249f792008-03-20 00:11:05 +0000104 case CB_MEM_RAM:
Uwe Hermanna0c00932008-03-27 20:46:49 +0000105 mvwprintw(win, row++, 3, " RAM: ");
Jordan Crouse7249f792008-03-20 00:11:05 +0000106 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000107 case CB_MEM_RESERVED:
Uwe Hermanna0c00932008-03-27 20:46:49 +0000108 mvwprintw(win, row++, 3, "Reserved: ");
Jordan Crouse7249f792008-03-20 00:11:05 +0000109 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000110 case CB_MEM_TABLE:
Uwe Hermanna0c00932008-03-27 20:46:49 +0000111 mvwprintw(win, row++, 3, " Table: ");
Jordan Crouse7249f792008-03-20 00:11:05 +0000112 }
113
114 wprintw(win, "%16.16llx - %16.16llx",
Philip Prindeville46404d72011-12-23 17:09:02 -0700115 cb_unpack64(cb_info.range[i].start),
116 cb_unpack64(cb_info.range[i].start) +
117 cb_unpack64(cb_info.range[i].size) - 1);
Jordan Crouse7249f792008-03-20 00:11:05 +0000118 }
Uwe Hermann35845a22008-03-20 20:05:22 +0000119
120 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000121}
122
123static void parse_memory(unsigned char *ptr)
124{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000125 struct cb_memory *mem = (struct cb_memory *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000126 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000127 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
Jordan Crouse7249f792008-03-20 00:11:05 +0000128 int i;
129
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000130 for (i = 0; i < max; i++) {
131 struct cb_memory_range *range =
132 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
Jordan Crouse7249f792008-03-20 00:11:05 +0000133
134 memcpy(&cb_info.range[i], range, sizeof(*range));
135 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000136
Jordan Crouse7249f792008-03-20 00:11:05 +0000137 cb_info.mem_count = max;
138 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
139}
140
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000141static void parse_mainboard(unsigned char *ptr)
Jordan Crouse7249f792008-03-20 00:11:05 +0000142{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000143 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000144
Alexandru Gagniuc811d6612012-08-15 06:36:00 -0500145 strncpy(cb_info.vendor, cb_mb_vendor_string(mb), sizeof(cb_info.vendor) - 1);
Philip Prindeville68299ee2011-12-23 18:45:33 -0700146 strncpy(cb_info.part, cb_mb_part_string(mb), sizeof(cb_info.part) - 1);
Jordan Crouse7249f792008-03-20 00:11:05 +0000147}
148
149static void parse_strings(unsigned char *ptr)
150{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000151 struct cb_string *string = (struct cb_string *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000152 int index = string->tag - CB_TAG_VERSION;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000153
Uwe Hermann35845a22008-03-20 20:05:22 +0000154 strncpy(cb_info.strings[index], (const char *)string->string, 63);
Jordan Crouse7249f792008-03-20 00:11:05 +0000155 cb_info.strings[index][63] = 0;
156}
157
158static void parse_serial(unsigned char *ptr)
159{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000160 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000161 sizeof(struct cb_serial));
162}
163
164static void parse_console(unsigned char *ptr)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000165{
166 memcpy(&cb_info.console, (struct cb_console *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000167 sizeof(struct cb_console));
168}
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000169
Jordan Crouse7249f792008-03-20 00:11:05 +0000170static int parse_header(void *addr, int len)
171{
172 struct cb_header *header;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000173 unsigned char *ptr = (unsigned char *)addr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000174 int i;
175
176 for (i = 0; i < len; i += 16, ptr += 16) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000177 header = (struct cb_header *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000178
Uwe Hermann35845a22008-03-20 20:05:22 +0000179 if (!strncmp((const char *)header->signature, "LBIO", 4))
Jordan Crouse7249f792008-03-20 00:11:05 +0000180 break;
181 }
182
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000183 /* We walked the entire space and didn't find anything. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000184 if (i >= len)
185 return -1;
186
187 if (!header->table_bytes)
188 return 0;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000189
190 /* FIXME: Check the checksum. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000191
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700192 if (cb_checksum(header, sizeof(*header)))
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000193 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000194
Philip Prindevillefe2f6b02011-12-23 17:22:05 -0700195 if (cb_checksum((ptr + sizeof(*header)), header->table_bytes)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000196 != header->table_checksum)
197 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000198
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000199 /* Now, walk the tables. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000200 ptr += header->header_bytes;
201
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000202 for (i = 0; i < header->table_entries; i++) {
203 struct cb_record *rec = (struct cb_record *)ptr;
204
205 switch (rec->tag) {
Myles Watson44163f72009-08-24 15:25:11 +0000206 case CB_TAG_FORWARD:
207 return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1);
208 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000209 case CB_TAG_MEMORY:
210 parse_memory(ptr);
211 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000212 case CB_TAG_MAINBOARD:
213 parse_mainboard(ptr);
214 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000215 case CB_TAG_VERSION:
216 case CB_TAG_EXTRA_VERSION:
217 case CB_TAG_BUILD:
218 case CB_TAG_COMPILE_TIME:
219 case CB_TAG_COMPILE_BY:
220 case CB_TAG_COMPILE_HOST:
221 case CB_TAG_COMPILE_DOMAIN:
222 case CB_TAG_COMPILER:
223 case CB_TAG_LINKER:
224 case CB_TAG_ASSEMBLER:
225 parse_strings(ptr);
226 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000227 case CB_TAG_SERIAL:
228 parse_serial(ptr);
229 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000230 case CB_TAG_CONSOLE:
231 parse_console(ptr);
232 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000233 default:
234 break;
235 }
236
237 ptr += rec->size;
238 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000239
Jordan Crouse7249f792008-03-20 00:11:05 +0000240 return 1;
241}
242
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000243static int coreboot_module_init(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000244{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000245 int ret = parse_header((void *)0x00000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000246
247 if (ret != 1)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000248 ret = parse_header((void *)0xf0000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000249
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000250 /* Return error if we couldn't find it at either address. */
251 tables_good = (ret == 1) ? 0 : -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000252 return tables_good;
253}
254
Jordan Crouse7249f792008-03-20 00:11:05 +0000255struct coreinfo_module coreboot_module = {
256 .name = "Coreboot",
257 .init = coreboot_module_init,
258 .redraw = coreboot_module_redraw,
259};
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000260
261#else
262
263struct coreinfo_module coreboot_module = {
264};
265
266#endif