import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.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 * and system devices are handled in drivers/base/sys.c.
10 *
11 * CPUs are exported via sysfs in the class/cpu/devices/
12 * directory.
13 */
14 #ifndef _LINUX_CPU_H_
15 #define _LINUX_CPU_H_
16
17 #include <linux/node.h>
18 #include <linux/compiler.h>
19 #include <linux/cpumask.h>
20
21 /*******************************************************************************
22 * 20131225 marc.huang *
23 * CPU Hotplug and idle integration *
24 *******************************************************************************/
25 extern atomic_t is_in_hotplug;
26 /******************************************************************************/
27
28 struct device;
29
30 struct cpu {
31 int node_id; /* The node which contains the CPU */
32 int hotpluggable; /* creates sysfs control file if hotpluggable */
33 struct device dev;
34 };
35
36 extern int register_cpu(struct cpu *cpu, int num);
37 extern struct device *get_cpu_device(unsigned cpu);
38 extern bool cpu_is_hotpluggable(unsigned cpu);
39
40 extern int cpu_add_dev_attr(struct device_attribute *attr);
41 extern void cpu_remove_dev_attr(struct device_attribute *attr);
42
43 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
44 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
45
46 #ifdef CONFIG_HOTPLUG_CPU
47 extern void unregister_cpu(struct cpu *cpu);
48 extern ssize_t arch_cpu_probe(const char *, size_t);
49 extern ssize_t arch_cpu_release(const char *, size_t);
50 #endif
51 struct notifier_block;
52
53 #ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
54 extern int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env);
55 extern ssize_t arch_print_cpu_modalias(struct device *dev,
56 struct device_attribute *attr,
57 char *bufptr);
58 #endif
59
60 /*
61 * CPU notifier priorities.
62 */
63 enum {
64 /*
65 * SCHED_ACTIVE marks a cpu which is coming up active during
66 * CPU_ONLINE and CPU_DOWN_FAILED and must be the first
67 * notifier. CPUSET_ACTIVE adjusts cpuset according to
68 * cpu_active mask right after SCHED_ACTIVE. During
69 * CPU_DOWN_PREPARE, SCHED_INACTIVE and CPUSET_INACTIVE are
70 * ordered in the similar way.
71 *
72 * This ordering guarantees consistent cpu_active mask and
73 * migration behavior to all cpu notifiers.
74 */
75 CPU_PRI_SCHED_ACTIVE = INT_MAX,
76 CPU_PRI_CPUSET_ACTIVE = INT_MAX - 1,
77 CPU_PRI_SCHED_INACTIVE = INT_MIN + 1,
78 CPU_PRI_CPUSET_INACTIVE = INT_MIN,
79
80 /* migration should happen before other stuff but after perf */
81 CPU_PRI_PERF = 20,
82 CPU_PRI_MIGRATION = 10,
83 /* bring up workqueues before normal notifiers and down after */
84 CPU_PRI_WORKQUEUE_UP = 5,
85 CPU_PRI_WORKQUEUE_DOWN = -5,
86 };
87
88 #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
89 #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
90 #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
91 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
92 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
93 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
94 #define CPU_DYING 0x0008 /* CPU (unsigned)v not running any task,
95 * not handling interrupts, soon dead.
96 * Called on the dying cpu, interrupts
97 * are already disabled. Must not
98 * sleep, must not fail */
99 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
100 * lock is dropped */
101 #define CPU_STARTING 0x000A /* CPU (unsigned)v soon running.
102 * Called on the new cpu, just before
103 * enabling interrupts. Must not sleep,
104 * must not fail */
105
106 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
107 * operation in progress
108 */
109 #define CPU_TASKS_FROZEN 0x0010
110
111 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
112 #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
113 #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
114 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
115 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
116 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
117 #define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN)
118 #define CPU_STARTING_FROZEN (CPU_STARTING | CPU_TASKS_FROZEN)
119
120
121 #ifdef CONFIG_SMP
122 /* Need to know about CPUs going up/down? */
123 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
124 #define cpu_notifier(fn, pri) { \
125 static struct notifier_block fn##_nb __cpuinitdata = \
126 { .notifier_call = fn, .priority = pri }; \
127 register_cpu_notifier(&fn##_nb); \
128 }
129 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
130 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
131 #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
132 #ifdef CONFIG_HOTPLUG_CPU
133 extern int register_cpu_notifier(struct notifier_block *nb);
134 extern void unregister_cpu_notifier(struct notifier_block *nb);
135 #else
136
137 #ifndef MODULE
138 extern int register_cpu_notifier(struct notifier_block *nb);
139 #else
140 static inline int register_cpu_notifier(struct notifier_block *nb)
141 {
142 return 0;
143 }
144 #endif
145
146 static inline void unregister_cpu_notifier(struct notifier_block *nb)
147 {
148 }
149 #endif
150
151 int cpu_up(unsigned int cpu);
152 void notify_cpu_starting(unsigned int cpu);
153 extern void cpu_maps_update_begin(void);
154 extern void cpu_maps_update_done(void);
155
156 #else /* CONFIG_SMP */
157
158 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
159
160 static inline int register_cpu_notifier(struct notifier_block *nb)
161 {
162 return 0;
163 }
164
165 static inline void unregister_cpu_notifier(struct notifier_block *nb)
166 {
167 }
168
169 static inline void cpu_maps_update_begin(void)
170 {
171 }
172
173 static inline void cpu_maps_update_done(void)
174 {
175 }
176
177 #endif /* CONFIG_SMP */
178 extern struct bus_type cpu_subsys;
179
180 #ifdef CONFIG_HOTPLUG_CPU
181 /* Stop CPUs going up and down. */
182
183 extern void get_online_cpus(void);
184 extern void put_online_cpus(void);
185 extern void cpu_hotplug_disable(void);
186 extern void cpu_hotplug_enable(void);
187 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
188 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
189 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
190 void clear_tasks_mm_cpumask(int cpu);
191 int cpu_down(unsigned int cpu);
192
193 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
194 extern void cpu_hotplug_driver_lock(void);
195 extern void cpu_hotplug_driver_unlock(void);
196 #else
197 static inline void cpu_hotplug_driver_lock(void)
198 {
199 }
200
201 static inline void cpu_hotplug_driver_unlock(void)
202 {
203 }
204 #endif
205
206 #else /* CONFIG_HOTPLUG_CPU */
207
208 #define get_online_cpus() do { } while (0)
209 #define put_online_cpus() do { } while (0)
210 #define cpu_hotplug_disable() do { } while (0)
211 #define cpu_hotplug_enable() do { } while (0)
212 #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
213 /* These aren't inline functions due to a GCC bug. */
214 #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
215 #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
216 #endif /* CONFIG_HOTPLUG_CPU */
217
218 #ifdef CONFIG_PM_SLEEP_SMP
219 extern int disable_nonboot_cpus(void);
220 extern void enable_nonboot_cpus(void);
221 #else /* !CONFIG_PM_SLEEP_SMP */
222 static inline int disable_nonboot_cpus(void) { return 0; }
223 static inline void enable_nonboot_cpus(void) {}
224 #endif /* !CONFIG_PM_SLEEP_SMP */
225
226 enum cpuhp_state {
227 CPUHP_OFFLINE,
228 CPUHP_ONLINE,
229 };
230
231 void cpu_startup_entry(enum cpuhp_state state);
232 void cpu_idle(void);
233
234 void cpu_idle_poll_ctrl(bool enable);
235
236 void arch_cpu_idle(void);
237 void arch_cpu_idle_prepare(void);
238 void arch_cpu_idle_enter(void);
239 void arch_cpu_idle_exit(void);
240 void arch_cpu_idle_dead(void);
241
242 #define IDLE_START 1
243 #define IDLE_END 2
244
245 void idle_notifier_register(struct notifier_block *n);
246 void idle_notifier_unregister(struct notifier_block *n);
247 void idle_notifier_call_chain(unsigned long val);
248
249 #endif /* _LINUX_CPU_H_ */