2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 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/amdk8_sysconf.h>
28 #include <../../../northbridge/amd/amdk8/amdk8_acpi.h>
30 #include <cpu/amd/model_fxx_powernow.h>
34 #define DUMP_ACPI_TABLES 0
37 * Assume the max pstate number is 8
38 * 0x21(33 bytes) is one package length of _PSS package
42 #define Defpkglength 0x21
44 #if DUMP_ACPI_TABLES == 1
45 static void dump_mem(u32 start, u32 end)
49 print_debug("dump_mem:");
50 for (i = start; i < end; i++) {
52 printk(BIOS_DEBUG, "\n%08x:", i);
54 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
60 extern const acpi_header_t AmlCode;
62 #if CONFIG_ACPI_SSDTX_NUM >= 1
63 extern const acpi_header_t AmlCode_ssdt2;
64 extern const acpi_header_t AmlCode_ssdt3;
65 extern const acpi_header_t AmlCode_ssdt4;
66 extern const acpi_header_t AmlCode_ssdt5;
69 #define IO_APIC_ADDR 0xfec00000UL
71 unsigned long acpi_fill_mcfg(unsigned long current)
77 unsigned long acpi_fill_madt(unsigned long current)
79 /* create all subtables for processors */
80 current = acpi_create_madt_lapics(current);
82 /* Write SB600 IOAPIC, only one */
83 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
86 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
88 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
89 current, 0, 9, 9, 0xF);
90 /* 0: mean bus 0--->ISA */
93 /* 5 mean: 0101 --> Edige-triggered, Active high */
95 /* create all subtables for processors */
96 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
97 /* 1: LINT1 connect to NMI */
102 extern void get_bus_conf(void);
104 static void update_ssdtx(void *ssdtx, int i)
115 *PCI = (uint8_t) ('4' + i - 1);
117 *PCI = (uint8_t) ('A' + i - 1 - 6);
120 *UID = (uint8_t) (i + 3);
122 /* FIXME: need to update the GSI id in the ssdtx too */
126 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
128 amd_model_fxx_generate_powernow(pm_base + 8, 6, 1);
129 return (unsigned long) (acpigen_get_current());
132 unsigned long write_acpi_tables(unsigned long start)
134 unsigned long current;
144 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
146 /* Align ACPI tables to 16byte */
147 start = (start + 0x0f) & -0x10;
150 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
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);
158 /* clear all table memory */
159 memset((void *)start, 0, current - start);
161 acpi_write_rsdp(rsdp, rsdt, NULL);
162 acpi_write_rsdt(rsdt);
165 * We explicitly add these tables later on:
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);
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);
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);
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);
197 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
198 ssdt = (acpi_header_t *)current;
200 acpi_create_ssdt_generator(ssdt, "DYNADATA");
201 current += ssdt->length;
202 acpi_add_table(rsdp, ssdt);
204 #if CONFIG_ACPI_SSDTX_NUM >= 1
206 /* same htio, but different position? We may have to copy, change HCIN, and recalculate the checknum and add_table */
208 for (i = 1; i < sysconf.hc_possible_num; i++) { /* 0: is hc sblink */
209 if ((sysconf.pci1234[i] & 1) != 1)
213 c = (uint8_t) ('4' + i - 1);
215 c = (uint8_t) ('A' + i - 1 - 6);
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]) {
235 current += p->length;
236 memcpy((void *)ssdtx, p, p->length);
237 update_ssdtx((void *)ssdtx, i);
239 ssdtx->checksum = acpi_checksum((u8 *)ssdtx, ssdtx->length);
240 acpi_add_table(rsdp, ssdtx);
245 printk(BIOS_DEBUG, "ACPI: * FACS\n");
246 facs = (acpi_facs_t *) current;
247 current += sizeof(acpi_facs_t);
248 acpi_create_facs(facs);
251 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
252 dsdt = (acpi_header_t *)current;
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 printk(BIOS_DEBUG, "ACPI: * FADT\n");
258 fadt = (acpi_fadt_t *) current;
259 current += sizeof(acpi_fadt_t);
261 acpi_create_fadt(fadt, facs, dsdt);
262 acpi_add_table(rsdp, fadt);
264 #if DUMP_ACPI_TABLES == 1
265 printk(BIOS_DEBUG, "rsdp\n");
266 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
268 printk(BIOS_DEBUG, "rsdt\n");
269 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
271 printk(BIOS_DEBUG, "madt\n");
272 dump_mem(madt, ((void *)madt) + madt->header.length);
274 printk(BIOS_DEBUG, "srat\n");
275 dump_mem(srat, ((void *)srat) + srat->header.length);
277 printk(BIOS_DEBUG, "slit\n");
278 dump_mem(slit, ((void *)slit) + slit->header.length);
280 printk(BIOS_DEBUG, "ssdt\n");
281 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
283 printk(BIOS_DEBUG, "fadt\n");
284 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
287 printk(BIOS_INFO, "ACPI: done.\n");