diff options
author | Stefan Reinauer <stepan@openbios.org> | 2004-01-28 16:56:14 +0000 |
---|---|---|
committer | Stefan Reinauer <stepan@openbios.org> | 2004-01-28 16:56:14 +0000 |
commit | 688b385aec24157e2112d0efa06868b4f8dfb97c (patch) | |
tree | e14205a31ab7c68432735d01e6f722a31623c041 /src/arch/i386/boot | |
parent | 22489894e189616bb5694cfed8bd951951e68fae (diff) |
please forgive me... ;)
* initial acpi support code
* fix header
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1358 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/arch/i386/boot')
-rw-r--r-- | src/arch/i386/boot/Config.lb | 4 | ||||
-rw-r--r-- | src/arch/i386/boot/acpi.c | 151 | ||||
-rw-r--r-- | src/arch/i386/boot/tables.c | 5 |
3 files changed, 160 insertions, 0 deletions
diff --git a/src/arch/i386/boot/Config.lb b/src/arch/i386/boot/Config.lb index ddbfa7b79e..c5a14d0f78 100644 --- a/src/arch/i386/boot/Config.lb +++ b/src/arch/i386/boot/Config.lb @@ -1,4 +1,5 @@ uses HAVE_PIRQ_TABLE +uses HAVE_ACPI_TABLES object boot.o object linuxbios_table.o @@ -6,4 +7,7 @@ object tables.o if HAVE_PIRQ_TABLE object pirq_routing.o end +if HAVE_ACPI_TABLES +object acpi.o +end diff --git a/src/arch/i386/boot/acpi.c b/src/arch/i386/boot/acpi.c new file mode 100644 index 0000000000..6afcd9c276 --- /dev/null +++ b/src/arch/i386/boot/acpi.c @@ -0,0 +1,151 @@ +/* + * LinuxBIOS ACPI Table support + * written by Stefan Reinauer <stepan@openbios.org> + * (C) 2004 SUSE LINUX AG + */ + +#include <console/console.h> +#include <string.h> +#include <arch/acpi.h> + +#define RSDP_SIG "RSD PTR " /* RSDT Pointer signature */ +#define RSDP_NAME "RSDP" + +#define RSDT_NAME "RSDT" +#define HPET_NAME "HPET" +#define RSDT_TABLE " RSDT " +#define HPET_TABLE "AMD64 " + +#define OEM_ID "LXBIOS" +#define ASLC "NONE" + +static u8 acpi_checksum(u8 *table, u32 length) +{ + u8 ret=0; + while (length--) { + ret += *table; + table++; + } + return ret; +} + +static void acpi_add_table(acpi_rsdt_t *rsdt, void *table) +{ + int i; + + for (i=0; i<8; i++) { + if(rsdt->entry[i]==0) { + rsdt->entry[i]=(u32)table; + /* fix checksum */ + /* hope this won't get optimized away */ + rsdt->header.checksum=0; + rsdt->header.checksum=acpi_checksum((u8 *)rsdt, + rsdt->header.length); + + printk_debug("ACPI: added table %d/8\n",i); + return; + } + } + + printk_warning("ACPI: could not ACPI table. failed.\n"); +} + +static void acpi_create_hpet(acpi_hpet_t *hpet) +{ +#define HPET_ADDR 0xfed00000ULL + acpi_header_t *header=&(hpet->header); + acpi_addr_t *addr=&(hpet->addr); + + /* fill out header fields */ + memcpy(header->signature, HPET_NAME, 4); + memcpy(header->oem_id, OEM_ID, 6); + memcpy(header->oem_table_id, HPET_TABLE, 8); + memcpy(header->asl_compiler_id, ASLC, 4); + + header->length = sizeof(acpi_hpet_t); + header->revision = 1; + + /* fill out HPET address */ + addr->space_id = 0; /* Memory */ + addr->bit_width = 64; + addr->bit_offset = 0; + addr->addrl = HPET_ADDR & 0xffffffff; + addr->addrh = HPET_ADDR >> 32; + + hpet->id = 0x102282a0; /* AMD ? */ + hpet->number = 0; + hpet->min_tick = 4096; + +} + +static void acpi_write_rsdt(acpi_rsdt_t *rsdt) +{ + acpi_header_t *header=&(rsdt->header); + + /* fill out header fields */ + memcpy(header->signature, RSDT_NAME, 4); + memcpy(header->oem_id, OEM_ID, 6); + memcpy(header->oem_table_id, RSDT_TABLE, 8); + memcpy(header->asl_compiler_id, ASLC, 4); + + header->length = sizeof(acpi_rsdt_t); + header->revision = 1; + + /* fill out entries */ + + // entries are filled in later, we come with an empty set. + + /* fix checksum */ + + header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); +} + +static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt) +{ + memcpy(rsdp->signature, RSDP_SIG, 8); + memcpy(rsdp->oem_id, OEM_ID, 6); + + rsdp->length = sizeof(acpi_rsdp_t); + rsdp->rsdt_address = (u32)rsdt; + rsdp->checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); + +} + +unsigned long write_acpi_tables(unsigned long start) +{ + unsigned long current = start; + acpi_rsdp_t *rsdp; + acpi_rsdt_t *rsdt; + acpi_hpet_t *hpet; + + printk_info("ACPI: Writing ACPI tables at %lx...\n", start); + + /* We need at least an RSDP and an RSDT Table */ + rsdp = (acpi_rsdp_t *) current; + current += sizeof(acpi_rsdp_t); + rsdt = (acpi_rsdt_t *) current; + current += sizeof(acpi_rsdt_t); + + /* clear all table memory */ + memset((void *)start, 0, current - start); + + acpi_write_rsdp(rsdp, rsdt); + acpi_write_rsdt(rsdt); + + /* + * We explicitly add these tables later on: + */ +#define HAVE_ACPI_HPET +#ifdef HAVE_ACPI_HPET + printk_debug("ACPI: * HPET\n"); + + hpet = (acpi_hpet_t *) current; + current += sizeof(acpi_hpet_t); + + acpi_create_hpet(hpet); + acpi_add_table(rsdt,hpet); +#endif + printk_info("ACPI: done.\n"); + return current; +} + diff --git a/src/arch/i386/boot/tables.c b/src/arch/i386/boot/tables.c index 513167188c..b0fdd23105 100644 --- a/src/arch/i386/boot/tables.c +++ b/src/arch/i386/boot/tables.c @@ -5,6 +5,7 @@ #include <boot/linuxbios_tables.h> #include <arch/pirq_routing.h> #include <arch/smp/mpspec.h> +#include <arch/acpi.h> #include "linuxbios_table.h" #if CONFIG_SMP && CONFIG_MAX_PHYSICAL_CPUS && (CONFIG_MAX_PHYSICAL_CPUS < CONFIG_MAX_CPUS) @@ -61,6 +62,10 @@ struct lb_memory *write_tables(struct mem_range *mem, unsigned long *processor_m if (low_table_end < 0x500) { low_table_end = 0x500; } + + /* Write ACPI tables */ + low_table_end = write_acpi_tables(low_table_end); + /* The linuxbios table must be in 0-4K or 960K-1M */ write_linuxbios_table(processor_map, mem, low_table_start, low_table_end, |