cpufreq.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
  3. *
  4. * Licensed under the terms of the GNU GPL License version 2.
  5. */
  6. #include <stdio.h>
  7. #include <errno.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "cpufreq.h"
  11. #include "sysfs.h"
  12. int cpufreq_cpu_exists(unsigned int cpu)
  13. {
  14. return sysfs_cpu_exists(cpu);
  15. }
  16. unsigned long cpufreq_get_freq_kernel(unsigned int cpu)
  17. {
  18. return sysfs_get_freq_kernel(cpu);
  19. }
  20. unsigned long cpufreq_get_freq_hardware(unsigned int cpu)
  21. {
  22. return sysfs_get_freq_hardware(cpu);
  23. }
  24. unsigned long cpufreq_get_transition_latency(unsigned int cpu)
  25. {
  26. return sysfs_get_freq_transition_latency(cpu);
  27. }
  28. int cpufreq_get_hardware_limits(unsigned int cpu,
  29. unsigned long *min,
  30. unsigned long *max)
  31. {
  32. if ((!min) || (!max))
  33. return -EINVAL;
  34. return sysfs_get_freq_hardware_limits(cpu, min, max);
  35. }
  36. char *cpufreq_get_driver(unsigned int cpu)
  37. {
  38. return sysfs_get_freq_driver(cpu);
  39. }
  40. void cpufreq_put_driver(char *ptr)
  41. {
  42. if (!ptr)
  43. return;
  44. free(ptr);
  45. }
  46. struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu)
  47. {
  48. return sysfs_get_freq_policy(cpu);
  49. }
  50. void cpufreq_put_policy(struct cpufreq_policy *policy)
  51. {
  52. if ((!policy) || (!policy->governor))
  53. return;
  54. free(policy->governor);
  55. policy->governor = NULL;
  56. free(policy);
  57. }
  58. struct cpufreq_available_governors *cpufreq_get_available_governors(unsigned
  59. int cpu)
  60. {
  61. return sysfs_get_freq_available_governors(cpu);
  62. }
  63. void cpufreq_put_available_governors(struct cpufreq_available_governors *any)
  64. {
  65. struct cpufreq_available_governors *tmp, *next;
  66. if (!any)
  67. return;
  68. tmp = any->first;
  69. while (tmp) {
  70. next = tmp->next;
  71. if (tmp->governor)
  72. free(tmp->governor);
  73. free(tmp);
  74. tmp = next;
  75. }
  76. }
  77. struct cpufreq_available_frequencies
  78. *cpufreq_get_available_frequencies(unsigned int cpu)
  79. {
  80. return sysfs_get_available_frequencies(cpu);
  81. }
  82. void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies
  83. *any) {
  84. struct cpufreq_available_frequencies *tmp, *next;
  85. if (!any)
  86. return;
  87. tmp = any->first;
  88. while (tmp) {
  89. next = tmp->next;
  90. free(tmp);
  91. tmp = next;
  92. }
  93. }
  94. struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned int cpu)
  95. {
  96. return sysfs_get_freq_affected_cpus(cpu);
  97. }
  98. void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any)
  99. {
  100. struct cpufreq_affected_cpus *tmp, *next;
  101. if (!any)
  102. return;
  103. tmp = any->first;
  104. while (tmp) {
  105. next = tmp->next;
  106. free(tmp);
  107. tmp = next;
  108. }
  109. }
  110. struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned int cpu)
  111. {
  112. return sysfs_get_freq_related_cpus(cpu);
  113. }
  114. void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *any)
  115. {
  116. cpufreq_put_affected_cpus(any);
  117. }
  118. int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy)
  119. {
  120. if (!policy || !(policy->governor))
  121. return -EINVAL;
  122. return sysfs_set_freq_policy(cpu, policy);
  123. }
  124. int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq)
  125. {
  126. return sysfs_modify_freq_policy_min(cpu, min_freq);
  127. }
  128. int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq)
  129. {
  130. return sysfs_modify_freq_policy_max(cpu, max_freq);
  131. }
  132. int cpufreq_modify_policy_governor(unsigned int cpu, char *governor)
  133. {
  134. if ((!governor) || (strlen(governor) > 19))
  135. return -EINVAL;
  136. return sysfs_modify_freq_policy_governor(cpu, governor);
  137. }
  138. int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency)
  139. {
  140. return sysfs_set_frequency(cpu, target_frequency);
  141. }
  142. struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,
  143. unsigned long long *total_time)
  144. {
  145. return sysfs_get_freq_stats(cpu, total_time);
  146. }
  147. void cpufreq_put_stats(struct cpufreq_stats *any)
  148. {
  149. struct cpufreq_stats *tmp, *next;
  150. if (!any)
  151. return;
  152. tmp = any->first;
  153. while (tmp) {
  154. next = tmp->next;
  155. free(tmp);
  156. tmp = next;
  157. }
  158. }
  159. unsigned long cpufreq_get_transitions(unsigned int cpu)
  160. {
  161. return sysfs_get_freq_transitions(cpu);
  162. }