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