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 unsigned char AmlCode_dsdt[];
39 extern unsigned char AmlCode_ssdt[];
44 * These four macros are copied from <arch/smp/mpspec.h>, I have to do this
45 * since the "default CONFIG_GENERATE_MP_TABLE = 0" in Options.lb, 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 unsigned int gsi_base = 0x18;
85 /* Create all subtables for processors. */
86 current = acpi_create_madt_lapics(current);
88 /* Write SB IOAPIC. */
89 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
90 VX800SB_APIC_ID, VX800SB_APIC_BASE, 0);
92 /* IRQ0 -> APIC IRQ2. */
93 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
94 current, 0, 0, 2, 0x0);
96 /* IRQ9 ACPI active low. */
97 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
98 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
100 /* Create all subtables for processors. */
101 current = acpi_create_madt_lapic_nmis(current,
102 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
107 unsigned long acpi_fill_slit(unsigned long current)
109 /* Not implemented. */
113 unsigned long acpi_fill_srat(unsigned long current)
115 /* No NUMA, no SRAT. */
118 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
119 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
121 unsigned long write_acpi_tables(unsigned long start)
123 unsigned long current;
132 acpi_header_t *dsdt, *ssdt;
134 /* Align ACPI tables to 16 byte. */
135 start = (start + 0x0f) & -0x10;
138 printk_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_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_debug("ACPI: * DSDT\n");
160 dsdt = (acpi_header_t *) current;
161 current += ((acpi_header_t *) AmlCode_dsdt)->length;
162 memcpy((void *)dsdt, (void *)AmlCode_dsdt,
163 ((acpi_header_t *) AmlCode_dsdt)->length);
164 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
165 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
166 printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt, dsdt->length);
168 printk_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_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_debug("ACPI: * HPET\n");
185 hpet = (acpi_mcfg_t *) current;
186 acpi_create_hpet(hpet);
187 current += hpet->header.length;
188 acpi_add_table(rsdp, hpet);
191 printk_debug("ACPI: * SSDT\n");
192 ssdt = (acpi_header_t *) current;
193 current += ((acpi_header_t *)AmlCode_ssdt)->length;
194 memcpy((void *)ssdt,(void *)AmlCode_ssdt, ((acpi_header_t *)AmlCode_ssdt)->length);
195 ssdt->checksum = 0; /* Don't trust iasl to get this right. */
196 ssdt->checksum = acpi_checksum(ssdt, ssdt->length);
197 acpi_add_table(rsdp, ssdt);
198 printk_debug("ACPI: * SSDT @ %08x Length %x\n", ssdt, ssdt->length);
201 printk_info("ACPI: done.\n");