2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2010 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,
24 #include <console/console.h>
25 #include <arch/acpi.h>
26 #include <arch/ioapic.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 unsigned char AmlCode[];
36 #include "southbridge/intel/i82801gx/i82801gx_nvs.h"
38 static void acpi_create_gnvs(global_nvs_t *gnvs)
40 memset((void *)gnvs, 0, sizeof(*gnvs));
42 gnvs->mpen = 1; /* Enable Multi Processing */
44 /* Enable COM port(s) */
50 gnvs->did[0] = 0x80000100;
51 gnvs->did[1] = 0x80000410;
52 gnvs->did[2] = 0x80000320;
53 gnvs->did[3] = 0x80000410;
54 gnvs->did[4] = 0x00000005;
57 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
59 #define HPET_ADDR 0xfed00000ULL
60 acpi_header_t *header = &(hpet->header);
61 acpi_addr_t *addr = &(hpet->addr);
63 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
65 /* fill out header fields */
66 memcpy(header->signature, "HPET", 4);
67 memcpy(header->oem_id, OEM_ID, 6);
68 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
69 memcpy(header->asl_compiler_id, ASLC, 4);
71 header->length = sizeof(acpi_hpet_t);
74 /* fill out HPET address */
75 addr->space_id = 0; /* Memory */
78 addr->addrl = HPET_ADDR & 0xffffffff;
79 addr->addrh = HPET_ADDR >> 32;
81 hpet->id = 0x8086a201; /* Intel */
83 hpet->min_tick = 0x0080;
86 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
89 static long acpi_create_ecdt(acpi_ecdt_t * ecdt)
91 /* Attention: Make sure these match the values from
94 static const char ec_id[] = "\\_SB.PCI0.LPCB.EC0";
95 int ecdt_len = sizeof(acpi_ecdt_t) + strlen(ec_id) + 1;
97 acpi_header_t *header = &(ecdt->header);
99 memset((void *) ecdt, 0, ecdt_len);
101 /* fill out header fields */
102 memcpy(header->signature, "ECDT", 4);
103 memcpy(header->oem_id, OEM_ID, 6);
104 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
105 memcpy(header->asl_compiler_id, ASLC, 4);
107 header->length = ecdt_len;
108 header->revision = 1;
110 /* Location of the two EC registers */
111 ecdt->ec_control.space_id = ACPI_ADDRESS_SPACE_IO;
112 ecdt->ec_control.bit_width = 8;
113 ecdt->ec_control.bit_offset = 0;
114 ecdt->ec_control.addrl = 0x66;
115 ecdt->ec_control.addrh = 0;
117 ecdt->ec_data.space_id = ACPI_ADDRESS_SPACE_IO; /* Memory */
118 ecdt->ec_data.bit_width = 8;
119 ecdt->ec_data.bit_offset = 0;
120 ecdt->ec_data.addrl = 0x62;
121 ecdt->ec_data.addrh = 0;
123 ecdt->uid = 1; // Must match _UID of the EC0 node.
125 ecdt->gpe_bit = 23; // SCI interrupt within GPEx_STS
127 strncpy((char *)ecdt->ec_id, ec_id, strlen(ec_id));
130 acpi_checksum((void *) ecdt, ecdt_len);
132 return header->length;
135 unsigned long acpi_fill_madt(unsigned long current)
138 current = acpi_create_madt_lapics(current);
141 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
145 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
146 current, 0, 0, 2, 0);
147 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
148 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
151 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
152 current, 0, 0x0005, 0x01);
153 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
154 current, 1, 0x0005, 0x01);
159 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
161 generate_cpu_entries();
162 return (unsigned long) (acpigen_get_current());
165 unsigned long acpi_fill_slit(unsigned long current)
171 unsigned long acpi_fill_srat(unsigned long current)
173 /* No NUMA, no SRAT */
177 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
179 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
180 unsigned long write_acpi_tables(unsigned long start)
182 unsigned long current;
192 #if CONFIG_HAVE_ACPI_SLIC
203 /* Align ACPI tables to 16byte */
206 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
208 /* We need at least an RSDP and an RSDT Table */
209 rsdp = (acpi_rsdp_t *) current;
210 current += sizeof(acpi_rsdp_t);
212 rsdt = (acpi_rsdt_t *) current;
213 current += sizeof(acpi_rsdt_t);
215 xsdt = (acpi_xsdt_t *) current;
216 current += sizeof(acpi_xsdt_t);
219 /* clear all table memory */
220 memset((void *) start, 0, current - start);
222 acpi_write_rsdp(rsdp, rsdt, xsdt);
223 acpi_write_rsdt(rsdt);
224 acpi_write_xsdt(xsdt);
227 * We explicitly add these tables later on:
229 printk(BIOS_DEBUG, "ACPI: * HPET\n");
231 hpet = (acpi_hpet_t *) current;
232 current += sizeof(acpi_hpet_t);
234 acpi_create_intel_hpet(hpet);
235 acpi_add_table(rsdp, hpet);
237 /* If we want to use HPET Timers Linux wants an MADT */
238 printk(BIOS_DEBUG, "ACPI: * MADT\n");
240 madt = (acpi_madt_t *) current;
241 acpi_create_madt(madt);
242 current += madt->header.length;
244 acpi_add_table(rsdp, madt);
246 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
247 mcfg = (acpi_mcfg_t *) current;
248 acpi_create_mcfg(mcfg);
249 current += mcfg->header.length;
251 acpi_add_table(rsdp, mcfg);
253 printk(BIOS_DEBUG, "ACPI: * FACS\n");
254 facs = (acpi_facs_t *) current;
255 current += sizeof(acpi_facs_t);
257 acpi_create_facs(facs);
259 dsdt = (acpi_header_t *) current;
260 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
261 current += dsdt->length;
262 memcpy(dsdt, &AmlCode, dsdt->length);
264 /* Fix up global NVS region for SMI handler. The GNVS region lives
265 * in the (high) table area. The low memory map looks like this:
267 * 0x00000000 - 0x000003ff Real Mode IVT
268 * 0x00000400 - 0x000004ff BDA (somewhat unused)
269 * 0x00000500 - 0x00000518 coreboot table forwarder
270 * 0x00000600 - 0x00000??? realmode trampoline
271 * 0x0007c000 - 0x0007dfff OS boot sector (unused?)
272 * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi)
273 * 0x00080000 - 0x0009fbff usable ram
274 * 0x0009fc00 - 0x0009ffff EBDA (unused?)
275 * 0x000a0000 - 0x000bffff VGA memory
276 * 0x000c0000 - 0x000cffff VGA option rom
277 * 0x000d0000 - 0x000dffff free for other option roms?
278 * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:)
279 * 0x000f0000 - 0x000f03ff PIRQ table
280 * 0x000f0400 - 0x000f66?? ACPI tables
281 * 0x000f66?? - 0x000f???? DMI tables
286 /* Pack GNVS into the ACPI table area */
287 for (i=0; i < dsdt->length; i++) {
288 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
289 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
290 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
296 acpi_create_gnvs((global_nvs_t *)current);
298 /* Keep pointer around */
299 gnvs = (void *)current;
304 for (i=0; i < dsdt->length; i++) {
305 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEDEAD) {
306 printk(BIOS_DEBUG, "ACPI: Patching up SMI1 area in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
307 *(u32*)(((u32)dsdt) + i) = current; // 0x100 bytes
312 /* Keep pointer around */
313 smi1 = (void *)current;
318 /* And tell SMI about it */
319 smm_setup_structures(gnvs, NULL, smi1);
321 /* We patched up the DSDT, so we need to recalculate the checksum */
323 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
325 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
328 printk(BIOS_DEBUG, "ACPI: * ECDT\n");
329 ecdt = (acpi_header_t *)current;
330 current += acpi_create_ecdt((acpi_ecdt_t *)current);
332 acpi_add_table(rsdp, ecdt);
334 #if CONFIG_HAVE_ACPI_SLIC
335 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
336 slic = (acpi_header_t *)current;
337 current += acpi_create_slic(current);
339 acpi_add_table(rsdp, slic);
342 printk(BIOS_DEBUG, "ACPI: * FADT\n");
343 fadt = (acpi_fadt_t *) current;
344 current += sizeof(acpi_fadt_t);
347 acpi_create_fadt(fadt, facs, dsdt);
348 acpi_add_table(rsdp, fadt);
350 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
351 ssdt = (acpi_header_t *)current;
352 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
353 current += ssdt->length;
354 acpi_add_table(rsdp, ssdt);
357 printk(BIOS_DEBUG, "current = %lx\n", current);
359 printk(BIOS_DEBUG, "ACPI: * DMI (Linux workaround)\n");
360 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
361 #if CONFIG_WRITE_HIGH_TABLES == 1
362 memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
363 current += DMI_TABLE_SIZE;
367 printk(BIOS_INFO, "ACPI: done.\n");