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
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
23 #include <console/console.h>
25 #include <arch/ioapic.h>
26 #include <arch/acpi.h>
27 #include <arch/acpigen.h>
28 #include <arch/smp/mpspec.h>
29 #include <device/device.h>
30 #include <device/pci.h>
31 #include <device/pci_ids.h>
34 extern const unsigned char AmlCode[];
35 #if CONFIG_HAVE_ACPI_SLIC
36 unsigned long acpi_create_slic(unsigned long current);
39 #include "southbridge/intel/i82801gx/nvs.h"
40 static void acpi_create_gnvs(global_nvs_t *gnvs)
42 memset((void *)gnvs, 0, sizeof(*gnvs));
44 gnvs->mpen = 1; /* Enable Multi Processing */
46 /* Enable both COM ports */
52 gnvs->did[0] = 0x80000100;
53 gnvs->did[1] = 0x80000240;
54 gnvs->did[2] = 0x80000410;
55 gnvs->did[3] = 0x80000410;
56 gnvs->did[4] = 0x00000005;
59 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
61 #define HPET_ADDR 0xfed00000ULL
62 acpi_header_t *header = &(hpet->header);
63 acpi_addr_t *addr = &(hpet->addr);
65 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
67 /* fill out header fields */
68 memcpy(header->signature, "HPET", 4);
69 memcpy(header->oem_id, OEM_ID, 6);
70 memcpy(header->oem_table_id, "COREBOOT", 8);
71 memcpy(header->asl_compiler_id, ASLC, 4);
73 header->length = sizeof(acpi_hpet_t);
76 /* fill out HPET address */
77 addr->space_id = 0; /* Memory */
80 addr->addrl = HPET_ADDR & 0xffffffff;
81 addr->addrh = HPET_ADDR >> 32;
83 hpet->id = 0x8086a201; /* Intel */
85 hpet->min_tick = 0x0080;
88 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
91 unsigned long acpi_fill_madt(unsigned long current)
94 current = acpi_create_madt_lapics(current);
97 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
101 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
103 MP_IRQ_POLARITY_HIGH |
104 MP_IRQ_TRIGGER_EDGE, 0x01);
105 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
106 current, 1, MP_IRQ_POLARITY_HIGH |
107 MP_IRQ_TRIGGER_EDGE, 0x01);
110 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
111 current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
112 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
113 current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
119 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
121 generate_cpu_entries();
122 return (unsigned long) (acpigen_get_current());
125 unsigned long acpi_fill_slit(unsigned long current)
131 unsigned long acpi_fill_srat(unsigned long current)
133 /* No NUMA, no SRAT */
137 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
139 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
140 unsigned long write_acpi_tables(unsigned long start)
142 unsigned long current;
152 #if CONFIG_HAVE_ACPI_SLIC
161 /* Align ACPI tables to 16byte */
164 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
166 /* We need at least an RSDP and an RSDT Table */
167 rsdp = (acpi_rsdp_t *) current;
168 current += sizeof(acpi_rsdp_t);
170 rsdt = (acpi_rsdt_t *) current;
171 current += sizeof(acpi_rsdt_t);
173 xsdt = (acpi_xsdt_t *) current;
174 current += sizeof(acpi_xsdt_t);
177 /* clear all table memory */
178 memset((void *) start, 0, current - start);
180 acpi_write_rsdp(rsdp, rsdt, xsdt);
181 acpi_write_rsdt(rsdt);
182 acpi_write_xsdt(xsdt);
185 * We explicitly add these tables later on:
187 printk(BIOS_DEBUG, "ACPI: * HPET\n");
189 hpet = (acpi_hpet_t *) current;
190 current += sizeof(acpi_hpet_t);
192 acpi_create_intel_hpet(hpet);
193 acpi_add_table(rsdp, hpet);
195 /* If we want to use HPET Timers Linux wants an MADT */
196 printk(BIOS_DEBUG, "ACPI: * MADT\n");
198 madt = (acpi_madt_t *) current;
199 acpi_create_madt(madt);
200 current += madt->header.length;
202 acpi_add_table(rsdp, madt);
204 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
205 mcfg = (acpi_mcfg_t *) current;
206 acpi_create_mcfg(mcfg);
207 current += mcfg->header.length;
209 acpi_add_table(rsdp, mcfg);
211 printk(BIOS_DEBUG, "ACPI: * FACS\n");
212 facs = (acpi_facs_t *) current;
213 current += sizeof(acpi_facs_t);
215 acpi_create_facs(facs);
217 dsdt = (acpi_header_t *) current;
218 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
219 current += dsdt->length;
220 memcpy(dsdt, &AmlCode, dsdt->length);
222 /* Fix up global NVS region for SMI handler. The GNVS region lives
223 * in the (high) table area. The low memory map looks like this:
225 * 0x00000000 - 0x000003ff Real Mode IVT
226 * 0x00000020 - 0x0000019c Low MP Table (XXX conflict?)
227 * 0x00000400 - 0x000004ff BDA (somewhat unused)
228 * 0x00000500 - 0x0000052f Moved GDT
229 * 0x00000530 - 0x00000b64 coreboot table
230 * 0x0007c000 - 0x0007dfff OS boot sector (unused?)
231 * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi)
232 * 0x00080000 - 0x0009fbff usable ram
233 * 0x0009fc00 - 0x0009ffff EBDA (unused?)
234 * 0x000a0000 - 0x000bffff VGA memory
235 * 0x000c0000 - 0x000cffff VGA option rom
236 * 0x000d0000 - 0x000dffff free for other option roms?
237 * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:)
238 * 0x000f0000 - 0x000f03ff PIRQ table
239 * 0x000f0400 - 0x000f66?? ACPI tables
240 * 0x000f66?? - 0x000f???? DMI tables
245 /* Pack GNVS into the ACPI table area */
246 for (i=0; i < dsdt->length; i++) {
247 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
248 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
249 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
255 acpi_create_gnvs((global_nvs_t *)current);
257 /* Keep pointer around */
258 gnvs = (void *)current;
263 /* And tell SMI about it */
264 smm_setup_structures(gnvs, NULL, NULL);
266 /* We patched up the DSDT, so we need to recalculate the checksum */
268 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
270 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
273 #if CONFIG_HAVE_ACPI_SLIC
274 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
275 slic = (acpi_header_t *)current;
276 current += acpi_create_slic(current);
278 acpi_add_table(rsdp, slic);
281 printk(BIOS_DEBUG, "ACPI: * FADT\n");
282 fadt = (acpi_fadt_t *) current;
283 current += sizeof(acpi_fadt_t);
286 acpi_create_fadt(fadt, facs, dsdt);
287 acpi_add_table(rsdp, fadt);
289 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
290 ssdt = (acpi_header_t *)current;
291 acpi_create_ssdt_generator(ssdt, "COREBOOT");
292 current += ssdt->length;
293 acpi_add_table(rsdp, ssdt);
296 printk(BIOS_DEBUG, "current = %lx\n", current);
298 printk(BIOS_DEBUG, "ACPI: * DMI (Linux workaround)\n");
299 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
300 #if CONFIG_WRITE_HIGH_TABLES == 1
301 memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
302 current += DMI_TABLE_SIZE;
306 printk(BIOS_INFO, "ACPI: done.\n");
308 /* Enable Dummy DCC ON# for DVI */
309 printk(BIOS_DEBUG, "Laptop handling...\n");
310 outb(inb(0x60f) & ~(1 << 5), 0x60f);