/include/linux/cpufreq.h

https://bitbucket.org/thekraven/iscream_thunderc-2.6.35 · C++ Header · 442 lines · 273 code · 92 blank · 77 comment · 8 complexity · 62ea9d1cd448da75fea51a9f8848f8e7 MD5 · raw file

  1. /*
  2. * linux/include/linux/cpufreq.h
  3. *
  4. * Copyright (C) 2001 Russell King
  5. * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _LINUX_CPUFREQ_H
  12. #define _LINUX_CPUFREQ_H
  13. #include <linux/mutex.h>
  14. #include <linux/notifier.h>
  15. #include <linux/threads.h>
  16. #include <linux/device.h>
  17. #include <linux/kobject.h>
  18. #include <linux/sysfs.h>
  19. #include <linux/completion.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/cpumask.h>
  22. #include <asm/div64.h>
  23. #define CPUFREQ_NAME_LEN 16
  24. /*********************************************************************
  25. * CPUFREQ NOTIFIER INTERFACE *
  26. *********************************************************************/
  27. #define CPUFREQ_TRANSITION_NOTIFIER (0)
  28. #define CPUFREQ_POLICY_NOTIFIER (1)
  29. #ifdef CONFIG_CPU_FREQ
  30. int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
  31. int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
  32. #else /* CONFIG_CPU_FREQ */
  33. static inline int cpufreq_register_notifier(struct notifier_block *nb,
  34. unsigned int list)
  35. {
  36. return 0;
  37. }
  38. static inline int cpufreq_unregister_notifier(struct notifier_block *nb,
  39. unsigned int list)
  40. {
  41. return 0;
  42. }
  43. #endif /* CONFIG_CPU_FREQ */
  44. /* if (cpufreq_driver->target) exists, the ->governor decides what frequency
  45. * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
  46. * two generic policies are available:
  47. */
  48. #define CPUFREQ_POLICY_POWERSAVE (1)
  49. #define CPUFREQ_POLICY_PERFORMANCE (2)
  50. /* Frequency values here are CPU kHz so that hardware which doesn't run
  51. * with some frequencies can complain without having to guess what per
  52. * cent / per mille means.
  53. * Maximum transition latency is in nanoseconds - if it's unknown,
  54. * CPUFREQ_ETERNAL shall be used.
  55. */
  56. struct cpufreq_governor;
  57. /* /sys/devices/system/cpu/cpufreq: entry point for global variables */
  58. extern struct kobject *cpufreq_global_kobject;
  59. #define CPUFREQ_ETERNAL (-1)
  60. struct cpufreq_cpuinfo {
  61. unsigned int max_freq;
  62. unsigned int min_freq;
  63. unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
  64. };
  65. struct cpufreq_real_policy {
  66. unsigned int min; /* in kHz */
  67. unsigned int max; /* in kHz */
  68. unsigned int policy; /* see above */
  69. struct cpufreq_governor *governor; /* see below */
  70. };
  71. struct cpufreq_policy {
  72. cpumask_var_t cpus; /* CPUs requiring sw coordination */
  73. cpumask_var_t related_cpus; /* CPUs with any coordination */
  74. unsigned int shared_type; /* ANY or ALL affected CPUs
  75. should set cpufreq */
  76. unsigned int cpu; /* cpu nr of registered CPU */
  77. struct cpufreq_cpuinfo cpuinfo;/* see above */
  78. unsigned int min; /* in kHz */
  79. unsigned int max; /* in kHz */
  80. unsigned int cur; /* in kHz, only needed if cpufreq
  81. * governors are used */
  82. unsigned int policy; /* see above */
  83. struct cpufreq_governor *governor; /* see below */
  84. struct work_struct update; /* if update_policy() needs to be
  85. * called, but you're in IRQ context */
  86. struct cpufreq_real_policy user_policy;
  87. struct kobject kobj;
  88. struct completion kobj_unregister;
  89. };
  90. #define CPUFREQ_ADJUST (0)
  91. #define CPUFREQ_INCOMPATIBLE (1)
  92. #define CPUFREQ_NOTIFY (2)
  93. #define CPUFREQ_START (3)
  94. #define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
  95. #define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
  96. #define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
  97. #define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
  98. /******************** cpufreq transition notifiers *******************/
  99. #define CPUFREQ_PRECHANGE (0)
  100. #define CPUFREQ_POSTCHANGE (1)
  101. #define CPUFREQ_RESUMECHANGE (8)
  102. #define CPUFREQ_SUSPENDCHANGE (9)
  103. struct cpufreq_freqs {
  104. unsigned int cpu; /* cpu nr */
  105. unsigned int old;
  106. unsigned int new;
  107. u8 flags; /* flags of cpufreq_driver, see below. */
  108. };
  109. /**
  110. * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
  111. * @old: old value
  112. * @div: divisor
  113. * @mult: multiplier
  114. *
  115. *
  116. * new = old * mult / div
  117. */
  118. static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
  119. {
  120. #if BITS_PER_LONG == 32
  121. u64 result = ((u64) old) * ((u64) mult);
  122. do_div(result, div);
  123. return (unsigned long) result;
  124. #elif BITS_PER_LONG == 64
  125. unsigned long result = old * ((u64) mult);
  126. result /= div;
  127. return result;
  128. #endif
  129. };
  130. /*********************************************************************
  131. * CPUFREQ GOVERNORS *
  132. *********************************************************************/
  133. #define CPUFREQ_GOV_START 1
  134. #define CPUFREQ_GOV_STOP 2
  135. #define CPUFREQ_GOV_LIMITS 3
  136. struct cpufreq_governor {
  137. char name[CPUFREQ_NAME_LEN];
  138. int (*governor) (struct cpufreq_policy *policy,
  139. unsigned int event);
  140. ssize_t (*show_setspeed) (struct cpufreq_policy *policy,
  141. char *buf);
  142. int (*store_setspeed) (struct cpufreq_policy *policy,
  143. unsigned int freq);
  144. unsigned int max_transition_latency; /* HW must be able to switch to
  145. next freq faster than this value in nano secs or we
  146. will fallback to performance governor */
  147. struct list_head governor_list;
  148. struct module *owner;
  149. };
  150. /* pass a target to the cpufreq driver
  151. */
  152. extern int cpufreq_driver_target(struct cpufreq_policy *policy,
  153. unsigned int target_freq,
  154. unsigned int relation);
  155. extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
  156. unsigned int target_freq,
  157. unsigned int relation);
  158. extern int __cpufreq_driver_getavg(struct cpufreq_policy *policy,
  159. unsigned int cpu);
  160. int cpufreq_register_governor(struct cpufreq_governor *governor);
  161. void cpufreq_unregister_governor(struct cpufreq_governor *governor);
  162. int lock_policy_rwsem_read(int cpu);
  163. int lock_policy_rwsem_write(int cpu);
  164. void unlock_policy_rwsem_read(int cpu);
  165. void unlock_policy_rwsem_write(int cpu);
  166. /*********************************************************************
  167. * CPUFREQ DRIVER INTERFACE *
  168. *********************************************************************/
  169. #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
  170. #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
  171. struct freq_attr;
  172. struct cpufreq_driver {
  173. struct module *owner;
  174. char name[CPUFREQ_NAME_LEN];
  175. u8 flags;
  176. /* needed by all drivers */
  177. int (*init) (struct cpufreq_policy *policy);
  178. int (*verify) (struct cpufreq_policy *policy);
  179. /* define one out of two */
  180. int (*setpolicy) (struct cpufreq_policy *policy);
  181. int (*target) (struct cpufreq_policy *policy,
  182. unsigned int target_freq,
  183. unsigned int relation);
  184. /* should be defined, if possible */
  185. unsigned int (*get) (unsigned int cpu);
  186. /* optional */
  187. unsigned int (*getavg) (struct cpufreq_policy *policy,
  188. unsigned int cpu);
  189. int (*bios_limit) (int cpu, unsigned int *limit);
  190. int (*exit) (struct cpufreq_policy *policy);
  191. int (*suspend) (struct cpufreq_policy *policy, pm_message_t pmsg);
  192. int (*resume) (struct cpufreq_policy *policy);
  193. struct freq_attr **attr;
  194. };
  195. /* flags */
  196. #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
  197. * all ->init() calls failed */
  198. #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
  199. * "constants" aren't affected by
  200. * frequency transitions */
  201. #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
  202. * mismatches */
  203. int cpufreq_register_driver(struct cpufreq_driver *driver_data);
  204. int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
  205. void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
  206. static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
  207. {
  208. if (policy->min < min)
  209. policy->min = min;
  210. if (policy->max < min)
  211. policy->max = min;
  212. if (policy->min > max)
  213. policy->min = max;
  214. if (policy->max > max)
  215. policy->max = max;
  216. if (policy->min > policy->max)
  217. policy->min = policy->max;
  218. return;
  219. }
  220. struct freq_attr {
  221. struct attribute attr;
  222. ssize_t (*show)(struct cpufreq_policy *, char *);
  223. ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
  224. };
  225. #define cpufreq_freq_attr_ro(_name) \
  226. static struct freq_attr _name = \
  227. __ATTR(_name, 0444, show_##_name, NULL)
  228. #define cpufreq_freq_attr_ro_perm(_name, _perm) \
  229. static struct freq_attr _name = \
  230. __ATTR(_name, _perm, show_##_name, NULL)
  231. #define cpufreq_freq_attr_ro_old(_name) \
  232. static struct freq_attr _name##_old = \
  233. __ATTR(_name, 0444, show_##_name##_old, NULL)
  234. #define cpufreq_freq_attr_rw(_name) \
  235. static struct freq_attr _name = \
  236. __ATTR(_name, 0644, show_##_name, store_##_name)
  237. #define cpufreq_freq_attr_rw_old(_name) \
  238. static struct freq_attr _name##_old = \
  239. __ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
  240. struct global_attr {
  241. struct attribute attr;
  242. ssize_t (*show)(struct kobject *kobj,
  243. struct attribute *attr, char *buf);
  244. ssize_t (*store)(struct kobject *a, struct attribute *b,
  245. const char *c, size_t count);
  246. };
  247. #define define_one_global_ro(_name) \
  248. static struct global_attr _name = \
  249. __ATTR(_name, 0444, show_##_name, NULL)
  250. #define define_one_global_rw(_name) \
  251. static struct global_attr _name = \
  252. __ATTR(_name, 0644, show_##_name, store_##_name)
  253. /*********************************************************************
  254. * CPUFREQ 2.6. INTERFACE *
  255. *********************************************************************/
  256. int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
  257. int cpufreq_update_policy(unsigned int cpu);
  258. #ifdef CONFIG_CPU_FREQ
  259. /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
  260. unsigned int cpufreq_get(unsigned int cpu);
  261. #else
  262. static inline unsigned int cpufreq_get(unsigned int cpu)
  263. {
  264. return 0;
  265. }
  266. #endif
  267. /* query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it */
  268. #ifdef CONFIG_CPU_FREQ
  269. unsigned int cpufreq_quick_get(unsigned int cpu);
  270. #else
  271. static inline unsigned int cpufreq_quick_get(unsigned int cpu)
  272. {
  273. return 0;
  274. }
  275. #endif
  276. /*********************************************************************
  277. * CPUFREQ DEFAULT GOVERNOR *
  278. *********************************************************************/
  279. /*
  280. Performance governor is fallback governor if any other gov failed to
  281. auto load due latency restrictions
  282. */
  283. #ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
  284. extern struct cpufreq_governor cpufreq_gov_performance;
  285. #endif
  286. #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
  287. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_performance)
  288. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
  289. extern struct cpufreq_governor cpufreq_gov_powersave;
  290. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_powersave)
  291. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
  292. extern struct cpufreq_governor cpufreq_gov_userspace;
  293. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_userspace)
  294. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
  295. extern struct cpufreq_governor cpufreq_gov_ondemand;
  296. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_ondemand)
  297. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
  298. extern struct cpufreq_governor cpufreq_gov_conservative;
  299. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_conservative)
  300. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_INTERACTIVE)
  301. extern struct cpufreq_governor cpufreq_gov_interactive;
  302. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_interactive)
  303. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_SMARTASS2)
  304. extern struct cpufreq_governor cpufreq_gov_smartass2;
  305. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_smartass2)
  306. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_MSM7K)
  307. extern struct cpufreq_governor cpufreq_gov_msm7k;
  308. #define CPUFREQ_DEFAULT_GOVERNOR (&cpufreq_gov_msm7k)
  309. #endif
  310. /*********************************************************************
  311. * FREQUENCY TABLE HELPERS *
  312. *********************************************************************/
  313. #define CPUFREQ_ENTRY_INVALID ~0
  314. #define CPUFREQ_TABLE_END ~1
  315. struct cpufreq_frequency_table {
  316. unsigned int index; /* any */
  317. unsigned int frequency; /* kHz - doesn't need to be in ascending
  318. * order */
  319. };
  320. int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
  321. struct cpufreq_frequency_table *table);
  322. int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
  323. struct cpufreq_frequency_table *table);
  324. int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
  325. struct cpufreq_frequency_table *table,
  326. unsigned int target_freq,
  327. unsigned int relation,
  328. unsigned int *index);
  329. /* the following 3 funtions are for cpufreq core use only */
  330. struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
  331. struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
  332. void cpufreq_cpu_put (struct cpufreq_policy *data);
  333. /* the following are really really optional */
  334. extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
  335. void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
  336. unsigned int cpu);
  337. void cpufreq_frequency_table_put_attr(unsigned int cpu);
  338. /*********************************************************************
  339. * UNIFIED DEBUG HELPERS *
  340. *********************************************************************/
  341. #define CPUFREQ_DEBUG_CORE 1
  342. #define CPUFREQ_DEBUG_DRIVER 2
  343. #define CPUFREQ_DEBUG_GOVERNOR 4
  344. #ifdef CONFIG_CPU_FREQ_DEBUG
  345. extern void cpufreq_debug_printk(unsigned int type, const char *prefix,
  346. const char *fmt, ...);
  347. #else
  348. #define cpufreq_debug_printk(msg...) do { } while(0)
  349. #endif /* CONFIG_CPU_FREQ_DEBUG */
  350. #endif /* _LINUX_CPUFREQ_H */