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