2 * coreboot ACPI Table support
3 * written by Stefan Reinauer <stepan@openbios.org>
4 * ACPI FADT, FACS, and DSDT table support added by
5 * Nick Barker <nick.barker9@btinternet.com>, and those portions
6 * (C) Copyright 2004 Nick Barker
7 * (C) Copyright 2005 Stefan Reinauer
8 * (C) Copyright 2009 Jon Harrison <bothlyn@blueyonder.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 * Most parts of this file copied from via\epia-m\acpi_tables.c,
27 * and via\epia-m700\acpi_tables.c
30 #include <console/console.h>
32 #include <arch/acpi.h>
33 #include <arch/ioapic.h>
34 #include <device/device.h>
35 #include <device/pci.h>
36 #include <device/pci_ids.h>
37 #include "southbridge/via/vt8237r/vt8237r.h"
39 extern const unsigned char AmlCode[];
42 * These 8 macros are copied from <arch/smp/mpspec.h>, I have to do this
43 * since the "CONFIG_GENERATE_MP_TABLE = 0", and also since
44 * mainboard/via/... have no mptable.c (so that I can not set
45 * "CONFIG_GENERATE_MP_TABLE = 1" as many other mainboards.
46 * So I have to copy these four to here. acpi_fill_madt() needs this.
48 #define MP_IRQ_POLARITY_DEFAULT 0x0
49 #define MP_IRQ_POLARITY_HIGH 0x1
50 #define MP_IRQ_POLARITY_LOW 0x3
51 #define MP_IRQ_POLARITY_MASK 0x3
52 #define MP_IRQ_TRIGGER_DEFAULT 0x0
53 #define MP_IRQ_TRIGGER_EDGE 0x4
54 #define MP_IRQ_TRIGGER_LEVEL 0xc
55 #define MP_IRQ_TRIGGER_MASK 0xc
57 unsigned long acpi_fill_mcfg(unsigned long current)
63 unsigned long acpi_fill_slit(unsigned long current)
69 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
75 for (cpu = all_devices; cpu; cpu = cpu->next) {
76 if ((cpu->path.type != DEVICE_PATH_APIC) ||
77 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
82 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
83 current, cpu_index, flags, lint);
89 unsigned long acpi_fill_madt(unsigned long current)
91 unsigned int gsi_base = 0x00;
93 /* Create all subtables for processors. */
94 current = acpi_create_madt_lapics(current);
96 /* Write SB IOAPIC. */
97 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
98 VT8237R_APIC_ID, IO_APIC_ADDR, gsi_base);
100 /* IRQ0 -> APIC IRQ2. */
101 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
102 current, 0, 0, 2, 0x0);
104 /* IRQ9 ACPI active low. */
105 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
106 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
108 /* Create all subtables for processors. */
109 current = acpi_create_madt_lapic_nmis(current,
110 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
115 unsigned long acpi_fill_srat(unsigned long current)
117 /* No NUMA, no SRAT */
121 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
122 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
123 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
125 unsigned long write_acpi_tables(unsigned long start)
127 unsigned long current;
135 /* Align ACPI tables to 16byte */
136 start = ( start + 0x0f ) & -0x10;
139 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
141 /* We need at least an RSDP and an RSDT Table */
142 rsdp = (acpi_rsdp_t *) current;
143 current += sizeof(acpi_rsdp_t);
144 rsdt = (acpi_rsdt_t *) current;
145 current += sizeof(acpi_rsdt_t);
147 /* clear all table memory */
148 memset((void *)start, 0, current - start);
150 acpi_write_rsdp(rsdp, rsdt, NULL);
151 acpi_write_rsdt(rsdt);
154 * We explicitly add these tables later on:
156 printk(BIOS_DEBUG, "ACPI: * FACS\n");
157 current = ALIGN(current, 64);
158 facs = (acpi_facs_t *) current;
159 current += sizeof(acpi_facs_t);
160 acpi_create_facs(facs);
162 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
163 dsdt = (acpi_header_t *)current;
164 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
165 current += dsdt->length;
166 memcpy(dsdt, &AmlCode, dsdt->length);
168 dsdt->checksum = 0; // don't trust intel iasl compiler to get this right
169 dsdt->checksum = acpi_checksum(dsdt,dsdt->length);
171 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
172 printk(BIOS_DEBUG, "ACPI: * FADT\n");
174 fadt = (acpi_fadt_t *) current;
175 current += sizeof(acpi_fadt_t);
177 acpi_create_fadt(fadt,facs,dsdt);
178 acpi_add_table(rsdp,fadt);
180 /* If we want IOAPIC Support Linux wants it in MADT. */
181 printk(BIOS_DEBUG, "ACPI: * MADT\n");
182 madt = (acpi_madt_t *) current;
183 acpi_create_madt(madt);
184 current += madt->header.length;
185 acpi_add_table(rsdp, madt);
187 printk(BIOS_INFO, "ACPI: done.\n");