aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorGlauber Costa <gcosta@redhat.com>2008-03-03 12:12:53 -0500
committerIngo Molnar <mingo@elte.hu>2008-04-17 11:40:56 -0400
commit8202350367ac11d571f6dd4c21c2027a4d235276 (patch)
tree2af8ec46d8191638c43b13ca16a8df2545db5064 /arch/x86
parentf9e47a126be2eaabf04a1a5c71ca7b23a473d0d8 (diff)
x86: create ipi.c
This patch moves all ipi and apic related functions from smp_32.c to ipi.c Signed-off-by: Glauber Costa <gcosta@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kernel/Makefile2
-rw-r--r--arch/x86/kernel/ipi.c178
-rw-r--r--arch/x86/kernel/smp_32.c153
3 files changed, 179 insertions, 154 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 0a4b088bab5..e3b01f96c56 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -47,7 +47,7 @@ obj-$(CONFIG_PCI) += early-quirks.o
47apm-y := apm_32.o 47apm-y := apm_32.o
48obj-$(CONFIG_APM) += apm.o 48obj-$(CONFIG_APM) += apm.o
49obj-$(CONFIG_X86_SMP) += smp_$(BITS).o smpboot_$(BITS).o smp.o 49obj-$(CONFIG_X86_SMP) += smp_$(BITS).o smpboot_$(BITS).o smp.o
50obj-$(CONFIG_X86_SMP) += smpboot.o tsc_sync.o 50obj-$(CONFIG_X86_SMP) += smpboot.o tsc_sync.o ipi.o
51obj-$(CONFIG_X86_32_SMP) += smpcommon.o 51obj-$(CONFIG_X86_32_SMP) += smpcommon.o
52obj-$(CONFIG_X86_64_SMP) += smp_64.o smpboot_64.o tsc_sync.o smpcommon.o 52obj-$(CONFIG_X86_64_SMP) += smp_64.o smpboot_64.o tsc_sync.o smpcommon.o
53obj-$(CONFIG_X86_TRAMPOLINE) += trampoline_$(BITS).o 53obj-$(CONFIG_X86_TRAMPOLINE) += trampoline_$(BITS).o
diff --git a/arch/x86/kernel/ipi.c b/arch/x86/kernel/ipi.c
new file mode 100644
index 00000000000..c0df7b89ca2
--- /dev/null
+++ b/arch/x86/kernel/ipi.c
@@ -0,0 +1,178 @@
1#include <linux/cpumask.h>
2#include <linux/interrupt.h>
3#include <linux/init.h>
4
5#include <linux/mm.h>
6#include <linux/delay.h>
7#include <linux/spinlock.h>
8#include <linux/kernel_stat.h>
9#include <linux/mc146818rtc.h>
10#include <linux/cache.h>
11#include <linux/interrupt.h>
12#include <linux/cpu.h>
13#include <linux/module.h>
14
15#include <asm/smp.h>
16#include <asm/mtrr.h>
17#include <asm/tlbflush.h>
18#include <asm/mmu_context.h>
19#include <asm/apic.h>
20#include <asm/proto.h>
21
22#ifdef CONFIG_X86_32
23#include <mach_apic.h>
24/*
25 * the following functions deal with sending IPIs between CPUs.
26 *
27 * We use 'broadcast', CPU->CPU IPIs and self-IPIs too.
28 */
29
30static inline int __prepare_ICR(unsigned int shortcut, int vector)
31{
32 unsigned int icr = shortcut | APIC_DEST_LOGICAL;
33
34 switch (vector) {
35 default:
36 icr |= APIC_DM_FIXED | vector;
37 break;
38 case NMI_VECTOR:
39 icr |= APIC_DM_NMI;
40 break;
41 }
42 return icr;
43}
44
45static inline int __prepare_ICR2(unsigned int mask)
46{
47 return SET_APIC_DEST_FIELD(mask);
48}
49
50void __send_IPI_shortcut(unsigned int shortcut, int vector)
51{
52 /*
53 * Subtle. In the case of the 'never do double writes' workaround
54 * we have to lock out interrupts to be safe. As we don't care
55 * of the value read we use an atomic rmw access to avoid costly
56 * cli/sti. Otherwise we use an even cheaper single atomic write
57 * to the APIC.
58 */
59 unsigned int cfg;
60
61 /*
62 * Wait for idle.
63 */
64 apic_wait_icr_idle();
65
66 /*
67 * No need to touch the target chip field
68 */
69 cfg = __prepare_ICR(shortcut, vector);
70
71 /*
72 * Send the IPI. The write to APIC_ICR fires this off.
73 */
74 apic_write_around(APIC_ICR, cfg);
75}
76
77void send_IPI_self(int vector)
78{
79 __send_IPI_shortcut(APIC_DEST_SELF, vector);
80}
81
82/*
83 * This is used to send an IPI with no shorthand notation (the destination is
84 * specified in bits 56 to 63 of the ICR).
85 */
86static inline void __send_IPI_dest_field(unsigned long mask, int vector)
87{
88 unsigned long cfg;
89
90 /*
91 * Wait for idle.
92 */
93 if (unlikely(vector == NMI_VECTOR))
94 safe_apic_wait_icr_idle();
95 else
96 apic_wait_icr_idle();
97
98 /*
99 * prepare target chip field
100 */
101 cfg = __prepare_ICR2(mask);
102 apic_write_around(APIC_ICR2, cfg);
103
104 /*
105 * program the ICR
106 */
107 cfg = __prepare_ICR(0, vector);
108
109 /*
110 * Send the IPI. The write to APIC_ICR fires this off.
111 */
112 apic_write_around(APIC_ICR, cfg);
113}
114
115/*
116 * This is only used on smaller machines.
117 */
118void send_IPI_mask_bitmask(cpumask_t cpumask, int vector)
119{
120 unsigned long mask = cpus_addr(cpumask)[0];
121 unsigned long flags;
122
123 local_irq_save(flags);
124 WARN_ON(mask & ~cpus_addr(cpu_online_map)[0]);
125 __send_IPI_dest_field(mask, vector);
126 local_irq_restore(flags);
127}
128
129void send_IPI_mask_sequence(cpumask_t mask, int vector)
130{
131 unsigned long flags;
132 unsigned int query_cpu;
133
134 /*
135 * Hack. The clustered APIC addressing mode doesn't allow us to send
136 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
137 * should be modified to do 1 message per cluster ID - mbligh
138 */
139
140 local_irq_save(flags);
141 for_each_possible_cpu(query_cpu) {
142 if (cpu_isset(query_cpu, mask)) {
143 __send_IPI_dest_field(cpu_to_logical_apicid(query_cpu),
144 vector);
145 }
146 }
147 local_irq_restore(flags);
148}
149
150/* must come after the send_IPI functions above for inlining */
151#include <mach_ipi.h>
152static int convert_apicid_to_cpu(int apic_id)
153{
154 int i;
155
156 for_each_possible_cpu(i) {
157 if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
158 return i;
159 }
160 return -1;
161}
162
163int safe_smp_processor_id(void)
164{
165 int apicid, cpuid;
166
167 if (!boot_cpu_has(X86_FEATURE_APIC))
168 return 0;
169
170 apicid = hard_smp_processor_id();
171 if (apicid == BAD_APICID)
172 return 0;
173
174 cpuid = convert_apicid_to_cpu(apicid);
175
176 return cpuid >= 0 ? cpuid : 0;
177}
178#endif
diff --git a/arch/x86/kernel/smp_32.c b/arch/x86/kernel/smp_32.c
index 61e546e8573..d80623aba9c 100644
--- a/arch/x86/kernel/smp_32.c
+++ b/arch/x86/kernel/smp_32.c
@@ -107,132 +107,6 @@
107 107
108DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate) ____cacheline_aligned = { &init_mm, 0, }; 108DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate) ____cacheline_aligned = { &init_mm, 0, };
109 109
110/*
111 * the following functions deal with sending IPIs between CPUs.
112 *
113 * We use 'broadcast', CPU->CPU IPIs and self-IPIs too.
114 */
115
116static inline int __prepare_ICR (unsigned int shortcut, int vector)
117{
118 unsigned int icr = shortcut | APIC_DEST_LOGICAL;
119
120 switch (vector) {
121 default:
122 icr |= APIC_DM_FIXED | vector;
123 break;
124 case NMI_VECTOR:
125 icr |= APIC_DM_NMI;
126 break;
127 }
128 return icr;
129}
130
131static inline int __prepare_ICR2 (unsigned int mask)
132{
133 return SET_APIC_DEST_FIELD(mask);
134}
135
136void __send_IPI_shortcut(unsigned int shortcut, int vector)
137{
138 /*
139 * Subtle. In the case of the 'never do double writes' workaround
140 * we have to lock out interrupts to be safe. As we don't care
141 * of the value read we use an atomic rmw access to avoid costly
142 * cli/sti. Otherwise we use an even cheaper single atomic write
143 * to the APIC.
144 */
145 unsigned int cfg;
146
147 /*
148 * Wait for idle.
149 */
150 apic_wait_icr_idle();
151
152 /*
153 * No need to touch the target chip field
154 */
155 cfg = __prepare_ICR(shortcut, vector);
156
157 /*
158 * Send the IPI. The write to APIC_ICR fires this off.
159 */
160 apic_write_around(APIC_ICR, cfg);
161}
162
163void send_IPI_self(int vector)
164{
165 __send_IPI_shortcut(APIC_DEST_SELF, vector);
166}
167
168/*
169 * This is used to send an IPI with no shorthand notation (the destination is
170 * specified in bits 56 to 63 of the ICR).
171 */
172static inline void __send_IPI_dest_field(unsigned long mask, int vector)
173{
174 unsigned long cfg;
175
176 /*
177 * Wait for idle.
178 */
179 if (unlikely(vector == NMI_VECTOR))
180 safe_apic_wait_icr_idle();
181 else
182 apic_wait_icr_idle();
183
184 /*
185 * prepare target chip field
186 */
187 cfg = __prepare_ICR2(mask);
188 apic_write_around(APIC_ICR2, cfg);
189
190 /*
191 * program the ICR
192 */
193 cfg = __prepare_ICR(0, vector);
194
195 /*
196 * Send the IPI. The write to APIC_ICR fires this off.
197 */
198 apic_write_around(APIC_ICR, cfg);
199}
200
201/*
202 * This is only used on smaller machines.
203 */
204void send_IPI_mask_bitmask(cpumask_t cpumask, int vector)
205{
206 unsigned long mask = cpus_addr(cpumask)[0];
207 unsigned long flags;
208
209 local_irq_save(flags);
210 WARN_ON(mask & ~cpus_addr(cpu_online_map)[0]);
211 __send_IPI_dest_field(mask, vector);
212 local_irq_restore(flags);
213}
214
215void send_IPI_mask_sequence(cpumask_t mask, int vector)
216{
217 unsigned long flags;
218 unsigned int query_cpu;
219
220 /*
221 * Hack. The clustered APIC addressing mode doesn't allow us to send
222 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
223 * should be modified to do 1 message per cluster ID - mbligh
224 */
225
226 local_irq_save(flags);
227 for_each_possible_cpu(query_cpu) {
228 if (cpu_isset(query_cpu, mask)) {
229 __send_IPI_dest_field(cpu_to_logical_apicid(query_cpu),
230 vector);
231 }
232 }
233 local_irq_restore(flags);
234}
235
236#include <mach_ipi.h> /* must come after the send_IPI functions above for inlining */ 110#include <mach_ipi.h> /* must come after the send_IPI functions above for inlining */
237 111
238/* 112/*
@@ -465,30 +339,3 @@ void flush_tlb_all(void)
465{ 339{
466 on_each_cpu(do_flush_tlb_all, NULL, 1, 1); 340 on_each_cpu(do_flush_tlb_all, NULL, 1, 1);
467} 341}
468
469static int convert_apicid_to_cpu(int apic_id)
470{
471 int i;
472
473 for_each_possible_cpu(i) {
474 if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
475 return i;
476 }
477 return -1;
478}
479
480int safe_smp_processor_id(void)
481{
482 int apicid, cpuid;
483
484 if (!boot_cpu_has(X86_FEATURE_APIC))
485 return 0;
486
487 apicid = hard_smp_processor_id();
488 if (apicid == BAD_APICID)
489 return 0;
490
491 cpuid = convert_apicid_to_cpu(apicid);
492
493 return cpuid >= 0 ? cpuid : 0;
494}