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,
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>
31 #include <cpu/x86/msr.h>
36 extern unsigned char AmlCode[];
38 unsigned long acpi_create_slic(unsigned long current);
40 void generate_cpu_entries(void); // from cpu/intel/speedstep
41 unsigned long acpi_fill_mcfg(unsigned long current); // from northbridge/intel/i945
44 typedef struct acpi_oemb {
69 } __attribute__((packed)) acpi_oemb_t;
72 typedef struct acpi_gnvs {
79 } __attribute__((packed)) acpi_gnvs_t;
82 void acpi_create_oemb(acpi_oemb_t *oemb)
84 acpi_header_t *header = &(oemb->header);
87 memset (oemb, 0, sizeof(*oemb));
89 /* fill out header fields */
90 memcpy(header->signature, "OEMB", 4);
91 memcpy(header->oem_id, OEM_ID, 6);
92 memcpy(header->oem_table_id, "COREBOOT", 8);
93 memcpy(header->asl_compiler_id, ASLC, 4);
95 header->length = sizeof(acpi_oemb_t);
98 oemb->ss = 0x09; // ss1 + ss 4
99 oemb->iost = 0x0403; // ??
101 tolud = pci_read_config32(dev_find_slot(0, PCI_DEVFN(2, 0)), 0x5c);
104 oemb->roms = 0xfff00000; // 1M hardcoded
106 oemb->mg1b = 0x000d0000;
107 oemb->mg1l = 0x00010000;
110 oemb->mg2l = 0-tolud;
113 oemb->hpta = 0x000e36c0;
116 acpi_checksum((void *) oemb, sizeof(acpi_oemb_t));
121 void acpi_create_gnvs(acpi_gnvs_t *gnvs)
123 memset((void *)gnvs, 0, sizeof(*gnvs));
127 void acpi_create_intel_hpet(acpi_hpet_t * hpet)
129 #define HPET_ADDR 0xfed00000ULL
130 acpi_header_t *header = &(hpet->header);
131 acpi_addr_t *addr = &(hpet->addr);
133 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
135 /* fill out header fields */
136 memcpy(header->signature, "HPET", 4);
137 memcpy(header->oem_id, OEM_ID, 6);
138 memcpy(header->oem_table_id, "COREBOOT", 8);
139 memcpy(header->asl_compiler_id, ASLC, 4);
141 header->length = sizeof(acpi_hpet_t);
142 header->revision = 1;
144 /* fill out HPET address */
145 addr->space_id = 0; /* Memory */
146 addr->bit_width = 64;
147 addr->bit_offset = 0;
148 addr->addrl = HPET_ADDR & 0xffffffff;
149 addr->addrh = HPET_ADDR >> 32;
151 hpet->id = 0x8086a201; /* Intel */
153 hpet->min_tick = 0x0080;
156 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
159 #define IO_APIC_ADDR 0xfec00000UL
161 unsigned long acpi_fill_madt(unsigned long current)
164 current = acpi_create_madt_lapics(current);
167 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
171 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
172 current, 0, 0, 2, 0);
173 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
174 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
179 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
181 generate_cpu_entries();
182 return (unsigned long) (acpigen_get_current());
185 unsigned long acpi_fill_slit(unsigned long current)
191 unsigned long acpi_fill_srat(unsigned long current)
193 /* No NUMA, no SRAT */
197 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
199 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
200 unsigned long write_acpi_tables(unsigned long start)
202 unsigned long current;
224 /* Align ACPI tables to 16byte */
227 printk_info("ACPI: Writing ACPI tables at %lx.\n", start);
229 /* We need at least an RSDP and an RSDT Table */
230 rsdp = (acpi_rsdp_t *) current;
231 current += sizeof(acpi_rsdp_t);
233 rsdt = (acpi_rsdt_t *) current;
234 current += sizeof(acpi_rsdt_t);
236 xsdt = (acpi_xsdt_t *) current;
237 current += sizeof(acpi_xsdt_t);
240 /* clear all table memory */
241 memset((void *) start, 0, current - start);
243 acpi_write_rsdp(rsdp, rsdt, xsdt);
244 acpi_write_rsdt(rsdt);
245 acpi_write_xsdt(xsdt);
248 * We explicitly add these tables later on:
250 printk_debug("ACPI: * HPET\n");
252 hpet = (acpi_hpet_t *) current;
253 current += sizeof(acpi_hpet_t);
255 acpi_create_intel_hpet(hpet);
256 acpi_add_table(rsdp, hpet);
258 /* If we want to use HPET Timers Linux wants an MADT */
259 printk_debug("ACPI: * MADT\n");
261 madt = (acpi_madt_t *) current;
262 acpi_create_madt(madt);
263 current += madt->header.length;
265 acpi_add_table(rsdp, madt);
267 printk_debug("ACPI: * MCFG\n");
268 mcfg = (acpi_mcfg_t *) current;
269 acpi_create_mcfg(mcfg);
270 current += mcfg->header.length;
272 acpi_add_table(rsdp, mcfg);
275 printk_debug("ACPI: * OEMB\n");
276 oemb=(acpi_oemb_t *)current;
277 current += sizeof(acpi_oemb_t);
279 acpi_create_oemb(oemb);
280 acpi_add_table(rsdp, oemb);
283 printk_debug("ACPI: * FACS\n");
284 facs = (acpi_facs_t *) current;
285 current += sizeof(acpi_facs_t);
287 acpi_create_facs(facs);
289 dsdt = (acpi_header_t *) current;
290 current += ((acpi_header_t *) AmlCode)->length;
291 memcpy((void *) dsdt, (void *) AmlCode,
292 ((acpi_header_t *) AmlCode)->length);
295 for (i=0; i < dsdt->length; i++) {
296 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBEEF) {
297 printk_debug("ACPI: Patching up DSDT at offset 0x%04x -> 0x%08x\n", i, 0x24 + (u32)oemb);
298 *(u32*)(((u32)dsdt) + i) = 0x24 + (u32)oemb;
306 /* Pack GNVS into the ACPI table area */
307 for (i=0; i < dsdt->length; i++) {
308 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
309 printk_debug("ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, current);
310 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
316 acpi_create_gnvs(current);
321 /* And tell SMI about it */
322 smm_setup_structures((void *)current, NULL, NULL);
324 /* We patched up the DSDT, so we need to recalculate the checksum */
326 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
328 printk_debug("ACPI: * DSDT @ %p Length %x\n", dsdt,
332 printk_debug("ACPI: * SLIC\n");
333 slic = (acpi_header_t *)current;
334 current += acpi_create_slic(current);
336 acpi_add_table(rsdp, slic);
339 printk_debug("ACPI: * FADT\n");
340 fadt = (acpi_fadt_t *) current;
341 current += sizeof(acpi_fadt_t);
344 acpi_create_fadt(fadt, facs, dsdt);
345 acpi_add_table(rsdp, fadt);
347 printk_debug("ACPI: * SSDT\n");
348 ssdt = (acpi_header_t *)current;
349 acpi_create_ssdt_generator(ssdt, "COREBOOT");
350 current += ssdt->length;
351 acpi_add_table(rsdp, ssdt);
354 printk_debug("current = %lx\n", current);
356 printk_debug("ACPI: * DMI (Linux workaround)\n");
357 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
358 #if CONFIG_HAVE_HIGH_TABLES == 1
359 memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
360 current += DMI_TABLE_SIZE;
364 printk_info("ACPI: done.\n");