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/acpigen.h>
27 #include <arch/smp/mpspec.h>
28 #include <device/device.h>
29 #include <device/pci.h>
30 #include <device/pci_ids.h>
33 extern unsigned char AmlCode[];
35 #include "southbridge/intel/i82801gx/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 #define IO_APIC_ADDR 0xfec00000UL
136 unsigned long acpi_fill_madt(unsigned long current)
139 current = acpi_create_madt_lapics(current);
142 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
146 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
147 current, 0, 0, 2, 0);
148 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
149 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
152 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
153 current, 0, 0x0005, 0x01);
154 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
155 current, 1, 0x0005, 0x01);
160 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
162 generate_cpu_entries();
163 return (unsigned long) (acpigen_get_current());
166 unsigned long acpi_fill_slit(unsigned long current)
172 unsigned long acpi_fill_srat(unsigned long current)
174 /* No NUMA, no SRAT */
178 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
180 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
181 unsigned long write_acpi_tables(unsigned long start)
183 unsigned long current;
193 #if CONFIG_HAVE_ACPI_SLIC
204 /* Align ACPI tables to 16byte */
207 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
209 /* We need at least an RSDP and an RSDT Table */
210 rsdp = (acpi_rsdp_t *) current;
211 current += sizeof(acpi_rsdp_t);
213 rsdt = (acpi_rsdt_t *) current;
214 current += sizeof(acpi_rsdt_t);
216 xsdt = (acpi_xsdt_t *) current;
217 current += sizeof(acpi_xsdt_t);
220 /* clear all table memory */
221 memset((void *) start, 0, current - start);
223 acpi_write_rsdp(rsdp, rsdt, xsdt);
224 acpi_write_rsdt(rsdt);
225 acpi_write_xsdt(xsdt);
228 * We explicitly add these tables later on:
230 printk(BIOS_DEBUG, "ACPI: * HPET\n");
232 hpet = (acpi_hpet_t *) current;
233 current += sizeof(acpi_hpet_t);
235 acpi_create_intel_hpet(hpet);
236 acpi_add_table(rsdp, hpet);
238 /* If we want to use HPET Timers Linux wants an MADT */
239 printk(BIOS_DEBUG, "ACPI: * MADT\n");
241 madt = (acpi_madt_t *) current;
242 acpi_create_madt(madt);
243 current += madt->header.length;
245 acpi_add_table(rsdp, madt);
247 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
248 mcfg = (acpi_mcfg_t *) current;
249 acpi_create_mcfg(mcfg);
250 current += mcfg->header.length;
252 acpi_add_table(rsdp, mcfg);
254 printk(BIOS_DEBUG, "ACPI: * FACS\n");
255 facs = (acpi_facs_t *) current;
256 current += sizeof(acpi_facs_t);
258 acpi_create_facs(facs);
260 dsdt = (acpi_header_t *) current;
261 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
262 current += dsdt->length;
263 memcpy(dsdt, &AmlCode, dsdt->length);
265 /* Fix up global NVS region for SMI handler. The GNVS region lives
266 * in the (high) table area. The low memory map looks like this:
268 * 0x00000000 - 0x000003ff Real Mode IVT
269 * 0x00000400 - 0x000004ff BDA (somewhat unused)
270 * 0x00000500 - 0x00000518 coreboot table forwarder
271 * 0x00000600 - 0x00000??? realmode trampoline
272 * 0x0007c000 - 0x0007dfff OS boot sector (unused?)
273 * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi)
274 * 0x00080000 - 0x0009fbff usable ram
275 * 0x0009fc00 - 0x0009ffff EBDA (unused?)
276 * 0x000a0000 - 0x000bffff VGA memory
277 * 0x000c0000 - 0x000cffff VGA option rom
278 * 0x000d0000 - 0x000dffff free for other option roms?
279 * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:)
280 * 0x000f0000 - 0x000f03ff PIRQ table
281 * 0x000f0400 - 0x000f66?? ACPI tables
282 * 0x000f66?? - 0x000f???? DMI tables
287 /* Pack GNVS into the ACPI table area */
288 for (i=0; i < dsdt->length; i++) {
289 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
290 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
291 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
297 acpi_create_gnvs((global_nvs_t *)current);
299 /* Keep pointer around */
300 gnvs = (void *)current;
305 for (i=0; i < dsdt->length; i++) {
306 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEDEAD) {
307 printk(BIOS_DEBUG, "ACPI: Patching up SMI1 area in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
308 *(u32*)(((u32)dsdt) + i) = current; // 0x100 bytes
313 /* Keep pointer around */
314 smi1 = (void *)current;
319 /* And tell SMI about it */
320 smm_setup_structures(gnvs, NULL, smi1);
322 /* We patched up the DSDT, so we need to recalculate the checksum */
324 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
326 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
329 printk(BIOS_DEBUG, "ACPI: * ECDT\n");
330 ecdt = (acpi_header_t *)current;
331 current += acpi_create_ecdt((acpi_ecdt_t *)current);
333 acpi_add_table(rsdp, ecdt);
335 #if CONFIG_HAVE_ACPI_SLIC
336 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
337 slic = (acpi_header_t *)current;
338 current += acpi_create_slic(current);
340 acpi_add_table(rsdp, slic);
343 printk(BIOS_DEBUG, "ACPI: * FADT\n");
344 fadt = (acpi_fadt_t *) current;
345 current += sizeof(acpi_fadt_t);
348 acpi_create_fadt(fadt, facs, dsdt);
349 acpi_add_table(rsdp, fadt);
351 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
352 ssdt = (acpi_header_t *)current;
353 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
354 current += ssdt->length;
355 acpi_add_table(rsdp, ssdt);
358 printk(BIOS_DEBUG, "current = %lx\n", current);
360 printk(BIOS_DEBUG, "ACPI: * DMI (Linux workaround)\n");
361 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
362 #if CONFIG_WRITE_HIGH_TABLES == 1
363 memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
364 current += DMI_TABLE_SIZE;
368 printk(BIOS_INFO, "ACPI: done.\n");