x86/apic: Implement single IPI for apic_noop
[linux-2.6-block.git] / arch / x86 / kernel / apic / ipi.c
CommitLineData
82023503
GC
1#include <linux/cpumask.h>
2#include <linux/interrupt.h>
82023503
GC
3
4#include <linux/mm.h>
5#include <linux/delay.h>
6#include <linux/spinlock.h>
7#include <linux/kernel_stat.h>
8#include <linux/mc146818rtc.h>
9#include <linux/cache.h>
82023503
GC
10#include <linux/cpu.h>
11#include <linux/module.h>
12
13#include <asm/smp.h>
14#include <asm/mtrr.h>
15#include <asm/tlbflush.h>
16#include <asm/mmu_context.h>
7b6aa335 17#include <asm/apic.h>
82023503 18#include <asm/proto.h>
43f39890 19#include <asm/ipi.h>
82023503 20
53be0fac
TG
21void default_send_IPI_single_phys(int cpu, int vector)
22{
23 unsigned long flags;
24
25 local_irq_save(flags);
26 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, cpu),
27 vector, APIC_DEST_PHYSICAL);
28 local_irq_restore(flags);
29}
30
c5e95482
YL
31void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector)
32{
33 unsigned long query_cpu;
34 unsigned long flags;
35
36 /*
37 * Hack. The clustered APIC addressing mode doesn't allow us to send
38 * to an arbitrary mask, so I do a unicast to each CPU instead.
39 * - mbligh
40 */
41 local_irq_save(flags);
42 for_each_cpu(query_cpu, mask) {
43 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
44 query_cpu), vector, APIC_DEST_PHYSICAL);
45 }
46 local_irq_restore(flags);
47}
48
49void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask,
50 int vector)
51{
52 unsigned int this_cpu = smp_processor_id();
53 unsigned int query_cpu;
54 unsigned long flags;
55
56 /* See Hack comment above */
57
58 local_irq_save(flags);
59 for_each_cpu(query_cpu, mask) {
60 if (query_cpu == this_cpu)
61 continue;
62 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
63 query_cpu), vector, APIC_DEST_PHYSICAL);
64 }
65 local_irq_restore(flags);
66}
67
1245e166
TH
68#ifdef CONFIG_X86_32
69
c5e95482
YL
70void default_send_IPI_mask_sequence_logical(const struct cpumask *mask,
71 int vector)
72{
73 unsigned long flags;
74 unsigned int query_cpu;
75
76 /*
77 * Hack. The clustered APIC addressing mode doesn't allow us to send
78 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
79 * should be modified to do 1 message per cluster ID - mbligh
80 */
81
82 local_irq_save(flags);
83 for_each_cpu(query_cpu, mask)
84 __default_send_IPI_dest_field(
6f802c4b
TH
85 early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
86 vector, apic->dest_logical);
c5e95482
YL
87 local_irq_restore(flags);
88}
89
90void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask,
91 int vector)
92{
93 unsigned long flags;
94 unsigned int query_cpu;
95 unsigned int this_cpu = smp_processor_id();
96
97 /* See Hack comment above */
98
99 local_irq_save(flags);
100 for_each_cpu(query_cpu, mask) {
101 if (query_cpu == this_cpu)
102 continue;
103 __default_send_IPI_dest_field(
6f802c4b
TH
104 early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
105 vector, apic->dest_logical);
c5e95482
YL
106 }
107 local_irq_restore(flags);
108}
109
c5e95482
YL
110/*
111 * This is only used on smaller machines.
112 */
113void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector)
114{
115 unsigned long mask = cpumask_bits(cpumask)[0];
116 unsigned long flags;
117
e3f0f36d 118 if (!mask)
83d349f3
LT
119 return;
120
c5e95482
YL
121 local_irq_save(flags);
122 WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
123 __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
124 local_irq_restore(flags);
125}
126
127void default_send_IPI_allbutself(int vector)
128{
129 /*
130 * if there are no other CPUs in the system then we get an APIC send
131 * error if we try to broadcast, thus avoid sending IPIs in this case.
132 */
133 if (!(num_online_cpus() > 1))
134 return;
135
136 __default_local_send_IPI_allbutself(vector);
137}
138
139void default_send_IPI_all(int vector)
140{
141 __default_local_send_IPI_all(vector);
142}
143
dac5f412 144void default_send_IPI_self(int vector)
82023503 145{
43f39890 146 __default_send_IPI_shortcut(APIC_DEST_SELF, vector, apic->dest_logical);
82023503
GC
147}
148
149/* must come after the send_IPI functions above for inlining */
82023503
GC
150static int convert_apicid_to_cpu(int apic_id)
151{
152 int i;
153
154 for_each_possible_cpu(i) {
155 if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
156 return i;
157 }
158 return -1;
159}
160
161int safe_smp_processor_id(void)
162{
163 int apicid, cpuid;
164
a1b4f1a5 165 if (!cpu_has_apic)
82023503
GC
166 return 0;
167
168 apicid = hard_smp_processor_id();
169 if (apicid == BAD_APICID)
170 return 0;
171
172 cpuid = convert_apicid_to_cpu(apicid);
173
174 return cpuid >= 0 ? cpuid : 0;
175}
176#endif