0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _LINUX_CPU_H_
0015 #define _LINUX_CPU_H_
0016
0017 #include <linux/node.h>
0018 #include <linux/compiler.h>
0019 #include <linux/cpumask.h>
0020 #include <linux/cpuhotplug.h>
0021
0022 struct device;
0023 struct device_node;
0024 struct attribute_group;
0025
0026 struct cpu {
0027 int node_id;
0028 int hotpluggable;
0029 struct device dev;
0030 };
0031
0032 extern void boot_cpu_init(void);
0033 extern void boot_cpu_hotplug_init(void);
0034 extern void cpu_init(void);
0035 extern void trap_init(void);
0036
0037 extern int register_cpu(struct cpu *cpu, int num);
0038 extern struct device *get_cpu_device(unsigned cpu);
0039 extern bool cpu_is_hotpluggable(unsigned cpu);
0040 extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
0041 extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
0042 int cpu, unsigned int *thread);
0043
0044 extern int cpu_add_dev_attr(struct device_attribute *attr);
0045 extern void cpu_remove_dev_attr(struct device_attribute *attr);
0046
0047 extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
0048 extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
0049
0050 extern ssize_t cpu_show_meltdown(struct device *dev,
0051 struct device_attribute *attr, char *buf);
0052 extern ssize_t cpu_show_spectre_v1(struct device *dev,
0053 struct device_attribute *attr, char *buf);
0054 extern ssize_t cpu_show_spectre_v2(struct device *dev,
0055 struct device_attribute *attr, char *buf);
0056 extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
0057 struct device_attribute *attr, char *buf);
0058 extern ssize_t cpu_show_l1tf(struct device *dev,
0059 struct device_attribute *attr, char *buf);
0060 extern ssize_t cpu_show_mds(struct device *dev,
0061 struct device_attribute *attr, char *buf);
0062 extern ssize_t cpu_show_tsx_async_abort(struct device *dev,
0063 struct device_attribute *attr,
0064 char *buf);
0065 extern ssize_t cpu_show_itlb_multihit(struct device *dev,
0066 struct device_attribute *attr, char *buf);
0067 extern ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf);
0068 extern ssize_t cpu_show_mmio_stale_data(struct device *dev,
0069 struct device_attribute *attr,
0070 char *buf);
0071 extern ssize_t cpu_show_retbleed(struct device *dev,
0072 struct device_attribute *attr, char *buf);
0073
0074 extern __printf(4, 5)
0075 struct device *cpu_device_create(struct device *parent, void *drvdata,
0076 const struct attribute_group **groups,
0077 const char *fmt, ...);
0078 #ifdef CONFIG_HOTPLUG_CPU
0079 extern void unregister_cpu(struct cpu *cpu);
0080 extern ssize_t arch_cpu_probe(const char *, size_t);
0081 extern ssize_t arch_cpu_release(const char *, size_t);
0082 #endif
0083
0084
0085
0086
0087
0088 #define CPU_ONLINE 0x0002
0089 #define CPU_UP_PREPARE 0x0003
0090 #define CPU_DEAD 0x0007
0091 #define CPU_DEAD_FROZEN 0x0008
0092 #define CPU_POST_DEAD 0x0009
0093 #define CPU_BROKEN 0x000B
0094
0095 #ifdef CONFIG_SMP
0096 extern bool cpuhp_tasks_frozen;
0097 int add_cpu(unsigned int cpu);
0098 int cpu_device_up(struct device *dev);
0099 void notify_cpu_starting(unsigned int cpu);
0100 extern void cpu_maps_update_begin(void);
0101 extern void cpu_maps_update_done(void);
0102 int bringup_hibernate_cpu(unsigned int sleep_cpu);
0103 void bringup_nonboot_cpus(unsigned int setup_max_cpus);
0104
0105 #else
0106 #define cpuhp_tasks_frozen 0
0107
0108 static inline void cpu_maps_update_begin(void)
0109 {
0110 }
0111
0112 static inline void cpu_maps_update_done(void)
0113 {
0114 }
0115
0116 static inline int add_cpu(unsigned int cpu) { return 0;}
0117
0118 #endif
0119 extern struct bus_type cpu_subsys;
0120
0121 extern int lockdep_is_cpus_held(void);
0122
0123 #ifdef CONFIG_HOTPLUG_CPU
0124 extern void cpus_write_lock(void);
0125 extern void cpus_write_unlock(void);
0126 extern void cpus_read_lock(void);
0127 extern void cpus_read_unlock(void);
0128 extern int cpus_read_trylock(void);
0129 extern void lockdep_assert_cpus_held(void);
0130 extern void cpu_hotplug_disable(void);
0131 extern void cpu_hotplug_enable(void);
0132 void clear_tasks_mm_cpumask(int cpu);
0133 int remove_cpu(unsigned int cpu);
0134 int cpu_device_down(struct device *dev);
0135 extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
0136
0137 #else
0138
0139 static inline void cpus_write_lock(void) { }
0140 static inline void cpus_write_unlock(void) { }
0141 static inline void cpus_read_lock(void) { }
0142 static inline void cpus_read_unlock(void) { }
0143 static inline int cpus_read_trylock(void) { return true; }
0144 static inline void lockdep_assert_cpus_held(void) { }
0145 static inline void cpu_hotplug_disable(void) { }
0146 static inline void cpu_hotplug_enable(void) { }
0147 static inline int remove_cpu(unsigned int cpu) { return -EPERM; }
0148 static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
0149 #endif
0150
0151 #ifdef CONFIG_PM_SLEEP_SMP
0152 extern int freeze_secondary_cpus(int primary);
0153 extern void thaw_secondary_cpus(void);
0154
0155 static inline int suspend_disable_secondary_cpus(void)
0156 {
0157 int cpu = 0;
0158
0159 if (IS_ENABLED(CONFIG_PM_SLEEP_SMP_NONZERO_CPU))
0160 cpu = -1;
0161
0162 return freeze_secondary_cpus(cpu);
0163 }
0164 static inline void suspend_enable_secondary_cpus(void)
0165 {
0166 return thaw_secondary_cpus();
0167 }
0168
0169 #else
0170 static inline void thaw_secondary_cpus(void) {}
0171 static inline int suspend_disable_secondary_cpus(void) { return 0; }
0172 static inline void suspend_enable_secondary_cpus(void) { }
0173 #endif
0174
0175 void __noreturn cpu_startup_entry(enum cpuhp_state state);
0176
0177 void cpu_idle_poll_ctrl(bool enable);
0178
0179
0180 #define __cpuidle __section(".cpuidle.text")
0181
0182 bool cpu_in_idle(unsigned long pc);
0183
0184 void arch_cpu_idle(void);
0185 void arch_cpu_idle_prepare(void);
0186 void arch_cpu_idle_enter(void);
0187 void arch_cpu_idle_exit(void);
0188 void arch_cpu_idle_dead(void);
0189
0190 int cpu_report_state(int cpu);
0191 int cpu_check_up_prepare(int cpu);
0192 void cpu_set_state_online(int cpu);
0193 void play_idle_precise(u64 duration_ns, u64 latency_ns);
0194
0195 static inline void play_idle(unsigned long duration_us)
0196 {
0197 play_idle_precise(duration_us * NSEC_PER_USEC, U64_MAX);
0198 }
0199
0200 #ifdef CONFIG_HOTPLUG_CPU
0201 bool cpu_wait_death(unsigned int cpu, int seconds);
0202 bool cpu_report_death(void);
0203 void cpuhp_report_idle_dead(void);
0204 #else
0205 static inline void cpuhp_report_idle_dead(void) { }
0206 #endif
0207
0208 enum cpuhp_smt_control {
0209 CPU_SMT_ENABLED,
0210 CPU_SMT_DISABLED,
0211 CPU_SMT_FORCE_DISABLED,
0212 CPU_SMT_NOT_SUPPORTED,
0213 CPU_SMT_NOT_IMPLEMENTED,
0214 };
0215
0216 #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
0217 extern enum cpuhp_smt_control cpu_smt_control;
0218 extern void cpu_smt_disable(bool force);
0219 extern void cpu_smt_check_topology(void);
0220 extern bool cpu_smt_possible(void);
0221 extern int cpuhp_smt_enable(void);
0222 extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
0223 #else
0224 # define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
0225 static inline void cpu_smt_disable(bool force) { }
0226 static inline void cpu_smt_check_topology(void) { }
0227 static inline bool cpu_smt_possible(void) { return false; }
0228 static inline int cpuhp_smt_enable(void) { return 0; }
0229 static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
0230 #endif
0231
0232 extern bool cpu_mitigations_off(void);
0233 extern bool cpu_mitigations_auto_nosmt(void);
0234
0235 #endif