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