2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2008 coresystems GmbH
5 * Copyright (C) 2009 Thomas Jourdan <thomas.jourdan@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * 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 <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
32 extern const unsigned char AmlCode[];
34 unsigned long acpi_fill_mcfg(unsigned long current)
39 dev = dev_find_device(0x8086, 0x35B0, 0); // 0:0x13.0
43 // MMCFG not supported or not enabled.
44 mmcfg = ((u64) pci_read_config16(dev, 0xce)) << 16;
48 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
49 mmcfg, 0x0, 0x0, 0xff);
54 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
56 #define HPET_ADDR 0xfed00000ULL
57 acpi_header_t *header = &(hpet->header);
58 acpi_addr_t *addr = &(hpet->addr);
60 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
62 /* fill out header fields */
63 memcpy(header->signature, "HPET", 4);
64 memcpy(header->oem_id, OEM_ID, 6);
65 memcpy(header->oem_table_id, "IC ", 8);
66 memcpy(header->asl_compiler_id, ASLC, 4);
68 header->length = sizeof(acpi_hpet_t);
71 /* fill out HPET address */
72 // XXX factory bios just puts an address here -- who's right?
73 addr->space_id = 0; /* Memory */
76 addr->addrl = HPET_ADDR & 0xffffffff;
77 addr->addrh = HPET_ADDR >> 32;
79 hpet->id = 0x80861234;
81 hpet->min_tick = 0x0090;
83 header->checksum = acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
89 unsigned long acpi_fill_madt(unsigned long current)
91 unsigned int irq_start = 0;
93 unsigned char bus_isa;
96 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 1, 0);
97 // This one is for the second core... Will it hurt?
98 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 2, 1);
101 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, IO_APIC0, IO_APIC_ADDR, irq_start);
102 irq_start += INTEL_IOAPIC_NUM_INTERRUPTS;
103 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, IO_APIC1, IO_APIC_ADDR + 0x10000, irq_start);
104 irq_start += INTEL_IOAPIC_NUM_INTERRUPTS;
106 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
109 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
112 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
116 /* Map ISA IRQ 0 to IRQ 2 */
117 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, bus_isa, 0, 2, 0);
119 /* IRQ9 differs from ISA standard - ours is active high, level-triggered */
120 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000d);
125 unsigned long acpi_fill_slit(unsigned long current)
131 unsigned long acpi_fill_srat(unsigned long current)
133 /* No NUMA, no SRAT */
138 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
139 unsigned long write_acpi_tables(unsigned long start)
141 unsigned long current;
153 /* Align ACPI tables to 16byte */
156 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", current);
158 /* We need at least an RSDP and an RSDT Table */
159 rsdp = (acpi_rsdp_t *) current;
160 current += sizeof(acpi_rsdp_t);
162 rsdt = (acpi_rsdt_t *) current;
163 current += sizeof(acpi_rsdt_t);
166 /* clear all table memory */
167 memset((void *) start, 0, current - start);
169 acpi_write_rsdp(rsdp, rsdt, NULL);
170 acpi_write_rsdt(rsdt);
173 * We explicitly add these tables later on:
175 printk(BIOS_DEBUG, "ACPI: * HPET\n");
177 hpet = (acpi_hpet_t *) current;
178 current += sizeof(acpi_hpet_t);
180 acpi_create_intel_hpet(hpet);
181 acpi_add_table(rsdp, hpet);
183 /* If we want to use HPET Timers Linux wants an MADT */
184 printk(BIOS_DEBUG, "ACPI: * MADT\n");
186 madt = (acpi_madt_t *) current;
187 acpi_create_madt(madt);
188 current += madt->header.length;
190 acpi_add_table(rsdp, madt);
192 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
193 mcfg = (acpi_mcfg_t *) current;
194 acpi_create_mcfg(mcfg);
195 current += mcfg->header.length;
197 acpi_add_table(rsdp, mcfg);
199 printk(BIOS_DEBUG, "ACPI: * FACS\n");
200 facs = (acpi_facs_t *) current;
201 current += sizeof(acpi_facs_t);
203 acpi_create_facs(facs);
205 dsdt = (acpi_header_t *) current;
206 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
207 current += dsdt->length;
208 memcpy(dsdt, &AmlCode, dsdt->length);
211 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
214 printk(BIOS_DEBUG, "ACPI: * FADT\n");
215 fadt = (acpi_fadt_t *) current;
216 current += sizeof(acpi_fadt_t);
219 acpi_create_fadt(fadt, facs, dsdt);
220 acpi_add_table(rsdp, fadt);
222 printk(BIOS_INFO, "ACPI: done.\n");