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 src\mainboard\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[];
42 These four macro copied from #include <arch/smp/mpspec.h>, I have to do this since "default HAVE_MP_TABLE = 0" in option.lb,
43 and also since mainboard/via/*.* have no Mptable.c(so that I can not set HAVE_MP_TABLE = 1) as many other mainboard.
44 So I have to copy these four to here. acpi_fill_madt() need this.
46 #define MP_IRQ_POLARITY_HIGH 0x1
47 #define MP_IRQ_POLARITY_LOW 0x3
48 #define MP_IRQ_TRIGGER_EDGE 0x4
49 #define MP_IRQ_TRIGGER_LEVEL 0xc
52 unsigned long acpi_fill_mcfg(unsigned long current)
54 /* NO MCFG in VX855, no pci-e*/
58 unsigned long acpi_create_madt_lapics(unsigned long current)
63 for(cpu = all_devices; cpu; cpu = cpu->next) {
64 if ((cpu->path.type != DEVICE_PATH_APIC) ||
65 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
71 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, cpu_index, cpu->path.apic.apic_id);
77 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags, u8 lint)
82 for(cpu = all_devices; cpu; cpu = cpu->next) {
83 if ((cpu->path.type != DEVICE_PATH_APIC) ||
84 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
90 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, cpu_index, flags, lint);
96 unsigned long acpi_fill_madt(unsigned long current)
98 unsigned int gsi_base = 0x18;
100 /* Create all subtables for processors. */
101 current = acpi_create_madt_lapics(current);
103 /* Write SB IOAPIC. */
104 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
105 VX800SB_APIC_ID, VX800SB_APIC_BASE, 0);
107 /* IRQ0 -> APIC IRQ2. */
108 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
109 current, 0, 0, 2, 0x0);
111 /* IRQ9 ACPI active low. */
112 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
113 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
115 /* Create all subtables for processors. */
116 current = acpi_create_madt_lapic_nmis(current,
117 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
122 unsigned long acpi_fill_slit(unsigned long current)
128 unsigned long acpi_fill_srat(unsigned long current)
130 /* No NUMA, no SRAT */
133 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
134 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
136 unsigned long write_acpi_tables(unsigned long start)
138 unsigned long current;
150 /* Align ACPI tables to 16byte */
151 start = ( start + 0x0f ) & -0x10;
154 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
156 /* We need at least an RSDP and an RSDT Table */
157 rsdp = (acpi_rsdp_t *) current;
158 current += sizeof(acpi_rsdp_t);
159 rsdt = (acpi_rsdt_t *) current;
160 current += sizeof(acpi_rsdt_t);
162 /* clear all table memory */
163 memset((void *)start, 0, current - start);
165 acpi_write_rsdp(rsdp, rsdt);
166 acpi_write_rsdt(rsdt);
169 * We explicitly add these tables later on:
171 printk_debug("ACPI: * FACS\n");
172 current = ALIGN(current, 64);
173 facs = (acpi_facs_t *) current;
174 current += sizeof(acpi_facs_t);
175 acpi_create_facs(facs);
177 printk_debug("ACPI: * DSDT\n");
178 dsdt = (acpi_header_t *) current;
179 current += ((acpi_header_t *)AmlCode_dsdt)->length;
180 memcpy((void *)dsdt,(void *)AmlCode_dsdt, ((acpi_header_t *)AmlCode_dsdt)->length);
181 dsdt->checksum = 0; /* don't trust intel iasl compiler to get this right. */
182 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
183 printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt, dsdt->length);
185 printk_debug("ACPI: * FADT\n");
186 fadt = (acpi_fadt_t *) current;
187 current += sizeof(acpi_fadt_t);
189 acpi_create_fadt(fadt,facs,dsdt);
190 acpi_add_table(rsdt,fadt);
192 /* If we want to use HPET timers Linux wants it in MADT. */
193 printk_debug("ACPI: * MADT\n");
194 madt = (acpi_madt_t *) current;
195 acpi_create_madt(madt);
196 current += madt->header.length;
197 acpi_add_table(rsdt, madt);
199 /* NO MCFG in VX855, no pci-e*/
201 printk_debug("ACPI: * HPET\n");
202 hpet = (acpi_mcfg_t *) current;
203 acpi_create_hpet(hpet);
204 current += hpet->header.length;
205 acpi_add_table(rsdt, hpet);
207 printk_debug("ACPI: * SSDT\n");
208 ssdt = (acpi_header_t *) current;
209 current += ((acpi_header_t *)AmlCode_ssdt)->length;
210 memcpy((void *)ssdt,(void *)AmlCode_ssdt, ((acpi_header_t *)AmlCode_ssdt)->length);
211 ssdt->checksum = 0; // don't trust intel iasl compiler to get this right
212 ssdt->checksum = acpi_checksum(ssdt, ssdt->length);
213 acpi_add_table(rsdt, ssdt);
214 printk_debug("ACPI: * SSDT @ %08x Length %x\n", ssdt, ssdt->length);
217 printk_info("ACPI: done.\n");
222 extern u8 acpi_sleep_type;
224 int acpi_is_wakeup(void) {
225 return (acpi_sleep_type == 3);