blob: c4a42dc1d6b30978fd09ca960e351306aaf28ba2 [file] [log] [blame]
Kerry Sheh6d6d18e2012-02-07 20:32:34 +08001/*
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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Kerry Sheh6d6d18e2012-02-07 20:32:34 +080018 */
19
20#include <console/console.h>
21#include <string.h>
22#include <arch/acpi.h>
23#include <arch/acpigen.h>
24#include <arch/ioapic.h>
25#include <arch/io.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
31#include "agesawrapper.h"
Bruce Griffith93b57c52013-06-25 19:27:17 -060032#include <cpu/amd/amdfam15.h>
Kerry Sheh6d6d18e2012-02-07 20:32:34 +080033
34#define DUMP_ACPI_TABLES 0
35
36#if DUMP_ACPI_TABLES == 1
37static void dump_mem(u32 start, u32 end)
38{
39
40 u32 i;
41 print_debug("dump_mem:");
42 for (i = start; i < end; i++) {
43 if ((i & 0xf) == 0) {
44 printk(BIOS_DEBUG, "\n%08x:", i);
45 }
46 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
47 }
48 print_debug("\n");
49}
50#endif
51
52extern const unsigned char AmlCode[];
53
54
55unsigned long acpi_fill_mcfg(unsigned long current)
56{
57 /* Just a dummy */
58 return current;
59}
60
61unsigned long acpi_fill_madt(unsigned long current)
62{
63 device_t dev;
64 u32 dword;
65 u32 gsi_base = 0;
66 u32 apicid_sb700;
67 u32 apicid_rd890;
68
69 /*
70 * AGESA v5 Apply apic enumeration rules
71 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
72 * put the local-APICs at m..z
73 * For systems with < 16 APICs, put the Local-APICs at 0..n and
74 * put the IO-APICs at (n + 1)..z
75 */
76#if CONFIG_MAX_CPUS >= 16
77 apicid_sb700 = 0x0;
78#else
79 apicid_sb700 = CONFIG_MAX_CPUS + 1
80#endif
81 apicid_rd890 = apicid_sb700 + 1;
82
83 /* create all subtables for processors */
84 current = acpi_create_madt_lapics(current);
85
86 /* Write sb700 IOAPIC, only one */
87 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
88 apicid_sb700,
89 IO_APIC_ADDR,
90 0
91 );
92
93 /* IOAPIC on rs5690 */
94 gsi_base += IO_APIC_INTERRUPTS; /* sb700 has 24 IOAPIC entries. */
95 dev = dev_find_slot(0, PCI_DEVFN(0, 0));
96 if (dev) {
97 pci_write_config32(dev, 0xF8, 0x1);
98 dword = pci_read_config32(dev, 0xFC) & 0xfffffff0;
99 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
100 apicid_rd890,
101 dword,
102 gsi_base
103 );
104 }
105
106 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current,
107 0, //BUS
108 0, //SOURCE
109 2, //gsirq
110 0 //flags
111 );
112
113 /* 0: mean bus 0--->ISA */
114 /* 0: PIC 0 */
115 /* 2: APIC 2 */
116 /* 5 mean: 0101 --> Edige-triggered, Active high */
117
118 /* create all subtables for processors */
119 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0, 5, 1);
120 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 1, 5, 1);
121 /* 1: LINT1 connect to NMI */
122
123 return current;
124}
125
zbaocaf494c82012-04-13 13:57:14 +0800126unsigned long acpi_fill_hest(acpi_hest_t *hest)
127{
128 void *addr, *current;
129
130 /* Skip the HEST header. */
131 current = (void *)(hest + 1);
132
133 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
134 if (addr != NULL)
135 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
136
137 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
138 if (addr != NULL)
139 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
140
141 return (unsigned long)current;
142}
143
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800144unsigned long acpi_fill_slit(unsigned long current)
145{
146 // Not implemented
147 return current;
148}
149
150unsigned long acpi_fill_srat(unsigned long current)
151{
152 /* No NUMA, no SRAT */
153 return current;
154}
155
156unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
157{
158 int lens;
159 msr_t msr;
160 char pscope[] = "\\_SB.PCI0";
161
162 lens = acpigen_write_scope(pscope);
163 msr = rdmsr(TOP_MEM);
164 lens += acpigen_write_name_dword("TOM1", msr.lo);
165 msr = rdmsr(TOP_MEM2);
166 /*
167 * Since XP only implements parts of ACPI 2.0, we can't use a qword
168 * here.
169 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
170 * slide 22ff.
171 * Shift value right by 20 bit to make it fit into 32bit,
172 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
173 */
174 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
175 acpigen_patch_len(lens - 1);
176 return (unsigned long) (acpigen_get_current());
177}
178
179unsigned long write_acpi_tables(unsigned long start)
180{
181 unsigned long current;
182 acpi_rsdp_t *rsdp;
183 acpi_rsdt_t *rsdt;
184 //acpi_hpet_t *hpet;
185 acpi_madt_t *madt;
186 acpi_srat_t *srat;
187 acpi_slit_t *slit;
188 acpi_fadt_t *fadt;
189 acpi_facs_t *facs;
190 acpi_header_t *dsdt;
191 acpi_header_t *ssdt;
192 acpi_header_t *ssdt2;
193 acpi_header_t *alib;
zbaocaf494c82012-04-13 13:57:14 +0800194 acpi_hest_t *hest;
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800195
196 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
197
198 /* Align ACPI tables to 16 bytes */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200199 start = ALIGN(start, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800200 current = start;
201
202 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
203
204 /* We need at least an RSDP and an RSDT Table */
205 rsdp = (acpi_rsdp_t *) current;
206 current += sizeof(acpi_rsdp_t);
207 rsdt = (acpi_rsdt_t *) current;
208 current += sizeof(acpi_rsdt_t);
209
210 /* clear all table memory */
211 memset((void *)start, 0, current - start);
212
213 acpi_write_rsdp(rsdp, rsdt, NULL);
214 acpi_write_rsdt(rsdt);
215
216 /* FACS */
217 printk(BIOS_DEBUG, "ACPI: * FACS\n");
218 facs = (acpi_facs_t *) current;
219 current += sizeof(acpi_facs_t);
220 acpi_create_facs(facs);
221
222 /* DSDT */
223 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
224 dsdt = (acpi_header_t *)current;
225 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
226 current += dsdt->length;
227 memcpy(dsdt, &AmlCode, dsdt->length);
228 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
229 /* FADT */
230 printk(BIOS_DEBUG, "ACPI: * FADT\n");
231 fadt = (acpi_fadt_t *) current;
232 current += sizeof(acpi_fadt_t);
233
234 acpi_create_fadt(fadt, facs, dsdt);
235 acpi_add_table(rsdp, fadt);
236
237 /*
238 * We explicitly add these tables later on:
239 */
240#ifdef UNUSED_CODE // Don't need HPET table. we have one in dsdt
Patrick Georgi26b00e62012-04-20 19:19:47 +0200241 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800242 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
243 hpet = (acpi_hpet_t *) current;
244 current += sizeof(acpi_hpet_t);
245 acpi_create_hpet(hpet);
246 acpi_add_table(rsdp, hpet);
247#endif
248
249 /* If we want to use HPET Timers Linux wants an MADT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200250 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800251 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
252 madt = (acpi_madt_t *) current;
253 acpi_create_madt(madt);
254 current += madt->header.length;
255 acpi_add_table(rsdp, madt);
256
zbaocaf494c82012-04-13 13:57:14 +0800257 /* HEST */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200258 current = ALIGN(current, 8);
zbaocaf494c82012-04-13 13:57:14 +0800259 hest = (acpi_hest_t *)current;
260 acpi_write_hest((void *)current);
261 acpi_add_table(rsdp, (void *)current);
262 current += ((acpi_header_t *)current)->length;
263
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800264 /* SRAT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200265 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800266 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
267 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
268 if (srat != NULL) {
269 memcpy((void *)current, srat, srat->header.length);
270 srat = (acpi_srat_t *) current;
271 //acpi_create_srat(srat);
272 current += srat->header.length;
273 acpi_add_table(rsdp, srat);
274 }
275
276 /* SLIT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200277 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800278 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
279 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
280 if (slit != NULL) {
281 memcpy((void *)current, slit, slit->header.length);
282 slit = (acpi_slit_t *) current;
283 //acpi_create_slit(slit);
284 current += slit->header.length;
285 acpi_add_table(rsdp, slit);
286 }
287
288 /* SSDT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200289 current = ALIGN(current, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800290 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
291 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
292 if (alib != NULL) {
293 memcpy((void *)current, alib, alib->length);
zbao21320052012-04-13 13:48:50 +0800294 alib = (acpi_header_t *) current;
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800295 current += alib->length;
zbao21320052012-04-13 13:48:50 +0800296 acpi_add_table(rsdp, (void *)alib);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800297 } else {
298 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
299 }
300
zbao585a4002012-04-12 11:27:26 +0800301 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
302 /* Keep the comment for a while. */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200303 current = ALIGN(current, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800304 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
305 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
306 if (ssdt != NULL) {
307 memcpy((void *)current, ssdt, ssdt->length);
308 ssdt = (acpi_header_t *) current;
309 current += ssdt->length;
zbao585a4002012-04-12 11:27:26 +0800310 acpi_add_table(rsdp,ssdt);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800311 } else {
zbao585a4002012-04-12 11:27:26 +0800312 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800313 }
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800314
Patrick Georgi26b00e62012-04-20 19:19:47 +0200315 current = ALIGN(current, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800316 printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current);
317 ssdt2 = (acpi_header_t *) current;
318 acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
319 current += ssdt2->length;
320 acpi_add_table(rsdp,ssdt2);
321
322#if DUMP_ACPI_TABLES == 1
323 printk(BIOS_DEBUG, "rsdp\n");
324 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
325
326 printk(BIOS_DEBUG, "rsdt\n");
327 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
328
329 printk(BIOS_DEBUG, "madt\n");
330 dump_mem(madt, ((void *)madt) + madt->header.length);
331
332 printk(BIOS_DEBUG, "srat\n");
333 dump_mem(srat, ((void *)srat) + srat->header.length);
334
335 printk(BIOS_DEBUG, "slit\n");
336 dump_mem(slit, ((void *)slit) + slit->header.length);
337
338 printk(BIOS_DEBUG, "ssdt\n");
339 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
340
341 printk(BIOS_DEBUG, "fadt\n");
342 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
zbaocaf494c82012-04-13 13:57:14 +0800343
344 printk(BIOS_DEBUG, "hest\n");
345 dump_mem(hest, ((void *)hest) + hest->header.length);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800346#endif
347
348 printk(BIOS_INFO, "ACPI: done.\n");
349 return current;
350}