b22b000cf6ee1b12982d5b628cc2fa2ae2053b23
[cascardo/linux.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 #include <linux/cpuhotplug.h>
20
21 struct device;
22 struct device_node;
23 struct attribute_group;
24
25 struct cpu {
26         int node_id;            /* The node which contains the CPU */
27         int hotpluggable;       /* creates sysfs control file if hotpluggable */
28         struct device dev;
29 };
30
31 extern void boot_cpu_init(void);
32 extern void boot_cpu_state_init(void);
33
34 extern int register_cpu(struct cpu *cpu, int num);
35 extern struct device *get_cpu_device(unsigned cpu);
36 extern bool cpu_is_hotpluggable(unsigned cpu);
37 extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
38 extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
39                                               int cpu, unsigned int *thread);
40
41 extern int cpu_add_dev_attr(struct device_attribute *attr);
42 extern void cpu_remove_dev_attr(struct device_attribute *attr);
43
44 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
45 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
46
47 extern __printf(4, 5)
48 struct device *cpu_device_create(struct device *parent, void *drvdata,
49                                  const struct attribute_group **groups,
50                                  const char *fmt, ...);
51 #ifdef CONFIG_HOTPLUG_CPU
52 extern void unregister_cpu(struct cpu *cpu);
53 extern ssize_t arch_cpu_probe(const char *, size_t);
54 extern ssize_t arch_cpu_release(const char *, size_t);
55 #endif
56 struct notifier_block;
57
58 /*
59  * CPU notifier priorities.
60  */
61 enum {
62         /* migration should happen before other stuff but after perf */
63         CPU_PRI_PERF            = 20,
64         CPU_PRI_MIGRATION       = 10,
65
66         /* bring up workqueues before normal notifiers and down after */
67         CPU_PRI_WORKQUEUE_UP    = 5,
68         CPU_PRI_WORKQUEUE_DOWN  = -5,
69 };
70
71 #define CPU_ONLINE              0x0002 /* CPU (unsigned)v is up */
72 #define CPU_UP_PREPARE          0x0003 /* CPU (unsigned)v coming up */
73 #define CPU_UP_CANCELED         0x0004 /* CPU (unsigned)v NOT coming up */
74 #define CPU_DOWN_PREPARE        0x0005 /* CPU (unsigned)v going down */
75 #define CPU_DOWN_FAILED         0x0006 /* CPU (unsigned)v NOT going down */
76 #define CPU_DEAD                0x0007 /* CPU (unsigned)v dead */
77 #define CPU_DYING               0x0008 /* CPU (unsigned)v not running any task,
78                                         * not handling interrupts, soon dead.
79                                         * Called on the dying cpu, interrupts
80                                         * are already disabled. Must not
81                                         * sleep, must not fail */
82 #define CPU_POST_DEAD           0x0009 /* CPU (unsigned)v dead, cpu_hotplug
83                                         * lock is dropped */
84 #define CPU_STARTING            0x000A /* CPU (unsigned)v soon running.
85                                         * Called on the new cpu, just before
86                                         * enabling interrupts. Must not sleep,
87                                         * must not fail */
88 #define CPU_BROKEN              0x000B /* CPU (unsigned)v did not die properly,
89                                         * perhaps due to preemption. */
90
91 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
92  * operation in progress
93  */
94 #define CPU_TASKS_FROZEN        0x0010
95
96 #define CPU_ONLINE_FROZEN       (CPU_ONLINE | CPU_TASKS_FROZEN)
97 #define CPU_UP_PREPARE_FROZEN   (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
98 #define CPU_UP_CANCELED_FROZEN  (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
99 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
100 #define CPU_DOWN_FAILED_FROZEN  (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
101 #define CPU_DEAD_FROZEN         (CPU_DEAD | CPU_TASKS_FROZEN)
102 #define CPU_DYING_FROZEN        (CPU_DYING | CPU_TASKS_FROZEN)
103 #define CPU_STARTING_FROZEN     (CPU_STARTING | CPU_TASKS_FROZEN)
104
105
106 #ifdef CONFIG_SMP
107 extern bool cpuhp_tasks_frozen;
108 /* Need to know about CPUs going up/down? */
109 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
110 #define cpu_notifier(fn, pri) {                                 \
111         static struct notifier_block fn##_nb =                  \
112                 { .notifier_call = fn, .priority = pri };       \
113         register_cpu_notifier(&fn##_nb);                        \
114 }
115
116 #define __cpu_notifier(fn, pri) {                               \
117         static struct notifier_block fn##_nb =                  \
118                 { .notifier_call = fn, .priority = pri };       \
119         __register_cpu_notifier(&fn##_nb);                      \
120 }
121 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
122 #define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
123 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
124 #endif /* #else #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
125
126 #ifdef CONFIG_HOTPLUG_CPU
127 extern int register_cpu_notifier(struct notifier_block *nb);
128 extern int __register_cpu_notifier(struct notifier_block *nb);
129 extern void unregister_cpu_notifier(struct notifier_block *nb);
130 extern void __unregister_cpu_notifier(struct notifier_block *nb);
131 #else
132
133 #ifndef MODULE
134 extern int register_cpu_notifier(struct notifier_block *nb);
135 extern int __register_cpu_notifier(struct notifier_block *nb);
136 #else
137 static inline int register_cpu_notifier(struct notifier_block *nb)
138 {
139         return 0;
140 }
141
142 static inline int __register_cpu_notifier(struct notifier_block *nb)
143 {
144         return 0;
145 }
146 #endif
147
148 static inline void unregister_cpu_notifier(struct notifier_block *nb)
149 {
150 }
151
152 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
153 {
154 }
155 #endif
156
157 int cpu_up(unsigned int cpu);
158 void notify_cpu_starting(unsigned int cpu);
159 extern void cpu_maps_update_begin(void);
160 extern void cpu_maps_update_done(void);
161
162 #define cpu_notifier_register_begin     cpu_maps_update_begin
163 #define cpu_notifier_register_done      cpu_maps_update_done
164
165 #else   /* CONFIG_SMP */
166 #define cpuhp_tasks_frozen      0
167
168 #define cpu_notifier(fn, pri)   do { (void)(fn); } while (0)
169 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
170
171 static inline int register_cpu_notifier(struct notifier_block *nb)
172 {
173         return 0;
174 }
175
176 static inline int __register_cpu_notifier(struct notifier_block *nb)
177 {
178         return 0;
179 }
180
181 static inline void unregister_cpu_notifier(struct notifier_block *nb)
182 {
183 }
184
185 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
186 {
187 }
188
189 static inline void cpu_maps_update_begin(void)
190 {
191 }
192
193 static inline void cpu_maps_update_done(void)
194 {
195 }
196
197 static inline void cpu_notifier_register_begin(void)
198 {
199 }
200
201 static inline void cpu_notifier_register_done(void)
202 {
203 }
204
205 #endif /* CONFIG_SMP */
206 extern struct bus_type cpu_subsys;
207
208 #ifdef CONFIG_HOTPLUG_CPU
209 /* Stop CPUs going up and down. */
210
211 extern void cpu_hotplug_begin(void);
212 extern void cpu_hotplug_done(void);
213 extern void get_online_cpus(void);
214 extern void put_online_cpus(void);
215 extern void cpu_hotplug_disable(void);
216 extern void cpu_hotplug_enable(void);
217 #define hotcpu_notifier(fn, pri)        cpu_notifier(fn, pri)
218 #define __hotcpu_notifier(fn, pri)      __cpu_notifier(fn, pri)
219 #define register_hotcpu_notifier(nb)    register_cpu_notifier(nb)
220 #define __register_hotcpu_notifier(nb)  __register_cpu_notifier(nb)
221 #define unregister_hotcpu_notifier(nb)  unregister_cpu_notifier(nb)
222 #define __unregister_hotcpu_notifier(nb)        __unregister_cpu_notifier(nb)
223 void clear_tasks_mm_cpumask(int cpu);
224 int cpu_down(unsigned int cpu);
225
226 #else           /* CONFIG_HOTPLUG_CPU */
227
228 static inline void cpu_hotplug_begin(void) {}
229 static inline void cpu_hotplug_done(void) {}
230 #define get_online_cpus()       do { } while (0)
231 #define put_online_cpus()       do { } while (0)
232 #define cpu_hotplug_disable()   do { } while (0)
233 #define cpu_hotplug_enable()    do { } while (0)
234 #define hotcpu_notifier(fn, pri)        do { (void)(fn); } while (0)
235 #define __hotcpu_notifier(fn, pri)      do { (void)(fn); } while (0)
236 /* These aren't inline functions due to a GCC bug. */
237 #define register_hotcpu_notifier(nb)    ({ (void)(nb); 0; })
238 #define __register_hotcpu_notifier(nb)  ({ (void)(nb); 0; })
239 #define unregister_hotcpu_notifier(nb)  ({ (void)(nb); })
240 #define __unregister_hotcpu_notifier(nb)        ({ (void)(nb); })
241 #endif          /* CONFIG_HOTPLUG_CPU */
242
243 #ifdef CONFIG_PM_SLEEP_SMP
244 extern int disable_nonboot_cpus(void);
245 extern void enable_nonboot_cpus(void);
246 #else /* !CONFIG_PM_SLEEP_SMP */
247 static inline int disable_nonboot_cpus(void) { return 0; }
248 static inline void enable_nonboot_cpus(void) {}
249 #endif /* !CONFIG_PM_SLEEP_SMP */
250
251 void cpu_startup_entry(enum cpuhp_state state);
252
253 void cpu_idle_poll_ctrl(bool enable);
254
255 void arch_cpu_idle(void);
256 void arch_cpu_idle_prepare(void);
257 void arch_cpu_idle_enter(void);
258 void arch_cpu_idle_exit(void);
259 void arch_cpu_idle_dead(void);
260
261 int cpu_report_state(int cpu);
262 int cpu_check_up_prepare(int cpu);
263 void cpu_set_state_online(int cpu);
264 #ifdef CONFIG_HOTPLUG_CPU
265 bool cpu_wait_death(unsigned int cpu, int seconds);
266 bool cpu_report_death(void);
267 void cpuhp_report_idle_dead(void);
268 #else
269 static inline void cpuhp_report_idle_dead(void) { }
270 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
271
272 #endif /* _LINUX_CPU_H_ */