Remove old ACPI code
[coreboot.git] / src / mainboard / intel / d945gclf / 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 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 <types.h>
21 #include <string.h>
22 #include <console/console.h>
23 #include <arch/acpi.h>
24 #include <arch/acpigen.h>
25 #include <arch/smp/mpspec.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
29 #include <cpu/x86/msr.h>
30 #include <arch/ioapic.h>
31 #include "dmi.h"
32
33 extern const unsigned char AmlCode[];
34 #if CONFIG_HAVE_ACPI_SLIC
35 unsigned long acpi_create_slic(unsigned long current);
36 #endif
37
38 #include "southbridge/intel/i82801gx/nvs.h"
39
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
47 static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
48 {
49 #define HPET_ADDR  0xfed00000ULL
50         acpi_header_t *header = &(hpet->header);
51         acpi_addr_t *addr = &(hpet->addr);
52
53         memset((void *) hpet, 0, sizeof(acpi_hpet_t));
54
55         /* fill out header fields */
56         memcpy(header->signature, "HPET", 4);
57         memcpy(header->oem_id, OEM_ID, 6);
58         memcpy(header->oem_table_id, "COREBOOT", 8);
59         memcpy(header->asl_compiler_id, ASLC, 4);
60
61         header->length = sizeof(acpi_hpet_t);
62         header->revision = 1;
63
64         /* fill out HPET address */
65         addr->space_id = 0;     /* Memory */
66         addr->bit_width = 64;
67         addr->bit_offset = 0;
68         addr->addrl = HPET_ADDR & 0xffffffff;
69         addr->addrh = HPET_ADDR >> 32;
70
71         hpet->id = 0x8086a201;  /* Intel */
72         hpet->number = 0x00;
73         hpet->min_tick = 0x0080;
74
75         header->checksum =
76             acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
77 }
78
79 unsigned long acpi_fill_madt(unsigned long current)
80 {
81         /* Local APICs */
82         current = acpi_create_madt_lapics(current);
83
84         /* IOAPIC */
85         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
86                                 2, IO_APIC_ADDR, 0);
87
88         /* INT_SRC_OVR */
89         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
90                  current, 0, 0, 2, 0);
91         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
92                  current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH);
93
94         return current;
95 }
96
97 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
98 {
99         generate_cpu_entries();
100         return (unsigned long) (acpigen_get_current());
101 }
102
103 unsigned long acpi_fill_slit(unsigned long current)
104 {
105         // Not implemented
106         return current;
107 }
108
109 unsigned long acpi_fill_srat(unsigned long current)
110 {
111         /* No NUMA, no SRAT */
112         return current;
113 }
114
115 #if CONFIG_HAVE_SMI_HANDLER
116 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
117 #endif
118
119 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
120 unsigned long write_acpi_tables(unsigned long start)
121 {
122         unsigned long current;
123         int i;
124         acpi_rsdp_t *rsdp;
125         acpi_rsdt_t *rsdt;
126         acpi_hpet_t *hpet;
127         acpi_madt_t *madt;
128         acpi_mcfg_t *mcfg;
129         acpi_fadt_t *fadt;
130         acpi_facs_t *facs;
131 #if CONFIG_HAVE_ACPI_SLIC
132         acpi_header_t *slic;
133 #endif
134         acpi_header_t *ssdt;
135         acpi_header_t *dsdt;
136
137         current = start;
138
139         /* Align ACPI tables to 16byte */
140         ALIGN_CURRENT;
141
142         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
143
144         /* We need at least an RSDP and an RSDT Table */
145         rsdp = (acpi_rsdp_t *) current;
146         current += sizeof(acpi_rsdp_t);
147         ALIGN_CURRENT;
148         rsdt = (acpi_rsdt_t *) current;
149         current += sizeof(acpi_rsdt_t);
150         ALIGN_CURRENT;
151
152         /* clear all table memory */
153         memset((void *) start, 0, current - start);
154
155         acpi_write_rsdp(rsdp, rsdt, NULL);
156         acpi_write_rsdt(rsdt);
157
158         /*
159          * We explicitly add these tables later on:
160          */
161         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
162
163         hpet = (acpi_hpet_t *) current;
164         current += sizeof(acpi_hpet_t);
165         ALIGN_CURRENT;
166         acpi_create_intel_hpet(hpet);
167         acpi_add_table(rsdp, hpet);
168
169         /* If we want to use HPET Timers Linux wants an MADT */
170         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
171
172         madt = (acpi_madt_t *) current;
173         acpi_create_madt(madt);
174         current += madt->header.length;
175         ALIGN_CURRENT;
176         acpi_add_table(rsdp, madt);
177
178         printk(BIOS_DEBUG, "ACPI:    * MCFG\n");
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
185         printk(BIOS_DEBUG, "ACPI:     * FACS\n");
186         facs = (acpi_facs_t *) current;
187         current += sizeof(acpi_facs_t);
188         ALIGN_CURRENT;
189         acpi_create_facs(facs);
190
191         dsdt = (acpi_header_t *) current;
192         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
193         current += dsdt->length;
194         memcpy(dsdt, &AmlCode, dsdt->length);
195
196         ALIGN_CURRENT;
197
198         /* Pack GNVS into the ACPI table area */
199         for (i=0; i < dsdt->length; i++) {
200                 if (*(u32*)(((u32)dsdt) + i) == 0xC0DEBABE) {
201                         printk(BIOS_DEBUG, "ACPI: Patching up global NVS in DSDT at offset 0x%04x -> 0x%08lx\n", i, current);
202                         *(u32*)(((u32)dsdt) + i) = current; // 0x92 bytes
203                         break;
204                 }
205         }
206
207         /* And fill it */
208         acpi_create_gnvs((global_nvs_t *)current);
209
210         current += 0x100;
211         ALIGN_CURRENT;
212
213 #if CONFIG_HAVE_SMI_HANDLER
214         /* And tell SMI about it */
215         smm_setup_structures((void *)current, NULL, NULL);
216 #endif
217
218         /* We patched up the DSDT, so we need to recalculate the checksum */
219         dsdt->checksum = 0;
220         dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
221
222         printk(BIOS_DEBUG, "ACPI:     * DSDT @ %p Length %x\n", dsdt,
223                      dsdt->length);
224
225 #if CONFIG_HAVE_ACPI_SLIC
226         printk(BIOS_DEBUG, "ACPI:     * SLIC\n");
227         slic = (acpi_header_t *)current;
228         current += acpi_create_slic(current);
229         ALIGN_CURRENT;
230         acpi_add_table(rsdp, slic);
231 #endif
232
233         printk(BIOS_DEBUG, "ACPI:     * FADT\n");
234         fadt = (acpi_fadt_t *) current;
235         current += sizeof(acpi_fadt_t);
236         ALIGN_CURRENT;
237
238         acpi_create_fadt(fadt, facs, dsdt);
239         acpi_add_table(rsdp, fadt);
240
241         printk(BIOS_DEBUG, "ACPI:     * SSDT\n");
242         ssdt = (acpi_header_t *)current;
243         acpi_create_ssdt_generator(ssdt, "DYNADATA");
244         current += ssdt->length;
245         acpi_add_table(rsdp, ssdt);
246
247         printk(BIOS_DEBUG, "current = %lx\n", current);
248
249         printk(BIOS_DEBUG, "ACPI:     * DMI (Linux workaround)\n");
250         memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
251 #if CONFIG_WRITE_HIGH_TABLES == 1
252         memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
253         current += DMI_TABLE_SIZE;
254         ALIGN_CURRENT;
255 #endif
256
257         printk(BIOS_INFO, "ACPI: done.\n");
258         return current;
259 }