printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / mainboard / amd / mahogany_fam10 / acpi_tables.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 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 <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <cpu/x86/msr.h>
26 #include <cpu/amd/mtrr.h>
27 #include <cpu/amd/amdfam10_sysconf.h>
28
29 #include "mb_sysconf.h"
30
31 #define DUMP_ACPI_TABLES 0
32
33 #if DUMP_ACPI_TABLES == 1
34 static void dump_mem(u32 start, u32 end)
35 {
36
37         u32 i;
38         print_debug("dump_mem:");
39         for(i=start;i<end;i++) {
40                 if((i & 0xf)==0) {
41                         printk(BIOS_DEBUG, "\n%08x:", i);
42                 }
43                 printk(BIOS_DEBUG, " %02x", (unsigned char)*((unsigned char *)i));
44         }
45         print_debug("\n");
46 }
47 #endif
48
49 extern u8 AmlCode[];
50 extern u8 AmlCode_ssdt[];
51
52 #if CONFIG_ACPI_SSDTX_NUM >= 1
53 extern u8 AmlCode_ssdt2[];
54 extern u8 AmlCode_ssdt3[];
55 extern u8 AmlCode_ssdt4[];
56 extern u8 AmlCode_ssdt5[];
57 #endif
58
59 #define IO_APIC_ADDR    0xfec00000UL
60
61 unsigned long acpi_fill_mcfg(unsigned long current)
62 {
63         /* Just a dummy */
64         return current;
65 }
66
67 unsigned long acpi_fill_madt(unsigned long current)
68 {
69         /* create all subtables for processors */
70         current = acpi_create_madt_lapics(current);
71
72         /* Write SB700 IOAPIC, only one */
73         current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
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         /* 0: mean bus 0--->ISA */
81         /* 0: PIC 0 */
82         /* 2: APIC 2 */
83         /* 5 mean: 0101 --> Edige-triggered, Active high */
84
85         /* create all subtables for processors */
86         /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
87         /* 1: LINT1 connect to NMI */
88
89         return current;
90 }
91
92 extern void get_bus_conf(void);
93 extern void update_ssdt(void *ssdt);
94
95
96 static void update_ssdtx(void *ssdtx, int i)
97 {
98         u8 *PCI;
99         u8 *HCIN;
100         u8 *UID;
101
102         PCI = ssdtx + 0x32;
103         HCIN = ssdtx + 0x39;
104         UID = ssdtx + 0x40;
105
106         if(i<7) {
107                 *PCI  = (u8) ('4' + i - 1);
108         }
109         else {
110                 *PCI  = (u8) ('A' + i - 1 - 6);
111         }
112         *HCIN = (u8) i;
113         *UID  = (u8) (i+3);
114
115         /* FIXME: need to update the GSI id in the ssdtx too */
116
117 }
118
119 unsigned long write_acpi_tables(unsigned long start)
120 {
121         unsigned long current;
122         acpi_rsdp_t *rsdp;
123         acpi_rsdt_t *rsdt;
124         acpi_hpet_t *hpet;
125         acpi_madt_t *madt;
126         acpi_srat_t *srat;
127         acpi_slit_t *slit;
128         acpi_fadt_t *fadt;
129         acpi_facs_t *facs;
130         acpi_header_t *dsdt;
131         acpi_header_t *ssdt;
132         acpi_header_t *ssdtx;
133         u8 *p;
134
135         int i;
136
137         get_bus_conf(); //it will get sblk, pci1234, hcdn, and sbdn
138
139         /* Align ACPI tables to 16 bytes */
140         start   = ( start + 0x0f) & -0x10;
141         current = start;
142
143         printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
144
145         /* We need at least an RSDP and an RSDT Table */
146         rsdp = (acpi_rsdp_t *) current;
147         current += sizeof(acpi_rsdp_t);
148         rsdt = (acpi_rsdt_t *) current;
149         current += sizeof(acpi_rsdt_t);
150
151         /* clear all table memory */
152         memset((void *)start, 0, current - start);
153
154         acpi_write_rsdp(rsdp, rsdt, NULL);
155         acpi_write_rsdt(rsdt);
156
157         /*
158          * We explicitly add these tables later on:
159          */
160         current   = ( current + 0x07) & -0x08;
161         printk(BIOS_DEBUG, "ACPI:    * HPET at %lx\n", current);
162         hpet = (acpi_hpet_t *) current;
163         current += sizeof(acpi_hpet_t);
164         acpi_create_hpet(hpet);
165         acpi_add_table(rsdp,hpet);
166
167         /* If we want to use HPET Timers Linux wants an MADT */
168         current   = ( current + 0x07) & -0x08;
169         printk(BIOS_DEBUG, "ACPI:    * MADT at %lx\n",current);
170         madt = (acpi_madt_t *) current;
171         acpi_create_madt(madt);
172         current+=madt->header.length;
173         acpi_add_table(rsdp,madt);
174
175         /* SRAT */
176         current   = ( current + 0x07) & -0x08;
177         printk(BIOS_DEBUG, "ACPI:    * SRAT at %lx\n", current);
178         srat = (acpi_srat_t *) current;
179         acpi_create_srat(srat);
180         current+=srat->header.length;
181         acpi_add_table(rsdp,srat);
182
183         /* SLIT */
184         current   = ( current + 0x07) & -0x08;
185         printk(BIOS_DEBUG, "ACPI:   * SLIT at %lx\n", current);
186         slit = (acpi_slit_t *) current;
187         acpi_create_slit(slit);
188         current+=slit->header.length;
189         acpi_add_table(rsdp,slit);
190
191         /* SSDT */
192         current   = ( current + 0x0f) & -0x10;
193         printk(BIOS_DEBUG, "ACPI:    * SSDT at %lx\n", current);
194         ssdt = (acpi_header_t *)current;
195         current += ((acpi_header_t *)AmlCode_ssdt)->length;
196         memcpy((void *)ssdt, (void *)AmlCode_ssdt, ((acpi_header_t *)AmlCode_ssdt)->length);
197         //Here you need to set value in pci1234, sblk and sbdn in get_bus_conf.c
198         update_ssdt((void*)ssdt);
199         /* recalculate checksum */
200         ssdt->checksum = 0;
201         ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
202         acpi_add_table(rsdp,ssdt);
203
204         printk(BIOS_DEBUG, "ACPI:    * SSDT for PState at %lx\n", current);
205         current = acpi_add_ssdt_pstates(rsdp, current);
206
207 #if 0 //CONFIG_ACPI_SSDTX_NUM >= 1
208
209         /* same htio, but different possition? We may have to copy,
210         change HCIN, and recalculate the checknum and add_table */
211
212         for(i=1;i<sysconf.hc_possible_num;i++) {  // 0: is hc sblink
213                 if((sysconf.pci1234[i] & 1) != 1 ) continue;
214                 u8 c;
215                 if(i<7) {
216                         c  = (u8) ('4' + i - 1);
217                 }
218                 else {
219                         c  = (u8) ('A' + i - 1 - 6);
220                 }
221                 current   = ( current + 0x07) & -0x08;
222                 printk(BIOS_DEBUG, "ACPI:    * SSDT for PCI%c at %lx\n", c, current); //pci0 and pci1 are in dsdt
223                 ssdtx = (acpi_header_t *)current;
224                 switch(sysconf.hcid[i]) {
225                 case 1:
226                         p = AmlCode_ssdt2;
227                         break;
228                 case 2:
229                         p = AmlCode_ssdt3;
230                         break;
231                 case 3: //8131
232                          p = AmlCode_ssdt4;
233                          break;
234                  default:
235                         //HTX no io apic
236                          p = AmlCode_ssdt5;
237                 }
238                 current += ((acpi_header_t *)p)->length;
239                 memcpy((void *)ssdtx, (void *)p, ((acpi_header_t *)p)->length);
240                 update_ssdtx((void *)ssdtx, i);
241                 ssdtx->checksum = 0;
242                 ssdtx->checksum = acpi_checksum((unsigned char *)ssdtx,ssdtx->length);
243                 acpi_add_table(rsdp,ssdtx);
244         }
245 #endif
246
247         /* DSDT */
248         current   = ( current + 0x07) & -0x08;
249         printk(BIOS_DEBUG, "ACPI:    * DSDT at %lx\n", current);
250         dsdt = (acpi_header_t *)current; // it will used by fadt
251         current += ((acpi_header_t *)AmlCode)->length;
252         memcpy((void *)dsdt,(void *)AmlCode, \
253                         ((acpi_header_t *)AmlCode)->length);
254         printk(BIOS_DEBUG, "ACPI:    * DSDT @ %p Length %x\n",dsdt,dsdt->length);
255
256         /* FACS */ // it needs 64 bit alignment
257         current   = ( current + 0x07) & -0x08;
258         printk(BIOS_DEBUG, "ACPI:       * FACS at %lx\n", current);
259         facs = (acpi_facs_t *) current; // it will be used by fadt
260         current += sizeof(acpi_facs_t);
261         acpi_create_facs(facs);
262
263         /* FDAT */
264         current   = ( current + 0x07) & -0x08;
265         printk(BIOS_DEBUG, "ACPI:    * FADT at %lx\n", current);
266         fadt = (acpi_fadt_t *) current;
267         current += sizeof(acpi_fadt_t);
268
269         acpi_create_fadt(fadt,facs,dsdt);
270         acpi_add_table(rsdp,fadt);
271
272 #if DUMP_ACPI_TABLES == 1
273         printk(BIOS_DEBUG, "rsdp\n");
274         dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
275
276         printk(BIOS_DEBUG, "rsdt\n");
277         dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
278
279         printk(BIOS_DEBUG, "madt\n");
280         dump_mem(madt, ((void *)madt) + madt->header.length);
281
282         printk(BIOS_DEBUG, "srat\n");
283         dump_mem(srat, ((void *)srat) + srat->header.length);
284
285         printk(BIOS_DEBUG, "slit\n");
286         dump_mem(slit, ((void *)slit) + slit->header.length);
287
288         printk(BIOS_DEBUG, "ssdt\n");
289         dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
290
291         printk(BIOS_DEBUG, "fadt\n");
292         dump_mem(fadt, ((void *)fadt) + fadt->header.length);
293 #endif
294
295         printk(BIOS_INFO, "ACPI: done.\n");
296         return current;
297 }
298