2 * This file is part of the coreboot project.
4 * LinuxBIOS ACPI Table support
5 * written by Stefan Reinauer <stepan@openbios.org>
6 * ACPI FADT, FACS, and DSDT table support added by
7 * Nick Barker <nick.barker9@btinternet.com>, and those portions
8 * (C) Copyright 2004 Nick Barker
9 * (C) Copyright 2005 Stefan Reinauer
10 * (C) Copyright 2009 One Laptop per Child, Association, Inc.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 * Most parts of this file copied from asus\a8v-e_se\acpi_tables.c,
28 * acpi_is_wakeup() is from Rudolf's S3 patch and SSDT was added.
31 #include <console/console.h>
33 #include <arch/acpi.h>
34 #include <device/device.h>
35 #include <device/pci_ids.h>
36 #include "northbridge/via/vx800/vx800.h"
38 extern const unsigned char AmlCode_dsdt[];
39 extern const unsigned char AmlCode_ssdt[];
44 * These four macros are copied from <arch/smp/mpspec.h>, I have to do this
45 * since the "CONFIG_GENERATE_MP_TABLE = 0", and also since
46 * mainboard/via/... have no mptable.c (so that I can not set
47 * "CONFIG_GENERATE_MP_TABLE = 1" as many other mainboards.
48 * So I have to copy these four to here. acpi_fill_madt() needs this.
50 #define MP_IRQ_POLARITY_HIGH 0x1
51 #define MP_IRQ_POLARITY_LOW 0x3
52 #define MP_IRQ_TRIGGER_EDGE 0x4
53 #define MP_IRQ_TRIGGER_LEVEL 0xc
55 unsigned long acpi_fill_mcfg(unsigned long current)
57 /* NO MCFG in VX855, no PCI-E. */
61 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
67 for (cpu = all_devices; cpu; cpu = cpu->next) {
68 if ((cpu->path.type != DEVICE_PATH_APIC) ||
69 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
74 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
75 current, cpu_index, flags, lint);
81 unsigned long acpi_fill_madt(unsigned long current)
83 /* Create all subtables for processors. */
84 current = acpi_create_madt_lapics(current);
86 /* Write SB IOAPIC. */
87 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
88 VX800SB_APIC_ID, VX800SB_APIC_BASE, 0);
90 /* IRQ0 -> APIC IRQ2. */
91 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
92 current, 0, 0, 2, 0x0);
94 /* IRQ9 ACPI active low. */
95 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
96 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
98 /* Create all subtables for processors. */
99 current = acpi_create_madt_lapic_nmis(current,
100 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
105 unsigned long acpi_fill_slit(unsigned long current)
107 /* Not implemented. */
111 unsigned long acpi_fill_srat(unsigned long current)
113 /* No NUMA, no SRAT. */
117 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
118 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
120 unsigned long write_acpi_tables(unsigned long start)
122 unsigned long current;
134 /* Align ACPI tables to 16 byte. */
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);
152 /* We explicitly add these tables later on: */
153 printk(BIOS_DEBUG, "ACPI: * FACS\n");
154 current = ALIGN(current, 64);
155 facs = (acpi_facs_t *) current;
156 current += sizeof(acpi_facs_t);
157 acpi_create_facs(facs);
159 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
160 dsdt = (acpi_header_t *) current;
161 memcpy(dsdt, &AmlCode_dsdt, sizeof(acpi_header_t));
162 current += dsdt->length;
163 memcpy(dsdt, &AmlCode_dsdt, dsdt->length);
164 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
165 dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
166 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
168 printk(BIOS_DEBUG, "ACPI: * FADT\n");
169 fadt = (acpi_fadt_t *) current;
170 current += sizeof(acpi_fadt_t);
172 acpi_create_fadt(fadt, facs, dsdt);
173 acpi_add_table(rsdp, fadt);
175 /* If we want to use HPET timers Linux wants it in MADT. */
176 printk(BIOS_DEBUG, "ACPI: * MADT\n");
177 madt = (acpi_madt_t *) current;
178 acpi_create_madt(madt);
179 current += madt->header.length;
180 acpi_add_table(rsdp, madt);
182 /* NO MCFG in VX855, no PCI-E. */
184 printk(BIOS_DEBUG, "ACPI: * HPET\n");
185 hpet = (acpi_hpet_t *) current;
186 acpi_create_hpet(hpet);
187 current += hpet->header.length;
188 acpi_add_table(rsdp, hpet);
191 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
192 ssdt = (acpi_header_t *) current;
193 memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
194 current += ssdt->length;
195 memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
196 ssdt->checksum = 0; /* Don't trust iasl to get this right. */
197 ssdt->checksum = acpi_checksum((u8*)ssdt, ssdt->length);
198 acpi_add_table(rsdp, ssdt);
199 printk(BIOS_DEBUG, "ACPI: * SSDT @ %08x Length %x\n", ssdt, ssdt->length);
202 printk(BIOS_INFO, "ACPI: done.\n");