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