Add constants for fast path resume copying
[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/acpigen.h>
24 #include <arch/ioapic.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cpu/x86/msr.h>
28 #include "agesawrapper.h"
29 #include <cpu/amd/mtrr.h>
30 #include <cpu/amd/amdfam14.h>
31
32 #define DUMP_ACPI_TABLES 0
33
34 #if DUMP_ACPI_TABLES == 1
35
36 static void dump_mem(u32 start, u32 end)
37 {
38
39         u32 i;
40         print_debug("dump_mem:");
41         for (i = start; i < end; i++) {
42                 if ((i & 0xf) == 0) {
43                         printk(BIOS_DEBUG, "\n%08x:", i);
44                 }
45                 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
46         }
47         print_debug("\n");
48 }
49 #endif
50
51 extern const unsigned char AmlCode[];
52
53 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
54 {
55         int lens;
56         msr_t msr;
57         char pscope[] = "\\_SB.PCI0";
58
59         lens = acpigen_write_scope(pscope);
60         msr = rdmsr(TOP_MEM);
61         lens += acpigen_write_name_dword("TOM1", msr.lo);
62         msr = rdmsr(TOP_MEM2);
63         /*
64          * Since XP only implements parts of ACPI 2.0, we can't use a qword
65          * here.
66          * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
67          * slide 22ff.
68          * Shift value right by 20 bit to make it fit into 32bit,
69          * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
70          */
71         lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
72         acpigen_patch_len(lens - 1);
73         return (unsigned long) (acpigen_get_current());
74 }
75
76 unsigned long acpi_fill_mcfg(unsigned long current)
77 {
78         /* Just a dummy */
79         return current;
80 }
81
82 unsigned long acpi_fill_madt(unsigned long current)
83 {
84         /* create all subtables for processors */
85         current = acpi_create_madt_lapics(current);
86
87         /* Write SB800 IOAPIC, only one */
88         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
89                         CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
90
91         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
92                         current, 0, 0, 2, 0);
93         current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
94                         current, 0, 9, 9, 0xF);
95
96         /* 0: mean bus 0--->ISA */
97         /* 0: PIC 0 */
98         /* 2: APIC 2 */
99         /* 5 mean: 0101 --> Edige-triggered, Active high */
100
101         /* create all subtables for processors */
102         /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
103         /* 1: LINT1 connect to NMI */
104
105         return current;
106 }
107
108 unsigned long acpi_fill_slit(unsigned long current)
109 {
110         // Not implemented
111         return current;
112 }
113
114 unsigned long acpi_fill_srat(unsigned long current)
115 {
116         /* No NUMA, no SRAT */
117         return current;
118 }
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_srat_t *srat;
128         acpi_slit_t *slit;
129         acpi_fadt_t *fadt;
130         acpi_facs_t *facs;
131         acpi_header_t *dsdt;
132         acpi_header_t *ssdt;
133         acpi_header_t *ssdt2;
134         acpi_header_t *alib;
135
136         get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
137
138         /* Align ACPI tables to 16 bytes */
139         start = (start + 0x0f) & -0x10;
140         current = start;
141
142         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
143
144         /* We need at least an RSDP and an RSDT Table */
145         rsdp = (acpi_rsdp_t *) current;
146         current += sizeof(acpi_rsdp_t);
147         rsdt = (acpi_rsdt_t *) current;
148         current += sizeof(acpi_rsdt_t);
149
150         /* clear all table memory */
151         memset((void *)start, 0, current - start);
152
153         acpi_write_rsdp(rsdp, rsdt, NULL);
154         acpi_write_rsdt(rsdt);
155
156         /* DSDT */
157         current  = ( current + 0x07) & -0x08;
158         printk(BIOS_DEBUG, "ACPI:  * DSDT at %lx\n", current);
159         dsdt = (acpi_header_t *)current;
160         memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
161         current += dsdt->length;
162         memcpy(dsdt, &AmlCode, dsdt->length);
163         printk(BIOS_DEBUG, "ACPI:  * DSDT @ %p Length %x\n",dsdt,dsdt->length);
164
165         /* FACS */ // it needs 64 bit alignment
166         current  = ( current + 0x07) & -0x08;
167         printk(BIOS_DEBUG, "ACPI:  * FACS at %lx\n", current);
168         facs = (acpi_facs_t *) current;
169         current += sizeof(acpi_facs_t);
170         acpi_create_facs(facs);
171
172         /* FADT */
173         current  = ( current + 0x07) & -0x08;
174         printk(BIOS_DEBUG, "ACPI:  * FADT at %lx\n", current);
175         fadt = (acpi_fadt_t *) current;
176         current += sizeof(acpi_fadt_t);
177
178         acpi_create_fadt(fadt, facs, dsdt);
179         acpi_add_table(rsdp, fadt);
180
181         /*
182          * We explicitly add these tables later on:
183          */
184         current  = ( current + 0x07) & -0x08;
185         printk(BIOS_DEBUG, "ACPI:  * HPET at %lx\n", current);
186         hpet = (acpi_hpet_t *) current;
187         current += sizeof(acpi_hpet_t);
188         acpi_create_hpet(hpet);
189         acpi_add_table(rsdp, hpet);
190
191         /* If we want to use HPET Timers Linux wants an MADT */
192         current  = ( current + 0x07) & -0x08;
193         printk(BIOS_DEBUG, "ACPI:  * MADT at %lx\n",current);
194         madt = (acpi_madt_t *) current;
195         acpi_create_madt(madt);
196         current += madt->header.length;
197         acpi_add_table(rsdp, madt);
198
199         /* SRAT */
200         current  = ( current + 0x07) & -0x08;
201         printk(BIOS_DEBUG, "ACPI:  * SRAT at %lx\n", current);
202         srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
203         if (srat != NULL) {
204                 memcpy((void *)current, srat, srat->header.length);
205                 srat = (acpi_srat_t *) current;
206                 current += srat->header.length;
207                 acpi_add_table(rsdp, srat);
208         }
209         else {
210                 printk(BIOS_DEBUG, "  AGESA SRAT table NULL. Skipping.\n");
211         }
212
213         /* SLIT */
214         current  = ( current + 0x07) & -0x08;
215         printk(BIOS_DEBUG, "ACPI:  * SLIT at %lx\n", current);
216         slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
217         if (slit != NULL) {
218                 memcpy((void *)current, slit, slit->header.length);
219                 slit = (acpi_slit_t *) current;
220                 current += slit->header.length;
221                 acpi_add_table(rsdp, slit);
222         }
223         else {
224                 printk(BIOS_DEBUG, "  AGESA SLIT table NULL. Skipping.\n");
225         }
226
227         /* SSDT */
228         current  = ( current + 0x0f) & -0x10;
229         printk(BIOS_DEBUG, "ACPI:  * AGESA ALIB SSDT at %lx\n", current);
230         alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
231         if (alib != NULL) {
232                 memcpy((void *)current, alib, alib->length);
233                 ssdt = (acpi_header_t *) current;
234                 current += alib->length;
235                 acpi_add_table(rsdp,alib);
236         }
237         else {
238                 printk(BIOS_DEBUG, "    AGESA ALIB SSDT table NULL. Skipping.\n");
239         }
240
241 #if 0 // The DSDT needs additional work for the AGESA SSDT Pstate table
242         current  = ( current + 0x0f) & -0x10;
243         printk(BIOS_DEBUG, "ACPI:  * AGESA SSDT Pstate at %lx\n", current);
244         ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
245         if (ssdt != NULL) {
246                 memcpy((void *)current, ssdt, ssdt->length);
247                 ssdt = (acpi_header_t *) current;
248                 current += ssdt->length;
249                 acpi_add_table(rsdp,ssdt);
250         }
251         else {
252                 printk(BIOS_DEBUG, "  AGESA SSDT Pstate table NULL. Skipping.\n");
253         }
254         acpi_add_table(rsdp,ssdt);
255 #endif
256
257         current  = ( current + 0x0f) & -0x10;
258         printk(BIOS_DEBUG, "ACPI:  * coreboot TOM SSDT2 at %lx\n", current);
259         ssdt2 = (acpi_header_t *) current;
260         acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR);
261         current += ssdt2->length;
262         acpi_add_table(rsdp,ssdt2);
263
264 #if DUMP_ACPI_TABLES == 1
265         printk(BIOS_DEBUG, "rsdp\n");
266         dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
267
268         printk(BIOS_DEBUG, "rsdt\n");
269         dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
270
271         printk(BIOS_DEBUG, "madt\n");
272         dump_mem(madt, ((void *)madt) + madt->header.length);
273
274         printk(BIOS_DEBUG, "srat\n");
275         dump_mem(srat, ((void *)srat) + srat->header.length);
276
277         printk(BIOS_DEBUG, "slit\n");
278         dump_mem(slit, ((void *)slit) + slit->header.length);
279
280         printk(BIOS_DEBUG, "alib\n");
281         dump_mem(ssdt, ((void *)alib) + alib->length);
282
283         printk(BIOS_DEBUG, "ssdt\n");
284         dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
285
286         printk(BIOS_DEBUG, "ssdt2\n");
287         dump_mem(ssdt2, ((void *)ssdt2) + ssdt2->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 }