2 * This file is part of the coreinfo project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
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.
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.
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
20 #include <coreboot_tables.h>
23 #define MAX_MEMORY_COUNT 5
29 struct cb_memory_range range[MAX_MEMORY_COUNT];
36 struct cb_serial serial;
37 struct cb_console console;
40 static int tables_good = 0;
42 int coreboot_module_redraw(WINDOW *win)
47 print_module_title(win, "Coreboot Tables");
50 mvwprintw(win, row++, 2, "No Coreboot tables were found");
54 mvwprintw(win, row++, 2, "Vendor: %s", cb_info.vendor);
55 mvwprintw(win, row++, 2, "Part: %s", cb_info.part);
57 mvwprintw(win, row++, 2, "Version: %s%s",
58 cb_info.strings[CB_TAG_VERSION - 0x4],
59 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
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]);
67 if (cb_info.serial.tag != 0x0) {
68 mvwprintw(win, row++, 2, "Serial Port I/O base: 0x%x",
69 cb_info.serial.ioport);
72 if (cb_info.console.tag != 0x0) {
73 mvwprintw(win, row++, 2, "Default Output Console: ");
75 switch (cb_info.console.type) {
76 case CB_TAG_CONSOLE_SERIAL8250:
77 wprintw(win, "Serial Port");
79 case CB_TAG_CONSOLE_VGA:
82 case CB_TAG_CONSOLE_BTEXT:
83 wprintw(win, "BTEXT");
85 case CB_TAG_CONSOLE_LOGBUF:
86 wprintw(win, "Log Buffer");
88 case CB_TAG_CONSOLE_SROM:
89 wprintw(win, "Serial ROM");
91 case CB_TAG_CONSOLE_EHCI:
92 wprintw(win, "USB Debug");
98 mvwprintw(win, row++, 2, "-- Memory Map --");
100 for (i = 0; i < cb_info.mem_count; i++) {
101 switch (cb_info.range[i].type) {
103 mvwprintw(win, row++, 4, " RAM: ");
105 case CB_MEM_RESERVED:
106 mvwprintw(win, row++, 4, "Reserved: ");
109 mvwprintw(win, row++, 4, " Table: ");
112 wprintw(win, "%16.16llx - %16.16llx",
113 UNPACK_CB64(cb_info.range[i].start),
114 UNPACK_CB64(cb_info.range[i].start) +
115 UNPACK_CB64(cb_info.range[i].size) - 1);
121 static void parse_memory(unsigned char *ptr)
123 struct cb_memory *mem = (struct cb_memory *)ptr;
125 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
126 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
129 for (i = 0; i < max; i++) {
130 struct cb_memory_range *range =
131 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
133 memcpy(&cb_info.range[i], range, sizeof(*range));
136 cb_info.mem_count = max;
137 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
140 static void parse_mainboard(unsigned char *ptr)
142 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
144 strncpy(cb_info.vendor, (const char *)MB_VENDOR_STRING(mb), 31);
145 strncpy(cb_info.part, (const char *)MB_PART_STRING(mb), 31);
148 static void parse_strings(unsigned char *ptr)
150 struct cb_string *string = (struct cb_string *)ptr;
151 int index = string->tag - CB_TAG_VERSION;
153 strncpy(cb_info.strings[index], (const char *)string->string, 63);
154 cb_info.strings[index][63] = 0;
157 static void parse_serial(unsigned char *ptr)
159 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
160 sizeof(struct cb_serial));
163 static void parse_console(unsigned char *ptr)
165 memcpy(&cb_info.console, (struct cb_console *)ptr,
166 sizeof(struct cb_console));
169 static int parse_header(void *addr, int len)
171 struct cb_header *header;
172 unsigned char *ptr = (unsigned char *)addr;
175 for (i = 0; i < len; i += 16, ptr += 16) {
176 header = (struct cb_header *)ptr;
178 if (!strncmp((const char *)header->signature, "LBIO", 4))
182 /* We walked the entire space and didn't find anything. */
186 if (!header->table_bytes)
189 /* FIXME: Check the checksum. */
191 if (ipchksum((uint16_t *) header, sizeof(*header)))
194 if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes)
195 != header->table_checksum)
198 /* Now, walk the tables. */
199 ptr += header->header_bytes;
201 for (i = 0; i < header->table_entries; i++) {
202 struct cb_record *rec = (struct cb_record *)ptr;
208 case CB_TAG_MAINBOARD:
209 parse_mainboard(ptr);
212 case CB_TAG_EXTRA_VERSION:
214 case CB_TAG_COMPILE_TIME:
215 case CB_TAG_COMPILE_BY:
216 case CB_TAG_COMPILE_HOST:
217 case CB_TAG_COMPILE_DOMAIN:
218 case CB_TAG_COMPILER:
220 case CB_TAG_ASSEMBLER:
239 int coreboot_module_init(void)
241 int ret = parse_header((void *)0x00000, 0x1000);
244 ret = parse_header((void *)0xf0000, 0x1000);
246 /* Return error if we couldn't find it at either address. */
247 tables_good = (ret == 1) ? 0 : -1;
251 struct coreinfo_module coreboot_module = {
253 .init = coreboot_module_init,
254 .redraw = coreboot_module_redraw,