blob: 5858e3ff7589051f4a089f20f03d5091b626cccd [file] [log] [blame]
Rudolf Marek05839972008-09-23 20:36:03 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Written by Stefan Reinauer <stepan@openbios.org>.
Stefan Reinauer14e22772010-04-27 06:56:47 +00005 * ACPI FADT, FACS, and DSDT table support added by
Rudolf Marek05839972008-09-23 20:36:03 +00006 *
7 * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org>
8 * Copyright (C) 2005 Nick Barker <nick.barker9@btinternet.com>
Rudolf Marek79e53252008-12-23 17:34:15 +00009 * Copyright (C) 2007, 2008 Rudolf Marek <r.marek@assembler.cz>
Rudolf Marek05839972008-09-23 20:36:03 +000010 *
11 * This program is free software; you can redistribute it and/or modify
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000012 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
Rudolf Marek05839972008-09-23 20:36:03 +000014 *
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 <device/device.h>
30#include <device/pci_ids.h>
Uwe Hermann5df41682010-09-25 16:17:20 +000031#include "southbridge/via/vt8237r/vt8237r.h"
32#include "southbridge/via/k8t890/k8t890.h"
33#include "northbridge/amd/amdk8/amdk8_acpi.h"
Rudolf Marekf997b552009-02-14 15:40:23 +000034#include <cpu/amd/model_fxx_powernow.h>
Rudolf Marek05839972008-09-23 20:36:03 +000035
Myles Watsonae608552010-04-09 03:41:23 +000036extern const unsigned char AmlCode[];
Rudolf Marek05839972008-09-23 20:36:03 +000037
38unsigned long acpi_fill_mcfg(unsigned long current)
39{
40 device_t dev;
41 struct resource *res;
42
Rudolf Marekb2bd9962009-07-23 08:10:51 +000043 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8M890CE_5, 0);
Rudolf Marek05839972008-09-23 20:36:03 +000044 if (!dev)
45 return current;
46
47 res = find_resource(dev, K8T890_MMCONFIG_MBAR);
48 if (res) {
49 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)
50 current, res->base, 0x0, 0x0, 0xff);
51 }
52 return current;
53}
54
55unsigned long acpi_fill_madt(unsigned long current)
56{
57 unsigned int gsi_base = 0x18;
58
59 /* Create all subtables for processors. */
60 current = acpi_create_madt_lapics(current);
61
62 /* Write SB IOAPIC. */
63 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
64 VT8237R_APIC_ID, VT8237R_APIC_BASE, 0);
65
66 /* Write NB IOAPIC. */
67 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
68 K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base);
69
70 /* IRQ9 ACPI active low. */
71 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
72 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
73
74 /* IRQ0 -> APIC IRQ2. */
75 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
Stefan Reinauer14e22772010-04-27 06:56:47 +000076 current, 0, 0, 2, 0x0);
Rudolf Marek05839972008-09-23 20:36:03 +000077
78 /* Create all subtables for processors. */
79 current = acpi_create_madt_lapic_nmis(current,
80 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
81
82 return current;
83}
84
Myles Watson3fe6b702009-10-09 20:13:43 +000085unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id)
Stefan Reinauerdecdb3c2009-03-31 14:10:42 +000086{
Rudolf Marek293b5f52009-02-01 18:35:15 +000087 k8acpi_write_vars();
Rudolf Marekf997b552009-02-14 15:40:23 +000088 amd_model_fxx_generate_powernow(0, 0, 0);
Rudolf Marek293b5f52009-02-01 18:35:15 +000089 return (unsigned long) (acpigen_get_current());
90}
91
Rudolf Marek05839972008-09-23 20:36:03 +000092unsigned long write_acpi_tables(unsigned long start)
93{
94 unsigned long current;
95 acpi_rsdp_t *rsdp;
96 acpi_srat_t *srat;
97 acpi_rsdt_t *rsdt;
98 acpi_mcfg_t *mcfg;
99 acpi_hpet_t *hpet;
100 acpi_madt_t *madt;
101 acpi_fadt_t *fadt;
102 acpi_facs_t *facs;
Rudolf Marek79e53252008-12-23 17:34:15 +0000103 acpi_slit_t *slit;
104 acpi_header_t *ssdt;
Rudolf Marek05839972008-09-23 20:36:03 +0000105 acpi_header_t *dsdt;
106
107 /* Align ACPI tables to 16 byte. */
108 start = (start + 0x0f) & -0x10;
109 current = start;
110
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000111 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start);
Rudolf Marek05839972008-09-23 20:36:03 +0000112
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
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000122 acpi_write_rsdp(rsdp, rsdt, NULL);
Rudolf Marek05839972008-09-23 20:36:03 +0000123 acpi_write_rsdt(rsdt);
124
125 /* We explicitly add these tables later on: */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000126 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Rudolf Marek79e53252008-12-23 17:34:15 +0000127
128 /* we should align FACS to 64B as per ACPI specs */
129
130 current = ALIGN(current, 64);
Rudolf Marek05839972008-09-23 20:36:03 +0000131 facs = (acpi_facs_t *) current;
132 current += sizeof(acpi_facs_t);
133 acpi_create_facs(facs);
134
135 dsdt = (acpi_header_t *) current;
Myles Watsonae608552010-04-09 03:41:23 +0000136 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
137 current += dsdt->length;
138 memcpy(dsdt, &AmlCode, dsdt->length);
Rudolf Marek05839972008-09-23 20:36:03 +0000139 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
Myles Watsonae608552010-04-09 03:41:23 +0000140 dsdt->checksum = acpi_checksum((u8*)dsdt, dsdt->length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000141 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
Rudolf Marek05839972008-09-23 20:36:03 +0000142 dsdt->length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000143 printk(BIOS_DEBUG, "ACPI: * FADT\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000144
145 fadt = (acpi_fadt_t *) current;
146 current += sizeof(acpi_fadt_t);
147
148 acpi_create_fadt(fadt, facs, dsdt);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000149 acpi_add_table(rsdp, fadt);
Rudolf Marek05839972008-09-23 20:36:03 +0000150
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000151 printk(BIOS_DEBUG, "ACPI: * HPET\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000152 hpet = (acpi_hpet_t *) current;
153 current += sizeof(acpi_hpet_t);
154 acpi_create_hpet(hpet);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000155 acpi_add_table(rsdp, hpet);
Rudolf Marek05839972008-09-23 20:36:03 +0000156
157 /* If we want to use HPET timers Linux wants an MADT. */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000158 printk(BIOS_DEBUG, "ACPI: * MADT\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000159 madt = (acpi_madt_t *) current;
160 acpi_create_madt(madt);
161 current += madt->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000162 acpi_add_table(rsdp, madt);
Rudolf Marek05839972008-09-23 20:36:03 +0000163
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000164 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000165 mcfg = (acpi_mcfg_t *) current;
166 acpi_create_mcfg(mcfg);
167 current += mcfg->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000168 acpi_add_table(rsdp, mcfg);
Rudolf Marek05839972008-09-23 20:36:03 +0000169
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000170 printk(BIOS_DEBUG, "ACPI: * SRAT\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000171 srat = (acpi_srat_t *) current;
172 acpi_create_srat(srat);
173 current += srat->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000174 acpi_add_table(rsdp, srat);
Rudolf Marek05839972008-09-23 20:36:03 +0000175
Rudolf Marek79e53252008-12-23 17:34:15 +0000176 /* SLIT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000177 printk(BIOS_DEBUG, "ACPI: * SLIT\n");
Rudolf Marek79e53252008-12-23 17:34:15 +0000178 slit = (acpi_slit_t *) current;
179 acpi_create_slit(slit);
180 current+=slit->header.length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000181 acpi_add_table(rsdp,slit);
Rudolf Marek79e53252008-12-23 17:34:15 +0000182
183 /* SSDT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000184 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
Rudolf Marek79e53252008-12-23 17:34:15 +0000185 ssdt = (acpi_header_t *)current;
Rudolf Marek293b5f52009-02-01 18:35:15 +0000186
187 acpi_create_ssdt_generator(ssdt, "DYNADATA");
188 current += ssdt->length;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000189 acpi_add_table(rsdp, ssdt);
Rudolf Marek79e53252008-12-23 17:34:15 +0000190
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000191 printk(BIOS_INFO, "ACPI: done.\n");
Rudolf Marek05839972008-09-23 20:36:03 +0000192 return current;
193}