2 * include/linux/cpu.h - generic cpu definition
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.
8 * Basic handling of the devices is done in drivers/base/cpu.c
10 * CPUs are exported via sysfs in the devices/system/cpu
16 #include <linux/node.h>
17 #include <linux/compiler.h>
18 #include <linux/cpumask.h>
19 #include <linux/cpuhotplug.h>
23 struct attribute_group;
26 int node_id; /* The node which contains the CPU */
27 int hotpluggable; /* creates sysfs control file if hotpluggable */
31 extern void boot_cpu_init(void);
32 extern void boot_cpu_state_init(void);
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);
41 extern int cpu_add_dev_attr(struct device_attribute *attr);
42 extern void cpu_remove_dev_attr(struct device_attribute *attr);
44 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
45 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
47 extern ssize_t cpu_show_meltdown(struct device *dev,
48 struct device_attribute *attr, char *buf);
49 extern ssize_t cpu_show_spectre_v1(struct device *dev,
50 struct device_attribute *attr, char *buf);
51 extern ssize_t cpu_show_spectre_v2(struct device *dev,
52 struct device_attribute *attr, char *buf);
53 extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
54 struct device_attribute *attr, char *buf);
57 struct device *cpu_device_create(struct device *parent, void *drvdata,
58 const struct attribute_group **groups,
59 const char *fmt, ...);
60 #ifdef CONFIG_HOTPLUG_CPU
61 extern void unregister_cpu(struct cpu *cpu);
62 extern ssize_t arch_cpu_probe(const char *, size_t);
63 extern ssize_t arch_cpu_release(const char *, size_t);
65 struct notifier_block;
67 #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */
68 #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */
69 #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */
70 #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */
71 #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */
72 #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */
73 #define CPU_POST_DEAD 0x0009 /* CPU (unsigned)v dead, cpu_hotplug
75 #define CPU_BROKEN 0x000B /* CPU (unsigned)v did not die properly,
76 * perhaps due to preemption. */
78 /* Used for CPU hotplug events occurring while tasks are frozen due to a suspend
79 * operation in progress
81 #define CPU_TASKS_FROZEN 0x0010
83 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN)
84 #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN)
85 #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN)
86 #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN)
87 #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN)
88 #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN)
91 extern bool cpuhp_tasks_frozen;
92 /* Need to know about CPUs going up/down? */
93 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
94 #define cpu_notifier(fn, pri) { \
95 static struct notifier_block fn##_nb = \
96 { .notifier_call = fn, .priority = pri }; \
97 register_cpu_notifier(&fn##_nb); \
100 #define __cpu_notifier(fn, pri) { \
101 static struct notifier_block fn##_nb = \
102 { .notifier_call = fn, .priority = pri }; \
103 __register_cpu_notifier(&fn##_nb); \
106 extern int register_cpu_notifier(struct notifier_block *nb);
107 extern int __register_cpu_notifier(struct notifier_block *nb);
108 extern void unregister_cpu_notifier(struct notifier_block *nb);
109 extern void __unregister_cpu_notifier(struct notifier_block *nb);
111 #else /* #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE) */
112 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
113 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
115 static inline int register_cpu_notifier(struct notifier_block *nb)
120 static inline int __register_cpu_notifier(struct notifier_block *nb)
125 static inline void unregister_cpu_notifier(struct notifier_block *nb)
129 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
134 int cpu_up(unsigned int cpu);
135 void notify_cpu_starting(unsigned int cpu);
136 extern void cpu_maps_update_begin(void);
137 extern void cpu_maps_update_done(void);
139 #define cpu_notifier_register_begin cpu_maps_update_begin
140 #define cpu_notifier_register_done cpu_maps_update_done
142 #else /* CONFIG_SMP */
143 #define cpuhp_tasks_frozen 0
145 #define cpu_notifier(fn, pri) do { (void)(fn); } while (0)
146 #define __cpu_notifier(fn, pri) do { (void)(fn); } while (0)
148 static inline int register_cpu_notifier(struct notifier_block *nb)
153 static inline int __register_cpu_notifier(struct notifier_block *nb)
158 static inline void unregister_cpu_notifier(struct notifier_block *nb)
162 static inline void __unregister_cpu_notifier(struct notifier_block *nb)
166 static inline void cpu_maps_update_begin(void)
170 static inline void cpu_maps_update_done(void)
174 static inline void cpu_notifier_register_begin(void)
178 static inline void cpu_notifier_register_done(void)
182 #endif /* CONFIG_SMP */
183 extern struct bus_type cpu_subsys;
185 #ifdef CONFIG_HOTPLUG_CPU
186 /* Stop CPUs going up and down. */
188 extern void cpu_hotplug_begin(void);
189 extern void cpu_hotplug_done(void);
190 extern void get_online_cpus(void);
191 extern void put_online_cpus(void);
192 extern void cpu_hotplug_disable(void);
193 extern void cpu_hotplug_enable(void);
194 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
195 #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
196 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
197 #define __register_hotcpu_notifier(nb) __register_cpu_notifier(nb)
198 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
199 #define __unregister_hotcpu_notifier(nb) __unregister_cpu_notifier(nb)
200 void clear_tasks_mm_cpumask(int cpu);
201 int cpu_down(unsigned int cpu);
203 #else /* CONFIG_HOTPLUG_CPU */
205 static inline void cpu_hotplug_begin(void) {}
206 static inline void cpu_hotplug_done(void) {}
207 #define get_online_cpus() do { } while (0)
208 #define put_online_cpus() do { } while (0)
209 #define cpu_hotplug_disable() do { } while (0)
210 #define cpu_hotplug_enable() do { } while (0)
211 #define hotcpu_notifier(fn, pri) do { (void)(fn); } 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 __register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
216 #define unregister_hotcpu_notifier(nb) ({ (void)(nb); })
217 #define __unregister_hotcpu_notifier(nb) ({ (void)(nb); })
218 #endif /* CONFIG_HOTPLUG_CPU */
220 #ifdef CONFIG_PM_SLEEP_SMP
221 extern int freeze_secondary_cpus(int primary);
222 static inline int disable_nonboot_cpus(void)
224 return freeze_secondary_cpus(0);
226 extern void enable_nonboot_cpus(void);
227 #else /* !CONFIG_PM_SLEEP_SMP */
228 static inline int disable_nonboot_cpus(void) { return 0; }
229 static inline void enable_nonboot_cpus(void) {}
230 #endif /* !CONFIG_PM_SLEEP_SMP */
232 void cpu_startup_entry(enum cpuhp_state state);
234 void cpu_idle_poll_ctrl(bool enable);
236 /* Attach to any functions which should be considered cpuidle. */
237 #define __cpuidle __attribute__((__section__(".cpuidle.text")))
239 bool cpu_in_idle(unsigned long pc);
241 void arch_cpu_idle(void);
242 void arch_cpu_idle_prepare(void);
243 void arch_cpu_idle_enter(void);
244 void arch_cpu_idle_exit(void);
245 void arch_cpu_idle_dead(void);
247 int cpu_report_state(int cpu);
248 int cpu_check_up_prepare(int cpu);
249 void cpu_set_state_online(int cpu);
250 #ifdef CONFIG_HOTPLUG_CPU
251 bool cpu_wait_death(unsigned int cpu, int seconds);
252 bool cpu_report_death(void);
253 void cpuhp_report_idle_dead(void);
255 static inline void cpuhp_report_idle_dead(void) { }
256 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
261 void idle_notifier_register(struct notifier_block *n);
262 void idle_notifier_unregister(struct notifier_block *n);
263 void idle_notifier_call_chain(unsigned long val);
265 #endif /* _LINUX_CPU_H_ */