blob: 33d7b014807813840a7dc05ff4a6d6aa8d0b9607 [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
24#include <console/console.h>
25#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000026#include <arch/ioapic.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000027#include <arch/smp/mpspec.h>
28#include <device/pci.h>
29#include <string.h>
30#include <stdint.h>
31
32// Generate MP-table IRQ numbers for PCI devices.
33#define IO_APIC0 2
34
35#define INT_A 0
36#define INT_B 1
37#define INT_C 2
38#define INT_D 3
39#define PCI_IRQ(dev, intLine) (((dev)<<2) | intLine)
40
41#define PIRQ_A 16
42#define PIRQ_B 17
43#define PIRQ_C 18
44#define PIRQ_D 19
45#define PIRQ_E 20
46#define PIRQ_F 21
47#define PIRQ_G 22
48#define PIRQ_H 23
49
50// RCBA
51#define RCBA 0xF0
52
53#define RCBA_D31IP 0x3100
54#define RCBA_D30IP 0x3104
55#define RCBA_D29IP 0x3108
56#define RCBA_D28IP 0x310C
57#define RCBA_D31IR 0x3140
58#define RCBA_D30IR 0x3142
59#define RCBA_D29IR 0x3144
60#define RCBA_D28IR 0x3146
61
Myles Watson08e0fb82010-03-22 16:33:25 +000062static void *smp_write_config_table(void *v)
Thomas Jourdan1a692d82009-07-01 17:01:17 +000063{
64 static const char sig[4] = "PCMP";
Stefan Reinauerd6532112010-04-16 00:31:44 +000065 static const char oem[8] = "COREBOOT";
Thomas Jourdan1a692d82009-07-01 17:01:17 +000066 static const char productid[12] = "EagleHeights";
67 struct mp_config_table *mc;
68 unsigned char bus_num, bus_chipset, bus_isa, bus_pci;
69 unsigned char bus_pcie_a, bus_pcie_a1, bus_pcie_b;
70 int i;
71 uint32_t pin, route;
72 device_t dev;
73 struct resource *res;
74 unsigned long rcba;
75
76 dev = dev_find_slot(0, PCI_DEVFN(0x1F,0));
77 res = find_resource(dev, RCBA);
78 if (!res) {
Stefan Reinauerc02c34e2010-04-07 02:30:57 +000079 return NULL;
Thomas Jourdan1a692d82009-07-01 17:01:17 +000080 }
81 rcba = res->base;
82
83 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
84 memset(mc, 0, sizeof(*mc));
85
86 memcpy(mc->mpc_signature, sig, sizeof(sig));
87 mc->mpc_length = sizeof(*mc); /* initially just the header */
88 mc->mpc_spec = 0x04;
89 mc->mpc_checksum = 0; /* not yet computed */
90 memcpy(mc->mpc_oem, oem, sizeof(oem));
91 memcpy(mc->mpc_productid, productid, sizeof(productid));
92 mc->mpc_oemptr = 0;
93 mc->mpc_oemsize = 0;
94 mc->mpc_entry_count = 0; /* No entries yet... */
95 mc->mpc_lapic = LAPIC_ADDR;
96 mc->mpe_length = 0;
97 mc->mpe_checksum = 0;
98 mc->reserved = 0;
99
100 smp_write_processors(mc);
101
102 /* Get bus numbers */
103 bus_chipset = 0;
104
105 /* PCI */
106 dev = dev_find_slot(0, PCI_DEVFN(0x1E,0));
107 if (dev) {
108 bus_pci = pci_read_config8(dev, PCI_SECONDARY_BUS);
109 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
110 bus_isa++;
111 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000112 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000113 bus_pci = 6;
114 bus_isa = 7;
115 }
116
117 dev = dev_find_slot(0, PCI_DEVFN(2,0));
118 if(dev) {
119 bus_pcie_a = pci_read_config8(dev, PCI_SECONDARY_BUS);
120 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000121 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port A 0:2.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000122 bus_pcie_a = 1;
123 }
124
125 dev = dev_find_slot(0, PCI_DEVFN(3,0));
126 if(dev) {
127 bus_pcie_a1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
128 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000129 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000130 bus_pcie_a1 = 2;
131 }
132
133 dev = dev_find_slot(0, PCI_DEVFN(0x1C,0));
134 if(dev) {
135 bus_pcie_b = pci_read_config8(dev, PCI_SECONDARY_BUS);
136 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000137 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000138 bus_pcie_b = 3;
139 }
140
141 /*Bus: Bus ID Type*/
142 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
143 smp_write_bus(mc, bus_num, "PCI ");
144 }
145 smp_write_bus(mc, bus_isa, "ISA ");
146
147 /*I/O APICs: APIC ID Version State Address*/
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000148 smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000149 /*
150 {
151 device_t dev;
152 struct resource *res;
153 dev = dev_find_slot(1, PCI_DEVFN(0x1e,0));
154 if (dev) {
155 res = find_resource(dev, PCI_BASE_ADDRESS_0);
156 if (res) {
157 smp_write_ioapic(mc, 3, 0x20, res->base);
158 }
159 }
160 dev = dev_find_slot(1, PCI_DEVFN(0x1c,0));
161 if (dev) {
162 res = find_resource(dev, PCI_BASE_ADDRESS_0);
163 if (res) {
164 smp_write_ioapic(mc, 4, 0x20, res->base);
165 }
166 }
167 dev = dev_find_slot(4, PCI_DEVFN(0x1e,0));
168 if (dev) {
169 res = find_resource(dev, PCI_BASE_ADDRESS_0);
170 if (res) {
171 smp_write_ioapic(mc, 5, 0x20, res->base);
172 }
173 }
174 dev = dev_find_slot(4, PCI_DEVFN(0x1c,0));
175 if (dev) {
176 res = find_resource(dev, PCI_BASE_ADDRESS_0);
177 if (res) {
178 smp_write_ioapic(mc, 8, 0x20, res->base);
179 }
180 }
181 }
182 */
Patrick Georgic5b87c82010-05-20 15:28:19 +0000183 mptable_add_isa_interrupts(mc, bus_isa, IO_APIC0, 0);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000184
185 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
186 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 0);
187 smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 1);
188
189 /* Internal PCI device for i3100 */
190
191 /* EDMA
192 */
193 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(1, INT_A), IO_APIC0, PIRQ_A);
194
195 /* PCIe Port A
196 */
197 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(2, INT_A), IO_APIC0, PIRQ_A);
198
199 /* PCIe Port A1
200 */
201 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(3, INT_A), IO_APIC0, PIRQ_A);
202
203 /* PCIe Port B
204 */
205 for(i = 0; i < 4; i++) {
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000206 pin = (read32(rcba + RCBA_D28IP) >> (i * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000207 if(pin > 0) {
208 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000209 route = PIRQ_A + ((read16(rcba + RCBA_D28IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000210 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(28, pin), IO_APIC0, route);
211 }
212 }
213
214 /* USB 1.1 : device 29, function 0, 1
215 */
216 for(i = 0; i < 2; i++) {
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000217 pin = (read32(rcba + RCBA_D29IP) >> (i * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000218 if(pin > 0) {
219 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000220 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000221 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
222 }
223 }
224
225 /* USB 2.0 : device 29, function 7
226 */
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000227 pin = (read32(rcba + RCBA_D29IP) >> (7 * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000228 if(pin > 0) {
229 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000230 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000231 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
232 }
233
234 /* SATA : device 31 function 2
235 SMBus : device 31 function 3
236 Performance counters : device 31 function 4
237 */
238 for(i = 2; i < 5; i++) {
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000239 pin = (read32(rcba + RCBA_D31IP) >> (i * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000240 if(pin > 0) {
241 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000242 route = PIRQ_A + ((read16(rcba + RCBA_D31IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000243 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(31, pin), IO_APIC0, route);
244 }
245 }
246
247 /* SLOTS */
248
249 /* PCIe 4x slot A
250 */
251 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
252 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
253 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
254 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
255
256 /* PCIe 4x slot A1
257 */
258 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
259 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
260 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
261 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_a1, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
262
263 /* PCIe 4x slot B
264 */
265 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
266 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
267 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
268 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcie_b, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
269
270 /* PCI slot
271 */
272 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_A), IO_APIC0, PIRQ_A);
273 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_B), IO_APIC0, PIRQ_B);
274 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_C), IO_APIC0, PIRQ_C);
275 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pci, PCI_IRQ(0, INT_D), IO_APIC0, PIRQ_D);
276
277 /* There is no extension information... */
278
279 /* Compute the checksums */
280 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
281 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000282 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000283 mc, smp_next_mpe_entry(mc));
284 return smp_next_mpe_entry(mc);
285}
286
287unsigned long write_smp_table(unsigned long addr)
288{
289 void *v;
290 v = smp_write_floating_table(addr);
291 return (unsigned long)smp_write_config_table(v);
292}