Remove old ACPI code
[coreboot.git] / src / mainboard / roda / rk886ex / acpi_tables.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2009 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 <string.h>
23 #include <console/console.h>
24 #include <arch/io.h>
25 #include <arch/ioapic.h>
26 #include <arch/acpi.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 "dmi.h"
33
34 extern const unsigned char AmlCode[];
35 #if CONFIG_HAVE_ACPI_SLIC
36 unsigned long acpi_create_slic(unsigned long current);
37 #endif
38
39 #include "southbridge/intel/i82801gx/nvs.h"
40 static void acpi_create_gnvs(global_nvs_t *gnvs)
41 {
42         memset((void *)gnvs, 0, sizeof(*gnvs));
43         gnvs->apic = 1;
44         gnvs->mpen = 1; /* Enable Multi Processing */
45
46         /* Enable both COM ports */
47         gnvs->cmap = 0x01;
48         gnvs->cmbp = 0x01;
49
50         /* IGD Displays */
51         gnvs->ndid = 3;
52         gnvs->did[0] = 0x80000100;
53         gnvs->did[1] = 0x80000240;
54         gnvs->did[2] = 0x80000410;
55         gnvs->did[3] = 0x80000410;
56         gnvs->did[4] = 0x00000005;
57 }
58
59 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
60 {
61 #define HPET_ADDR  0xfed00000ULL
62         acpi_header_t *header = &(hpet->header);
63         acpi_addr_t *addr = &(hpet->addr);
64
65         memset((void *) hpet, 0, sizeof(acpi_hpet_t));
66
67         /* fill out header fields */
68         memcpy(header->signature, "HPET", 4);
69         memcpy(header->oem_id, OEM_ID, 6);
70         memcpy(header->oem_table_id, "COREBOOT", 8);
71         memcpy(header->asl_compiler_id, ASLC, 4);
72
73         header->length = sizeof(acpi_hpet_t);
74         header->revision = 1;
75
76         /* fill out HPET address */
77         addr->space_id = 0;     /* Memory */
78         addr->bit_width = 64;
79         addr->bit_offset = 0;
80         addr->addrl = HPET_ADDR & 0xffffffff;
81         addr->addrh = HPET_ADDR >> 32;
82
83         hpet->id = 0x8086a201;  /* Intel */
84         hpet->number = 0x00;
85         hpet->min_tick = 0x0080;
86
87         header->checksum =
88             acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
89 }
90
91 unsigned long acpi_fill_madt(unsigned long current)
92 {
93         /* Local APICs */
94         current = acpi_create_madt_lapics(current);
95
96         /* IOAPIC */
97         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
98                                 2, IO_APIC_ADDR, 0);
99
100         /* LAPIC_NMI */
101         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
102                                 current, 0,
103                                 MP_IRQ_POLARITY_HIGH |
104                                 MP_IRQ_TRIGGER_EDGE, 0x01);
105         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
106                                 current, 1, MP_IRQ_POLARITY_HIGH |
107                                 MP_IRQ_TRIGGER_EDGE, 0x01);
108
109         /* INT_SRC_OVR */
110         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
111                  current, 0, 0, 2, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_EDGE);
112         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
113                  current, 0, 9, 9, MP_IRQ_POLARITY_HIGH | MP_IRQ_TRIGGER_LEVEL);
114
115
116         return current;
117 }
118
119 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
120 {
121         generate_cpu_entries();
122         return (unsigned long) (acpigen_get_current());
123 }
124
125 unsigned long acpi_fill_slit(unsigned long current)
126 {
127         // Not implemented
128         return current;
129 }
130
131 unsigned long acpi_fill_srat(unsigned long current)
132 {
133         /* No NUMA, no SRAT */
134         return current;
135 }
136
137 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
138
139 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
140 unsigned long write_acpi_tables(unsigned long start)
141 {
142         unsigned long current;
143         int i;
144         acpi_rsdp_t *rsdp;
145         acpi_rsdt_t *rsdt;
146         acpi_xsdt_t *xsdt;
147         acpi_hpet_t *hpet;
148         acpi_madt_t *madt;
149         acpi_mcfg_t *mcfg;
150         acpi_fadt_t *fadt;
151         acpi_facs_t *facs;
152 #if CONFIG_HAVE_ACPI_SLIC
153         acpi_header_t *slic;
154 #endif
155         acpi_header_t *ssdt;
156         acpi_header_t *dsdt;
157         void *gnvs;
158
159         current = start;
160
161         /* Align ACPI tables to 16byte */
162         ALIGN_CURRENT;
163
164         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
165
166         /* We need at least an RSDP and an RSDT Table */
167         rsdp = (acpi_rsdp_t *) current;
168         current += sizeof(acpi_rsdp_t);
169         ALIGN_CURRENT;
170         rsdt = (acpi_rsdt_t *) current;
171         current += sizeof(acpi_rsdt_t);
172         ALIGN_CURRENT;
173         xsdt = (acpi_xsdt_t *) current;
174         current += sizeof(acpi_xsdt_t);
175         ALIGN_CURRENT;
176
177         /* clear all table memory */
178         memset((void *) start, 0, current - start);
179
180         acpi_write_rsdp(rsdp, rsdt, xsdt);
181         acpi_write_rsdt(rsdt);
182         acpi_write_xsdt(xsdt);
183
184         /*
185          * We explicitly add these tables later on:
186          */
187         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
188
189         hpet = (acpi_hpet_t *) current;
190         current += sizeof(acpi_hpet_t);
191         ALIGN_CURRENT;
192         acpi_create_intel_hpet(hpet);
193         acpi_add_table(rsdp, hpet);
194
195         /* If we want to use HPET Timers Linux wants an MADT */
196         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
197
198         madt = (acpi_madt_t *) current;
199         acpi_create_madt(madt);
200         current += madt->header.length;
201         ALIGN_CURRENT;
202         acpi_add_table(rsdp, madt);
203
204         printk(BIOS_DEBUG, "ACPI:    * MCFG\n");
205         mcfg = (acpi_mcfg_t *) current;
206         acpi_create_mcfg(mcfg);
207         current += mcfg->header.length;
208         ALIGN_CURRENT;
209         acpi_add_table(rsdp, mcfg);
210
211         printk(BIOS_DEBUG, "ACPI:     * FACS\n");
212         facs = (acpi_facs_t *) current;
213         current += sizeof(acpi_facs_t);
214         ALIGN_CURRENT;
215         acpi_create_facs(facs);
216
217         dsdt = (acpi_header_t *) current;
218         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
219         current += dsdt->length;
220         memcpy(dsdt, &AmlCode, dsdt->length);
221
222         /* Fix up global NVS region for SMI handler. The GNVS region lives
223          * in the (high) table area. The low memory map looks like this:
224          *
225          * 0x00000000 - 0x000003ff      Real Mode IVT
226          * 0x00000020 - 0x0000019c      Low MP Table (XXX conflict?)
227          * 0x00000400 - 0x000004ff      BDA (somewhat unused)
228          * 0x00000500 - 0x0000052f      Moved GDT
229          * 0x00000530 - 0x00000b64      coreboot table
230          * 0x0007c000 - 0x0007dfff      OS boot sector (unused?)
231          * 0x0007e000 - 0x0007ffff      free to use (so no good for acpi+smi)
232          * 0x00080000 - 0x0009fbff      usable ram
233          * 0x0009fc00 - 0x0009ffff      EBDA (unused?)
234          * 0x000a0000 - 0x000bffff      VGA memory
235          * 0x000c0000 - 0x000cffff      VGA option rom
236          * 0x000d0000 - 0x000dffff      free for other option roms?
237          * 0x000e0000 - 0x000fffff      SeaBIOS? (conflict with low tables:)
238          * 0x000f0000 - 0x000f03ff      PIRQ table
239          * 0x000f0400 - 0x000f66??      ACPI tables
240          * 0x000f66?? - 0x000f????      DMI tables
241          */
242
243         ALIGN_CURRENT;
244
245         /* Pack GNVS into the ACPI table area */
246         for (i=0; i < dsdt->length; i++) {
247                 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
248                         printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08x\n", i, (u32)current);
249                         *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
250                         break;
251                 }
252         }
253
254         /* And fill it */
255         acpi_create_gnvs((global_nvs_t *)current);
256
257         /* Keep pointer around */
258         gnvs = (void *)current;
259
260         current += 0x100;
261         ALIGN_CURRENT;
262
263         /* And tell SMI about it */
264         smm_setup_structures(gnvs, NULL, NULL);
265
266         /* We patched up the DSDT, so we need to recalculate the checksum */
267         dsdt->checksum = 0;
268         dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
269
270         printk(BIOS_DEBUG, "ACPI:     * DSDT @ %p Length %x\n", dsdt,
271                      dsdt->length);
272
273 #if CONFIG_HAVE_ACPI_SLIC
274         printk(BIOS_DEBUG, "ACPI:     * SLIC\n");
275         slic = (acpi_header_t *)current;
276         current += acpi_create_slic(current);
277         ALIGN_CURRENT;
278         acpi_add_table(rsdp, slic);
279 #endif
280
281         printk(BIOS_DEBUG, "ACPI:     * FADT\n");
282         fadt = (acpi_fadt_t *) current;
283         current += sizeof(acpi_fadt_t);
284         ALIGN_CURRENT;
285
286         acpi_create_fadt(fadt, facs, dsdt);
287         acpi_add_table(rsdp, fadt);
288
289         printk(BIOS_DEBUG, "ACPI:     * SSDT\n");
290         ssdt = (acpi_header_t *)current;
291         acpi_create_ssdt_generator(ssdt, "COREBOOT");
292         current += ssdt->length;
293         acpi_add_table(rsdp, ssdt);
294         ALIGN_CURRENT;
295
296         printk(BIOS_DEBUG, "current = %lx\n", current);
297
298         printk(BIOS_DEBUG, "ACPI:     * DMI (Linux workaround)\n");
299         memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
300 #if CONFIG_WRITE_HIGH_TABLES == 1
301         memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
302         current += DMI_TABLE_SIZE;
303         ALIGN_CURRENT;
304 #endif
305
306         printk(BIOS_INFO, "ACPI: done.\n");
307
308         /* Enable Dummy DCC ON# for DVI */
309         printk(BIOS_DEBUG, "Laptop handling...\n");
310         outb(inb(0x60f) & ~(1 << 5), 0x60f);
311
312         return current;
313 }