remove trailing whitespace
[coreboot.git] / src / mainboard / supermicro / h8qgi / 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 #include <cpu/amd/amdfam10_sysconf.h>
30 #include "agesawrapper.h"
31
32 #define DUMP_ACPI_TABLES 0
33
34 #if DUMP_ACPI_TABLES == 1
35 static void dump_mem(u32 start, u32 end)
36 {
37
38         u32 i;
39         print_debug("dump_mem:");
40         for (i = start; i < end; i++) {
41                 if ((i & 0xf) == 0) {
42                         printk(BIOS_DEBUG, "\n%08x:", i);
43                 }
44                 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
45         }
46         print_debug("\n");
47 }
48 #endif
49
50 extern const unsigned char AmlCode[];
51 extern const unsigned char AmlCode_ssdt[];
52
53
54 unsigned long acpi_fill_mcfg(unsigned long current)
55 {
56         /* Just a dummy */
57         return current;
58 }
59
60 unsigned long acpi_fill_madt(unsigned long current)
61 {
62         device_t dev;
63         u32 dword;
64         u32 gsi_base = 0;
65         u32 apicid_sp5100;
66         u32 apicid_sr5650;
67
68         /*
69          * AGESA v5 Apply apic enumeration rules
70          * For systems with >= 16 APICs, put the IO-APICs at 0..n and
71          * put the local-APICs at m..z
72          * For systems with < 16 APICs, put the Local-APICs at 0..n and
73          * put the IO-APICs at (n + 1)..z
74          */
75 #if CONFIG_MAX_CPUS >= 16
76         apicid_sp5100 = 0x0;
77 #else
78         apicid_sp5100 = CONFIG_MAX_CPUS + 1
79 #endif
80         apicid_sr5650 = apicid_sp5100 + 1;
81
82         /* create all subtables for processors */
83         current = acpi_create_madt_lapics(current);
84
85         /* Write sp5100 IOAPIC, only one */
86         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
87                         apicid_sp5100,
88                         IO_APIC_ADDR,
89                         0
90                         );
91
92         /* IOAPIC on rs5690 */
93         gsi_base += IO_APIC_INTERRUPTS;  /* SP5100 has 24 IOAPIC entries. */
94         dev = dev_find_slot(0, PCI_DEVFN(0, 0));
95         if (dev) {
96                 pci_write_config32(dev, 0xF8, 0x1);
97                 dword = pci_read_config32(dev, 0xFC) & 0xfffffff0;
98                 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
99                                 apicid_sr5650,
100                                 dword,
101                                 gsi_base
102                                 );
103         }
104
105         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current,
106                         0, //BUS
107                         0, //SOURCE
108                         2, //gsirq
109                         0  //flags
110                         );
111
112         /* 0: mean bus 0--->ISA */
113         /* 0: PIC 0 */
114         /* 2: APIC 2 */
115         /* 5 mean: 0101 --> Edige-triggered, Active high */
116
117         /* create all subtables for processors */
118         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0, 5, 1);
119         current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 1, 5, 1);
120         /* 1: LINT1 connect to NMI */
121
122         return current;
123 }
124
125 unsigned long acpi_fill_slit(unsigned long current)
126 {
127         // Not implemented
128         return current;
129 }
130
131 unsigned long acpi_fill_srat(unsigned long current)
132 {
133         /* No NUMA, no SRAT */
134         return current;
135 }
136
137 unsigned long write_acpi_tables(unsigned long start)
138 {
139         unsigned long current;
140         acpi_rsdp_t *rsdp;
141         acpi_rsdt_t *rsdt;
142         //acpi_hpet_t *hpet;
143         acpi_madt_t *madt;
144         acpi_srat_t *srat;
145         acpi_slit_t *slit;
146         acpi_fadt_t *fadt;
147         acpi_facs_t *facs;
148         acpi_header_t *dsdt;
149         //acpi_header_t *ssdt;
150
151         get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
152
153         /* Align ACPI tables to 16 bytes */
154         start = (start + 0x0f) & -0x10;
155         current = start;
156
157         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
158
159         /* We need at least an RSDP and an RSDT Table */
160         rsdp = (acpi_rsdp_t *) current;
161         current += sizeof(acpi_rsdp_t);
162         rsdt = (acpi_rsdt_t *) current;
163         current += sizeof(acpi_rsdt_t);
164
165         /* clear all table memory */
166         memset((void *)start, 0, current - start);
167
168         acpi_write_rsdp(rsdp, rsdt, NULL);
169         acpi_write_rsdt(rsdt);
170
171         /* FACS */
172         printk(BIOS_DEBUG, "ACPI:    * FACS\n");
173         facs = (acpi_facs_t *) current;
174         current += sizeof(acpi_facs_t);
175         acpi_create_facs(facs);
176
177         /* DSDT */
178         printk(BIOS_DEBUG, "ACPI:    * DSDT\n");
179         dsdt = (acpi_header_t *)current;
180         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
181         current += dsdt->length;
182         memcpy(dsdt, &AmlCode, dsdt->length);
183         printk(BIOS_DEBUG, "ACPI:    * DSDT @ %p Length %x\n", dsdt, dsdt->length);
184         /* FADT */
185         printk(BIOS_DEBUG, "ACPI:    * FADT\n");
186         fadt = (acpi_fadt_t *) current;
187         current += sizeof(acpi_fadt_t);
188
189         acpi_create_fadt(fadt, facs, dsdt);
190         acpi_add_table(rsdp, fadt);
191
192         /*
193          * We explicitly add these tables later on:
194          */
195 #ifdef UNUSED_CODE // Don't need HPET table. we have one in dsdt
196         current   = ( current + 0x07) & -0x08;
197         printk(BIOS_DEBUG, "ACPI:    * HPET at %lx\n", current);
198         hpet = (acpi_hpet_t *) current;
199         current += sizeof(acpi_hpet_t);
200         acpi_create_hpet(hpet);
201         acpi_add_table(rsdp, hpet);
202 #endif
203
204         /* If we want to use HPET Timers Linux wants an MADT */
205         current   = ( current + 0x07) & -0x08;
206         printk(BIOS_DEBUG, "ACPI:    * MADT at %lx\n",current);
207         madt = (acpi_madt_t *) current;
208         acpi_create_madt(madt);
209         current += madt->header.length;
210         acpi_add_table(rsdp, madt);
211
212         /* SRAT */
213         current   = ( current + 0x07) & -0x08;
214         printk(BIOS_DEBUG, "ACPI:    * SRAT at %lx\n", current);
215         srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
216         if (srat != NULL) {
217                 memcpy((void *)current, srat, srat->header.length);
218                 srat = (acpi_srat_t *) current;
219                 //acpi_create_srat(srat);
220                 current += srat->header.length;
221                 acpi_add_table(rsdp, srat);
222         }
223
224         /* SLIT */
225         current   = ( current + 0x07) & -0x08;
226         printk(BIOS_DEBUG, "ACPI:   * SLIT at %lx\n", current);
227         slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
228         if (slit != NULL) {
229                 memcpy((void *)current, slit, slit->header.length);
230                 slit = (acpi_slit_t *) current;
231                 //acpi_create_slit(slit);
232                 current += slit->header.length;
233                 acpi_add_table(rsdp, slit);
234         }
235
236         /* SSDT */
237         /* NOTE: we not update_ssdt, so ssdt only contain initialize value from ssdt.asl */
238 #ifdef UNUSED_CODE
239         current   = ( current + 0x0f) & -0x10;
240         printk(BIOS_DEBUG, "ACPI:    * SSDT at %lx\n", current);
241         ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
242         if (ssdt != NULL) {
243                 memcpy(current, ssdt, ssdt->length);
244                 ssdt = (acpi_header_t *) current;
245                 current += ssdt->length;
246         }
247         else {
248                 ssdt = (acpi_header_t *) current;
249                 memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
250                 current += ssdt->length;
251                 memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
252                 /* recalculate checksum */
253                 ssdt->checksum = 0;
254                 ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
255         }
256         acpi_add_table(rsdp,ssdt);
257
258         printk(BIOS_DEBUG, "ACPI:    * SSDT for PState at %lx\n", current);
259 #endif
260
261         /* DSDT */
262         current   = ( current + 0x07) & -0x08;
263         printk(BIOS_DEBUG, "ACPI:    * DSDT at %lx\n", current);
264         dsdt = (acpi_header_t *)current; // it will used by fadt
265         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
266         current += dsdt->length;
267         memcpy(dsdt, &AmlCode, dsdt->length);
268         printk(BIOS_DEBUG, "ACPI:    * DSDT @ %p Length %x\n",dsdt,dsdt->length);
269
270 #if DUMP_ACPI_TABLES == 1
271         printk(BIOS_DEBUG, "rsdp\n");
272         dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
273
274         printk(BIOS_DEBUG, "rsdt\n");
275         dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
276
277         printk(BIOS_DEBUG, "madt\n");
278         dump_mem(madt, ((void *)madt) + madt->header.length);
279
280         printk(BIOS_DEBUG, "srat\n");
281         dump_mem(srat, ((void *)srat) + srat->header.length);
282
283         printk(BIOS_DEBUG, "slit\n");
284         dump_mem(slit, ((void *)slit) + slit->header.length);
285
286         printk(BIOS_DEBUG, "ssdt\n");
287         dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
288
289         printk(BIOS_DEBUG, "fadt\n");
290         dump_mem(fadt, ((void *)fadt) + fadt->header.length);
291 #endif
292
293         printk(BIOS_INFO, "ACPI: done.\n");
294         return current;
295 }