6 * Alan Cox. <alan@redhat.com>
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/list.h>
12 #include <linux/cpumask.h>
13 #include <linux/init.h>
14 #include <linux/irqflags.h>
16 extern void cpu_idle(void);
18 typedef void (*smp_call_func_t
)(void *info
);
19 struct call_single_data
{
20 struct list_head list
;
23 cpumask_var_t cpumask
;
28 /* total number of cpus in this system (may exceed NR_CPUS) */
29 extern unsigned int total_cpus
;
31 int smp_call_function_single(int cpuid
, smp_call_func_t func
, void *info
,
34 int mtk_smp_call_function_single(int cpuid
, smp_call_func_t func
, void *info
, int wait
);
38 #include <linux/preempt.h>
39 #include <linux/kernel.h>
40 #include <linux/compiler.h>
41 #include <linux/thread_info.h>
45 * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
46 * (defined in asm header):
50 * stops all CPUs but the current one:
52 extern void smp_send_stop(void);
55 * sends a 'reschedule' event to another CPU:
57 extern void smp_send_reschedule(int cpu
);
61 * Prepare machine for booting other CPUs.
63 extern void smp_prepare_cpus(unsigned int max_cpus
);
68 extern int __cpu_up(unsigned int cpunum
, struct task_struct
*tidle
);
71 * Final polishing of CPUs
73 extern void smp_cpus_done(unsigned int max_cpus
);
76 * Call a function on all other processors
78 int smp_call_function(smp_call_func_t func
, void *info
, int wait
);
79 void smp_call_function_many(const struct cpumask
*mask
,
80 smp_call_func_t func
, void *info
, bool wait
);
82 void __smp_call_function_single(int cpuid
, struct call_single_data
*data
,
85 int smp_call_function_any(const struct cpumask
*mask
,
86 smp_call_func_t func
, void *info
, int wait
);
88 void kick_all_cpus_sync(void);
91 * Generic and arch helpers
93 #ifdef CONFIG_USE_GENERIC_SMP_HELPERS
94 void __init
call_function_init(void);
95 void generic_smp_call_function_single_interrupt(void);
96 #define generic_smp_call_function_interrupt \
97 generic_smp_call_function_single_interrupt
99 static inline void call_function_init(void) { }
103 * Call a function on all processors
105 int on_each_cpu(smp_call_func_t func
, void *info
, int wait
);
108 * Call a function on processors specified by mask, which might include
111 void on_each_cpu_mask(const struct cpumask
*mask
, smp_call_func_t func
,
112 void *info
, bool wait
);
115 * Call a function on each processor for which the supplied function
116 * cond_func returns a positive value. This may include the local
119 void on_each_cpu_cond(bool (*cond_func
)(int cpu
, void *info
),
120 smp_call_func_t func
, void *info
, bool wait
,
124 * Mark the boot cpu "online" so that it can call console drivers in
125 * printk() and can access its per-cpu storage.
127 void smp_prepare_boot_cpu(void);
129 extern unsigned int setup_max_cpus
;
130 extern void __init
setup_nr_cpu_ids(void);
131 extern void __init
smp_init(void);
135 static inline void smp_send_stop(void) { }
138 * These macros fold the SMP functionality into a single CPU system
140 #define raw_smp_processor_id() 0
141 static inline int up_smp_call_function(smp_call_func_t func
, void *info
)
145 #define smp_call_function(func, info, wait) \
146 (up_smp_call_function(func, info))
148 static inline int on_each_cpu(smp_call_func_t func
, void *info
, int wait
)
152 local_irq_save(flags
);
154 local_irq_restore(flags
);
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
164 #define on_each_cpu_mask(mask, func, info, wait) \
166 if (cpumask_test_cpu(0, (mask))) { \
167 local_irq_disable(); \
169 local_irq_enable(); \
173 * Preemption is disabled here to make sure the cond_func is called under the
174 * same condtions in UP and SMP.
176 #define on_each_cpu_cond(cond_func, func, info, wait, gfp_flags)\
178 void *__info = (info); \
180 if ((cond_func)(0, __info)) { \
181 local_irq_disable(); \
183 local_irq_enable(); \
188 static inline void smp_send_reschedule(int cpu
) { }
189 #define smp_prepare_boot_cpu() do {} while (0)
190 #define smp_call_function_many(mask, func, info, wait) \
191 (up_smp_call_function(func, info))
192 static inline void call_function_init(void) { }
195 smp_call_function_any(const struct cpumask
*mask
, smp_call_func_t func
,
196 void *info
, int wait
)
198 return smp_call_function_single(0, func
, info
, wait
);
201 static inline void kick_all_cpus_sync(void) { }
206 * smp_processor_id(): get the current CPU ID.
208 * if DEBUG_PREEMPT is enabled then we check whether it is
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.)
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.
220 #ifdef CONFIG_DEBUG_PREEMPT
221 extern unsigned int debug_smp_processor_id(void);
222 # define smp_processor_id() debug_smp_processor_id()
224 # define smp_processor_id() raw_smp_processor_id()
227 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
228 #define put_cpu() preempt_enable()
231 * Callback to arch code if there's nosmp or maxcpus=0 on the
234 extern void arch_disable_smp_support(void);
236 void smp_setup_processor_id(void);
238 #endif /* __LINUX_SMP_H */