Fix a few whitespace and coding style issues.
[coreboot.git] / src / mainboard / iwave / iWRainbowG6 / 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 modify
7  * it under the terms of the GNU General Public License as published by
8  * 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/ioapic.h>
25 #include <arch/acpigen.h>
26 #include <arch/smp/mpspec.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <cpu/x86/msr.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"     // FIXME: our own copy of nvs would be nice
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         /* 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 = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
88 }
89
90 unsigned long acpi_fill_madt(unsigned long current)
91 {
92         /* Local APICs */
93         current = acpi_create_madt_lapics(current);
94
95         /* IOAPIC */
96         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
97                                            2, IO_APIC_ADDR, 0);
98
99         /* INT_SRC_OVR */
100         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
101                                                 current, 0, 0, 2, 0);
102         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
103                                                 current, 0, 9, 9,
104                                                 MP_IRQ_TRIGGER_LEVEL |
105                                                 MP_IRQ_POLARITY_HIGH);
106
107         return current;
108 }
109
110 unsigned long acpi_fill_ssdt_generator(unsigned long current,
111                                        const char *oem_table_id)
112 {
113         generate_cpu_entries();
114         return (unsigned long)(acpigen_get_current());
115 }
116
117 unsigned long acpi_fill_slit(unsigned long current)
118 {
119         /* Not implemented. */
120         return current;
121 }
122
123 unsigned long acpi_fill_srat(unsigned long current)
124 {
125         /* No NUMA, no SRAT */
126         return current;
127 }
128
129 void smm_setup_structures(void *gnvs, void *tcg, void *smi1);
130
131 #define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
132 unsigned long write_acpi_tables(unsigned long start)
133 {
134         unsigned long current;
135         int i;
136
137         acpi_rsdp_t *rsdp;
138         acpi_rsdt_t *rsdt;
139         acpi_xsdt_t *xsdt;
140         acpi_hpet_t *hpet;
141         acpi_madt_t *madt;
142         acpi_mcfg_t *mcfg;
143         acpi_fadt_t *fadt;
144         acpi_facs_t *facs;
145 #if CONFIG_HAVE_ACPI_SLIC
146         acpi_header_t *slic;
147 #endif
148         acpi_header_t *ssdt;
149         acpi_header_t *dsdt;
150
151         current = start;
152
153         /* Align ACPI tables to 16byte */
154         ALIGN_CURRENT;
155
156         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
157
158         /* We need at least an RSDP and an RSDT Table */
159         rsdp = (acpi_rsdp_t *) current;
160         current += sizeof(acpi_rsdp_t);
161         ALIGN_CURRENT;
162         rsdt = (acpi_rsdt_t *) current;
163         current += sizeof(acpi_rsdt_t);
164         ALIGN_CURRENT;
165         xsdt = (acpi_xsdt_t *) current;
166         current += sizeof(acpi_xsdt_t);
167         ALIGN_CURRENT;
168
169         /* clear all table memory */
170         memset((void *)start, 0, current - start);
171
172         acpi_write_rsdp(rsdp, rsdt, xsdt);
173         acpi_write_rsdt(rsdt);
174         acpi_write_xsdt(xsdt);
175
176         /*
177          * We explicitly add these tables later on:
178          */
179         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
180
181         hpet = (acpi_hpet_t *) current;
182         current += sizeof(acpi_hpet_t);
183         ALIGN_CURRENT;
184         acpi_create_intel_hpet(hpet);
185         acpi_add_table(rsdp, hpet);
186
187         /* If we want to use HPET Timers Linux wants an MADT */
188         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
189
190         madt = (acpi_madt_t *) current;
191         acpi_create_madt(madt);
192         current += madt->header.length;
193         ALIGN_CURRENT;
194         acpi_add_table(rsdp, madt);
195
196         printk(BIOS_DEBUG, "ACPI:    * MCFG\n");
197         mcfg = (acpi_mcfg_t *) current;
198         acpi_create_mcfg(mcfg);
199         current += mcfg->header.length;
200         ALIGN_CURRENT;
201         acpi_add_table(rsdp, mcfg);
202
203         printk(BIOS_DEBUG, "ACPI:     * FACS\n");
204         facs = (acpi_facs_t *) current;
205         current += sizeof(acpi_facs_t);
206         ALIGN_CURRENT;
207         acpi_create_facs(facs);
208
209         dsdt = (acpi_header_t *) current;
210         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
211         current += dsdt->length;
212         memcpy(dsdt, &AmlCode, dsdt->length);
213
214         ALIGN_CURRENT;
215
216         /* Pack GNVS into the ACPI table area */
217         for (i = 0; i < dsdt->length; i++) {
218                 if (*(u32 *) (((u32) dsdt) + i) == 0xC0DEBABE) {
219                         printk(BIOS_DEBUG, "ACPI: Patching up global NVS in "
220                                "DSDT at offset 0x%04x -> 0x%08lx\n",
221                                i, current);
222                         *(u32 *) (((u32) dsdt) + i) = current;  // 0x92 bytes
223                         break;
224                 }
225         }
226
227         /* And fill it */
228         acpi_create_gnvs((global_nvs_t *) current);
229
230         current += 0x100;
231         ALIGN_CURRENT;
232
233         /* And tell SMI about it */
234         smm_setup_structures((void *)current, NULL, NULL);
235
236         /* We patched up the DSDT, so we need to recalculate the checksum */
237         dsdt->checksum = 0;
238         dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
239
240         printk(BIOS_DEBUG, "ACPI:     * DSDT @ %p Length %x\n", dsdt,
241                dsdt->length);
242
243 #if CONFIG_HAVE_ACPI_SLIC
244         printk(BIOS_DEBUG, "ACPI:     * SLIC\n");
245         slic = (acpi_header_t *) current;
246         current += acpi_create_slic(current);
247         ALIGN_CURRENT;
248         acpi_add_table(rsdp, slic);
249 #endif
250
251         printk(BIOS_DEBUG, "ACPI:     * FADT\n");
252         fadt = (acpi_fadt_t *) current;
253         current += sizeof(acpi_fadt_t);
254         ALIGN_CURRENT;
255
256         acpi_create_fadt(fadt, facs, dsdt);
257         acpi_add_table(rsdp, fadt);
258
259         printk(BIOS_DEBUG, "ACPI:     * SSDT\n");
260         ssdt = (acpi_header_t *) current;
261         acpi_create_ssdt_generator(ssdt, "COREBOOT");
262         current += ssdt->length;
263         acpi_add_table(rsdp, ssdt);
264         ALIGN_CURRENT;
265
266         printk(BIOS_DEBUG, "current = %lx\n", current);
267
268         printk(BIOS_DEBUG, "ACPI:     * DMI (Linux workaround)\n");
269         memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
270 #if CONFIG_WRITE_HIGH_TABLES == 1
271         memcpy((void *)current, dmi_table, DMI_TABLE_SIZE);
272         current += DMI_TABLE_SIZE;
273         ALIGN_CURRENT;
274 #endif
275
276         printk(BIOS_INFO, "ACPI: done.\n");
277         return current;
278 }