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 unsigned char AmlCode[];
62 #define IO_APIC_ADDR 0xfec00000UL
64 unsigned long acpi_fill_mcfg(unsigned long current)
70 unsigned long acpi_fill_madt(unsigned long current)
72 /* create all subtables for processors */
73 current = acpi_create_madt_lapics(current);
75 /* Write SB600 IOAPIC, only one */
76 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
79 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
81 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
82 current, 0, 9, 9, 0xF);
83 /* 0: mean bus 0--->ISA */
86 /* 5 mean: 0101 --> Edige-triggered, Active high */
88 /* create all subtables for processors */
89 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
90 /* 1: LINT1 connect to NMI */
95 static void update_ssdtx(void *ssdtx, int i)
106 *PCI = (uint8_t) ('4' + i - 1);
108 *PCI = (uint8_t) ('A' + i - 1 - 6);
111 *UID = (uint8_t) (i + 3);
113 /* FIXME: need to update the GSI id in the ssdtx too */
117 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
119 amd_model_fxx_generate_powernow(pm_base + 8, 6, 1);
120 return (unsigned long) (acpigen_get_current());
123 unsigned long write_acpi_tables(unsigned long start)
125 unsigned long current;
135 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
137 /* Align ACPI tables to 16byte */
138 start = (start + 0x0f) & -0x10;
141 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
143 /* We need at least an RSDP and an RSDT Table */
144 rsdp = (acpi_rsdp_t *) current;
145 current += sizeof(acpi_rsdp_t);
146 rsdt = (acpi_rsdt_t *) current;
147 current += sizeof(acpi_rsdt_t);
149 /* clear all table memory */
150 memset((void *)start, 0, current - start);
152 acpi_write_rsdp(rsdp, rsdt, NULL);
153 acpi_write_rsdt(rsdt);
156 * We explicitly add these tables later on:
158 /* If we want to use HPET Timers Linux wants an MADT */
159 printk(BIOS_DEBUG, "ACPI: * HPET\n");
160 hpet = (acpi_hpet_t *) current;
161 current += sizeof(acpi_hpet_t);
162 acpi_create_hpet(hpet);
163 acpi_add_table(rsdp, hpet);
165 printk(BIOS_DEBUG, "ACPI: * MADT\n");
166 madt = (acpi_madt_t *) current;
167 acpi_create_madt(madt);
168 current += madt->header.length;
169 acpi_add_table(rsdp, madt);
172 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
173 ssdt = (acpi_header_t *)current;
175 acpi_create_ssdt_generator(ssdt, "DYNADATA");
176 current += ssdt->length;
177 acpi_add_table(rsdp, ssdt);
180 printk(BIOS_DEBUG, "ACPI: * FACS\n");
181 facs = (acpi_facs_t *) current;
182 current += sizeof(acpi_facs_t);
183 acpi_create_facs(facs);
186 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
187 dsdt = (acpi_header_t *)current;
188 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
189 current += dsdt->length;
190 memcpy(dsdt, &AmlCode, dsdt->length);
191 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
193 printk(BIOS_DEBUG, "ACPI: * FADT\n");
194 fadt = (acpi_fadt_t *) current;
195 current += sizeof(acpi_fadt_t);
197 acpi_create_fadt(fadt, facs, dsdt);
198 acpi_add_table(rsdp, fadt);
200 #if DUMP_ACPI_TABLES == 1
201 printk(BIOS_DEBUG, "rsdp\n");
202 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
204 printk(BIOS_DEBUG, "rsdt\n");
205 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
207 printk(BIOS_DEBUG, "madt\n");
208 dump_mem(madt, ((void *)madt) + madt->header.length);
210 printk(BIOS_DEBUG, "ssdt\n");
211 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
213 printk(BIOS_DEBUG, "fadt\n");
214 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
217 printk(BIOS_INFO, "ACPI: done.\n");