Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 2 | /* |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 3 | * APIC driver for "bigsmp" xAPIC machines with more than 8 virtual CPUs. |
| 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Drives the local APIC in "clustered mode". |
| 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/cpumask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/dmi.h> |
Yinghai Lu | 4696ca5 | 2008-07-11 18:43:10 -0700 | [diff] [blame] | 9 | #include <linux/smp.h> |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 10 | |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 11 | #include <asm/apic.h> |
Ingo Molnar | 13c0113 | 2020-08-06 14:34:32 +0200 | [diff] [blame] | 12 | #include <asm/io_apic.h> |
Thomas Gleixner | 8b542da | 2019-07-22 20:47:12 +0200 | [diff] [blame] | 13 | |
Thomas Gleixner | c94f071 | 2019-07-22 20:47:14 +0200 | [diff] [blame] | 14 | #include "local.h" |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 15 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 16 | static unsigned bigsmp_get_apic_id(unsigned long x) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 17 | { |
| 18 | return (x >> 24) & 0xFF; |
| 19 | } |
| 20 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 21 | static int bigsmp_apic_id_registered(void) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 22 | { |
| 23 | return 1; |
| 24 | } |
| 25 | |
Thomas Gleixner | 57e0aa4 | 2017-09-13 23:29:18 +0200 | [diff] [blame] | 26 | static bool bigsmp_check_apicid_used(physid_mask_t *map, int apicid) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 27 | { |
Thomas Gleixner | 57e0aa4 | 2017-09-13 23:29:18 +0200 | [diff] [blame] | 28 | return false; |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Tejun Heo | 12bf24a | 2011-01-23 14:37:35 +0100 | [diff] [blame] | 31 | static int bigsmp_early_logical_apicid(int cpu) |
| 32 | { |
| 33 | /* on bigsmp, logical apicid is the same as physical */ |
| 34 | return early_per_cpu(x86_cpu_to_apicid, cpu); |
| 35 | } |
| 36 | |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 37 | /* |
Bandan Das | bae3a8d | 2019-08-26 06:15:12 -0400 | [diff] [blame] | 38 | * bigsmp enables physical destination mode |
| 39 | * and doesn't use LDR and DFR |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 40 | */ |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 41 | static void bigsmp_init_apic_ldr(void) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 42 | { |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 45 | static void bigsmp_setup_apic_routing(void) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 46 | { |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 47 | printk(KERN_INFO |
| 48 | "Enabling APIC mode: Physflat. Using %d I/O APICs\n", |
| 49 | nr_ioapics); |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 52 | static int bigsmp_cpu_present_to_apicid(int mps_cpu) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 53 | { |
| 54 | if (mps_cpu < nr_cpu_ids) |
| 55 | return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu); |
| 56 | |
| 57 | return BAD_APICID; |
| 58 | } |
| 59 | |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 60 | static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 61 | { |
| 62 | /* For clustered we don't have a good way to do this yet - hack */ |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 63 | physids_promote(0xFFL, retmap); |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Thomas Gleixner | e11dada | 2009-08-31 15:18:40 +0200 | [diff] [blame] | 66 | static int bigsmp_check_phys_apicid_present(int phys_apicid) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 67 | { |
| 68 | return 1; |
| 69 | } |
| 70 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 71 | static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 72 | { |
| 73 | return cpuid_apic >> index_msb; |
| 74 | } |
| 75 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 76 | static void bigsmp_send_IPI_allbutself(int vector) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 77 | { |
Yinghai Lu | 43f3989 | 2009-01-29 19:31:49 -0800 | [diff] [blame] | 78 | default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector); |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Jiri Slaby | 9694cd6 | 2009-03-02 10:53:55 +0100 | [diff] [blame] | 81 | static void bigsmp_send_IPI_all(int vector) |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 82 | { |
Thomas Gleixner | 500bd02 | 2015-11-04 22:57:03 +0000 | [diff] [blame] | 83 | default_send_IPI_mask_sequence_phys(cpu_online_mask, vector); |
Ingo Molnar | 9f4187f | 2009-01-28 19:19:12 +0100 | [diff] [blame] | 84 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | static int dmi_bigsmp; /* can be set by dmi scanners */ |
| 87 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 88 | static int hp_ht_bigsmp(const struct dmi_system_id *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident); |
| 91 | dmi_bigsmp = 1; |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 97 | static const struct dmi_system_id bigsmp_dmi_table[] = { |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 98 | { hp_ht_bigsmp, "HP ProLiant DL760 G2", |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 99 | { DMI_MATCH(DMI_BIOS_VENDOR, "HP"), |
| 100 | DMI_MATCH(DMI_BIOS_VERSION, "P44-"), |
| 101 | } |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 102 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 104 | { hp_ht_bigsmp, "HP ProLiant DL740", |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 105 | { DMI_MATCH(DMI_BIOS_VENDOR, "HP"), |
| 106 | DMI_MATCH(DMI_BIOS_VERSION, "P47-"), |
| 107 | } |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 108 | }, |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 109 | { } /* NULL entry stops DMI scanning */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
William Lee Irwin III | af669c9 | 2007-05-23 13:58:23 -0700 | [diff] [blame] | 112 | static int probe_bigsmp(void) |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 113 | { |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 114 | if (def_to_bigsmp) |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 115 | dmi_bigsmp = 1; |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 116 | else |
| 117 | dmi_check_system(bigsmp_dmi_table); |
Ingo Molnar | 7731319 | 2009-02-17 14:09:20 +0100 | [diff] [blame] | 118 | |
Paolo Ciarrocchi | 637cba0 | 2008-02-20 00:18:52 +0100 | [diff] [blame] | 119 | return dmi_bigsmp; |
| 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Kees Cook | 404f6aa | 2016-08-08 16:29:06 -0700 | [diff] [blame] | 122 | static struct apic apic_bigsmp __ro_after_init = { |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 123 | |
| 124 | .name = "bigsmp", |
| 125 | .probe = probe_bigsmp, |
Ingo Molnar | 306db03 | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 126 | .acpi_madt_oem_check = NULL, |
Daniel J Blueman | fa63030 | 2012-03-14 15:17:34 +0800 | [diff] [blame] | 127 | .apic_id_valid = default_apic_id_valid, |
Ingo Molnar | 7ed248d | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 128 | .apic_id_registered = bigsmp_apic_id_registered, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 129 | |
Thomas Gleixner | 7216129 | 2020-10-24 22:35:05 +0100 | [diff] [blame] | 130 | .delivery_mode = APIC_DELIVERY_MODE_FIXED, |
Thomas Gleixner | 8c44963 | 2020-10-24 22:35:08 +0100 | [diff] [blame] | 131 | .dest_mode_logical = false, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 132 | |
Ingo Molnar | 08125d3 | 2009-01-28 05:08:44 +0100 | [diff] [blame] | 133 | .disable_esr = 1, |
Thomas Gleixner | e57d04e | 2020-10-24 22:35:07 +0100 | [diff] [blame] | 134 | |
Ingo Molnar | d1d7cae | 2009-01-28 05:41:42 +0100 | [diff] [blame] | 135 | .check_apicid_used = bigsmp_check_apicid_used, |
Ingo Molnar | a5c4329 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 136 | .init_apic_ldr = bigsmp_init_apic_ldr, |
Ingo Molnar | d190cb8 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 137 | .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map, |
Ingo Molnar | 72ce016 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 138 | .setup_apic_routing = bigsmp_setup_apic_routing, |
Ingo Molnar | a21769a4 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 139 | .cpu_present_to_apicid = bigsmp_cpu_present_to_apicid, |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 140 | .apicid_to_cpu_present = physid_set_mask_of_physid, |
Ingo Molnar | a27a621 | 2009-01-28 12:43:18 +0100 | [diff] [blame] | 141 | .check_phys_apicid_present = bigsmp_check_phys_apicid_present, |
Ingo Molnar | cb8cc44 | 2009-01-28 13:24:54 +0100 | [diff] [blame] | 142 | .phys_pkg_id = bigsmp_phys_pkg_id, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 143 | |
Ingo Molnar | ca6c8ed | 2009-01-28 14:08:38 +0100 | [diff] [blame] | 144 | .get_apic_id = bigsmp_get_apic_id, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 145 | .set_apic_id = NULL, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 146 | |
Thomas Gleixner | 9f9e3bb | 2017-09-13 23:29:37 +0200 | [diff] [blame] | 147 | .calc_dest_apicid = apic_default_calc_apicid, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 148 | |
Thomas Gleixner | 5789a12 | 2015-11-04 22:57:04 +0000 | [diff] [blame] | 149 | .send_IPI = default_send_IPI_single_phys, |
Thomas Gleixner | 500bd02 | 2015-11-04 22:57:03 +0000 | [diff] [blame] | 150 | .send_IPI_mask = default_send_IPI_mask_sequence_phys, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 151 | .send_IPI_mask_allbutself = NULL, |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 152 | .send_IPI_allbutself = bigsmp_send_IPI_allbutself, |
| 153 | .send_IPI_all = bigsmp_send_IPI_all, |
Ingo Molnar | 6b64ee0 | 2009-01-30 23:42:18 +0100 | [diff] [blame] | 154 | .send_IPI_self = default_send_IPI_self, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 155 | |
Ingo Molnar | 25dc004 | 2009-01-28 16:31:52 +0100 | [diff] [blame] | 156 | .inquire_remote_apic = default_inquire_remote_apic, |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 157 | |
| 158 | .read = native_apic_mem_read, |
| 159 | .write = native_apic_mem_write, |
Michael S. Tsirkin | 2a43195 | 2012-05-16 19:03:52 +0300 | [diff] [blame] | 160 | .eoi_write = native_apic_mem_write, |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 161 | .icr_read = native_apic_icr_read, |
| 162 | .icr_write = native_apic_icr_write, |
| 163 | .wait_icr_idle = native_apic_wait_icr_idle, |
| 164 | .safe_wait_icr_idle = native_safe_apic_wait_icr_idle, |
Tejun Heo | acb8bc0 | 2011-01-23 14:37:33 +0100 | [diff] [blame] | 165 | |
Tejun Heo | 12bf24a | 2011-01-23 14:37:35 +0100 | [diff] [blame] | 166 | .x86_32_early_logical_apicid = bigsmp_early_logical_apicid, |
Ingo Molnar | d26b6d6 | 2009-01-28 03:32:03 +0100 | [diff] [blame] | 167 | }; |
Suresh Siddha | 107e0e0 | 2011-05-20 17:51:17 -0700 | [diff] [blame] | 168 | |
Jan Beulich | 838312b | 2011-09-28 16:44:54 +0100 | [diff] [blame] | 169 | void __init generic_bigsmp_probe(void) |
Suresh Siddha | 69c252f | 2011-05-20 17:51:19 -0700 | [diff] [blame] | 170 | { |
Jan Beulich | 838312b | 2011-09-28 16:44:54 +0100 | [diff] [blame] | 171 | unsigned int cpu; |
Suresh Siddha | 69c252f | 2011-05-20 17:51:19 -0700 | [diff] [blame] | 172 | |
Jan Beulich | 838312b | 2011-09-28 16:44:54 +0100 | [diff] [blame] | 173 | if (!probe_bigsmp()) |
| 174 | return; |
| 175 | |
| 176 | apic = &apic_bigsmp; |
| 177 | |
| 178 | for_each_possible_cpu(cpu) { |
| 179 | if (early_per_cpu(x86_cpu_to_logical_apicid, |
| 180 | cpu) == BAD_APICID) |
| 181 | continue; |
| 182 | early_per_cpu(x86_cpu_to_logical_apicid, cpu) = |
| 183 | bigsmp_early_logical_apicid(cpu); |
| 184 | } |
| 185 | |
| 186 | pr_info("Overriding APIC driver with %s\n", apic_bigsmp.name); |
Suresh Siddha | 69c252f | 2011-05-20 17:51:19 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Suresh Siddha | 107e0e0 | 2011-05-20 17:51:17 -0700 | [diff] [blame] | 189 | apic_driver(apic_bigsmp); |