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
7 * modify it under the terms of the GNU General Public License as
8 * published by 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/acpigen.h>
25 #include <arch/smp/mpspec.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
29 #include <cpu/x86/msr.h>
30 #include <arch/ioapic.h>
32 extern const unsigned char AmlCode[];
33 #if CONFIG_HAVE_ACPI_SLIC
34 unsigned long acpi_create_slic(unsigned long current);
37 #include "southbridge/intel/i82801gx/nvs.h"
39 static void acpi_create_gnvs(global_nvs_t *gnvs)
41 memset((void *)gnvs, 0, sizeof(*gnvs));
43 gnvs->mpen = 1; /* Enable Multi Processing */
46 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
48 #define HPET_ADDR 0xfed00000ULL
49 acpi_header_t *header = &(hpet->header);
50 acpi_addr_t *addr = &(hpet->addr);
52 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
54 /* fill out header fields */
55 memcpy(header->signature, "HPET", 4);
56 memcpy(header->oem_id, OEM_ID, 6);
57 memcpy(header->oem_table_id, "COREBOOT", 8);
58 memcpy(header->asl_compiler_id, ASLC, 4);
60 header->length = sizeof(acpi_hpet_t);
63 /* fill out HPET address */
64 addr->space_id = 0; /* Memory */
67 addr->addrl = HPET_ADDR & 0xffffffff;
68 addr->addrh = HPET_ADDR >> 32;
70 hpet->id = 0x8086a201; /* Intel */
72 hpet->min_tick = 0x0080;
75 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
78 unsigned long acpi_fill_madt(unsigned long current)
81 current = acpi_create_madt_lapics(current);
84 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
88 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
90 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
91 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
96 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
98 generate_cpu_entries();
99 return (unsigned long) (acpigen_get_current());
102 unsigned long acpi_fill_slit(unsigned long current)
108 unsigned long acpi_fill_srat(unsigned long current)
110 /* No NUMA, no SRAT */
114 #if CONFIG_HAVE_SMI_HANDLER
115 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
118 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
119 unsigned long write_acpi_tables(unsigned long start)
121 unsigned long current;
130 #if CONFIG_HAVE_ACPI_SLIC
138 /* Align ACPI tables to 16byte */
141 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
143 /* We need at least an RSDP and an RSDT Table */
144 rsdp = (acpi_rsdp_t *) current;
145 current += sizeof(acpi_rsdp_t);
147 rsdt = (acpi_rsdt_t *) current;
148 current += sizeof(acpi_rsdt_t);
151 /* clear all table memory */
152 memset((void *) start, 0, current - start);
154 acpi_write_rsdp(rsdp, rsdt, NULL);
155 acpi_write_rsdt(rsdt);
158 * We explicitly add these tables later on:
160 printk(BIOS_DEBUG, "ACPI: * HPET\n");
162 hpet = (acpi_hpet_t *) current;
163 current += sizeof(acpi_hpet_t);
165 acpi_create_intel_hpet(hpet);
166 acpi_add_table(rsdp, hpet);
168 /* If we want to use HPET Timers Linux wants an MADT */
169 printk(BIOS_DEBUG, "ACPI: * MADT\n");
171 madt = (acpi_madt_t *) current;
172 acpi_create_madt(madt);
173 current += madt->header.length;
175 acpi_add_table(rsdp, madt);
177 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
178 mcfg = (acpi_mcfg_t *) current;
179 acpi_create_mcfg(mcfg);
180 current += mcfg->header.length;
182 acpi_add_table(rsdp, mcfg);
184 printk(BIOS_DEBUG, "ACPI: * FACS\n");
185 facs = (acpi_facs_t *) current;
186 current += sizeof(acpi_facs_t);
188 acpi_create_facs(facs);
190 dsdt = (acpi_header_t *) current;
191 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
192 current += dsdt->length;
193 memcpy(dsdt, &AmlCode, dsdt->length);
197 /* Pack GNVS into the ACPI table area */
198 for (i=0; i < dsdt->length; i++) {
199 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
200 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08lx\n", i, current);
201 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
207 acpi_create_gnvs((global_nvs_t *)current);
212 #if CONFIG_HAVE_SMI_HANDLER
213 /* And tell SMI about it */
214 smm_setup_structures((void *)current, NULL, NULL);
217 /* We patched up the DSDT, so we need to recalculate the checksum */
219 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
221 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
224 #if CONFIG_HAVE_ACPI_SLIC
225 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
226 slic = (acpi_header_t *)current;
227 current += acpi_create_slic(current);
229 acpi_add_table(rsdp, slic);
232 printk(BIOS_DEBUG, "ACPI: * FADT\n");
233 fadt = (acpi_fadt_t *) current;
234 current += sizeof(acpi_fadt_t);
237 acpi_create_fadt(fadt, facs, dsdt);
238 acpi_add_table(rsdp, fadt);
240 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
241 ssdt = (acpi_header_t *)current;
242 acpi_create_ssdt_generator(ssdt, "DYNADATA");
243 current += ssdt->length;
244 acpi_add_table(rsdp, ssdt);
246 printk(BIOS_DEBUG, "current = %lx\n", current);
247 printk(BIOS_INFO, "ACPI: done.\n");