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.
17 #include <coreboot_tables.h>
19 #if CONFIG(MODULE_COREBOOT)
21 #define MAX_MEMORY_COUNT 5
27 struct cb_memory_range range
[MAX_MEMORY_COUNT
];
34 struct cb_serial serial
;
35 struct cb_console console
;
38 static int tables_good
= 0;
40 static int coreboot_module_redraw(WINDOW
*win
)
45 print_module_title(win
, "coreboot Tables");
48 mvwprintw(win
, row
++, 1, "No coreboot tables were found");
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");
77 case CB_TAG_CONSOLE_VGA
:
80 case CB_TAG_CONSOLE_BTEXT
:
81 wprintw(win
, "BTEXT");
83 case CB_TAG_CONSOLE_LOGBUF
:
84 wprintw(win
, "Log Buffer");
86 case CB_TAG_CONSOLE_SROM
:
87 wprintw(win
, "Serial ROM");
89 case CB_TAG_CONSOLE_EHCI
:
90 wprintw(win
, "USB Debug");
96 mvwprintw(win
, row
++, 1, "-- Memory Map --");
98 for (i
= 0; i
< cb_info
.mem_count
; i
++) {
99 switch (cb_info
.range
[i
].type
) {
101 mvwprintw(win
, row
++, 3, " RAM: ");
103 case CB_MEM_RESERVED
:
104 mvwprintw(win
, row
++, 3, "Reserved: ");
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);
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
);
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
;
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))
179 /* We walked the entire space and didn't find anything. */
183 if (!header
->table_bytes
)
186 /* FIXME: Check the checksum. */
188 if (cb_checksum(header
, sizeof(*header
)))
191 if (cb_checksum((ptr
+ sizeof(*header
)), header
->table_bytes
)
192 != header
->table_checksum
)
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
;
203 return parse_header((void *)(unsigned long)((struct cb_forward
*)rec
)->forward
, 1);
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 static 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
,
259 struct coreinfo_module coreboot_module
= {