2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2009 coresystems GmbH
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <console/console.h>
23 #include <arch/acpi.h>
24 #include <arch/ioapic.h>
25 #include <arch/acpigen.h>
26 #include <arch/smp/mpspec.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <cpu/x86/msr.h>
33 extern const unsigned char AmlCode[];
34 #if CONFIG_HAVE_ACPI_SLIC
35 unsigned long acpi_create_slic(unsigned long current);
38 #include "southbridge/intel/i82801gx/nvs.h" // FIXME: our own copy of nvs would be nice
39 static void acpi_create_gnvs(global_nvs_t *gnvs)
41 memset((void *)gnvs, 0, sizeof(*gnvs));
43 gnvs->mpen = 1; /* Enable Multi Processing */
45 /* Enable both COM ports */
51 gnvs->did[0] = 0x80000100;
52 gnvs->did[1] = 0x80000240;
53 gnvs->did[2] = 0x80000410;
54 gnvs->did[3] = 0x80000410;
55 gnvs->did[4] = 0x00000005;
58 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
60 #define HPET_ADDR 0xfed00000ULL
61 acpi_header_t *header = &(hpet->header);
62 acpi_addr_t *addr = &(hpet->addr);
64 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
66 /* fill out header fields */
67 memcpy(header->signature, "HPET", 4);
68 memcpy(header->oem_id, OEM_ID, 6);
69 memcpy(header->oem_table_id, "COREBOOT", 8);
70 memcpy(header->asl_compiler_id, ASLC, 4);
72 header->length = sizeof(acpi_hpet_t);
75 /* fill out HPET address */
76 addr->space_id = 0; /* Memory */
79 addr->addrl = HPET_ADDR & 0xffffffff;
80 addr->addrh = HPET_ADDR >> 32;
82 hpet->id = 0x8086a201; /* Intel */
84 hpet->min_tick = 0x0080;
87 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
90 unsigned long acpi_fill_madt(unsigned long current)
93 current = acpi_create_madt_lapics(current);
96 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
100 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
101 current, 0, 0, 2, 0);
102 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
103 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
108 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
110 generate_cpu_entries();
111 return (unsigned long) (acpigen_get_current());
114 unsigned long acpi_fill_slit(unsigned long current)
120 unsigned long acpi_fill_srat(unsigned long current)
122 /* No NUMA, no SRAT */
126 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
128 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
129 unsigned long write_acpi_tables(unsigned long start)
131 unsigned long current;
141 #if CONFIG_HAVE_ACPI_SLIC
149 /* Align ACPI tables to 16byte */
152 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
154 /* We need at least an RSDP and an RSDT Table */
155 rsdp = (acpi_rsdp_t *) current;
156 current += sizeof(acpi_rsdp_t);
158 rsdt = (acpi_rsdt_t *) current;
159 current += sizeof(acpi_rsdt_t);
161 xsdt = (acpi_xsdt_t *) current;
162 current += sizeof(acpi_xsdt_t);
165 /* clear all table memory */
166 memset((void *) start, 0, current - start);
168 acpi_write_rsdp(rsdp, rsdt, xsdt);
169 acpi_write_rsdt(rsdt);
170 acpi_write_xsdt(xsdt);
173 * We explicitly add these tables later on:
175 printk(BIOS_DEBUG, "ACPI: * HPET\n");
177 hpet = (acpi_hpet_t *) current;
178 current += sizeof(acpi_hpet_t);
180 acpi_create_intel_hpet(hpet);
181 acpi_add_table(rsdp, hpet);
183 /* If we want to use HPET Timers Linux wants an MADT */
184 printk(BIOS_DEBUG, "ACPI: * MADT\n");
186 madt = (acpi_madt_t *) current;
187 acpi_create_madt(madt);
188 current += madt->header.length;
190 acpi_add_table(rsdp, madt);
192 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
193 mcfg = (acpi_mcfg_t *) current;
194 acpi_create_mcfg(mcfg);
195 current += mcfg->header.length;
197 acpi_add_table(rsdp, mcfg);
199 printk(BIOS_DEBUG, "ACPI: * FACS\n");
200 facs = (acpi_facs_t *) current;
201 current += sizeof(acpi_facs_t);
203 acpi_create_facs(facs);
205 dsdt = (acpi_header_t *) current;
206 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
207 current += dsdt->length;
208 memcpy(dsdt, &AmlCode, dsdt->length);
212 /* Pack GNVS into the ACPI table area */
213 for (i=0; i < dsdt->length; i++) {
214 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
215 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08lx\n", i, current);
216 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
222 acpi_create_gnvs((global_nvs_t *)current);
227 /* And tell SMI about it */
228 smm_setup_structures((void *)current, NULL, NULL);
230 /* We patched up the DSDT, so we need to recalculate the checksum */
232 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
234 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
237 #if CONFIG_HAVE_ACPI_SLIC
238 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
239 slic = (acpi_header_t *)current;
240 current += acpi_create_slic(current);
242 acpi_add_table(rsdp, slic);
245 printk(BIOS_DEBUG, "ACPI: * FADT\n");
246 fadt = (acpi_fadt_t *) current;
247 current += sizeof(acpi_fadt_t);
250 acpi_create_fadt(fadt, facs, dsdt);
251 acpi_add_table(rsdp, fadt);
253 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
254 ssdt = (acpi_header_t *)current;
255 acpi_create_ssdt_generator(ssdt, "COREBOOT");
256 current += ssdt->length;
257 acpi_add_table(rsdp, ssdt);
260 printk(BIOS_DEBUG, "current = %lx\n", current);
262 printk(BIOS_DEBUG, "ACPI: * DMI (Linux workaround)\n");
263 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
264 #if CONFIG_WRITE_HIGH_TABLES == 1
265 memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
266 current += DMI_TABLE_SIZE;
270 printk(BIOS_INFO, "ACPI: done.\n");