blob: 0dbad24160812b9f8f4650c13c02c9f2266435bc [file] [log] [blame]
Thomas Jourdan1a692d82009-07-01 17:01:17 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2008 coresystems GmbH
5 * Copyright (C) 2009 Thomas Jourdan <thomas.jourdan@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
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.
16 *
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,
20 * MA 02110-1301 USA
21 */
22
23#include <string.h>
24#include <console/console.h>
25#include <arch/acpi.h>
26#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
29#include "ioapic.h"
30
31extern unsigned char AmlCode[];
32
33unsigned long acpi_fill_mcfg(unsigned long current)
34{
35 device_t dev;
36 u64 mmcfg;
37
38 dev = dev_find_device(0x8086, 0x35B0, 0); // 0:0x13.0
39 if (!dev)
40 return current;
41
42 // MMCFG not supported or not enabled.
43 mmcfg = ((u64) pci_read_config16(dev, 0xce)) << 16;
44 if (!mmcfg)
45 return current;
46
47 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
48 mmcfg, 0x0, 0x0, 0xff);
49
50 return current;
51}
52
53void acpi_create_intel_hpet(acpi_hpet_t * hpet)
54{
55#define HPET_ADDR 0xfed00000ULL
56 acpi_header_t *header = &(hpet->header);
57 acpi_addr_t *addr = &(hpet->addr);
58
59 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
60
61 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +000062 memcpy(header->signature, "HPET", 4);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000063 memcpy(header->oem_id, OEM_ID, 6);
64 memcpy(header->oem_table_id, "IC ", 8);
65 memcpy(header->asl_compiler_id, ASLC, 4);
66
67 header->length = sizeof(acpi_hpet_t);
68 header->revision = 1;
69
70 /* fill out HPET address */
71 // XXX factory bios just puts an address here -- who's right?
72 addr->space_id = 0; /* Memory */
73 addr->bit_width = 64;
74 addr->bit_offset = 0;
75 addr->addrl = HPET_ADDR & 0xffffffff;
76 addr->addrh = HPET_ADDR >> 32;
77
78 hpet->id = 0x80861234;
79 hpet->number = 0x00;
80 hpet->min_tick = 0x0090;
81
82 header->checksum = acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
83}
84
85#define IO_APIC0 2
86#define IO_APIC1 3
87#define IO_APIC0_ADDR 0xfec00000UL
88#define IO_APIC1_ADDR 0xfec10000UL
89
90unsigned long acpi_fill_madt(unsigned long current)
91{
92 unsigned int irq_start = 0;
93 device_t dev = 0;
94 struct resource* res = NULL;
95 unsigned char bus_isa;
96
97 /* Local Apic */
98 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 1, 0);
99 // This one is for the second core... Will it hurt?
100 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 2, 1);
101
102 /* IOAPIC */
103 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, IO_APIC0, IO_APIC0_ADDR, irq_start);
104 irq_start += INTEL_IOAPIC_NUM_INTERRUPTS;
105 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, IO_APIC1, IO_APIC1_ADDR, irq_start);
106 irq_start += INTEL_IOAPIC_NUM_INTERRUPTS;
107
108 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
109
110 if (dev) {
111 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
112 bus_isa++;
113 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000114 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000115 bus_isa = 7;
116 }
117
118 /* Map ISA IRQ 0 to IRQ 2 */
119 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, bus_isa, 0, 2, 0);
120
121 /* IRQ9 differs from ISA standard - ours is active high, level-triggered */
122 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000d);
123
124 return current;
125}
126
127unsigned long acpi_fill_slit(unsigned long current)
128{
129 // Not implemented
130 return current;
131}
132
133unsigned long acpi_fill_srat(unsigned long current)
134{
135 /* No NUMA, no SRAT */
136 return current;
137}
138
139
140#define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
141unsigned long write_acpi_tables(unsigned long start)
142{
143 unsigned long current;
144 int i;
145 acpi_rsdp_t *rsdp;
146 acpi_rsdt_t *rsdt;
147 acpi_hpet_t *hpet;
148 acpi_madt_t *madt;
149 acpi_mcfg_t *mcfg;
150 acpi_fadt_t *fadt;
151 acpi_facs_t *facs;
152 acpi_header_t *dsdt;
153
154 current = start;
155
156 /* Align ACPI tables to 16byte */
157 ALIGN_CURRENT;
158
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000159 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", current);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000160
161 /* We need at least an RSDP and an RSDT Table */
162 rsdp = (acpi_rsdp_t *) current;
163 current += sizeof(acpi_rsdp_t);
164 ALIGN_CURRENT;
165 rsdt = (acpi_rsdt_t *) current;
166 current += sizeof(acpi_rsdt_t);
167 ALIGN_CURRENT;
168
169 /* clear all table memory */
170 memset((void *) start, 0, current - start);
171
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000172 acpi_write_rsdp(rsdp, rsdt, NULL);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000173 acpi_write_rsdt(rsdt);
174
175 /*
176 * We explicitly add these tables later on:
177 */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000178 printk(BIOS_DEBUG, "ACPI: * HPET\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000179
180 hpet = (acpi_hpet_t *) current;
181 current += sizeof(acpi_hpet_t);
182 ALIGN_CURRENT;
183 acpi_create_intel_hpet(hpet);
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000184 acpi_add_table(rsdp, hpet);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000185
186 /* If we want to use HPET Timers Linux wants an MADT */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000187 printk(BIOS_DEBUG, "ACPI: * MADT\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000188
189 madt = (acpi_madt_t *) current;
190 acpi_create_madt(madt);
191 current += madt->header.length;
192 ALIGN_CURRENT;
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000193 acpi_add_table(rsdp, madt);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000194
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000195 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000196 mcfg = (acpi_mcfg_t *) current;
197 acpi_create_mcfg(mcfg);
198 current += mcfg->header.length;
199 ALIGN_CURRENT;
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000200 acpi_add_table(rsdp, mcfg);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000201
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000202 printk(BIOS_DEBUG, "ACPI: * FACS\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000203 facs = (acpi_facs_t *) current;
204 current += sizeof(acpi_facs_t);
205 ALIGN_CURRENT;
206 acpi_create_facs(facs);
207
208 dsdt = (acpi_header_t *) current;
209 current += ((acpi_header_t *) AmlCode)->length;
210 ALIGN_CURRENT;
211 memcpy((void *) dsdt, (void *) AmlCode,
212 ((acpi_header_t *) AmlCode)->length);
213
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000214 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000215 dsdt->length);
216
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000217 printk(BIOS_DEBUG, "ACPI: * FADT\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000218 fadt = (acpi_fadt_t *) current;
219 current += sizeof(acpi_fadt_t);
220 ALIGN_CURRENT;
221
222 acpi_create_fadt(fadt, facs, dsdt);
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000223 acpi_add_table(rsdp, fadt);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000224
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000225 printk(BIOS_INFO, "ACPI: done.\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000226 return current;
227}