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 <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
30 extern const unsigned char AmlCode[];
32 unsigned long acpi_fill_mcfg(unsigned long current)
37 dev = dev_find_device(0x1106, 0x324b, 0); // 0:0x13.0
41 // MMCFG not supported or not enabled.
42 if ((pci_read_config8(dev, 0x40) & 0xC0) != 0xC0)
45 mmcfg = ((u64) pci_read_config8(dev, 0x41)) << 28;
49 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, mmcfg, 0x0, 0x0, 0xff);
55 static void acpi_create_via_hpet(acpi_hpet_t * hpet)
57 #define HPET_ADDR 0xfe800000ULL
58 acpi_header_t *header = &(hpet->header);
59 acpi_addr_t *addr = &(hpet->addr);
61 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
63 /* fill out header fields */
64 memcpy(header->signature, "HPET", 4);
65 memcpy(header->oem_id, OEM_ID, 6);
66 memcpy(header->oem_table_id, "COREBOOT", 8);
67 memcpy(header->asl_compiler_id, ASLC, 4);
69 header->length = sizeof(acpi_hpet_t);
72 /* fill out HPET address */
73 // XXX factory bios just puts an address here -- who's right?
74 addr->space_id = 0; /* Memory */
77 addr->addrl = HPET_ADDR & 0xffffffff;
78 addr->addrh = HPET_ADDR >> 32;
80 hpet->id = 0x11068201; /* VIA */
82 hpet->min_tick = 0x0090;
85 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
90 #define IO_APIC_ADDR 0xfec00000UL
92 unsigned long acpi_fill_madt(unsigned long current)
95 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 0, 0);
98 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0);
101 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 0, 2, 0);
102 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000f); // low/level
105 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) current, 0, 0x0005, 1); // high/edge
110 unsigned long acpi_fill_slit(unsigned long current)
116 unsigned long acpi_fill_srat(unsigned long current)
118 /* No NUMA, no SRAT */
122 unsigned long write_acpi_tables(unsigned long start)
124 unsigned long current;
134 /* Align ACPI tables to 16byte */
135 start = (start + 0x0f) & -0x10;
138 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
140 /* We need at least an RSDP and an RSDT Table */
141 rsdp = (acpi_rsdp_t *) current;
142 current += sizeof(acpi_rsdp_t);
143 rsdt = (acpi_rsdt_t *) current;
144 current += sizeof(acpi_rsdt_t);
146 /* clear all table memory */
147 memset((void *) start, 0, current - start);
149 acpi_write_rsdp(rsdp, rsdt, NULL);
150 acpi_write_rsdt(rsdt);
153 * We explicitly add these tables later on:
156 printk(BIOS_DEBUG, "ACPI: * HPET\n");
158 hpet = (acpi_hpet_t *) current;
159 current += sizeof(acpi_hpet_t);
160 acpi_create_via_hpet(hpet);
161 acpi_add_table(rsdp, hpet);
163 /* If we want to use HPET Timers Linux wants an MADT */
164 printk(BIOS_DEBUG, "ACPI: * MADT\n");
166 madt = (acpi_madt_t *) current;
167 acpi_create_madt(madt);
168 current += madt->header.length;
169 acpi_add_table(rsdp, madt);
171 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
172 mcfg = (acpi_mcfg_t *) current;
173 acpi_create_mcfg(mcfg);
174 current += mcfg->header.length;
175 acpi_add_table(rsdp, mcfg);
177 printk(BIOS_DEBUG, "ACPI: * FACS\n");
178 facs = (acpi_facs_t *) current;
179 current += sizeof(acpi_facs_t);
180 acpi_create_facs(facs);
182 dsdt = (acpi_header_t *) current;
183 dsdt = (acpi_header_t *)current;
184 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
185 current += dsdt->length;
186 memcpy(dsdt, &AmlCode, dsdt->length);
187 #ifdef DONT_TRUST_IASL
188 dsdt->checksum = 0; // don't trust intel iasl compiler to get this right
189 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
191 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
193 printk(BIOS_DEBUG, "ACPI: * FADT\n");
195 fadt = (acpi_fadt_t *) current;
196 current += sizeof(acpi_fadt_t);
198 acpi_create_fadt(fadt, facs, dsdt);
199 acpi_add_table(rsdp, fadt);
201 printk(BIOS_DEBUG, "ACPI: * DMI (Linux workaround)\n");
202 memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
204 printk(BIOS_INFO, "ACPI: done.\n");