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/ioapic.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cpu/x86/msr.h>
28 #include <cpu/amd/mtrr.h>
29 #include <cpu/amd/amdfam10_sysconf.h>
30 #include "agesawrapper.h"
32 #define DUMP_ACPI_TABLES 0
34 #if DUMP_ACPI_TABLES == 1
35 static void dump_mem(u32 start, u32 end)
39 print_debug("dump_mem:");
40 for (i = start; i < end; i++) {
42 printk(BIOS_DEBUG, "\n%08x:", i);
44 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
50 extern const unsigned char AmlCode[];
51 extern const unsigned char AmlCode_ssdt[];
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 write_acpi_tables(unsigned long start)
139 unsigned long current;
149 //acpi_header_t *ssdt;
151 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
153 /* Align ACPI tables to 16 bytes */
154 start = (start + 0x0f) & -0x10;
157 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
159 /* We need at least an RSDP and an RSDT Table */
160 rsdp = (acpi_rsdp_t *) current;
161 current += sizeof(acpi_rsdp_t);
162 rsdt = (acpi_rsdt_t *) current;
163 current += sizeof(acpi_rsdt_t);
165 /* clear all table memory */
166 memset((void *)start, 0, current - start);
168 acpi_write_rsdp(rsdp, rsdt, NULL);
169 acpi_write_rsdt(rsdt);
172 printk(BIOS_DEBUG, "ACPI: * FACS\n");
173 facs = (acpi_facs_t *) current;
174 current += sizeof(acpi_facs_t);
175 acpi_create_facs(facs);
178 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
179 dsdt = (acpi_header_t *)current;
180 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
181 current += dsdt->length;
182 memcpy(dsdt, &AmlCode, dsdt->length);
183 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
185 printk(BIOS_DEBUG, "ACPI: * FADT\n");
186 fadt = (acpi_fadt_t *) current;
187 current += sizeof(acpi_fadt_t);
189 acpi_create_fadt(fadt, facs, dsdt);
190 acpi_add_table(rsdp, fadt);
193 * We explicitly add these tables later on:
195 #ifdef UNUSED_CODE // Don't need HPET table. we have one in dsdt
196 current = ( current + 0x07) & -0x08;
197 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
198 hpet = (acpi_hpet_t *) current;
199 current += sizeof(acpi_hpet_t);
200 acpi_create_hpet(hpet);
201 acpi_add_table(rsdp, hpet);
204 /* If we want to use HPET Timers Linux wants an MADT */
205 current = ( current + 0x07) & -0x08;
206 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
207 madt = (acpi_madt_t *) current;
208 acpi_create_madt(madt);
209 current += madt->header.length;
210 acpi_add_table(rsdp, madt);
213 current = ( current + 0x07) & -0x08;
214 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
215 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
217 memcpy((void *)current, srat, srat->header.length);
218 srat = (acpi_srat_t *) current;
219 //acpi_create_srat(srat);
220 current += srat->header.length;
221 acpi_add_table(rsdp, srat);
225 current = ( current + 0x07) & -0x08;
226 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
227 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
229 memcpy((void *)current, slit, slit->header.length);
230 slit = (acpi_slit_t *) current;
231 //acpi_create_slit(slit);
232 current += slit->header.length;
233 acpi_add_table(rsdp, slit);
237 /* NOTE: we not update_ssdt, so ssdt only contain initialize value from ssdt.asl */
239 current = ( current + 0x0f) & -0x10;
240 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
241 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
243 memcpy(current, ssdt, ssdt->length);
244 ssdt = (acpi_header_t *) current;
245 current += ssdt->length;
248 ssdt = (acpi_header_t *) current;
249 memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
250 current += ssdt->length;
251 memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
252 /* recalculate checksum */
254 ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
256 acpi_add_table(rsdp,ssdt);
258 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
262 current = ( current + 0x07) & -0x08;
263 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
264 dsdt = (acpi_header_t *)current; // it will used by fadt
265 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
266 current += dsdt->length;
267 memcpy(dsdt, &AmlCode, dsdt->length);
268 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
270 #if DUMP_ACPI_TABLES == 1
271 printk(BIOS_DEBUG, "rsdp\n");
272 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
274 printk(BIOS_DEBUG, "rsdt\n");
275 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
277 printk(BIOS_DEBUG, "madt\n");
278 dump_mem(madt, ((void *)madt) + madt->header.length);
280 printk(BIOS_DEBUG, "srat\n");
281 dump_mem(srat, ((void *)srat) + srat->header.length);
283 printk(BIOS_DEBUG, "slit\n");
284 dump_mem(slit, ((void *)slit) + slit->header.length);
286 printk(BIOS_DEBUG, "ssdt\n");
287 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
289 printk(BIOS_DEBUG, "fadt\n");
290 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
293 printk(BIOS_INFO, "ACPI: done.\n");