blob: 809feec9de1a2ac26ded81b077f8a152f1a66407 [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
Thomas Jourdan1a692d82009-07-01 17:01:17 +000023#include <console/console.h>
24#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000025#include <arch/ioapic.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000026#include <arch/smp/mpspec.h>
27#include <device/pci.h>
28#include <string.h>
29#include <stdint.h>
30
31// Generate MP-table IRQ numbers for PCI devices.
32#define IO_APIC0 2
33
34#define INT_A 0
35#define INT_B 1
36#define INT_C 2
37#define INT_D 3
38#define PCI_IRQ(dev, intLine) (((dev)<<2) | intLine)
39
40#define PIRQ_A 16
41#define PIRQ_B 17
42#define PIRQ_C 18
43#define PIRQ_D 19
44#define PIRQ_E 20
45#define PIRQ_F 21
46#define PIRQ_G 22
47#define PIRQ_H 23
48
49// RCBA
50#define RCBA 0xF0
51
52#define RCBA_D31IP 0x3100
53#define RCBA_D30IP 0x3104
54#define RCBA_D29IP 0x3108
55#define RCBA_D28IP 0x310C
56#define RCBA_D31IR 0x3140
57#define RCBA_D30IR 0x3142
58#define RCBA_D29IR 0x3144
59#define RCBA_D28IR 0x3146
60
Myles Watson08e0fb82010-03-22 16:33:25 +000061static void *smp_write_config_table(void *v)
Thomas Jourdan1a692d82009-07-01 17:01:17 +000062{
Thomas Jourdan1a692d82009-07-01 17:01:17 +000063 struct mp_config_table *mc;
Patrick Georgi7411eab2010-11-22 14:14:56 +000064 unsigned char bus_chipset, bus_pci;
Thomas Jourdan1a692d82009-07-01 17:01:17 +000065 unsigned char bus_pcie_a, bus_pcie_a1, bus_pcie_b;
Patrick Georgi7411eab2010-11-22 14:14:56 +000066 int bus_isa, i;
Thomas Jourdan1a692d82009-07-01 17:01:17 +000067 uint32_t pin, route;
68 device_t dev;
69 struct resource *res;
70 unsigned long rcba;
71
72 dev = dev_find_slot(0, PCI_DEVFN(0x1F,0));
73 res = find_resource(dev, RCBA);
74 if (!res) {
Stefan Reinauerc02c34e2010-04-07 02:30:57 +000075 return NULL;
Thomas Jourdan1a692d82009-07-01 17:01:17 +000076 }
77 rcba = res->base;
78
79 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000080
Patrick Georgic8feedd2012-02-16 18:43:25 +010081 mptable_init(mc, LOCAL_APIC_ADDR);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000082
83 smp_write_processors(mc);
84
85 /* Get bus numbers */
86 bus_chipset = 0;
87
88 /* PCI */
89 dev = dev_find_slot(0, PCI_DEVFN(0x1E,0));
90 if (dev) {
91 bus_pci = pci_read_config8(dev, PCI_SECONDARY_BUS);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000092 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000093 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +000094 bus_pci = 6;
Thomas Jourdan1a692d82009-07-01 17:01:17 +000095 }
96
97 dev = dev_find_slot(0, PCI_DEVFN(2,0));
98 if(dev) {
99 bus_pcie_a = pci_read_config8(dev, PCI_SECONDARY_BUS);
100 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000101 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port A 0:2.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000102 bus_pcie_a = 1;
103 }
104
105 dev = dev_find_slot(0, PCI_DEVFN(3,0));
106 if(dev) {
107 bus_pcie_a1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
108 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000109 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000110 bus_pcie_a1 = 2;
111 }
112
113 dev = dev_find_slot(0, PCI_DEVFN(0x1C,0));
114 if(dev) {
115 bus_pcie_b = pci_read_config8(dev, PCI_SECONDARY_BUS);
116 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000117 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000118 bus_pcie_b = 3;
119 }
120
Patrick Georgi7411eab2010-11-22 14:14:56 +0000121 mptable_write_buses(mc, NULL, &bus_isa);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000122
123 /*I/O APICs: APIC ID Version State Address*/
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000124 smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
Uwe Hermannf98921662010-10-31 19:37:50 +0000125
Patrick Georgic5b87c82010-05-20 15:28:19 +0000126 mptable_add_isa_interrupts(mc, bus_isa, IO_APIC0, 0);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000127
128 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
Patrick Georgi6eb7a532011-10-07 21:42:52 +0200129 mptable_lintsrc(mc, bus_isa);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000130
131 /* Internal PCI device for i3100 */
132
133 /* EDMA
134 */
135 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);
136
137 /* PCIe Port A
138 */
139 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);
140
141 /* PCIe Port A1
142 */
143 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);
144
145 /* PCIe Port B
146 */
147 for(i = 0; i < 4; i++) {
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000148 pin = (read32(rcba + RCBA_D28IP) >> (i * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000149 if(pin > 0) {
150 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000151 route = PIRQ_A + ((read16(rcba + RCBA_D28IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000152 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(28, pin), IO_APIC0, route);
153 }
154 }
155
156 /* USB 1.1 : device 29, function 0, 1
157 */
158 for(i = 0; i < 2; i++) {
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000159 pin = (read32(rcba + RCBA_D29IP) >> (i * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000160 if(pin > 0) {
161 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000162 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000163 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
164 }
165 }
166
167 /* USB 2.0 : device 29, function 7
168 */
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000169 pin = (read32(rcba + RCBA_D29IP) >> (7 * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000170 if(pin > 0) {
171 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000172 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000173 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
174 }
175
176 /* SATA : device 31 function 2
177 SMBus : device 31 function 3
178 Performance counters : device 31 function 4
179 */
180 for(i = 2; i < 5; i++) {
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000181 pin = (read32(rcba + RCBA_D31IP) >> (i * 4)) & 0x0F;
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000182 if(pin > 0) {
183 pin -= 1;
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000184 route = PIRQ_A + ((read16(rcba + RCBA_D31IR) >> (pin * 4)) & 0x07);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000185 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(31, pin), IO_APIC0, route);
186 }
187 }
188
189 /* SLOTS */
190
191 /* PCIe 4x slot A
192 */
193 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);
194 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);
195 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);
196 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);
197
198 /* PCIe 4x slot A1
199 */
200 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);
201 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);
202 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);
203 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);
204
205 /* PCIe 4x slot B
206 */
207 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);
208 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);
209 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);
210 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);
211
212 /* PCI slot
213 */
214 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);
215 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);
216 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);
217 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);
218
219 /* There is no extension information... */
220
221 /* Compute the checksums */
Patrick Georgib0a9c5c2011-10-07 23:01:55 +0200222 return mptable_finalize(mc);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000223}
224
225unsigned long write_smp_table(unsigned long addr)
226{
227 void *v;
Patrick Georgic75c79b2011-10-07 22:41:07 +0200228 v = smp_write_floating_table(addr, 0);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000229 return (unsigned long)smp_write_config_table(v);
230}