2 * This file is part of the coreboot project.
4 * Written by Stefan Reinauer <stepan@openbios.org>.
5 * ACPI FADT, FACS, and DSDT table support added by
7 * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org>
8 * Copyright (C) 2005 Nick Barker <nick.barker9@btinternet.com>
9 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <console/console.h>
27 #include <arch/acpi.h>
28 #include <arch/smp/mpspec.h>
29 #include <arch/ioapic.h>
30 #include <device/device.h>
31 #include <device/pci_ids.h>
32 #include "southbridge/via/vt8237r/vt8237r.h"
33 #include "southbridge/via/k8t890/k8t890.h"
35 extern const unsigned char AmlCode[];
37 unsigned long acpi_fill_mcfg(unsigned long current)
42 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CE_5, 0);
46 res = find_resource(dev, K8T890_MMCONFIG_MBAR);
48 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)
49 current, res->base, 0x0, 0x0, 0xff);
54 unsigned long acpi_fill_madt(unsigned long current)
56 unsigned int gsi_base = 0x18;
58 /* Create all subtables for processors. */
59 current = acpi_create_madt_lapics(current);
61 /* Write SB IOAPIC. */
62 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
63 VT8237R_APIC_ID, IO_APIC_ADDR, 0);
65 /* Write NB IOAPIC. */
66 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
67 K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base);
69 /* IRQ9 ACPI active low. */
70 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
71 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
73 /* IRQ0 -> APIC IRQ2. */
74 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
75 current, 0, 0, 2, 0x0);
77 /* Create all subtables for processors. */
78 current = acpi_create_madt_lapic_nmis(current,
79 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
84 unsigned long write_acpi_tables(unsigned long start)
86 unsigned long current;
96 /* Align ACPI tables to 16 byte. */
97 start = (start + 0x0f) & -0x10;
100 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
102 /* We need at least an RSDP and an RSDT table. */
103 rsdp = (acpi_rsdp_t *) current;
104 current += sizeof(acpi_rsdp_t);
105 rsdt = (acpi_rsdt_t *) current;
106 current += sizeof(acpi_rsdt_t);
108 /* Clear all table memory. */
109 memset((void *) start, 0, current - start);
111 acpi_write_rsdp(rsdp, rsdt, NULL);
112 acpi_write_rsdt(rsdt);
114 /* We explicitly add these tables later on: */
115 printk(BIOS_DEBUG, "ACPI: * FACS\n");
116 facs = (acpi_facs_t *) current;
117 current += sizeof(acpi_facs_t);
118 acpi_create_facs(facs);
120 dsdt = (acpi_header_t *)current;
121 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
122 current += dsdt->length;
123 memcpy(dsdt, &AmlCode, dsdt->length);
124 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
125 dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
126 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
128 printk(BIOS_DEBUG, "ACPI: * FADT\n");
130 fadt = (acpi_fadt_t *) current;
131 current += sizeof(acpi_fadt_t);
133 acpi_create_fadt(fadt, facs, dsdt);
134 acpi_add_table(rsdp, fadt);
136 /* If we want to use HPET timers Linux wants it in MADT. */
137 printk(BIOS_DEBUG, "ACPI: * MADT\n");
138 madt = (acpi_madt_t *) current;
139 acpi_create_madt(madt);
140 current += madt->header.length;
141 acpi_add_table(rsdp, madt);
142 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
143 mcfg = (acpi_mcfg_t *) current;
144 acpi_create_mcfg(mcfg);
145 current += mcfg->header.length;
146 acpi_add_table(rsdp, mcfg);
148 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
149 srat = (acpi_srat_t *) current;
150 acpi_create_srat(srat);
151 current += srat->header.length;
152 acpi_add_table(rsdp, srat);
154 printk(BIOS_INFO, "ACPI: done.\n");