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>
29 #include "mb_sysconf.h"
31 #define DUMP_ACPI_TABLES 0
33 #if DUMP_ACPI_TABLES == 1
34 static void dump_mem(u32 start, u32 end)
38 print_debug("dump_mem:");
39 for (i = start; i < end; i++) {
41 printk(BIOS_DEBUG, "\n%08x:", i);
43 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
49 extern const acpi_header_t AmlCode;
50 extern const acpi_header_t AmlCode_ssdt;
52 #if CONFIG_ACPI_SSDTX_NUM >= 1
53 extern const acpi_header_t AmlCode_ssdt2;
54 extern const acpi_header_t AmlCode_ssdt3;
55 extern const acpi_header_t AmlCode_ssdt4;
56 extern const acpi_header_t AmlCode_ssdt5;
59 #define IO_APIC_ADDR 0xfec00000UL
61 unsigned long acpi_fill_mcfg(unsigned long current)
67 unsigned long acpi_fill_madt(unsigned long current)
69 /* create all subtables for processors */
70 current = acpi_create_madt_lapics(current);
72 /* Write SB700 IOAPIC, only one */
73 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
76 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
78 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
79 current, 0, 9, 9, 0xF);
80 /* 0: mean bus 0--->ISA */
83 /* 5 mean: 0101 --> Edige-triggered, Active high */
85 /* create all subtables for processors */
86 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
87 /* 1: LINT1 connect to NMI */
92 extern void get_bus_conf(void);
93 extern void update_ssdt(void *ssdt);
96 #if CONFIG_ACPI_SSDTX_NUM >= 1
97 static void update_ssdtx(void *ssdtx, int i)
108 *PCI = (u8) ('4' + i - 1);
110 *PCI = (u8) ('A' + i - 1 - 6);
115 /* FIXME: need to update the GSI id in the ssdtx too */
120 unsigned long write_acpi_tables(unsigned long start)
122 unsigned long current;
133 #if CONFIG_ACPI_SSDTX_NUM >= 1
134 acpi_header_t *ssdtx;
135 acpi_header_t const *p;
139 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
141 /* Align ACPI tables to 16 bytes */
142 start = (start + 0x0f) & -0x10;
145 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
147 /* We need at least an RSDP and an RSDT Table */
148 rsdp = (acpi_rsdp_t *) current;
149 current += sizeof(acpi_rsdp_t);
150 rsdt = (acpi_rsdt_t *) current;
151 current += sizeof(acpi_rsdt_t);
153 /* clear all table memory */
154 memset((void *)start, 0, current - start);
156 acpi_write_rsdp(rsdp, rsdt, NULL);
157 acpi_write_rsdt(rsdt);
160 * We explicitly add these tables later on:
162 current = ( current + 0x07) & -0x08;
163 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
164 hpet = (acpi_hpet_t *) current;
165 current += sizeof(acpi_hpet_t);
166 acpi_create_hpet(hpet);
167 acpi_add_table(rsdp, hpet);
169 /* If we want to use HPET Timers Linux wants an MADT */
170 current = ( current + 0x07) & -0x08;
171 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
172 madt = (acpi_madt_t *) current;
173 acpi_create_madt(madt);
174 current += madt->header.length;
175 acpi_add_table(rsdp, madt);
178 current = ( current + 0x07) & -0x08;
179 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
180 srat = (acpi_srat_t *) current;
181 acpi_create_srat(srat);
182 current += srat->header.length;
183 acpi_add_table(rsdp, srat);
186 current = ( current + 0x07) & -0x08;
187 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
188 slit = (acpi_slit_t *) current;
189 acpi_create_slit(slit);
190 current += slit->header.length;
191 acpi_add_table(rsdp, slit);
194 current = ( current + 0x0f) & -0x10;
195 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
196 ssdt = (acpi_header_t *)current;
197 current += AmlCode_ssdt.length;
198 memcpy((void *)ssdt, &AmlCode_ssdt, AmlCode_ssdt.length);
199 //Here you need to set value in pci1234, sblk and sbdn in get_bus_conf.c
200 update_ssdt((void*)ssdt);
201 /* recalculate checksum */
203 ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length);
204 acpi_add_table(rsdp,ssdt);
206 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
207 current = acpi_add_ssdt_pstates(rsdp, current);
209 #if CONFIG_ACPI_SSDTX_NUM >= 1
211 /* same htio, but different position? We may have to copy,
212 change HCIN, and recalculate the checknum and add_table */
214 for(i=1;i<sysconf.hc_possible_num;i++) { // 0: is hc sblink
215 if((sysconf.pci1234[i] & 1) != 1 ) continue;
218 c = (u8) ('4' + i - 1);
220 c = (u8) ('A' + i - 1 - 6);
222 current = ( current + 0x07) & -0x08;
223 printk(BIOS_DEBUG, "ACPI: * SSDT for PCI%c at %lx\n", c, current); //pci0 and pci1 are in dsdt
224 ssdtx = (acpi_header_t *)current;
225 switch (sysconf.hcid[i]) {
240 current += p->length;
241 memcpy((void *)ssdtx, p, p->length);
242 update_ssdtx((void *)ssdtx, i);
244 ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length);
245 acpi_add_table(rsdp, ssdtx);
250 current = ( current + 0x07) & -0x08;
251 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
252 dsdt = (acpi_header_t *)current; // it will used by fadt
253 current += AmlCode.length;
254 memcpy((void *)dsdt, &AmlCode, AmlCode.length);
255 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
257 /* FACS */ // it needs 64 bit alignment
258 current = ( current + 0x07) & -0x08;
259 printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
260 facs = (acpi_facs_t *) current; // it will be used by fadt
261 current += sizeof(acpi_facs_t);
262 acpi_create_facs(facs);
265 current = ( current + 0x07) & -0x08;
266 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
267 fadt = (acpi_fadt_t *) current;
268 current += sizeof(acpi_fadt_t);
270 acpi_create_fadt(fadt, facs, dsdt);
271 acpi_add_table(rsdp, fadt);
273 #if DUMP_ACPI_TABLES == 1
274 printk(BIOS_DEBUG, "rsdp\n");
275 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
277 printk(BIOS_DEBUG, "rsdt\n");
278 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
280 printk(BIOS_DEBUG, "madt\n");
281 dump_mem(madt, ((void *)madt) + madt->header.length);
283 printk(BIOS_DEBUG, "srat\n");
284 dump_mem(srat, ((void *)srat) + srat->header.length);
286 printk(BIOS_DEBUG, "slit\n");
287 dump_mem(slit, ((void *)slit) + slit->header.length);
289 printk(BIOS_DEBUG, "ssdt\n");
290 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
292 printk(BIOS_DEBUG, "fadt\n");
293 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
296 printk(BIOS_INFO, "ACPI: done.\n");