Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 1 | /* |
| 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 Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 23 | #include <console/console.h> |
| 24 | #include <arch/io.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 25 | #include <arch/ioapic.h> |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 26 | #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 Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 61 | static void *smp_write_config_table(void *v) |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 62 | { |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 63 | struct mp_config_table *mc; |
| 64 | unsigned char bus_num, bus_chipset, bus_isa, bus_pci; |
| 65 | unsigned char bus_pcie_a, bus_pcie_a1, bus_pcie_b; |
| 66 | int i; |
| 67 | 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 Reinauer | c02c34e | 2010-04-07 02:30:57 +0000 | [diff] [blame] | 75 | return NULL; |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 76 | } |
| 77 | rcba = res->base; |
| 78 | |
| 79 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 80 | |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 81 | mptable_init(mc, "EagleHeights", LAPIC_ADDR); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 82 | |
| 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); |
| 92 | bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS); |
| 93 | bus_isa++; |
| 94 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 95 | printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n"); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 96 | bus_pci = 6; |
| 97 | bus_isa = 7; |
| 98 | } |
| 99 | |
| 100 | dev = dev_find_slot(0, PCI_DEVFN(2,0)); |
| 101 | if(dev) { |
| 102 | bus_pcie_a = pci_read_config8(dev, PCI_SECONDARY_BUS); |
| 103 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 104 | printk(BIOS_DEBUG, "ERROR - could not find PCIe Port A 0:2.0, using defaults\n"); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 105 | bus_pcie_a = 1; |
| 106 | } |
| 107 | |
| 108 | dev = dev_find_slot(0, PCI_DEVFN(3,0)); |
| 109 | if(dev) { |
| 110 | bus_pcie_a1 = pci_read_config8(dev, PCI_SECONDARY_BUS); |
| 111 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 112 | printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n"); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 113 | bus_pcie_a1 = 2; |
| 114 | } |
| 115 | |
| 116 | dev = dev_find_slot(0, PCI_DEVFN(0x1C,0)); |
| 117 | if(dev) { |
| 118 | bus_pcie_b = pci_read_config8(dev, PCI_SECONDARY_BUS); |
| 119 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 120 | printk(BIOS_DEBUG, "ERROR - could not find PCIe Port B 0:3.0, using defaults\n"); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 121 | bus_pcie_b = 3; |
| 122 | } |
| 123 | |
| 124 | /*Bus: Bus ID Type*/ |
| 125 | for(bus_num = 0; bus_num < bus_isa; bus_num++) { |
| 126 | smp_write_bus(mc, bus_num, "PCI "); |
| 127 | } |
| 128 | smp_write_bus(mc, bus_isa, "ISA "); |
| 129 | |
| 130 | /*I/O APICs: APIC ID Version State Address*/ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 131 | smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 132 | /* |
| 133 | { |
| 134 | device_t dev; |
| 135 | struct resource *res; |
| 136 | dev = dev_find_slot(1, PCI_DEVFN(0x1e,0)); |
| 137 | if (dev) { |
| 138 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 139 | if (res) { |
| 140 | smp_write_ioapic(mc, 3, 0x20, res->base); |
| 141 | } |
| 142 | } |
| 143 | dev = dev_find_slot(1, PCI_DEVFN(0x1c,0)); |
| 144 | if (dev) { |
| 145 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 146 | if (res) { |
| 147 | smp_write_ioapic(mc, 4, 0x20, res->base); |
| 148 | } |
| 149 | } |
| 150 | dev = dev_find_slot(4, PCI_DEVFN(0x1e,0)); |
| 151 | if (dev) { |
| 152 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 153 | if (res) { |
| 154 | smp_write_ioapic(mc, 5, 0x20, res->base); |
| 155 | } |
| 156 | } |
| 157 | dev = dev_find_slot(4, PCI_DEVFN(0x1c,0)); |
| 158 | if (dev) { |
| 159 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 160 | if (res) { |
| 161 | smp_write_ioapic(mc, 8, 0x20, res->base); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | */ |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 166 | mptable_add_isa_interrupts(mc, bus_isa, IO_APIC0, 0); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 167 | |
| 168 | /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/ |
Tobias Diedrich | b907d32 | 2010-10-26 22:40:16 +0000 | [diff] [blame] | 169 | smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 0); |
| 170 | smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, bus_isa, 0, MP_APIC_ALL, 1); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 171 | |
| 172 | /* Internal PCI device for i3100 */ |
| 173 | |
| 174 | /* EDMA |
| 175 | */ |
| 176 | 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); |
| 177 | |
| 178 | /* PCIe Port A |
| 179 | */ |
| 180 | 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); |
| 181 | |
| 182 | /* PCIe Port A1 |
| 183 | */ |
| 184 | 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); |
| 185 | |
| 186 | /* PCIe Port B |
| 187 | */ |
| 188 | for(i = 0; i < 4; i++) { |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 189 | pin = (read32(rcba + RCBA_D28IP) >> (i * 4)) & 0x0F; |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 190 | if(pin > 0) { |
| 191 | pin -= 1; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 192 | route = PIRQ_A + ((read16(rcba + RCBA_D28IR) >> (pin * 4)) & 0x07); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 193 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(28, pin), IO_APIC0, route); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /* USB 1.1 : device 29, function 0, 1 |
| 198 | */ |
| 199 | for(i = 0; i < 2; i++) { |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 200 | pin = (read32(rcba + RCBA_D29IP) >> (i * 4)) & 0x0F; |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 201 | if(pin > 0) { |
| 202 | pin -= 1; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 203 | route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 204 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* USB 2.0 : device 29, function 7 |
| 209 | */ |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 210 | pin = (read32(rcba + RCBA_D29IP) >> (7 * 4)) & 0x0F; |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 211 | if(pin > 0) { |
| 212 | pin -= 1; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 213 | route = PIRQ_A + ((read16(rcba + RCBA_D29IR) >> (pin * 4)) & 0x07); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 214 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(29, pin), IO_APIC0, route); |
| 215 | } |
| 216 | |
| 217 | /* SATA : device 31 function 2 |
| 218 | SMBus : device 31 function 3 |
| 219 | Performance counters : device 31 function 4 |
| 220 | */ |
| 221 | for(i = 2; i < 5; i++) { |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 222 | pin = (read32(rcba + RCBA_D31IP) >> (i * 4)) & 0x0F; |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 223 | if(pin > 0) { |
| 224 | pin -= 1; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 225 | route = PIRQ_A + ((read16(rcba + RCBA_D31IR) >> (pin * 4)) & 0x07); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 226 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chipset, PCI_IRQ(31, pin), IO_APIC0, route); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* SLOTS */ |
| 231 | |
| 232 | /* PCIe 4x slot A |
| 233 | */ |
| 234 | 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); |
| 235 | 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); |
| 236 | 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); |
| 237 | 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); |
| 238 | |
| 239 | /* PCIe 4x slot A1 |
| 240 | */ |
| 241 | 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); |
| 242 | 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); |
| 243 | 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); |
| 244 | 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); |
| 245 | |
| 246 | /* PCIe 4x slot B |
| 247 | */ |
| 248 | 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); |
| 249 | 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); |
| 250 | 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); |
| 251 | 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); |
| 252 | |
| 253 | /* PCI slot |
| 254 | */ |
| 255 | 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); |
| 256 | 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); |
| 257 | 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); |
| 258 | 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); |
| 259 | |
| 260 | /* There is no extension information... */ |
| 261 | |
| 262 | /* Compute the checksums */ |
| 263 | mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length); |
| 264 | mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 265 | printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n", |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 266 | mc, smp_next_mpe_entry(mc)); |
| 267 | return smp_next_mpe_entry(mc); |
| 268 | } |
| 269 | |
| 270 | unsigned long write_smp_table(unsigned long addr) |
| 271 | { |
| 272 | void *v; |
| 273 | v = smp_write_floating_table(addr); |
| 274 | return (unsigned long)smp_write_config_table(v); |
| 275 | } |