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,
23 #include <console/console.h>
24 #include <arch/acpi.h>
25 #include <arch/ioapic.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
31 extern const unsigned char AmlCode[];
33 unsigned long acpi_fill_mcfg(unsigned long current)
38 dev = dev_find_device(0x1106, 0x324b, 0); // 0:0x13.0
42 // MMCFG not supported or not enabled.
43 if ((pci_read_config8(dev, 0x40) & 0xC0) != 0xC0)
46 mmcfg = ((u64) pci_read_config8(dev, 0x41)) << 28;
50 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, mmcfg, 0x0, 0x0, 0xff);
56 static void acpi_create_via_hpet(acpi_hpet_t * hpet)
58 #define HPET_ADDR 0xfe800000ULL
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, "COREBOOT", 8);
68 memcpy(header->asl_compiler_id, ASLC, 4);
70 header->length = sizeof(acpi_hpet_t);
73 /* fill out HPET address */
74 // XXX factory bios just puts an address here -- who's right?
75 addr->space_id = 0; /* Memory */
78 addr->addrl = HPET_ADDR & 0xffffffff;
79 addr->addrh = HPET_ADDR >> 32;
81 hpet->id = 0x11068201; /* VIA */
83 hpet->min_tick = 0x0090;
86 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
89 unsigned long acpi_fill_madt(unsigned long current)
92 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 0, 0);
95 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0);
98 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 0, 2, 0);
99 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000f); // low/level
102 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) current, 0, 0x0005, 1); // high/edge
107 unsigned long acpi_fill_slit(unsigned long current)
113 unsigned long acpi_fill_srat(unsigned long current)
115 /* No NUMA, no SRAT */
119 unsigned long write_acpi_tables(unsigned long start)
121 unsigned long current;
131 /* Align ACPI tables to 16byte */
132 start = (start + 0x0f) & -0x10;
135 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
137 /* We need at least an RSDP and an RSDT Table */
138 rsdp = (acpi_rsdp_t *) current;
139 current += sizeof(acpi_rsdp_t);
140 rsdt = (acpi_rsdt_t *) current;
141 current += sizeof(acpi_rsdt_t);
143 /* clear all table memory */
144 memset((void *) start, 0, current - start);
146 acpi_write_rsdp(rsdp, rsdt, NULL);
147 acpi_write_rsdt(rsdt);
150 * We explicitly add these tables later on:
153 printk(BIOS_DEBUG, "ACPI: * HPET\n");
155 hpet = (acpi_hpet_t *) current;
156 current += sizeof(acpi_hpet_t);
157 acpi_create_via_hpet(hpet);
158 acpi_add_table(rsdp, hpet);
160 /* If we want to use HPET Timers Linux wants an MADT */
161 printk(BIOS_DEBUG, "ACPI: * MADT\n");
163 madt = (acpi_madt_t *) current;
164 acpi_create_madt(madt);
165 current += madt->header.length;
166 acpi_add_table(rsdp, madt);
168 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
169 mcfg = (acpi_mcfg_t *) current;
170 acpi_create_mcfg(mcfg);
171 current += mcfg->header.length;
172 acpi_add_table(rsdp, mcfg);
174 printk(BIOS_DEBUG, "ACPI: * FACS\n");
175 facs = (acpi_facs_t *) current;
176 current += sizeof(acpi_facs_t);
177 acpi_create_facs(facs);
179 dsdt = (acpi_header_t *) current;
180 dsdt = (acpi_header_t *)current;
181 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
182 current += dsdt->length;
183 memcpy(dsdt, &AmlCode, dsdt->length);
184 #ifdef DONT_TRUST_IASL
185 dsdt->checksum = 0; // don't trust intel iasl compiler to get this right
186 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
188 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
190 printk(BIOS_DEBUG, "ACPI: * FADT\n");
192 fadt = (acpi_fadt_t *) current;
193 current += sizeof(acpi_fadt_t);
195 acpi_create_fadt(fadt, facs, dsdt);
196 acpi_add_table(rsdp, fadt);
198 printk(BIOS_DEBUG, "ACPI: * DMI (Linux workaround)\n");
199 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
201 printk(BIOS_INFO, "ACPI: done.\n");