2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org>
5 * Copyright (C) 2005 Nick Barker <nick.barker9@btinternet.com>
6 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <console/console.h>
24 #include <arch/acpi.h>
25 #include <arch/acpigen.h>
26 #include <arch/smp/mpspec.h>
27 #include <device/device.h>
28 #include <device/pci_ids.h>
31 extern const unsigned char AmlCode[];
33 static int determine_total_number_of_cores(void)
37 for(cpu = all_devices; cpu; cpu = cpu->next) {
38 if ((cpu->path.type != DEVICE_PATH_APIC) ||
39 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
50 void generate_cpu_entries(void)
54 int cpu, pcontrol_blk=DEFAULT_PMBASE+PCNTRL, plen=6;
55 int numcpus = determine_total_number_of_cores();
56 printk(BIOS_DEBUG, "Found %d CPU(s).\n", numcpus);
58 /* without the outer scope, furhter ssdt addition will end up
59 * within the processor statement */
60 len = acpigen_write_scope("\\_PR");
61 for (cpu=0; cpu < numcpus; cpu++) {
62 len_pr = acpigen_write_processor(cpu, pcontrol_blk, plen);
63 acpigen_patch_len(len_pr - 1);
66 acpigen_patch_len(len - 1);
69 unsigned long __attribute__((weak)) acpi_fill_slit(unsigned long current)
75 unsigned long __attribute__((weak)) acpi_fill_srat(unsigned long current)
81 unsigned long __attribute__((weak)) acpi_fill_madt(unsigned long current)
83 /* mainboard has no ioapic */
87 unsigned long __attribute__((weak)) acpi_fill_mcfg(unsigned long current)
89 /* chipset doesn't have mmconfig */
93 unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(unsigned long current,
94 const char *oem_table_id)
96 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
97 /* generate_cpu_entries() generates weird bytecode and has to come
98 * last or else the following entries will end up inside the
100 generate_cpu_entries();
101 return (unsigned long) acpigen_get_current();
104 unsigned long __attribute__((weak)) write_acpi_tables(unsigned long start)
106 unsigned long current;
115 /* Align ACPI tables to 16 byte. */
116 start = (start + 0x0f) & -0x10;
119 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
121 /* We need at least an RSDP and an RSDT table. */
122 rsdp = (acpi_rsdp_t *) current;
123 current += sizeof(acpi_rsdp_t);
124 rsdt = (acpi_rsdt_t *) current;
125 current += sizeof(acpi_rsdt_t);
127 /* Clear all table memory. */
128 memset((void *) start, 0, current - start);
130 acpi_write_rsdp(rsdp, rsdt, NULL);
131 acpi_write_rsdt(rsdt);
133 /* We explicitly add these tables later on: */
134 printk(BIOS_DEBUG, "ACPI: * FACS\n");
136 /* we should align FACS to 64B as per ACPI specs */
137 current = ALIGN(current, 64);
138 facs = (acpi_facs_t *) current;
139 current += sizeof(acpi_facs_t);
140 acpi_create_facs(facs);
142 dsdt = (acpi_header_t *)current;
143 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
144 current += dsdt->length;
145 memcpy(dsdt, &AmlCode, dsdt->length);
146 /* Don't trust iasl to get checksum right. */
147 dsdt->checksum = 0; /* needs to be set to 0 first (part of csum) */
148 dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
149 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
151 printk(BIOS_DEBUG, "ACPI: * FADT\n");
153 fadt = (acpi_fadt_t *) current;
154 current += sizeof(acpi_fadt_t);
156 acpi_create_fadt(fadt, facs, dsdt);
157 acpi_add_table(rsdp, fadt);
159 printk(BIOS_DEBUG, "ACPI: * MADT\n");
160 madt = (acpi_madt_t *) current;
161 acpi_create_madt(madt);
162 if (madt->header.length > sizeof(acpi_madt_t)) {
163 current += madt->header.length;
164 acpi_add_table(rsdp, madt);
166 /* don't add empty madt */
167 current = (unsigned long)madt;
170 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
171 ssdt = (acpi_header_t *)current;
172 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
173 current += ssdt->length;
174 acpi_add_table(rsdp, ssdt);
176 printk(BIOS_INFO, "ACPI: done.\n");