OSDN Git Service

960f2750bc42de0048f98427e298797606fb42e6
[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
69 extern __printf(4, 5)
70 struct device *cpu_device_create(struct device *parent, void *drvdata,
71                                  const struct attribute_group **groups,
72                                  const char *fmt, ...);
73 #ifdef CONFIG_HOTPLUG_CPU
74 extern void unregister_cpu(struct cpu *cpu);
75 extern ssize_t arch_cpu_probe(const char *, size_t);
76 extern ssize_t arch_cpu_release(const char *, size_t);
77 #endif
78 struct notifier_block;
79
80 /*
81  * CPU notifier priorities.
82  */
83 enum {
84         /*
85          * SCHED_ACTIVE marks a cpu which is coming up active during
86          * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
87          * notifier.  CPUSET_ACTIVE adjusts cpuset according to
88          * cpu_active mask right after SCHED_ACTIVE.  During
89          * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
90          * ordered in the similar way.
91          *
92          * This ordering guarantees consistent cpu_active mask and
93          * migration behavior to all cpu notifiers.
94          */
95         CPU_PRI_SCHED_ACTIVE    = INT_MAX,
96         CPU_PRI_CPUSET_ACTIVE   = INT_MAX - 1,
97         CPU_PRI_SCHED_INACTIVE  = INT_MIN + 1,
98         CPU_PRI_CPUSET_INACTIVE = INT_MIN,
99
100         /* migration should happen before other stuff but after perf */
101         CPU_PRI_PERF            = 20,
102         CPU_PRI_MIGRATION       = 10,
103         CPU_PRI_SMPBOOT         = 9,
104         /* bring up workqueues before normal notifiers and down after */
105         CPU_PRI_WORKQUEUE_UP    = 5,
106         CPU_PRI_WORKQUEUE_DOWN  = -5,
107 };
108
109 #define CPU_ONLINE              0x0002 /* CPU (unsigned)v is up */
110 #define CPU_UP_PREPARE          0x0003 /* CPU (unsigned)v coming up */
111 #define CPU_UP_CANCELED         0x0004 /* CPU (unsigned)v NOT coming up */
112 #define CPU_DOWN_PREPARE        0x0005 /* CPU (unsigned)v going down */
113 #define CPU_DOWN_FAILED         0x0006 /* CPU (unsigned)v NOT going down */
114 #define CPU_DEAD                0x0007 /* CPU (unsigned)v dead */
115 #define CPU_DYING               0x0008 /* CPU (unsigned)v not running any task,
116                                         * not handling interrupts, soon dead.
117                                         * Called on the dying cpu, interrupts
118                                         * are already disabled. Must not
119                                         * sleep, must not fail */
120 #define CPU_POST_DEAD           0x0009 /* CPU (unsigned)v dead, cpu_hotplug
121                                         * lock is dropped */
122 #define CPU_STARTING            0x000A /* CPU (unsigned)v soon running.
123                                         * Called on the new cpu, just before
124                                         * enabling interrupts. Must not sleep,
125                                         * must not fail */
126 #define CPU_DYING_IDLE          0x000B /* CPU (unsigned)v dying, reached
127                                         * idle loop. */
128 #define CPU_BROKEN              0x000C /* CPU (unsigned)v did not die properly,
129                                         * perhaps due to preemption. */
130
131 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
132  * operation in progress
133  */
134 #define CPU_TASKS_FROZEN        0x0010
135
136 #define CPU_ONLINE_FROZEN       (CPU_ONLINE | CPU_TASKS_FROZEN)
137 #define CPU_UP_PREPARE_FROZEN   (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
138 #define CPU_UP_CANCELED_FROZEN  (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
139 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
140 #define CPU_DOWN_FAILED_FROZEN  (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
141 #define CPU_DEAD_FROZEN         (CPU_DEAD | CPU_TASKS_FROZEN)
142 #define CPU_DYING_FROZEN        (CPU_DYING | CPU_TASKS_FROZEN)
143 #define CPU_STARTING_FROZEN     (CPU_STARTING | CPU_TASKS_FROZEN)
144
145
146 #ifdef CONFIG_SMP
147 /* Need to know about CPUs going up/down? */
148 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
149 #define cpu_notifier(fn, pri) {                                 \
150         static struct notifier_block fn##_nb =                  \
151                 { .notifier_call = fn, .priority = pri };       \
152         register_cpu_notifier(&fn##_nb);                        \
153 }
154
155 #define __cpu_notifier(fn, pri) {                               \
156         static struct notifier_block fn##_nb =                  \
157                 { .notifier_call = fn, .priority = pri };       \
158         __register_cpu_notifier(&fn##_nb);                      \
159 }
160
161 extern int register_cpu_notifier(struct notifier_block *nb);
162 extern int __register_cpu_notifier(struct notifier_block *nb);
163 extern void unregister_cpu_notifier(struct notifier_block *nb);
164 extern void __unregister_cpu_notifier(struct notifier_block *nb);
165
166 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
167 #define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
168 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
169
170 static inline int register_cpu_notifier(struct notifier_block *nb)
171 {
172         return 0;
173 }
174
175 static inline int __register_cpu_notifier(struct notifier_block *nb)
176 {
177         return 0;
178 }
179
180 static inline void unregister_cpu_notifier(struct notifier_block *nb)
181 {
182 }
183
184 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
185 {
186 }
187 #endif
188
189 void smpboot_thread_init(void);
190 int cpu_up(unsigned int cpu);
191 void notify_cpu_starting(unsigned int cpu);
192 extern void cpu_maps_update_begin(void);
193 extern void cpu_maps_update_done(void);
194
195 #define cpu_notifier_register_begin     cpu_maps_update_begin
196 #define cpu_notifier_register_done      cpu_maps_update_done
197
198 #else   /* CONFIG_SMP */
199
200 #define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
201 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
202
203 static inline int register_cpu_notifier(struct notifier_block *nb)
204 {
205         return 0;
206 }
207
208 static inline int __register_cpu_notifier(struct notifier_block *nb)
209 {
210         return 0;
211 }
212
213 static inline void unregister_cpu_notifier(struct notifier_block *nb)
214 {
215 }
216
217 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
218 {
219 }
220
221 static inline void cpu_maps_update_begin(void)
222 {
223 }
224
225 static inline void cpu_maps_update_done(void)
226 {
227 }
228
229 static inline void cpu_notifier_register_begin(void)
230 {
231 }
232
233 static inline void cpu_notifier_register_done(void)
234 {
235 }
236
237 static inline void smpboot_thread_init(void)
238 {
239 }
240
241 #endif /* CONFIG_SMP */
242 extern struct bus_type cpu_subsys;
243
244 #ifdef CONFIG_HOTPLUG_CPU
245 /* Stop CPUs going up and down. */
246
247 extern void cpu_hotplug_begin(void);
248 extern void cpu_hotplug_done(void);
249 extern void get_online_cpus(void);
250 extern void cpu_hotplug_mutex_held(void);
251 extern void put_online_cpus(void);
252 extern void cpu_hotplug_disable(void);
253 extern void cpu_hotplug_enable(void);
254 #define hotcpu_notifier(fn, pri)        cpu_notifier(fn, pri)
255 #define __hotcpu_notifier(fn, pri)      __cpu_notifier(fn, pri)
256 #define register_hotcpu_notifier(nb)    register_cpu_notifier(nb)
257 #define __register_hotcpu_notifier(nb)  __register_cpu_notifier(nb)
258 #define unregister_hotcpu_notifier(nb)  unregister_cpu_notifier(nb)
259 #define __unregister_hotcpu_notifier(nb)        __unregister_cpu_notifier(nb)
260 void clear_tasks_mm_cpumask(int cpu);
261 int cpu_down(unsigned int cpu);
262
263 #else           /* CONFIG_HOTPLUG_CPU */
264
265 static inline void cpu_hotplug_begin(void) {}
266 static inline void cpu_hotplug_done(void) {}
267 #define get_online_cpus()       do { } while (0)
268 #define put_online_cpus()       do { } while (0)
269 #define cpu_hotplug_disable()   do { } while (0)
270 #define cpu_hotplug_enable()    do { } while (0)
271 #define hotcpu_notifier(fn, pri)        do { (void)(fn); } while (0)
272 #define __hotcpu_notifier(fn, pri)      do { (void)(fn); } while (0)
273 #define cpu_hotplug_mutex_held()        do { } while (0)
274 /* These aren't inline functions due to a GCC bug. */
275 #define register_hotcpu_notifier(nb)    ({ (void)(nb); 0; })
276 #define __register_hotcpu_notifier(nb)  ({ (void)(nb); 0; })
277 #define unregister_hotcpu_notifier(nb)  ({ (void)(nb); })
278 #define __unregister_hotcpu_notifier(nb)        ({ (void)(nb); })
279 #endif          /* CONFIG_HOTPLUG_CPU */
280
281 #ifdef CONFIG_PM_SLEEP_SMP
282 extern int disable_nonboot_cpus(void);
283 extern void enable_nonboot_cpus(void);
284 #else /* !CONFIG_PM_SLEEP_SMP */
285 static inline int disable_nonboot_cpus(void) { return 0; }
286 static inline void enable_nonboot_cpus(void) {}
287 #endif /* !CONFIG_PM_SLEEP_SMP */
288
289 struct cpu_pwr_stats *get_cpu_pwr_stats(void);
290 void trigger_cpu_pwr_stats_calc(void);
291
292 enum cpuhp_state {
293         CPUHP_OFFLINE,
294         CPUHP_ONLINE,
295 };
296
297 void cpu_startup_entry(enum cpuhp_state state);
298
299 void cpu_idle_poll_ctrl(bool enable);
300
301 void arch_cpu_idle(void);
302 void arch_cpu_idle_prepare(void);
303 void arch_cpu_idle_enter(void);
304 void arch_cpu_idle_exit(void);
305 void arch_cpu_idle_dead(void);
306
307 DECLARE_PER_CPU(bool, cpu_dead_idle);
308
309 int cpu_report_state(int cpu);
310 int cpu_check_up_prepare(int cpu);
311 void cpu_set_state_online(int cpu);
312 #ifdef CONFIG_HOTPLUG_CPU
313 bool cpu_wait_death(unsigned int cpu, int seconds);
314 bool cpu_report_death(void);
315 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
316
317 /*
318  * These are used for a global "mitigations=" cmdline option for toggling
319  * optional CPU mitigations.
320  */
321 enum cpu_mitigations {
322         CPU_MITIGATIONS_OFF,
323         CPU_MITIGATIONS_AUTO,
324 };
325
326 extern enum cpu_mitigations cpu_mitigations;
327
328 /* mitigations=off */
329 static inline bool cpu_mitigations_off(void)
330 {
331         return cpu_mitigations == CPU_MITIGATIONS_OFF;
332 }
333
334 #define IDLE_START 1
335 #define IDLE_END 2
336
337 void idle_notifier_register(struct notifier_block *n);
338 void idle_notifier_unregister(struct notifier_block *n);
339 void idle_notifier_call_chain(unsigned long val);
340
341 #endif /* _LINUX_CPU_H_ */