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>
33 extern unsigned char AmlCode[];
35 #include "southbridge/intel/i82801gx/nvs.h"
37 static void acpi_create_gnvs(global_nvs_t *gnvs)
39 memset((void *)gnvs, 0, sizeof(*gnvs));
41 gnvs->mpen = 1; /* Enable Multi Processing */
43 /* Enable COM port(s) */
49 gnvs->did[0] = 0x80000100;
50 gnvs->did[1] = 0x80000410;
51 gnvs->did[2] = 0x80000320;
52 gnvs->did[3] = 0x80000410;
53 gnvs->did[4] = 0x00000005;
56 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
58 #define HPET_ADDR 0xfed00000ULL
59 acpi_header_t *header = &(hpet->header);
60 acpi_addr_t *addr = &(hpet->addr);
62 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
64 /* fill out header fields */
65 memcpy(header->signature, "HPET", 4);
66 memcpy(header->oem_id, OEM_ID, 6);
67 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
68 memcpy(header->asl_compiler_id, ASLC, 4);
70 header->length = sizeof(acpi_hpet_t);
73 /* fill out HPET address */
74 addr->space_id = 0; /* Memory */
77 addr->addrl = HPET_ADDR & 0xffffffff;
78 addr->addrh = HPET_ADDR >> 32;
80 hpet->id = 0x8086a201; /* Intel */
82 hpet->min_tick = 0x0080;
85 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
88 static long acpi_create_ecdt(acpi_ecdt_t * ecdt)
90 /* Attention: Make sure these match the values from
93 static const char ec_id[] = "\\_SB.PCI0.LPCB.EC0";
94 int ecdt_len = sizeof(acpi_ecdt_t) + strlen(ec_id) + 1;
96 acpi_header_t *header = &(ecdt->header);
98 memset((void *) ecdt, 0, ecdt_len);
100 /* fill out header fields */
101 memcpy(header->signature, "ECDT", 4);
102 memcpy(header->oem_id, OEM_ID, 6);
103 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
104 memcpy(header->asl_compiler_id, ASLC, 4);
106 header->length = ecdt_len;
107 header->revision = 1;
109 /* Location of the two EC registers */
110 ecdt->ec_control.space_id = ACPI_ADDRESS_SPACE_IO;
111 ecdt->ec_control.bit_width = 8;
112 ecdt->ec_control.bit_offset = 0;
113 ecdt->ec_control.addrl = 0x66;
114 ecdt->ec_control.addrh = 0;
116 ecdt->ec_data.space_id = ACPI_ADDRESS_SPACE_IO; /* Memory */
117 ecdt->ec_data.bit_width = 8;
118 ecdt->ec_data.bit_offset = 0;
119 ecdt->ec_data.addrl = 0x62;
120 ecdt->ec_data.addrh = 0;
122 ecdt->uid = 1; // Must match _UID of the EC0 node.
124 ecdt->gpe_bit = 23; // SCI interrupt within GPEx_STS
126 strncpy((char *)ecdt->ec_id, ec_id, strlen(ec_id));
129 acpi_checksum((void *) ecdt, ecdt_len);
131 return header->length;
134 unsigned long acpi_fill_madt(unsigned long current)
137 current = acpi_create_madt_lapics(current);
140 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
144 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
145 current, 0, 0, 2, 0);
146 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
147 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
150 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
151 current, 0, 0x0005, 0x01);
152 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
153 current, 1, 0x0005, 0x01);
158 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
160 generate_cpu_entries();
161 return (unsigned long) (acpigen_get_current());
164 unsigned long acpi_fill_slit(unsigned long current)
170 unsigned long acpi_fill_srat(unsigned long current)
172 /* No NUMA, no SRAT */
176 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
178 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
179 unsigned long write_acpi_tables(unsigned long start)
181 unsigned long current;
191 #if CONFIG_HAVE_ACPI_SLIC
202 /* Align ACPI tables to 16byte */
205 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
207 /* We need at least an RSDP and an RSDT Table */
208 rsdp = (acpi_rsdp_t *) current;
209 current += sizeof(acpi_rsdp_t);
211 rsdt = (acpi_rsdt_t *) current;
212 current += sizeof(acpi_rsdt_t);
214 xsdt = (acpi_xsdt_t *) current;
215 current += sizeof(acpi_xsdt_t);
218 /* clear all table memory */
219 memset((void *) start, 0, current - start);
221 acpi_write_rsdp(rsdp, rsdt, xsdt);
222 acpi_write_rsdt(rsdt);
223 acpi_write_xsdt(xsdt);
226 * We explicitly add these tables later on:
228 printk(BIOS_DEBUG, "ACPI: * HPET\n");
230 hpet = (acpi_hpet_t *) current;
231 current += sizeof(acpi_hpet_t);
233 acpi_create_intel_hpet(hpet);
234 acpi_add_table(rsdp, hpet);
236 /* If we want to use HPET Timers Linux wants an MADT */
237 printk(BIOS_DEBUG, "ACPI: * MADT\n");
239 madt = (acpi_madt_t *) current;
240 acpi_create_madt(madt);
241 current += madt->header.length;
243 acpi_add_table(rsdp, madt);
245 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
246 mcfg = (acpi_mcfg_t *) current;
247 acpi_create_mcfg(mcfg);
248 current += mcfg->header.length;
250 acpi_add_table(rsdp, mcfg);
252 printk(BIOS_DEBUG, "ACPI: * FACS\n");
253 facs = (acpi_facs_t *) current;
254 current += sizeof(acpi_facs_t);
256 acpi_create_facs(facs);
258 dsdt = (acpi_header_t *) current;
259 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
260 current += dsdt->length;
261 memcpy(dsdt, &AmlCode, dsdt->length);
263 /* Fix up global NVS region for SMI handler. The GNVS region lives
264 * in the (high) table area. The low memory map looks like this:
266 * 0x00000000 - 0x000003ff Real Mode IVT
267 * 0x00000400 - 0x000004ff BDA (somewhat unused)
268 * 0x00000500 - 0x00000518 coreboot table forwarder
269 * 0x00000600 - 0x00000??? realmode trampoline
270 * 0x0007c000 - 0x0007dfff OS boot sector (unused?)
271 * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi)
272 * 0x00080000 - 0x0009fbff usable ram
273 * 0x0009fc00 - 0x0009ffff EBDA (unused?)
274 * 0x000a0000 - 0x000bffff VGA memory
275 * 0x000c0000 - 0x000cffff VGA option rom
276 * 0x000d0000 - 0x000dffff free for other option roms?
277 * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:)
278 * 0x000f0000 - 0x000f03ff PIRQ table
279 * 0x000f0400 - 0x000f66?? ACPI tables
280 * 0x000f66?? - 0x000f???? DMI tables
285 /* Pack GNVS into the ACPI table area */
286 for (i=0; i < dsdt->length; i++) {
287 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
288 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
289 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
295 acpi_create_gnvs((global_nvs_t *)current);
297 /* Keep pointer around */
298 gnvs = (void *)current;
303 for (i=0; i < dsdt->length; i++) {
304 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEDEAD) {
305 printk(BIOS_DEBUG, "ACPI: Patching up SMI1 area in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
306 *(u32*)(((u32)dsdt) + i) = current; // 0x100 bytes
311 /* Keep pointer around */
312 smi1 = (void *)current;
317 /* And tell SMI about it */
318 smm_setup_structures(gnvs, NULL, smi1);
320 /* We patched up the DSDT, so we need to recalculate the checksum */
322 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
324 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
327 printk(BIOS_DEBUG, "ACPI: * ECDT\n");
328 ecdt = (acpi_header_t *)current;
329 current += acpi_create_ecdt((acpi_ecdt_t *)current);
331 acpi_add_table(rsdp, ecdt);
333 #if CONFIG_HAVE_ACPI_SLIC
334 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
335 slic = (acpi_header_t *)current;
336 current += acpi_create_slic(current);
338 acpi_add_table(rsdp, slic);
341 printk(BIOS_DEBUG, "ACPI: * FADT\n");
342 fadt = (acpi_fadt_t *) current;
343 current += sizeof(acpi_fadt_t);
346 acpi_create_fadt(fadt, facs, dsdt);
347 acpi_add_table(rsdp, fadt);
349 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
350 ssdt = (acpi_header_t *)current;
351 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
352 current += ssdt->length;
353 acpi_add_table(rsdp, ssdt);
356 printk(BIOS_DEBUG, "current = %lx\n", current);
357 printk(BIOS_INFO, "ACPI: done.\n");