blob: 676d6610bea33ac25f31904a0c3aef830525844e [file] [log] [blame]
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer5ff7c132011-10-31 12:56:45 -07003 *
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00004 * Copyright (C) 2007-2010 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * 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,
19 * MA 02110-1301 USA
20 */
21
22#include <types.h>
23#include <string.h>
24#include <console/console.h>
25#include <arch/acpi.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000026#include <arch/ioapic.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000027#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>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000032
33extern unsigned char AmlCode[];
34
stepan836ae292010-12-08 05:42:47 +000035#include "southbridge/intel/i82801gx/nvs.h"
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000036
37static void acpi_create_gnvs(global_nvs_t *gnvs)
38{
39 memset((void *)gnvs, 0, sizeof(*gnvs));
40 gnvs->apic = 1;
41 gnvs->mpen = 1; /* Enable Multi Processing */
42
43 /* Enable COM port(s) */
44 gnvs->cmap = 0x01;
45 gnvs->cmbp = 0x00;
46
47 /* IGD Displays */
48 gnvs->ndid = 2;
49 gnvs->did[0] = 0x80000100;
50 gnvs->did[1] = 0x80000410;
51 gnvs->did[2] = 0x80000320;
52 gnvs->did[3] = 0x80000410;
53 gnvs->did[4] = 0x00000005;
54}
55
56static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
57{
58#define HPET_ADDR 0xfed00000ULL
59 acpi_header_t *header = &(hpet->header);
60 acpi_addr_t *addr = &(hpet->addr);
61
62 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
63
64 /* fill out header fields */
65 memcpy(header->signature, "HPET", 4);
66 memcpy(header->oem_id, OEM_ID, 6);
67 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
68 memcpy(header->asl_compiler_id, ASLC, 4);
69
70 header->length = sizeof(acpi_hpet_t);
71 header->revision = 1;
72
73 /* fill out HPET address */
74 addr->space_id = 0; /* Memory */
75 addr->bit_width = 64;
76 addr->bit_offset = 0;
77 addr->addrl = HPET_ADDR & 0xffffffff;
78 addr->addrh = HPET_ADDR >> 32;
79
80 hpet->id = 0x8086a201; /* Intel */
81 hpet->number = 0x00;
82 hpet->min_tick = 0x0080;
83
84 header->checksum =
85 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
86}
87
88static long acpi_create_ecdt(acpi_ecdt_t * ecdt)
89{
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070090 /* Attention: Make sure these match the values from
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000091 * the DSDT's ec.asl
92 */
93 static const char ec_id[] = "\\_SB.PCI0.LPCB.EC0";
94 int ecdt_len = sizeof(acpi_ecdt_t) + strlen(ec_id) + 1;
95
96 acpi_header_t *header = &(ecdt->header);
97
98 memset((void *) ecdt, 0, ecdt_len);
99
100 /* fill out header fields */
101 memcpy(header->signature, "ECDT", 4);
102 memcpy(header->oem_id, OEM_ID, 6);
103 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
104 memcpy(header->asl_compiler_id, ASLC, 4);
105
106 header->length = ecdt_len;
107 header->revision = 1;
108
109 /* Location of the two EC registers */
110 ecdt->ec_control.space_id = ACPI_ADDRESS_SPACE_IO;
111 ecdt->ec_control.bit_width = 8;
112 ecdt->ec_control.bit_offset = 0;
113 ecdt->ec_control.addrl = 0x66;
114 ecdt->ec_control.addrh = 0;
115
116 ecdt->ec_data.space_id = ACPI_ADDRESS_SPACE_IO; /* Memory */
117 ecdt->ec_data.bit_width = 8;
118 ecdt->ec_data.bit_offset = 0;
119 ecdt->ec_data.addrl = 0x62;
120 ecdt->ec_data.addrh = 0;
121
122 ecdt->uid = 1; // Must match _UID of the EC0 node.
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700123
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000124 ecdt->gpe_bit = 23; // SCI interrupt within GPEx_STS
125
126 strncpy((char *)ecdt->ec_id, ec_id, strlen(ec_id));
127
128 header->checksum =
129 acpi_checksum((void *) ecdt, ecdt_len);
130
131 return header->length;
132}
133
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000134unsigned long acpi_fill_madt(unsigned long current)
135{
136 /* Local APICs */
137 current = acpi_create_madt_lapics(current);
138
139 /* IOAPIC */
140 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
141 2, IO_APIC_ADDR, 0);
142
143 /* INT_SRC_OVR */
144 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
145 current, 0, 0, 2, 0);
146 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
147 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
148
149 /* LAPIC_NMI */
150 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
151 current, 0, 0x0005, 0x01);
152 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
153 current, 1, 0x0005, 0x01);
154
155 return current;
156}
157
158unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
159{
160 generate_cpu_entries();
161 return (unsigned long) (acpigen_get_current());
162}
163
164unsigned long acpi_fill_slit(unsigned long current)
165{
166 // Not implemented
167 return current;
168}
169
170unsigned long acpi_fill_srat(unsigned long current)
171{
172 /* No NUMA, no SRAT */
173 return current;
174}
175
176void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
177
178#define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
179unsigned long write_acpi_tables(unsigned long start)
180{
181 unsigned long current;
182 int i;
183 acpi_rsdp_t *rsdp;
184 acpi_rsdt_t *rsdt;
185 acpi_xsdt_t *xsdt;
186 acpi_hpet_t *hpet;
187 acpi_madt_t *madt;
188 acpi_mcfg_t *mcfg;
189 acpi_fadt_t *fadt;
190 acpi_facs_t *facs;
191#if CONFIG_HAVE_ACPI_SLIC
192 acpi_header_t *slic;
193#endif
194 acpi_header_t *ssdt;
195 acpi_header_t *dsdt;
196 acpi_header_t *ecdt;
197
198 void *gnvs, *smi1;
199
200 current = start;
201
202 /* Align ACPI tables to 16byte */
203 ALIGN_CURRENT;
204
205 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
206
207 /* We need at least an RSDP and an RSDT Table */
208 rsdp = (acpi_rsdp_t *) current;
209 current += sizeof(acpi_rsdp_t);
210 ALIGN_CURRENT;
211 rsdt = (acpi_rsdt_t *) current;
212 current += sizeof(acpi_rsdt_t);
213 ALIGN_CURRENT;
214 xsdt = (acpi_xsdt_t *) current;
215 current += sizeof(acpi_xsdt_t);
216 ALIGN_CURRENT;
217
218 /* clear all table memory */
219 memset((void *) start, 0, current - start);
220
221 acpi_write_rsdp(rsdp, rsdt, xsdt);
222 acpi_write_rsdt(rsdt);
223 acpi_write_xsdt(xsdt);
224
225 /*
226 * We explicitly add these tables later on:
227 */
228 printk(BIOS_DEBUG, "ACPI: * HPET\n");
229
230 hpet = (acpi_hpet_t *) current;
231 current += sizeof(acpi_hpet_t);
232 ALIGN_CURRENT;
233 acpi_create_intel_hpet(hpet);
234 acpi_add_table(rsdp, hpet);
235
236 /* If we want to use HPET Timers Linux wants an MADT */
237 printk(BIOS_DEBUG, "ACPI: * MADT\n");
238
239 madt = (acpi_madt_t *) current;
240 acpi_create_madt(madt);
241 current += madt->header.length;
242 ALIGN_CURRENT;
243 acpi_add_table(rsdp, madt);
244
245 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
246 mcfg = (acpi_mcfg_t *) current;
247 acpi_create_mcfg(mcfg);
248 current += mcfg->header.length;
249 ALIGN_CURRENT;
250 acpi_add_table(rsdp, mcfg);
251
252 printk(BIOS_DEBUG, "ACPI: * FACS\n");
253 facs = (acpi_facs_t *) current;
254 current += sizeof(acpi_facs_t);
255 ALIGN_CURRENT;
256 acpi_create_facs(facs);
257
258 dsdt = (acpi_header_t *) current;
259 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
260 current += dsdt->length;
261 memcpy(dsdt, &AmlCode, dsdt->length);
262
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700263 /* Fix up global NVS region for SMI handler. The GNVS region lives
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000264 * in the (high) table area. The low memory map looks like this:
265 *
266 * 0x00000000 - 0x000003ff Real Mode IVT
267 * 0x00000400 - 0x000004ff BDA (somewhat unused)
268 * 0x00000500 - 0x00000518 coreboot table forwarder
269 * 0x00000600 - 0x00000??? realmode trampoline
270 * 0x0007c000 - 0x0007dfff OS boot sector (unused?)
271 * 0x0007e000 - 0x0007ffff free to use (so no good for acpi+smi)
272 * 0x00080000 - 0x0009fbff usable ram
273 * 0x0009fc00 - 0x0009ffff EBDA (unused?)
274 * 0x000a0000 - 0x000bffff VGA memory
275 * 0x000c0000 - 0x000cffff VGA option rom
276 * 0x000d0000 - 0x000dffff free for other option roms?
277 * 0x000e0000 - 0x000fffff SeaBIOS? (conflict with low tables:)
278 * 0x000f0000 - 0x000f03ff PIRQ table
279 * 0x000f0400 - 0x000f66?? ACPI tables
280 * 0x000f66?? - 0x000f???? DMI tables
281 */
282
283 ALIGN_CURRENT;
284
285 /* Pack GNVS into the ACPI table area */
286 for (i=0; i < dsdt->length; i++) {
287 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
288 printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
289 *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
290 break;
291 }
292 }
293
294 /* And fill it */
295 acpi_create_gnvs((global_nvs_t *)current);
296
297 /* Keep pointer around */
298 gnvs = (void *)current;
299
300 current += 0x100;
301 ALIGN_CURRENT;
302
303 for (i=0; i < dsdt->length; i++) {
304 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEDEAD) {
305 printk(BIOS_DEBUG, "ACPI: Patching up SMI1 area in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
306 *(u32*)(((u32)dsdt) + i) = current; // 0x100 bytes
307 break;
308 }
309 }
310
311 /* Keep pointer around */
312 smi1 = (void *)current;
313
314 current += 0x100;
315 ALIGN_CURRENT;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700316
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000317 /* And tell SMI about it */
318 smm_setup_structures(gnvs, NULL, smi1);
319
320 /* We patched up the DSDT, so we need to recalculate the checksum */
321 dsdt->checksum = 0;
322 dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
323
324 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
325 dsdt->length);
326
327 printk(BIOS_DEBUG, "ACPI: * ECDT\n");
328 ecdt = (acpi_header_t *)current;
329 current += acpi_create_ecdt((acpi_ecdt_t *)current);
330 ALIGN_CURRENT;
331 acpi_add_table(rsdp, ecdt);
332
333#if CONFIG_HAVE_ACPI_SLIC
334 printk(BIOS_DEBUG, "ACPI: * SLIC\n");
335 slic = (acpi_header_t *)current;
336 current += acpi_create_slic(current);
337 ALIGN_CURRENT;
338 acpi_add_table(rsdp, slic);
339#endif
340
341 printk(BIOS_DEBUG, "ACPI: * FADT\n");
342 fadt = (acpi_fadt_t *) current;
343 current += sizeof(acpi_fadt_t);
344 ALIGN_CURRENT;
345
346 acpi_create_fadt(fadt, facs, dsdt);
347 acpi_add_table(rsdp, fadt);
348
349 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
350 ssdt = (acpi_header_t *)current;
351 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
352 current += ssdt->length;
353 acpi_add_table(rsdp, ssdt);
354 ALIGN_CURRENT;
355
356 printk(BIOS_DEBUG, "current = %lx\n", current);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +0000357 printk(BIOS_INFO, "ACPI: done.\n");
358 return current;
359}