blob: b0105651ea4fa4897fb43586f796dbf17570e7fb [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 */
Kyösti Mälkkia6c525a2014-04-16 09:43:40 +030076 if (CONFIG_MAX_CPUS >= 16)
77 apicid_sb700 = 0x0;
78 else
79 apicid_sb700 = CONFIG_MAX_CPUS + 1;
80 apicid_rd890 = apicid_sb700 + 1;
Kerry Sheh6d6d18e2012-02-07 20:32:34 +080081
82 /* create all subtables for processors */
83 current = acpi_create_madt_lapics(current);
84
85 /* Write sb700 IOAPIC, only one */
86 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
87 apicid_sb700,
88 IO_APIC_ADDR,
89 0
90 );
91
92 /* IOAPIC on rs5690 */
93 gsi_base += IO_APIC_INTERRUPTS; /* sb700 has 24 IOAPIC entries. */
94 dev = dev_find_slot(0, PCI_DEVFN(0, 0));
95 if (dev) {
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,
99 apicid_rd890,
100 dword,
101 gsi_base
102 );
103 }
104
105 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current,
106 0, //BUS
107 0, //SOURCE
108 2, //gsirq
109 0 //flags
110 );
111
112 /* 0: mean bus 0--->ISA */
113 /* 0: PIC 0 */
114 /* 2: APIC 2 */
115 /* 5 mean: 0101 --> Edige-triggered, Active high */
116
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 */
121
122 return current;
123}
124
zbaocaf494c82012-04-13 13:57:14 +0800125unsigned long acpi_fill_hest(acpi_hest_t *hest)
126{
127 void *addr, *current;
128
129 /* Skip the HEST header. */
130 current = (void *)(hest + 1);
131
132 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
133 if (addr != NULL)
134 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
135
136 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
137 if (addr != NULL)
138 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
139
140 return (unsigned long)current;
141}
142
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800143unsigned long acpi_fill_slit(unsigned long current)
144{
145 // Not implemented
146 return current;
147}
148
149unsigned long acpi_fill_srat(unsigned long current)
150{
151 /* No NUMA, no SRAT */
152 return current;
153}
154
155unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
156{
157 int lens;
158 msr_t msr;
159 char pscope[] = "\\_SB.PCI0";
160
161 lens = acpigen_write_scope(pscope);
162 msr = rdmsr(TOP_MEM);
163 lens += acpigen_write_name_dword("TOM1", msr.lo);
164 msr = rdmsr(TOP_MEM2);
165 /*
166 * Since XP only implements parts of ACPI 2.0, we can't use a qword
167 * here.
168 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
169 * slide 22ff.
170 * Shift value right by 20 bit to make it fit into 32bit,
171 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
172 */
173 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
174 acpigen_patch_len(lens - 1);
175 return (unsigned long) (acpigen_get_current());
176}
177
178unsigned long write_acpi_tables(unsigned long start)
179{
180 unsigned long current;
181 acpi_rsdp_t *rsdp;
182 acpi_rsdt_t *rsdt;
183 //acpi_hpet_t *hpet;
184 acpi_madt_t *madt;
185 acpi_srat_t *srat;
186 acpi_slit_t *slit;
187 acpi_fadt_t *fadt;
188 acpi_facs_t *facs;
189 acpi_header_t *dsdt;
190 acpi_header_t *ssdt;
191 acpi_header_t *ssdt2;
192 acpi_header_t *alib;
zbaocaf494c82012-04-13 13:57:14 +0800193 acpi_hest_t *hest;
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800194
195 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
196
197 /* Align ACPI tables to 16 bytes */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200198 start = ALIGN(start, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800199 current = start;
200
201 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
202
203 /* We need at least an RSDP and an RSDT Table */
204 rsdp = (acpi_rsdp_t *) current;
205 current += sizeof(acpi_rsdp_t);
206 rsdt = (acpi_rsdt_t *) current;
207 current += sizeof(acpi_rsdt_t);
208
209 /* clear all table memory */
210 memset((void *)start, 0, current - start);
211
212 acpi_write_rsdp(rsdp, rsdt, NULL);
213 acpi_write_rsdt(rsdt);
214
215 /* FACS */
216 printk(BIOS_DEBUG, "ACPI: * FACS\n");
217 facs = (acpi_facs_t *) current;
218 current += sizeof(acpi_facs_t);
219 acpi_create_facs(facs);
220
221 /* DSDT */
222 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
223 dsdt = (acpi_header_t *)current;
224 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
225 current += dsdt->length;
226 memcpy(dsdt, &AmlCode, dsdt->length);
227 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
228 /* FADT */
229 printk(BIOS_DEBUG, "ACPI: * FADT\n");
230 fadt = (acpi_fadt_t *) current;
231 current += sizeof(acpi_fadt_t);
232
233 acpi_create_fadt(fadt, facs, dsdt);
234 acpi_add_table(rsdp, fadt);
235
236 /*
237 * We explicitly add these tables later on:
238 */
239#ifdef UNUSED_CODE // Don't need HPET table. we have one in dsdt
Patrick Georgi26b00e62012-04-20 19:19:47 +0200240 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800241 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
242 hpet = (acpi_hpet_t *) current;
243 current += sizeof(acpi_hpet_t);
244 acpi_create_hpet(hpet);
245 acpi_add_table(rsdp, hpet);
246#endif
247
248 /* If we want to use HPET Timers Linux wants an MADT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200249 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800250 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
251 madt = (acpi_madt_t *) current;
252 acpi_create_madt(madt);
253 current += madt->header.length;
254 acpi_add_table(rsdp, madt);
255
zbaocaf494c82012-04-13 13:57:14 +0800256 /* HEST */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200257 current = ALIGN(current, 8);
zbaocaf494c82012-04-13 13:57:14 +0800258 hest = (acpi_hest_t *)current;
259 acpi_write_hest((void *)current);
260 acpi_add_table(rsdp, (void *)current);
261 current += ((acpi_header_t *)current)->length;
262
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800263 /* SRAT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200264 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800265 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
266 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
267 if (srat != NULL) {
268 memcpy((void *)current, srat, srat->header.length);
269 srat = (acpi_srat_t *) current;
270 //acpi_create_srat(srat);
271 current += srat->header.length;
272 acpi_add_table(rsdp, srat);
273 }
274
275 /* SLIT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200276 current = ALIGN(current, 8);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800277 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
278 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
279 if (slit != NULL) {
280 memcpy((void *)current, slit, slit->header.length);
281 slit = (acpi_slit_t *) current;
282 //acpi_create_slit(slit);
283 current += slit->header.length;
284 acpi_add_table(rsdp, slit);
285 }
286
287 /* SSDT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200288 current = ALIGN(current, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800289 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
290 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
291 if (alib != NULL) {
292 memcpy((void *)current, alib, alib->length);
zbao21320052012-04-13 13:48:50 +0800293 alib = (acpi_header_t *) current;
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800294 current += alib->length;
zbao21320052012-04-13 13:48:50 +0800295 acpi_add_table(rsdp, (void *)alib);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800296 } else {
297 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
298 }
299
zbao585a4002012-04-12 11:27:26 +0800300 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
301 /* Keep the comment for a while. */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200302 current = ALIGN(current, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800303 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
304 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
305 if (ssdt != NULL) {
306 memcpy((void *)current, ssdt, ssdt->length);
307 ssdt = (acpi_header_t *) current;
308 current += ssdt->length;
zbao585a4002012-04-12 11:27:26 +0800309 acpi_add_table(rsdp,ssdt);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800310 } else {
zbao585a4002012-04-12 11:27:26 +0800311 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800312 }
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800313
Patrick Georgi26b00e62012-04-20 19:19:47 +0200314 current = ALIGN(current, 16);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800315 printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current);
316 ssdt2 = (acpi_header_t *) current;
317 acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
318 current += ssdt2->length;
319 acpi_add_table(rsdp,ssdt2);
320
321#if DUMP_ACPI_TABLES == 1
322 printk(BIOS_DEBUG, "rsdp\n");
323 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
324
325 printk(BIOS_DEBUG, "rsdt\n");
326 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
327
328 printk(BIOS_DEBUG, "madt\n");
329 dump_mem(madt, ((void *)madt) + madt->header.length);
330
331 printk(BIOS_DEBUG, "srat\n");
332 dump_mem(srat, ((void *)srat) + srat->header.length);
333
334 printk(BIOS_DEBUG, "slit\n");
335 dump_mem(slit, ((void *)slit) + slit->header.length);
336
337 printk(BIOS_DEBUG, "ssdt\n");
338 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
339
340 printk(BIOS_DEBUG, "fadt\n");
341 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
zbaocaf494c82012-04-13 13:57:14 +0800342
343 printk(BIOS_DEBUG, "hest\n");
344 dump_mem(hest, ((void *)hest) + hest->header.length);
Kerry Sheh6d6d18e2012-02-07 20:32:34 +0800345#endif
346
347 printk(BIOS_INFO, "ACPI: done.\n");
348 return current;
349}