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 <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/amdk8_sysconf.h>
29 #include "northbridge/amd/amdk8/acpi.h"
31 #include <cpu/amd/model_fxx_powernow.h>
35 #define DUMP_ACPI_TABLES 0
38 * Assume the max pstate number is 8
39 * 0x21(33 bytes) is one package length of _PSS package
43 #define Defpkglength 0x21
45 #if DUMP_ACPI_TABLES == 1
46 static void dump_mem(u32 start, u32 end)
50 print_debug("dump_mem:");
51 for (i = start; i < end; i++) {
53 printk(BIOS_DEBUG, "\n%08x:", i);
55 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
61 extern const unsigned char AmlCode[];
63 unsigned long acpi_fill_mcfg(unsigned long current)
69 unsigned long acpi_fill_madt(unsigned long current)
71 /* create all subtables for processors */
72 current = acpi_create_madt_lapics(current);
74 /* Write SB600 IOAPIC, only one */
75 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, 2,
78 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
80 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
81 current, 0, 9, 9, 0xF);
82 /* 0: mean bus 0--->ISA */
85 /* 5 mean: 0101 --> Edige-triggered, Active high */
87 /* create all subtables for processors */
88 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
89 /* 1: LINT1 connect to NMI */
94 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) {
96 amd_model_fxx_generate_powernow(pm_base + 8, 6, 1);
97 return (unsigned long) (acpigen_get_current());
100 unsigned long write_acpi_tables(unsigned long start)
102 unsigned long current;
112 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
114 /* Align ACPI tables to 16byte */
115 start = (start + 0x0f) & -0x10;
118 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
120 /* We need at least an RSDP and an RSDT Table */
121 rsdp = (acpi_rsdp_t *) current;
122 current += sizeof(acpi_rsdp_t);
123 rsdt = (acpi_rsdt_t *) current;
124 current += sizeof(acpi_rsdt_t);
126 /* clear all table memory */
127 memset((void *)start, 0, current - start);
129 acpi_write_rsdp(rsdp, rsdt, NULL);
130 acpi_write_rsdt(rsdt);
133 printk(BIOS_DEBUG, "ACPI: * FACS\n");
134 facs = (acpi_facs_t *) current;
135 current += sizeof(acpi_facs_t);
136 acpi_create_facs(facs);
139 printk(BIOS_DEBUG, "ACPI: * DSDT\n");
140 dsdt = (acpi_header_t *) current;
141 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
142 current += dsdt->length;
143 memcpy(dsdt, &AmlCode, dsdt->length);
145 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length);
147 printk(BIOS_DEBUG, "ACPI: * FADT\n");
148 fadt = (acpi_fadt_t *) current;
149 current += sizeof(acpi_fadt_t);
151 acpi_create_fadt(fadt, facs, dsdt);
152 acpi_add_table(rsdp, fadt);
155 * We explicitly add these tables later on:
157 /* If we want to use HPET Timers Linux wants an MADT */
158 printk(BIOS_DEBUG, "ACPI: * HPET\n");
159 hpet = (acpi_hpet_t *) current;
160 current += sizeof(acpi_hpet_t);
161 acpi_create_hpet(hpet);
162 acpi_add_table(rsdp, hpet);
164 printk(BIOS_DEBUG, "ACPI: * MADT\n");
165 madt = (acpi_madt_t *) current;
166 acpi_create_madt(madt);
167 current += madt->header.length;
168 acpi_add_table(rsdp, madt);
171 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
172 ssdt = (acpi_header_t *)current;
174 acpi_create_ssdt_generator(ssdt, "DYNADATA");
175 current += ssdt->length;
176 acpi_add_table(rsdp, ssdt);
178 #if DUMP_ACPI_TABLES == 1
179 printk(BIOS_DEBUG, "rsdp\n");
180 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
182 printk(BIOS_DEBUG, "rsdt\n");
183 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
185 printk(BIOS_DEBUG, "madt\n");
186 dump_mem(madt, ((void *)madt) + madt->header.length);
188 printk(BIOS_DEBUG, "ssdt\n");
189 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
191 printk(BIOS_DEBUG, "fadt\n");
192 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
195 printk(BIOS_INFO, "ACPI: done.\n");