blob: 1c1d94bdfab4da558be3417ae335e7f51a57672e [file] [log] [blame]
Alexandru Gagniucfccfee32014-03-26 18:51:08 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 *
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.
9 *
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.
14 *
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
18 */
19
Alexandru Gagniuc1d87dac2014-03-28 14:48:13 -050020#include "agesawrapper.h"
21
Alexandru Gagniucfccfee32014-03-26 18:51:08 -050022#include <arch/acpi.h>
23#include <arch/acpigen.h>
24#include <arch/ioapic.h>
Alexandru Gagniuc1d87dac2014-03-28 14:48:13 -050025#include <cpu/amd/amdfam15.h>
26#include <console/console.h>
Alexandru Gagniucfccfee32014-03-26 18:51:08 -050027#include <device/pci.h>
28#include <device/pci_ids.h>
Alexandru Gagniuc1d87dac2014-03-28 14:48:13 -050029#include <string.h>
Alexandru Gagniucfccfee32014-03-26 18:51:08 -050030
31#define DUMP_ACPI_TABLES 0
32
33#if DUMP_ACPI_TABLES == 1
34
35static void dump_mem(u32 start, u32 end)
36{
37 u32 i;
38 print_debug("dump_mem:");
39 for (i = start; i < end; i++) {
40 if ((i & 0xf) == 0) {
41 printk(BIOS_DEBUG, "\n%08x:", i);
42 }
43 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
44 }
45 print_debug("\n");
46}
47#endif
48
49extern const unsigned char AmlCode[];
50
51unsigned long acpi_fill_mcfg(unsigned long current)
52{
53 /* Just a dummy */
54 return current;
55}
56
57unsigned long acpi_fill_madt(unsigned long current)
58{
59 /* create all subtables for processors */
60 current = acpi_create_madt_lapics(current);
61
62 /* Write Hudson IOAPIC, only one */
63 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, CONFIG_MAX_CPUS,
64 IO_APIC_ADDR, 0);
65
66 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
67 current, 0, 0, 2, 0);
68 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
69 current, 0, 9, 9, 0xF);
70 /* 0: mean bus 0--->ISA */
71 /* 0: PIC 0 */
72 /* 2: APIC 2 */
73 /* 5 mean: 0101 --> Edige-triggered, Active high */
74
75 /* create all subtables for processors */
76 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 5, 1);
77 /* 1: LINT1 connect to NMI */
78
79 return current;
80}
81
82unsigned long acpi_fill_hest(acpi_hest_t *hest)
83{
84 void *addr, *current;
85
86 /* Skip the HEST header. */
87 current = (void *)(hest + 1);
88
89 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
90 if (addr != NULL)
91 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
92
93 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
94 if (addr != NULL)
95 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
96
97 return (unsigned long)current;
98}
99
100unsigned long acpi_fill_slit(unsigned long current)
101{
102 /* Not implemented */
103 return current;
104}
105
106unsigned long acpi_fill_srat(unsigned long current)
107{
108 /* No NUMA, no SRAT */
109 return current;
110}
111
112unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
113{
114 int lens;
115 msr_t msr;
116 char pscope[] = "\\_SB.PCI0";
117
118 lens = acpigen_write_scope(pscope);
119 msr = rdmsr(TOP_MEM);
120 lens += acpigen_write_name_dword("TOM1", msr.lo);
121 msr = rdmsr(TOP_MEM2);
122 /*
123 * Since XP only implements parts of ACPI 2.0, we can't use a qword
124 * here.
125 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
126 * slide 22ff.
127 * Shift value right by 20 bit to make it fit into 32bit,
128 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
129 */
130 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
131 acpigen_patch_len(lens - 1);
132 return (unsigned long) (acpigen_get_current());
133}
134
135unsigned long write_acpi_tables(unsigned long start)
136{
137 unsigned long current;
138 acpi_rsdp_t *rsdp;
139 acpi_rsdt_t *rsdt;
140 acpi_hpet_t *hpet;
141 acpi_madt_t *madt;
142 acpi_srat_t *srat;
143 acpi_slit_t *slit;
144 acpi_fadt_t *fadt;
145 acpi_facs_t *facs;
146 acpi_header_t *dsdt;
147 acpi_header_t *ssdt;
148 acpi_header_t *alib;
149 acpi_header_t *ivrs;
150 acpi_hest_t *hest;
151
152 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
153
154 /* Align ACPI tables to 16 bytes */
155 start = ALIGN(start, 16);
156 current = start;
157
158 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
159
160 /* We need at least an RSDP and an RSDT Table */
161 rsdp = (acpi_rsdp_t *) current;
162 current += sizeof(acpi_rsdp_t);
163 rsdt = (acpi_rsdt_t *) current;
164 current += sizeof(acpi_rsdt_t);
165
166 /* clear all table memory */
167 memset((void *)start, 0, current - start);
168
169 acpi_write_rsdp(rsdp, rsdt, NULL);
170 acpi_write_rsdt(rsdt);
171
172 /* DSDT */
173 current = ALIGN(current, 8);
174 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
175 dsdt = (acpi_header_t *)current; /* it will used by fadt */
176 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
177 current += dsdt->length;
178 memcpy(dsdt, &AmlCode, dsdt->length);
179 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
180
181 /* FACS */ /* it needs 64 bit alignment */
182 current = ALIGN(current, 8);
183 printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
184 facs = (acpi_facs_t *) current; /* it will be used by fadt */
185 current += sizeof(acpi_facs_t);
186 acpi_create_facs(facs);
187
188 /* FADT */
189 current = ALIGN(current, 8);
190 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
191 fadt = (acpi_fadt_t *) current;
192 current += sizeof(acpi_fadt_t);
193
194 acpi_create_fadt(fadt, facs, dsdt);
195 acpi_add_table(rsdp, fadt);
196
197 /*
198 * We explicitly add these tables later on:
199 */
200 current = ALIGN(current, 8);
201 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
202 hpet = (acpi_hpet_t *) current;
203 current += sizeof(acpi_hpet_t);
204 acpi_create_hpet(hpet);
205 acpi_add_table(rsdp, hpet);
206
207 /* If we want to use HPET Timers Linux wants an MADT */
208 current = ALIGN(current, 8);
209 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
210 madt = (acpi_madt_t *) current;
211 acpi_create_madt(madt);
212 current += madt->header.length;
213 acpi_add_table(rsdp, madt);
214
215 /* HEST */
216 current = ALIGN(current, 8);
217 hest = (acpi_hest_t *)current;
218 acpi_write_hest((void *)current);
219 acpi_add_table(rsdp, (void *)current);
220 current += ((acpi_header_t *)current)->length;
221
222 current = ALIGN(current, 8);
223 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
224 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
225 if (ivrs != NULL) {
226 memcpy((void *)current, ivrs, ivrs->length);
227 ivrs = (acpi_header_t *) current;
228 current += ivrs->length;
229 acpi_add_table(rsdp, ivrs);
230 } else {
231 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
232 }
233
234 /* SRAT */
235 current = ALIGN(current, 8);
236 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
237 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
238 if (srat != NULL) {
239 memcpy((void *)current, srat, srat->header.length);
240 srat = (acpi_srat_t *) current;
241 current += srat->header.length;
242 acpi_add_table(rsdp, srat);
243 } else {
244 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
245 }
246
247 /* SLIT */
248 current = ALIGN(current, 8);
249 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
250 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
251 if (slit != NULL) {
252 memcpy((void *)current, slit, slit->header.length);
253 slit = (acpi_slit_t *) current;
254 current += slit->header.length;
255 acpi_add_table(rsdp, slit);
256 } else {
257 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
258 }
259
260 /* ALIB */
261 current = ALIGN(current, 16);
262 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
263 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
264 if (alib != NULL) {
265 memcpy((void *)current, alib, alib->length);
266 alib = (acpi_header_t *) current;
267 current += alib->length;
268 acpi_add_table(rsdp, (void *)alib);
269 }
270 else {
271 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
272 }
273
274 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
275 /* SSDT */
276 current = ALIGN(current, 16);
277 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
278 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
279 if (ssdt != NULL) {
280 memcpy((void *)current, ssdt, ssdt->length);
281 ssdt = (acpi_header_t *) current;
282 current += ssdt->length;
283 }
284 else {
285 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
286 }
287 acpi_add_table(rsdp,ssdt);
288
289 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
290
291 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
292 ssdt = (acpi_header_t *)current;
293
294 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
295 current += ssdt->length;
296 acpi_add_table(rsdp, ssdt);
297
298#if DUMP_ACPI_TABLES == 1
299 printk(BIOS_DEBUG, "rsdp\n");
300 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
301
302 printk(BIOS_DEBUG, "rsdt\n");
303 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
304
305 printk(BIOS_DEBUG, "madt\n");
306 dump_mem(madt, ((void *)madt) + madt->header.length);
307
308 printk(BIOS_DEBUG, "srat\n");
309 dump_mem(srat, ((void *)srat) + srat->header.length);
310
311 printk(BIOS_DEBUG, "slit\n");
312 dump_mem(slit, ((void *)slit) + slit->header.length);
313
314 printk(BIOS_DEBUG, "ssdt\n");
315 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
316
317 printk(BIOS_DEBUG, "fadt\n");
318 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
319
320 printk(BIOS_DEBUG, "hest\n");
321 dump_mem(hest, ((void *)hest) + hest->header.length);
322#endif
323
324 printk(BIOS_INFO, "ACPI: done.\n");
325 return current;
326}