Documentation/releases: Finalize 4.11, start 4.12
[coreboot.git] / payloads / coreinfo / coreboot_module.c
blobe56ce68ed606ca96dc9cf0ad9b8a7e90dedc2f5f
1 /*
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.
16 #include "coreinfo.h"
17 #include <coreboot_tables.h>
19 #if CONFIG(MODULE_COREBOOT)
21 #define MAX_MEMORY_COUNT 5
23 static struct {
24 int mem_count;
25 int mem_actual;
27 struct cb_memory_range range[MAX_MEMORY_COUNT];
29 char vendor[32];
30 char part[32];
32 char strings[10][64];
34 struct cb_serial serial;
35 struct cb_console console;
36 } cb_info;
38 static int tables_good = 0;
40 static int coreboot_module_redraw(WINDOW *win)
42 int row = 2;
43 int i;
45 print_module_title(win, "coreboot Tables");
47 if (tables_good) {
48 mvwprintw(win, row++, 1, "No coreboot tables were found");
49 return 0;
52 mvwprintw(win, row++, 1, "Vendor: %s", cb_info.vendor);
53 mvwprintw(win, row++, 1, "Part: %s", cb_info.part);
55 mvwprintw(win, row++, 1, "Version: %s%s",
56 cb_info.strings[CB_TAG_VERSION - 0x4],
57 cb_info.strings[CB_TAG_EXTRA_VERSION - 0x4]);
59 mvwprintw(win, row++, 1, "Built: %s (%s@%s.%s)",
60 cb_info.strings[CB_TAG_BUILD - 0x4],
61 cb_info.strings[CB_TAG_COMPILE_BY - 0x04],
62 cb_info.strings[CB_TAG_COMPILE_HOST - 0x04],
63 cb_info.strings[CB_TAG_COMPILE_DOMAIN - 0x04]);
65 if (cb_info.serial.tag != 0x0) {
66 mvwprintw(win, row++, 1, "Serial Port I/O base: 0x%x",
67 cb_info.serial.baseaddr);
70 if (cb_info.console.tag != 0x0) {
71 mvwprintw(win, row++, 1, "Default Output Console: ");
73 switch (cb_info.console.type) {
74 case CB_TAG_CONSOLE_SERIAL8250:
75 wprintw(win, "Serial Port");
76 break;
77 case CB_TAG_CONSOLE_VGA:
78 wprintw(win, "VGA");
79 break;
80 case CB_TAG_CONSOLE_BTEXT:
81 wprintw(win, "BTEXT");
82 break;
83 case CB_TAG_CONSOLE_LOGBUF:
84 wprintw(win, "Log Buffer");
85 break;
86 case CB_TAG_CONSOLE_SROM:
87 wprintw(win, "Serial ROM");
88 break;
89 case CB_TAG_CONSOLE_EHCI:
90 wprintw(win, "USB Debug");
91 break;
95 row++;
96 mvwprintw(win, row++, 1, "-- Memory Map --");
98 for (i = 0; i < cb_info.mem_count; i++) {
99 switch (cb_info.range[i].type) {
100 case CB_MEM_RAM:
101 mvwprintw(win, row++, 3, " RAM: ");
102 break;
103 case CB_MEM_RESERVED:
104 mvwprintw(win, row++, 3, "Reserved: ");
105 break;
106 case CB_MEM_TABLE:
107 mvwprintw(win, row++, 3, " Table: ");
110 wprintw(win, "%16.16llx - %16.16llx",
111 cb_unpack64(cb_info.range[i].start),
112 cb_unpack64(cb_info.range[i].start) +
113 cb_unpack64(cb_info.range[i].size) - 1);
116 return 0;
119 static void parse_memory(unsigned char *ptr)
121 struct cb_memory *mem = (struct cb_memory *)ptr;
122 int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
123 ? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
124 int i;
126 for (i = 0; i < max; i++) {
127 struct cb_memory_range *range =
128 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
130 memcpy(&cb_info.range[i], range, sizeof(*range));
133 cb_info.mem_count = max;
134 cb_info.mem_actual = MEM_RANGE_COUNT(mem);
137 static void parse_mainboard(unsigned char *ptr)
139 struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
141 strncpy(cb_info.vendor, cb_mb_vendor_string(mb), sizeof(cb_info.vendor) - 1);
142 strncpy(cb_info.part, cb_mb_part_string(mb), sizeof(cb_info.part) - 1);
145 static void parse_strings(unsigned char *ptr)
147 struct cb_string *string = (struct cb_string *)ptr;
148 int index = string->tag - CB_TAG_VERSION;
150 strncpy(cb_info.strings[index], (const char *)string->string, 63);
151 cb_info.strings[index][63] = 0;
154 static void parse_serial(unsigned char *ptr)
156 memcpy(&cb_info.serial, (struct cb_serial *)ptr,
157 sizeof(struct cb_serial));
160 static void parse_console(unsigned char *ptr)
162 memcpy(&cb_info.console, (struct cb_console *)ptr,
163 sizeof(struct cb_console));
166 static int parse_header(void *addr, int len)
168 struct cb_header *header;
169 unsigned char *ptr = (unsigned char *)addr;
170 int i;
172 for (i = 0; i < len; i += 16, ptr += 16) {
173 header = (struct cb_header *)ptr;
175 if (!strncmp((const char *)header->signature, "LBIO", 4))
176 break;
179 /* We walked the entire space and didn't find anything. */
180 if (i >= len)
181 return -1;
183 if (!header->table_bytes)
184 return 0;
186 /* FIXME: Check the checksum. */
188 if (cb_checksum(header, sizeof(*header)))
189 return -1;
191 if (cb_checksum((ptr + sizeof(*header)), header->table_bytes)
192 != header->table_checksum)
193 return -1;
195 /* Now, walk the tables. */
196 ptr += header->header_bytes;
198 for (u32 j = 0; j < header->table_entries; j++) {
199 struct cb_record *rec = (struct cb_record *)ptr;
201 switch (rec->tag) {
202 case CB_TAG_FORWARD:
203 return parse_header((void *)(unsigned long)((struct cb_forward *)rec)->forward, 1);
204 break;
205 case CB_TAG_MEMORY:
206 parse_memory(ptr);
207 break;
208 case CB_TAG_MAINBOARD:
209 parse_mainboard(ptr);
210 break;
211 case CB_TAG_VERSION:
212 case CB_TAG_EXTRA_VERSION:
213 case CB_TAG_BUILD:
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:
219 case CB_TAG_LINKER:
220 case CB_TAG_ASSEMBLER:
221 parse_strings(ptr);
222 break;
223 case CB_TAG_SERIAL:
224 parse_serial(ptr);
225 break;
226 case CB_TAG_CONSOLE:
227 parse_console(ptr);
228 break;
229 default:
230 break;
233 ptr += rec->size;
236 return 1;
239 static int coreboot_module_init(void)
241 int ret = parse_header((void *)0x00000, 0x1000);
243 if (ret != 1)
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;
248 return tables_good;
251 struct coreinfo_module coreboot_module = {
252 .name = "coreboot",
253 .init = coreboot_module_init,
254 .redraw = coreboot_module_redraw,
257 #else
259 struct coreinfo_module coreboot_module = {
262 #endif