Fix/drop some obsolete comments,
[coreboot.git] / src / mainboard / via / epia-m700 / acpi_tables.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * LinuxBIOS ACPI Table support
5  * written by Stefan Reinauer <stepan@openbios.org>
6  * ACPI FADT, FACS, and DSDT table support added by
7  * Nick Barker <nick.barker9@btinternet.com>, and those portions
8  * (C) Copyright 2004 Nick Barker
9  * (C) Copyright 2005 Stefan Reinauer
10  * (C) Copyright 2009 One Laptop per Child, Association, Inc.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; version 2 of the License.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
24  */
25
26 /*
27  * Most parts of this file copied from asus\a8v-e_se\acpi_tables.c,
28  * acpi_is_wakeup() is from Rudolf's S3 patch and SSDT was added.
29  */
30
31 #include <console/console.h>
32 #include <string.h>
33 #include <arch/acpi.h>
34 #include <device/device.h>
35 #include <device/pci_ids.h>
36 #include "northbridge/via/vx800/vx800.h"
37
38 extern const unsigned char AmlCode_dsdt[];
39 extern const unsigned char AmlCode_ssdt[];
40
41 extern u32 wake_vec;
42
43 /*
44  * These four macros are copied from <arch/smp/mpspec.h>, I have to do this
45  * since the "CONFIG_GENERATE_MP_TABLE = 0", and also since
46  * mainboard/via/... have no mptable.c (so that I can not set
47  * "CONFIG_GENERATE_MP_TABLE = 1" as many other mainboards.
48  * So I have to copy these four to here. acpi_fill_madt() needs this.
49  */
50 #define MP_IRQ_POLARITY_HIGH    0x1
51 #define MP_IRQ_POLARITY_LOW     0x3
52 #define MP_IRQ_TRIGGER_EDGE     0x4
53 #define MP_IRQ_TRIGGER_LEVEL    0xc
54
55 unsigned long acpi_fill_mcfg(unsigned long current)
56 {
57         /* NO MCFG in VX855, no PCI-E. */
58         return current;
59 }
60
61 unsigned long acpi_create_madt_lapic_nmis(unsigned long current, u16 flags,
62                                           u8 lint)
63 {
64         device_t cpu;
65         int cpu_index = 0;
66
67         for (cpu = all_devices; cpu; cpu = cpu->next) {
68                 if ((cpu->path.type != DEVICE_PATH_APIC) ||
69                     (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
70                         continue;
71                 }
72                 if (!cpu->enabled)
73                         continue;
74                 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)
75                                               current, cpu_index, flags, lint);
76                 cpu_index++;
77         }
78         return current;
79 }
80
81 unsigned long acpi_fill_madt(unsigned long current)
82 {
83         /* Create all subtables for processors. */
84         current = acpi_create_madt_lapics(current);
85
86         /* Write SB IOAPIC. */
87         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
88                                    VX800SB_APIC_ID, VX800SB_APIC_BASE, 0);
89
90         /* IRQ0 -> APIC IRQ2. */
91         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
92                                                 current, 0, 0, 2, 0x0);
93
94         /* IRQ9 ACPI active low. */
95         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
96                 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
97
98         /* Create all subtables for processors. */
99         current = acpi_create_madt_lapic_nmis(current,
100                               MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
101
102         return current;
103 }
104
105 unsigned long acpi_fill_slit(unsigned long current)
106 {
107         /* Not implemented. */
108         return current;
109 }
110
111 unsigned long acpi_fill_srat(unsigned long current)
112 {
113         /* No NUMA, no SRAT. */
114         return current;
115 }
116
117 #define ALIGN(x,a)              __ALIGN_MASK(x,(typeof(x))(a)-1)
118 #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))
119
120 unsigned long write_acpi_tables(unsigned long start)
121 {
122         unsigned long current;
123         acpi_rsdp_t *rsdp;
124         acpi_rsdt_t *rsdt;
125         acpi_hpet_t *hpet;
126         acpi_madt_t *madt;
127         acpi_fadt_t *fadt;
128         acpi_facs_t *facs;
129         acpi_header_t *dsdt;
130 #if 0
131         acpi_header_t *ssdt;
132 #endif
133
134         /* Align ACPI tables to 16 byte. */
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         /* We explicitly add these tables later on: */
153         printk(BIOS_DEBUG, "ACPI:     * FACS\n");
154         current = ALIGN(current, 64);
155         facs = (acpi_facs_t *) current;
156         current += sizeof(acpi_facs_t);
157         acpi_create_facs(facs);
158
159         printk(BIOS_DEBUG, "ACPI:     * DSDT\n");
160         dsdt = (acpi_header_t *) current;
161         memcpy(dsdt, &AmlCode_dsdt, sizeof(acpi_header_t));
162         current += dsdt->length;
163         memcpy(dsdt, &AmlCode_dsdt, dsdt->length);
164         dsdt->checksum = 0; /* Don't trust iasl to get this right. */
165         dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
166         printk(BIOS_DEBUG, "ACPI:     * DSDT @ %p Length %x\n", dsdt, dsdt->length);
167
168         printk(BIOS_DEBUG, "ACPI:     * FADT\n");
169         fadt = (acpi_fadt_t *) current;
170         current += sizeof(acpi_fadt_t);
171
172         acpi_create_fadt(fadt, facs, dsdt);
173         acpi_add_table(rsdp, fadt);
174
175         /* If we want to use HPET timers Linux wants it in MADT. */
176         printk(BIOS_DEBUG, "ACPI:    * MADT\n");
177         madt = (acpi_madt_t *) current;
178         acpi_create_madt(madt);
179         current += madt->header.length;
180         acpi_add_table(rsdp, madt);
181
182         /* NO MCFG in VX855, no PCI-E. */
183
184         printk(BIOS_DEBUG, "ACPI:    * HPET\n");
185         hpet = (acpi_hpet_t *) current;
186         acpi_create_hpet(hpet);
187         current += hpet->header.length;
188         acpi_add_table(rsdp, hpet);
189
190 #if 0
191         printk(BIOS_DEBUG, "ACPI:     * SSDT\n");
192         ssdt = (acpi_header_t *) current;
193         memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
194         current += ssdt->length;
195         memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
196         ssdt->checksum = 0; /* Don't trust iasl to get this right. */
197         ssdt->checksum = acpi_checksum((u8*)ssdt, ssdt->length);
198         acpi_add_table(rsdp, ssdt);
199         printk(BIOS_DEBUG, "ACPI:     * SSDT @ %08x Length %x\n", ssdt, ssdt->length);
200 #endif
201
202         printk(BIOS_INFO, "ACPI: done.\n");
203         return current;
204 }
205