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