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/ioapic.h>
27 #include <arch/smp/mpspec.h>
28 #include <device/pci.h>
32 // Generate MP-table IRQ numbers for PCI devices.
39 #define PCI_IRQ(dev, intLine) (((dev)<<2) | intLine)
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
62 static void *smp_write_config_table(void *v)
64 static const char sig[4] = "PCMP";
65 static const char oem[8] = "COREBOOT";
66 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;
76 dev = dev_find_slot(0, PCI_DEVFN(0x1F,0));
77 res = find_resource(dev, RCBA);
83 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
84 memset(mc, 0, sizeof(*mc));
86 memcpy(mc->mpc_signature, sig, sizeof(sig));
87 mc->mpc_length = sizeof(*mc); /* initially just the header */
89 mc->mpc_checksum = 0; /* not yet computed */
90 memcpy(mc->mpc_oem, oem, sizeof(oem));
91 memcpy(mc->mpc_productid, productid, sizeof(productid));
94 mc->mpc_entry_count = 0; /* No entries yet... */
95 mc->mpc_lapic = LAPIC_ADDR;
100 smp_write_processors(mc);
102 /* Get bus numbers */
106 dev = dev_find_slot(0, PCI_DEVFN(0x1E,0));
108 bus_pci = pci_read_config8(dev, PCI_SECONDARY_BUS);
109 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
112 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
117 dev = dev_find_slot(0, PCI_DEVFN(2,0));
119 bus_pcie_a = pci_read_config8(dev, PCI_SECONDARY_BUS);
121 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port A 0:2.0, using defaults\n");
125 dev = dev_find_slot(0, PCI_DEVFN(3,0));
127 bus_pcie_a1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
129 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
133 dev = dev_find_slot(0, PCI_DEVFN(0x1C,0));
135 bus_pcie_b = pci_read_config8(dev, PCI_SECONDARY_BUS);
137 printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n");
142 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
143 smp_write_bus(mc, bus_num, "PCI ");
145 smp_write_bus(mc, bus_isa, "ISA ");
147 /*I/O APICs: APIC ID Version State Address*/
148 smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
152 struct resource *res;
153 dev = dev_find_slot(1, PCI_DEVFN(0x1e,0));
155 res = find_resource(dev, PCI_BASE_ADDRESS_0);
157 smp_write_ioapic(mc, 3, 0x20, res->base);
160 dev = dev_find_slot(1, PCI_DEVFN(0x1c,0));
162 res = find_resource(dev, PCI_BASE_ADDRESS_0);
164 smp_write_ioapic(mc, 4, 0x20, res->base);
167 dev = dev_find_slot(4, PCI_DEVFN(0x1e,0));
169 res = find_resource(dev, PCI_BASE_ADDRESS_0);
171 smp_write_ioapic(mc, 5, 0x20, res->base);
174 dev = dev_find_slot(4, PCI_DEVFN(0x1c,0));
176 res = find_resource(dev, PCI_BASE_ADDRESS_0);
178 smp_write_ioapic(mc, 8, 0x20, res->base);
183 mptable_add_isa_interrupts(mc, bus_isa, IO_APIC0, 0);
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);
189 /* Internal PCI device for i3100 */
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);
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);
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);
205 for(i = 0; i < 4; i++) {
206 pin = (read32(rcba + RCBA_D28IP) >> (i * 4)) & 0x0F;
209 route = PIRQ_A + ((read16(rcba + RCBA_D28IR) >> (pin * 4)) & 0x07);
210 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(28, pin), IO_APIC0, route);
214 /* USB 1.1 : device 29, function 0, 1
216 for(i = 0; i < 2; i++) {
217 pin = (read32(rcba + RCBA_D29IP) >> (i * 4)) & 0x0F;
220 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
221 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
225 /* USB 2.0 : device 29, function 7
227 pin = (read32(rcba + RCBA_D29IP) >> (7 * 4)) & 0x0F;
230 route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07);
231 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route);
234 /* SATA : device 31 function 2
235 SMBus : device 31 function 3
236 Performance counters : device 31 function 4
238 for(i = 2; i < 5; i++) {
239 pin = (read32(rcba + RCBA_D31IP) >> (i * 4)) & 0x0F;
242 route = PIRQ_A + ((read16(rcba + RCBA_D31IR) >> (pin * 4)) & 0x07);
243 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(31, pin), IO_APIC0, route);
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);
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);
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);
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);
277 /* There is no extension information... */
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);
282 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
283 mc, smp_next_mpe_entry(mc));
284 return smp_next_mpe_entry(mc);
287 unsigned long write_smp_table(unsigned long addr)
290 v = smp_write_floating_table(addr);
291 return (unsigned long)smp_write_config_table(v);