processor.h 11 KB

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