1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * include/linux/cpu.h - generic cpu definition
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * This is mainly for topological representation. We define the
61da177e4SLinus Torvalds * basic 'struct cpu' here, which can be embedded in per-arch
71da177e4SLinus Torvalds * definitions of processors.
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * Basic handling of the devices is done in drivers/base/cpu.c
101da177e4SLinus Torvalds *
11611a75e1SRobert P. J. Day * CPUs are exported via sysfs in the devices/system/cpu
121da177e4SLinus Torvalds * directory.
131da177e4SLinus Torvalds */
141da177e4SLinus Torvalds #ifndef _LINUX_CPU_H_
151da177e4SLinus Torvalds #define _LINUX_CPU_H_
161da177e4SLinus Torvalds
171da177e4SLinus Torvalds #include <linux/node.h>
181da177e4SLinus Torvalds #include <linux/compiler.h>
19cff7d378SThomas Gleixner #include <linux/cpuhotplug.h>
20195fb517STony Luck #include <linux/cpuhplock.h>
213f916919SMichael Ellerman #include <linux/cpu_smt.h>
221da177e4SLinus Torvalds
23313162d0SPaul Gortmaker struct device;
24d1cb9d1aSDavid Miller struct device_node;
253d52943bSSudeep Holla struct attribute_group;
26313162d0SPaul Gortmaker
271da177e4SLinus Torvalds struct cpu {
281da177e4SLinus Torvalds int node_id; /* The node which contains the CPU */
2972486f1fSSiddha, Suresh B int hotpluggable; /* creates sysfs control file if hotpluggable */
308a25a2fdSKay Sievers struct device dev;
311da177e4SLinus Torvalds };
321da177e4SLinus Torvalds
33cff7d378SThomas Gleixner extern void boot_cpu_init(void);
34b5b1404dSLinus Torvalds extern void boot_cpu_hotplug_init(void);
351777e463SIngo Molnar extern void cpu_init(void);
361777e463SIngo Molnar extern void trap_init(void);
37cff7d378SThomas Gleixner
3876b67ed9SKAMEZAWA Hiroyuki extern int register_cpu(struct cpu *cpu, int num);
398a25a2fdSKay Sievers extern struct device *get_cpu_device(unsigned cpu);
402987557fSJosh Triplett extern bool cpu_is_hotpluggable(unsigned cpu);
41183912d3SSudeep KarkadaNagesha extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
42d1cb9d1aSDavid Miller extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
43d1cb9d1aSDavid Miller int cpu, unsigned int *thread);
440344c6c5SChristian Krafft
458a25a2fdSKay Sievers extern int cpu_add_dev_attr(struct device_attribute *attr);
468a25a2fdSKay Sievers extern void cpu_remove_dev_attr(struct device_attribute *attr);
470344c6c5SChristian Krafft
488a25a2fdSKay Sievers extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
498a25a2fdSKay Sievers extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
500344c6c5SChristian Krafft
5187590ce6SThomas Gleixner extern ssize_t cpu_show_meltdown(struct device *dev,
5287590ce6SThomas Gleixner struct device_attribute *attr, char *buf);
5387590ce6SThomas Gleixner extern ssize_t cpu_show_spectre_v1(struct device *dev,
5487590ce6SThomas Gleixner struct device_attribute *attr, char *buf);
5587590ce6SThomas Gleixner extern ssize_t cpu_show_spectre_v2(struct device *dev,
5687590ce6SThomas Gleixner struct device_attribute *attr, char *buf);
57c456442cSKonrad Rzeszutek Wilk extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
58c456442cSKonrad Rzeszutek Wilk struct device_attribute *attr, char *buf);
5917dbca11SAndi Kleen extern ssize_t cpu_show_l1tf(struct device *dev,
6017dbca11SAndi Kleen struct device_attribute *attr, char *buf);
618a4b06d3SThomas Gleixner extern ssize_t cpu_show_mds(struct device *dev,
628a4b06d3SThomas Gleixner struct device_attribute *attr, char *buf);
636608b45aSPawan Gupta extern ssize_t cpu_show_tsx_async_abort(struct device *dev,
646608b45aSPawan Gupta struct device_attribute *attr,
656608b45aSPawan Gupta char *buf);
66db4d30fbSVineela Tummalapalli extern ssize_t cpu_show_itlb_multihit(struct device *dev,
67db4d30fbSVineela Tummalapalli struct device_attribute *attr, char *buf);
682accfa69SGuenter Roeck extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
698d50cdf8SPawan Gupta extern ssize_t cpu_show_mmio_stale_data(struct device *dev,
708d50cdf8SPawan Gupta struct device_attribute *attr,
718d50cdf8SPawan Gupta char *buf);
726b80b59bSAlexandre Chartre extern ssize_t cpu_show_retbleed(struct device *dev,
736b80b59bSAlexandre Chartre struct device_attribute *attr, char *buf);
74fb3bd914SBorislav Petkov (AMD) extern ssize_t cpu_show_spec_rstack_overflow(struct device *dev,
75fb3bd914SBorislav Petkov (AMD) struct device_attribute *attr, char *buf);
76a57c27c7SArnd Bergmann extern ssize_t cpu_show_gds(struct device *dev,
77a57c27c7SArnd Bergmann struct device_attribute *attr, char *buf);
788076fcdeSPawan Gupta extern ssize_t cpu_show_reg_file_data_sampling(struct device *dev,
798076fcdeSPawan Gupta struct device_attribute *attr, char *buf);
804bf97069SCharlie Jenkins extern ssize_t cpu_show_ghostwrite(struct device *dev, struct device_attribute *attr, char *buf);
81*f4818881SPawan Gupta extern ssize_t cpu_show_indirect_target_selection(struct device *dev,
82*f4818881SPawan Gupta struct device_attribute *attr, char *buf);
8387590ce6SThomas Gleixner
848db14860SNicolas Iooss extern __printf(4, 5)
858db14860SNicolas Iooss struct device *cpu_device_create(struct device *parent, void *drvdata,
863d52943bSSudeep Holla const struct attribute_group **groups,
873d52943bSSudeep Holla const char *fmt, ...);
88bb5e44fbSRussell King (Oracle) extern bool arch_cpu_is_hotpluggable(int cpu);
89c4dd854fSRussell King (Oracle) extern int arch_register_cpu(int cpu);
90c4dd854fSRussell King (Oracle) extern void arch_unregister_cpu(int cpu);
911da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU
9276b67ed9SKAMEZAWA Hiroyuki extern void unregister_cpu(struct cpu *cpu);
9312633e80SNathan Fontenot extern ssize_t arch_cpu_probe(const char *, size_t);
9412633e80SNathan Fontenot extern ssize_t arch_cpu_release(const char *, size_t);
951da177e4SLinus Torvalds #endif
961da177e4SLinus Torvalds
970949dd96SJames Morse #ifdef CONFIG_GENERIC_CPU_DEVICES
980949dd96SJames Morse DECLARE_PER_CPU(struct cpu, cpu_devices);
990949dd96SJames Morse #endif
1000949dd96SJames Morse
101f4c09f87SThomas Gleixner /*
102f4c09f87SThomas Gleixner * These states are not related to the core CPU hotplug mechanism. They are
103f4c09f87SThomas Gleixner * used by various (sub)architectures to track internal state
10480f1ff97SAmerigo Wang */
105f4c09f87SThomas Gleixner #define CPU_ONLINE 0x0002 /* CPU is up */
106f4c09f87SThomas Gleixner #define CPU_UP_PREPARE 0x0003 /* CPU coming up */
107f4c09f87SThomas Gleixner #define CPU_DEAD 0x0007 /* CPU dead */
108f4c09f87SThomas Gleixner #define CPU_DEAD_FROZEN 0x0008 /* CPU timed out on unplug */
109f4c09f87SThomas Gleixner #define CPU_POST_DEAD 0x0009 /* CPU successfully unplugged */
110f4c09f87SThomas Gleixner #define CPU_BROKEN 0x000B /* CPU did not die properly */
11180f1ff97SAmerigo Wang
1121da177e4SLinus Torvalds #ifdef CONFIG_SMP
113090e77c3SThomas Gleixner extern bool cpuhp_tasks_frozen;
11493ef1429SQais Yousef int add_cpu(unsigned int cpu);
11533c3736eSQais Yousef int cpu_device_up(struct device *dev);
116e545a614SManfred Spraul void notify_cpu_starting(unsigned int cpu);
1173da1c84cSOleg Nesterov extern void cpu_maps_update_begin(void);
1183da1c84cSOleg Nesterov extern void cpu_maps_update_done(void);
119d720f986SQais Yousef int bringup_hibernate_cpu(unsigned int sleep_cpu);
1204c8a4985SIngo Molnar void bringup_nonboot_cpus(unsigned int max_cpus);
121d0d23b54SIngo Molnar
1223da1c84cSOleg Nesterov #else /* CONFIG_SMP */
123090e77c3SThomas Gleixner #define cpuhp_tasks_frozen 0
1241da177e4SLinus Torvalds
cpu_maps_update_begin(void)1253da1c84cSOleg Nesterov static inline void cpu_maps_update_begin(void)
1263da1c84cSOleg Nesterov {
1273da1c84cSOleg Nesterov }
1283da1c84cSOleg Nesterov
cpu_maps_update_done(void)1293da1c84cSOleg Nesterov static inline void cpu_maps_update_done(void)
1303da1c84cSOleg Nesterov {
1313da1c84cSOleg Nesterov }
1323da1c84cSOleg Nesterov
add_cpu(unsigned int cpu)13351f24030SShuo Liu static inline int add_cpu(unsigned int cpu) { return 0;}
13451f24030SShuo Liu
1351da177e4SLinus Torvalds #endif /* CONFIG_SMP */
1363a480d4bSGreg Kroah-Hartman extern const struct bus_type cpu_subsys;
1371da177e4SLinus Torvalds
138f3de4be9SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP_SMP
139fb7fb84aSQais Yousef extern int freeze_secondary_cpus(int primary);
14056555855SQais Yousef extern void thaw_secondary_cpus(void);
1412f1a6fbbSNicholas Piggin
suspend_disable_secondary_cpus(void)1422f1a6fbbSNicholas Piggin static inline int suspend_disable_secondary_cpus(void)
1432f1a6fbbSNicholas Piggin {
1449ca12ac0SNicholas Piggin int cpu = 0;
1459ca12ac0SNicholas Piggin
1469ca12ac0SNicholas Piggin if (IS_ENABLED(CONFIG_PM_SLEEP_SMP_NONZERO_CPU))
1479ca12ac0SNicholas Piggin cpu = -1;
1489ca12ac0SNicholas Piggin
1499ca12ac0SNicholas Piggin return freeze_secondary_cpus(cpu);
1502f1a6fbbSNicholas Piggin }
suspend_enable_secondary_cpus(void)1512f1a6fbbSNicholas Piggin static inline void suspend_enable_secondary_cpus(void)
1522f1a6fbbSNicholas Piggin {
153ede7cd60SZijun Hu thaw_secondary_cpus();
1542f1a6fbbSNicholas Piggin }
1552f1a6fbbSNicholas Piggin
156f3de4be9SRafael J. Wysocki #else /* !CONFIG_PM_SLEEP_SMP */
thaw_secondary_cpus(void)15756555855SQais Yousef static inline void thaw_secondary_cpus(void) {}
suspend_disable_secondary_cpus(void)1582f1a6fbbSNicholas Piggin static inline int suspend_disable_secondary_cpus(void) { return 0; }
suspend_enable_secondary_cpus(void)1592f1a6fbbSNicholas Piggin static inline void suspend_enable_secondary_cpus(void) { }
160f3de4be9SRafael J. Wysocki #endif /* !CONFIG_PM_SLEEP_SMP */
161e3920fb4SRafael J. Wysocki
162d4e5268aSPeter Zijlstra void __noreturn cpu_startup_entry(enum cpuhp_state state);
163a1a04ec3SThomas Gleixner
164d1669912SThomas Gleixner void cpu_idle_poll_ctrl(bool enable);
165d1669912SThomas Gleixner
1666727ad9eSChris Metcalf bool cpu_in_idle(unsigned long pc);
1676727ad9eSChris Metcalf
168d1669912SThomas Gleixner void arch_cpu_idle(void);
169d1669912SThomas Gleixner void arch_cpu_idle_prepare(void);
170d1669912SThomas Gleixner void arch_cpu_idle_enter(void);
171d1669912SThomas Gleixner void arch_cpu_idle_exit(void);
1722be2a197SThomas Gleixner void arch_tick_broadcast_enter(void);
1732be2a197SThomas Gleixner void arch_tick_broadcast_exit(void);
174071c44e4SJosh Poimboeuf void __noreturn arch_cpu_idle_dead(void);
175d1669912SThomas Gleixner
1767725acaaSThomas Gleixner #ifdef CONFIG_ARCH_HAS_CPU_FINALIZE_INIT
1777725acaaSThomas Gleixner void arch_cpu_finalize_init(void);
1787725acaaSThomas Gleixner #else
arch_cpu_finalize_init(void)1797725acaaSThomas Gleixner static inline void arch_cpu_finalize_init(void) { }
1807725acaaSThomas Gleixner #endif
1817725acaaSThomas Gleixner
182c55b51a0SDaniel Lezcano void play_idle_precise(u64 duration_ns, u64 latency_ns);
183c55b51a0SDaniel Lezcano
play_idle(unsigned long duration_us)184c55b51a0SDaniel Lezcano static inline void play_idle(unsigned long duration_us)
185c55b51a0SDaniel Lezcano {
186c55b51a0SDaniel Lezcano play_idle_precise(duration_us * NSEC_PER_USEC, U64_MAX);
187c55b51a0SDaniel Lezcano }
188c1de45caSPeter Zijlstra
1898038dad7SPaul E. McKenney #ifdef CONFIG_HOTPLUG_CPU
190e69aab13SThomas Gleixner void cpuhp_report_idle_dead(void);
191e69aab13SThomas Gleixner #else
cpuhp_report_idle_dead(void)192e69aab13SThomas Gleixner static inline void cpuhp_report_idle_dead(void) { }
1938038dad7SPaul E. McKenney #endif /* #ifdef CONFIG_HOTPLUG_CPU */
1948038dad7SPaul E. McKenney
195ce0abef6SSean Christopherson #ifdef CONFIG_CPU_MITIGATIONS
196731dc9dfSTyler Hicks extern bool cpu_mitigations_off(void);
197731dc9dfSTyler Hicks extern bool cpu_mitigations_auto_nosmt(void);
198ce0abef6SSean Christopherson #else
cpu_mitigations_off(void)199ce0abef6SSean Christopherson static inline bool cpu_mitigations_off(void)
200ce0abef6SSean Christopherson {
201ce0abef6SSean Christopherson return true;
202ce0abef6SSean Christopherson }
cpu_mitigations_auto_nosmt(void)203ce0abef6SSean Christopherson static inline bool cpu_mitigations_auto_nosmt(void)
204ce0abef6SSean Christopherson {
205ce0abef6SSean Christopherson return false;
206ce0abef6SSean Christopherson }
207ce0abef6SSean Christopherson #endif
20898af8452SJosh Poimboeuf
2091da177e4SLinus Torvalds #endif /* _LINUX_CPU_H_ */
210