Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * include/linux/cpu.h - generic cpu definition |
| 4 | * |
| 5 | * This is mainly for topological representation. We define the |
| 6 | * basic 'struct cpu' here, which can be embedded in per-arch |
| 7 | * definitions of processors. |
| 8 | * |
| 9 | * Basic handling of the devices is done in drivers/base/cpu.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
Robert P. J. Day | 611a75e1 | 2013-05-03 06:45:48 -0400 | [diff] [blame] | 11 | * CPUs are exported via sysfs in the devices/system/cpu |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * directory. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | #ifndef _LINUX_CPU_H_ |
| 15 | #define _LINUX_CPU_H_ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/node.h> |
| 18 | #include <linux/compiler.h> |
| 19 | #include <linux/cpumask.h> |
Thomas Gleixner | cff7d37 | 2016-02-26 18:43:28 +0000 | [diff] [blame] | 20 | #include <linux/cpuhotplug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 22 | struct device; |
David Miller | d1cb9d1 | 2013-10-03 17:24:51 -0400 | [diff] [blame] | 23 | struct device_node; |
Sudeep Holla | 3d52943 | 2014-09-30 14:48:24 +0100 | [diff] [blame] | 24 | struct attribute_group; |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | struct cpu { |
| 27 | int node_id; /* The node which contains the CPU */ |
Siddha, Suresh B | 72486f1 | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 28 | int hotpluggable; /* creates sysfs control file if hotpluggable */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 29 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Thomas Gleixner | cff7d37 | 2016-02-26 18:43:28 +0000 | [diff] [blame] | 32 | extern void boot_cpu_init(void); |
| 33 | extern void boot_cpu_state_init(void); |
Ingo Molnar | 1777e46 | 2017-02-05 14:47:12 +0100 | [diff] [blame] | 34 | extern void cpu_init(void); |
| 35 | extern void trap_init(void); |
Thomas Gleixner | cff7d37 | 2016-02-26 18:43:28 +0000 | [diff] [blame] | 36 | |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 37 | extern int register_cpu(struct cpu *cpu, int num); |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 38 | extern struct device *get_cpu_device(unsigned cpu); |
Josh Triplett | 2987557 | 2011-12-03 13:06:50 -0800 | [diff] [blame] | 39 | extern bool cpu_is_hotpluggable(unsigned cpu); |
Sudeep KarkadaNagesha | 183912d | 2013-08-15 14:01:40 +0100 | [diff] [blame] | 40 | extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id); |
David Miller | d1cb9d1 | 2013-10-03 17:24:51 -0400 | [diff] [blame] | 41 | extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun, |
| 42 | int cpu, unsigned int *thread); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 43 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 44 | extern int cpu_add_dev_attr(struct device_attribute *attr); |
| 45 | extern void cpu_remove_dev_attr(struct device_attribute *attr); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 46 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 47 | extern int cpu_add_dev_attr_group(struct attribute_group *attrs); |
| 48 | extern void cpu_remove_dev_attr_group(struct attribute_group *attrs); |
Christian Krafft | 0344c6c | 2006-10-24 18:31:24 +0200 | [diff] [blame] | 49 | |
Thomas Gleixner | 87590ce | 2018-01-07 22:48:00 +0100 | [diff] [blame] | 50 | extern ssize_t cpu_show_meltdown(struct device *dev, |
| 51 | struct device_attribute *attr, char *buf); |
| 52 | extern ssize_t cpu_show_spectre_v1(struct device *dev, |
| 53 | struct device_attribute *attr, char *buf); |
| 54 | extern ssize_t cpu_show_spectre_v2(struct device *dev, |
| 55 | struct device_attribute *attr, char *buf); |
Konrad Rzeszutek Wilk | c456442 | 2018-04-25 22:04:20 -0400 | [diff] [blame] | 56 | extern ssize_t cpu_show_spec_store_bypass(struct device *dev, |
| 57 | struct device_attribute *attr, char *buf); |
Andi Kleen | 17dbca1 | 2018-06-13 15:48:26 -0700 | [diff] [blame] | 58 | extern ssize_t cpu_show_l1tf(struct device *dev, |
| 59 | struct device_attribute *attr, char *buf); |
Thomas Gleixner | 87590ce | 2018-01-07 22:48:00 +0100 | [diff] [blame] | 60 | |
Nicolas Iooss | 8db1486 | 2015-07-17 16:23:42 -0700 | [diff] [blame] | 61 | extern __printf(4, 5) |
| 62 | struct device *cpu_device_create(struct device *parent, void *drvdata, |
| 63 | const struct attribute_group **groups, |
| 64 | const char *fmt, ...); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_HOTPLUG_CPU |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 66 | extern void unregister_cpu(struct cpu *cpu); |
Nathan Fontenot | 12633e8 | 2009-11-25 17:23:25 +0000 | [diff] [blame] | 67 | extern ssize_t arch_cpu_probe(const char *, size_t); |
| 68 | extern ssize_t arch_cpu_release(const char *, size_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Thomas Gleixner | f4c09f8 | 2017-11-13 09:39:01 +0100 | [diff] [blame] | 71 | /* |
| 72 | * These states are not related to the core CPU hotplug mechanism. They are |
| 73 | * used by various (sub)architectures to track internal state |
Amerigo Wang | 80f1ff9 | 2011-07-25 17:13:08 -0700 | [diff] [blame] | 74 | */ |
Thomas Gleixner | f4c09f8 | 2017-11-13 09:39:01 +0100 | [diff] [blame] | 75 | #define CPU_ONLINE 0x0002 /* CPU is up */ |
| 76 | #define CPU_UP_PREPARE 0x0003 /* CPU coming up */ |
| 77 | #define CPU_DEAD 0x0007 /* CPU dead */ |
| 78 | #define CPU_DEAD_FROZEN 0x0008 /* CPU timed out on unplug */ |
| 79 | #define CPU_POST_DEAD 0x0009 /* CPU successfully unplugged */ |
| 80 | #define CPU_BROKEN 0x000B /* CPU did not die properly */ |
Amerigo Wang | 80f1ff9 | 2011-07-25 17:13:08 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #ifdef CONFIG_SMP |
Thomas Gleixner | 090e77c | 2016-02-26 18:43:23 +0000 | [diff] [blame] | 83 | extern bool cpuhp_tasks_frozen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | int cpu_up(unsigned int cpu); |
Manfred Spraul | e545a61 | 2008-09-07 16:57:22 +0200 | [diff] [blame] | 85 | void notify_cpu_starting(unsigned int cpu); |
Oleg Nesterov | 3da1c84 | 2008-07-25 01:47:50 -0700 | [diff] [blame] | 86 | extern void cpu_maps_update_begin(void); |
| 87 | extern void cpu_maps_update_done(void); |
Ingo Molnar | d0d23b5 | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 88 | |
Oleg Nesterov | 3da1c84 | 2008-07-25 01:47:50 -0700 | [diff] [blame] | 89 | #else /* CONFIG_SMP */ |
Thomas Gleixner | 090e77c | 2016-02-26 18:43:23 +0000 | [diff] [blame] | 90 | #define cpuhp_tasks_frozen 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Oleg Nesterov | 3da1c84 | 2008-07-25 01:47:50 -0700 | [diff] [blame] | 92 | static inline void cpu_maps_update_begin(void) |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | static inline void cpu_maps_update_done(void) |
| 97 | { |
| 98 | } |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif /* CONFIG_SMP */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 101 | extern struct bus_type cpu_subsys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_HOTPLUG_CPU |
Thomas Gleixner | 8f553c4 | 2017-05-24 10:15:12 +0200 | [diff] [blame] | 104 | extern void cpus_write_lock(void); |
| 105 | extern void cpus_write_unlock(void); |
| 106 | extern void cpus_read_lock(void); |
| 107 | extern void cpus_read_unlock(void); |
Thomas Gleixner | fc8dffd | 2017-05-24 10:15:40 +0200 | [diff] [blame] | 108 | extern void lockdep_assert_cpus_held(void); |
Srivatsa S. Bhat | 16e53db | 2013-06-12 14:04:36 -0700 | [diff] [blame] | 109 | extern void cpu_hotplug_disable(void); |
| 110 | extern void cpu_hotplug_enable(void); |
Anton Vorontsov | cb79295 | 2012-05-31 16:26:22 -0700 | [diff] [blame] | 111 | void clear_tasks_mm_cpumask(int cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int cpu_down(unsigned int cpu); |
Gautham R Shenoy | f7dff2b | 2006-12-06 20:38:58 -0800 | [diff] [blame] | 113 | |
Thomas Gleixner | 8f553c4 | 2017-05-24 10:15:12 +0200 | [diff] [blame] | 114 | #else /* CONFIG_HOTPLUG_CPU */ |
Gautham R Shenoy | f7dff2b | 2006-12-06 20:38:58 -0800 | [diff] [blame] | 115 | |
Thomas Gleixner | 8f553c4 | 2017-05-24 10:15:12 +0200 | [diff] [blame] | 116 | static inline void cpus_write_lock(void) { } |
| 117 | static inline void cpus_write_unlock(void) { } |
| 118 | static inline void cpus_read_lock(void) { } |
| 119 | static inline void cpus_read_unlock(void) { } |
Thomas Gleixner | ade3f68 | 2017-05-24 10:15:13 +0200 | [diff] [blame] | 120 | static inline void lockdep_assert_cpus_held(void) { } |
Thomas Gleixner | 8f553c4 | 2017-05-24 10:15:12 +0200 | [diff] [blame] | 121 | static inline void cpu_hotplug_disable(void) { } |
| 122 | static inline void cpu_hotplug_enable(void) { } |
| 123 | #endif /* !CONFIG_HOTPLUG_CPU */ |
| 124 | |
| 125 | /* Wrappers which go away once all code is converted */ |
| 126 | static inline void cpu_hotplug_begin(void) { cpus_write_lock(); } |
| 127 | static inline void cpu_hotplug_done(void) { cpus_write_unlock(); } |
| 128 | static inline void get_online_cpus(void) { cpus_read_lock(); } |
| 129 | static inline void put_online_cpus(void) { cpus_read_unlock(); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Rafael J. Wysocki | f3de4be | 2007-08-30 23:56:29 -0700 | [diff] [blame] | 131 | #ifdef CONFIG_PM_SLEEP_SMP |
James Morse | d391e55 | 2016-08-17 13:50:25 +0100 | [diff] [blame] | 132 | extern int freeze_secondary_cpus(int primary); |
| 133 | static inline int disable_nonboot_cpus(void) |
| 134 | { |
| 135 | return freeze_secondary_cpus(0); |
| 136 | } |
Rafael J. Wysocki | e3920fb | 2006-09-25 23:32:48 -0700 | [diff] [blame] | 137 | extern void enable_nonboot_cpus(void); |
Rafael J. Wysocki | f3de4be | 2007-08-30 23:56:29 -0700 | [diff] [blame] | 138 | #else /* !CONFIG_PM_SLEEP_SMP */ |
Rafael J. Wysocki | e3920fb | 2006-09-25 23:32:48 -0700 | [diff] [blame] | 139 | static inline int disable_nonboot_cpus(void) { return 0; } |
| 140 | static inline void enable_nonboot_cpus(void) {} |
Rafael J. Wysocki | f3de4be | 2007-08-30 23:56:29 -0700 | [diff] [blame] | 141 | #endif /* !CONFIG_PM_SLEEP_SMP */ |
Rafael J. Wysocki | e3920fb | 2006-09-25 23:32:48 -0700 | [diff] [blame] | 142 | |
Thomas Gleixner | a1a04ec | 2013-03-21 22:49:34 +0100 | [diff] [blame] | 143 | void cpu_startup_entry(enum cpuhp_state state); |
Thomas Gleixner | a1a04ec | 2013-03-21 22:49:34 +0100 | [diff] [blame] | 144 | |
Thomas Gleixner | d166991 | 2013-03-21 22:49:35 +0100 | [diff] [blame] | 145 | void cpu_idle_poll_ctrl(bool enable); |
| 146 | |
Chris Metcalf | 6727ad9 | 2016-10-07 17:02:55 -0700 | [diff] [blame] | 147 | /* Attach to any functions which should be considered cpuidle. */ |
| 148 | #define __cpuidle __attribute__((__section__(".cpuidle.text"))) |
| 149 | |
| 150 | bool cpu_in_idle(unsigned long pc); |
| 151 | |
Thomas Gleixner | d166991 | 2013-03-21 22:49:35 +0100 | [diff] [blame] | 152 | void arch_cpu_idle(void); |
| 153 | void arch_cpu_idle_prepare(void); |
| 154 | void arch_cpu_idle_enter(void); |
| 155 | void arch_cpu_idle_exit(void); |
| 156 | void arch_cpu_idle_dead(void); |
| 157 | |
Paul E. McKenney | 8038dad | 2015-02-25 10:34:39 -0800 | [diff] [blame] | 158 | int cpu_report_state(int cpu); |
| 159 | int cpu_check_up_prepare(int cpu); |
| 160 | void cpu_set_state_online(int cpu); |
Peter Zijlstra | c1de45c | 2016-11-28 23:03:05 -0800 | [diff] [blame] | 161 | void play_idle(unsigned long duration_ms); |
| 162 | |
Paul E. McKenney | 8038dad | 2015-02-25 10:34:39 -0800 | [diff] [blame] | 163 | #ifdef CONFIG_HOTPLUG_CPU |
| 164 | bool cpu_wait_death(unsigned int cpu, int seconds); |
| 165 | bool cpu_report_death(void); |
Thomas Gleixner | e69aab1 | 2016-02-26 18:43:43 +0000 | [diff] [blame] | 166 | void cpuhp_report_idle_dead(void); |
| 167 | #else |
| 168 | static inline void cpuhp_report_idle_dead(void) { } |
Paul E. McKenney | 8038dad | 2015-02-25 10:34:39 -0800 | [diff] [blame] | 169 | #endif /* #ifdef CONFIG_HOTPLUG_CPU */ |
| 170 | |
Thomas Gleixner | 05736e4 | 2018-05-29 17:48:27 +0200 | [diff] [blame] | 171 | enum cpuhp_smt_control { |
| 172 | CPU_SMT_ENABLED, |
| 173 | CPU_SMT_DISABLED, |
| 174 | CPU_SMT_FORCE_DISABLED, |
| 175 | CPU_SMT_NOT_SUPPORTED, |
| 176 | }; |
| 177 | |
| 178 | #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT) |
| 179 | extern enum cpuhp_smt_control cpu_smt_control; |
Jiri Kosina | 8e1b706 | 2018-07-13 16:23:23 +0200 | [diff] [blame^] | 180 | extern void cpu_smt_disable(bool force); |
Thomas Gleixner | 05736e4 | 2018-05-29 17:48:27 +0200 | [diff] [blame] | 181 | #else |
| 182 | # define cpu_smt_control (CPU_SMT_ENABLED) |
Jiri Kosina | 8e1b706 | 2018-07-13 16:23:23 +0200 | [diff] [blame^] | 183 | static inline void cpu_smt_disable(bool force) { } |
Thomas Gleixner | 05736e4 | 2018-05-29 17:48:27 +0200 | [diff] [blame] | 184 | #endif |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | #endif /* _LINUX_CPU_H_ */ |