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>
10 * Copyright (C) 2009 Harald Gutmann <harald.gutmann@gmx.net>
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
26 #include <console/console.h>
28 #include <arch/acpi.h>
29 #include <arch/smp/mpspec.h>
30 #include <device/device.h>
31 #include <device/pci_ids.h>
32 //#include "northbridge/amd/amdfam10/amdfam10_acpi.h"
33 #include <cpu/amd/model_fxx_powernow.h>
34 #include <device/pci.h>
35 #include <cpu/amd/amdfam10_sysconf.h>
36 #include "mb_sysconf.h"
38 extern const unsigned char AmlCode[];
40 unsigned long acpi_fill_mcfg(unsigned long current)
46 unsigned long acpi_fill_madt(unsigned long current)
48 unsigned int gsi_base = 0x18;
49 struct mb_sysconf_t *m;
50 //extern unsigned char bus_mcp55[8];
51 //extern unsigned apicid_mcp55;
61 /* Create all subtables for processors. */
62 current = acpi_create_madt_lapics(current);
64 /* Write SB IOAPIC. */
65 dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0));
67 res = find_resource(dev, PCI_BASE_ADDRESS_1);
69 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
70 m->apicid_mcp55, res->base, 0);
74 /* Write NB IOAPIC. */
75 dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sbdn+ 0x12,1));
77 res = find_resource(dev, PCI_BASE_ADDRESS_1);
79 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
80 m->apicid_mcp55++, res->base, gsi_base);
84 /* IRQ9 ACPI active low. */
85 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
86 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
88 /* IRQ0 -> APIC IRQ2. */
89 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
90 current, 0, 0, 2, 0x0);
92 /* Create all subtables for processors. */
93 current = acpi_create_madt_lapic_nmis(current,
94 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
99 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
101 //k8acpi_write_vars();
102 //amd_model_fxx_generate_powernow(0, 0, 0);
103 //return (unsigned long) (acpigen_get_current());
107 unsigned long write_acpi_tables(unsigned long start)
109 unsigned long current;
122 /* Align ACPI tables to 16 byte. */
123 start = (start + 0x0f) & -0x10;
126 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
128 /* We need at least an RSDP and an RSDT table. */
129 rsdp = (acpi_rsdp_t *) current;
130 current += sizeof(acpi_rsdp_t);
131 rsdt = (acpi_rsdt_t *) current;
132 current += sizeof(acpi_rsdt_t);
134 /* Clear all table memory. */
135 memset((void *) start, 0, current - start);
137 acpi_write_rsdp(rsdp, rsdt, NULL);
138 acpi_write_rsdt(rsdt);
140 /* We explicitly add these tables later on: */
141 printk(BIOS_DEBUG, "ACPI: * FACS\n");
143 /* we should align FACS to 64B as per ACPI specs */
144 current = ALIGN(current, 64);
145 facs = (acpi_facs_t *) current;
146 current += sizeof(acpi_facs_t);
147 acpi_create_facs(facs);
149 dsdt = (acpi_header_t *) current;
150 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
151 current += dsdt->length;
152 memcpy(dsdt, &AmlCode, dsdt->length);
153 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
154 dsdt->checksum = acpi_checksum((u8 *)dsdt, dsdt->length);
155 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
157 printk(BIOS_DEBUG, "ACPI: * FADT\n");
159 fadt = (acpi_fadt_t *) current;
160 current += sizeof(acpi_fadt_t);
162 acpi_create_fadt(fadt, facs, dsdt);
163 acpi_add_table(rsdp, fadt);
165 printk(BIOS_DEBUG, "ACPI: * HPET\n");
166 hpet = (acpi_hpet_t *) current;
167 current += sizeof(acpi_hpet_t);
168 acpi_create_hpet(hpet);
169 acpi_add_table(rsdp, hpet);
171 /* If we want to use HPET timers Linux wants an MADT. */
172 printk(BIOS_DEBUG, "ACPI: * MADT\n");
173 madt = (acpi_madt_t *) current;
174 acpi_create_madt(madt);
175 current += madt->header.length;
176 acpi_add_table(rsdp, madt);
178 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
179 mcfg = (acpi_mcfg_t *) current;
180 acpi_create_mcfg(mcfg);
181 current += mcfg->header.length;
182 acpi_add_table(rsdp, mcfg);
184 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
185 srat = (acpi_srat_t *) current;
186 acpi_create_srat(srat);
187 current += srat->header.length;
188 acpi_add_table(rsdp, srat);
191 printk(BIOS_DEBUG, "ACPI: * SLIT\n");
192 slit = (acpi_slit_t *) current;
193 acpi_create_slit(slit);
194 current+=slit->header.length;
195 acpi_add_table(rsdp, slit);
198 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
199 ssdt = (acpi_header_t *)current;
201 acpi_create_ssdt_generator(ssdt, "DYNADATA");
202 current += ssdt->length;
203 acpi_add_table(rsdp, ssdt);
205 printk(BIOS_INFO, "ACPI: done.\n");