Fix Fam14 mainboard whitespace
[coreboot.git] / src / mainboard / amd / inagua / acpi_tables.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 Advanced Micro Devices, Inc.
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 <console/console.h>
21 #include <string.h>
22 #include <arch/acpi.h>
23 #include <arch/ioapic.h>
24 #include <arch/io.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cpu/x86/msr.h>
28 #include <cpu/amd/mtrr.h>
29
30 #include "agesawrapper.h"
31
32 #define DUMP_ACPI_TABLES 0
33 extern u32 apicid_sb800;
34
35
36 #if DUMP_ACPI_TABLES == 1
37
38 static void dump_mem(u32 start, u32 end)
39 {
40
41         u32 i;
42         print_debug("dump_mem:");
43         for (i = start; i < end; i++) {
44                 if ((i & 0xf) == 0) {
45                         printk(BIOS_DEBUG, "\n%08x:", i);
46                 }
47                 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
48         }
49         print_debug("\n");
50 }
51 #endif
52
53 extern const unsigned char AmlCode[];
54 extern const unsigned char AmlCode_ssdt[];
55
56
57 unsigned long acpi_fill_mcfg(unsigned long current)
58 {
59         /* Just a dummy */
60         return current;
61 }
62
63 unsigned long acpi_fill_madt(unsigned long current)
64 {
65
66         /* create all subtables for processors */
67         current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, 0, 0);
68         current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, 1, 1);
69
70         /* Write SB800 IOAPIC, only one */
71         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, apicid_sb800,
72                          IO_APIC_ADDR, 0);
73
74         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
75                         current, 0, 0, 2, 0);
76
77         /* 0: mean bus 0--->ISA */
78         /* 0: PIC 0 */
79         /* 2: APIC 2 */
80         /* 5 mean: 0101 --> Edige-triggered, Active high */
81
82         /* create all subtables for processors */
83         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0, 5, 1);
84         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 1, 5, 1);
85         /* 1: LINT1 connect to NMI */
86
87         return current;
88 }
89
90 unsigned long acpi_fill_slit(unsigned long current)
91 {
92         // Not implemented
93         return current;
94 }
95
96 unsigned long acpi_fill_srat(unsigned long current)
97 {
98         /* No NUMA, no SRAT */
99         return current;
100 }
101
102 unsigned long write_acpi_tables(unsigned long start)
103 {
104         unsigned long current;
105         acpi_rsdp_t *rsdp;
106         acpi_rsdt_t *rsdt;
107         acpi_hpet_t *hpet;
108         acpi_madt_t *madt;
109         acpi_srat_t *srat;
110         acpi_slit_t *slit;
111         acpi_fadt_t *fadt;
112         acpi_facs_t *facs;
113         acpi_header_t *dsdt;
114         acpi_header_t *ssdt;
115
116         get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
117
118         /* Align ACPI tables to 16 bytes */
119         start = (start + 0x0f) & -0x10;
120         current = start;
121
122         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
123
124         /* We need at least an RSDP and an RSDT Table */
125         rsdp = (acpi_rsdp_t *) current;
126         current += sizeof(acpi_rsdp_t);
127         rsdt = (acpi_rsdt_t *) current;
128         current += sizeof(acpi_rsdt_t);
129
130         /* clear all table memory */
131         memset((void *)start, 0, current - start);
132
133         acpi_write_rsdp(rsdp, rsdt, NULL);
134         acpi_write_rsdt(rsdt);
135
136         /* DSDT */
137         current  = ( current + 0x07) & -0x08;
138         printk(BIOS_DEBUG, "ACPI:  * DSDT at %lx\n", current);
139         dsdt = (acpi_header_t *)current; // it will used by fadt
140         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
141         current += dsdt->length;
142         memcpy(dsdt, &AmlCode, dsdt->length);
143         printk(BIOS_DEBUG, "ACPI:  * DSDT @ %p Length %x\n",dsdt,dsdt->length);
144
145         /* FACS */ // it needs 64 bit alignment
146         current  = ( current + 0x07) & -0x08;
147         printk(BIOS_DEBUG, "ACPI:  * FACS at %lx\n", current);
148         facs = (acpi_facs_t *) current; // it will be used by fadt
149         current += sizeof(acpi_facs_t);
150         acpi_create_facs(facs);
151
152         /* FADT */
153         current  = ( current + 0x07) & -0x08;
154         printk(BIOS_DEBUG, "ACPI:  * FADT at %lx\n", current);
155         fadt = (acpi_fadt_t *) current;
156         current += sizeof(acpi_fadt_t);
157
158         acpi_create_fadt(fadt, facs, dsdt);
159         acpi_add_table(rsdp, fadt);
160
161         /*
162          * We explicitly add these tables later on:
163          */
164 #if 0 // Don't need HPET table.
165         current  = ( current + 0x07) & -0x08;
166         printk(BIOS_DEBUG, "ACPI:  * HPET at %lx\n", current);
167         hpet = (acpi_hpet_t *) current;
168         current += sizeof(acpi_hpet_t);
169         acpi_create_hpet(hpet);
170         acpi_add_table(rsdp, hpet);
171 #endif
172
173         /* If we want to use HPET Timers Linux wants an MADT */
174         current  = ( current + 0x07) & -0x08;
175         printk(BIOS_DEBUG, "ACPI:  * MADT at %lx\n",current);
176         madt = (acpi_madt_t *) current;
177         acpi_create_madt(madt);
178         current += madt->header.length;
179         acpi_add_table(rsdp, madt);
180
181         /* SRAT */
182         current  = ( current + 0x07) & -0x08;
183         printk(BIOS_DEBUG, "ACPI:  * SRAT at %lx\n", current);
184         srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
185         if (srat != NULL) {
186                 memcpy(current, srat, srat->header.length);
187                 srat = (acpi_srat_t *) current;
188                 //acpi_create_srat(srat);
189                 current += srat->header.length;
190                 acpi_add_table(rsdp, srat);
191         }
192
193         /* SLIT */
194         current  = ( current + 0x07) & -0x08;
195         printk(BIOS_DEBUG, "ACPI:  * SLIT at %lx\n", current);
196         slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
197         if (slit != NULL) {
198                 memcpy(current, slit, slit->header.length);
199                 slit = (acpi_slit_t *) current;
200                 //acpi_create_slit(slit);
201                 current += slit->header.length;
202                 acpi_add_table(rsdp, slit);
203         }
204
205         /* SSDT */
206         current  = ( current + 0x0f) & -0x10;
207         printk(BIOS_DEBUG, "ACPI:  * SSDT at %lx\n", current);
208         ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
209         if (ssdt != NULL) {
210                 memcpy(current, ssdt, ssdt->length);
211                 ssdt = (acpi_header_t *) current;
212                 current += ssdt->length;
213         }
214         else {
215                 ssdt = (acpi_header_t *) current;
216                 memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
217                 current += ssdt->length;
218                 memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
219                  /* recalculate checksum */
220                 ssdt->checksum = 0;
221                 ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
222         }
223         acpi_add_table(rsdp,ssdt);
224
225         printk(BIOS_DEBUG, "ACPI:  * SSDT for PState at %lx\n", current);
226
227 #if DUMP_ACPI_TABLES == 1
228         printk(BIOS_DEBUG, "rsdp\n");
229         dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
230
231         printk(BIOS_DEBUG, "rsdt\n");
232         dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
233
234         printk(BIOS_DEBUG, "madt\n");
235         dump_mem(madt, ((void *)madt) + madt->header.length);
236
237         printk(BIOS_DEBUG, "srat\n");
238         dump_mem(srat, ((void *)srat) + srat->header.length);
239
240         printk(BIOS_DEBUG, "slit\n");
241         dump_mem(slit, ((void *)slit) + slit->header.length);
242
243         printk(BIOS_DEBUG, "ssdt\n");
244         dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
245
246         printk(BIOS_DEBUG, "fadt\n");
247         dump_mem(fadt, ((void *)fadt) + fadt->header.length);
248 #endif
249
250         printk(BIOS_INFO, "ACPI: done.\n");
251         return current;
252 }