blob: e32a42bbd7d3615fd86e330cce22b28f455cde9e [file] [log] [blame]
Scott Duplichana649a962011-02-24 05:00:33 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 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>
zbao585a4002012-04-12 11:27:26 +080023#include <arch/acpigen.h>
Scott Duplichana649a962011-02-24 05:00:33 +000024#include <arch/ioapic.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
27#include <cpu/x86/msr.h>
Scott Duplichana649a962011-02-24 05:00:33 +000028#include "agesawrapper.h"
Marc Jones84e0dfc2011-12-12 21:12:43 -070029#include <cpu/amd/mtrr.h>
30#include <cpu/amd/amdfam14.h>
Scott Duplichana649a962011-02-24 05:00:33 +000031
32#define DUMP_ACPI_TABLES 0
33
34#if DUMP_ACPI_TABLES == 1
35
36static void dump_mem(u32 start, u32 end)
37{
38
Marc Jones522ba282012-01-03 16:02:07 -070039 u32 i;
40 print_debug("dump_mem:");
41 for (i = start; i < end; i++) {
42 if ((i & 0xf) == 0) {
43 printk(BIOS_DEBUG, "\n%08x:", i);
44 }
45 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
46 }
47 print_debug("\n");
Scott Duplichana649a962011-02-24 05:00:33 +000048}
49#endif
50
51extern const unsigned char AmlCode[];
Marc Jones84e0dfc2011-12-12 21:12:43 -070052
53unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
54{
55 int lens;
56 msr_t msr;
57 char pscope[] = "\\_SB.PCI0";
58
59 lens = acpigen_write_scope(pscope);
60 msr = rdmsr(TOP_MEM);
61 lens += acpigen_write_name_dword("TOM1", msr.lo);
62 msr = rdmsr(TOP_MEM2);
63 /*
64 * Since XP only implements parts of ACPI 2.0, we can't use a qword
65 * here.
66 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
67 * slide 22ff.
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.
70 */
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());
74}
Scott Duplichana649a962011-02-24 05:00:33 +000075
76unsigned long acpi_fill_mcfg(unsigned long current)
77{
Marc Jones522ba282012-01-03 16:02:07 -070078 /* Just a dummy */
79 return current;
Scott Duplichana649a962011-02-24 05:00:33 +000080}
81
82unsigned long acpi_fill_madt(unsigned long current)
83{
Marc Jones522ba282012-01-03 16:02:07 -070084 /* create all subtables for processors */
85 current = acpi_create_madt_lapics(current);
Scott Duplichana649a962011-02-24 05:00:33 +000086
Marc Jones522ba282012-01-03 16:02:07 -070087 /* Write SB800 IOAPIC, only one */
88 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
89 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
Scott Duplichana649a962011-02-24 05:00:33 +000090
Marc Jones522ba282012-01-03 16:02:07 -070091 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
92 current, 0, 0, 2, 0);
93 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
94 current, 0, 9, 9, 0xF);
Scott Duplichana649a962011-02-24 05:00:33 +000095
Marc Jones522ba282012-01-03 16:02:07 -070096 /* 0: mean bus 0--->ISA */
97 /* 0: PIC 0 */
98 /* 2: APIC 2 */
99 /* 5 mean: 0101 --> Edige-triggered, Active high */
Scott Duplichana649a962011-02-24 05:00:33 +0000100
Marc Jones522ba282012-01-03 16:02:07 -0700101 /* create all subtables for processors */
102 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
103 /* 1: LINT1 connect to NMI */
104
105 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000106}
107
zbaocaf494c82012-04-13 13:57:14 +0800108unsigned long acpi_fill_hest(acpi_hest_t *hest)
109{
110 void *addr, *current;
111
112 /* Skip the HEST header. */
113 current = (void *)(hest + 1);
114
115 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
116 if (addr != NULL)
117 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
118
119 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
120 if (addr != NULL)
121 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
122
123 return (unsigned long)current;
124}
125
Scott Duplichana649a962011-02-24 05:00:33 +0000126unsigned long acpi_fill_slit(unsigned long current)
127{
Marc Jones522ba282012-01-03 16:02:07 -0700128 // Not implemented
129 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000130}
131
132unsigned long acpi_fill_srat(unsigned long current)
133{
Marc Jones522ba282012-01-03 16:02:07 -0700134 /* No NUMA, no SRAT */
135 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000136}
137
138unsigned long write_acpi_tables(unsigned long start)
139{
Marc Jones522ba282012-01-03 16:02:07 -0700140 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;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700151 acpi_header_t *ssdt2;
Marc Jones7bfd22e2011-12-12 22:04:25 -0700152 acpi_header_t *alib;
zbaocaf494c82012-04-13 13:57:14 +0800153 acpi_hest_t *hest;
Scott Duplichana649a962011-02-24 05:00:33 +0000154
Marc Jones522ba282012-01-03 16:02:07 -0700155 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
Scott Duplichana649a962011-02-24 05:00:33 +0000156
Marc Jones522ba282012-01-03 16:02:07 -0700157 /* Align ACPI tables to 16 bytes */
158 start = (start + 0x0f) & -0x10;
159 current = start;
Scott Duplichana649a962011-02-24 05:00:33 +0000160
Marc Jones522ba282012-01-03 16:02:07 -0700161 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
Scott Duplichana649a962011-02-24 05:00:33 +0000162
Marc Jones522ba282012-01-03 16:02:07 -0700163 /* 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);
Scott Duplichana649a962011-02-24 05:00:33 +0000168
Marc Jones522ba282012-01-03 16:02:07 -0700169 /* clear all table memory */
170 memset((void *)start, 0, current - start);
Scott Duplichana649a962011-02-24 05:00:33 +0000171
Marc Jones522ba282012-01-03 16:02:07 -0700172 acpi_write_rsdp(rsdp, rsdt, NULL);
173 acpi_write_rsdt(rsdt);
Scott Duplichana649a962011-02-24 05:00:33 +0000174
Marc Jones84e0dfc2011-12-12 21:12:43 -0700175 /* DSDT */
zbaocaf494c82012-04-13 13:57:14 +0800176 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700177 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);
183
184 /* FACS */ // it needs 64 bit alignment
zbaocaf494c82012-04-13 13:57:14 +0800185 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700186 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);
190
191 /* FADT */
zbaocaf494c82012-04-13 13:57:14 +0800192 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700193 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
Marc Jones522ba282012-01-03 16:02:07 -0700200 /*
Marc Jones84e0dfc2011-12-12 21:12:43 -0700201 * We explicitly add these tables later on:
202 */
zbaocaf494c82012-04-13 13:57:14 +0800203 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700204 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700205 hpet = (acpi_hpet_t *) current;
206 current += sizeof(acpi_hpet_t);
207 acpi_create_hpet(hpet);
208 acpi_add_table(rsdp, hpet);
Scott Duplichana649a962011-02-24 05:00:33 +0000209
Marc Jones522ba282012-01-03 16:02:07 -0700210 /* If we want to use HPET Timers Linux wants an MADT */
zbaocaf494c82012-04-13 13:57:14 +0800211 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700212 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
Marc Jones522ba282012-01-03 16:02:07 -0700213 madt = (acpi_madt_t *) current;
214 acpi_create_madt(madt);
215 current += madt->header.length;
216 acpi_add_table(rsdp, madt);
Scott Duplichana649a962011-02-24 05:00:33 +0000217
zbaocaf494c82012-04-13 13:57:14 +0800218 /* 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
Marc Jones522ba282012-01-03 16:02:07 -0700225 /* SRAT */
zbaocaf494c82012-04-13 13:57:14 +0800226 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700227 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700228 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
229 if (srat != NULL) {
Marc Jones84e0dfc2011-12-12 21:12:43 -0700230 memcpy((void *)current, srat, srat->header.length);
231 srat = (acpi_srat_t *) current;
232 current += srat->header.length;
233 acpi_add_table(rsdp, srat);
234 }
235 else {
236 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
Marc Jones522ba282012-01-03 16:02:07 -0700237 }
Scott Duplichana649a962011-02-24 05:00:33 +0000238
Marc Jones522ba282012-01-03 16:02:07 -0700239 /* SLIT */
zbaocaf494c82012-04-13 13:57:14 +0800240 current = (current + 0x07) & -0x08;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700241 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700242 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
243 if (slit != NULL) {
Marc Jones84e0dfc2011-12-12 21:12:43 -0700244 memcpy((void *)current, slit, slit->header.length);
245 slit = (acpi_slit_t *) current;
246 current += slit->header.length;
247 acpi_add_table(rsdp, slit);
248 }
249 else {
250 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
Marc Jones522ba282012-01-03 16:02:07 -0700251 }
Scott Duplichana649a962011-02-24 05:00:33 +0000252
Marc Jones522ba282012-01-03 16:02:07 -0700253 /* SSDT */
zbaocaf494c82012-04-13 13:57:14 +0800254 current = (current + 0x0f) & -0x10;
Marc Jones7bfd22e2011-12-12 22:04:25 -0700255 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
256 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
257 if (alib != NULL) {
258 memcpy((void *)current, alib, alib->length);
259 ssdt = (acpi_header_t *) current;
260 current += alib->length;
261 acpi_add_table(rsdp,alib);
262 }
263 else {
264 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
265 }
266
zbao585a4002012-04-12 11:27:26 +0800267 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
268 /* Keep the comment for a while. */
zbaocaf494c82012-04-13 13:57:14 +0800269 current = (current + 0x0f) & -0x10;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700270 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700271 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
272 if (ssdt != NULL) {
Marc Jones84e0dfc2011-12-12 21:12:43 -0700273 memcpy((void *)current, ssdt, ssdt->length);
274 ssdt = (acpi_header_t *) current;
275 current += ssdt->length;
zbao585a4002012-04-12 11:27:26 +0800276 acpi_add_table(rsdp,ssdt);
277 } else {
278 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
Marc Jones522ba282012-01-03 16:02:07 -0700279 }
Scott Duplichana649a962011-02-24 05:00:33 +0000280
zbaocaf494c82012-04-13 13:57:14 +0800281 current = (current + 0x0f) & -0x10;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700282 printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current);
283 ssdt2 = (acpi_header_t *) current;
284 acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
285 current += ssdt2->length;
286 acpi_add_table(rsdp,ssdt2);
Scott Duplichana649a962011-02-24 05:00:33 +0000287
288#if DUMP_ACPI_TABLES == 1
Marc Jones522ba282012-01-03 16:02:07 -0700289 printk(BIOS_DEBUG, "rsdp\n");
290 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
Scott Duplichana649a962011-02-24 05:00:33 +0000291
Marc Jones522ba282012-01-03 16:02:07 -0700292 printk(BIOS_DEBUG, "rsdt\n");
293 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
Scott Duplichana649a962011-02-24 05:00:33 +0000294
Marc Jones522ba282012-01-03 16:02:07 -0700295 printk(BIOS_DEBUG, "madt\n");
296 dump_mem(madt, ((void *)madt) + madt->header.length);
Scott Duplichana649a962011-02-24 05:00:33 +0000297
Marc Jones522ba282012-01-03 16:02:07 -0700298 printk(BIOS_DEBUG, "srat\n");
299 dump_mem(srat, ((void *)srat) + srat->header.length);
Scott Duplichana649a962011-02-24 05:00:33 +0000300
Marc Jones522ba282012-01-03 16:02:07 -0700301 printk(BIOS_DEBUG, "slit\n");
302 dump_mem(slit, ((void *)slit) + slit->header.length);
Scott Duplichana649a962011-02-24 05:00:33 +0000303
Marc Jones522ba282012-01-03 16:02:07 -0700304 printk(BIOS_DEBUG, "ssdt\n");
305 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
Scott Duplichana649a962011-02-24 05:00:33 +0000306
Marc Jones84e0dfc2011-12-12 21:12:43 -0700307 printk(BIOS_DEBUG, "ssdt2\n");
308 dump_mem(ssdt2, ((void *)ssdt2) + ssdt2->length);
309
Marc Jones522ba282012-01-03 16:02:07 -0700310 printk(BIOS_DEBUG, "fadt\n");
311 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
zbaocaf494c82012-04-13 13:57:14 +0800312
313 printk(BIOS_DEBUG, "hest\n");
314 dump_mem(hest, ((void *)hest) + hest->header.length);
Scott Duplichana649a962011-02-24 05:00:33 +0000315#endif
316
Marc Jones522ba282012-01-03 16:02:07 -0700317 printk(BIOS_INFO, "ACPI: done.\n");
318 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000319}