2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 - 2012 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <console/console.h>
22 #include <arch/acpi.h>
23 #include <arch/acpigen.h>
24 #include <arch/ioapic.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28 #include <cpu/x86/msr.h>
29 #include <cpu/amd/mtrr.h>
30 #include <cpu/amd/amdfam10_sysconf.h>
31 #include "agesawrapper.h"
33 #define DUMP_ACPI_TABLES 0
35 #if DUMP_ACPI_TABLES == 1
36 static void dump_mem(u32 start, u32 end)
40 print_debug("dump_mem:");
41 for (i = start; i < end; i++) {
43 printk(BIOS_DEBUG, "\n%08x:", i);
45 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
51 extern const unsigned char AmlCode[];
54 unsigned long acpi_fill_mcfg(unsigned long current)
60 unsigned long acpi_fill_madt(unsigned long current)
69 * AGESA v5 Apply apic enumeration rules
70 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
71 * put the local-APICs at m..z
72 * For systems with < 16 APICs, put the Local-APICs at 0..n and
73 * put the IO-APICs at (n + 1)..z
75 #if CONFIG_MAX_CPUS >= 16
78 apicid_sp5100 = CONFIG_MAX_CPUS + 1
80 apicid_sr5650 = apicid_sp5100 + 1;
82 /* create all subtables for processors */
83 current = acpi_create_madt_lapics(current);
85 /* Write sp5100 IOAPIC, only one */
86 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
92 /* IOAPIC on rs5690 */
93 gsi_base += IO_APIC_INTERRUPTS; /* SP5100 has 24 IOAPIC entries. */
94 dev = dev_find_slot(0, PCI_DEVFN(0, 0));
96 pci_write_config32(dev, 0xF8, 0x1);
97 dword = pci_read_config32(dev, 0xFC) & 0xfffffff0;
98 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
105 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current,
112 /* 0: mean bus 0--->ISA */
115 /* 5 mean: 0101 --> Edige-triggered, Active high */
117 /* create all subtables for processors */
118 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0, 5, 1);
119 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 1, 5, 1);
120 /* 1: LINT1 connect to NMI */
125 unsigned long acpi_fill_slit(unsigned long current)
131 unsigned long acpi_fill_srat(unsigned long current)
133 /* No NUMA, no SRAT */
137 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
141 char pscope[] = "\\_SB.PCI0";
143 lens = acpigen_write_scope(pscope);
144 msr = rdmsr(TOP_MEM);
145 lens += acpigen_write_name_dword("TOM1", msr.lo);
146 msr = rdmsr(TOP_MEM2);
148 * Since XP only implements parts of ACPI 2.0, we can't use a qword
150 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
152 * Shift value right by 20 bit to make it fit into 32bit,
153 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
155 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
156 acpigen_patch_len(lens - 1);
157 return (unsigned long) (acpigen_get_current());
160 unsigned long write_acpi_tables(unsigned long start)
162 unsigned long current;
173 acpi_header_t *ssdt2;
176 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
178 /* Align ACPI tables to 16 bytes */
179 start = (start + 0x0f) & -0x10;
182 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
184 /* We need at least an RSDP and an RSDT Table */
185 rsdp = (acpi_rsdp_t *) current;
186 current += sizeof(acpi_rsdp_t);
187 rsdt = (acpi_rsdt_t *) current;
188 current += sizeof(acpi_rsdt_t);
190 /* clear all table memory */
191 memset((void *)start, 0, current - start);
193 acpi_write_rsdp(rsdp, rsdt, NULL);
194 acpi_write_rsdt(rsdt);
197 printk(BIOS_DEBUG, "ACPI: * FACS\n");
198 facs = (acpi_facs_t *) current;
199 current += sizeof(acpi_facs_t);
200 acpi_create_facs(facs);
203 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
204 dsdt = (acpi_header_t *)current;
205 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
206 current += dsdt->length;
207 memcpy(dsdt, &AmlCode, dsdt->length);
208 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
210 printk(BIOS_DEBUG, "ACPI: * FADT\n");
211 fadt = (acpi_fadt_t *) current;
212 current += sizeof(acpi_fadt_t);
214 acpi_create_fadt(fadt, facs, dsdt);
215 acpi_add_table(rsdp, fadt);
218 * We explicitly add these tables later on:
220 #ifdef UNUSED_CODE // Don't need HPET table. we have one in dsdt
221 current = ( current + 0x07) & -0x08;
222 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
223 hpet = (acpi_hpet_t *) current;
224 current += sizeof(acpi_hpet_t);
225 acpi_create_hpet(hpet);
226 acpi_add_table(rsdp, hpet);
229 /* If we want to use HPET Timers Linux wants an MADT */
230 current = ( current + 0x07) & -0x08;
231 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
232 madt = (acpi_madt_t *) current;
233 acpi_create_madt(madt);
234 current += madt->header.length;
235 acpi_add_table(rsdp, madt);
238 current = ( current + 0x07) & -0x08;
239 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
240 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
242 memcpy((void *)current, srat, srat->header.length);
243 srat = (acpi_srat_t *) current;
244 //acpi_create_srat(srat);
245 current += srat->header.length;
246 acpi_add_table(rsdp, srat);
250 current = ( current + 0x07) & -0x08;
251 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
252 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
254 memcpy((void *)current, slit, slit->header.length);
255 slit = (acpi_slit_t *) current;
256 //acpi_create_slit(slit);
257 current += slit->header.length;
258 acpi_add_table(rsdp, slit);
262 current = (current + 0x0f) & -0x10;
263 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
264 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
266 memcpy((void *)current, alib, alib->length);
267 ssdt = (acpi_header_t *) current;
268 current += alib->length;
269 acpi_add_table(rsdp,alib);
271 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
274 #if 0 // The DSDT needs additional work for the AGESA SSDT Pstate table
275 current = ( current + 0x0f) & -0x10;
276 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
277 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
279 memcpy((void *)current, ssdt, ssdt->length);
280 ssdt = (acpi_header_t *) current;
281 current += ssdt->length;
283 printk(BIOS_DEBUG, " AGESA SSDT table NULL. Skipping.\n");
285 acpi_add_table(rsdp,ssdt);
288 current = ( current + 0x0f) & -0x10;
289 printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current);
290 ssdt2 = (acpi_header_t *) current;
291 acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
292 current += ssdt2->length;
293 acpi_add_table(rsdp,ssdt2);
295 #if DUMP_ACPI_TABLES == 1
296 printk(BIOS_DEBUG, "rsdp\n");
297 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
299 printk(BIOS_DEBUG, "rsdt\n");
300 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
302 printk(BIOS_DEBUG, "madt\n");
303 dump_mem(madt, ((void *)madt) + madt->header.length);
305 printk(BIOS_DEBUG, "srat\n");
306 dump_mem(srat, ((void *)srat) + srat->header.length);
308 printk(BIOS_DEBUG, "slit\n");
309 dump_mem(slit, ((void *)slit) + slit->header.length);
311 printk(BIOS_DEBUG, "ssdt\n");
312 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
314 printk(BIOS_DEBUG, "fadt\n");
315 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
318 printk(BIOS_INFO, "ACPI: done.\n");