We define IO_APIC_ADDR in <arch/ioapic.h>, let's use it.
[coreboot.git] / src / mainboard / via / vt8454c / 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/acpi.h>
25 #include <arch/ioapic.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
29 #include "dmi.h"
30
31 extern const unsigned char AmlCode[];
32
33 unsigned long acpi_fill_mcfg(unsigned long current)
34 {
35         device_t dev;
36         u64 mmcfg;
37
38         dev = dev_find_device(0x1106, 0x324b, 0);       // 0:0x13.0
39         if (!dev)
40                 return current;
41
42         // MMCFG not supported or not enabled.
43         if ((pci_read_config8(dev, 0x40) & 0xC0) != 0xC0)
44                 return current;
45
46         mmcfg = ((u64) pci_read_config8(dev, 0x41)) << 28;
47         if (!mmcfg)
48                 return current;
49
50         current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, mmcfg, 0x0, 0x0, 0xff);
51
52         return current;
53 }
54
55
56 static void acpi_create_via_hpet(acpi_hpet_t * hpet)
57 {
58 #define HPET_ADDR  0xfe800000ULL
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, "COREBOOT", 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         // XXX factory bios just puts an address here -- who's right?
75         addr->space_id = 0;     /* Memory */
76         addr->bit_width = 64;
77         addr->bit_offset = 0;
78         addr->addrl = HPET_ADDR & 0xffffffff;
79         addr->addrh = HPET_ADDR >> 32;
80
81         hpet->id = 0x11068201;  /* VIA */
82         hpet->number = 0x00;
83         hpet->min_tick = 0x0090;
84
85         header->checksum =
86             acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
87 }
88
89 unsigned long acpi_fill_madt(unsigned long current)
90 {
91         /* Local Apic */
92         current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 0, 0);
93
94         /* IOAPIC */
95         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2, IO_APIC_ADDR, 0);
96
97         /* INT_SRC_OVR */
98         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 0, 2, 0);
99         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000f);  // low/level
100
101         /* LAPIC_NMI */
102         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *) current, 0, 0x0005, 1); // high/edge
103
104         return current;
105 }
106
107 unsigned long acpi_fill_slit(unsigned long current)
108 {
109         // Not implemented
110         return current;
111 }
112
113 unsigned long acpi_fill_srat(unsigned long current)
114 {
115         /* No NUMA, no SRAT */
116         return current;
117 }
118
119 unsigned long write_acpi_tables(unsigned long start)
120 {
121         unsigned long current;
122         acpi_rsdp_t *rsdp;
123         acpi_rsdt_t *rsdt;
124         acpi_hpet_t *hpet;
125         acpi_madt_t *madt;
126         acpi_mcfg_t *mcfg;
127         acpi_fadt_t *fadt;
128         acpi_facs_t *facs;
129         acpi_header_t *dsdt;
130
131         /* Align ACPI tables to 16byte */
132         start = (start + 0x0f) & -0x10;
133         current = start;
134
135         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
136
137         /* We need at least an RSDP and an RSDT Table */
138         rsdp = (acpi_rsdp_t *) current;
139         current += sizeof(acpi_rsdp_t);
140         rsdt = (acpi_rsdt_t *) current;
141         current += sizeof(acpi_rsdt_t);
142
143         /* clear all table memory */
144         memset((void *) start, 0, current - start);
145
146         acpi_write_rsdp(rsdp, rsdt, NULL);
147         acpi_write_rsdt(rsdt);
148
149         /*
150          * We explicitly add these tables later on:
151          */
152
153         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
154
155         hpet = (acpi_hpet_t *) current;
156         current += sizeof(acpi_hpet_t);
157         acpi_create_via_hpet(hpet);
158         acpi_add_table(rsdp, hpet);
159
160         /* If we want to use HPET Timers Linux wants an MADT */
161         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
162
163         madt = (acpi_madt_t *) current;
164         acpi_create_madt(madt);
165         current += madt->header.length;
166         acpi_add_table(rsdp, madt);
167
168         printk(BIOS_DEBUG, "ACPI:    * MCFG\n");
169         mcfg = (acpi_mcfg_t *) current;
170         acpi_create_mcfg(mcfg);
171         current += mcfg->header.length;
172         acpi_add_table(rsdp, mcfg);
173
174         printk(BIOS_DEBUG, "ACPI:     * FACS\n");
175         facs = (acpi_facs_t *) current;
176         current += sizeof(acpi_facs_t);
177         acpi_create_facs(facs);
178
179         dsdt = (acpi_header_t *) current;
180         dsdt = (acpi_header_t *)current;
181         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
182         current += dsdt->length;
183         memcpy(dsdt, &AmlCode, dsdt->length);
184 #ifdef DONT_TRUST_IASL
185         dsdt->checksum = 0;     // don't trust intel iasl compiler to get this right
186         dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
187 #endif
188         printk(BIOS_DEBUG, "ACPI:     * DSDT @ %p Length %x\n", dsdt,
189                      dsdt->length);
190         printk(BIOS_DEBUG, "ACPI:     * FADT\n");
191
192         fadt = (acpi_fadt_t *) current;
193         current += sizeof(acpi_fadt_t);
194
195         acpi_create_fadt(fadt, facs, dsdt);
196         acpi_add_table(rsdp, fadt);
197
198         printk(BIOS_DEBUG, "ACPI:     * DMI (Linux workaround)\n");
199         memcpy((void *)0xfff80, dmi_table, DMI_TABLE_SIZE);
200
201         printk(BIOS_INFO, "ACPI: done.\n");
202         return current;
203 }