]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/x86/kernel/apic/apic_flat_64.c
x86/apic: Remove dest argument from __default_send_IPI_shortcut()
[linux.git] / arch / x86 / kernel / apic / apic_flat_64.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2004 James Cleverdon, IBM.
4  *
5  * Flat APIC subarch code.
6  *
7  * Hacked for x86-64 by James Cleverdon from i386 architecture code by
8  * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
9  * James Cleverdon.
10  */
11 #include <linux/cpumask.h>
12 #include <linux/export.h>
13 #include <linux/acpi.h>
14
15 #include <asm/jailhouse_para.h>
16 #include <asm/apic.h>
17
18 #include "local.h"
19
20 static struct apic apic_physflat;
21 static struct apic apic_flat;
22
23 struct apic *apic __ro_after_init = &apic_flat;
24 EXPORT_SYMBOL_GPL(apic);
25
26 static int flat_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
27 {
28         return 1;
29 }
30
31 /*
32  * Set up the logical destination ID.
33  *
34  * Intel recommends to set DFR, LDR and TPR before enabling
35  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
36  * document number 292116).  So here it goes...
37  */
38 void flat_init_apic_ldr(void)
39 {
40         unsigned long val;
41         unsigned long num, id;
42
43         num = smp_processor_id();
44         id = 1UL << num;
45         apic_write(APIC_DFR, APIC_DFR_FLAT);
46         val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
47         val |= SET_APIC_LOGICAL_ID(id);
48         apic_write(APIC_LDR, val);
49 }
50
51 static void _flat_send_IPI_mask(unsigned long mask, int vector)
52 {
53         unsigned long flags;
54
55         local_irq_save(flags);
56         __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
57         local_irq_restore(flags);
58 }
59
60 static void flat_send_IPI_mask(const struct cpumask *cpumask, int vector)
61 {
62         unsigned long mask = cpumask_bits(cpumask)[0];
63
64         _flat_send_IPI_mask(mask, vector);
65 }
66
67 static void
68 flat_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector)
69 {
70         unsigned long mask = cpumask_bits(cpumask)[0];
71         int cpu = smp_processor_id();
72
73         if (cpu < BITS_PER_LONG)
74                 __clear_bit(cpu, &mask);
75
76         _flat_send_IPI_mask(mask, vector);
77 }
78
79 static void flat_send_IPI_allbutself(int vector)
80 {
81         int cpu = smp_processor_id();
82
83         if (IS_ENABLED(CONFIG_HOTPLUG_CPU) || vector == NMI_VECTOR) {
84                 if (!cpumask_equal(cpu_online_mask, cpumask_of(cpu))) {
85                         unsigned long mask = cpumask_bits(cpu_online_mask)[0];
86
87                         if (cpu < BITS_PER_LONG)
88                                 __clear_bit(cpu, &mask);
89
90                         _flat_send_IPI_mask(mask, vector);
91                 }
92         } else if (num_online_cpus() > 1) {
93                 __default_send_IPI_shortcut(APIC_DEST_ALLBUT, vector);
94         }
95 }
96
97 static void flat_send_IPI_all(int vector)
98 {
99         if (vector == NMI_VECTOR) {
100                 flat_send_IPI_mask(cpu_online_mask, vector);
101         } else {
102                 __default_send_IPI_shortcut(APIC_DEST_ALLINC, vector);
103         }
104 }
105
106 static unsigned int flat_get_apic_id(unsigned long x)
107 {
108         return (x >> 24) & 0xFF;
109 }
110
111 static u32 set_apic_id(unsigned int id)
112 {
113         return (id & 0xFF) << 24;
114 }
115
116 static unsigned int read_xapic_id(void)
117 {
118         return flat_get_apic_id(apic_read(APIC_ID));
119 }
120
121 static int flat_apic_id_registered(void)
122 {
123         return physid_isset(read_xapic_id(), phys_cpu_present_map);
124 }
125
126 static int flat_phys_pkg_id(int initial_apic_id, int index_msb)
127 {
128         return initial_apic_id >> index_msb;
129 }
130
131 static int flat_probe(void)
132 {
133         return 1;
134 }
135
136 static struct apic apic_flat __ro_after_init = {
137         .name                           = "flat",
138         .probe                          = flat_probe,
139         .acpi_madt_oem_check            = flat_acpi_madt_oem_check,
140         .apic_id_valid                  = default_apic_id_valid,
141         .apic_id_registered             = flat_apic_id_registered,
142
143         .irq_delivery_mode              = dest_Fixed,
144         .irq_dest_mode                  = 1, /* logical */
145
146         .disable_esr                    = 0,
147         .dest_logical                   = APIC_DEST_LOGICAL,
148         .check_apicid_used              = NULL,
149
150         .init_apic_ldr                  = flat_init_apic_ldr,
151
152         .ioapic_phys_id_map             = NULL,
153         .setup_apic_routing             = NULL,
154         .cpu_present_to_apicid          = default_cpu_present_to_apicid,
155         .apicid_to_cpu_present          = NULL,
156         .check_phys_apicid_present      = default_check_phys_apicid_present,
157         .phys_pkg_id                    = flat_phys_pkg_id,
158
159         .get_apic_id                    = flat_get_apic_id,
160         .set_apic_id                    = set_apic_id,
161
162         .calc_dest_apicid               = apic_flat_calc_apicid,
163
164         .send_IPI                       = default_send_IPI_single,
165         .send_IPI_mask                  = flat_send_IPI_mask,
166         .send_IPI_mask_allbutself       = flat_send_IPI_mask_allbutself,
167         .send_IPI_allbutself            = flat_send_IPI_allbutself,
168         .send_IPI_all                   = flat_send_IPI_all,
169         .send_IPI_self                  = apic_send_IPI_self,
170
171         .inquire_remote_apic            = default_inquire_remote_apic,
172
173         .read                           = native_apic_mem_read,
174         .write                          = native_apic_mem_write,
175         .eoi_write                      = native_apic_mem_write,
176         .icr_read                       = native_apic_icr_read,
177         .icr_write                      = native_apic_icr_write,
178         .wait_icr_idle                  = native_apic_wait_icr_idle,
179         .safe_wait_icr_idle             = native_safe_apic_wait_icr_idle,
180 };
181
182 /*
183  * Physflat mode is used when there are more than 8 CPUs on a system.
184  * We cannot use logical delivery in this case because the mask
185  * overflows, so use physical mode.
186  */
187 static int physflat_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
188 {
189 #ifdef CONFIG_ACPI
190         /*
191          * Quirk: some x86_64 machines can only use physical APIC mode
192          * regardless of how many processors are present (x86_64 ES7000
193          * is an example).
194          */
195         if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
196                 (acpi_gbl_FADT.flags & ACPI_FADT_APIC_PHYSICAL)) {
197                 printk(KERN_DEBUG "system APIC only can use physical flat");
198                 return 1;
199         }
200
201         if (!strncmp(oem_id, "IBM", 3) && !strncmp(oem_table_id, "EXA", 3)) {
202                 printk(KERN_DEBUG "IBM Summit detected, will use apic physical");
203                 return 1;
204         }
205 #endif
206
207         return 0;
208 }
209
210 static void physflat_init_apic_ldr(void)
211 {
212         /*
213          * LDR and DFR are not involved in physflat mode, rather:
214          * "In physical destination mode, the destination processor is
215          * specified by its local APIC ID [...]." (Intel SDM, 10.6.2.1)
216          */
217 }
218
219 static void physflat_send_IPI_allbutself(int vector)
220 {
221         default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
222 }
223
224 static void physflat_send_IPI_all(int vector)
225 {
226         default_send_IPI_mask_sequence_phys(cpu_online_mask, vector);
227 }
228
229 static int physflat_probe(void)
230 {
231         if (apic == &apic_physflat || num_possible_cpus() > 8 ||
232             jailhouse_paravirt())
233                 return 1;
234
235         return 0;
236 }
237
238 static struct apic apic_physflat __ro_after_init = {
239
240         .name                           = "physical flat",
241         .probe                          = physflat_probe,
242         .acpi_madt_oem_check            = physflat_acpi_madt_oem_check,
243         .apic_id_valid                  = default_apic_id_valid,
244         .apic_id_registered             = flat_apic_id_registered,
245
246         .irq_delivery_mode              = dest_Fixed,
247         .irq_dest_mode                  = 0, /* physical */
248
249         .disable_esr                    = 0,
250         .dest_logical                   = 0,
251         .check_apicid_used              = NULL,
252
253         .init_apic_ldr                  = physflat_init_apic_ldr,
254
255         .ioapic_phys_id_map             = NULL,
256         .setup_apic_routing             = NULL,
257         .cpu_present_to_apicid          = default_cpu_present_to_apicid,
258         .apicid_to_cpu_present          = NULL,
259         .check_phys_apicid_present      = default_check_phys_apicid_present,
260         .phys_pkg_id                    = flat_phys_pkg_id,
261
262         .get_apic_id                    = flat_get_apic_id,
263         .set_apic_id                    = set_apic_id,
264
265         .calc_dest_apicid               = apic_default_calc_apicid,
266
267         .send_IPI                       = default_send_IPI_single_phys,
268         .send_IPI_mask                  = default_send_IPI_mask_sequence_phys,
269         .send_IPI_mask_allbutself       = default_send_IPI_mask_allbutself_phys,
270         .send_IPI_allbutself            = physflat_send_IPI_allbutself,
271         .send_IPI_all                   = physflat_send_IPI_all,
272         .send_IPI_self                  = apic_send_IPI_self,
273
274         .inquire_remote_apic            = default_inquire_remote_apic,
275
276         .read                           = native_apic_mem_read,
277         .write                          = native_apic_mem_write,
278         .eoi_write                      = native_apic_mem_write,
279         .icr_read                       = native_apic_icr_read,
280         .icr_write                      = native_apic_icr_write,
281         .wait_icr_idle                  = native_apic_wait_icr_idle,
282         .safe_wait_icr_idle             = native_safe_apic_wait_icr_idle,
283 };
284
285 /*
286  * We need to check for physflat first, so this order is important.
287  */
288 apic_drivers(apic_physflat, apic_flat);