Merge tag 'mailbox-v5.11' of git://git.linaro.org/landing-teams/working/fujitsu/integ...
[linux-2.6-microblaze.git] / include / linux / smp.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_SMP_H
3 #define __LINUX_SMP_H
4
5 /*
6  *      Generic SMP support
7  *              Alan Cox. <alan@redhat.com>
8  */
9
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/list.h>
13 #include <linux/cpumask.h>
14 #include <linux/init.h>
15 #include <linux/smp_types.h>
16
17 typedef void (*smp_call_func_t)(void *info);
18 typedef bool (*smp_cond_func_t)(int cpu, void *info);
19
20 /*
21  * structure shares (partial) layout with struct irq_work
22  */
23 struct __call_single_data {
24         struct __call_single_node node;
25         smp_call_func_t func;
26         void *info;
27 };
28
29 #define CSD_INIT(_func, _info) \
30         (struct __call_single_data){ .func = (_func), .info = (_info), }
31
32 /* Use __aligned() to avoid to use 2 cache lines for 1 csd */
33 typedef struct __call_single_data call_single_data_t
34         __aligned(sizeof(struct __call_single_data));
35
36 #define INIT_CSD(_csd, _func, _info)            \
37 do {                                            \
38         *(_csd) = CSD_INIT((_func), (_info));   \
39 } while (0)
40
41 /*
42  * Enqueue a llist_node on the call_single_queue; be very careful, read
43  * flush_smp_call_function_queue() in detail.
44  */
45 extern void __smp_call_single_queue(int cpu, struct llist_node *node);
46
47 /* total number of cpus in this system (may exceed NR_CPUS) */
48 extern unsigned int total_cpus;
49
50 int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
51                              int wait);
52
53 /*
54  * Call a function on all processors
55  */
56 void on_each_cpu(smp_call_func_t func, void *info, int wait);
57
58 /*
59  * Call a function on processors specified by mask, which might include
60  * the local one.
61  */
62 void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
63                 void *info, bool wait);
64
65 /*
66  * Call a function on each processor for which the supplied function
67  * cond_func returns a positive value. This may include the local
68  * processor.
69  */
70 void on_each_cpu_cond(smp_cond_func_t cond_func, smp_call_func_t func,
71                       void *info, bool wait);
72
73 void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func,
74                            void *info, bool wait, const struct cpumask *mask);
75
76 int smp_call_function_single_async(int cpu, call_single_data_t *csd);
77
78 #ifdef CONFIG_SMP
79
80 #include <linux/preempt.h>
81 #include <linux/kernel.h>
82 #include <linux/compiler.h>
83 #include <linux/thread_info.h>
84 #include <asm/smp.h>
85
86 /*
87  * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
88  * (defined in asm header):
89  */
90
91 /*
92  * stops all CPUs but the current one:
93  */
94 extern void smp_send_stop(void);
95
96 /*
97  * sends a 'reschedule' event to another CPU:
98  */
99 extern void smp_send_reschedule(int cpu);
100
101
102 /*
103  * Prepare machine for booting other CPUs.
104  */
105 extern void smp_prepare_cpus(unsigned int max_cpus);
106
107 /*
108  * Bring a CPU up
109  */
110 extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
111
112 /*
113  * Final polishing of CPUs
114  */
115 extern void smp_cpus_done(unsigned int max_cpus);
116
117 /*
118  * Call a function on all other processors
119  */
120 void smp_call_function(smp_call_func_t func, void *info, int wait);
121 void smp_call_function_many(const struct cpumask *mask,
122                             smp_call_func_t func, void *info, bool wait);
123
124 int smp_call_function_any(const struct cpumask *mask,
125                           smp_call_func_t func, void *info, int wait);
126
127 void kick_all_cpus_sync(void);
128 void wake_up_all_idle_cpus(void);
129
130 /*
131  * Generic and arch helpers
132  */
133 void __init call_function_init(void);
134 void generic_smp_call_function_single_interrupt(void);
135 #define generic_smp_call_function_interrupt \
136         generic_smp_call_function_single_interrupt
137
138 /*
139  * Mark the boot cpu "online" so that it can call console drivers in
140  * printk() and can access its per-cpu storage.
141  */
142 void smp_prepare_boot_cpu(void);
143
144 extern unsigned int setup_max_cpus;
145 extern void __init setup_nr_cpu_ids(void);
146 extern void __init smp_init(void);
147
148 extern int __boot_cpu_id;
149
150 static inline int get_boot_cpu_id(void)
151 {
152         return __boot_cpu_id;
153 }
154
155 #else /* !SMP */
156
157 static inline void smp_send_stop(void) { }
158
159 /*
160  *      These macros fold the SMP functionality into a single CPU system
161  */
162 #define raw_smp_processor_id()                  0
163 static inline void up_smp_call_function(smp_call_func_t func, void *info)
164 {
165 }
166 #define smp_call_function(func, info, wait) \
167                         (up_smp_call_function(func, info))
168
169 static inline void smp_send_reschedule(int cpu) { }
170 #define smp_prepare_boot_cpu()                  do {} while (0)
171 #define smp_call_function_many(mask, func, info, wait) \
172                         (up_smp_call_function(func, info))
173 static inline void call_function_init(void) { }
174
175 static inline int
176 smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
177                       void *info, int wait)
178 {
179         return smp_call_function_single(0, func, info, wait);
180 }
181
182 static inline void kick_all_cpus_sync(void) {  }
183 static inline void wake_up_all_idle_cpus(void) {  }
184
185 #ifdef CONFIG_UP_LATE_INIT
186 extern void __init up_late_init(void);
187 static inline void smp_init(void) { up_late_init(); }
188 #else
189 static inline void smp_init(void) { }
190 #endif
191
192 static inline int get_boot_cpu_id(void)
193 {
194         return 0;
195 }
196
197 #endif /* !SMP */
198
199 /**
200  * raw_processor_id() - get the current (unstable) CPU id
201  *
202  * For then you know what you are doing and need an unstable
203  * CPU id.
204  */
205
206 /**
207  * smp_processor_id() - get the current (stable) CPU id
208  *
209  * This is the normal accessor to the CPU id and should be used
210  * whenever possible.
211  *
212  * The CPU id is stable when:
213  *
214  *  - IRQs are disabled;
215  *  - preemption is disabled;
216  *  - the task is CPU affine.
217  *
218  * When CONFIG_DEBUG_PREEMPT; we verify these assumption and WARN
219  * when smp_processor_id() is used when the CPU id is not stable.
220  */
221
222 /*
223  * Allow the architecture to differentiate between a stable and unstable read.
224  * For example, x86 uses an IRQ-safe asm-volatile read for the unstable but a
225  * regular asm read for the stable.
226  */
227 #ifndef __smp_processor_id
228 #define __smp_processor_id(x) raw_smp_processor_id(x)
229 #endif
230
231 #ifdef CONFIG_DEBUG_PREEMPT
232   extern unsigned int debug_smp_processor_id(void);
233 # define smp_processor_id() debug_smp_processor_id()
234 #else
235 # define smp_processor_id() __smp_processor_id()
236 #endif
237
238 #define get_cpu()               ({ preempt_disable(); __smp_processor_id(); })
239 #define put_cpu()               preempt_enable()
240
241 /*
242  * Callback to arch code if there's nosmp or maxcpus=0 on the
243  * boot command line:
244  */
245 extern void arch_disable_smp_support(void);
246
247 extern void arch_thaw_secondary_cpus_begin(void);
248 extern void arch_thaw_secondary_cpus_end(void);
249
250 void smp_setup_processor_id(void);
251
252 int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
253                     bool phys);
254
255 /* SMP core functions */
256 int smpcfd_prepare_cpu(unsigned int cpu);
257 int smpcfd_dead_cpu(unsigned int cpu);
258 int smpcfd_dying_cpu(unsigned int cpu);
259
260 #endif /* __LINUX_SMP_H */