blob: 45ed38cccde4d5e0a00448abc09c0a2bf793fd80 [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
23#define MAX_MEMORY_COUNT 5
24
25static struct {
26 int mem_count;
27 int mem_actual;
28
29 struct cb_memory_range range[MAX_MEMORY_COUNT];
30
31 char vendor[32];
32 char part[32];
33
34 char strings[10][64];
Uwe Hermann3a406fe2008-03-20 01:11:28 +000035
Jordan Crouse7249f792008-03-20 00:11:05 +000036 struct cb_serial serial;
37 struct cb_console console;
38} cb_info;
39
40static int tables_good = 0;
41
Uwe Hermann3a406fe2008-03-20 01:11:28 +000042int coreboot_module_redraw(WINDOW *win)
Jordan Crouse7249f792008-03-20 00:11:05 +000043{
44 int row = 2;
45 int i;
46
47 print_module_title(win, "Coreboot Tables");
48
49 if (tables_good) {
50 mvwprintw(win, row++, 2, "No Coreboot tables were found");
51 return 0;
52 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +000053
Jordan Crouse7249f792008-03-20 00:11:05 +000054 mvwprintw(win, row++, 2, "Vendor: %s", cb_info.vendor);
55 mvwprintw(win, row++, 2, "Part: %s", cb_info.part);
56
Uwe Hermann3a406fe2008-03-20 01:11:28 +000057 mvwprintw(win, row++, 2, "Version: %s%s",
58 cb_info.strings[CB_TAG_VERSION - 0x4],
59 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
Jordan Crouse7249f792008-03-20 00:11:05 +000060
61 mvwprintw(win, row++, 2, "Built: %s (%s@%s.%s)",
62 cb_info.strings[CB_TAG_BUILD - 0x4],
63 cb_info.strings[CB_TAG_COMPILE_BY - 0x04],
64 cb_info.strings[CB_TAG_COMPILE_HOST - 0x04],
65 cb_info.strings[CB_TAG_COMPILE_DOMAIN - 0x04]);
66
67 if (cb_info.serial.tag != 0x0) {
68 mvwprintw(win, row++, 2, "Serial Port I/O base: 0x%x",
Uwe Hermann3a406fe2008-03-20 01:11:28 +000069 cb_info.serial.ioport);
Jordan Crouse7249f792008-03-20 00:11:05 +000070 }
71
72 if (cb_info.console.tag != 0x0) {
73 mvwprintw(win, row++, 2, "Default Output Console: ");
Uwe Hermann3a406fe2008-03-20 01:11:28 +000074
75 switch (cb_info.console.type) {
Jordan Crouse7249f792008-03-20 00:11:05 +000076 case CB_TAG_CONSOLE_SERIAL8250:
77 wprintw(win, "Serial Port");
78 break;
79 case CB_TAG_CONSOLE_VGA:
80 wprintw(win, "VGA");
81 break;
82 case CB_TAG_CONSOLE_BTEXT:
83 wprintw(win, "BTEXT");
84 break;
85 case CB_TAG_CONSOLE_LOGBUF:
86 wprintw(win, "Log Buffer");
87 break;
88 case CB_TAG_CONSOLE_SROM:
89 wprintw(win, "Serial ROM");
90 break;
91 case CB_TAG_CONSOLE_EHCI:
92 wprintw(win, "USB Debug");
93 break;
94 }
95 }
96
97 row++;
98 mvwprintw(win, row++, 2, "-- Memory Map --");
Jordan Crouse7249f792008-03-20 00:11:05 +000099
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000100 for (i = 0; i < cb_info.mem_count; i++) {
101 switch (cb_info.range[i].type) {
Jordan Crouse7249f792008-03-20 00:11:05 +0000102 case CB_MEM_RAM:
103 mvwprintw(win, row++, 4, " RAM: ");
104 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000105 case CB_MEM_RESERVED:
106 mvwprintw(win, row++, 4, "Reserved: ");
107 break;
Jordan Crouse7249f792008-03-20 00:11:05 +0000108 case CB_MEM_TABLE:
109 mvwprintw(win, row++, 4, " Table: ");
110 }
111
112 wprintw(win, "%16.16llx - %16.16llx",
113 UNPACK_CB64(cb_info.range[i].start),
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000114 UNPACK_CB64(cb_info.range[i].start) +
Jordan Crouse7249f792008-03-20 00:11:05 +0000115 UNPACK_CB64(cb_info.range[i].size) - 1);
116 }
Uwe Hermann35845a22008-03-20 20:05:22 +0000117
118 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000119}
120
121static void parse_memory(unsigned char *ptr)
122{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000123 struct cb_memory *mem = (struct cb_memory *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000124 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000125 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
Jordan Crouse7249f792008-03-20 00:11:05 +0000126 int i;
127
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000128 for (i = 0; i < max; i++) {
129 struct cb_memory_range *range =
130 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
Jordan Crouse7249f792008-03-20 00:11:05 +0000131
132 memcpy(&cb_info.range[i], range, sizeof(*range));
133 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000134
Jordan Crouse7249f792008-03-20 00:11:05 +0000135 cb_info.mem_count = max;
136 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
137}
138
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000139static void parse_mainboard(unsigned char *ptr)
Jordan Crouse7249f792008-03-20 00:11:05 +0000140{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000141 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000142
Uwe Hermann35845a22008-03-20 20:05:22 +0000143 strncpy(cb_info.vendor, (const char *)MB_VENDOR_STRING(mb), 31);
144 strncpy(cb_info.part, (const char *)MB_PART_STRING(mb), 31);
Jordan Crouse7249f792008-03-20 00:11:05 +0000145}
146
147static void parse_strings(unsigned char *ptr)
148{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000149 struct cb_string *string = (struct cb_string *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000150 int index = string->tag - CB_TAG_VERSION;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000151
Uwe Hermann35845a22008-03-20 20:05:22 +0000152 strncpy(cb_info.strings[index], (const char *)string->string, 63);
Jordan Crouse7249f792008-03-20 00:11:05 +0000153 cb_info.strings[index][63] = 0;
154}
155
156static void parse_serial(unsigned char *ptr)
157{
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000158 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000159 sizeof(struct cb_serial));
160}
161
162static void parse_console(unsigned char *ptr)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000163{
164 memcpy(&cb_info.console, (struct cb_console *)ptr,
Jordan Crouse7249f792008-03-20 00:11:05 +0000165 sizeof(struct cb_console));
166}
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000167
Jordan Crouse7249f792008-03-20 00:11:05 +0000168static int parse_header(void *addr, int len)
169{
170 struct cb_header *header;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000171 unsigned char *ptr = (unsigned char *)addr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000172 int i;
173
174 for (i = 0; i < len; i += 16, ptr += 16) {
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000175 header = (struct cb_header *)ptr;
Jordan Crouse7249f792008-03-20 00:11:05 +0000176
Uwe Hermann35845a22008-03-20 20:05:22 +0000177 if (!strncmp((const char *)header->signature, "LBIO", 4))
Jordan Crouse7249f792008-03-20 00:11:05 +0000178 break;
179 }
180
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000181 /* We walked the entire space and didn't find anything. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000182 if (i >= len)
183 return -1;
184
185 if (!header->table_bytes)
186 return 0;
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000187
188 /* FIXME: Check the checksum. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000189
190 if (ipchksum((uint16_t *) header, sizeof(*header)))
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000191 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000192
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000193 if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes)
194 != header->table_checksum)
195 return -1;
Jordan Crouse7249f792008-03-20 00:11:05 +0000196
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000197 /* Now, walk the tables. */
Jordan Crouse7249f792008-03-20 00:11:05 +0000198 ptr += header->header_bytes;
199
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000200 for (i = 0; i < header->table_entries; i++) {
201 struct cb_record *rec = (struct cb_record *)ptr;
202
203 switch (rec->tag) {
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 = {
251 .name = "Coreboot",
252 .init = coreboot_module_init,
253 .redraw = coreboot_module_redraw,
254};