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 <arch/acpigen.h>
24 #include <arch/ioapic.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cpu/x86/msr.h>
28 #include <cpu/amd/mtrr.h>
29 #include <cpu/amd/amdfam10_sysconf.h>
30 #include "mb_sysconf.h"
32 #define DUMP_ACPI_TABLES 0
34 #if DUMP_ACPI_TABLES == 1
35 static void dump_mem(u32 start, u32 end)
39 print_debug("dump_mem:");
40 for (i = start; i < end; i++) {
42 printk(BIOS_DEBUG, "\n%08x:", i);
44 printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i));
50 extern const unsigned char AmlCode[];
51 extern const unsigned char AmlCode_ssdt[];
53 unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
57 char pscope[] = "\\_SB.PCI0";
59 lens = acpigen_write_scope(pscope);
61 lens += acpigen_write_name_dword("TOM1", msr.lo);
62 msr = rdmsr(TOP_MEM2);
64 * Since XP only implements parts of ACPI 2.0, we can't use a qword
66 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
68 * Shift value right by 20 bit to make it fit into 32bit,
69 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
71 lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
72 acpigen_patch_len(lens - 1);
74 /* TODO: More HT and other tables need to go into this table generation.
75 * This should also be moved out to the silicon level if it can.
78 return (unsigned long) (acpigen_get_current());
83 unsigned long acpi_fill_mcfg(unsigned long current)
89 unsigned long acpi_fill_madt(unsigned long current)
91 /* create all subtables for processors */
92 current = acpi_create_madt_lapics(current);
94 /* Write SB700 IOAPIC, only one */
95 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
96 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
98 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
100 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
101 current, 0, 9, 9, 0xF);
102 /* 0: mean bus 0--->ISA */
105 /* 5 mean: 0101 --> Edige-triggered, Active high */
107 /* create all subtables for processors */
108 /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */
109 /* 1: LINT1 connect to NMI */
114 unsigned long write_acpi_tables(unsigned long start)
116 unsigned long current;
128 get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */
130 /* Align ACPI tables to 16 bytes */
131 start = (start + 0x0f) & -0x10;
134 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
136 /* We need at least an RSDP and an RSDT Table */
137 rsdp = (acpi_rsdp_t *) current;
138 current += sizeof(acpi_rsdp_t);
139 rsdt = (acpi_rsdt_t *) current;
140 current += sizeof(acpi_rsdt_t);
142 /* clear all table memory */
143 memset((void *)start, 0, current - start);
145 acpi_write_rsdp(rsdp, rsdt, NULL);
146 acpi_write_rsdt(rsdt);
149 * We explicitly add these tables later on:
151 current = ( current + 0x07) & -0x08;
152 printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current);
153 hpet = (acpi_hpet_t *) current;
154 current += sizeof(acpi_hpet_t);
155 acpi_create_hpet(hpet);
156 acpi_add_table(rsdp, hpet);
158 /* If we want to use HPET Timers Linux wants an MADT */
159 current = ( current + 0x07) & -0x08;
160 printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current);
161 madt = (acpi_madt_t *) current;
162 acpi_create_madt(madt);
163 current += madt->header.length;
164 acpi_add_table(rsdp, madt);
167 current = ( current + 0x07) & -0x08;
168 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
169 srat = (acpi_srat_t *) current;
170 acpi_create_srat(srat);
171 current += srat->header.length;
172 acpi_add_table(rsdp, srat);
175 current = ( current + 0x07) & -0x08;
176 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
177 slit = (acpi_slit_t *) current;
178 acpi_create_slit(slit);
179 current += slit->header.length;
180 acpi_add_table(rsdp, slit);
183 current = ( current + 0x0f) & -0x10;
184 printk(BIOS_DEBUG, "ACPI: * coreboot PSTATE/TOM SSDT at %lx\n", current);
185 ssdt = (acpi_header_t *) current;
186 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
187 current += ssdt->length;
188 acpi_add_table(rsdp,ssdt);
191 current = ( current + 0x07) & -0x08;
192 printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current);
193 dsdt = (acpi_header_t *)current; // it will used by fadt
194 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
195 current += dsdt->length;
196 memcpy(dsdt, &AmlCode, dsdt->length);
197 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length);
199 /* FACS */ // it needs 64 bit alignment
200 current = ( current + 0x07) & -0x08;
201 printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current);
202 facs = (acpi_facs_t *) current; // it will be used by fadt
203 current += sizeof(acpi_facs_t);
204 acpi_create_facs(facs);
207 current = ( current + 0x07) & -0x08;
208 printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current);
209 fadt = (acpi_fadt_t *) current;
210 current += sizeof(acpi_fadt_t);
212 acpi_create_fadt(fadt, facs, dsdt);
213 acpi_add_table(rsdp, fadt);
215 #if DUMP_ACPI_TABLES == 1
216 printk(BIOS_DEBUG, "rsdp\n");
217 dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t));
219 printk(BIOS_DEBUG, "rsdt\n");
220 dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t));
222 printk(BIOS_DEBUG, "madt\n");
223 dump_mem(madt, ((void *)madt) + madt->header.length);
225 printk(BIOS_DEBUG, "srat\n");
226 dump_mem(srat, ((void *)srat) + srat->header.length);
228 printk(BIOS_DEBUG, "slit\n");
229 dump_mem(slit, ((void *)slit) + slit->header.length);
231 printk(BIOS_DEBUG, "ssdt\n");
232 dump_mem(ssdt, ((void *)ssdt) + ssdt->length);
234 printk(BIOS_DEBUG, "fadt\n");
235 dump_mem(fadt, ((void *)fadt) + fadt->header.length);
238 printk(BIOS_INFO, "ACPI: done.\n");