cpu.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  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
  10. *
  11. * CPUs are exported via sysfs in the devices/system/cpu
  12. * directory.
  13. */
  14. #ifndef _LINUX_CPU_H_
  15. #define _LINUX_CPU_H_
  16. #include <linux/node.h>
  17. #include <linux/compiler.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/cpuhotplug.h>
  20. struct device;
  21. struct device_node;
  22. struct attribute_group;
  23. struct cpu {
  24. int node_id; /* The node which contains the CPU */
  25. int hotpluggable; /* creates sysfs control file if hotpluggable */
  26. struct device dev;
  27. };
  28. extern void boot_cpu_init(void);
  29. extern void boot_cpu_hotplug_init(void);
  30. extern void cpu_init(void);
  31. extern void trap_init(void);
  32. extern int register_cpu(struct cpu *cpu, int num);
  33. extern struct device *get_cpu_device(unsigned cpu);
  34. extern bool cpu_is_hotpluggable(unsigned cpu);
  35. extern bool arch_match_cpu_phys_id(int cpu, u64 phys_id);
  36. extern bool arch_find_n_match_cpu_physical_id(struct device_node *cpun,
  37. int cpu, unsigned int *thread);
  38. extern int cpu_add_dev_attr(struct device_attribute *attr);
  39. extern void cpu_remove_dev_attr(struct device_attribute *attr);
  40. extern int cpu_add_dev_attr_group(struct attribute_group *attrs);
  41. extern void cpu_remove_dev_attr_group(struct attribute_group *attrs);
  42. extern ssize_t cpu_show_meltdown(struct device *dev,
  43. struct device_attribute *attr, char *buf);
  44. extern ssize_t cpu_show_spectre_v1(struct device *dev,
  45. struct device_attribute *attr, char *buf);
  46. extern ssize_t cpu_show_spectre_v2(struct device *dev,
  47. struct device_attribute *attr, char *buf);
  48. extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
  49. struct device_attribute *attr, char *buf);
  50. extern ssize_t cpu_show_l1tf(struct device *dev,
  51. struct device_attribute *attr, char *buf);
  52. extern __printf(4, 5)
  53. struct device *cpu_device_create(struct device *parent, void *drvdata,
  54. const struct attribute_group **groups,
  55. const char *fmt, ...);
  56. #ifdef CONFIG_HOTPLUG_CPU
  57. extern void unregister_cpu(struct cpu *cpu);
  58. extern ssize_t arch_cpu_probe(const char *, size_t);
  59. extern ssize_t arch_cpu_release(const char *, size_t);
  60. #endif
  61. /*
  62. * These states are not related to the core CPU hotplug mechanism. They are
  63. * used by various (sub)architectures to track internal state
  64. */
  65. #define CPU_ONLINE 0x0002 /* CPU is up */
  66. #define CPU_UP_PREPARE 0x0003 /* CPU coming up */
  67. #define CPU_DEAD 0x0007 /* CPU dead */
  68. #define CPU_DEAD_FROZEN 0x0008 /* CPU timed out on unplug */
  69. #define CPU_POST_DEAD 0x0009 /* CPU successfully unplugged */
  70. #define CPU_BROKEN 0x000B /* CPU did not die properly */
  71. #ifdef CONFIG_SMP
  72. extern bool cpuhp_tasks_frozen;
  73. int cpu_up(unsigned int cpu);
  74. void notify_cpu_starting(unsigned int cpu);
  75. extern void cpu_maps_update_begin(void);
  76. extern void cpu_maps_update_done(void);
  77. #else /* CONFIG_SMP */
  78. #define cpuhp_tasks_frozen 0
  79. static inline void cpu_maps_update_begin(void)
  80. {
  81. }
  82. static inline void cpu_maps_update_done(void)
  83. {
  84. }
  85. #endif /* CONFIG_SMP */
  86. extern struct bus_type cpu_subsys;
  87. #ifdef CONFIG_HOTPLUG_CPU
  88. extern void cpus_write_lock(void);
  89. extern void cpus_write_unlock(void);
  90. extern void cpus_read_lock(void);
  91. extern void cpus_read_unlock(void);
  92. extern int cpus_read_trylock(void);
  93. extern void lockdep_assert_cpus_held(void);
  94. extern void cpu_hotplug_disable(void);
  95. extern void cpu_hotplug_enable(void);
  96. void clear_tasks_mm_cpumask(int cpu);
  97. int cpu_down(unsigned int cpu);
  98. #else /* CONFIG_HOTPLUG_CPU */
  99. static inline void cpus_write_lock(void) { }
  100. static inline void cpus_write_unlock(void) { }
  101. static inline void cpus_read_lock(void) { }
  102. static inline void cpus_read_unlock(void) { }
  103. static inline int cpus_read_trylock(void) { return true; }
  104. static inline void lockdep_assert_cpus_held(void) { }
  105. static inline void cpu_hotplug_disable(void) { }
  106. static inline void cpu_hotplug_enable(void) { }
  107. #endif /* !CONFIG_HOTPLUG_CPU */
  108. /* Wrappers which go away once all code is converted */
  109. static inline void cpu_hotplug_begin(void) { cpus_write_lock(); }
  110. static inline void cpu_hotplug_done(void) { cpus_write_unlock(); }
  111. static inline void get_online_cpus(void) { cpus_read_lock(); }
  112. static inline void put_online_cpus(void) { cpus_read_unlock(); }
  113. #ifdef CONFIG_PM_SLEEP_SMP
  114. extern int freeze_secondary_cpus(int primary);
  115. static inline int disable_nonboot_cpus(void)
  116. {
  117. return freeze_secondary_cpus(0);
  118. }
  119. extern void enable_nonboot_cpus(void);
  120. #else /* !CONFIG_PM_SLEEP_SMP */
  121. static inline int disable_nonboot_cpus(void) { return 0; }
  122. static inline void enable_nonboot_cpus(void) {}
  123. #endif /* !CONFIG_PM_SLEEP_SMP */
  124. void cpu_startup_entry(enum cpuhp_state state);
  125. void cpu_idle_poll_ctrl(bool enable);
  126. /* Attach to any functions which should be considered cpuidle. */
  127. #define __cpuidle __attribute__((__section__(".cpuidle.text")))
  128. bool cpu_in_idle(unsigned long pc);
  129. void arch_cpu_idle(void);
  130. void arch_cpu_idle_prepare(void);
  131. void arch_cpu_idle_enter(void);
  132. void arch_cpu_idle_exit(void);
  133. void arch_cpu_idle_dead(void);
  134. int cpu_report_state(int cpu);
  135. int cpu_check_up_prepare(int cpu);
  136. void cpu_set_state_online(int cpu);
  137. void play_idle(unsigned long duration_ms);
  138. #ifdef CONFIG_HOTPLUG_CPU
  139. bool cpu_wait_death(unsigned int cpu, int seconds);
  140. bool cpu_report_death(void);
  141. void cpuhp_report_idle_dead(void);
  142. #else
  143. static inline void cpuhp_report_idle_dead(void) { }
  144. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  145. enum cpuhp_smt_control {
  146. CPU_SMT_ENABLED,
  147. CPU_SMT_DISABLED,
  148. CPU_SMT_FORCE_DISABLED,
  149. CPU_SMT_NOT_SUPPORTED,
  150. };
  151. #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
  152. extern enum cpuhp_smt_control cpu_smt_control;
  153. extern void cpu_smt_disable(bool force);
  154. extern void cpu_smt_check_topology_early(void);
  155. extern void cpu_smt_check_topology(void);
  156. #else
  157. # define cpu_smt_control (CPU_SMT_ENABLED)
  158. static inline void cpu_smt_disable(bool force) { }
  159. static inline void cpu_smt_check_topology_early(void) { }
  160. static inline void cpu_smt_check_topology(void) { }
  161. #endif
  162. #endif /* _LINUX_CPU_H_ */