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>
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"
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_lapic_nmi((acpi_madt_lapic_nmi_t *)
102 MP_IRQ_POLARITY_HIGH |
103 MP_IRQ_TRIGGER_EDGE, 0x01);
104 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
105 current, 1, MP_IRQ_POLARITY_HIGH |
106 MP_IRQ_TRIGGER_EDGE, 0x01);
109 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
110 current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
111 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
112 current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
118 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
120 generate_cpu_entries();
121 return (unsigned long) (acpigen_get_current());
124 unsigned long acpi_fill_slit(unsigned long current)
130 unsigned long acpi_fill_srat(unsigned long current)
132 /* No NUMA, no SRAT */
136 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
138 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
139 unsigned long write_acpi_tables(unsigned long start)
141 unsigned long current;
151 #if CONFIG_HAVE_ACPI_SLIC
160 /* Align ACPI tables to 16byte */
163 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
165 /* We need at least an RSDP and an RSDT Table */
166 rsdp = (acpi_rsdp_t *) current;
167 current += sizeof(acpi_rsdp_t);
169 rsdt = (acpi_rsdt_t *) current;
170 current += sizeof(acpi_rsdt_t);
172 xsdt = (acpi_xsdt_t *) current;
173 current += sizeof(acpi_xsdt_t);
176 /* clear all table memory */
177 memset((void *) start, 0, current - start);
179 acpi_write_rsdp(rsdp, rsdt, xsdt);
180 acpi_write_rsdt(rsdt);
181 acpi_write_xsdt(xsdt);
184 * We explicitly add these tables later on:
186 printk(BIOS_DEBUG, "ACPI: * HPET\n");
188 hpet = (acpi_hpet_t *) current;
189 current += sizeof(acpi_hpet_t);
191 acpi_create_intel_hpet(hpet);
192 acpi_add_table(rsdp, hpet);
194 /* If we want to use HPET Timers Linux wants an MADT */
195 printk(BIOS_DEBUG, "ACPI: * MADT\n");
197 madt = (acpi_madt_t *) current;
198 acpi_create_madt(madt);
199 current += madt->header.length;
201 acpi_add_table(rsdp, madt);
203 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
204 mcfg = (acpi_mcfg_t *) current;
205 acpi_create_mcfg(mcfg);
206 current += mcfg->header.length;
208 acpi_add_table(rsdp, mcfg);
210 printk(BIOS_DEBUG, "ACPI: * FACS\n");
211 facs = (acpi_facs_t *) current;
212 current += sizeof(acpi_facs_t);
214 acpi_create_facs(facs);
216 dsdt = (acpi_header_t *) current;
217 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
218 current += dsdt->length;
219 memcpy(dsdt, &AmlCode, dsdt->length);
221 /* Fix up global NVS region for SMI handler. The GNVS region lives
222 * in the (high) table area. The low memory map looks like this:
224 * 0x00000000 - 0x000003ff Real Mode IVT
225 * 0x00000020 - 0x0000019c Low MP Table (XXX conflict?)
226 * 0x00000400 - 0x000004ff BDA (somewhat unused)
227 * 0x00000500 - 0x0000052f Moved GDT
228 * 0x00000530 - 0x00000b64 coreboot table
229 * 0x0007c000 - 0x0007dfff OS boot sector (unused?)
230 * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi)
231 * 0x00080000 - 0x0009fbff usable ram
232 * 0x0009fc00 - 0x0009ffff EBDA (unused?)
233 * 0x000a0000 - 0x000bffff VGA memory
234 * 0x000c0000 - 0x000cffff VGA option rom
235 * 0x000d0000 - 0x000dffff free for other option roms?
236 * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:)
237 * 0x000f0000 - 0x000f03ff PIRQ table
238 * 0x000f0400 - 0x000f66?? ACPI tables
239 * 0x000f66?? - 0x000f???? DMI tables
244 /* Pack GNVS into the ACPI table area */
245 for (i=0; i < dsdt->length; i++) {
246 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
247 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
248 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
254 acpi_create_gnvs((global_nvs_t *)current);
256 /* Keep pointer around */
257 gnvs = (void *)current;
262 /* And tell SMI about it */
263 smm_setup_structures(gnvs, NULL, NULL);
265 /* We patched up the DSDT, so we need to recalculate the checksum */
267 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
269 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
272 #if CONFIG_HAVE_ACPI_SLIC
273 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
274 slic = (acpi_header_t *)current;
275 current += acpi_create_slic(current);
277 acpi_add_table(rsdp, slic);
280 printk(BIOS_DEBUG, "ACPI: * FADT\n");
281 fadt = (acpi_fadt_t *) current;
282 current += sizeof(acpi_fadt_t);
285 acpi_create_fadt(fadt, facs, dsdt);
286 acpi_add_table(rsdp, fadt);
288 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
289 ssdt = (acpi_header_t *)current;
290 acpi_create_ssdt_generator(ssdt, "COREBOOT");
291 current += ssdt->length;
292 acpi_add_table(rsdp, ssdt);
295 printk(BIOS_DEBUG, "current = %lx\n", current);
296 printk(BIOS_INFO, "ACPI: done.\n");
298 /* Enable Dummy DCC ON# for DVI */
299 printk(BIOS_DEBUG, "Laptop handling...\n");
300 outb(inb(0x60f) & ~(1 << 5), 0x60f);