blob: 16a63c544df74ee975b075459ba716cdd2004ee8 [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
20#include <coreboot_tables.h>
21#include "coreinfo.h"
22
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",
Uwe Hermann3a406fe2008-03-20 01:11:28 +000071 cb_info.serial.ioport);
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",
115 UNPACK_CB64(cb_info.range[i].start),
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000116 UNPACK_CB64(cb_info.range[i].start) +
Jordan Crouse7249f792008-03-20 00:11:05 +0000117 UNPACK_CB64(cb_info.range[i].size) - 1);
118 }
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
Uwe Hermann35845a22008-03-20 20:05:22 +0000145 strncpy(cb_info.vendor, (const char *)MB_VENDOR_STRING(mb), 31);
146 strncpy(cb_info.part, (const char *)MB_PART_STRING(mb), 31);
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
192 if (ipchksum((uint16_t *) header, sizeof(*header)))
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000193 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000194
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000195 if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes)
196 != 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) {
Jordan Crouse7249f792008-03-20 00:11:05 +0000206 case CB_TAG_MEMORY:
207 parse_memory(ptr);
208 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000209 case CB_TAG_MAINBOARD:
210 parse_mainboard(ptr);
211 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000212 case CB_TAG_VERSION:
213 case CB_TAG_EXTRA_VERSION:
214 case CB_TAG_BUILD:
215 case CB_TAG_COMPILE_TIME:
216 case CB_TAG_COMPILE_BY:
217 case CB_TAG_COMPILE_HOST:
218 case CB_TAG_COMPILE_DOMAIN:
219 case CB_TAG_COMPILER:
220 case CB_TAG_LINKER:
221 case CB_TAG_ASSEMBLER:
222 parse_strings(ptr);
223 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000224 case CB_TAG_SERIAL:
225 parse_serial(ptr);
226 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000227 case CB_TAG_CONSOLE:
228 parse_console(ptr);
229 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000230 default:
231 break;
232 }
233
234 ptr += rec->size;
235 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000236
Jordan Crouse7249f792008-03-20 00:11:05 +0000237 return 1;
238}
239
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000240static int coreboot_module_init(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000241{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000242 int ret = parse_header((void *)0x00000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000243
244 if (ret != 1)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000245 ret = parse_header((void *)0xf0000, 0x1000);
Jordan Crouse7249f792008-03-20 00:11:05 +0000246
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000247 /* Return error if we couldn't find it at either address. */
248 tables_good = (ret == 1) ? 0 : -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000249 return tables_good;
250}
251
Jordan Crouse7249f792008-03-20 00:11:05 +0000252struct coreinfo_module coreboot_module = {
253 .name = "Coreboot",
254 .init = coreboot_module_init,
255 .redraw = coreboot_module_redraw,
256};
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000257
258#else
259
260struct coreinfo_module coreboot_module = {
261};
262
263#endif