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