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, 2008 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/acpigen.h>
29 #include <arch/smp/mpspec.h>
30 #include <arch/ioapic.h>
31 #include <device/device.h>
32 #include <device/pci.h>
33 #include <device/pci_ids.h>
34 #include "southbridge/via/vt8237r/vt8237r.h"
35 #include "southbridge/via/k8t890/k8t890.h"
36 #include "northbridge/amd/amdk8/acpi.h"
37 #include <cpu/amd/model_fxx_powernow.h>
39 extern const unsigned char AmlCode[];
41 unsigned long acpi_fill_mcfg(unsigned long current)
46 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CF_5, 0);
50 res = find_resource(dev, K8T890_MMCONFIG_MBAR);
52 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)
53 current, res->base, 0x0, 0x0, 0xff);
58 unsigned long acpi_fill_madt(unsigned long current)
60 unsigned int gsi_base = 0x18;
62 /* Create all subtables for processors. */
63 current = acpi_create_madt_lapics(current);
65 /* Write SB IOAPIC. */
66 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
67 VT8237R_APIC_ID, IO_APIC_ADDR, 0);
69 /* Write NB IOAPIC. */
70 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
71 K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base);
73 /* IRQ9 ACPI active low. */
74 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
75 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
77 /* IRQ0 -> APIC IRQ2. */
78 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
79 current, 0, 0, 2, 0x0);
81 /* Create all subtables for processors. */
82 current = acpi_create_madt_lapic_nmis(current,
83 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
88 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
91 amd_model_fxx_generate_powernow(0, 0, 0);
92 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
93 return (unsigned long) (acpigen_get_current());
96 unsigned long write_acpi_tables(unsigned long start)
98 unsigned long current;
111 /* Align ACPI tables to 16 byte. */
112 start = (start + 0x0f) & -0x10;
115 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
117 /* We need at least an RSDP and an RSDT table. */
118 rsdp = (acpi_rsdp_t *) current;
119 current += sizeof(acpi_rsdp_t);
120 rsdt = (acpi_rsdt_t *) current;
121 current += sizeof(acpi_rsdt_t);
123 /* Clear all table memory. */
124 memset((void *) start, 0, current - start);
126 acpi_write_rsdp(rsdp, rsdt, NULL);
127 acpi_write_rsdt(rsdt);
129 /* We explicitly add these tables later on: */
130 printk(BIOS_DEBUG, "ACPI: * FACS\n");
132 /* we should align FACS to 64B as per ACPI specs */
134 current = ALIGN(current, 64);
135 facs = (acpi_facs_t *) current;
136 current += sizeof(acpi_facs_t);
137 acpi_create_facs(facs);
139 dsdt = (acpi_header_t *) current;
140 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
141 current += dsdt->length;
142 memcpy(dsdt, &AmlCode, dsdt->length);
143 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
144 dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
145 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
147 printk(BIOS_DEBUG, "ACPI: * FADT\n");
149 fadt = (acpi_fadt_t *) current;
150 current += sizeof(acpi_fadt_t);
152 acpi_create_fadt(fadt, facs, dsdt);
153 acpi_add_table(rsdp, fadt);
155 printk(BIOS_DEBUG, "ACPI: * HPET\n");
156 hpet = (acpi_hpet_t *) current;
157 current += sizeof(acpi_hpet_t);
158 acpi_create_hpet(hpet);
159 acpi_add_table(rsdp, hpet);
161 /* If we want to use HPET timers Linux wants an MADT. */
162 printk(BIOS_DEBUG, "ACPI: * MADT\n");
163 madt = (acpi_madt_t *) current;
164 acpi_create_madt(madt);
165 current += madt->header.length;
166 acpi_add_table(rsdp, madt);
168 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
169 mcfg = (acpi_mcfg_t *) current;
170 acpi_create_mcfg(mcfg);
171 current += mcfg->header.length;
172 acpi_add_table(rsdp, mcfg);
174 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
175 srat = (acpi_srat_t *) current;
176 acpi_create_srat(srat);
177 current += srat->header.length;
178 acpi_add_table(rsdp, srat);
181 printk(BIOS_DEBUG, "ACPI: * SLIT\n");
182 slit = (acpi_slit_t *) current;
183 acpi_create_slit(slit);
184 current+=slit->header.length;
185 acpi_add_table(rsdp,slit);
188 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
189 ssdt = (acpi_header_t *)current;
191 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
192 current += ssdt->length;
193 acpi_add_table(rsdp, ssdt);
195 printk(BIOS_INFO, "ACPI: done.\n");