drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / smp.h
1 #ifndef __LINUX_SMP_H
2 #define __LINUX_SMP_H
3
4 /*
5 * Generic SMP support
6 * Alan Cox. <alan@redhat.com>
7 */
8
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>
15
16 extern void cpu_idle(void);
17
18 typedef void (*smp_call_func_t)(void *info);
19 struct call_single_data {
20 struct list_head list;
21 smp_call_func_t func;
22 void *info;
23 cpumask_var_t cpumask;
24 u16 flags;
25 u16 priv;
26 };
27
28 /* total number of cpus in this system (may exceed NR_CPUS) */
29 extern unsigned int total_cpus;
30
31 int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
32 int wait);
33
34 int mtk_smp_call_function_single(int cpuid, smp_call_func_t func, void *info, int wait);
35
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>
43
44 /*
45 * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
46 * (defined in asm header):
47 */
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 */
68 extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
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 */
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);
81
82 void __smp_call_function_single(int cpuid, struct call_single_data *data,
83 int wait);
84
85 int smp_call_function_any(const struct cpumask *mask,
86 smp_call_func_t func, void *info, int wait);
87
88 void kick_all_cpus_sync(void);
89
90 /*
91 * Generic and arch helpers
92 */
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
98 #else
99 static inline void call_function_init(void) { }
100 #endif
101
102 /*
103 * Call a function on all processors
104 */
105 int on_each_cpu(smp_call_func_t func, void *info, int wait);
106
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
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
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
129 extern unsigned int setup_max_cpus;
130 extern void __init setup_nr_cpu_ids(void);
131 extern void __init smp_init(void);
132
133 #else /* !SMP */
134
135 static inline void smp_send_stop(void) { }
136
137 /*
138 * These macros fold the SMP functionality into a single CPU system
139 */
140 #define raw_smp_processor_id() 0
141 static inline int up_smp_call_function(smp_call_func_t func, void *info)
142 {
143 return 0;
144 }
145 #define smp_call_function(func, info, wait) \
146 (up_smp_call_function(func, info))
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
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)
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)
187
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) { }
193
194 static inline int
195 smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
196 void *info, int wait)
197 {
198 return smp_call_function_single(0, func, info, wait);
199 }
200
201 static inline void kick_all_cpus_sync(void) { }
202
203 #endif /* !SMP */
204
205 /*
206 * smp_processor_id(): get the current CPU ID.
207 *
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.)
212 *
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.
219 */
220 #ifdef CONFIG_DEBUG_PREEMPT
221 extern unsigned int debug_smp_processor_id(void);
222 # define smp_processor_id() debug_smp_processor_id()
223 #else
224 # define smp_processor_id() raw_smp_processor_id()
225 #endif
226
227 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
228 #define put_cpu() preempt_enable()
229
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
236 void smp_setup_processor_id(void);
237
238 #endif /* __LINUX_SMP_H */