cpufreq.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. *
  8. * $Id: cpufreq.h,v 1.36 2003/01/20 17:31:48 db Exp $
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifndef _LINUX_CPUFREQ_H
  15. #define _LINUX_CPUFREQ_H
  16. #include <linux/mutex.h>
  17. #include <linux/notifier.h>
  18. #include <linux/threads.h>
  19. #include <linux/device.h>
  20. #include <linux/kobject.h>
  21. #include <linux/sysfs.h>
  22. #include <linux/completion.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/cpumask.h>
  25. #include <asm/div64.h>
  26. #define CPUFREQ_NAME_LEN 16
  27. /*********************************************************************
  28. * CPUFREQ NOTIFIER INTERFACE *
  29. *********************************************************************/
  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. #define CPUFREQ_TRANSITION_NOTIFIER (0)
  33. #define CPUFREQ_POLICY_NOTIFIER (1)
  34. /* if (cpufreq_driver->target) exists, the ->governor decides what frequency
  35. * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
  36. * two generic policies are available:
  37. */
  38. #define CPUFREQ_POLICY_POWERSAVE (1)
  39. #define CPUFREQ_POLICY_PERFORMANCE (2)
  40. /* Frequency values here are CPU kHz so that hardware which doesn't run
  41. * with some frequencies can complain without having to guess what per
  42. * cent / per mille means.
  43. * Maximum transition latency is in nanoseconds - if it's unknown,
  44. * CPUFREQ_ETERNAL shall be used.
  45. */
  46. struct cpufreq_governor;
  47. #define CPUFREQ_ETERNAL (-1)
  48. struct cpufreq_cpuinfo {
  49. unsigned int max_freq;
  50. unsigned int min_freq;
  51. unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
  52. };
  53. struct cpufreq_real_policy {
  54. unsigned int min; /* in kHz */
  55. unsigned int max; /* in kHz */
  56. unsigned int policy; /* see above */
  57. struct cpufreq_governor *governor; /* see below */
  58. };
  59. struct cpufreq_policy {
  60. cpumask_t cpus; /* affected CPUs */
  61. unsigned int shared_type; /* ANY or ALL affected CPUs
  62. should set cpufreq */
  63. unsigned int cpu; /* cpu nr of registered CPU */
  64. struct cpufreq_cpuinfo cpuinfo;/* see above */
  65. unsigned int min; /* in kHz */
  66. unsigned int max; /* in kHz */
  67. unsigned int cur; /* in kHz, only needed if cpufreq
  68. * governors are used */
  69. unsigned int policy; /* see above */
  70. struct cpufreq_governor *governor; /* see below */
  71. struct mutex lock; /* CPU ->setpolicy or ->target may
  72. only be called once a time */
  73. struct work_struct update; /* if update_policy() needs to be
  74. * called, but you're in IRQ context */
  75. struct cpufreq_real_policy user_policy;
  76. struct kobject kobj;
  77. struct completion kobj_unregister;
  78. };
  79. #define CPUFREQ_ADJUST (0)
  80. #define CPUFREQ_INCOMPATIBLE (1)
  81. #define CPUFREQ_NOTIFY (2)
  82. #define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
  83. #define CPUFREQ_SHARED_TYPE_HW (1) /* HW does needed coordination */
  84. #define CPUFREQ_SHARED_TYPE_ALL (2) /* All dependent CPUs should set freq */
  85. #define CPUFREQ_SHARED_TYPE_ANY (3) /* Freq can be set from any dependent CPU*/
  86. /******************** cpufreq transition notifiers *******************/
  87. #define CPUFREQ_PRECHANGE (0)
  88. #define CPUFREQ_POSTCHANGE (1)
  89. #define CPUFREQ_RESUMECHANGE (8)
  90. #define CPUFREQ_SUSPENDCHANGE (9)
  91. struct cpufreq_freqs {
  92. unsigned int cpu; /* cpu nr */
  93. unsigned int old;
  94. unsigned int new;
  95. u8 flags; /* flags of cpufreq_driver, see below. */
  96. };
  97. /**
  98. * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch safe)
  99. * @old: old value
  100. * @div: divisor
  101. * @mult: multiplier
  102. *
  103. *
  104. * new = old * mult / div
  105. */
  106. static inline unsigned long cpufreq_scale(unsigned long old, u_int div, u_int mult)
  107. {
  108. #if BITS_PER_LONG == 32
  109. u64 result = ((u64) old) * ((u64) mult);
  110. do_div(result, div);
  111. return (unsigned long) result;
  112. #elif BITS_PER_LONG == 64
  113. unsigned long result = old * ((u64) mult);
  114. result /= div;
  115. return result;
  116. #endif
  117. };
  118. /*********************************************************************
  119. * CPUFREQ GOVERNORS *
  120. *********************************************************************/
  121. #define CPUFREQ_GOV_START 1
  122. #define CPUFREQ_GOV_STOP 2
  123. #define CPUFREQ_GOV_LIMITS 3
  124. struct cpufreq_governor {
  125. char name[CPUFREQ_NAME_LEN];
  126. int (*governor) (struct cpufreq_policy *policy,
  127. unsigned int event);
  128. struct list_head governor_list;
  129. struct module *owner;
  130. };
  131. /* pass a target to the cpufreq driver
  132. */
  133. extern int cpufreq_driver_target(struct cpufreq_policy *policy,
  134. unsigned int target_freq,
  135. unsigned int relation);
  136. extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
  137. unsigned int target_freq,
  138. unsigned int relation);
  139. int cpufreq_register_governor(struct cpufreq_governor *governor);
  140. void cpufreq_unregister_governor(struct cpufreq_governor *governor);
  141. /*********************************************************************
  142. * CPUFREQ DRIVER INTERFACE *
  143. *********************************************************************/
  144. #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
  145. #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
  146. struct freq_attr;
  147. struct cpufreq_driver {
  148. struct module *owner;
  149. char name[CPUFREQ_NAME_LEN];
  150. u8 flags;
  151. /* needed by all drivers */
  152. int (*init) (struct cpufreq_policy *policy);
  153. int (*verify) (struct cpufreq_policy *policy);
  154. /* define one out of two */
  155. int (*setpolicy) (struct cpufreq_policy *policy);
  156. int (*target) (struct cpufreq_policy *policy,
  157. unsigned int target_freq,
  158. unsigned int relation);
  159. /* should be defined, if possible */
  160. unsigned int (*get) (unsigned int cpu);
  161. /* optional */
  162. int (*exit) (struct cpufreq_policy *policy);
  163. int (*suspend) (struct cpufreq_policy *policy, pm_message_t pmsg);
  164. int (*resume) (struct cpufreq_policy *policy);
  165. struct freq_attr **attr;
  166. };
  167. /* flags */
  168. #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
  169. * all ->init() calls failed */
  170. #define CPUFREQ_CONST_LOOPS 0x02 /* loops_per_jiffy or other kernel
  171. * "constants" aren't affected by
  172. * frequency transitions */
  173. #define CPUFREQ_PM_NO_WARN 0x04 /* don't warn on suspend/resume speed
  174. * mismatches */
  175. int cpufreq_register_driver(struct cpufreq_driver *driver_data);
  176. int cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
  177. void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state);
  178. static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max)
  179. {
  180. if (policy->min < min)
  181. policy->min = min;
  182. if (policy->max < min)
  183. policy->max = min;
  184. if (policy->min > max)
  185. policy->min = max;
  186. if (policy->max > max)
  187. policy->max = max;
  188. if (policy->min > policy->max)
  189. policy->min = policy->max;
  190. return;
  191. }
  192. struct freq_attr {
  193. struct attribute attr;
  194. ssize_t (*show)(struct cpufreq_policy *, char *);
  195. ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
  196. };
  197. /*********************************************************************
  198. * CPUFREQ 2.6. INTERFACE *
  199. *********************************************************************/
  200. int cpufreq_set_policy(struct cpufreq_policy *policy);
  201. int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
  202. int cpufreq_update_policy(unsigned int cpu);
  203. /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
  204. unsigned int cpufreq_get(unsigned int cpu);
  205. /* query the last known CPU freq (in kHz). If zero, cpufreq couldn't detect it */
  206. #ifdef CONFIG_CPU_FREQ
  207. unsigned int cpufreq_quick_get(unsigned int cpu);
  208. #else
  209. static inline unsigned int cpufreq_quick_get(unsigned int cpu)
  210. {
  211. return 0;
  212. }
  213. #endif
  214. /*********************************************************************
  215. * CPUFREQ DEFAULT GOVERNOR *
  216. *********************************************************************/
  217. #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
  218. extern struct cpufreq_governor cpufreq_gov_performance;
  219. #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
  220. #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
  221. extern struct cpufreq_governor cpufreq_gov_userspace;
  222. #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
  223. #endif
  224. /*********************************************************************
  225. * FREQUENCY TABLE HELPERS *
  226. *********************************************************************/
  227. #define CPUFREQ_ENTRY_INVALID ~0
  228. #define CPUFREQ_TABLE_END ~1
  229. struct cpufreq_frequency_table {
  230. unsigned int index; /* any */
  231. unsigned int frequency; /* kHz - doesn't need to be in ascending
  232. * order */
  233. };
  234. int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
  235. struct cpufreq_frequency_table *table);
  236. int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
  237. struct cpufreq_frequency_table *table);
  238. int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
  239. struct cpufreq_frequency_table *table,
  240. unsigned int target_freq,
  241. unsigned int relation,
  242. unsigned int *index);
  243. /* the following 3 funtions are for cpufreq core use only */
  244. struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
  245. struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
  246. void cpufreq_cpu_put (struct cpufreq_policy *data);
  247. /* the following are really really optional */
  248. extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
  249. void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
  250. unsigned int cpu);
  251. void cpufreq_frequency_table_put_attr(unsigned int cpu);
  252. /*********************************************************************
  253. * UNIFIED DEBUG HELPERS *
  254. *********************************************************************/
  255. #define CPUFREQ_DEBUG_CORE 1
  256. #define CPUFREQ_DEBUG_DRIVER 2
  257. #define CPUFREQ_DEBUG_GOVERNOR 4
  258. #ifdef CONFIG_CPU_FREQ_DEBUG
  259. extern void cpufreq_debug_printk(unsigned int type, const char *prefix,
  260. const char *fmt, ...);
  261. #else
  262. #define cpufreq_debug_printk(msg...) do { } while(0)
  263. #endif /* CONFIG_CPU_FREQ_DEBUG */
  264. #endif /* _LINUX_CPUFREQ_H */