OSDN Git Service

Merge 72078891843ce0d5b8e95040d09ba92913916af9 on remote branch
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / cpu.h
1 /*
2  * include/linux/cpu.h - generic cpu definition
3  *
4  * This is mainly for topological representation. We define the 
5  * basic 'struct cpu' here, which can be embedded in per-arch 
6  * definitions of processors.
7  *
8  * Basic handling of the devices is done in drivers/base/cpu.c
9  *
10  * CPUs are exported via sysfs in the devices/system/cpu
11  * directory. 
12  */
13 #ifndef _LINUX_CPU_H_
14 #define _LINUX_CPU_H_
15
16 #include <linux/node.h>
17 #include <linux/compiler.h>
18 #include <linux/cpumask.h>
19
20 struct device;
21 struct device_node;
22 struct attribute_group;
23
24 struct cpu {
25         int node_id;            /* The node which contains the CPU */
26         int hotpluggable;       /* creates sysfs control file if hotpluggable */
27         struct device dev;
28 };
29
30 struct cpu_pstate_pwr {
31         unsigned int freq;
32         uint32_t power;
33 };
34
35 struct cpu_pwr_stats {
36         int cpu;
37         long temp;
38         struct cpu_pstate_pwr *ptable;
39         bool throttling;
40         int len;
41 };
42
43 extern int register_cpu(struct cpu *cpu, int num);
44 extern struct device *get_cpu_device(unsigned cpu);
45 extern bool cpu_is_hotpluggable(unsigned cpu);
46 extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
47 extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
48                                               int cpu, unsigned int *thread);
49
50 extern int cpu_add_dev_attr(struct device_attribute *attr);
51 extern void cpu_remove_dev_attr(struct device_attribute *attr);
52
53 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
54 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
55
56 extern ssize_t cpu_show_meltdown(struct device *dev,
57                                  struct device_attribute *attr, char *buf);
58 extern ssize_t cpu_show_spectre_v1(struct device *dev,
59                                    struct device_attribute *attr, char *buf);
60 extern ssize_t cpu_show_spectre_v2(struct device *dev,
61                                    struct device_attribute *attr, char *buf);
62 extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
63                                           struct device_attribute *attr, char *buf);
64 extern ssize_t cpu_show_l1tf(struct device *dev,
65                              struct device_attribute *attr, char *buf);
66 extern ssize_t cpu_show_mds(struct device *dev,
67                             struct device_attribute *attr, char *buf);
68 extern ssize_t cpu_show_tsx_async_abort(struct device *dev,
69                                         struct device_attribute *attr,
70                                         char *buf);
71 extern ssize_t cpu_show_itlb_multihit(struct device *dev,
72                                       struct device_attribute *attr, char *buf);
73
74 extern __printf(4, 5)
75 struct device *cpu_device_create(struct device *parent, void *drvdata,
76                                  const struct attribute_group **groups,
77                                  const char *fmt, ...);
78 #ifdef CONFIG_HOTPLUG_CPU
79 extern void unregister_cpu(struct cpu *cpu);
80 extern ssize_t arch_cpu_probe(const char *, size_t);
81 extern ssize_t arch_cpu_release(const char *, size_t);
82 #endif
83 struct notifier_block;
84
85 /*
86  * CPU notifier priorities.
87  */
88 enum {
89         /*
90          * SCHED_ACTIVE marks a cpu which is coming up active during
91          * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
92          * notifier.  CPUSET_ACTIVE adjusts cpuset according to
93          * cpu_active mask right after SCHED_ACTIVE.  During
94          * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
95          * ordered in the similar way.
96          *
97          * This ordering guarantees consistent cpu_active mask and
98          * migration behavior to all cpu notifiers.
99          */
100         CPU_PRI_SCHED_ACTIVE    = INT_MAX,
101         CPU_PRI_CPUSET_ACTIVE   = INT_MAX - 1,
102         CPU_PRI_SCHED_INACTIVE  = INT_MIN + 1,
103         CPU_PRI_CPUSET_INACTIVE = INT_MIN,
104
105         /* migration should happen before other stuff but after perf */
106         CPU_PRI_PERF            = 20,
107         CPU_PRI_MIGRATION       = 10,
108         CPU_PRI_SMPBOOT         = 9,
109         /* bring up workqueues before normal notifiers and down after */
110         CPU_PRI_WORKQUEUE_UP    = 5,
111         CPU_PRI_WORKQUEUE_DOWN  = -5,
112 };
113
114 #define CPU_ONLINE              0x0002 /* CPU (unsigned)v is up */
115 #define CPU_UP_PREPARE          0x0003 /* CPU (unsigned)v coming up */
116 #define CPU_UP_CANCELED         0x0004 /* CPU (unsigned)v NOT coming up */
117 #define CPU_DOWN_PREPARE        0x0005 /* CPU (unsigned)v going down */
118 #define CPU_DOWN_FAILED         0x0006 /* CPU (unsigned)v NOT going down */
119 #define CPU_DEAD                0x0007 /* CPU (unsigned)v dead */
120 #define CPU_DYING               0x0008 /* CPU (unsigned)v not running any task,
121                                         * not handling interrupts, soon dead.
122                                         * Called on the dying cpu, interrupts
123                                         * are already disabled. Must not
124                                         * sleep, must not fail */
125 #define CPU_POST_DEAD           0x0009 /* CPU (unsigned)v dead, cpu_hotplug
126                                         * lock is dropped */
127 #define CPU_STARTING            0x000A /* CPU (unsigned)v soon running.
128                                         * Called on the new cpu, just before
129                                         * enabling interrupts. Must not sleep,
130                                         * must not fail */
131 #define CPU_DYING_IDLE          0x000B /* CPU (unsigned)v dying, reached
132                                         * idle loop. */
133 #define CPU_BROKEN              0x000C /* CPU (unsigned)v did not die properly,
134                                         * perhaps due to preemption. */
135
136 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
137  * operation in progress
138  */
139 #define CPU_TASKS_FROZEN        0x0010
140
141 #define CPU_ONLINE_FROZEN       (CPU_ONLINE | CPU_TASKS_FROZEN)
142 #define CPU_UP_PREPARE_FROZEN   (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
143 #define CPU_UP_CANCELED_FROZEN  (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
144 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
145 #define CPU_DOWN_FAILED_FROZEN  (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
146 #define CPU_DEAD_FROZEN         (CPU_DEAD | CPU_TASKS_FROZEN)
147 #define CPU_DYING_FROZEN        (CPU_DYING | CPU_TASKS_FROZEN)
148 #define CPU_STARTING_FROZEN     (CPU_STARTING | CPU_TASKS_FROZEN)
149
150
151 #ifdef CONFIG_SMP
152 /* Need to know about CPUs going up/down? */
153 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
154 #define cpu_notifier(fn, pri) {                                 \
155         static struct notifier_block fn##_nb =                  \
156                 { .notifier_call = fn, .priority = pri };       \
157         register_cpu_notifier(&fn##_nb);                        \
158 }
159
160 #define __cpu_notifier(fn, pri) {                               \
161         static struct notifier_block fn##_nb =                  \
162                 { .notifier_call = fn, .priority = pri };       \
163         __register_cpu_notifier(&fn##_nb);                      \
164 }
165
166 extern int register_cpu_notifier(struct notifier_block *nb);
167 extern int __register_cpu_notifier(struct notifier_block *nb);
168 extern void unregister_cpu_notifier(struct notifier_block *nb);
169 extern void __unregister_cpu_notifier(struct notifier_block *nb);
170
171 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
172 #define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
173 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
174
175 static inline int register_cpu_notifier(struct notifier_block *nb)
176 {
177         return 0;
178 }
179
180 static inline int __register_cpu_notifier(struct notifier_block *nb)
181 {
182         return 0;
183 }
184
185 static inline void unregister_cpu_notifier(struct notifier_block *nb)
186 {
187 }
188
189 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
190 {
191 }
192 #endif
193
194 void smpboot_thread_init(void);
195 int cpu_up(unsigned int cpu);
196 void notify_cpu_starting(unsigned int cpu);
197 extern void cpu_maps_update_begin(void);
198 extern void cpu_maps_update_done(void);
199
200 #define cpu_notifier_register_begin     cpu_maps_update_begin
201 #define cpu_notifier_register_done      cpu_maps_update_done
202
203 #else   /* CONFIG_SMP */
204
205 #define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
206 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
207
208 static inline int register_cpu_notifier(struct notifier_block *nb)
209 {
210         return 0;
211 }
212
213 static inline int __register_cpu_notifier(struct notifier_block *nb)
214 {
215         return 0;
216 }
217
218 static inline void unregister_cpu_notifier(struct notifier_block *nb)
219 {
220 }
221
222 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
223 {
224 }
225
226 static inline void cpu_maps_update_begin(void)
227 {
228 }
229
230 static inline void cpu_maps_update_done(void)
231 {
232 }
233
234 static inline void cpu_notifier_register_begin(void)
235 {
236 }
237
238 static inline void cpu_notifier_register_done(void)
239 {
240 }
241
242 static inline void smpboot_thread_init(void)
243 {
244 }
245
246 #endif /* CONFIG_SMP */
247 extern struct bus_type cpu_subsys;
248
249 #ifdef CONFIG_HOTPLUG_CPU
250 /* Stop CPUs going up and down. */
251
252 extern void cpu_hotplug_begin(void);
253 extern void cpu_hotplug_done(void);
254 extern void get_online_cpus(void);
255 extern void cpu_hotplug_mutex_held(void);
256 extern void put_online_cpus(void);
257 extern void cpu_hotplug_disable(void);
258 extern void cpu_hotplug_enable(void);
259 #define hotcpu_notifier(fn, pri)        cpu_notifier(fn, pri)
260 #define __hotcpu_notifier(fn, pri)      __cpu_notifier(fn, pri)
261 #define register_hotcpu_notifier(nb)    register_cpu_notifier(nb)
262 #define __register_hotcpu_notifier(nb)  __register_cpu_notifier(nb)
263 #define unregister_hotcpu_notifier(nb)  unregister_cpu_notifier(nb)
264 #define __unregister_hotcpu_notifier(nb)        __unregister_cpu_notifier(nb)
265 void clear_tasks_mm_cpumask(int cpu);
266 int cpu_down(unsigned int cpu);
267
268 #else           /* CONFIG_HOTPLUG_CPU */
269
270 static inline void cpu_hotplug_begin(void) {}
271 static inline void cpu_hotplug_done(void) {}
272 #define get_online_cpus()       do { } while (0)
273 #define put_online_cpus()       do { } while (0)
274 #define cpu_hotplug_disable()   do { } while (0)
275 #define cpu_hotplug_enable()    do { } while (0)
276 #define hotcpu_notifier(fn, pri)        do { (void)(fn); } while (0)
277 #define __hotcpu_notifier(fn, pri)      do { (void)(fn); } while (0)
278 #define cpu_hotplug_mutex_held()        do { } while (0)
279 /* These aren't inline functions due to a GCC bug. */
280 #define register_hotcpu_notifier(nb)    ({ (void)(nb); 0; })
281 #define __register_hotcpu_notifier(nb)  ({ (void)(nb); 0; })
282 #define unregister_hotcpu_notifier(nb)  ({ (void)(nb); })
283 #define __unregister_hotcpu_notifier(nb)        ({ (void)(nb); })
284 #endif          /* CONFIG_HOTPLUG_CPU */
285
286 #ifdef CONFIG_PM_SLEEP_SMP
287 extern int disable_nonboot_cpus(void);
288 extern void enable_nonboot_cpus(void);
289 #else /* !CONFIG_PM_SLEEP_SMP */
290 static inline int disable_nonboot_cpus(void) { return 0; }
291 static inline void enable_nonboot_cpus(void) {}
292 #endif /* !CONFIG_PM_SLEEP_SMP */
293
294 struct cpu_pwr_stats *get_cpu_pwr_stats(void);
295 void trigger_cpu_pwr_stats_calc(void);
296
297 enum cpuhp_state {
298         CPUHP_OFFLINE,
299         CPUHP_ONLINE,
300 };
301
302 void cpu_startup_entry(enum cpuhp_state state);
303
304 void cpu_idle_poll_ctrl(bool enable);
305
306 void arch_cpu_idle(void);
307 void arch_cpu_idle_prepare(void);
308 void arch_cpu_idle_enter(void);
309 void arch_cpu_idle_exit(void);
310 void arch_cpu_idle_dead(void);
311
312 DECLARE_PER_CPU(bool, cpu_dead_idle);
313
314 int cpu_report_state(int cpu);
315 int cpu_check_up_prepare(int cpu);
316 void cpu_set_state_online(int cpu);
317 #ifdef CONFIG_HOTPLUG_CPU
318 bool cpu_wait_death(unsigned int cpu, int seconds);
319 bool cpu_report_death(void);
320 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
321
322 /*
323  * These are used for a global "mitigations=" cmdline option for toggling
324  * optional CPU mitigations.
325  */
326 enum cpu_mitigations {
327         CPU_MITIGATIONS_OFF,
328         CPU_MITIGATIONS_AUTO,
329 };
330
331 extern enum cpu_mitigations cpu_mitigations;
332
333 /* mitigations=off */
334 static inline bool cpu_mitigations_off(void)
335 {
336         return cpu_mitigations == CPU_MITIGATIONS_OFF;
337 }
338
339 #define IDLE_START 1
340 #define IDLE_END 2
341
342 void idle_notifier_register(struct notifier_block *n);
343 void idle_notifier_unregister(struct notifier_block *n);
344 void idle_notifier_call_chain(unsigned long val);
345
346 #endif /* _LINUX_CPU_H_ */