blob: c2f90b5ef40dd81c75e78b73586cabe72a7c6dca [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
Paul Menzel2872f4e2013-02-21 13:10:24 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Scott Duplichana649a962011-02-24 05:00:33 +000018 */
19
Edward O'Callaghanb53b50b2014-04-29 20:26:02 +100020#include "agesawrapper.h"
21
Scott Duplichana649a962011-02-24 05:00:33 +000022#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>
Edward O'Callaghanb53b50b2014-04-29 20:26:02 +100025#include <console/console.h>
26#include <cpu/amd/amdfam14.h>
Scott Duplichana649a962011-02-24 05:00:33 +000027#include <device/pci.h>
28#include <device/pci_ids.h>
Edward O'Callaghanb53b50b2014-04-29 20:26:02 +100029#include <string.h>
Scott Duplichana649a962011-02-24 05:00:33 +000030
Scott Duplichana649a962011-02-24 05:00:33 +000031extern const unsigned char AmlCode[];
Marc Jones84e0dfc2011-12-12 21:12:43 -070032
33unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
34{
35 int lens;
36 msr_t msr;
37 char pscope[] = "\\_SB.PCI0";
38
39 lens = acpigen_write_scope(pscope);
40 msr = rdmsr(TOP_MEM);
41 lens += acpigen_write_name_dword("TOM1", msr.lo);
42 msr = rdmsr(TOP_MEM2);
43 /*
44 * Since XP only implements parts of ACPI 2.0, we can't use a qword
45 * here.
46 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
47 * slide 22ff.
48 * Shift value right by 20 bit to make it fit into 32bit,
49 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
50 */
51 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
52 acpigen_patch_len(lens - 1);
53 return (unsigned long) (acpigen_get_current());
54}
Scott Duplichana649a962011-02-24 05:00:33 +000055
56unsigned long acpi_fill_mcfg(unsigned long current)
57{
Marc Jones522ba282012-01-03 16:02:07 -070058 /* Just a dummy */
59 return current;
Scott Duplichana649a962011-02-24 05:00:33 +000060}
61
62unsigned long acpi_fill_madt(unsigned long current)
63{
Marc Jones522ba282012-01-03 16:02:07 -070064 /* create all subtables for processors */
65 current = acpi_create_madt_lapics(current);
Scott Duplichana649a962011-02-24 05:00:33 +000066
Marc Jones522ba282012-01-03 16:02:07 -070067 /* Write SB800 IOAPIC, only one */
68 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
Paul Menzel2872f4e2013-02-21 13:10:24 +010069 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
Scott Duplichana649a962011-02-24 05:00:33 +000070
Marc Jones522ba282012-01-03 16:02:07 -070071 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
72 current, 0, 0, 2, 0);
73 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
74 current, 0, 9, 9, 0xF);
Scott Duplichana649a962011-02-24 05:00:33 +000075
Marc Jones522ba282012-01-03 16:02:07 -070076 /* 0: mean bus 0--->ISA */
77 /* 0: PIC 0 */
78 /* 2: APIC 2 */
79 /* 5 mean: 0101 --> Edige-triggered, Active high */
Scott Duplichana649a962011-02-24 05:00:33 +000080
Marc Jones522ba282012-01-03 16:02:07 -070081 /* create all subtables for processors */
82 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
83 /* 1: LINT1 connect to NMI */
84
85 return current;
Scott Duplichana649a962011-02-24 05:00:33 +000086}
87
zbaocaf494c82012-04-13 13:57:14 +080088unsigned long acpi_fill_hest(acpi_hest_t *hest)
89{
90 void *addr, *current;
91
92 /* Skip the HEST header. */
93 current = (void *)(hest + 1);
94
95 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
96 if (addr != NULL)
97 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
98
99 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
100 if (addr != NULL)
101 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
102
103 return (unsigned long)current;
104}
105
Scott Duplichana649a962011-02-24 05:00:33 +0000106unsigned long acpi_fill_slit(unsigned long current)
107{
Marc Jones522ba282012-01-03 16:02:07 -0700108 // Not implemented
109 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000110}
111
112unsigned long acpi_fill_srat(unsigned long current)
113{
Marc Jones522ba282012-01-03 16:02:07 -0700114 /* No NUMA, no SRAT */
115 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000116}
117
118unsigned long write_acpi_tables(unsigned long start)
119{
Marc Jones522ba282012-01-03 16:02:07 -0700120 unsigned long current;
121 acpi_rsdp_t *rsdp;
122 acpi_rsdt_t *rsdt;
123 acpi_hpet_t *hpet;
124 acpi_madt_t *madt;
125 acpi_srat_t *srat;
126 acpi_slit_t *slit;
127 acpi_fadt_t *fadt;
128 acpi_facs_t *facs;
129 acpi_header_t *dsdt;
130 acpi_header_t *ssdt;
Marc Jones84e0dfc2011-12-12 21:12:43 -0700131 acpi_header_t *ssdt2;
Marc Jones7bfd22e2011-12-12 22:04:25 -0700132 acpi_header_t *alib;
zbaocaf494c82012-04-13 13:57:14 +0800133 acpi_hest_t *hest;
Scott Duplichana649a962011-02-24 05:00:33 +0000134
Marc Jones522ba282012-01-03 16:02:07 -0700135 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
Scott Duplichana649a962011-02-24 05:00:33 +0000136
Marc Jones522ba282012-01-03 16:02:07 -0700137 /* Align ACPI tables to 16 bytes */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200138 start = ALIGN(start, 16);
Marc Jones522ba282012-01-03 16:02:07 -0700139 current = start;
Scott Duplichana649a962011-02-24 05:00:33 +0000140
Marc Jones522ba282012-01-03 16:02:07 -0700141 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
Scott Duplichana649a962011-02-24 05:00:33 +0000142
Marc Jones522ba282012-01-03 16:02:07 -0700143 /* We need at least an RSDP and an RSDT Table */
144 rsdp = (acpi_rsdp_t *) current;
145 current += sizeof(acpi_rsdp_t);
146 rsdt = (acpi_rsdt_t *) current;
147 current += sizeof(acpi_rsdt_t);
Scott Duplichana649a962011-02-24 05:00:33 +0000148
Marc Jones522ba282012-01-03 16:02:07 -0700149 /* clear all table memory */
150 memset((void *)start, 0, current - start);
Scott Duplichana649a962011-02-24 05:00:33 +0000151
Marc Jones522ba282012-01-03 16:02:07 -0700152 acpi_write_rsdp(rsdp, rsdt, NULL);
153 acpi_write_rsdt(rsdt);
Scott Duplichana649a962011-02-24 05:00:33 +0000154
Marc Jones84e0dfc2011-12-12 21:12:43 -0700155 /* DSDT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200156 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700157 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
158 dsdt = (acpi_header_t *)current;
159 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
160 current += dsdt->length;
161 memcpy(dsdt, &AmlCode, dsdt->length);
162 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
163
164 /* FACS */ // it needs 64 bit alignment
Patrick Georgi26b00e62012-04-20 19:19:47 +0200165 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700166 printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
167 facs = (acpi_facs_t *) current;
168 current += sizeof(acpi_facs_t);
169 acpi_create_facs(facs);
170
171 /* FADT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200172 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700173 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
174 fadt = (acpi_fadt_t *) current;
175 current += sizeof(acpi_fadt_t);
176
177 acpi_create_fadt(fadt, facs, dsdt);
178 acpi_add_table(rsdp, fadt);
179
Marc Jones522ba282012-01-03 16:02:07 -0700180 /*
Marc Jones84e0dfc2011-12-12 21:12:43 -0700181 * We explicitly add these tables later on:
182 */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200183 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700184 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700185 hpet = (acpi_hpet_t *) current;
186 current += sizeof(acpi_hpet_t);
187 acpi_create_hpet(hpet);
188 acpi_add_table(rsdp, hpet);
Scott Duplichana649a962011-02-24 05:00:33 +0000189
Marc Jones522ba282012-01-03 16:02:07 -0700190 /* If we want to use HPET Timers Linux wants an MADT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200191 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700192 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
Marc Jones522ba282012-01-03 16:02:07 -0700193 madt = (acpi_madt_t *) current;
194 acpi_create_madt(madt);
195 current += madt->header.length;
196 acpi_add_table(rsdp, madt);
Scott Duplichana649a962011-02-24 05:00:33 +0000197
zbaocaf494c82012-04-13 13:57:14 +0800198 /* HEST */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200199 current = ALIGN(current, 8);
zbaocaf494c82012-04-13 13:57:14 +0800200 hest = (acpi_hest_t *)current;
201 acpi_write_hest((void *)current);
202 acpi_add_table(rsdp, (void *)current);
203 current += ((acpi_header_t *)current)->length;
204
Marc Jones522ba282012-01-03 16:02:07 -0700205 /* SRAT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200206 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700207 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700208 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
209 if (srat != NULL) {
Marc Jones84e0dfc2011-12-12 21:12:43 -0700210 memcpy((void *)current, srat, srat->header.length);
211 srat = (acpi_srat_t *) current;
212 current += srat->header.length;
213 acpi_add_table(rsdp, srat);
214 }
215 else {
216 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
Marc Jones522ba282012-01-03 16:02:07 -0700217 }
Scott Duplichana649a962011-02-24 05:00:33 +0000218
Marc Jones522ba282012-01-03 16:02:07 -0700219 /* SLIT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200220 current = ALIGN(current, 8);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700221 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700222 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
223 if (slit != NULL) {
Marc Jones84e0dfc2011-12-12 21:12:43 -0700224 memcpy((void *)current, slit, slit->header.length);
225 slit = (acpi_slit_t *) current;
226 current += slit->header.length;
227 acpi_add_table(rsdp, slit);
228 }
229 else {
230 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
Marc Jones522ba282012-01-03 16:02:07 -0700231 }
Scott Duplichana649a962011-02-24 05:00:33 +0000232
Marc Jones522ba282012-01-03 16:02:07 -0700233 /* SSDT */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200234 current = ALIGN(current, 16);
Marc Jones7bfd22e2011-12-12 22:04:25 -0700235 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
236 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
237 if (alib != NULL) {
238 memcpy((void *)current, alib, alib->length);
zbao21320052012-04-13 13:48:50 +0800239 alib = (acpi_header_t *) current;
Marc Jones7bfd22e2011-12-12 22:04:25 -0700240 current += alib->length;
zbao21320052012-04-13 13:48:50 +0800241 acpi_add_table(rsdp, (void *)alib);
242 } else {
Marc Jones7bfd22e2011-12-12 22:04:25 -0700243 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
244 }
245
zbao585a4002012-04-12 11:27:26 +0800246 /* The DSDT needs additional work for the AGESA SSDT Pstate table */
247 /* Keep the comment for a while. */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200248 current = ALIGN(current, 16);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700249 printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current);
Marc Jones522ba282012-01-03 16:02:07 -0700250 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
251 if (ssdt != NULL) {
Marc Jones84e0dfc2011-12-12 21:12:43 -0700252 memcpy((void *)current, ssdt, ssdt->length);
253 ssdt = (acpi_header_t *) current;
254 current += ssdt->length;
zbao585a4002012-04-12 11:27:26 +0800255 acpi_add_table(rsdp,ssdt);
256 } else {
257 printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n");
Marc Jones522ba282012-01-03 16:02:07 -0700258 }
Scott Duplichana649a962011-02-24 05:00:33 +0000259
Patrick Georgi26b00e62012-04-20 19:19:47 +0200260 current = ALIGN(current, 16);
Marc Jones84e0dfc2011-12-12 21:12:43 -0700261 printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current);
262 ssdt2 = (acpi_header_t *) current;
263 acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
264 current += ssdt2->length;
265 acpi_add_table(rsdp,ssdt2);
Scott Duplichana649a962011-02-24 05:00:33 +0000266
Marc Jones522ba282012-01-03 16:02:07 -0700267 printk(BIOS_INFO, "ACPI: done.\n");
268 return current;
Scott Duplichana649a962011-02-24 05:00:33 +0000269}