Linux 4.16-rc1
[cris-mirror.git] / tools / power / cpupower / utils / helpers / helpers.h
blob41da392be448a9abc63ec9032ced298095416bd6
1 /*
2 * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
4 * Licensed under the terms of the GNU GPL License version 2.
6 * Miscellaneous helpers which do not fit or are worth
7 * to put into separate headers
8 */
10 #ifndef __CPUPOWERUTILS_HELPERS__
11 #define __CPUPOWERUTILS_HELPERS__
13 #include <libintl.h>
14 #include <locale.h>
16 #include "helpers/bitmask.h"
17 #include <cpupower.h>
19 /* Internationalization ****************************/
20 #ifdef NLS
22 #define _(String) gettext(String)
23 #ifndef gettext_noop
24 #define gettext_noop(String) String
25 #endif
26 #define N_(String) gettext_noop(String)
28 #else /* !NLS */
30 #define _(String) String
31 #define N_(String) String
33 #endif
34 /* Internationalization ****************************/
36 extern int run_as_root;
37 extern int base_cpu;
38 extern struct bitmask *cpus_chosen;
40 /* Global verbose (-d) stuff *********************************/
42 * define DEBUG via global Makefile variable
43 * Debug output is sent to stderr, do:
44 * cpupower monitor 2>/tmp/debug
45 * to split debug output away from normal output
47 #ifdef DEBUG
48 extern int be_verbose;
50 #define dprint(fmt, ...) { \
51 if (be_verbose) { \
52 fprintf(stderr, "%s: " fmt, \
53 __func__, ##__VA_ARGS__); \
54 } \
56 #else
57 static inline void dprint(const char *fmt, ...) { }
58 #endif
59 extern int be_verbose;
60 /* Global verbose (-v) stuff *********************************/
62 /* cpuid and cpuinfo helpers **************************/
63 enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
64 X86_VENDOR_AMD, X86_VENDOR_MAX};
66 #define CPUPOWER_CAP_INV_TSC 0x00000001
67 #define CPUPOWER_CAP_APERF 0x00000002
68 #define CPUPOWER_CAP_AMD_CBP 0x00000004
69 #define CPUPOWER_CAP_PERF_BIAS 0x00000008
70 #define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
71 #define CPUPOWER_CAP_IS_SNB 0x00000020
72 #define CPUPOWER_CAP_INTEL_IDA 0x00000040
74 #define CPUPOWER_AMD_CPBDIS 0x02000000
76 #define MAX_HW_PSTATES 10
78 struct cpupower_cpu_info {
79 enum cpupower_cpu_vendor vendor;
80 unsigned int family;
81 unsigned int model;
82 unsigned int stepping;
83 /* CPU capabilities read out from cpuid */
84 unsigned long long caps;
87 /* get_cpu_info
89 * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
91 * Returns 0 on success or a negative error code
92 * Only used on x86, below global's struct values are zero/unknown on
93 * other archs
95 extern int get_cpu_info(struct cpupower_cpu_info *cpu_info);
96 extern struct cpupower_cpu_info cpupower_cpu_info;
97 /* cpuid and cpuinfo helpers **************************/
99 /* X86 ONLY ****************************************/
100 #if defined(__i386__) || defined(__x86_64__)
102 #include <pci/pci.h>
104 /* Read/Write msr ****************************/
105 extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
106 extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
108 extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
109 extern int msr_intel_get_perf_bias(unsigned int cpu);
110 extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
112 /* Read/Write msr ****************************/
114 /* PCI stuff ****************************/
115 extern int amd_pci_get_num_boost_states(int *active, int *states);
116 extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain,
117 int bus, int slot, int func, int vendor,
118 int dev);
119 extern struct pci_dev *pci_slot_func_init(struct pci_access **pacc,
120 int slot, int func);
122 /* PCI stuff ****************************/
124 /* AMD HW pstate decoding **************************/
126 extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
127 int boost_states, unsigned long *pstates, int *no);
129 /* AMD HW pstate decoding **************************/
131 extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
132 int *active, int * states);
134 * CPUID functions returning a single datum
136 unsigned int cpuid_eax(unsigned int op);
137 unsigned int cpuid_ebx(unsigned int op);
138 unsigned int cpuid_ecx(unsigned int op);
139 unsigned int cpuid_edx(unsigned int op);
141 /* cpuid and cpuinfo helpers **************************/
142 /* X86 ONLY ********************************************/
143 #else
144 static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
145 int boost_states, unsigned long *pstates,
146 int *no)
147 { return -1; };
149 static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
150 { return -1; };
151 static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
152 { return -1; };
153 static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
154 { return -1; };
155 static inline int msr_intel_get_perf_bias(unsigned int cpu)
156 { return -1; };
157 static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
158 { return 0; };
160 /* Read/Write msr ****************************/
162 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
163 int *active, int * states)
164 { return -1; }
166 /* cpuid and cpuinfo helpers **************************/
168 static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
169 static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
170 static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
171 static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
172 #endif /* defined(__i386__) || defined(__x86_64__) */
174 #endif /* __CPUPOWERUTILS_HELPERS__ */