blob: 86fee0c99a1efc1e1582f7aab99ae1ccc12c50be [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>.
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 v2 as published by
13 * the Free Software Foundation.
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 <device/device.h>
30#include <device/pci_ids.h>
31#include <../../../southbridge/via/vt8237r/vt8237r.h>
32#include <../../../southbridge/via/k8t890/k8t890.h>
33
34extern unsigned char AmlCode[];
35
36unsigned long acpi_fill_mcfg(unsigned long current)
37{
38 device_t dev;
39 struct resource *res;
40
41 dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_K8T890CE_5, 0);
42 if (!dev)
43 return current;
44
45 res = find_resource(dev, K8T890_MMCONFIG_MBAR);
46 if (res) {
47 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)
48 current, res->base, 0x0, 0x0, 0xff);
49 }
50 return current;
51}
52
53unsigned long acpi_fill_madt(unsigned long current)
54{
55 unsigned int gsi_base = 0x18;
56
57 /* Create all subtables for processors. */
58 current = acpi_create_madt_lapics(current);
59
60 /* Write SB IOAPIC. */
61 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
62 VT8237R_APIC_ID, VT8237R_APIC_BASE, 0);
63
64 /* Write NB IOAPIC. */
65 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
66 K8T890_APIC_ID, K8T890_APIC_BASE, gsi_base);
67
68 /* IRQ9 ACPI active low. */
69 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
70 current, 0, 9, 9, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
71
72 /* IRQ0 -> APIC IRQ2. */
73 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
74 current, 0, 0, 2, 0x0);
75
76 /* Create all subtables for processors. */
77 current = acpi_create_madt_lapic_nmis(current,
78 MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 1);
79
80 return current;
81}
82
83unsigned long write_acpi_tables(unsigned long start)
84{
85 unsigned long current;
86 acpi_rsdp_t *rsdp;
87 acpi_srat_t *srat;
88 acpi_rsdt_t *rsdt;
89 acpi_mcfg_t *mcfg;
90 acpi_hpet_t *hpet;
91 acpi_madt_t *madt;
92 acpi_fadt_t *fadt;
93 acpi_facs_t *facs;
94 acpi_header_t *dsdt;
95
96 /* Align ACPI tables to 16 byte. */
97 start = (start + 0x0f) & -0x10;
98 current = start;
99
100 printk_info("ACPI: Writing ACPI tables at %lx...\n", start);
101
102 /* We need at least an RSDP and an RSDT table. */
103 rsdp = (acpi_rsdp_t *) current;
104 current += sizeof(acpi_rsdp_t);
105 rsdt = (acpi_rsdt_t *) current;
106 current += sizeof(acpi_rsdt_t);
107
108 /* Clear all table memory. */
109 memset((void *) start, 0, current - start);
110
111 acpi_write_rsdp(rsdp, rsdt);
112 acpi_write_rsdt(rsdt);
113
114 /* We explicitly add these tables later on: */
115 printk_debug("ACPI: * FACS\n");
116 facs = (acpi_facs_t *) current;
117 current += sizeof(acpi_facs_t);
118 acpi_create_facs(facs);
119
120 dsdt = (acpi_header_t *) current;
121 current += ((acpi_header_t *) AmlCode)->length;
122 memcpy((void *) dsdt, (void *) AmlCode,
123 ((acpi_header_t *) AmlCode)->length);
124 dsdt->checksum = 0; /* Don't trust iasl to get this right. */
125 dsdt->checksum = acpi_checksum(dsdt, dsdt->length);
126 printk_debug("ACPI: * DSDT @ %08x Length %x\n", dsdt,
127 dsdt->length);
128 printk_debug("ACPI: * FADT\n");
129
130 fadt = (acpi_fadt_t *) current;
131 current += sizeof(acpi_fadt_t);
132
133 acpi_create_fadt(fadt, facs, dsdt);
134 acpi_add_table(rsdt, fadt);
135
136 printk_debug("ACPI: * HPET\n");
137 hpet = (acpi_hpet_t *) current;
138 current += sizeof(acpi_hpet_t);
139 acpi_create_hpet(hpet);
140 acpi_add_table(rsdt, hpet);
141
142 /* If we want to use HPET timers Linux wants an MADT. */
143 printk_debug("ACPI: * MADT\n");
144 madt = (acpi_madt_t *) current;
145 acpi_create_madt(madt);
146 current += madt->header.length;
147 acpi_add_table(rsdt, madt);
148
149 printk_debug("ACPI: * MCFG\n");
150 mcfg = (acpi_mcfg_t *) current;
151 acpi_create_mcfg(mcfg);
152 current += mcfg->header.length;
153 acpi_add_table(rsdt, mcfg);
154
155 printk_debug("ACPI: * SRAT\n");
156 srat = (acpi_srat_t *) current;
157 acpi_create_srat(srat);
158 current += srat->header.length;
159 acpi_add_table(rsdt, srat);
160
161 printk_info("ACPI: done.\n");
162 return current;
163}