helpers.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
  3. *
  4. * Licensed under the terms of the GNU GPL License version 2.
  5. *
  6. * Miscellaneous helpers which do not fit or are worth
  7. * to put into separate headers
  8. */
  9. #ifndef __CPUPOWERUTILS_HELPERS__
  10. #define __CPUPOWERUTILS_HELPERS__
  11. #include <libintl.h>
  12. #include <locale.h>
  13. #include "helpers/bitmask.h"
  14. #include <cpupower.h>
  15. /* Internationalization ****************************/
  16. #ifdef NLS
  17. #define _(String) gettext(String)
  18. #ifndef gettext_noop
  19. #define gettext_noop(String) String
  20. #endif
  21. #define N_(String) gettext_noop(String)
  22. #else /* !NLS */
  23. #define _(String) String
  24. #define N_(String) String
  25. #endif
  26. /* Internationalization ****************************/
  27. extern int run_as_root;
  28. extern struct bitmask *cpus_chosen;
  29. /* Global verbose (-d) stuff *********************************/
  30. /*
  31. * define DEBUG via global Makefile variable
  32. * Debug output is sent to stderr, do:
  33. * cpupower monitor 2>/tmp/debug
  34. * to split debug output away from normal output
  35. */
  36. #ifdef DEBUG
  37. extern int be_verbose;
  38. #define dprint(fmt, ...) { \
  39. if (be_verbose) { \
  40. fprintf(stderr, "%s: " fmt, \
  41. __func__, ##__VA_ARGS__); \
  42. } \
  43. }
  44. #else
  45. static inline void dprint(const char *fmt, ...) { }
  46. #endif
  47. extern int be_verbose;
  48. /* Global verbose (-v) stuff *********************************/
  49. /* cpuid and cpuinfo helpers **************************/
  50. enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
  51. X86_VENDOR_AMD, X86_VENDOR_MAX};
  52. #define CPUPOWER_CAP_INV_TSC 0x00000001
  53. #define CPUPOWER_CAP_APERF 0x00000002
  54. #define CPUPOWER_CAP_AMD_CBP 0x00000004
  55. #define CPUPOWER_CAP_PERF_BIAS 0x00000008
  56. #define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
  57. #define CPUPOWER_CAP_IS_SNB 0x00000020
  58. #define CPUPOWER_CAP_INTEL_IDA 0x00000040
  59. #define MAX_HW_PSTATES 10
  60. struct cpupower_cpu_info {
  61. enum cpupower_cpu_vendor vendor;
  62. unsigned int family;
  63. unsigned int model;
  64. unsigned int stepping;
  65. /* CPU capabilities read out from cpuid */
  66. unsigned long long caps;
  67. };
  68. /* get_cpu_info
  69. *
  70. * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
  71. *
  72. * Returns 0 on success or a negativ error code
  73. * Only used on x86, below global's struct values are zero/unknown on
  74. * other archs
  75. */
  76. extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
  77. extern struct cpupower_cpu_info cpupower_cpu_info;
  78. /* cpuid and cpuinfo helpers **************************/
  79. /* X86 ONLY ****************************************/
  80. #if defined(__i386__) || defined(__x86_64__)
  81. #include <pci/pci.h>
  82. /* Read/Write msr ****************************/
  83. extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
  84. extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
  85. extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
  86. extern int msr_intel_get_perf_bias(unsigned int cpu);
  87. extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
  88. /* Read/Write msr ****************************/
  89. /* PCI stuff ****************************/
  90. extern int amd_pci_get_num_boost_states(int *active, int *states);
  91. extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain,
  92. int bus, int slot, int func, int vendor,
  93. int dev);
  94. extern struct pci_dev *pci_slot_func_init(struct pci_access **pacc,
  95. int slot, int func);
  96. /* PCI stuff ****************************/
  97. /* AMD HW pstate decoding **************************/
  98. extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
  99. int boost_states, unsigned long *pstates, int *no);
  100. /* AMD HW pstate decoding **************************/
  101. extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
  102. int *active, int * states);
  103. /*
  104. * CPUID functions returning a single datum
  105. */
  106. unsigned int cpuid_eax(unsigned int op);
  107. unsigned int cpuid_ebx(unsigned int op);
  108. unsigned int cpuid_ecx(unsigned int op);
  109. unsigned int cpuid_edx(unsigned int op);
  110. /* cpuid and cpuinfo helpers **************************/
  111. /* X86 ONLY ********************************************/
  112. #else
  113. static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
  114. int boost_states, unsigned long *pstates,
  115. int *no)
  116. { return -1; };
  117. static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
  118. { return -1; };
  119. static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
  120. { return -1; };
  121. static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
  122. { return -1; };
  123. static inline int msr_intel_get_perf_bias(unsigned int cpu)
  124. { return -1; };
  125. static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
  126. { return 0; };
  127. /* Read/Write msr ****************************/
  128. static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
  129. int *active, int * states)
  130. { return -1; }
  131. /* cpuid and cpuinfo helpers **************************/
  132. static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
  133. static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
  134. static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
  135. static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
  136. #endif /* defined(__i386__) || defined(__x86_64__) */
  137. #endif /* __CPUPOWERUTILS_HELPERS__ */