Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mike Loptien | 9159734 | 2014-06-12 10:22:27 -0600 | [diff] [blame] | 2 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | #include <console/console.h> |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 4 | #include <device/path.h> |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 5 | #include <device/pci_ids.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 6 | #include <arch/smp/mpspec.h> |
| 7 | #include <string.h> |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 8 | #include <arch/cpu.h> |
Kyösti Mälkki | dea42e0 | 2021-05-31 20:26:16 +0300 | [diff] [blame^] | 9 | #include <cpu/cpu.h> |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 10 | #include <cpu/x86/lapic.h> |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 11 | #include <drivers/generic/ioapic/chip.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 12 | |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 13 | /* Initialize the specified "mc" struct with initial values. */ |
Kyösti Mälkki | dea42e0 | 2021-05-31 20:26:16 +0300 | [diff] [blame^] | 14 | void mptable_init(struct mp_config_table *mc) |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 15 | { |
Uwe Hermann | c36d506 | 2010-12-16 19:51:38 +0000 | [diff] [blame] | 16 | int i; |
Kyösti Mälkki | dea42e0 | 2021-05-31 20:26:16 +0300 | [diff] [blame^] | 17 | u32 lapic_addr = cpu_get_lapic_addr(); |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 18 | |
| 19 | memset(mc, 0, sizeof(*mc)); |
Uwe Hermann | c36d506 | 2010-12-16 19:51:38 +0000 | [diff] [blame] | 20 | |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 21 | memcpy(mc->mpc_signature, MPC_SIGNATURE, 4); |
Uwe Hermann | c36d506 | 2010-12-16 19:51:38 +0000 | [diff] [blame] | 22 | |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 23 | mc->mpc_length = sizeof(*mc); /* Initially just the header size. */ |
| 24 | mc->mpc_spec = 0x04; /* MultiProcessor specification 1.4 */ |
| 25 | mc->mpc_checksum = 0; /* Not yet computed. */ |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 26 | mc->mpc_oemptr = 0; |
| 27 | mc->mpc_oemsize = 0; |
| 28 | mc->mpc_entry_count = 0; /* No entries yet... */ |
| 29 | mc->mpc_lapic = lapic_addr; |
| 30 | mc->mpe_length = 0; |
| 31 | mc->mpe_checksum = 0; |
| 32 | mc->reserved = 0; |
Uwe Hermann | c36d506 | 2010-12-16 19:51:38 +0000 | [diff] [blame] | 33 | |
| 34 | strncpy(mc->mpc_oem, CONFIG_MAINBOARD_VENDOR, 8); |
| 35 | strncpy(mc->mpc_productid, CONFIG_MAINBOARD_PART_NUMBER, 12); |
| 36 | |
| 37 | /* |
| 38 | * The oem/productid fields are exactly 8/12 bytes long. If the resp. |
| 39 | * entry is shorter, the remaining bytes are filled with spaces. |
| 40 | */ |
| 41 | for (i = MIN(strlen(CONFIG_MAINBOARD_VENDOR), 8); i < 8; i++) |
| 42 | mc->mpc_oem[i] = ' '; |
| 43 | for (i = MIN(strlen(CONFIG_MAINBOARD_PART_NUMBER), 12); i < 12; i++) |
| 44 | mc->mpc_productid[i] = ' '; |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 47 | static unsigned char smp_compute_checksum(void *v, int len) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 48 | { |
| 49 | unsigned char *bytes; |
| 50 | unsigned char checksum; |
| 51 | int i; |
| 52 | bytes = v; |
| 53 | checksum = 0; |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 54 | for (i = 0; i < len; i++) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 55 | checksum -= bytes[i]; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 56 | return checksum; |
| 57 | } |
| 58 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 59 | static void *smp_write_floating_table_physaddr(uintptr_t addr, |
| 60 | uintptr_t mpf_physptr, unsigned int virtualwire) |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 61 | { |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 62 | struct intel_mp_floating *mf; |
| 63 | void *v; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 64 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 65 | v = (void *)addr; |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 66 | mf = v; |
| 67 | mf->mpf_signature[0] = '_'; |
| 68 | mf->mpf_signature[1] = 'M'; |
| 69 | mf->mpf_signature[2] = 'P'; |
| 70 | mf->mpf_signature[3] = '_'; |
| 71 | mf->mpf_physptr = mpf_physptr; |
| 72 | mf->mpf_length = 1; |
| 73 | mf->mpf_specification = 4; |
| 74 | mf->mpf_checksum = 0; |
| 75 | mf->mpf_feature1 = 0; |
Mike Loptien | d0167d3 | 2014-06-11 14:20:48 -0600 | [diff] [blame] | 76 | mf->mpf_feature2 = virtualwire?MP_FEATURE_PIC:MP_FEATURE_VIRTUALWIRE; |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 77 | mf->mpf_feature3 = 0; |
| 78 | mf->mpf_feature4 = 0; |
| 79 | mf->mpf_feature5 = 0; |
| 80 | mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16); |
| 81 | return v; |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Patrick Georgi | c75c79b | 2011-10-07 22:41:07 +0200 | [diff] [blame] | 84 | void *smp_write_floating_table(unsigned long addr, unsigned int virtualwire) |
| 85 | { |
| 86 | /* 16 byte align the table address */ |
| 87 | addr = (addr + 0xf) & (~0xf); |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 88 | return smp_write_floating_table_physaddr(addr, addr |
| 89 | + SMP_FLOATING_TABLE_LEN, virtualwire); |
Patrick Georgi | c75c79b | 2011-10-07 22:41:07 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 92 | void *smp_next_mpc_entry(struct mp_config_table *mc) |
| 93 | { |
| 94 | void *v; |
| 95 | v = (void *)(((char *)mc) + mc->mpc_length); |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 96 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 97 | return v; |
| 98 | } |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 99 | static void smp_add_mpc_entry(struct mp_config_table *mc, u16 length) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 100 | { |
| 101 | mc->mpc_length += length; |
| 102 | mc->mpc_entry_count++; |
| 103 | } |
| 104 | |
| 105 | void *smp_next_mpe_entry(struct mp_config_table *mc) |
| 106 | { |
| 107 | void *v; |
| 108 | v = (void *)(((char *)mc) + mc->mpc_length + mc->mpe_length); |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 109 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 110 | return v; |
| 111 | } |
| 112 | static void smp_add_mpe_entry(struct mp_config_table *mc, mpe_t mpe) |
| 113 | { |
| 114 | mc->mpe_length += mpe->mpe_length; |
| 115 | } |
| 116 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 117 | /* |
| 118 | * Type 0: Processor Entries: |
| 119 | * Entry Type, LAPIC ID, LAPIC Version, CPU Flags EN/BP, |
| 120 | * CPU Signature (Stepping, Model, Family), Feature Flags |
| 121 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 122 | void smp_write_processor(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 123 | u8 apicid, u8 apicver, u8 cpuflag, |
| 124 | u32 cpufeature, u32 featureflag) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 125 | { |
| 126 | struct mpc_config_processor *mpc; |
| 127 | mpc = smp_next_mpc_entry(mc); |
| 128 | memset(mpc, '\0', sizeof(*mpc)); |
| 129 | mpc->mpc_type = MP_PROCESSOR; |
| 130 | mpc->mpc_apicid = apicid; |
| 131 | mpc->mpc_apicver = apicver; |
| 132 | mpc->mpc_cpuflag = cpuflag; |
| 133 | mpc->mpc_cpufeature = cpufeature; |
| 134 | mpc->mpc_featureflag = featureflag; |
| 135 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 136 | } |
| 137 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 138 | /* |
| 139 | * If we assume a symmetric processor configuration we can |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 140 | * get all of the information we need to write the processor |
| 141 | * entry from the bootstrap processor. |
| 142 | * Plus I don't think linux really even cares. |
| 143 | * Having the proper apicid's in the table so the non-bootstrap |
| 144 | * processors can be woken up should be enough. |
| 145 | */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 146 | void smp_write_processors(struct mp_config_table *mc) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 147 | { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 148 | int boot_apic_id; |
Patrick Georgi | 07b4215 | 2011-10-14 23:02:57 +0200 | [diff] [blame] | 149 | int order_id; |
Lee Leahy | e5f29e8 | 2017-03-16 14:16:56 -0700 | [diff] [blame] | 150 | unsigned int apic_version; |
| 151 | unsigned int cpu_features; |
| 152 | unsigned int cpu_feature_flags; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 153 | struct device *cpu; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 154 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 155 | boot_apic_id = lapicid(); |
| 156 | apic_version = lapic_read(LAPIC_LVR) & 0xff; |
Subrata Banik | 53b08c3 | 2018-12-10 14:11:35 +0530 | [diff] [blame] | 157 | cpu_features = cpu_get_cpuid(); |
| 158 | cpu_feature_flags = cpu_get_feature_flags_edx(); |
Patrick Georgi | 07b4215 | 2011-10-14 23:02:57 +0200 | [diff] [blame] | 159 | /* order the output of the cpus to fix a bug in kernel 2.6.11 */ |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 160 | for (order_id = 0; order_id < 256; order_id++) { |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 161 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 162 | unsigned long cpu_flag; |
| 163 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 164 | (cpu->bus->dev->path.type != |
| 165 | DEVICE_PATH_CPU_CLUSTER)) |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 166 | continue; |
| 167 | |
| 168 | if (!cpu->enabled) |
| 169 | continue; |
| 170 | |
| 171 | cpu_flag = MPC_CPU_ENABLED; |
| 172 | |
| 173 | if (boot_apic_id == cpu->path.apic.apic_id) |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 174 | cpu_flag = MPC_CPU_ENABLED |
| 175 | | MPC_CPU_BOOTPROCESSOR; |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 176 | |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 177 | if (cpu->path.apic.apic_id == order_id) { |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 178 | smp_write_processor(mc, |
| 179 | cpu->path.apic.apic_id, apic_version, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 180 | cpu_flag, cpu_features, |
| 181 | cpu_feature_flags |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 182 | ); |
| 183 | break; |
| 184 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 185 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 189 | /* |
| 190 | * Type 1: Bus Entries: |
| 191 | * Entry Type, Bus ID, Bus Type |
| 192 | */ |
Patrick Georgi patrick | 612fcc3 | 2010-11-23 07:19:54 +0000 | [diff] [blame] | 193 | static void smp_write_bus(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 194 | u8 id, const char *bustype) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 195 | { |
| 196 | struct mpc_config_bus *mpc; |
| 197 | mpc = smp_next_mpc_entry(mc); |
| 198 | memset(mpc, '\0', sizeof(*mpc)); |
| 199 | mpc->mpc_type = MP_BUS; |
| 200 | mpc->mpc_busid = id; |
| 201 | memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype)); |
| 202 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 203 | } |
| 204 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 205 | /* |
| 206 | * Type 2: I/O APIC Entries: |
| 207 | * Entry Type, APIC ID, Version, |
| 208 | * APIC Flags:EN, Address |
| 209 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 210 | void smp_write_ioapic(struct mp_config_table *mc, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 211 | u8 id, u8 ver, void *apicaddr) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 212 | { |
| 213 | struct mpc_config_ioapic *mpc; |
| 214 | mpc = smp_next_mpc_entry(mc); |
| 215 | memset(mpc, '\0', sizeof(*mpc)); |
| 216 | mpc->mpc_type = MP_IOAPIC; |
| 217 | mpc->mpc_apicid = id; |
| 218 | mpc->mpc_apicver = ver; |
| 219 | mpc->mpc_flags = MPC_APIC_USABLE; |
| 220 | mpc->mpc_apicaddr = apicaddr; |
| 221 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 222 | } |
| 223 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 224 | /* |
| 225 | * Type 3: I/O Interrupt Table Entries: |
| 226 | * Entry Type, Int Type, Int Polarity, Int Level, |
| 227 | * Source Bus ID, Source Bus IRQ, Dest APIC ID, Dest PIN# |
| 228 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 229 | void smp_write_intsrc(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 230 | u8 irqtype, u16 irqflag, |
| 231 | u8 srcbus, u8 srcbusirq, |
| 232 | u8 dstapic, u8 dstirq) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 233 | { |
| 234 | struct mpc_config_intsrc *mpc; |
| 235 | mpc = smp_next_mpc_entry(mc); |
| 236 | memset(mpc, '\0', sizeof(*mpc)); |
| 237 | mpc->mpc_type = MP_INTSRC; |
| 238 | mpc->mpc_irqtype = irqtype; |
| 239 | mpc->mpc_irqflag = irqflag; |
| 240 | mpc->mpc_srcbus = srcbus; |
| 241 | mpc->mpc_srcbusirq = srcbusirq; |
| 242 | mpc->mpc_dstapic = dstapic; |
| 243 | mpc->mpc_dstirq = dstirq; |
| 244 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 247 | /* |
| 248 | * Type 3: I/O Interrupt Table Entries for PCI Devices: |
| 249 | * This has the same fields as 'Type 3: I/O Interrupt Table Entries' |
| 250 | * but the Source Bus IRQ field has a slightly different |
| 251 | * definition: |
| 252 | * Bits 1-0: PIRQ pin: INT_A# = 0, INT_B# = 1, INT_C# = 2, INT_D# = 3 |
| 253 | * Bits 2-6: Originating PCI Device Number (Not its parent bridge device number) |
| 254 | * Bit 7: Reserved |
| 255 | */ |
| 256 | void smp_write_pci_intsrc(struct mp_config_table *mc, |
| 257 | u8 irqtype, u8 srcbus, u8 dev, u8 pirq, |
| 258 | u8 dstapic, u8 dstirq) |
| 259 | { |
| 260 | u8 srcbusirq = (dev << 2) | pirq; |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 261 | printk(BIOS_SPEW, |
| 262 | "\tPCI srcbusirq = 0x%x from dev = 0x%x and pirq = %x\n", |
| 263 | srcbusirq, dev, pirq); |
| 264 | smp_write_intsrc(mc, irqtype, MP_IRQ_TRIGGER_LEVEL |
| 265 | | MP_IRQ_POLARITY_LOW, srcbus, srcbusirq, dstapic, dstirq); |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 266 | } |
| 267 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 268 | void smp_write_intsrc_pci_bridge(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 269 | u8 irqtype, u16 irqflag, struct device *dev, |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 270 | unsigned char dstapic, unsigned char *dstirq) |
| 271 | { |
| 272 | struct device *child; |
| 273 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 274 | int i; |
| 275 | int srcbus; |
| 276 | int slot; |
| 277 | |
| 278 | struct bus *link; |
| 279 | unsigned char dstirq_x[4]; |
| 280 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 281 | for (link = dev->link_list; link; link = link->next) { |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 282 | |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 283 | child = link->children; |
| 284 | srcbus = link->secondary; |
| 285 | |
| 286 | while (child) { |
| 287 | if (child->path.type != DEVICE_PATH_PCI) |
| 288 | goto next; |
| 289 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 290 | slot = (child->path.pci.devfn >> 3); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 291 | /* round pins */ |
| 292 | for (i = 0; i < 4; i++) |
| 293 | dstirq_x[i] = dstirq[(i + slot) % 4]; |
| 294 | |
| 295 | if ((child->class >> 16) != PCI_BASE_CLASS_BRIDGE) { |
| 296 | /* pci device */ |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 297 | printk(BIOS_DEBUG, "route irq: %s\n", |
| 298 | dev_path(child)); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 299 | for (i = 0; i < 4; i++) |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 300 | smp_write_intsrc(mc, irqtype, irqflag, |
| 301 | srcbus, (slot<<2)|i, dstapic, |
| 302 | dstirq_x[i]); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 303 | goto next; |
| 304 | } |
| 305 | |
| 306 | switch (child->class>>8) { |
| 307 | case PCI_CLASS_BRIDGE_PCI: |
| 308 | case PCI_CLASS_BRIDGE_PCMCIA: |
| 309 | case PCI_CLASS_BRIDGE_CARDBUS: |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 310 | printk(BIOS_DEBUG, "route irq bridge: %s\n", |
| 311 | dev_path(child)); |
| 312 | smp_write_intsrc_pci_bridge(mc, irqtype, |
| 313 | irqflag, child, dstapic, dstirq_x); |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Patrick Georgi | c5fc7db | 2012-03-07 15:55:47 +0100 | [diff] [blame] | 316 | next: |
Yinghai Lu | f327d9f | 2008-02-20 17:41:38 +0000 | [diff] [blame] | 317 | child = child->sibling; |
| 318 | } |
| 319 | |
| 320 | } |
| 321 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 322 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 323 | /* |
| 324 | * Type 4: Local Interrupt Assignment Entries: |
| 325 | * Entry Type, Int Type, Int Polarity, Int Level, |
| 326 | * Source Bus ID, Source Bus IRQ, Dest LAPIC ID, |
| 327 | * Dest LAPIC LINTIN# |
| 328 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 329 | void smp_write_lintsrc(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 330 | u8 irqtype, u16 irqflag, |
| 331 | u8 srcbusid, u8 srcbusirq, |
| 332 | u8 destapic, u8 destapiclint) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 333 | { |
| 334 | struct mpc_config_lintsrc *mpc; |
| 335 | mpc = smp_next_mpc_entry(mc); |
| 336 | memset(mpc, '\0', sizeof(*mpc)); |
| 337 | mpc->mpc_type = MP_LINTSRC; |
| 338 | mpc->mpc_irqtype = irqtype; |
| 339 | mpc->mpc_irqflag = irqflag; |
| 340 | mpc->mpc_srcbusid = srcbusid; |
| 341 | mpc->mpc_srcbusirq = srcbusirq; |
| 342 | mpc->mpc_destapic = destapic; |
| 343 | mpc->mpc_destapiclint = destapiclint; |
| 344 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 345 | } |
| 346 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 347 | /* |
| 348 | * Type 128: System Address Space Mapping Entries |
| 349 | * Entry Type, Entry Length, Bus ID, Address Type, |
| 350 | * Address Base Lo/Hi, Address Length Lo/Hi |
| 351 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 352 | void smp_write_address_space(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 353 | u8 busid, u8 address_type, |
| 354 | u32 address_base_low, u32 address_base_high, |
| 355 | u32 address_length_low, u32 address_length_high) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 356 | { |
| 357 | struct mp_exten_system_address_space *mpe; |
| 358 | mpe = smp_next_mpe_entry(mc); |
| 359 | memset(mpe, '\0', sizeof(*mpe)); |
| 360 | mpe->mpe_type = MPE_SYSTEM_ADDRESS_SPACE; |
| 361 | mpe->mpe_length = sizeof(*mpe); |
| 362 | mpe->mpe_busid = busid; |
| 363 | mpe->mpe_address_type = address_type; |
| 364 | mpe->mpe_address_base_low = address_base_low; |
| 365 | mpe->mpe_address_base_high = address_base_high; |
| 366 | mpe->mpe_address_length_low = address_length_low; |
| 367 | mpe->mpe_address_length_high = address_length_high; |
| 368 | smp_add_mpe_entry(mc, (mpe_t)mpe); |
| 369 | } |
| 370 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 371 | /* |
| 372 | * Type 129: Bus Hierarchy Descriptor Entry |
| 373 | * Entry Type, Entry Length, Bus ID, Bus Info, |
| 374 | * Parent Bus ID |
| 375 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 376 | void smp_write_bus_hierarchy(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 377 | u8 busid, u8 bus_info, u8 parent_busid) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 378 | { |
| 379 | struct mp_exten_bus_hierarchy *mpe; |
| 380 | mpe = smp_next_mpe_entry(mc); |
| 381 | memset(mpe, '\0', sizeof(*mpe)); |
| 382 | mpe->mpe_type = MPE_BUS_HIERARCHY; |
| 383 | mpe->mpe_length = sizeof(*mpe); |
| 384 | mpe->mpe_busid = busid; |
| 385 | mpe->mpe_bus_info = bus_info; |
| 386 | mpe->mpe_parent_busid = parent_busid; |
| 387 | smp_add_mpe_entry(mc, (mpe_t)mpe); |
| 388 | } |
| 389 | |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 390 | /* |
| 391 | * Type 130: Compatibility Bus Address Space Modifier Entry |
| 392 | * Entry Type, Entry Length, Bus ID, Address Modifier |
| 393 | * Predefined Range List |
| 394 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 395 | void smp_write_compatibility_address_space(struct mp_config_table *mc, |
Mike Loptien | bd4553b | 2014-06-16 10:46:56 -0600 | [diff] [blame] | 396 | u8 busid, u8 address_modifier, |
| 397 | u32 range_list) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 398 | { |
| 399 | struct mp_exten_compatibility_address_space *mpe; |
| 400 | mpe = smp_next_mpe_entry(mc); |
| 401 | memset(mpe, '\0', sizeof(*mpe)); |
| 402 | mpe->mpe_type = MPE_COMPATIBILITY_ADDRESS_SPACE; |
| 403 | mpe->mpe_length = sizeof(*mpe); |
| 404 | mpe->mpe_busid = busid; |
| 405 | mpe->mpe_address_modifier = address_modifier; |
| 406 | mpe->mpe_range_list = range_list; |
| 407 | smp_add_mpe_entry(mc, (mpe_t)mpe); |
| 408 | } |
| 409 | |
Patrick Georgi | 6eb7a53 | 2011-10-07 21:42:52 +0200 | [diff] [blame] | 410 | void mptable_lintsrc(struct mp_config_table *mc, unsigned long bus_isa) |
| 411 | { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 412 | smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE |
| 413 | | MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0); |
| 414 | smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE |
| 415 | | MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1); |
Patrick Georgi | 6eb7a53 | 2011-10-07 21:42:52 +0200 | [diff] [blame] | 416 | } |
| 417 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 418 | void mptable_add_isa_interrupts(struct mp_config_table *mc, |
| 419 | unsigned long bus_isa, unsigned long apicid, int external_int2) |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 420 | { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 421 | /*I/O Ints: Type Trigger Polarity |
| 422 | * Bus ID IRQ APIC ID PIN# */ |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 423 | smp_write_intsrc(mc, external_int2?mp_INT:mp_ExtINT, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 424 | MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 425 | bus_isa, 0x0, apicid, 0x0); |
| 426 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 427 | bus_isa, 0x1, apicid, 0x1); |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 428 | smp_write_intsrc(mc, external_int2?mp_ExtINT:mp_INT, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 429 | MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 430 | bus_isa, 0x0, apicid, 0x2); |
| 431 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 432 | bus_isa, 0x3, apicid, 0x3); |
| 433 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 434 | bus_isa, 0x4, apicid, 0x4); |
| 435 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 436 | bus_isa, 0x6, apicid, 0x6); |
| 437 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 438 | bus_isa, 0x7, apicid, 0x7); |
| 439 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 440 | bus_isa, 0x8, apicid, 0x8); |
| 441 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 442 | bus_isa, 0x9, apicid, 0x9); |
| 443 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 444 | bus_isa, 0xa, apicid, 0xa); |
| 445 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 446 | bus_isa, 0xb, apicid, 0xb); |
| 447 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 448 | bus_isa, 0xc, apicid, 0xc); |
| 449 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 450 | bus_isa, 0xd, apicid, 0xd); |
| 451 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 452 | bus_isa, 0xe, apicid, 0xe); |
| 453 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, |
| 454 | bus_isa, 0xf, apicid, 0xf); |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 455 | } |
Patrick Georgi | ab27266 | 2010-06-25 13:43:22 +0000 | [diff] [blame] | 456 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 457 | void mptable_write_buses(struct mp_config_table *mc, int *max_pci_bus, |
| 458 | int *isa_bus) |
| 459 | { |
Patrick Georgi | ab27266 | 2010-06-25 13:43:22 +0000 | [diff] [blame] | 460 | int dummy, i, highest; |
| 461 | char buses[256]; |
| 462 | struct device *dev; |
| 463 | |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 464 | if (!max_pci_bus) |
| 465 | max_pci_bus = &dummy; |
| 466 | if (!isa_bus) |
| 467 | isa_bus = &dummy; |
Patrick Georgi | ab27266 | 2010-06-25 13:43:22 +0000 | [diff] [blame] | 468 | |
| 469 | *max_pci_bus = 0; |
| 470 | highest = 0; |
| 471 | memset(buses, 0, sizeof(buses)); |
| 472 | |
| 473 | for (dev = all_devices; dev; dev = dev->next) { |
| 474 | struct bus *bus; |
| 475 | for (bus = dev->link_list; bus; bus = bus->next) { |
| 476 | if (bus->secondary > 255) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 477 | printk(BIOS_ERR, |
| 478 | "A bus claims to have a bus ID > 255?!? Aborting"); |
Patrick Georgi | ab27266 | 2010-06-25 13:43:22 +0000 | [diff] [blame] | 479 | return; |
| 480 | } |
| 481 | buses[bus->secondary] = 1; |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 482 | if (highest < bus->secondary) |
| 483 | highest = bus->secondary; |
Patrick Georgi | ab27266 | 2010-06-25 13:43:22 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 486 | for (i = 0; i <= highest; i++) { |
Patrick Georgi | ab27266 | 2010-06-25 13:43:22 +0000 | [diff] [blame] | 487 | if (buses[i]) { |
| 488 | smp_write_bus(mc, i, "PCI "); |
| 489 | *max_pci_bus = i; |
| 490 | } |
| 491 | } |
| 492 | *isa_bus = *max_pci_bus + 1; |
| 493 | smp_write_bus(mc, *isa_bus, "ISA "); |
| 494 | } |
| 495 | |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 496 | void *mptable_finalize(struct mp_config_table *mc) |
| 497 | { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 498 | mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), |
| 499 | mc->mpe_length); |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 500 | mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length); |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 501 | printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n", |
| 502 | mc, smp_next_mpe_entry(mc)); |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 503 | return smp_next_mpe_entry(mc); |
| 504 | } |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 505 | |
Lubomir Rintel | 294446a | 2018-04-14 11:48:27 +0200 | [diff] [blame] | 506 | static const struct device *find_next_ioapic(unsigned int last_ioapic_id) |
| 507 | { |
| 508 | const struct device *dev; |
| 509 | const struct device *result = NULL; |
| 510 | unsigned int ioapic_id = MAX_APICS; |
| 511 | |
| 512 | for (dev = all_devices; dev; dev = dev->next) { |
| 513 | if (dev->path.type == DEVICE_PATH_IOAPIC && |
| 514 | dev->path.ioapic.ioapic_id > last_ioapic_id && |
| 515 | dev->path.ioapic.ioapic_id <= ioapic_id) { |
| 516 | result = dev; |
| 517 | } |
| 518 | } |
| 519 | return result; |
| 520 | } |
| 521 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 522 | unsigned long __weak write_smp_table(unsigned long addr) |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 523 | { |
| 524 | struct drivers_generic_ioapic_config *ioapic_config; |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 525 | struct mp_config_table *mc; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 526 | int isa_bus, pin, parentpin; |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 527 | const struct device *dev; |
| 528 | const struct device *parent; |
| 529 | const struct device *oldparent; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 530 | void *tmp, *v; |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 531 | int isaioapic = -1, have_fixed_entries; |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 532 | const struct pci_irq_info *pci_irq_info; |
Lubomir Rintel | 294446a | 2018-04-14 11:48:27 +0200 | [diff] [blame] | 533 | unsigned int ioapic_id = 0; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 534 | |
| 535 | v = smp_write_floating_table(addr, 0); |
Edward O'Callaghan | 0bb0aff | 2014-05-02 03:58:32 +1000 | [diff] [blame] | 536 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 537 | |
Kyösti Mälkki | dea42e0 | 2021-05-31 20:26:16 +0300 | [diff] [blame^] | 538 | mptable_init(mc); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 539 | |
Alexandru Gagniuc | 0d5d70b | 2012-08-21 17:08:03 -0500 | [diff] [blame] | 540 | smp_write_processors(mc); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 541 | |
| 542 | mptable_write_buses(mc, NULL, &isa_bus); |
| 543 | |
Lubomir Rintel | 294446a | 2018-04-14 11:48:27 +0200 | [diff] [blame] | 544 | while ((dev = find_next_ioapic(ioapic_id))) { |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 545 | ioapic_config = dev->chip_info; |
| 546 | if (!ioapic_config) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 547 | printk(BIOS_ERR, "%s has no config, ignoring\n", |
| 548 | dev_path(dev)); |
Lubomir Rintel | 294446a | 2018-04-14 11:48:27 +0200 | [diff] [blame] | 549 | ioapic_id++; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 550 | continue; |
| 551 | } |
Lubomir Rintel | 294446a | 2018-04-14 11:48:27 +0200 | [diff] [blame] | 552 | |
| 553 | ioapic_id = dev->path.ioapic.ioapic_id; |
| 554 | smp_write_ioapic(mc, ioapic_id, |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 555 | ioapic_config->version, |
| 556 | ioapic_config->base); |
| 557 | |
| 558 | if (ioapic_config->have_isa_interrupts) { |
Alexandru Gagniuc | 0d5d70b | 2012-08-21 17:08:03 -0500 | [diff] [blame] | 559 | if (isaioapic >= 0) |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 560 | printk(BIOS_ERR, |
| 561 | "More than one IOAPIC with ISA interrupts?\n"); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 562 | else |
Alexandru Gagniuc | 0d5d70b | 2012-08-21 17:08:03 -0500 | [diff] [blame] | 563 | isaioapic = dev->path.ioapic.ioapic_id; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| 567 | if (isaioapic >= 0) { |
| 568 | /* Legacy Interrupts */ |
Alexandru Gagniuc | 0d5d70b | 2012-08-21 17:08:03 -0500 | [diff] [blame] | 569 | printk(BIOS_DEBUG, "Writing ISA IRQs\n"); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 570 | mptable_add_isa_interrupts(mc, isa_bus, isaioapic, 0); |
| 571 | } |
| 572 | |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 573 | for (dev = all_devices; dev; dev = dev->next) { |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 574 | |
Sven Schnelle | 64c40dd | 2012-08-20 11:17:52 +0200 | [diff] [blame] | 575 | if (dev->path.type != DEVICE_PATH_PCI || !dev->enabled) |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 576 | continue; |
| 577 | |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 578 | have_fixed_entries = 0; |
| 579 | for (pin = 0; pin < 4; pin++) { |
| 580 | if (dev->pci_irq_info[pin].ioapic_dst_id) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 581 | printk(BIOS_DEBUG, |
| 582 | "fixed IRQ entry for: %s: INT%c# -> IOAPIC %d PIN %d\n", |
| 583 | dev_path(dev), |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 584 | pin + 'A', |
| 585 | dev->pci_irq_info[pin].ioapic_dst_id, |
| 586 | dev->pci_irq_info[pin].ioapic_irq_pin); |
| 587 | smp_write_intsrc(mc, mp_INT, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 588 | dev->pci_irq_info[pin].ioapic_flags, |
| 589 | dev->bus->secondary, |
| 590 | ((dev->path.pci.devfn & 0xf8) >> 1) |
| 591 | | pin, |
| 592 | dev->pci_irq_info[pin].ioapic_dst_id, |
| 593 | dev->pci_irq_info[pin].ioapic_irq_pin); |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 594 | have_fixed_entries = 1; |
| 595 | } |
| 596 | } |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 597 | |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 598 | if (!have_fixed_entries) { |
| 599 | pin = (dev->path.pci.devfn & 7) % 4; |
| 600 | oldparent = parent = dev; |
Lee Leahy | 024b13d | 2017-03-16 13:41:11 -0700 | [diff] [blame] | 601 | while ((parent = parent->bus->dev)) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 602 | parentpin = (oldparent->path.pci.devfn >> 3) |
| 603 | + (oldparent->path.pci.devfn & 7); |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 604 | parentpin += dev->path.pci.devfn & 7; |
| 605 | parentpin += dev->path.pci.devfn >> 3; |
| 606 | parentpin %= 4; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 607 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 608 | pci_irq_info = &parent->pci_irq_info[parentpin]; |
| 609 | if (pci_irq_info->ioapic_dst_id) { |
| 610 | printk(BIOS_DEBUG, |
| 611 | "automatic IRQ entry for %s: INT%c# -> IOAPIC %d PIN %d\n", |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 612 | dev_path(dev), pin + 'A', |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 613 | pci_irq_info->ioapic_dst_id, |
| 614 | pci_irq_info->ioapic_irq_pin); |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 615 | smp_write_intsrc(mc, mp_INT, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 616 | pci_irq_info->ioapic_flags, |
| 617 | dev->bus->secondary, |
| 618 | ((dev->path.pci.devfn & 0xf8) |
| 619 | >> 1) | pin, |
| 620 | pci_irq_info->ioapic_dst_id, |
| 621 | pci_irq_info->ioapic_irq_pin); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 622 | |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 623 | break; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 624 | } |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 625 | |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 626 | if (parent->path.type == DEVICE_PATH_DOMAIN) { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 627 | printk(BIOS_WARNING, |
| 628 | "no IRQ found for %s\n", |
| 629 | dev_path(dev)); |
Sven Schnelle | 8c02790 | 2012-08-20 11:19:00 +0200 | [diff] [blame] | 630 | break; |
| 631 | } |
| 632 | oldparent = parent; |
| 633 | } |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
| 637 | mptable_lintsrc(mc, isa_bus); |
| 638 | tmp = mptable_finalize(mc); |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 639 | printk(BIOS_INFO, "MPTABLE len: %d\n", (unsigned int)((uintptr_t)tmp - |
| 640 | (uintptr_t)v)); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 641 | return (unsigned long)tmp; |
| 642 | } |