2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2008 coresystems GmbH
5 * Copyright (C) 2009 Thomas Jourdan <thomas.jourdan@gmail.com>
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
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.
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,
24 #include <console/console.h>
26 #include <arch/smp/mpspec.h>
27 #include <device/pci.h>
31 // Generate MP-table IRQ numbers for PCI devices.
38 #define PCI_IRQ(dev, intLine) (((dev)<<2) | intLine)
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
61 static void *smp_write_config_table(void *v)
63 static const char sig[4] = "PCMP";
64 static const char oem[8] = "COREBOOT";
65 static const char productid[12] = "EagleHeights";
66 struct mp_config_table *mc;
67 unsigned char bus_num, bus_chipset, bus_isa, bus_pci;
68 unsigned char bus_pcie_a, bus_pcie_a1, bus_pcie_b;
75 dev = dev_find_slot(0, PCI_DEVFN(0x1F,0));
76 res = find_resource(dev, RCBA);
82 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
83 memset(mc, 0, sizeof(*mc));
85 memcpy(mc->mpc_signature, sig, sizeof(sig));
86 mc->mpc_length = sizeof(*mc); /* initially just the header */
88 mc->mpc_checksum = 0; /* not yet computed */
89 memcpy(mc->mpc_oem, oem, sizeof(oem));
90 memcpy(mc->mpc_productid, productid, sizeof(productid));
93 mc->mpc_entry_count = 0; /* No entries yet... */
94 mc->mpc_lapic = LAPIC_ADDR;
99 smp_write_processors(mc);
101 /* Get bus numbers */
105 dev = dev_find_slot(0, PCI_DEVFN(0x1E,0));
107 bus_pci = pci_read_config8(dev, PCI_SECONDARY_BUS);
108 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
111 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
116 dev = dev_find_slot(0, PCI_DEVFN(2,0));
118 bus_pcie_a = pci_read_config8(dev, PCI_SECONDARY_BUS);
120 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port A 0:2.0, using defaults\n");
124 dev = dev_find_slot(0, PCI_DEVFN(3,0));
126 bus_pcie_a1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
128 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
132 dev = dev_find_slot(0, PCI_DEVFN(0x1C,0));
134 bus_pcie_b = pci_read_config8(dev, PCI_SECONDARY_BUS);
136 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
141 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
142 smp_write_bus(mc, bus_num, "PCI ");
144 smp_write_bus(mc, bus_isa, "ISA ");
146 /*I/O APICs: APIC ID Version State Address*/
147 smp_write_ioapic(mc, 2, 0x20, 0xfec00000);
151 struct resource *res;
152 dev = dev_find_slot(1, PCI_DEVFN(0x1e,0));
154 res = find_resource(dev, PCI_BASE_ADDRESS_0);
156 smp_write_ioapic(mc, 3, 0x20, res->base);
159 dev = dev_find_slot(1, PCI_DEVFN(0x1c,0));
161 res = find_resource(dev, PCI_BASE_ADDRESS_0);
163 smp_write_ioapic(mc, 4, 0x20, res->base);
166 dev = dev_find_slot(4, PCI_DEVFN(0x1e,0));
168 res = find_resource(dev, PCI_BASE_ADDRESS_0);
170 smp_write_ioapic(mc, 5, 0x20, res->base);
173 dev = dev_find_slot(4, PCI_DEVFN(0x1c,0));
175 res = find_resource(dev, PCI_BASE_ADDRESS_0);
177 smp_write_ioapic(mc, 8, 0x20, res->base);
182 /*I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
183 /* IRQ0 8254 Counter 0, MNT0 */
184 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, IO_APIC0, 0);
186 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 1, IO_APIC0, 1);
187 /* IRQ2 8259 cascade only */
188 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, IO_APIC0, 2);
189 /* IRQ3 COM2, Option for PIRQx */
190 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 3, IO_APIC0, 3);
191 /* IRQ4 COM1, Option for PIRQx */
192 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 4, IO_APIC0, 4);
193 /* IRQ5 Option for PIRQx */
194 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 5, IO_APIC0, 5);
195 /* IRQ6 Option for PIRQx */
196 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 6, IO_APIC0, 6);
197 /* IRQ7 OPtion for PIRQx */
198 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 7, IO_APIC0, 7);
199 /* IRQ8# RTC, MNT1 */
200 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE |MP_IRQ_POLARITY_HIGH, bus_isa, 8, IO_APIC0, 8);
201 /* IRQ9 Option for PIRQx, SCI, TCO */
202 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 9, IO_APIC0, 9);
203 /* IRQ10 Option for PIRQx, SCI, TCO */
204 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 12, IO_APIC0, 10);
205 /* IRQ11 Option for PIRQx, SCI, TCO, MMT2 */
206 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 12, IO_APIC0, 11);
207 /* IRQ12 Mouse, Option for PIRQx */
208 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 12, IO_APIC0, 12);
209 /* IRQ13 Floating point interrupt generated off of the processor assertion of FERR# */
210 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 13, IO_APIC0, 13);
211 /* IRQ14 PIRQx Sata primary (legacy mode) */
212 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 14, IO_APIC0, 14);
213 /* IRQ15 PIRQx Sata secondary (legacy mode) */
214 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 15, IO_APIC0, 15);
216 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
217 smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 0);
218 smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 1);
220 /* Internal PCI device for i3100 */
224 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);
228 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);
232 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);
236 for(i = 0; i < 4; i++) {
237 pin = (read32(rcba + RCBA_D28IP) >> (i * 4)) & 0x0F;
240 route = PIRQ_A + ((read16(rcba + RCBA_D28IR) >> (pin * 4)) & 0x07);
241 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(28, pin), IO_APIC0, route);
245 /* USB 1.1 : device 29, function 0, 1
247 for(i = 0; i < 2; i++) {
248 pin = (read32(rcba + RCBA_D29IP) >> (i * 4)) & 0x0F;
251 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
252 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
256 /* USB 2.0 : device 29, function 7
258 pin = (read32(rcba + RCBA_D29IP) >> (7 * 4)) & 0x0F;
261 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
262 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
265 /* SATA : device 31 function 2
266 SMBus : device 31 function 3
267 Performance counters : device 31 function 4
269 for(i = 2; i < 5; i++) {
270 pin = (read32(rcba + RCBA_D31IP) >> (i * 4)) & 0x0F;
273 route = PIRQ_A + ((read16(rcba + RCBA_D31IR) >> (pin * 4)) & 0x07);
274 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(31, pin), IO_APIC0, route);
282 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);
283 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);
284 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);
285 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);
289 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);
290 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);
291 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);
292 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);
296 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);
297 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);
298 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);
299 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);
303 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);
304 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);
305 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);
306 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);
308 /* There is no extension information... */
310 /* Compute the checksums */
311 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
312 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
313 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
314 mc, smp_next_mpe_entry(mc));
315 return smp_next_mpe_entry(mc);
318 unsigned long write_smp_table(unsigned long addr)
321 v = smp_write_floating_table(addr);
322 return (unsigned long)smp_write_config_table(v);