2 * LinuxBIOS ACPI Table support
3 * written by Stefan Reinauer <stepan@openbios.org>
4 * (C) 2004 SUSE LINUX AG
7 #include <console/console.h>
11 #define RSDP_SIG "RSD PTR " /* RSDT Pointer signature */
12 #define RSDP_NAME "RSDP"
14 #define RSDT_NAME "RSDT"
15 #define HPET_NAME "HPET"
16 #define RSDT_TABLE " RSDT "
17 #define HPET_TABLE "AMD64 "
19 #define OEM_ID "LXBIOS"
22 static u8 acpi_checksum(u8 *table, u32 length)
32 static void acpi_add_table(acpi_rsdt_t *rsdt, void *table)
37 if(rsdt->entry[i]==0) {
38 rsdt->entry[i]=(u32)table;
40 /* hope this won't get optimized away */
41 rsdt->header.checksum=0;
42 rsdt->header.checksum=acpi_checksum((u8 *)rsdt,
45 printk_debug("ACPI: added table %d/8\n",i);
50 printk_warning("ACPI: could not ACPI table. failed.\n");
53 static void acpi_create_hpet(acpi_hpet_t *hpet)
55 #define HPET_ADDR 0xfed00000ULL
56 acpi_header_t *header=&(hpet->header);
57 acpi_addr_t *addr=&(hpet->addr);
59 /* fill out header fields */
60 memcpy(header->signature, HPET_NAME, 4);
61 memcpy(header->oem_id, OEM_ID, 6);
62 memcpy(header->oem_table_id, HPET_TABLE, 8);
63 memcpy(header->asl_compiler_id, ASLC, 4);
65 header->length = sizeof(acpi_hpet_t);
68 /* fill out HPET address */
69 addr->space_id = 0; /* Memory */
72 addr->addrl = HPET_ADDR & 0xffffffff;
73 addr->addrh = HPET_ADDR >> 32;
75 hpet->id = 0x102282a0; /* AMD ? */
77 hpet->min_tick = 4096;
81 static void acpi_write_rsdt(acpi_rsdt_t *rsdt)
83 acpi_header_t *header=&(rsdt->header);
85 /* fill out header fields */
86 memcpy(header->signature, RSDT_NAME, 4);
87 memcpy(header->oem_id, OEM_ID, 6);
88 memcpy(header->oem_table_id, RSDT_TABLE, 8);
89 memcpy(header->asl_compiler_id, ASLC, 4);
91 header->length = sizeof(acpi_rsdt_t);
94 /* fill out entries */
96 // entries are filled in later, we come with an empty set.
100 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
103 static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt)
105 memcpy(rsdp->signature, RSDP_SIG, 8);
106 memcpy(rsdp->oem_id, OEM_ID, 6);
108 rsdp->length = sizeof(acpi_rsdp_t);
109 rsdp->rsdt_address = (u32)rsdt;
110 rsdp->checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
114 unsigned long write_acpi_tables(unsigned long start)
116 unsigned long current = start;
121 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
123 /* We need at least an RSDP and an RSDT Table */
124 rsdp = (acpi_rsdp_t *) current;
125 current += sizeof(acpi_rsdp_t);
126 rsdt = (acpi_rsdt_t *) current;
127 current += sizeof(acpi_rsdt_t);
129 /* clear all table memory */
130 memset((void *)start, 0, current - start);
132 acpi_write_rsdp(rsdp, rsdt);
133 acpi_write_rsdt(rsdt);
136 * We explicitly add these tables later on:
138 #define HAVE_ACPI_HPET
139 #ifdef HAVE_ACPI_HPET
140 printk_debug("ACPI: * HPET\n");
142 hpet = (acpi_hpet_t *) current;
143 current += sizeof(acpi_hpet_t);
145 acpi_create_hpet(hpet);
146 acpi_add_table(rsdt,hpet);
148 printk_info("ACPI: done.\n");