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 <device/device.h>
34 #include <device/pci.h>
35 #include <device/pci_ids.h>
36 #include "../../../southbridge/via/vt8237r/vt8237r.h"
38 extern const unsigned char AmlCode[];
41 * These four macros are copied from <arch/smp/mpspec.h>, I have to do this
42 * since the "default CONFIG_GENERATE_MP_TABLE = 0" in Options.lb, and also since
43 * mainboard/via/... have no mptable.c (so that I can not set
44 * CONFIG_GENERATE_MP_TABLE = 1) as many other mainboards.
45 * So I have to copy these four to here. acpi_fill_madt() needs this.
47 #define MP_IRQ_POLARITY_DEFAULT 0x0
48 #define MP_IRQ_POLARITY_HIGH 0x1
49 #define MP_IRQ_POLARITY_LOW 0x3
50 #define MP_IRQ_POLARITY_MASK 0x3
51 #define MP_IRQ_TRIGGER_DEFAULT 0x0
52 #define MP_IRQ_TRIGGER_EDGE 0x4
53 #define MP_IRQ_TRIGGER_LEVEL 0xc
54 #define MP_IRQ_TRIGGER_MASK 0xc
56 unsigned long acpi_fill_mcfg(unsigned long current)
62 unsigned long acpi_fill_slit(unsigned long current)
68 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
74 for (cpu = all_devices; cpu; cpu = cpu->next) {
75 if ((cpu->path.type != DEVICE_PATH_APIC) ||
76 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
81 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
82 current, cpu_index, flags, lint);
88 unsigned long acpi_fill_madt(unsigned long current)
90 unsigned int gsi_base = 0x00;
92 /* Create all subtables for processors. */
93 current = acpi_create_madt_lapics(current);
95 /* Write SB IOAPIC. */
96 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
97 VT8237R_APIC_ID, VT8237R_APIC_BASE, gsi_base);
99 /* IRQ0 -> APIC IRQ2. */
100 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
101 current, 0, 0, 2, 0x0);
103 /* IRQ9 ACPI active low. */
104 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
105 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
107 /* Create all subtables for processors. */
108 current = acpi_create_madt_lapic_nmis(current,
109 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
114 unsigned long acpi_fill_srat(unsigned long current)
116 /* No NUMA, no SRAT */
120 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
121 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
122 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
124 unsigned long write_acpi_tables(unsigned long start)
126 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:
155 printk(BIOS_DEBUG, "ACPI: * FACS\n");
156 current = ALIGN(current, 64);
157 facs = (acpi_facs_t *) current;
158 current += sizeof(acpi_facs_t);
159 acpi_create_facs(facs);
161 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
162 dsdt = (acpi_header_t *)current;
163 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
164 current += dsdt->length;
165 memcpy(dsdt, &AmlCode, dsdt->length);
167 dsdt->checksum = 0; // don't trust intel iasl compiler to get this right
168 dsdt->checksum = acpi_checksum(dsdt,dsdt->length);
170 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
171 printk(BIOS_DEBUG, "ACPI: * FADT\n");
173 fadt = (acpi_fadt_t *) current;
174 current += sizeof(acpi_fadt_t);
176 acpi_create_fadt(fadt,facs,dsdt);
177 acpi_add_table(rsdp,fadt);
179 /* If we want IOAPIC Support Linux wants it in MADT. */
180 printk(BIOS_DEBUG, "ACPI: * MADT\n");
181 madt = (acpi_madt_t *) current;
182 acpi_create_madt(madt);
183 current += madt->header.length;
184 acpi_add_table(rsdp, madt);
186 printk(BIOS_INFO, "ACPI: done.\n");