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_hest(acpi_hest_t
*hest
)
110 void *addr
, *current
;
112 /* Skip the HEST header. */
113 current
= (void *)(hest
+ 1);
115 addr
= agesawrapper_getlateinitptr(PICK_WHEA_MCE
);
117 current
+= acpi_create_hest_error_source(hest
, current
, 0, (void *)((u32
)addr
+ 2), *(UINT16
*)addr
- 2);
119 addr
= agesawrapper_getlateinitptr(PICK_WHEA_CMC
);
121 current
+= acpi_create_hest_error_source(hest
, current
, 1, (void *)((u32
)addr
+ 2), *(UINT16
*)addr
- 2);
123 return (unsigned long)current
;
126 unsigned long acpi_fill_slit(unsigned long current
)
132 unsigned long acpi_fill_srat(unsigned long current
)
134 /* No NUMA, no SRAT */
138 unsigned long write_acpi_tables(unsigned long start
)
140 unsigned long current
;
151 acpi_header_t
*ssdt2
;
155 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
157 /* Align ACPI tables to 16 bytes */
158 start
= (start
+ 0x0f) & -0x10;
161 printk(BIOS_INFO
, "ACPI: Writing ACPI tables at %lx...\n", start
);
163 /* We need at least an RSDP and an RSDT Table */
164 rsdp
= (acpi_rsdp_t
*) current
;
165 current
+= sizeof(acpi_rsdp_t
);
166 rsdt
= (acpi_rsdt_t
*) current
;
167 current
+= sizeof(acpi_rsdt_t
);
169 /* clear all table memory */
170 memset((void *)start
, 0, current
- start
);
172 acpi_write_rsdp(rsdp
, rsdt
, NULL
);
173 acpi_write_rsdt(rsdt
);
176 current
= (current
+ 0x07) & -0x08;
177 printk(BIOS_DEBUG
, "ACPI: * DSDT at %lx\n", current
);
178 dsdt
= (acpi_header_t
*)current
;
179 memcpy(dsdt
, &AmlCode
, sizeof(acpi_header_t
));
180 current
+= dsdt
->length
;
181 memcpy(dsdt
, &AmlCode
, dsdt
->length
);
182 printk(BIOS_DEBUG
, "ACPI: * DSDT @ %p Length %x\n",dsdt
,dsdt
->length
);
184 /* FACS */ // it needs 64 bit alignment
185 current
= (current
+ 0x07) & -0x08;
186 printk(BIOS_DEBUG
, "ACPI: * FACS at %lx\n", current
);
187 facs
= (acpi_facs_t
*) current
;
188 current
+= sizeof(acpi_facs_t
);
189 acpi_create_facs(facs
);
192 current
= (current
+ 0x07) & -0x08;
193 printk(BIOS_DEBUG
, "ACPI: * FADT at %lx\n", current
);
194 fadt
= (acpi_fadt_t
*) current
;
195 current
+= sizeof(acpi_fadt_t
);
197 acpi_create_fadt(fadt
, facs
, dsdt
);
198 acpi_add_table(rsdp
, fadt
);
201 * We explicitly add these tables later on:
203 current
= (current
+ 0x07) & -0x08;
204 printk(BIOS_DEBUG
, "ACPI: * HPET at %lx\n", current
);
205 hpet
= (acpi_hpet_t
*) current
;
206 current
+= sizeof(acpi_hpet_t
);
207 acpi_create_hpet(hpet
);
208 acpi_add_table(rsdp
, hpet
);
210 /* If we want to use HPET Timers Linux wants an MADT */
211 current
= (current
+ 0x07) & -0x08;
212 printk(BIOS_DEBUG
, "ACPI: * MADT at %lx\n",current
);
213 madt
= (acpi_madt_t
*) current
;
214 acpi_create_madt(madt
);
215 current
+= madt
->header
.length
;
216 acpi_add_table(rsdp
, madt
);
219 current
= (current
+ 0x07) & -0x08;
220 hest
= (acpi_hest_t
*)current
;
221 acpi_write_hest((void *)current
);
222 acpi_add_table(rsdp
, (void *)current
);
223 current
+= ((acpi_header_t
*)current
)->length
;
226 current
= (current
+ 0x07) & -0x08;
227 printk(BIOS_DEBUG
, "ACPI: * SRAT at %lx\n", current
);
228 srat
= (acpi_srat_t
*) agesawrapper_getlateinitptr (PICK_SRAT
);
230 memcpy((void *)current
, srat
, srat
->header
.length
);
231 srat
= (acpi_srat_t
*) current
;
232 current
+= srat
->header
.length
;
233 acpi_add_table(rsdp
, srat
);
236 printk(BIOS_DEBUG
, " AGESA SRAT table NULL. Skipping.\n");
240 current
= (current
+ 0x07) & -0x08;
241 printk(BIOS_DEBUG
, "ACPI: * SLIT at %lx\n", current
);
242 slit
= (acpi_slit_t
*) agesawrapper_getlateinitptr (PICK_SLIT
);
244 memcpy((void *)current
, slit
, slit
->header
.length
);
245 slit
= (acpi_slit_t
*) current
;
246 current
+= slit
->header
.length
;
247 acpi_add_table(rsdp
, slit
);
250 printk(BIOS_DEBUG
, " AGESA SLIT table NULL. Skipping.\n");
254 current
= (current
+ 0x0f) & -0x10;
255 printk(BIOS_DEBUG
, "ACPI: * AGESA ALIB SSDT at %lx\n", current
);
256 alib
= (acpi_header_t
*)agesawrapper_getlateinitptr (PICK_ALIB
);
258 memcpy((void *)current
, alib
, alib
->length
);
259 alib
= (acpi_header_t
*) current
;
260 current
+= alib
->length
;
261 acpi_add_table(rsdp
, (void *)alib
);
263 printk(BIOS_DEBUG
, " AGESA ALIB SSDT table NULL. Skipping.\n");
266 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
267 /* Keep the comment for a while. */
268 current
= (current
+ 0x0f) & -0x10;
269 printk(BIOS_DEBUG
, "ACPI: * AGESA SSDT Pstate at %lx\n", current
);
270 ssdt
= (acpi_header_t
*)agesawrapper_getlateinitptr (PICK_PSTATE
);
272 memcpy((void *)current
, ssdt
, ssdt
->length
);
273 ssdt
= (acpi_header_t
*) current
;
274 current
+= ssdt
->length
;
275 acpi_add_table(rsdp
,ssdt
);
277 printk(BIOS_DEBUG
, " AGESA SSDT Pstate table NULL. Skipping.\n");
280 current
= (current
+ 0x0f) & -0x10;
281 printk(BIOS_DEBUG
, "ACPI: * coreboot TOM SSDT2 at %lx\n", current
);
282 ssdt2
= (acpi_header_t
*) current
;
283 acpi_create_ssdt_generator(ssdt2
, ACPI_TABLE_CREATOR
);
284 current
+= ssdt2
->length
;
285 acpi_add_table(rsdp
,ssdt2
);
287 #if DUMP_ACPI_TABLES == 1
288 printk(BIOS_DEBUG
, "rsdp\n");
289 dump_mem(rsdp
, ((void *)rsdp
) + sizeof(acpi_rsdp_t
));
291 printk(BIOS_DEBUG
, "rsdt\n");
292 dump_mem(rsdt
, ((void *)rsdt
) + sizeof(acpi_rsdt_t
));
294 printk(BIOS_DEBUG
, "madt\n");
295 dump_mem(madt
, ((void *)madt
) + madt
->header
.length
);
297 printk(BIOS_DEBUG
, "srat\n");
298 dump_mem(srat
, ((void *)srat
) + srat
->header
.length
);
300 printk(BIOS_DEBUG
, "slit\n");
301 dump_mem(slit
, ((void *)slit
) + slit
->header
.length
);
303 printk(BIOS_DEBUG
, "ssdt\n");
304 dump_mem(ssdt
, ((void *)ssdt
) + ssdt
->length
);
306 printk(BIOS_DEBUG
, "ssdt2\n");
307 dump_mem(ssdt2
, ((void *)ssdt2
) + ssdt2
->length
);
309 printk(BIOS_DEBUG
, "fadt\n");
310 dump_mem(fadt
, ((void *)fadt
) + fadt
->header
.length
);
312 printk(BIOS_DEBUG
, "hest\n");
313 dump_mem(hest
, ((void *)hest
) + hest
->header
.length
);
316 printk(BIOS_INFO
, "ACPI: done.\n");