2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2008 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>
24 #include <arch/acpi.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
30 extern unsigned char AmlCode[];
32 typedef struct acpi_oemb {
57 } __attribute__((packed)) acpi_oemb_t;
59 void acpi_create_oemb(acpi_oemb_t *oemb)
61 acpi_header_t *header = &(oemb->header);
64 memset (oemb, 0, sizeof(oemb));
66 /* fill out header fields */
67 memcpy(header->signature, "OEMB", 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_oemb_t);
75 oemb->ss = 0x09; // ss1 + ss 4
76 oemb->iost = 0x0403; // ??
78 tolud = pci_read_config32(dev_find_slot(0, PCI_DEVFN(2, 0)), 0x5c);
81 oemb->roms = 0xfff00000; // 1M hardcoded
83 oemb->mg1b = 0x000d0000;
84 oemb->mg1l = 0x00010000;
90 oemb->hpta = 0x000e36c0;
93 acpi_checksum((void *) oemb, sizeof(acpi_oemb_t));
97 unsigned long acpi_fill_mcfg(unsigned long current)
103 dev = dev_find_device(0x1106, 0x324b, 0); // 0:0x13.0
107 // MMCFG not supported or not enabled.
108 if ((pci_read_config8(dev, 0x40) & 0xC0) != 0xC0)
111 mmcfg = ((u64) pci_read_config8(dev, 0x41)) << 28;
115 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, mmcfg, 0x0, 0x0, 0xff);
120 void acpi_create_intel_hpet(acpi_hpet_t * hpet)
122 #define HPET_ADDR 0xfe800000ULL
123 acpi_header_t *header = &(hpet->header);
124 acpi_addr_t *addr = &(hpet->addr);
126 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
128 /* fill out header fields */
129 memcpy(header->signature, HPET_NAME, 4);
130 memcpy(header->oem_id, OEM_ID, 6);
131 memcpy(header->oem_table_id, "COREBOOT", 8);
132 memcpy(header->asl_compiler_id, ASLC, 4);
134 header->length = sizeof(acpi_hpet_t);
135 header->revision = 1;
137 /* fill out HPET address */
138 // XXX factory bios just puts an address here -- who's right?
139 addr->space_id = 0; /* Memory */
140 addr->bit_width = 64;
141 addr->bit_offset = 0;
142 addr->addrl = HPET_ADDR & 0xffffffff;
143 addr->addrh = HPET_ADDR >> 32;
145 hpet->id = 0x80861234; /* VIA */
147 hpet->min_tick = 0x0090;
150 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
155 #define IO_APIC_ADDR 0xfec00000UL
157 unsigned long acpi_fill_madt(unsigned long current)
160 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 1, 0);
161 // This one is for the second core... Will it hurt?
162 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 2, 1);
165 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0);
168 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 0, 2, 0);
169 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000d); // high/level
174 unsigned long acpi_fill_srat(unsigned long current)
176 /* No NUMA, no SRAT */
181 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
182 unsigned long write_acpi_tables(unsigned long start)
184 unsigned long current;
196 /* Align ACPI tables to 16byte */
197 start = (start + 0x0f) & -0x10;
200 printk_info("ACPI: Writing ACPI tables at %lx.\n", start);
202 /* We need at least an RSDP and an RSDT Table */
203 rsdp = (acpi_rsdp_t *) current;
204 current += sizeof(acpi_rsdp_t);
206 rsdt = (acpi_rsdt_t *) current;
207 current += sizeof(acpi_rsdt_t);
210 /* clear all table memory */
211 memset((void *) start, 0, current - start);
213 acpi_write_rsdp(rsdp, rsdt);
214 acpi_write_rsdt(rsdt);
217 * We explicitly add these tables later on:
220 printk_debug("ACPI: * HPET\n");
222 hpet = (acpi_hpet_t *) current;
223 current += sizeof(acpi_hpet_t);
225 acpi_create_intel_hpet(hpet);
226 acpi_add_table(rsdt, hpet);
228 /* If we want to use HPET Timers Linux wants an MADT */
229 printk_debug("ACPI: * MADT\n");
231 madt = (acpi_madt_t *) current;
232 acpi_create_madt(madt);
233 current += madt->header.length;
235 acpi_add_table(rsdt, madt);
237 printk_debug("ACPI: * MCFG\n");
238 mcfg = (acpi_mcfg_t *) current;
239 acpi_create_mcfg(mcfg);
240 current += mcfg->header.length;
242 acpi_add_table(rsdt, mcfg);
245 printk_debug("ACPI: * OEMB\n");
246 oemb=(acpi_oemb_t *)current;
247 current += sizeof(acpi_oemb_t);
249 acpi_create_oemb(oemb);
250 acpi_add_table(rsdt, oemb);
252 printk_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 current += ((acpi_header_t *) AmlCode)->length;
261 memcpy((void *) dsdt, (void *) AmlCode,
262 ((acpi_header_t *) AmlCode)->length);
265 for (i=0; i < dsdt->length; i++) {
266 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
267 printk_debug("ACPI: Patching up DSDT at offset 0x%04x -> 0x%08x\n", i, 0x24 + (u32)oemb);
268 *(u32*)(((u32)dsdt) + i) = 0x24 + (u32)oemb;
273 /* We patched up the DSDT, so we need to recalculate the checksum */
275 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
278 printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt,
281 printk_debug("ACPI: * FADT\n");
282 fadt = (acpi_fadt_t *) current;
283 current += sizeof(acpi_fadt_t);
286 acpi_create_fadt(fadt, facs, dsdt);
287 acpi_add_table(rsdt, fadt);
288 printk_debug("current = %x\n", current);
290 printk_debug("ACPI: * DMI (Linux workaround)\n");
291 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
293 printk_info("ACPI: done.\n");