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