processor.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ACPI_PROCESSOR_H
  3. #define __ACPI_PROCESSOR_H
  4. #include <linux/kernel.h>
  5. #include <linux/cpu.h>
  6. #include <linux/thermal.h>
  7. #include <asm/acpi.h>
  8. #define ACPI_PROCESSOR_CLASS "processor"
  9. #define ACPI_PROCESSOR_DEVICE_NAME "Processor"
  10. #define ACPI_PROCESSOR_DEVICE_HID "ACPI0007"
  11. #define ACPI_PROCESSOR_CONTAINER_HID "ACPI0010"
  12. #define ACPI_PROCESSOR_BUSY_METRIC 10
  13. #define ACPI_PROCESSOR_MAX_POWER 8
  14. #define ACPI_PROCESSOR_MAX_C2_LATENCY 100
  15. #define ACPI_PROCESSOR_MAX_C3_LATENCY 1000
  16. #define ACPI_PROCESSOR_MAX_THROTTLING 16
  17. #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */
  18. #define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4
  19. #define ACPI_PDC_REVISION_ID 0x1
  20. #define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
  21. #define ACPI_PSD_REV0_ENTRIES 5
  22. #define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
  23. #define ACPI_TSD_REV0_ENTRIES 5
  24. /*
  25. * Types of coordination defined in ACPI 3.0. Same macros can be used across
  26. * P, C and T states
  27. */
  28. #define DOMAIN_COORD_TYPE_SW_ALL 0xfc
  29. #define DOMAIN_COORD_TYPE_SW_ANY 0xfd
  30. #define DOMAIN_COORD_TYPE_HW_ALL 0xfe
  31. #define ACPI_CSTATE_SYSTEMIO 0
  32. #define ACPI_CSTATE_FFH 1
  33. #define ACPI_CSTATE_HALT 2
  34. #define ACPI_CSTATE_INTEGER 3
  35. #define ACPI_CX_DESC_LEN 32
  36. /* Power Management */
  37. struct acpi_processor_cx;
  38. struct acpi_power_register {
  39. u8 descriptor;
  40. u16 length;
  41. u8 space_id;
  42. u8 bit_width;
  43. u8 bit_offset;
  44. u8 access_size;
  45. u64 address;
  46. } __packed;
  47. struct acpi_processor_cx {
  48. u8 valid;
  49. u8 type;
  50. u32 address;
  51. u8 entry_method;
  52. u8 index;
  53. u32 latency;
  54. u8 bm_sts_skip;
  55. char desc[ACPI_CX_DESC_LEN];
  56. };
  57. struct acpi_lpi_state {
  58. u32 min_residency;
  59. u32 wake_latency; /* worst case */
  60. u32 flags;
  61. u32 arch_flags;
  62. u32 res_cnt_freq;
  63. u32 enable_parent_state;
  64. u64 address;
  65. u8 index;
  66. u8 entry_method;
  67. char desc[ACPI_CX_DESC_LEN];
  68. };
  69. struct acpi_processor_power {
  70. int count;
  71. union {
  72. struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
  73. struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER];
  74. };
  75. int timer_broadcast_on_state;
  76. };
  77. /* Performance Management */
  78. struct acpi_psd_package {
  79. u64 num_entries;
  80. u64 revision;
  81. u64 domain;
  82. u64 coord_type;
  83. u64 num_processors;
  84. } __packed;
  85. struct acpi_pct_register {
  86. u8 descriptor;
  87. u16 length;
  88. u8 space_id;
  89. u8 bit_width;
  90. u8 bit_offset;
  91. u8 reserved;
  92. u64 address;
  93. } __packed;
  94. struct acpi_processor_px {
  95. u64 core_frequency; /* megahertz */
  96. u64 power; /* milliWatts */
  97. u64 transition_latency; /* microseconds */
  98. u64 bus_master_latency; /* microseconds */
  99. u64 control; /* control value */
  100. u64 status; /* success indicator */
  101. };
  102. struct acpi_processor_performance {
  103. unsigned int state;
  104. unsigned int platform_limit;
  105. struct acpi_pct_register control_register;
  106. struct acpi_pct_register status_register;
  107. unsigned int state_count;
  108. struct acpi_processor_px *states;
  109. struct acpi_psd_package domain_info;
  110. cpumask_var_t shared_cpu_map;
  111. unsigned int shared_type;
  112. };
  113. /* Throttling Control */
  114. struct acpi_tsd_package {
  115. u64 num_entries;
  116. u64 revision;
  117. u64 domain;
  118. u64 coord_type;
  119. u64 num_processors;
  120. } __packed;
  121. struct acpi_ptc_register {
  122. u8 descriptor;
  123. u16 length;
  124. u8 space_id;
  125. u8 bit_width;
  126. u8 bit_offset;
  127. u8 reserved;
  128. u64 address;
  129. } __packed;
  130. struct acpi_processor_tx_tss {
  131. u64 freqpercentage; /* */
  132. u64 power; /* milliWatts */
  133. u64 transition_latency; /* microseconds */
  134. u64 control; /* control value */
  135. u64 status; /* success indicator */
  136. };
  137. struct acpi_processor_tx {
  138. u16 power;
  139. u16 performance;
  140. };
  141. struct acpi_processor;
  142. struct acpi_processor_throttling {
  143. unsigned int state;
  144. unsigned int platform_limit;
  145. struct acpi_pct_register control_register;
  146. struct acpi_pct_register status_register;
  147. unsigned int state_count;
  148. struct acpi_processor_tx_tss *states_tss;
  149. struct acpi_tsd_package domain_info;
  150. cpumask_var_t shared_cpu_map;
  151. int (*acpi_processor_get_throttling) (struct acpi_processor * pr);
  152. int (*acpi_processor_set_throttling) (struct acpi_processor * pr,
  153. int state, bool force);
  154. u32 address;
  155. u8 duty_offset;
  156. u8 duty_width;
  157. u8 tsd_valid_flag;
  158. unsigned int shared_type;
  159. struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
  160. };
  161. /* Limit Interface */
  162. struct acpi_processor_lx {
  163. int px; /* performance state */
  164. int tx; /* throttle level */
  165. };
  166. struct acpi_processor_limit {
  167. struct acpi_processor_lx state; /* current limit */
  168. struct acpi_processor_lx thermal; /* thermal limit */
  169. struct acpi_processor_lx user; /* user limit */
  170. };
  171. struct acpi_processor_flags {
  172. u8 power:1;
  173. u8 performance:1;
  174. u8 throttling:1;
  175. u8 limit:1;
  176. u8 bm_control:1;
  177. u8 bm_check:1;
  178. u8 has_cst:1;
  179. u8 has_lpi:1;
  180. u8 power_setup_done:1;
  181. u8 bm_rld_set:1;
  182. u8 need_hotplug_init:1;
  183. };
  184. struct acpi_processor {
  185. acpi_handle handle;
  186. u32 acpi_id;
  187. phys_cpuid_t phys_id; /* CPU hardware ID such as APIC ID for x86 */
  188. u32 id; /* CPU logical ID allocated by OS */
  189. u32 pblk;
  190. int performance_platform_limit;
  191. int throttling_platform_limit;
  192. /* 0 - states 0..n-th state available */
  193. struct acpi_processor_flags flags;
  194. struct acpi_processor_power power;
  195. struct acpi_processor_performance *performance;
  196. struct acpi_processor_throttling throttling;
  197. struct acpi_processor_limit limit;
  198. struct thermal_cooling_device *cdev;
  199. struct device *dev; /* Processor device. */
  200. };
  201. struct acpi_processor_errata {
  202. u8 smp;
  203. struct {
  204. u8 throttle:1;
  205. u8 fdma:1;
  206. u8 reserved:6;
  207. u32 bmisx;
  208. } piix4;
  209. };
  210. extern int acpi_processor_preregister_performance(struct
  211. acpi_processor_performance
  212. __percpu *performance);
  213. extern int acpi_processor_register_performance(struct acpi_processor_performance
  214. *performance, unsigned int cpu);
  215. extern void acpi_processor_unregister_performance(unsigned int cpu);
  216. int acpi_processor_pstate_control(void);
  217. /* note: this locks both the calling module and the processor module
  218. if a _PPC object exists, rmmod is disallowed then */
  219. int acpi_processor_notify_smm(struct module *calling_module);
  220. /* parsing the _P* objects. */
  221. extern int acpi_processor_get_performance_info(struct acpi_processor *pr);
  222. /* for communication between multiple parts of the processor kernel module */
  223. DECLARE_PER_CPU(struct acpi_processor *, processors);
  224. extern struct acpi_processor_errata errata;
  225. #if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
  226. void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
  227. unsigned int cpu);
  228. int acpi_processor_ffh_cstate_probe(unsigned int cpu,
  229. struct acpi_processor_cx *cx,
  230. struct acpi_power_register *reg);
  231. void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
  232. #else
  233. static inline void acpi_processor_power_init_bm_check(struct
  234. acpi_processor_flags
  235. *flags, unsigned int cpu)
  236. {
  237. flags->bm_check = 1;
  238. return;
  239. }
  240. static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
  241. struct acpi_processor_cx *cx,
  242. struct acpi_power_register
  243. *reg)
  244. {
  245. return -1;
  246. }
  247. static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
  248. *cstate)
  249. {
  250. return;
  251. }
  252. #endif
  253. static inline int call_on_cpu(int cpu, long (*fn)(void *), void *arg,
  254. bool direct)
  255. {
  256. if (direct || (is_percpu_thread() && cpu == smp_processor_id()))
  257. return fn(arg);
  258. return work_on_cpu(cpu, fn, arg);
  259. }
  260. /* in processor_perflib.c */
  261. #ifdef CONFIG_CPU_FREQ
  262. void acpi_processor_ppc_init(void);
  263. void acpi_processor_ppc_exit(void);
  264. void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag);
  265. extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit);
  266. #else
  267. static inline void acpi_processor_ppc_init(void)
  268. {
  269. return;
  270. }
  271. static inline void acpi_processor_ppc_exit(void)
  272. {
  273. return;
  274. }
  275. static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr,
  276. int event_flag)
  277. {
  278. static unsigned int printout = 1;
  279. if (printout) {
  280. printk(KERN_WARNING
  281. "Warning: Processor Platform Limit event detected, but not handled.\n");
  282. printk(KERN_WARNING
  283. "Consider compiling CPUfreq support into your kernel.\n");
  284. printout = 0;
  285. }
  286. return 0;
  287. }
  288. static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
  289. {
  290. return -ENODEV;
  291. }
  292. #endif /* CONFIG_CPU_FREQ */
  293. /* in processor_core.c */
  294. phys_cpuid_t acpi_get_phys_id(acpi_handle, int type, u32 acpi_id);
  295. phys_cpuid_t acpi_map_madt_entry(u32 acpi_id);
  296. int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id);
  297. int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
  298. #ifdef CONFIG_ACPI_CPPC_LIB
  299. extern int acpi_cppc_processor_probe(struct acpi_processor *pr);
  300. extern void acpi_cppc_processor_exit(struct acpi_processor *pr);
  301. #else
  302. static inline int acpi_cppc_processor_probe(struct acpi_processor *pr)
  303. {
  304. return 0;
  305. }
  306. static inline void acpi_cppc_processor_exit(struct acpi_processor *pr)
  307. {
  308. return;
  309. }
  310. #endif /* CONFIG_ACPI_CPPC_LIB */
  311. /* in processor_pdc.c */
  312. void acpi_processor_set_pdc(acpi_handle handle);
  313. /* in processor_throttling.c */
  314. #ifdef CONFIG_ACPI_CPU_FREQ_PSS
  315. int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
  316. int acpi_processor_get_throttling_info(struct acpi_processor *pr);
  317. extern int acpi_processor_set_throttling(struct acpi_processor *pr,
  318. int state, bool force);
  319. /*
  320. * Reevaluate whether the T-state is invalid after one cpu is
  321. * onlined/offlined. In such case the flags.throttling will be updated.
  322. */
  323. extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
  324. bool is_dead);
  325. extern const struct file_operations acpi_processor_throttling_fops;
  326. extern void acpi_processor_throttling_init(void);
  327. #else
  328. static inline int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
  329. {
  330. return 0;
  331. }
  332. static inline int acpi_processor_get_throttling_info(struct acpi_processor *pr)
  333. {
  334. return -ENODEV;
  335. }
  336. static inline int acpi_processor_set_throttling(struct acpi_processor *pr,
  337. int state, bool force)
  338. {
  339. return -ENODEV;
  340. }
  341. static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
  342. bool is_dead) {}
  343. static inline void acpi_processor_throttling_init(void) {}
  344. #endif /* CONFIG_ACPI_CPU_FREQ_PSS */
  345. /* in processor_idle.c */
  346. extern struct cpuidle_driver acpi_idle_driver;
  347. #ifdef CONFIG_ACPI_PROCESSOR_IDLE
  348. int acpi_processor_power_init(struct acpi_processor *pr);
  349. int acpi_processor_power_exit(struct acpi_processor *pr);
  350. int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
  351. int acpi_processor_hotplug(struct acpi_processor *pr);
  352. #else
  353. static inline int acpi_processor_power_init(struct acpi_processor *pr)
  354. {
  355. return -ENODEV;
  356. }
  357. static inline int acpi_processor_power_exit(struct acpi_processor *pr)
  358. {
  359. return -ENODEV;
  360. }
  361. static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
  362. {
  363. return -ENODEV;
  364. }
  365. static inline int acpi_processor_hotplug(struct acpi_processor *pr)
  366. {
  367. return -ENODEV;
  368. }
  369. #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
  370. /* in processor_thermal.c */
  371. int acpi_processor_get_limit_info(struct acpi_processor *pr);
  372. extern const struct thermal_cooling_device_ops processor_cooling_ops;
  373. #if defined(CONFIG_ACPI_CPU_FREQ_PSS) & defined(CONFIG_CPU_FREQ)
  374. void acpi_thermal_cpufreq_init(void);
  375. void acpi_thermal_cpufreq_exit(void);
  376. #else
  377. static inline void acpi_thermal_cpufreq_init(void)
  378. {
  379. return;
  380. }
  381. static inline void acpi_thermal_cpufreq_exit(void)
  382. {
  383. return;
  384. }
  385. #endif /* CONFIG_ACPI_CPU_FREQ_PSS */
  386. #endif