blob: aa79945445b5e86200644de9b4bea6aa6a4aa765 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_IPI_H
2#define _ASM_X86_IPI_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
Ingo Molnard53e2f22009-01-28 19:14:52 +01004#ifdef CONFIG_X86_LOCAL_APIC
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006/*
7 * Copyright 2004 James Cleverdon, IBM.
8 * Subject to the GNU Public License, v.2
9 *
10 * Generic APIC InterProcessor Interrupt code.
11 *
12 * Moved to include file by James Cleverdon from
13 * arch/x86-64/kernel/smp.c
14 *
15 * Copyrights from kernel/smp.c:
16 *
17 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
18 * (c) 1998-99, 2000 Ingo Molnar <mingo@redhat.com>
19 * (c) 2002,2003 Andi Kleen, SuSE Labs.
20 * Subject to the GNU Public License, v.2
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/hw_irq.h>
Jan Beulich00f1ea62007-05-02 19:27:04 +020024#include <asm/apic.h>
Paul Jacksone3f8ba82008-05-14 08:15:04 -070025#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
28 * the following functions deal with sending IPIs between CPUs.
29 *
30 * We use 'broadcast', CPU->CPU IPIs and self-IPIs too.
31 */
32
Joe Perches061b3d92008-03-23 01:02:27 -070033static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector,
34 unsigned int dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Jan Beulich1a426cb2005-09-12 18:49:24 +020036 unsigned int icr = shortcut | dest;
37
38 switch (vector) {
39 default:
40 icr |= APIC_DM_FIXED | vector;
41 break;
42 case NMI_VECTOR:
Jan Beulich1a426cb2005-09-12 18:49:24 +020043 icr |= APIC_DM_NMI;
44 break;
45 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 return icr;
47}
48
Joe Perches061b3d92008-03-23 01:02:27 -070049static inline int __prepare_ICR2(unsigned int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
51 return SET_APIC_DEST_FIELD(mask);
52}
53
Suresh Siddha1b374e42008-07-10 11:16:49 -070054static inline void __xapic_wait_icr_idle(void)
55{
56 while (native_apic_mem_read(APIC_ICR) & APIC_ICR_BUSY)
57 cpu_relax();
58}
59
Ingo Molnardac5f412009-01-28 15:42:24 +010060static inline void
Ingo Molnard53e2f22009-01-28 19:14:52 +010061__default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 /*
64 * Subtle. In the case of the 'never do double writes' workaround
65 * we have to lock out interrupts to be safe. As we don't care
66 * of the value read we use an atomic rmw access to avoid costly
67 * cli/sti. Otherwise we use an even cheaper single atomic write
68 * to the APIC.
69 */
70 unsigned int cfg;
71
72 /*
73 * Wait for idle.
74 */
Suresh Siddha1b374e42008-07-10 11:16:49 -070075 __xapic_wait_icr_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 /*
78 * No need to touch the target chip field
79 */
80 cfg = __prepare_ICR(shortcut, vector, dest);
81
82 /*
83 * Send the IPI. The write to APIC_ICR fires this off.
84 */
Suresh Siddha1b374e42008-07-10 11:16:49 -070085 native_apic_mem_write(APIC_ICR, cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +020088/*
89 * This is used to send an IPI with no shorthand notation (the destination is
90 * specified in bits 56 to 63 of the ICR).
91 */
Ingo Molnardac5f412009-01-28 15:42:24 +010092static inline void
93 __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int dest)
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +020094{
95 unsigned long cfg;
96
97 /*
98 * Wait for idle.
99 */
Fernando Luis [** ISO-8859-1 charset **] VázquezCao70ae77f2007-05-02 19:27:18 +0200100 if (unlikely(vector == NMI_VECTOR))
101 safe_apic_wait_icr_idle();
102 else
Suresh Siddha1b374e42008-07-10 11:16:49 -0700103 __xapic_wait_icr_idle();
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200104
105 /*
106 * prepare target chip field
107 */
108 cfg = __prepare_ICR2(mask);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700109 native_apic_mem_write(APIC_ICR2, cfg);
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200110
111 /*
112 * program the ICR
113 */
114 cfg = __prepare_ICR(0, vector, dest);
115
116 /*
117 * Send the IPI. The write to APIC_ICR fires this off.
118 */
Suresh Siddha1b374e42008-07-10 11:16:49 -0700119 native_apic_mem_write(APIC_ICR, cfg);
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200120}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Ingo Molnardac5f412009-01-28 15:42:24 +0100122static inline void
Yinghai Lu43f39892009-01-29 19:31:49 -0800123default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 unsigned long query_cpu;
Ingo Molnardac5f412009-01-28 15:42:24 +0100126 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /*
129 * Hack. The clustered APIC addressing mode doesn't allow us to send
130 * to an arbitrary mask, so I do a unicast to each CPU instead.
131 * - mbligh
132 */
133 local_irq_save(flags);
Mike Travisbcda0162008-12-16 17:33:59 -0800134 for_each_cpu(query_cpu, mask) {
Ingo Molnardac5f412009-01-28 15:42:24 +0100135 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
136 query_cpu), vector, APIC_DEST_PHYSICAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138 local_irq_restore(flags);
139}
140
Ingo Molnardac5f412009-01-28 15:42:24 +0100141static inline void
Yinghai Lu43f39892009-01-29 19:31:49 -0800142default_send_IPI_mask_allbutself_phys(const struct cpumask *mask, int vector)
Mike Travise7986732008-12-16 17:33:52 -0800143{
Mike Travise7986732008-12-16 17:33:52 -0800144 unsigned int this_cpu = smp_processor_id();
Ingo Molnardac5f412009-01-28 15:42:24 +0100145 unsigned int query_cpu;
146 unsigned long flags;
Mike Travise7986732008-12-16 17:33:52 -0800147
148 /* See Hack comment above */
149
150 local_irq_save(flags);
Ingo Molnardac5f412009-01-28 15:42:24 +0100151 for_each_cpu(query_cpu, mask) {
152 if (query_cpu == this_cpu)
153 continue;
154 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
155 query_cpu), vector, APIC_DEST_PHYSICAL);
156 }
Mike Travise7986732008-12-16 17:33:52 -0800157 local_irq_restore(flags);
158}
159
Yinghai Lu43f39892009-01-29 19:31:49 -0800160#include <asm/genapic.h>
161
162static inline void
163default_send_IPI_mask_sequence_logical(const struct cpumask *mask, int vector)
164{
165 unsigned long flags;
166 unsigned int query_cpu;
167
168 /*
169 * Hack. The clustered APIC addressing mode doesn't allow us to send
170 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
171 * should be modified to do 1 message per cluster ID - mbligh
172 */
173
174 local_irq_save(flags);
175 for_each_cpu(query_cpu, mask)
176 __default_send_IPI_dest_field(
177 apic->cpu_to_logical_apicid(query_cpu), vector,
178 apic->dest_logical);
179 local_irq_restore(flags);
180}
181
182static inline void
183default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, int vector)
184{
185 unsigned long flags;
186 unsigned int query_cpu;
187 unsigned int this_cpu = smp_processor_id();
188
189 /* See Hack comment above */
190
191 local_irq_save(flags);
192 for_each_cpu(query_cpu, mask) {
193 if (query_cpu == this_cpu)
194 continue;
195 __default_send_IPI_dest_field(
196 apic->cpu_to_logical_apicid(query_cpu), vector,
197 apic->dest_logical);
198 }
199 local_irq_restore(flags);
200}
Ingo Molnard53e2f22009-01-28 19:14:52 +0100201
202/* Avoid include hell */
203#define NMI_VECTOR 0x02
204
Ingo Molnard53e2f22009-01-28 19:14:52 +0100205extern int no_broadcast;
206
Yinghai Lu43f39892009-01-29 19:31:49 -0800207#ifndef CONFIG_X86_64
208/*
209 * This is only used on smaller machines.
210 */
211static inline void default_send_IPI_mask_bitmask_logical(const struct cpumask *cpumask, int vector)
Ingo Molnard53e2f22009-01-28 19:14:52 +0100212{
Yinghai Lu43f39892009-01-29 19:31:49 -0800213 unsigned long mask = cpumask_bits(cpumask)[0];
214 unsigned long flags;
215
216 local_irq_save(flags);
217 WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
218 __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
219 local_irq_restore(flags);
Ingo Molnard53e2f22009-01-28 19:14:52 +0100220}
Yinghai Lu43f39892009-01-29 19:31:49 -0800221
222static inline void default_send_IPI_mask_logical(const struct cpumask *mask, int vector)
223{
224 default_send_IPI_mask_bitmask_logical(mask, vector);
225}
Ingo Molnard53e2f22009-01-28 19:14:52 +0100226#endif
227
228static inline void __default_local_send_IPI_allbutself(int vector)
229{
230 if (no_broadcast || vector == NMI_VECTOR)
231 apic->send_IPI_mask_allbutself(cpu_online_mask, vector);
232 else
233 __default_send_IPI_shortcut(APIC_DEST_ALLBUT, vector, apic->dest_logical);
234}
235
236static inline void __default_local_send_IPI_all(int vector)
237{
238 if (no_broadcast || vector == NMI_VECTOR)
239 apic->send_IPI_mask(cpu_online_mask, vector);
240 else
241 __default_send_IPI_shortcut(APIC_DEST_ALLINC, vector, apic->dest_logical);
242}
243
244#ifdef CONFIG_X86_32
245static inline void default_send_IPI_allbutself(int vector)
246{
247 /*
248 * if there are no other CPUs in the system then we get an APIC send
249 * error if we try to broadcast, thus avoid sending IPIs in this case.
250 */
251 if (!(num_online_cpus() > 1))
252 return;
253
254 __default_local_send_IPI_allbutself(vector);
255}
256
257static inline void default_send_IPI_all(int vector)
258{
259 __default_local_send_IPI_all(vector);
260}
261#endif
262
263#endif
264
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700265#endif /* _ASM_X86_IPI_H */