Add constants for fast path resume copying
[coreboot.git] / src / mainboard / amd / torpedo / 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 "agesawrapper.h"
29 #include <cpu/amd/mtrr.h>
30 #include <cpu/amd/amdfam12.h>
31
32 #define DUMP_ACPI_TABLES 0
33 extern u32 apicid_sb900;
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   current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, 2, 2);
70   current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, 3, 3);
71
72   /* Write SB900 IOAPIC, only one */
73   current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, apicid_sb900,
74              IO_APIC_ADDR, 0);
75
76   current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
77             current, 0, 0, 2, 0);
78   current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
79             current, 0, 9, 9, 0xF);
80
81   /* 0: mean bus 0--->ISA */
82   /* 0: PIC 0 */
83   /* 2: APIC 2 */
84   /* 5 mean: 0101 --> Edige-triggered, Active high */
85
86   /* create all subtables for processors */
87   current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0, 5, 1);
88   current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 1, 5, 1);
89   current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 2, 5, 1);
90   current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 3, 5, 1);
91   /* 1: LINT1 connect to NMI */
92
93   return current;
94 }
95
96 unsigned long acpi_fill_slit(unsigned long current)
97 {
98   // Not implemented
99   return current;
100 }
101
102 unsigned long acpi_fill_srat(unsigned long current)
103 {
104   /* No NUMA, no SRAT */
105   return current;
106 }
107
108 unsigned long write_acpi_tables(unsigned long start)
109 {
110   unsigned long current;
111   acpi_rsdp_t *rsdp;
112   acpi_rsdt_t *rsdt;
113 #if 0 // Don't need HPET table.
114   acpi_hpet_t *hpet;
115 #endif
116   acpi_madt_t *madt;
117   acpi_srat_t *srat;
118   acpi_slit_t *slit;
119   acpi_fadt_t *fadt;
120   acpi_facs_t *facs;
121   acpi_header_t *dsdt;
122   acpi_header_t *ssdt;
123
124   get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
125
126   /* Align ACPI tables to 16 bytes */
127   start = (start + 0x0f) & -0x10;
128   current = start;
129
130   printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
131
132   /* We need at least an RSDP and an RSDT Table */
133   rsdp = (acpi_rsdp_t *) current;
134   current += sizeof(acpi_rsdp_t);
135   rsdt = (acpi_rsdt_t *) current;
136   current += sizeof(acpi_rsdt_t);
137
138   /* clear all table memory */
139   memset((void *)start, 0, current - start);
140
141   acpi_write_rsdp(rsdp, rsdt, NULL);
142   acpi_write_rsdt(rsdt);
143
144   /*
145    * We explicitly add these tables later on:
146    */
147 #if 0 // Don't need HPET table.
148   current   = ( current + 0x07) & -0x08;
149   printk(BIOS_DEBUG, "ACPI:    * HPET at %lx\n", current);
150   hpet = (acpi_hpet_t *) current;
151   current += sizeof(acpi_hpet_t);
152   acpi_create_hpet(hpet);
153   acpi_add_table(rsdp, hpet);
154 #endif
155
156   /* If we want to use HPET Timers Linux wants an MADT */
157   current   = ( current + 0x07) & -0x08;
158   printk(BIOS_DEBUG, "ACPI:    * MADT at %lx\n",current);
159   madt = (acpi_madt_t *) current;
160   acpi_create_madt(madt);
161   current += madt->header.length;
162   acpi_add_table(rsdp, madt);
163
164   /* SRAT */
165   current   = ( current + 0x07) & -0x08;
166   printk(BIOS_DEBUG, "ACPI:    * SRAT at %lx\n", current);
167   srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
168   if (srat != NULL) {
169     memcpy((void *)current, srat, srat->header.length);
170     srat = (acpi_srat_t *) current;
171     //acpi_create_srat(srat);
172     current += srat->header.length;
173     acpi_add_table(rsdp, srat);
174   }
175
176   /* SLIT */
177   current   = ( current + 0x07) & -0x08;
178   printk(BIOS_DEBUG, "ACPI:   * SLIT at %lx\n", current);
179   slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
180   if (slit != NULL) {
181     memcpy((void *)current, slit, slit->header.length);
182     slit = (acpi_slit_t *) current;
183     //acpi_create_slit(slit);
184     current += slit->header.length;
185     acpi_add_table(rsdp, slit);
186   }
187
188   /* SSDT */
189   current   = ( current + 0x0f) & -0x10;
190   printk(BIOS_DEBUG, "ACPI:    * SSDT at %lx\n", current);
191   ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
192   if (ssdt != NULL) {
193     memcpy((void *)current, ssdt, ssdt->length);
194     ssdt = (acpi_header_t *) current;
195     current += ssdt->length;
196   }
197   else {
198     ssdt = (acpi_header_t *) current;
199     memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
200     current += ssdt->length;
201     memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
202    /* recalculate checksum */
203     ssdt->checksum = 0;
204     ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
205   }
206   acpi_add_table(rsdp,ssdt);
207
208   printk(BIOS_DEBUG, "ACPI:    * SSDT for PState at %lx\n", current);
209
210   /* DSDT */
211   current   = ( current + 0x07) & -0x08;
212   printk(BIOS_DEBUG, "ACPI:    * DSDT at %lx\n", current);
213   dsdt = (acpi_header_t *)current; // it will used by fadt
214   memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
215   current += dsdt->length;
216   memcpy(dsdt, &AmlCode, dsdt->length);
217   printk(BIOS_DEBUG, "ACPI:    * DSDT @ %p Length %x\n",dsdt,dsdt->length);
218
219   /* FACS */ // it needs 64 bit alignment
220   current   = ( current + 0x07) & -0x08;
221   printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
222   facs = (acpi_facs_t *) current; // it will be used by fadt
223   current += sizeof(acpi_facs_t);
224   acpi_create_facs(facs);
225
226   /* FADT */
227   current   = ( current + 0x07) & -0x08;
228   printk(BIOS_DEBUG, "ACPI:    * FADT at %lx\n", current);
229   fadt = (acpi_fadt_t *) current;
230   current += sizeof(acpi_fadt_t);
231
232   acpi_create_fadt(fadt, facs, dsdt);
233   acpi_add_table(rsdp, fadt);
234
235 #if DUMP_ACPI_TABLES == 1
236   printk(BIOS_DEBUG, "rsdp\n");
237   dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
238
239   printk(BIOS_DEBUG, "rsdt\n");
240   dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
241
242   printk(BIOS_DEBUG, "madt\n");
243   dump_mem(madt, ((void *)madt) + madt->header.length);
244
245   printk(BIOS_DEBUG, "srat\n");
246   dump_mem(srat, ((void *)srat) + srat->header.length);
247
248   printk(BIOS_DEBUG, "slit\n");
249   dump_mem(slit, ((void *)slit) + slit->header.length);
250
251   printk(BIOS_DEBUG, "ssdt\n");
252   dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
253
254   printk(BIOS_DEBUG, "fadt\n");
255   dump_mem(fadt, ((void *)fadt) + fadt->header.length);
256 #endif
257
258   printk(BIOS_INFO, "ACPI: done.\n");
259   return current;
260 }