2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
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.
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.
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
20 #include <console/console.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>
30 #define DUMP_ACPI_TABLES 0
32 #if DUMP_ACPI_TABLES == 1
33 static void dump_mem(u32 start, u32 end)
37 print_debug("dump_mem:");
38 for (i = start; i < end; i++) {
40 printk(BIOS_DEBUG, "\n%08x:", i);
42 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
48 extern const unsigned char AmlCode[];
49 extern const unsigned char AmlCode_ssdt[];
51 #if CONFIG_ACPI_SSDTX_NUM >= 1
52 extern const unsigned char AmlCode_ssdt2[];
53 extern const unsigned char AmlCode_ssdt3[];
54 extern const unsigned char AmlCode_ssdt4[];
55 extern const unsigned char AmlCode_ssdt5[];
58 #define IO_APIC_ADDR 0xfec00000UL
60 unsigned long acpi_fill_mcfg(unsigned long current)
66 unsigned long acpi_fill_madt(unsigned long current)
68 /* create all subtables for processors */
69 current = acpi_create_madt_lapics(current);
71 /* Write SB700 IOAPIC, only one */
72 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
75 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
77 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
78 current, 0, 9, 9, 0xF);
79 /* 0: mean bus 0--->ISA */
82 /* 5 mean: 0101 --> Edige-triggered, Active high */
84 /* create all subtables for processors */
85 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
86 /* 1: LINT1 connect to NMI */
91 unsigned long write_acpi_tables(unsigned long start)
93 unsigned long current;
104 #if CONFIG_ACPI_SSDTX_NUM >= 1
105 acpi_header_t *ssdtx;
110 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
112 /* Align ACPI tables to 16 bytes */
113 start = (start + 0x0f) & -0x10;
116 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
118 /* We need at least an RSDP and an RSDT Table */
119 rsdp = (acpi_rsdp_t *) current;
120 current += sizeof(acpi_rsdp_t);
121 rsdt = (acpi_rsdt_t *) current;
122 current += sizeof(acpi_rsdt_t);
124 /* clear all table memory */
125 memset((void *)start, 0, current - start);
127 acpi_write_rsdp(rsdp, rsdt, NULL);
128 acpi_write_rsdt(rsdt);
131 * We explicitly add these tables later on:
133 current = ( current + 0x07) & -0x08;
134 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
135 hpet = (acpi_hpet_t *) current;
136 current += sizeof(acpi_hpet_t);
137 acpi_create_hpet(hpet);
138 acpi_add_table(rsdp, hpet);
140 /* If we want to use HPET Timers Linux wants an MADT */
141 current = ( current + 0x07) & -0x08;
142 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
143 madt = (acpi_madt_t *) current;
144 acpi_create_madt(madt);
145 current += madt->header.length;
146 acpi_add_table(rsdp, madt);
149 current = ( current + 0x07) & -0x08;
150 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
151 srat = (acpi_srat_t *) current;
152 acpi_create_srat(srat);
153 current += srat->header.length;
154 acpi_add_table(rsdp, srat);
157 current = ( current + 0x07) & -0x08;
158 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
159 slit = (acpi_slit_t *) current;
160 acpi_create_slit(slit);
161 current += slit->header.length;
162 acpi_add_table(rsdp, slit);
165 current = ( current + 0x0f) & -0x10;
166 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
167 ssdt = (acpi_header_t *)current;
168 memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t));
169 current += ssdt->length;
170 memcpy(ssdt, &AmlCode_ssdt, ssdt->length);
171 //Here you need to set value in pci1234, sblk and sbdn in get_bus_conf.c
172 update_ssdt((void*)ssdt);
173 /* recalculate checksum */
175 ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
176 acpi_add_table(rsdp,ssdt);
178 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
179 current = acpi_add_ssdt_pstates(rsdp, current);
181 #if CONFIG_ACPI_SSDTX_NUM >= 1
183 /* same htio, but different position? We may have to copy,
184 change HCIN, and recalculate the checknum and add_table */
186 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
187 if((sysconf.pci1234[i] & 1) != 1 ) continue;
190 c = (u8) ('4' + i - 1);
192 c = (u8) ('A' + i - 1 - 6);
194 current = ( current + 0x07) & -0x08;
195 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c at %lx\n", c, current); //pci0 and pci1 are in dsdt
196 ssdtx = (acpi_header_t *)current;
197 switch (sysconf.hcid[i]) {
212 memcpy(ssdtx, p, sizeof(acpi_header_t));
213 current += ssdtx->length;
214 memcpy(ssdtx, p, ssdtx->length);
215 update_ssdtx((void *)ssdtx, i);
217 ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length);
218 acpi_add_table(rsdp, ssdtx);
223 current = ( current + 0x07) & -0x08;
224 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
225 dsdt = (acpi_header_t *)current; // it will used by fadt
226 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
227 current += dsdt->length;
228 memcpy(dsdt, &AmlCode, dsdt->length);
229 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
231 /* FACS */ // it needs 64 bit alignment
232 current = ( current + 0x07) & -0x08;
233 printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
234 facs = (acpi_facs_t *) current; // it will be used by fadt
235 current += sizeof(acpi_facs_t);
236 acpi_create_facs(facs);
239 current = ( current + 0x07) & -0x08;
240 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
241 fadt = (acpi_fadt_t *) current;
242 current += sizeof(acpi_fadt_t);
244 acpi_create_fadt(fadt, facs, dsdt);
245 acpi_add_table(rsdp, fadt);
247 #if DUMP_ACPI_TABLES == 1
248 printk(BIOS_DEBUG, "rsdp\n");
249 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
251 printk(BIOS_DEBUG, "rsdt\n");
252 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
254 printk(BIOS_DEBUG, "madt\n");
255 dump_mem(madt, ((void *)madt) + madt->header.length);
257 printk(BIOS_DEBUG, "srat\n");
258 dump_mem(srat, ((void *)srat) + srat->header.length);
260 printk(BIOS_DEBUG, "slit\n");
261 dump_mem(slit, ((void *)slit) + slit->header.length);
263 printk(BIOS_DEBUG, "ssdt\n");
264 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
266 printk(BIOS_DEBUG, "fadt\n");
267 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
270 printk(BIOS_INFO, "ACPI: done.\n");