2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 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>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cpu/x86/msr.h>
28 #include "agesawrapper.h"
29 #include <cpu/amd/mtrr.h>
30 #include <cpu/amd/amdfam14.h>
32 #define DUMP_ACPI_TABLES 0
34 #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[];
53 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
57 char pscope[] = "\\_SB.PCI0";
59 lens = acpigen_write_scope(pscope);
61 lens += acpigen_write_name_dword("TOM1", msr.lo);
62 msr = rdmsr(TOP_MEM2);
64 * Since XP only implements parts of ACPI 2.0, we can't use a qword
66 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
68 * Shift value right by 20 bit to make it fit into 32bit,
69 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
71 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
72 acpigen_patch_len(lens - 1);
73 return (unsigned long) (acpigen_get_current());
76 unsigned long acpi_fill_mcfg(unsigned long current)
82 unsigned long acpi_fill_madt(unsigned long current)
84 /* create all subtables for processors */
85 current = acpi_create_madt_lapics(current);
87 /* Write SB800 IOAPIC, only one */
88 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
89 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
91 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
93 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
94 current, 0, 9, 9, 0xF);
96 /* 0: mean bus 0--->ISA */
99 /* 5 mean: 0101 --> Edige-triggered, Active high */
101 /* create all subtables for processors */
102 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
103 /* 1: LINT1 connect to NMI */
108 unsigned long acpi_fill_slit(unsigned long current)
114 unsigned long acpi_fill_srat(unsigned long current)
116 /* No NUMA, no SRAT */
120 unsigned long write_acpi_tables(unsigned long start)
122 unsigned long current;
133 acpi_header_t *ssdt2;
136 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
138 /* Align ACPI tables to 16 bytes */
139 start = (start + 0x0f) & -0x10;
142 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
144 /* We need at least an RSDP and an RSDT Table */
145 rsdp = (acpi_rsdp_t *) current;
146 current += sizeof(acpi_rsdp_t);
147 rsdt = (acpi_rsdt_t *) current;
148 current += sizeof(acpi_rsdt_t);
150 /* clear all table memory */
151 memset((void *)start, 0, current - start);
153 acpi_write_rsdp(rsdp, rsdt, NULL);
154 acpi_write_rsdt(rsdt);
157 current = ( current + 0x07) & -0x08;
158 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
159 dsdt = (acpi_header_t *)current;
160 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
161 current += dsdt->length;
162 memcpy(dsdt, &AmlCode, dsdt->length);
163 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
165 /* FACS */ // it needs 64 bit alignment
166 current = ( current + 0x07) & -0x08;
167 printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
168 facs = (acpi_facs_t *) current;
169 current += sizeof(acpi_facs_t);
170 acpi_create_facs(facs);
173 current = ( current + 0x07) & -0x08;
174 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
175 fadt = (acpi_fadt_t *) current;
176 current += sizeof(acpi_fadt_t);
178 acpi_create_fadt(fadt, facs, dsdt);
179 acpi_add_table(rsdp, fadt);
182 * We explicitly add these tables later on:
184 current = ( current + 0x07) & -0x08;
185 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
186 hpet = (acpi_hpet_t *) current;
187 current += sizeof(acpi_hpet_t);
188 acpi_create_hpet(hpet);
189 acpi_add_table(rsdp, hpet);
191 /* If we want to use HPET Timers Linux wants an MADT */
192 current = ( current + 0x07) & -0x08;
193 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
194 madt = (acpi_madt_t *) current;
195 acpi_create_madt(madt);
196 current += madt->header.length;
197 acpi_add_table(rsdp, madt);
200 current = ( current + 0x07) & -0x08;
201 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
202 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
204 memcpy((void *)current, srat, srat->header.length);
205 srat = (acpi_srat_t *) current;
206 current += srat->header.length;
207 acpi_add_table(rsdp, srat);
210 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
214 current = ( current + 0x07) & -0x08;
215 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
216 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
218 memcpy((void *)current, slit, slit->header.length);
219 slit = (acpi_slit_t *) current;
220 current += slit->header.length;
221 acpi_add_table(rsdp, slit);
224 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
228 current = ( current + 0x0f) & -0x10;
229 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
230 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
232 memcpy((void *)current, alib, alib->length);
233 ssdt = (acpi_header_t *) current;
234 current += alib->length;
235 acpi_add_table(rsdp,alib);
238 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
241 #if 0 // The DSDT needs additional work for the AGESA SSDT Pstate table
242 current = ( current + 0x0f) & -0x10;
243 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
244 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
246 memcpy((void *)current, ssdt, ssdt->length);
247 ssdt = (acpi_header_t *) current;
248 current += ssdt->length;
249 acpi_add_table(rsdp,ssdt);
252 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
254 acpi_add_table(rsdp,ssdt);
257 current = ( current + 0x0f) & -0x10;
258 printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current);
259 ssdt2 = (acpi_header_t *) current;
260 acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
261 current += ssdt2->length;
262 acpi_add_table(rsdp,ssdt2);
264 #if DUMP_ACPI_TABLES == 1
265 printk(BIOS_DEBUG, "rsdp\n");
266 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
268 printk(BIOS_DEBUG, "rsdt\n");
269 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
271 printk(BIOS_DEBUG, "madt\n");
272 dump_mem(madt, ((void *)madt) + madt->header.length);
274 printk(BIOS_DEBUG, "srat\n");
275 dump_mem(srat, ((void *)srat) + srat->header.length);
277 printk(BIOS_DEBUG, "slit\n");
278 dump_mem(slit, ((void *)slit) + slit->header.length);
280 printk(BIOS_DEBUG, "alib\n");
281 dump_mem(ssdt, ((void *)alib) + alib->length);
283 printk(BIOS_DEBUG, "ssdt\n");
284 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
286 printk(BIOS_DEBUG, "ssdt2\n");
287 dump_mem(ssdt2, ((void *)ssdt2) + ssdt2->length);
289 printk(BIOS_DEBUG, "fadt\n");
290 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
293 printk(BIOS_INFO, "ACPI: done.\n");