printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / arch / i386 / boot / coreboot_table.c
index 900ab7c10647e36c0961c31f2b1ac62ff0749a61..8baaab4f600190fa74e8ec8242b7a590e113bf91 100644 (file)
@@ -1,13 +1,36 @@
+/*
+ * This file is part of the coreboot project.
+ * 
+ * Copyright (C) 2003-2004 Eric Biederman
+ * Copyright (C) 2005-2009 coresystems GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 of
+ * the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
 #include <console/console.h>
 #include <ip_checksum.h>
+#include <boot/tables.h>
 #include <boot/coreboot_tables.h>
-#include "coreboot_table.h"
+#include <arch/coreboot_tables.h>
 #include <string.h>
 #include <version.h>
 #include <device/device.h>
 #include <stdlib.h>
 
-struct lb_header *lb_table_init(unsigned long addr)
+static struct lb_header *lb_table_init(unsigned long addr)
 {
        struct lb_header *header;
 
@@ -28,27 +51,29 @@ struct lb_header *lb_table_init(unsigned long addr)
        return header;
 }
 
-struct lb_record *lb_first_record(struct lb_header *header)
+static struct lb_record *lb_first_record(struct lb_header *header)
 {
        struct lb_record *rec;
        rec = (void *)(((char *)header) + sizeof(*header));
        return rec;
 }
 
-struct lb_record *lb_last_record(struct lb_header *header)
+static struct lb_record *lb_last_record(struct lb_header *header)
 {
        struct lb_record *rec;
        rec = (void *)(((char *)header) + sizeof(*header) + header->table_bytes);
        return rec;
 }
 
-struct lb_record *lb_next_record(struct lb_record *rec)
+#if 0
+static struct lb_record *lb_next_record(struct lb_record *rec)
 {
        rec = (void *)(((char *)rec) + rec->size);      
        return rec;
 }
+#endif
 
-struct lb_record *lb_new_record(struct lb_header *header)
+static struct lb_record *lb_new_record(struct lb_header *header)
 {
        struct lb_record *rec;
        rec = lb_last_record(header);
@@ -63,7 +88,7 @@ struct lb_record *lb_new_record(struct lb_header *header)
 }
 
 
-struct lb_memory *lb_memory(struct lb_header *header)
+static struct lb_memory *lb_memory(struct lb_header *header)
 {
        struct lb_record *rec;
        struct lb_memory *mem;
@@ -74,57 +99,69 @@ struct lb_memory *lb_memory(struct lb_header *header)
        return mem;
 }
 
-struct lb_serial *lb_serial(struct lb_header *header)
+static struct lb_serial *lb_serial(struct lb_header *header)
 {
-#if defined(TTYS0_BASE)
+#if CONFIG_CONSOLE_SERIAL8250
        struct lb_record *rec;
        struct lb_serial *serial;
        rec = lb_new_record(header);
        serial = (struct lb_serial *)rec;
        serial->tag = LB_TAG_SERIAL;
        serial->size = sizeof(*serial);
-       serial->ioport = TTYS0_BASE;
-       serial->baud = TTYS0_BAUD;
+       serial->ioport = CONFIG_TTYS0_BASE;
+       serial->baud = CONFIG_TTYS0_BAUD;
        return serial;
 #else
        return header;
 #endif
 }
 
-void add_console(struct lb_header *header, u16 consoletype)
+static void add_console(struct lb_header *header, u16 consoletype)
 {
-       struct lb_record *rec;
        struct lb_console *console;
-       rec = lb_new_record(header);
+
        console = (struct lb_console *)lb_new_record(header);
        console->tag = LB_TAG_CONSOLE;
        console->size = sizeof(*console);
        console->type = consoletype;
 }
 
-void lb_console(struct lb_header *header)
+static void lb_console(struct lb_header *header)
 {
-#ifdef CONFIG_CONSOLE_SERIAL8250
+#if CONFIG_CONSOLE_SERIAL8250
        add_console(header, LB_TAG_CONSOLE_SERIAL8250);
 #endif
-#ifdef CONFIG_CONSOLE_VGA
+#if CONFIG_CONSOLE_VGA
        add_console(header, LB_TAG_CONSOLE_VGA);
 #endif
-#ifdef CONFIG_CONSOLE_BTEXT
+#if CONFIG_CONSOLE_BTEXT
        add_console(header, LB_TAG_CONSOLE_BTEXT);
 #endif
-#ifdef CONFIG_CONSOLE_LOGBUF
+#if CONFIG_CONSOLE_LOGBUF
        add_console(header, LB_TAG_CONSOLE_LOGBUF);
 #endif
-#ifdef CONFIG_CONSOLE_SROM
+#if CONFIG_CONSOLE_SROM
        add_console(header, LB_TAG_CONSOLE_SROM);
 #endif
-#ifdef CONFIG_USBDEBUG_DIRECT
+#if CONFIG_USBDEBUG_DIRECT
        add_console(header, LB_TAG_CONSOLE_EHCI);
 #endif
 }
 
-struct lb_mainboard *lb_mainboard(struct lb_header *header)
+static void lb_framebuffer(struct lb_header *header)
+{
+#if defined(CONFIG_BOOTSPLASH) && CONFIG_BOOTSPLASH && CONFIG_COREBOOT_KEEP_FRAMEBUFFER
+       void fill_lb_framebuffer(struct lb_framebuffer *framebuffer);
+
+       struct lb_framebuffer *framebuffer;
+       framebuffer = (struct lb_framebuffer *)lb_new_record(header);
+       framebuffer->tag = LB_TAG_FRAMEBUFFER;
+       framebuffer->size = sizeof(*framebuffer);
+       fill_lb_framebuffer(framebuffer);
+#endif
+}
+
+static struct lb_mainboard *lb_mainboard(struct lb_header *header)
 {
        struct lb_record *rec;
        struct lb_mainboard *mainboard;
@@ -148,7 +185,8 @@ struct lb_mainboard *lb_mainboard(struct lb_header *header)
        return mainboard;
 }
 
-struct cmos_checksum *lb_cmos_checksum(struct lb_header *header)
+#if (CONFIG_HAVE_OPTION_TABLE == 1)
+static struct cmos_checksum *lb_cmos_checksum(struct lb_header *header)
 {
        struct lb_record *rec;
        struct cmos_checksum *cmos_checksum;
@@ -158,15 +196,16 @@ struct cmos_checksum *lb_cmos_checksum(struct lb_header *header)
 
        cmos_checksum->size = (sizeof(*cmos_checksum));
 
-       cmos_checksum->range_start = LB_CKS_RANGE_START * 8;
-       cmos_checksum->range_end = ( LB_CKS_RANGE_END * 8 ) + 7;
-       cmos_checksum->location = LB_CKS_LOC * 8;
+       cmos_checksum->range_start = CONFIG_LB_CKS_RANGE_START * 8;
+       cmos_checksum->range_end = ( CONFIG_LB_CKS_RANGE_END * 8 ) + 7;
+       cmos_checksum->location = CONFIG_LB_CKS_LOC * 8;
        cmos_checksum->type = CHECKSUM_PCBIOS;
        
        return cmos_checksum;
 }
+#endif
 
-void lb_strings(struct lb_header *header)
+static void lb_strings(struct lb_header *header)
 {
        static const struct {
                uint32_t tag;
@@ -184,7 +223,7 @@ void lb_strings(struct lb_header *header)
                { LB_TAG_ASSEMBLER,      coreboot_assembler,      },
        };
        unsigned int i;
-       for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+       for(i = 0; i < ARRAY_SIZE(strings); i++) {
                struct lb_string *rec;
                size_t len;
                rec = (struct lb_string *)lb_new_record(header);
@@ -196,6 +235,20 @@ void lb_strings(struct lb_header *header)
 
 }
 
+#if CONFIG_WRITE_HIGH_TABLES == 1
+static struct lb_forward *lb_forward(struct lb_header *header, struct lb_header *next_header)
+{
+       struct lb_record *rec;
+       struct lb_forward *forward;
+       rec = lb_new_record(header);
+       forward = (struct lb_forward *)rec;
+       forward->tag = LB_TAG_FORWARD;
+       forward->size = sizeof(*forward);
+       forward->forward = (uint64_t)(unsigned long)next_header;
+       return forward;
+}
+#endif
+
 void lb_memory_range(struct lb_memory *mem,
        uint32_t type, uint64_t start, uint64_t size)
 {
@@ -239,19 +292,22 @@ static void lb_reserve_table_memory(struct lb_header *head)
        }
 }
 
-unsigned long lb_table_fini(struct lb_header *head)
+static unsigned long lb_table_fini(struct lb_header *head, int fixup)
 {
        struct lb_record *rec, *first_rec;
        rec = lb_last_record(head);
        if (head->table_entries) {
                head->table_bytes += rec->size;
        }
-       lb_reserve_table_memory(head);
+
+       if (fixup)
+               lb_reserve_table_memory(head);
+
        first_rec = lb_first_record(head);
        head->table_checksum = compute_ip_checksum(first_rec, head->table_bytes);
        head->header_checksum = 0;
        head->header_checksum = compute_ip_checksum(head, sizeof(*head));
-       printk_debug("Wrote coreboot table at: %p - %p  checksum %lx\n",
+       printk(BIOS_DEBUG, "Wrote coreboot table at: %p - %p  checksum %x\n",
                head, rec, head->table_checksum);
        return (unsigned long)rec;
 }
@@ -357,7 +413,8 @@ static void lb_remove_memory_range(struct lb_memory *mem,
        }
 }
 
-static void lb_add_memory_range(struct lb_memory *mem,
+/* This function is used in mainboard specific code, too */
+void lb_add_memory_range(struct lb_memory *mem,
        uint32_t type, uint64_t start, uint64_t size)
 {
        lb_remove_memory_range(mem, start, size);
@@ -365,6 +422,36 @@ static void lb_add_memory_range(struct lb_memory *mem,
        lb_cleanup_memory_ranges(mem);
 }
 
+static void lb_dump_memory_ranges(struct lb_memory *mem)
+{
+       int entries;
+       int i;
+       entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]);
+       
+       printk(BIOS_DEBUG, "coreboot memory table:\n");
+       for(i = 0; i < entries; i++) {
+               uint64_t entry_start = unpack_lb64(mem->map[i].start);
+               uint64_t entry_size = unpack_lb64(mem->map[i].size);
+               const char *entry_type;
+
+               switch (mem->map[i].type) {
+               case LB_MEM_RAM: entry_type="RAM"; break;
+               case LB_MEM_RESERVED: entry_type="RESERVED"; break;
+               case LB_MEM_ACPI: entry_type="ACPI"; break;
+               case LB_MEM_NVS: entry_type="NVS"; break;
+               case LB_MEM_UNUSABLE: entry_type="UNUSABLE"; break;
+               case LB_MEM_VENDOR_RSVD: entry_type="VENDOR RESERVED"; break;
+               case LB_MEM_TABLE: entry_type="CONFIGURATION TABLES"; break;
+               default: entry_type="UNKNOWN!"; break;
+               }
+
+               printk(BIOS_DEBUG, "%2d. %016llx-%016llx: %s\n", 
+                       i, entry_start, entry_start+entry_size-1, entry_type);
+               
+       }
+}
+
+
 /* Routines to extract part so the coreboot table or 
  * information from the coreboot table after we have written it.
  * Currently get_lb_mem relies on a global we can change the
@@ -398,6 +485,10 @@ static struct lb_memory *build_lb_mem(struct lb_header *head)
        return mem;
 }
 
+#if CONFIG_WRITE_HIGH_TABLES == 1
+extern uint64_t high_tables_base, high_tables_size;
+#endif
+
 unsigned long write_coreboot_table( 
        unsigned long low_table_start, unsigned long low_table_end, 
        unsigned long rom_table_start, unsigned long rom_table_end)
@@ -405,6 +496,21 @@ unsigned long write_coreboot_table(
        struct lb_header *head;
        struct lb_memory *mem;
 
+#if CONFIG_WRITE_HIGH_TABLES == 1
+       printk(BIOS_DEBUG, "Writing high table forward entry at 0x%08lx\n",
+                       low_table_end);
+       head = lb_table_init(low_table_end);
+       lb_forward(head, (struct lb_header*)rom_table_end);
+
+       low_table_end = (unsigned long) lb_table_fini(head, 0);
+       printk(BIOS_DEBUG, "New low_table_end: 0x%08lx\n", low_table_end);
+       printk(BIOS_DEBUG, "Now going to write high coreboot table at 0x%08lx\n",
+                       rom_table_end);
+       
+       head = lb_table_init(rom_table_end);
+       rom_table_end = (unsigned long)head;
+       printk(BIOS_DEBUG, "rom_table_end = 0x%08lx\n", rom_table_end);
+#else
        if(low_table_end > (0x1000 - sizeof(struct lb_header))) { /* after 4K */
                /* We need to put lbtable on  to [0xf0000,0x100000) */
                head = lb_table_init(rom_table_end);
@@ -413,25 +519,24 @@ unsigned long write_coreboot_table(
                head = lb_table_init(low_table_end);
                low_table_end = (unsigned long)head;
        }
+#endif
  
-       printk_debug("Adjust low_table_end from 0x%08x to ", low_table_end);
+       printk(BIOS_DEBUG, "Adjust low_table_end from 0x%08lx to ", low_table_end);
        low_table_end += 0xfff; // 4K aligned
        low_table_end &= ~0xfff;
-       printk_debug("0x%08x \n", low_table_end);
+       printk(BIOS_DEBUG, "0x%08lx \n", low_table_end);
 
        /* The Linux kernel assumes this region is reserved */
-       printk_debug("Adjust rom_table_end from 0x%08x to ", rom_table_end);
+       printk(BIOS_DEBUG, "Adjust rom_table_end from 0x%08lx to ", rom_table_end);
        rom_table_end += 0xffff; // 64K align
        rom_table_end &= ~0xffff;
-       printk_debug("0x%08x \n", rom_table_end);
+       printk(BIOS_DEBUG, "0x%08lx \n", rom_table_end);
 
-#if (HAVE_OPTION_TABLE == 1) 
+#if (CONFIG_HAVE_OPTION_TABLE == 1) 
        {
-               struct lb_record *rec_dest, *rec_src;
-               /* Write the option config table... */
-               rec_dest = lb_new_record(head);
-               rec_src = (struct lb_record *)(void *)&option_table;
-               memcpy(rec_dest,  rec_src, rec_src->size);
+               struct lb_record *rec_dest = lb_new_record(head);
+               /* Copy the option config table, it's already a lb_record... */
+               memcpy(rec_dest,  &option_table, option_table.size);
                /* Create cmos checksum entry in coreboot table */
                lb_cmos_checksum(head);
        }
@@ -444,9 +549,22 @@ unsigned long write_coreboot_table(
                low_table_start, low_table_end - low_table_start);
 
        /* Record the pirq table, acpi tables, and maybe the mptable */
-       lb_add_memory_range(mem, LB_MEM_TABLE, 
+       lb_add_memory_range(mem, LB_MEM_TABLE,
                rom_table_start, rom_table_end-rom_table_start);
 
+#if CONFIG_WRITE_HIGH_TABLES == 1
+       printk(BIOS_DEBUG, "Adding high table area\n");
+       // should this be LB_MEM_ACPI?
+       lb_add_memory_range(mem, LB_MEM_TABLE,
+               high_tables_base, high_tables_size);
+#endif
+
+#if (CONFIG_HAVE_MAINBOARD_RESOURCES == 1)
+       add_mainboard_resources(mem);
+#endif
+
+       lb_dump_memory_ranges(mem);
+
        /* Note:
         * I assume that there is always memory at immediately after
         * the low_table_end.  This means that after I setup the coreboot table.
@@ -462,8 +580,10 @@ unsigned long write_coreboot_table(
        lb_console(head);
        /* Record our various random string information */
        lb_strings(head);
+       /* Record our framebuffer */
+       lb_framebuffer(head);
 
        /* Remember where my valid memory ranges are */
-       return lb_table_fini(head);
+       return lb_table_fini(head, 1);
        
 }