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/amdk8/amdk8_acpi.h>
33 #include <cpu/amd/model_fxx_powernow.h>
34 #include <device/pci.h>
35 #include <cpu/amd/amdk8_sysconf.h>
37 extern unsigned char AmlCode[];
39 unsigned long acpi_fill_mcfg(unsigned long current)
45 unsigned long acpi_fill_madt(unsigned long current)
47 unsigned int gsi_base = 0x18;
48 extern unsigned char bus_mcp55[8];
49 extern unsigned apicid_mcp55;
50 extern void get_bus_conf(void);
58 /* Create all subtables for processors. */
59 current = acpi_create_madt_lapics(current);
61 /* Write SB IOAPIC. */
62 dev = dev_find_slot(bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0));
64 res = find_resource(dev, PCI_BASE_ADDRESS_1);
66 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
67 apicid_mcp55, res->base, 0);
71 /* Write NB IOAPIC. */
72 dev = dev_find_slot(bus_mcp55[0], PCI_DEVFN(sbdn+ 0x12,1));
74 res = find_resource(dev, PCI_BASE_ADDRESS_1);
76 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
77 apicid_mcp55++, res->base, gsi_base);
81 /* IRQ9 ACPI active low. */
82 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
83 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
85 /* IRQ0 -> APIC IRQ2. */
86 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
87 current, 0, 0, 2, 0x0);
89 /* Create all subtables for processors. */
90 current = acpi_create_madt_lapic_nmis(current,
91 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
96 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
99 amd_model_fxx_generate_powernow(0, 0, 0);
100 return (unsigned long) (acpigen_get_current());
103 unsigned long write_acpi_tables(unsigned long start)
105 unsigned long current;
118 /* Align ACPI tables to 16 byte. */
119 start = (start + 0x0f) & -0x10;
122 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
124 /* We need at least an RSDP and an RSDT table. */
125 rsdp = (acpi_rsdp_t *) current;
126 current += sizeof(acpi_rsdp_t);
127 rsdt = (acpi_rsdt_t *) current;
128 current += sizeof(acpi_rsdt_t);
130 /* Clear all table memory. */
131 memset((void *) start, 0, current - start);
133 acpi_write_rsdp(rsdp, rsdt, NULL);
134 acpi_write_rsdt(rsdt);
136 /* We explicitly add these tables later on: */
137 printk_debug("ACPI: * FACS\n");
139 /* we should align FACS to 64B as per ACPI specs */
140 current = ALIGN(current, 64);
141 facs = (acpi_facs_t *) current;
142 current += sizeof(acpi_facs_t);
143 acpi_create_facs(facs);
145 dsdt = (acpi_header_t *) current;
146 current += ((acpi_header_t *) AmlCode)->length;
147 memcpy((void *) dsdt, (void *) AmlCode,
148 ((acpi_header_t *) AmlCode)->length);
149 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
150 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
151 printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt,
153 printk_debug("ACPI: * FADT\n");
155 fadt = (acpi_fadt_t *) current;
156 current += sizeof(acpi_fadt_t);
158 acpi_create_fadt(fadt, facs, dsdt);
159 acpi_add_table(rsdp, fadt);
161 printk_debug("ACPI: * HPET\n");
162 hpet = (acpi_hpet_t *) current;
163 current += sizeof(acpi_hpet_t);
164 acpi_create_hpet(hpet);
165 acpi_add_table(rsdp, hpet);
167 /* If we want to use HPET timers Linux wants an MADT. */
168 printk_debug("ACPI: * MADT\n");
169 madt = (acpi_madt_t *) current;
170 acpi_create_madt(madt);
171 current += madt->header.length;
172 acpi_add_table(rsdp, madt);
174 printk_debug("ACPI: * MCFG\n");
175 mcfg = (acpi_mcfg_t *) current;
176 acpi_create_mcfg(mcfg);
177 current += mcfg->header.length;
178 acpi_add_table(rsdp, mcfg);
180 printk_debug("ACPI: * SRAT\n");
181 srat = (acpi_srat_t *) current;
182 acpi_create_srat(srat);
183 current += srat->header.length;
184 acpi_add_table(rsdp, srat);
187 printk_debug("ACPI: * SLIT\n");
188 slit = (acpi_slit_t *) current;
189 acpi_create_slit(slit);
190 current+=slit->header.length;
191 acpi_add_table(rsdp, slit);
194 printk_debug("ACPI: * SSDT\n");
195 ssdt = (acpi_header_t *)current;
197 acpi_create_ssdt_generator(ssdt, "DYNADATA");
198 current += ssdt->length;
199 acpi_add_table(rsdp, ssdt);
201 printk_info("ACPI: done.\n");