blob: 5f81e2604a0b4d3c0cd01f377cb577511775da00 [file] [log] [blame]
Werner Zehc42a6132015-02-12 12:40:15 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Google Inc.
5 * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <types.h>
22#include <string.h>
23#include <cbmem.h>
24#include <console/console.h>
25#include <arch/acpi.h>
26#include <arch/ioapic.h>
27#include <arch/acpigen.h>
28#include <arch/smp/mpspec.h>
29#include <device/device.h>
30#include <device/pci.h>
31#include <device/pci_ids.h>
32#include <cpu/cpu.h>
33#include <cpu/x86/msr.h>
34#include <baytrail/acpi.h>
35#include <baytrail/nvs.h>
36#include <baytrail/iomap.h>
37
38
39extern const unsigned char AmlCode[];
40
41static void acpi_create_gnvs(global_nvs_t *gnvs)
42{
43 acpi_init_gnvs(gnvs);
44
45 /* Enable USB ports in S3 */
46 gnvs->s3u0 = 1;
47 gnvs->s3u1 = 1;
48
49 /* Disable USB ports in S5 */
50 gnvs->s5u0 = 0;
51 gnvs->s5u1 = 0;
52
53 /* TPM Present */
54 gnvs->tpmp = 0;
55
56 /* Enable DPTF */
57 gnvs->dpte = 0;
58}
59
60unsigned long acpi_fill_madt(unsigned long current)
61{
62 /* Local APICs */
63 current = acpi_create_madt_lapics(current);
64
65 /* IOAPIC */
66 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
67 2, IO_APIC_ADDR, 0);
68
69 current = acpi_madt_irq_overrides(current);
70
71 return current;
72}
73
74unsigned long acpi_fill_ssdt_generator(unsigned long current,
75 const char *oem_table_id)
76{
77 generate_cpu_entries();
78 return (unsigned long) (acpigen_get_current());
79}
80
81unsigned long acpi_fill_slit(unsigned long current)
82{
83 // Not implemented
84 return current;
85}
86
87unsigned long acpi_fill_srat(unsigned long current)
88{
89 /* No NUMA, no SRAT */
90 return current;
91}
92
93#define ALIGN_CURRENT current = (ALIGN(current, 16))
94unsigned long write_acpi_tables(unsigned long start)
95{
96 unsigned long current;
97 int i;
98 acpi_rsdp_t *rsdp;
99 acpi_rsdt_t *rsdt;
100 acpi_xsdt_t *xsdt;
101 acpi_hpet_t *hpet;
102 acpi_madt_t *madt;
103 acpi_mcfg_t *mcfg;
104 acpi_fadt_t *fadt;
105 acpi_facs_t *facs;
106 acpi_header_t *ssdt;
107 acpi_header_t *ssdt2;
108 acpi_header_t *dsdt;
109 global_nvs_t *gnvs;
110
111 current = start;
112
113 /* Align ACPI tables to 16byte */
114 ALIGN_CURRENT;
115
116 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
117
118 /* We need at least an RSDP and an RSDT Table */
119 rsdp = (acpi_rsdp_t *) current;
120 current += sizeof(acpi_rsdp_t);
121 ALIGN_CURRENT;
122 rsdt = (acpi_rsdt_t *) current;
123 current += sizeof(acpi_rsdt_t);
124 ALIGN_CURRENT;
125 xsdt = (acpi_xsdt_t *) current;
126 current += sizeof(acpi_xsdt_t);
127 ALIGN_CURRENT;
128
129 /* clear all table memory */
130 memset((void *) start, 0, current - start);
131
132 acpi_write_rsdp(rsdp, rsdt, xsdt);
133 acpi_write_rsdt(rsdt);
134 acpi_write_xsdt(xsdt);
135
136 facs = (acpi_facs_t *) current;
137 current += sizeof(acpi_facs_t);
138 ALIGN_CURRENT;
139 acpi_create_facs(facs);
140 printk(BIOS_DEBUG, "ACPI: * FACS @ %p Length %x", facs,
141 facs->length);
142
143 dsdt = (acpi_header_t *) current;
144 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
145 current += dsdt->length;
146 ALIGN_CURRENT;
147 memcpy(dsdt, &AmlCode, dsdt->length);
148 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x", dsdt,
149 dsdt->length);
150
151 fadt = (acpi_fadt_t *) current;
152 current += sizeof(acpi_fadt_t);
153 ALIGN_CURRENT;
154 acpi_create_fadt(fadt, facs, dsdt);
155 acpi_add_table(rsdp, fadt);
156 printk(BIOS_DEBUG, "ACPI: * FADT @ %p Length %x", fadt,
157 fadt->header.length);
158
159 /*
160 * We explicitly add these tables later on:
161 */
162 hpet = (acpi_hpet_t *) current;
163 current += sizeof(acpi_hpet_t);
164 ALIGN_CURRENT;
165 acpi_create_intel_hpet(hpet);
166 acpi_add_table(rsdp, hpet);
167 printk(BIOS_DEBUG, "ACPI: * HPET @ %p Length %x\n", hpet,
168 hpet->header.length);
169
170 /* If we want to use HPET Timers Linux wants an MADT */
171 madt = (acpi_madt_t *) current;
172 acpi_create_madt(madt);
173 current += madt->header.length;
174 ALIGN_CURRENT;
175 acpi_add_table(rsdp, madt);
176 printk(BIOS_DEBUG, "ACPI: * MADT @ %p Length %x\n",madt,
177 madt->header.length);
178
179 mcfg = (acpi_mcfg_t *) current;
180 acpi_create_mcfg(mcfg);
181 current += mcfg->header.length;
182 ALIGN_CURRENT;
183 acpi_add_table(rsdp, mcfg);
184 printk(BIOS_DEBUG, "ACPI: * MCFG @ %p Length %x\n",mcfg,
185 mcfg->header.length);
186
187 /* Update GNVS pointer into CBMEM */
188 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
189 if (!gnvs) {
190 printk(BIOS_DEBUG, "ACPI: Could not find CBMEM GNVS\n");
191 gnvs = (global_nvs_t *)current;
192 }
193
194 for (i=0; i < dsdt->length; i++) {
195 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
196 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in "
197 "DSDT at offset 0x%04x -> %p\n", i, gnvs);
198 *(u32*)(((u32)dsdt) + i) = (unsigned long)gnvs;
199 acpi_save_gnvs((unsigned long)gnvs);
200 break;
201 }
202 }
203
204 /* And fill it */
205 acpi_create_gnvs(gnvs);
206
207 /* And tell SMI about it */
208#if CONFIG_HAVE_SMI_HANDLER
209 smm_setup_structures(gnvs, NULL, NULL);
210#endif
211
212 current += sizeof(global_nvs_t);
213 ALIGN_CURRENT;
214
215 /* We patched up the DSDT, so we need to recalculate the checksum */
216 dsdt->checksum = 0;
217 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
218
219 printk(BIOS_DEBUG, "ACPI Updated DSDT @ %p Length %x\n", dsdt,
220 dsdt->length);
221
222 ssdt = (acpi_header_t *)current;
223 memset(ssdt, 0, sizeof(acpi_header_t));
224 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
225 if (ssdt->length) {
226 current += ssdt->length;
227 acpi_add_table(rsdp, ssdt);
228 printk(BIOS_DEBUG, "ACPI: * SSDT @ %p Length %x\n",ssdt,
229 ssdt->length);
230 ALIGN_CURRENT;
231 } else {
232 ssdt = NULL;
233 printk(BIOS_DEBUG, "ACPI: * SSDT not generated.\n");
234 }
235
236 ssdt2 = (acpi_header_t *)current;
237 memset(ssdt2, 0, sizeof(acpi_header_t));
238 acpi_create_serialio_ssdt(ssdt2);
239 if (ssdt2->length) {
240 current += ssdt2->length;
241 acpi_add_table(rsdp, ssdt2);
242 printk(BIOS_DEBUG, "ACPI: * SSDT2 @ %p Length %x\n",ssdt2,
243 ssdt2->length);
244 ALIGN_CURRENT;
245 } else {
246 ssdt2 = NULL;
247 printk(BIOS_DEBUG, "ACPI: * SSDT2 not generated.\n");
248 }
249
250 printk(BIOS_DEBUG, "current = %lx\n", current);
251
252 printk(BIOS_INFO, "ACPI: done.\n");
253 return current;
254}