blob: 0fe83ea26e6b742ca0809cba760495e71fc0508d [file] [log] [blame]
Florian Zumbiehl21385562011-11-01 20:19:40 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Written by Stefan Reinauer <stepan@openbios.org>.
5 * ACPI FADT, FACS, and DSDT table support added by
6 *
7 * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org>
8 * Copyright (C) 2005 Nick Barker <nick.barker9@btinternet.com>
9 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include <console/console.h>
26#include <string.h>
27#include <arch/acpi.h>
28#include <arch/smp/mpspec.h>
29#include <arch/ioapic.h>
30#include <device/device.h>
31#include <device/pci_ids.h>
32#include "southbridge/via/vt8237r/vt8237r.h"
Florian Zumbiehl6cdf5a92011-11-01 20:19:41 +010033#include "southbridge/via/k8t890/k8x8xx.h"
Florian Zumbiehl21385562011-11-01 20:19:40 +010034#include "northbridge/amd/amdk8/acpi.h"
35#include <cpu/amd/model_fxx_powernow.h>
36
37extern const unsigned char AmlCode[];
38
39unsigned long acpi_fill_mcfg(unsigned long current)
40{
41 device_t dev;
42 struct resource *res;
43
44 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CE_5, 0);
45 if (!dev)
46 return current;
47
48 res = find_resource(dev, K8T890_MMCONFIG_MBAR);
49 if (res) {
50 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)
51 current, res->base, 0x0, 0x0, 0xff);
52 }
53 return current;
54}
55
56unsigned long acpi_fill_madt(unsigned long current)
57{
58 unsigned int gsi_base = 0x18;
59
60 /* Create all subtables for processors. */
61 current = acpi_create_madt_lapics(current);
62
63 /* Write SB IOAPIC. */
64 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
65 VT8237R_APIC_ID, IO_APIC_ADDR, 0);
66
67 /* Write NB IOAPIC. */
68 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
69 K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base);
70
71 /* IRQ9 ACPI active low. */
72 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
73 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
74
75 /* IRQ0 -> APIC IRQ2. */
76 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
77 current, 0, 0, 2, 0x0);
78
79 /* Create all subtables for processors. */
80 current = acpi_create_madt_lapic_nmis(current,
81 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
82
83 return current;
84}
85
86unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
87{
88 k8acpi_write_vars();
89 amd_model_fxx_generate_powernow(0, 0, 0);
90 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
91 return (unsigned long) (acpigen_get_current());
92}
93
94unsigned long write_acpi_tables(unsigned long start)
95{
96 unsigned long current;
97 acpi_rsdp_t *rsdp;
98 acpi_srat_t *srat;
99 acpi_rsdt_t *rsdt;
100 acpi_madt_t *madt;
101 acpi_mcfg_t *mcfg;
102 acpi_fadt_t *fadt;
103 acpi_facs_t *facs;
104 acpi_header_t *ssdt;
105 acpi_header_t *dsdt;
106
107 /* Align ACPI tables to 16 byte. */
Patrick Georgi26b00e62012-04-20 19:19:47 +0200108 start = ALIGN(start, 16);
Florian Zumbiehl21385562011-11-01 20:19:40 +0100109 current = start;
110
111 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
112
113 /* We need at least an RSDP and an RSDT table. */
114 rsdp = (acpi_rsdp_t *) current;
115 current += sizeof(acpi_rsdp_t);
116 rsdt = (acpi_rsdt_t *) current;
117 current += sizeof(acpi_rsdt_t);
118
119 /* Clear all table memory. */
120 memset((void *) start, 0, current - start);
121
122 acpi_write_rsdp(rsdp, rsdt, NULL);
123 acpi_write_rsdt(rsdt);
124
125 /* We explicitly add these tables later on: */
126 printk(BIOS_DEBUG, "ACPI: * FACS\n");
127 facs = (acpi_facs_t *) current;
128 current += sizeof(acpi_facs_t);
129 acpi_create_facs(facs);
130
131 dsdt = (acpi_header_t *)current;
132 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
133 current += dsdt->length;
134 memcpy(dsdt, &AmlCode, dsdt->length);
135 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
136 dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
137 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
138 dsdt->length);
139 printk(BIOS_DEBUG, "ACPI: * FADT\n");
140
141 fadt = (acpi_fadt_t *) current;
142 current += sizeof(acpi_fadt_t);
143
144 acpi_create_fadt(fadt, facs, dsdt);
145 acpi_add_table(rsdp, fadt);
146
147 /* If we want to use HPET timers Linux wants it in MADT. */
148 printk(BIOS_DEBUG, "ACPI: * MADT\n");
149 madt = (acpi_madt_t *) current;
150 acpi_create_madt(madt);
151 current += madt->header.length;
152 acpi_add_table(rsdp, madt);
153 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
154 mcfg = (acpi_mcfg_t *) current;
155 acpi_create_mcfg(mcfg);
156 current += mcfg->header.length;
157 acpi_add_table(rsdp, mcfg);
158
159 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
160 srat = (acpi_srat_t *) current;
161 acpi_create_srat(srat);
162 current += srat->header.length;
163 acpi_add_table(rsdp, srat);
164
165 /* SSDT */
166 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
167 ssdt = (acpi_header_t *)current;
168
169 acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR);
170 current += ssdt->length;
171 acpi_add_table(rsdp, ssdt);
172
173 printk(BIOS_INFO, "ACPI: done.\n");
174 return current;
175}