blob: 0a64535e002167569a95ac6305620f30c6cec6ce [file] [log] [blame]
zbao323a9232012-07-19 16:39:01 +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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
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 <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/amdfam15.h>
31
32#include "agesawrapper.h"
33
34#define DUMP_ACPI_TABLES 0
35
36#if DUMP_ACPI_TABLES == 1
37
38static void dump_mem(u32 start, u32 end)
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
54unsigned long acpi_fill_mcfg(unsigned long current)
55{
56 /* Just a dummy */
57 return current;
58}
59
60unsigned long acpi_fill_madt(unsigned long current)
61{
62 /* create all subtables for processors */
63 current = acpi_create_madt_lapics(current);
64
65 /* Write SB800 IOAPIC, only one */
66 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, CONFIG_MAX_CPUS,
67 IO_APIC_ADDR, 0);
68
69 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
70 current, 0, 0, 2, 0);
71 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
72 current, 0, 9, 9, 0xF);
73 /* 0: mean bus 0--->ISA */
74 /* 0: PIC 0 */
75 /* 2: APIC 2 */
76 /* 5 mean: 0101 --> Edige-triggered, Active high */
77
78 /* create all subtables for processors */
zbao15945442012-08-03 11:47:53 +080079 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 5, 1);
zbao323a9232012-07-19 16:39:01 +080080 /* 1: LINT1 connect to NMI */
81
82 return current;
83}
84
85unsigned long acpi_fill_hest(acpi_hest_t *hest)
86{
87 void *addr, *current;
88
89 /* Skip the HEST header. */
90 current = (void *)(hest + 1);
91
92 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
93 if (addr != NULL)
94 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
95
96 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
97 if (addr != NULL)
98 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
99
100 return (unsigned long)current;
101}
102
103unsigned long acpi_fill_slit(unsigned long current)
104{
105 /* Not implemented */
106 return current;
107}
108
109unsigned long acpi_fill_srat(unsigned long current)
110{
111 /* No NUMA, no SRAT */
112 return current;
113}
114
115unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
116{
117 int lens;
118 msr_t msr;
119 char pscope[] = "\\_SB.PCI0";
120
121 lens = acpigen_write_scope(pscope);
122 msr = rdmsr(TOP_MEM);
123 lens += acpigen_write_name_dword("TOM1", msr.lo);
124 msr = rdmsr(TOP_MEM2);
125 /*
126 * Since XP only implements parts of ACPI 2.0, we can't use a qword
127 * here.
128 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
129 * slide 22ff.
130 * Shift value right by 20 bit to make it fit into 32bit,
131 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
132 */
133 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
134 acpigen_patch_len(lens - 1);
135 return (unsigned long) (acpigen_get_current());
136}
137
138unsigned long write_acpi_tables(unsigned long start)
139{
140 unsigned long current;
141 acpi_rsdp_t *rsdp;
142 acpi_rsdt_t *rsdt;
143 acpi_hpet_t *hpet;
144 acpi_madt_t *madt;
145 acpi_srat_t *srat;
146 acpi_slit_t *slit;
147 acpi_fadt_t *fadt;
148 acpi_facs_t *facs;
149 acpi_header_t *dsdt;
150 acpi_header_t *ssdt;
151 acpi_header_t *alib;
152 acpi_header_t *ivrs;
153 acpi_hest_t *hest;
154
155 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
156
157 /* Align ACPI tables to 16 bytes */
158 start = (start + 0x0f) & -0x10;
159 current = start;
160
161 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
162
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);
168
169 /* clear all table memory */
170 memset((void *)start, 0, current - start);
171
172 acpi_write_rsdp(rsdp, rsdt, NULL);
173 acpi_write_rsdt(rsdt);
174
175 /* DSDT */
176 current = (current + 0x07) & -0x08;
177 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
178 dsdt = (acpi_header_t *)current; /* it will used by fadt */
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);
183
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; /* it will be used by fadt */
188 current += sizeof(acpi_facs_t);
189 acpi_create_facs(facs);
190
191 /* FADT */
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);
196
197 acpi_create_fadt(fadt, facs, dsdt);
198 acpi_add_table(rsdp, fadt);
199
200 /*
201 * We explicitly add these tables later on:
202 */
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);
209
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);
217
218 /* HEST */
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;
224
225 current = (current + 0x07) & -0x08;
226 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
227 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
228 if (ivrs != NULL) {
229 memcpy((void *)current, ivrs, ivrs->length);
230 ivrs = (acpi_header_t *) current;
231 current += ivrs->length;
232 acpi_add_table(rsdp, ivrs);
233 } else {
234 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
235 }
236
237 /* SRAT */
238 current = (current + 0x07) & -0x08;
239 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
240 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
241 if (srat != NULL) {
242 memcpy((void *)current, srat, srat->header.length);
243 srat = (acpi_srat_t *) current;
244 current += srat->header.length;
245 acpi_add_table(rsdp, srat);
246 } else {
247 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
248 }
249
250 /* SLIT */
251 current = (current + 0x07) & -0x08;
252 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
253 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
254 if (slit != NULL) {
255 memcpy((void *)current, slit, slit->header.length);
256 slit = (acpi_slit_t *) current;
257 current += slit->header.length;
258 acpi_add_table(rsdp, slit);
259 } else {
260 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
261 }
262
263 /* ALIB */
264 current = (current + 0x0f) & -0x10;
265 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
266 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
267 if (alib != NULL) {
268 memcpy((void *)current, alib, alib->length);
269 alib = (acpi_header_t *) current;
270 current += alib->length;
271 acpi_add_table(rsdp, (void *)alib);
272 }
273 else {
274 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
275 }
276
277 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
278 /* SSDT */
279 current = ( current + 0x0f) & -0x10;
280 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
281 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
282 if (ssdt != NULL) {
283 memcpy((void *)current, ssdt, ssdt->length);
284 ssdt = (acpi_header_t *) current;
285 current += ssdt->length;
286 }
287 else {
288 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
289 }
290 acpi_add_table(rsdp,ssdt);
291
292 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
293
294 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
295 ssdt = (acpi_header_t *)current;
296
297 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
298 current += ssdt->length;
299 acpi_add_table(rsdp, ssdt);
300
301#if DUMP_ACPI_TABLES == 1
302 printk(BIOS_DEBUG, "rsdp\n");
303 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
304
305 printk(BIOS_DEBUG, "rsdt\n");
306 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
307
308 printk(BIOS_DEBUG, "madt\n");
309 dump_mem(madt, ((void *)madt) + madt->header.length);
310
311 printk(BIOS_DEBUG, "srat\n");
312 dump_mem(srat, ((void *)srat) + srat->header.length);
313
314 printk(BIOS_DEBUG, "slit\n");
315 dump_mem(slit, ((void *)slit) + slit->header.length);
316
317 printk(BIOS_DEBUG, "ssdt\n");
318 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
319
320 printk(BIOS_DEBUG, "fadt\n");
321 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
322
323 printk(BIOS_DEBUG, "hest\n");
324 dump_mem(hest, ((void *)hest) + hest->header.length);
325#endif
326
327 printk(BIOS_INFO, "ACPI: done.\n");
328 return current;
329}