processor.h 12 KB

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