Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef __LINUX_SMP_H |
2 | #define __LINUX_SMP_H | |
3 | ||
4 | /* | |
5 | * Generic SMP support | |
6 | * Alan Cox. <alan@redhat.com> | |
7 | */ | |
8 | ||
79974a0e | 9 | #include <linux/errno.h> |
54514a70 | 10 | #include <linux/types.h> |
3d442233 | 11 | #include <linux/list.h> |
3d442233 | 12 | #include <linux/cpumask.h> |
04948c7f | 13 | #include <linux/init.h> |
f21afc25 | 14 | #include <linux/irqflags.h> |
1da177e4 LT |
15 | |
16 | extern void cpu_idle(void); | |
17 | ||
3a5f65df | 18 | typedef void (*smp_call_func_t)(void *info); |
3d442233 JA |
19 | struct call_single_data { |
20 | struct list_head list; | |
3a5f65df | 21 | smp_call_func_t func; |
3d442233 | 22 | void *info; |
6fa3eb70 | 23 | cpumask_var_t cpumask; |
54514a70 | 24 | u16 flags; |
6fa3eb70 | 25 | u16 priv; |
3d442233 JA |
26 | }; |
27 | ||
e057d7ae MT |
28 | /* total number of cpus in this system (may exceed NR_CPUS) */ |
29 | extern unsigned int total_cpus; | |
30 | ||
3a5f65df DH |
31 | int smp_call_function_single(int cpuid, smp_call_func_t func, void *info, |
32 | int wait); | |
53ce3d95 | 33 | |
6fa3eb70 S |
34 | int mtk_smp_call_function_single(int cpuid, smp_call_func_t func, void *info, int wait); |
35 | ||
1da177e4 LT |
36 | #ifdef CONFIG_SMP |
37 | ||
38 | #include <linux/preempt.h> | |
39 | #include <linux/kernel.h> | |
40 | #include <linux/compiler.h> | |
41 | #include <linux/thread_info.h> | |
42 | #include <asm/smp.h> | |
1da177e4 LT |
43 | |
44 | /* | |
45 | * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc. | |
46 | * (defined in asm header): | |
d1dedb52 | 47 | */ |
1da177e4 LT |
48 | |
49 | /* | |
50 | * stops all CPUs but the current one: | |
51 | */ | |
52 | extern void smp_send_stop(void); | |
53 | ||
54 | /* | |
55 | * sends a 'reschedule' event to another CPU: | |
56 | */ | |
57 | extern void smp_send_reschedule(int cpu); | |
58 | ||
59 | ||
60 | /* | |
61 | * Prepare machine for booting other CPUs. | |
62 | */ | |
63 | extern void smp_prepare_cpus(unsigned int max_cpus); | |
64 | ||
65 | /* | |
66 | * Bring a CPU up | |
67 | */ | |
8239c25f | 68 | extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle); |
1da177e4 LT |
69 | |
70 | /* | |
71 | * Final polishing of CPUs | |
72 | */ | |
73 | extern void smp_cpus_done(unsigned int max_cpus); | |
74 | ||
75 | /* | |
76 | * Call a function on all other processors | |
77 | */ | |
3a5f65df | 78 | int smp_call_function(smp_call_func_t func, void *info, int wait); |
54b11e6d | 79 | void smp_call_function_many(const struct cpumask *mask, |
3a5f65df | 80 | smp_call_func_t func, void *info, bool wait); |
2d3854a3 | 81 | |
6e275637 PZ |
82 | void __smp_call_function_single(int cpuid, struct call_single_data *data, |
83 | int wait); | |
3d442233 | 84 | |
2ea6dec4 | 85 | int smp_call_function_any(const struct cpumask *mask, |
3a5f65df | 86 | smp_call_func_t func, void *info, int wait); |
2ea6dec4 | 87 | |
f37f435f TG |
88 | void kick_all_cpus_sync(void); |
89 | ||
3d442233 JA |
90 | /* |
91 | * Generic and arch helpers | |
92 | */ | |
93 | #ifdef CONFIG_USE_GENERIC_SMP_HELPERS | |
d8ad7d11 | 94 | void __init call_function_init(void); |
3d442233 | 95 | void generic_smp_call_function_single_interrupt(void); |
9a46ad6d SL |
96 | #define generic_smp_call_function_interrupt \ |
97 | generic_smp_call_function_single_interrupt | |
d8ad7d11 TI |
98 | #else |
99 | static inline void call_function_init(void) { } | |
3d442233 | 100 | #endif |
a3bc0dbc | 101 | |
1da177e4 LT |
102 | /* |
103 | * Call a function on all processors | |
104 | */ | |
3a5f65df | 105 | int on_each_cpu(smp_call_func_t func, void *info, int wait); |
1da177e4 | 106 | |
3fc498f1 GBY |
107 | /* |
108 | * Call a function on processors specified by mask, which might include | |
109 | * the local one. | |
110 | */ | |
111 | void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func, | |
112 | void *info, bool wait); | |
113 | ||
b3a7e98e GBY |
114 | /* |
115 | * Call a function on each processor for which the supplied function | |
116 | * cond_func returns a positive value. This may include the local | |
117 | * processor. | |
118 | */ | |
119 | void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), | |
120 | smp_call_func_t func, void *info, bool wait, | |
121 | gfp_t gfp_flags); | |
122 | ||
1da177e4 LT |
123 | /* |
124 | * Mark the boot cpu "online" so that it can call console drivers in | |
125 | * printk() and can access its per-cpu storage. | |
126 | */ | |
127 | void smp_prepare_boot_cpu(void); | |
128 | ||
ca74a6f8 | 129 | extern unsigned int setup_max_cpus; |
34db18a0 AW |
130 | extern void __init setup_nr_cpu_ids(void); |
131 | extern void __init smp_init(void); | |
ca74a6f8 | 132 | |
1da177e4 LT |
133 | #else /* !SMP */ |
134 | ||
d1dedb52 IM |
135 | static inline void smp_send_stop(void) { } |
136 | ||
1da177e4 LT |
137 | /* |
138 | * These macros fold the SMP functionality into a single CPU system | |
139 | */ | |
39c715b7 | 140 | #define raw_smp_processor_id() 0 |
3a5f65df | 141 | static inline int up_smp_call_function(smp_call_func_t func, void *info) |
3c30b06d CK |
142 | { |
143 | return 0; | |
144 | } | |
8691e5a8 | 145 | #define smp_call_function(func, info, wait) \ |
a5fbb6d1 | 146 | (up_smp_call_function(func, info)) |
f21afc25 DD |
147 | |
148 | static inline int on_each_cpu(smp_call_func_t func, void *info, int wait) | |
149 | { | |
150 | unsigned long flags; | |
151 | ||
152 | local_irq_save(flags); | |
153 | func(info); | |
154 | local_irq_restore(flags); | |
155 | return 0; | |
156 | } | |
157 | ||
3fc498f1 GBY |
158 | /* |
159 | * Note we still need to test the mask even for UP | |
160 | * because we actually can get an empty mask from | |
161 | * code that on SMP might call us without the local | |
162 | * CPU in the mask. | |
163 | */ | |
164 | #define on_each_cpu_mask(mask, func, info, wait) \ | |
165 | do { \ | |
166 | if (cpumask_test_cpu(0, (mask))) { \ | |
167 | local_irq_disable(); \ | |
168 | (func)(info); \ | |
169 | local_irq_enable(); \ | |
170 | } \ | |
171 | } while (0) | |
b3a7e98e GBY |
172 | /* |
173 | * Preemption is disabled here to make sure the cond_func is called under the | |
174 | * same condtions in UP and SMP. | |
175 | */ | |
176 | #define on_each_cpu_cond(cond_func, func, info, wait, gfp_flags)\ | |
177 | do { \ | |
178 | void *__info = (info); \ | |
179 | preempt_disable(); \ | |
180 | if ((cond_func)(0, __info)) { \ | |
181 | local_irq_disable(); \ | |
182 | (func)(__info); \ | |
183 | local_irq_enable(); \ | |
184 | } \ | |
185 | preempt_enable(); \ | |
186 | } while (0) | |
3fc498f1 | 187 | |
79a88102 | 188 | static inline void smp_send_reschedule(int cpu) { } |
2ac6608c | 189 | #define smp_prepare_boot_cpu() do {} while (0) |
d2ff9118 RR |
190 | #define smp_call_function_many(mask, func, info, wait) \ |
191 | (up_smp_call_function(func, info)) | |
d8ad7d11 | 192 | static inline void call_function_init(void) { } |
2ea6dec4 RR |
193 | |
194 | static inline int | |
3a5f65df | 195 | smp_call_function_any(const struct cpumask *mask, smp_call_func_t func, |
2ea6dec4 | 196 | void *info, int wait) |
3d442233 | 197 | { |
2ea6dec4 | 198 | return smp_call_function_single(0, func, info, wait); |
3d442233 | 199 | } |
2ea6dec4 | 200 | |
f37f435f TG |
201 | static inline void kick_all_cpus_sync(void) { } |
202 | ||
1da177e4 LT |
203 | #endif /* !SMP */ |
204 | ||
205 | /* | |
39c715b7 | 206 | * smp_processor_id(): get the current CPU ID. |
1da177e4 | 207 | * |
cfd8d6c0 | 208 | * if DEBUG_PREEMPT is enabled then we check whether it is |
39c715b7 IM |
209 | * used in a preemption-safe way. (smp_processor_id() is safe |
210 | * if it's used in a preemption-off critical section, or in | |
211 | * a thread that is bound to the current CPU.) | |
1da177e4 | 212 | * |
39c715b7 IM |
213 | * NOTE: raw_smp_processor_id() is for internal use only |
214 | * (smp_processor_id() is the preferred variant), but in rare | |
215 | * instances it might also be used to turn off false positives | |
216 | * (i.e. smp_processor_id() use that the debugging code reports but | |
217 | * which use for some reason is legal). Don't use this to hack around | |
218 | * the warning message, as your code might not work under PREEMPT. | |
1da177e4 | 219 | */ |
39c715b7 IM |
220 | #ifdef CONFIG_DEBUG_PREEMPT |
221 | extern unsigned int debug_smp_processor_id(void); | |
222 | # define smp_processor_id() debug_smp_processor_id() | |
1da177e4 | 223 | #else |
39c715b7 | 224 | # define smp_processor_id() raw_smp_processor_id() |
1da177e4 LT |
225 | #endif |
226 | ||
227 | #define get_cpu() ({ preempt_disable(); smp_processor_id(); }) | |
228 | #define put_cpu() preempt_enable() | |
1da177e4 | 229 | |
a146649b IM |
230 | /* |
231 | * Callback to arch code if there's nosmp or maxcpus=0 on the | |
232 | * boot command line: | |
233 | */ | |
234 | extern void arch_disable_smp_support(void); | |
235 | ||
033ab7f8 AM |
236 | void smp_setup_processor_id(void); |
237 | ||
1da177e4 | 238 | #endif /* __LINUX_SMP_H */ |