blob: 9eb13b73f1e5f7ca744fad3de3ed5eaaa215cb33 [file] [log] [blame]
Stefan Reinauerb883d4c2009-08-27 11:23:06 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2003-2004 Eric Biederman
5 * Copyright (C) 2005-2009 coresystems GmbH
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
Eric Biederman8ca8d762003-04-22 19:02:15 +000023#include <console/console.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000024#include <ip_checksum.h>
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000025#include <boot/tables.h>
Stefan Reinauerca374d42008-01-18 16:16:45 +000026#include <boot/coreboot_tables.h>
27#include "coreboot_table.h"
Eric Biederman8ca8d762003-04-22 19:02:15 +000028#include <string.h>
29#include <version.h>
Eric Biedermanb78c1972004-10-14 20:54:17 +000030#include <device/device.h>
31#include <stdlib.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000032
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000033static struct lb_header *lb_table_init(unsigned long addr)
Eric Biederman8ca8d762003-04-22 19:02:15 +000034{
35 struct lb_header *header;
36
37 /* 16 byte align the address */
38 addr += 15;
39 addr &= ~15;
40
41 header = (void *)addr;
42 header->signature[0] = 'L';
43 header->signature[1] = 'B';
44 header->signature[2] = 'I';
45 header->signature[3] = 'O';
46 header->header_bytes = sizeof(*header);
47 header->header_checksum = 0;
48 header->table_bytes = 0;
49 header->table_checksum = 0;
50 header->table_entries = 0;
51 return header;
52}
53
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000054static struct lb_record *lb_first_record(struct lb_header *header)
Eric Biederman8ca8d762003-04-22 19:02:15 +000055{
56 struct lb_record *rec;
57 rec = (void *)(((char *)header) + sizeof(*header));
58 return rec;
59}
60
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000061static struct lb_record *lb_last_record(struct lb_header *header)
Eric Biederman8ca8d762003-04-22 19:02:15 +000062{
63 struct lb_record *rec;
64 rec = (void *)(((char *)header) + sizeof(*header) + header->table_bytes);
65 return rec;
66}
67
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000068static struct lb_record *lb_next_record(struct lb_record *rec)
Eric Biederman8ca8d762003-04-22 19:02:15 +000069{
70 rec = (void *)(((char *)rec) + rec->size);
71 return rec;
72}
73
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000074static struct lb_record *lb_new_record(struct lb_header *header)
Eric Biederman8ca8d762003-04-22 19:02:15 +000075{
76 struct lb_record *rec;
77 rec = lb_last_record(header);
78 if (header->table_entries) {
79 header->table_bytes += rec->size;
80 }
81 rec = lb_last_record(header);
82 header->table_entries++;
83 rec->tag = LB_TAG_UNUSED;
84 rec->size = sizeof(*rec);
85 return rec;
86}
87
88
Stefan Reinauerb883d4c2009-08-27 11:23:06 +000089static struct lb_memory *lb_memory(struct lb_header *header)
Eric Biederman8ca8d762003-04-22 19:02:15 +000090{
91 struct lb_record *rec;
92 struct lb_memory *mem;
93 rec = lb_new_record(header);
94 mem = (struct lb_memory *)rec;
95 mem->tag = LB_TAG_MEMORY;
96 mem->size = sizeof(*mem);
97 return mem;
98}
99
Stefan Reinauerb883d4c2009-08-27 11:23:06 +0000100static struct lb_serial *lb_serial(struct lb_header *header)
Patrick Georgi8c2a0c12008-01-25 18:28:18 +0000101{
Myles Watsonec0ee642009-10-19 16:21:30 +0000102#if CONFIG_CONSOLE_SERIAL8250
Patrick Georgi8c2a0c12008-01-25 18:28:18 +0000103 struct lb_record *rec;
104 struct lb_serial *serial;
105 rec = lb_new_record(header);
106 serial = (struct lb_serial *)rec;
107 serial->tag = LB_TAG_SERIAL;
108 serial->size = sizeof(*serial);
Stefan Reinauer08670622009-06-30 15:17:49 +0000109 serial->ioport = CONFIG_TTYS0_BASE;
110 serial->baud = CONFIG_TTYS0_BAUD;
Patrick Georgi8c2a0c12008-01-25 18:28:18 +0000111 return serial;
112#else
113 return header;
114#endif
115}
116
Stefan Reinauerb883d4c2009-08-27 11:23:06 +0000117static void add_console(struct lb_header *header, u16 consoletype)
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000118{
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000119 struct lb_console *console;
Patrick Georgi16cdbb22009-04-21 20:14:31 +0000120
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000121 console = (struct lb_console *)lb_new_record(header);
122 console->tag = LB_TAG_CONSOLE;
123 console->size = sizeof(*console);
124 console->type = consoletype;
125}
126
Stefan Reinauerb883d4c2009-08-27 11:23:06 +0000127static void lb_console(struct lb_header *header)
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000128{
Myles Watsonec0ee642009-10-19 16:21:30 +0000129#if CONFIG_CONSOLE_SERIAL8250
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000130 add_console(header, LB_TAG_CONSOLE_SERIAL8250);
131#endif
Myles Watsonec0ee642009-10-19 16:21:30 +0000132#if CONFIG_CONSOLE_VGA
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000133 add_console(header, LB_TAG_CONSOLE_VGA);
134#endif
Myles Watsonec0ee642009-10-19 16:21:30 +0000135#if CONFIG_CONSOLE_BTEXT
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000136 add_console(header, LB_TAG_CONSOLE_BTEXT);
137#endif
Myles Watsonec0ee642009-10-19 16:21:30 +0000138#if CONFIG_CONSOLE_LOGBUF
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000139 add_console(header, LB_TAG_CONSOLE_LOGBUF);
140#endif
Myles Watsonec0ee642009-10-19 16:21:30 +0000141#if CONFIG_CONSOLE_SROM
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000142 add_console(header, LB_TAG_CONSOLE_SROM);
143#endif
Myles Watsonec0ee642009-10-19 16:21:30 +0000144#if CONFIG_USBDEBUG_DIRECT
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000145 add_console(header, LB_TAG_CONSOLE_EHCI);
146#endif
147}
148
Eric Biederman8ca8d762003-04-22 19:02:15 +0000149struct lb_mainboard *lb_mainboard(struct lb_header *header)
150{
151 struct lb_record *rec;
152 struct lb_mainboard *mainboard;
153 rec = lb_new_record(header);
154 mainboard = (struct lb_mainboard *)rec;
155 mainboard->tag = LB_TAG_MAINBOARD;
156
157 mainboard->size = (sizeof(*mainboard) +
158 strlen(mainboard_vendor) + 1 +
159 strlen(mainboard_part_number) + 1 +
160 3) & ~3;
161
162 mainboard->vendor_idx = 0;
163 mainboard->part_number_idx = strlen(mainboard_vendor) + 1;
164
165 memcpy(mainboard->strings + mainboard->vendor_idx,
166 mainboard_vendor, strlen(mainboard_vendor) + 1);
167 memcpy(mainboard->strings + mainboard->part_number_idx,
168 mainboard_part_number, strlen(mainboard_part_number) + 1);
169
170 return mainboard;
171}
172
Stefan Reinauerb883d4c2009-08-27 11:23:06 +0000173static struct cmos_checksum *lb_cmos_checksum(struct lb_header *header)
Stefan Reinauer4bd0de02005-12-03 22:39:23 +0000174{
175 struct lb_record *rec;
176 struct cmos_checksum *cmos_checksum;
177 rec = lb_new_record(header);
178 cmos_checksum = (struct cmos_checksum *)rec;
179 cmos_checksum->tag = LB_TAG_OPTION_CHECKSUM;
180
181 cmos_checksum->size = (sizeof(*cmos_checksum));
182
Stefan Reinauer08670622009-06-30 15:17:49 +0000183 cmos_checksum->range_start = CONFIG_LB_CKS_RANGE_START * 8;
184 cmos_checksum->range_end = ( CONFIG_LB_CKS_RANGE_END * 8 ) + 7;
185 cmos_checksum->location = CONFIG_LB_CKS_LOC * 8;
Stefan Reinauer4bd0de02005-12-03 22:39:23 +0000186 cmos_checksum->type = CHECKSUM_PCBIOS;
187
188 return cmos_checksum;
189}
190
Stefan Reinauerb883d4c2009-08-27 11:23:06 +0000191static void lb_strings(struct lb_header *header)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000192{
193 static const struct {
194 uint32_t tag;
Stefan Reinauer0dff6e32007-10-23 22:17:45 +0000195 const char *string;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000196 } strings[] = {
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000197 { LB_TAG_VERSION, coreboot_version, },
198 { LB_TAG_EXTRA_VERSION, coreboot_extra_version, },
199 { LB_TAG_BUILD, coreboot_build, },
200 { LB_TAG_COMPILE_TIME, coreboot_compile_time, },
201 { LB_TAG_COMPILE_BY, coreboot_compile_by, },
202 { LB_TAG_COMPILE_HOST, coreboot_compile_host, },
203 { LB_TAG_COMPILE_DOMAIN, coreboot_compile_domain, },
204 { LB_TAG_COMPILER, coreboot_compiler, },
205 { LB_TAG_LINKER, coreboot_linker, },
206 { LB_TAG_ASSEMBLER, coreboot_assembler, },
Eric Biederman8ca8d762003-04-22 19:02:15 +0000207 };
Eric Biederman52685572003-05-19 19:16:21 +0000208 unsigned int i;
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +0000209 for(i = 0; i < ARRAY_SIZE(strings); i++) {
Eric Biederman8ca8d762003-04-22 19:02:15 +0000210 struct lb_string *rec;
211 size_t len;
212 rec = (struct lb_string *)lb_new_record(header);
213 len = strlen(strings[i].string);
214 rec->tag = strings[i].tag;
215 rec->size = (sizeof(*rec) + len + 1 + 3) & ~3;
216 memcpy(rec->string, strings[i].string, len+1);
217 }
218
219}
220
Stefan Reinauerb883d4c2009-08-27 11:23:06 +0000221static struct lb_forward *lb_forward(struct lb_header *header, struct lb_header *next_header)
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000222{
223 struct lb_record *rec;
224 struct lb_forward *forward;
225 rec = lb_new_record(header);
226 forward = (struct lb_forward *)rec;
227 forward->tag = LB_TAG_FORWARD;
228 forward->size = sizeof(*forward);
Stefan Reinauerdf77f342009-04-06 14:00:53 +0000229 forward->forward = (uint64_t)(unsigned long)next_header;
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000230 return forward;
231}
232
Eric Biederman8ca8d762003-04-22 19:02:15 +0000233void lb_memory_range(struct lb_memory *mem,
Eric Biederman6e53f502004-10-27 08:53:57 +0000234 uint32_t type, uint64_t start, uint64_t size)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000235{
236 int entries;
237 entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]);
Eric Biedermanec01aa92004-12-10 20:50:43 +0000238 mem->map[entries].start = pack_lb64(start);
239 mem->map[entries].size = pack_lb64(size);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000240 mem->map[entries].type = type;
241 mem->size += sizeof(mem->map[0]);
242}
243
Eric Biederman8ca8d762003-04-22 19:02:15 +0000244static void lb_reserve_table_memory(struct lb_header *head)
245{
246 struct lb_record *last_rec;
247 struct lb_memory *mem;
248 uint64_t start;
249 uint64_t end;
250 int i, entries;
251
252 last_rec = lb_last_record(head);
253 mem = get_lb_mem();
254 start = (unsigned long)head;
255 end = (unsigned long)last_rec;
256 entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]);
257 /* Resize the right two memory areas so this table is in
258 * a reserved area of memory. Everything has been carefully
259 * setup so that is all we need to do.
260 */
261 for(i = 0; i < entries; i++ ) {
Eric Biedermanec01aa92004-12-10 20:50:43 +0000262 uint64_t map_start = unpack_lb64(mem->map[i].start);
263 uint64_t map_end = map_start + unpack_lb64(mem->map[i].size);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000264 /* Does this area need to be expanded? */
265 if (map_end == start) {
Eric Biedermanec01aa92004-12-10 20:50:43 +0000266 mem->map[i].size = pack_lb64(end - map_start);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000267 }
268 /* Does this area need to be contracted? */
269 else if (map_start == start) {
Eric Biedermanec01aa92004-12-10 20:50:43 +0000270 mem->map[i].start = pack_lb64(end);
271 mem->map[i].size = pack_lb64(map_end - end);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000272 }
273 }
274}
275
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000276static unsigned long lb_table_fini(struct lb_header *head, int fixup)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000277{
278 struct lb_record *rec, *first_rec;
279 rec = lb_last_record(head);
280 if (head->table_entries) {
281 head->table_bytes += rec->size;
282 }
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000283
284 if (fixup)
285 lb_reserve_table_memory(head);
286
Eric Biederman8ca8d762003-04-22 19:02:15 +0000287 first_rec = lb_first_record(head);
288 head->table_checksum = compute_ip_checksum(first_rec, head->table_bytes);
289 head->header_checksum = 0;
290 head->header_checksum = compute_ip_checksum(head, sizeof(*head));
Myles Watsonc4ddbff2009-02-09 17:52:54 +0000291 printk_debug("Wrote coreboot table at: %p - %p checksum %x\n",
Eric Biederman8ca8d762003-04-22 19:02:15 +0000292 head, rec, head->table_checksum);
293 return (unsigned long)rec;
294}
295
Eric Biederman6e53f502004-10-27 08:53:57 +0000296static void lb_cleanup_memory_ranges(struct lb_memory *mem)
297{
298 int entries;
299 int i, j;
300 entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]);
301
302 /* Sort the lb memory ranges */
303 for(i = 0; i < entries; i++) {
Eric Biedermanec01aa92004-12-10 20:50:43 +0000304 uint64_t entry_start = unpack_lb64(mem->map[i].start);
Eric Biederman6e53f502004-10-27 08:53:57 +0000305 for(j = i; j < entries; j++) {
Eric Biedermanec01aa92004-12-10 20:50:43 +0000306 uint64_t temp_start = unpack_lb64(mem->map[j].start);
307 if (temp_start < entry_start) {
Eric Biederman6e53f502004-10-27 08:53:57 +0000308 struct lb_memory_range tmp;
309 tmp = mem->map[i];
310 mem->map[i] = mem->map[j];
311 mem->map[j] = tmp;
312 }
313 }
314 }
315
316 /* Merge adjacent entries */
317 for(i = 0; (i + 1) < entries; i++) {
318 uint64_t start, end, nstart, nend;
319 if (mem->map[i].type != mem->map[i + 1].type) {
320 continue;
321 }
Eric Biedermanec01aa92004-12-10 20:50:43 +0000322 start = unpack_lb64(mem->map[i].start);
323 end = start + unpack_lb64(mem->map[i].size);
324 nstart = unpack_lb64(mem->map[i + 1].start);
325 nend = nstart + unpack_lb64(mem->map[i + 1].size);
Eric Biederman6e53f502004-10-27 08:53:57 +0000326 if ((start <= nstart) && (end > nstart)) {
327 if (start > nstart) {
328 start = nstart;
329 }
330 if (end < nend) {
331 end = nend;
332 }
333 /* Record the new region size */
Eric Biedermanec01aa92004-12-10 20:50:43 +0000334 mem->map[i].start = pack_lb64(start);
335 mem->map[i].size = pack_lb64(end - start);
Eric Biederman6e53f502004-10-27 08:53:57 +0000336
337 /* Delete the entry I have merged with */
338 memmove(&mem->map[i + 1], &mem->map[i + 2],
339 ((entries - i - 2) * sizeof(mem->map[0])));
340 mem->size -= sizeof(mem->map[0]);
341 entries -= 1;
342 /* See if I can merge with the next entry as well */
343 i -= 1;
344 }
345 }
346}
347
348static void lb_remove_memory_range(struct lb_memory *mem,
349 uint64_t start, uint64_t size)
350{
351 uint64_t end;
352 int entries;
353 int i;
354
355 end = start + size;
356 entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]);
357
358 /* Remove a reserved area from the memory map */
359 for(i = 0; i < entries; i++) {
Eric Biedermanec01aa92004-12-10 20:50:43 +0000360 uint64_t map_start = unpack_lb64(mem->map[i].start);
361 uint64_t map_end = map_start + unpack_lb64(mem->map[i].size);
Eric Biederman6e53f502004-10-27 08:53:57 +0000362 if ((start <= map_start) && (end >= map_end)) {
363 /* Remove the completely covered range */
364 memmove(&mem->map[i], &mem->map[i + 1],
365 ((entries - i - 1) * sizeof(mem->map[0])));
366 mem->size -= sizeof(mem->map[0]);
367 entries -= 1;
368 /* Since the index will disappear revisit what will appear here */
369 i -= 1;
370 }
371 else if ((start > map_start) && (end < map_end)) {
372 /* Split the memory range */
373 memmove(&mem->map[i + 1], &mem->map[i],
374 ((entries - i) * sizeof(mem->map[0])));
375 mem->size += sizeof(mem->map[0]);
376 entries += 1;
377 /* Update the first map entry */
Eric Biedermanec01aa92004-12-10 20:50:43 +0000378 mem->map[i].size = pack_lb64(start - map_start);
Eric Biederman6e53f502004-10-27 08:53:57 +0000379 /* Update the second map entry */
Eric Biedermanec01aa92004-12-10 20:50:43 +0000380 mem->map[i + 1].start = pack_lb64(end);
381 mem->map[i + 1].size = pack_lb64(map_end - end);
Eric Biederman6e53f502004-10-27 08:53:57 +0000382 /* Don't bother with this map entry again */
383 i += 1;
384 }
385 else if ((start <= map_start) && (end > map_start)) {
386 /* Shrink the start of the memory range */
Eric Biedermanec01aa92004-12-10 20:50:43 +0000387 mem->map[i].start = pack_lb64(end);
388 mem->map[i].size = pack_lb64(map_end - end);
Eric Biederman6e53f502004-10-27 08:53:57 +0000389 }
390 else if ((start < map_end) && (start > map_start)) {
391 /* Shrink the end of the memory range */
Eric Biedermanec01aa92004-12-10 20:50:43 +0000392 mem->map[i].size = pack_lb64(start - map_start);
Eric Biederman6e53f502004-10-27 08:53:57 +0000393 }
394 }
395}
396
Stefan Reinauer045c3482008-12-13 20:51:34 +0000397/* This function is used in mainboard specific code, too */
398void lb_add_memory_range(struct lb_memory *mem,
Eric Biederman6e53f502004-10-27 08:53:57 +0000399 uint32_t type, uint64_t start, uint64_t size)
400{
401 lb_remove_memory_range(mem, start, size);
402 lb_memory_range(mem, type, start, size);
403 lb_cleanup_memory_ranges(mem);
404}
Eric Biederman8ca8d762003-04-22 19:02:15 +0000405
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000406/* Routines to extract part so the coreboot table or
407 * information from the coreboot table after we have written it.
Eric Biederman8ca8d762003-04-22 19:02:15 +0000408 * Currently get_lb_mem relies on a global we can change the
409 * implementaiton.
410 */
411static struct lb_memory *mem_ranges = 0;
412struct lb_memory *get_lb_mem(void)
413{
414 return mem_ranges;
415}
416
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000417static void build_lb_mem_range(void *gp, struct device *dev, struct resource *res)
418{
419 struct lb_memory *mem = gp;
420 lb_memory_range(mem, LB_MEM_RAM, res->base, res->size);
421}
422
Eric Biederman6e53f502004-10-27 08:53:57 +0000423static struct lb_memory *build_lb_mem(struct lb_header *head)
Eric Biedermanb78c1972004-10-14 20:54:17 +0000424{
Eric Biederman6e53f502004-10-27 08:53:57 +0000425 struct lb_memory *mem;
Eric Biedermanb78c1972004-10-14 20:54:17 +0000426
Eric Biederman6e53f502004-10-27 08:53:57 +0000427 /* Record where the lb memory ranges will live */
428 mem = lb_memory(head);
429 mem_ranges = mem;
430
431 /* Build the raw table of memory */
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000432 search_global_resources(
433 IORESOURCE_MEM | IORESOURCE_CACHEABLE, IORESOURCE_MEM | IORESOURCE_CACHEABLE,
434 build_lb_mem_range, mem);
Eric Biederman6e53f502004-10-27 08:53:57 +0000435 lb_cleanup_memory_ranges(mem);
Eric Biedermanb78c1972004-10-14 20:54:17 +0000436 return mem;
437}
438
Myles Watsonb8e20272009-10-15 13:35:47 +0000439#if CONFIG_WRITE_HIGH_TABLES == 1
Patrick Georgibccaafc2009-04-28 12:57:25 +0000440extern uint64_t high_tables_base, high_tables_size;
441#endif
442
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000443unsigned long write_coreboot_table(
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000444 unsigned long low_table_start, unsigned long low_table_end,
445 unsigned long rom_table_start, unsigned long rom_table_end)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000446{
Eric Biederman8ca8d762003-04-22 19:02:15 +0000447 struct lb_header *head;
448 struct lb_memory *mem;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000449
Myles Watsonb8e20272009-10-15 13:35:47 +0000450#if CONFIG_WRITE_HIGH_TABLES == 1
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000451 printk_debug("Writing high table forward entry at 0x%08lx\n",
452 low_table_end);
453 head = lb_table_init(low_table_end);
Myles Watsonfa12b672009-04-30 22:45:41 +0000454 lb_forward(head, (struct lb_header*)rom_table_end);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000455
Patrick Georgibab4f922009-05-26 19:39:14 +0000456 low_table_end = (unsigned long) lb_table_fini(head, 0);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000457 printk_debug("New low_table_end: 0x%08lx\n", low_table_end);
458 printk_debug("Now going to write high coreboot table at 0x%08lx\n",
459 rom_table_end);
460
461 head = lb_table_init(rom_table_end);
462 rom_table_end = (unsigned long)head;
463 printk_debug("rom_table_end = 0x%08lx\n", rom_table_end);
464#else
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000465 if(low_table_end > (0x1000 - sizeof(struct lb_header))) { /* after 4K */
466 /* We need to put lbtable on to [0xf0000,0x100000) */
467 head = lb_table_init(rom_table_end);
468 rom_table_end = (unsigned long)head;
469 } else {
470 head = lb_table_init(low_table_end);
471 low_table_end = (unsigned long)head;
472 }
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000473#endif
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000474
Myles Watsonc4ddbff2009-02-09 17:52:54 +0000475 printk_debug("Adjust low_table_end from 0x%08lx to ", low_table_end);
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000476 low_table_end += 0xfff; // 4K aligned
477 low_table_end &= ~0xfff;
Myles Watsonc4ddbff2009-02-09 17:52:54 +0000478 printk_debug("0x%08lx \n", low_table_end);
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000479
480 /* The Linux kernel assumes this region is reserved */
Myles Watsonc4ddbff2009-02-09 17:52:54 +0000481 printk_debug("Adjust rom_table_end from 0x%08lx to ", rom_table_end);
Yinghai Lu47cb7c72007-04-06 20:27:40 +0000482 rom_table_end += 0xffff; // 64K align
483 rom_table_end &= ~0xffff;
Myles Watsonc4ddbff2009-02-09 17:52:54 +0000484 printk_debug("0x%08lx \n", rom_table_end);
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000485
Stefan Reinauer08670622009-06-30 15:17:49 +0000486#if (CONFIG_HAVE_OPTION_TABLE == 1)
Stefan Reinauerba430642007-04-06 12:14:51 +0000487 {
Eric Biederman6e53f502004-10-27 08:53:57 +0000488 struct lb_record *rec_dest, *rec_src;
489 /* Write the option config table... */
490 rec_dest = lb_new_record(head);
Eric Biedermana9e632c2004-11-18 22:38:08 +0000491 rec_src = (struct lb_record *)(void *)&option_table;
Eric Biederman6e53f502004-10-27 08:53:57 +0000492 memcpy(rec_dest, rec_src, rec_src->size);
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000493 /* Create cmos checksum entry in coreboot table */
Stefan Reinauer4bd0de02005-12-03 22:39:23 +0000494 lb_cmos_checksum(head);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000495 }
Stefan Reinauerba430642007-04-06 12:14:51 +0000496#endif
Eric Biederman6e53f502004-10-27 08:53:57 +0000497 /* Record where RAM is located */
498 mem = build_lb_mem(head);
499
Eric Biederman6e53f502004-10-27 08:53:57 +0000500 /* Record the mptable and the the lb_table (This will be adjusted later) */
501 lb_add_memory_range(mem, LB_MEM_TABLE,
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000502 low_table_start, low_table_end - low_table_start);
Eric Biederman6e53f502004-10-27 08:53:57 +0000503
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000504 /* Record the pirq table, acpi tables, and maybe the mptable */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000505 lb_add_memory_range(mem, LB_MEM_TABLE,
Roman Kononov96e30222008-07-23 23:22:59 +0000506 rom_table_start, rom_table_end-rom_table_start);
Eric Biederman6e53f502004-10-27 08:53:57 +0000507
Myles Watsonb8e20272009-10-15 13:35:47 +0000508#if CONFIG_WRITE_HIGH_TABLES == 1
Patrick Georgibccaafc2009-04-28 12:57:25 +0000509 printk_debug("Adding high table area\n");
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000510 // should this be LB_MEM_ACPI?
Patrick Georgibccaafc2009-04-28 12:57:25 +0000511 lb_add_memory_range(mem, LB_MEM_TABLE,
512 high_tables_base, high_tables_size);
513#endif
514
Stefan Reinauer08670622009-06-30 15:17:49 +0000515#if (CONFIG_HAVE_MAINBOARD_RESOURCES == 1)
Stefan Reinauer045c3482008-12-13 20:51:34 +0000516 add_mainboard_resources(mem);
Michael Xie06755e42008-09-22 13:07:20 +0000517#endif
518
Eric Biederman6e53f502004-10-27 08:53:57 +0000519 /* Note:
520 * I assume that there is always memory at immediately after
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000521 * the low_table_end. This means that after I setup the coreboot table.
Eric Biederman6e53f502004-10-27 08:53:57 +0000522 * I can trivially fixup the reserved memory ranges to hold the correct
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000523 * size of the coreboot table.
Eric Biederman6e53f502004-10-27 08:53:57 +0000524 */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000525
Patrick Georgi8c2a0c12008-01-25 18:28:18 +0000526 /* Record our motherboard */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000527 lb_mainboard(head);
Patrick Georgi8c2a0c12008-01-25 18:28:18 +0000528 /* Record the serial port, if present */
529 lb_serial(head);
Patrick Georgi3bbf2ff2008-01-27 14:12:54 +0000530 /* Record our console setup */
531 lb_console(head);
Eric Biederman8ca8d762003-04-22 19:02:15 +0000532 /* Record our various random string information */
533 lb_strings(head);
534
Eric Biederman8ca8d762003-04-22 19:02:15 +0000535 /* Remember where my valid memory ranges are */
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000536 return lb_table_fini(head, 1);
Stefan Reinauer4f1cb232006-07-19 15:32:49 +0000537
Eric Biederman8ca8d762003-04-22 19:02:15 +0000538}