cpupowerutils - cpufrequtils extended with quite some features
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / power / cpupower / utils / helpers / helpers.h
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
10 #ifndef __CPUPOWERUTILS_HELPERS__
11 #define __CPUPOWERUTILS_HELPERS__
12
13 #include <libintl.h>
14 #include <locale.h>
15
16 #include "helpers/bitmask.h"
17
18 /* Internationalization ****************************/
19 #define _(String) gettext(String)
20 #ifndef gettext_noop
21 #define gettext_noop(String) String
22 #endif
23 #define N_(String) gettext_noop (String)
24 /* Internationalization ****************************/
25
26 extern int run_as_root;
27 extern struct bitmask *cpus_chosen;
28
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
39 #define dprint(fmt, ...) {                                      \
40                 if (be_verbose) {                               \
41                         fprintf(stderr, "%s: " fmt,             \
42                                 __FUNCTION__, ##__VA_ARGS__);   \
43                 }                                               \
44         }
45 #else
46 static inline void dprint(const char *fmt, ...) { }      
47 #endif
48 extern int be_verbose;
49 /* Global verbose (-v) stuff *********************************/
50
51 /* cpuid and cpuinfo helpers  **************************/
52 enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
53                           X86_VENDOR_AMD, X86_VENDOR_MAX};
54
55 #define CPUPOWER_CAP_INV_TSC    0x00000001
56 #define CPUPOWER_CAP_APERF      0x00000002
57 #define CPUPOWER_CAP_AMD_CBP    0x00000004
58 #define CPUPOWER_CAP_PERF_BIAS  0x00000008
59
60 #define MAX_HW_PSTATES 10
61
62 struct cpupower_cpu_info {
63         enum cpupower_cpu_vendor vendor;
64         unsigned int family;
65         unsigned int model;
66         unsigned int stepping;
67         /* CPU capabilities read out from cpuid */
68         unsigned long long caps;
69 };
70
71 /* get_cpu_info
72  *
73  * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
74  *
75  * Returns 0 on success or a negativ error code
76  * Only used on x86, below global's struct values are zero/unknown on
77  * other archs
78  */
79 extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
80 extern struct cpupower_cpu_info cpupower_cpu_info;
81 /* cpuid and cpuinfo helpers  **************************/
82
83
84 /* CPU topology/hierarchy parsing ******************/
85 struct cpupower_topology {
86         /* Amount of CPU cores, packages and threads per core in the system */
87         unsigned int cores;
88         unsigned int pkgs;
89         unsigned int threads; /* per core */
90
91         /* Array gets mallocated with cores entries, holding per core info */
92         struct {
93                 int pkg;
94                 int core;
95                 int cpu;
96         } *core_info;
97 };
98
99 extern int get_cpu_topology(struct cpupower_topology *cpu_top);
100 extern void cpu_topology_release(struct cpupower_topology cpu_top);
101 /* CPU topology/hierarchy parsing ******************/
102
103 /* X86 ONLY ****************************************/
104 #if defined(__i386__) || defined(__x86_64__)
105
106 #include <pci/pci.h>
107
108 /* Read/Write msr ****************************/
109 extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
110 extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
111
112 extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
113 extern int msr_intel_get_perf_bias(unsigned int cpu);
114
115 extern int msr_intel_has_boost_support(unsigned int cpu);
116 extern int msr_intel_boost_is_active(unsigned int cpu);
117
118 /* Read/Write msr ****************************/
119
120 /* PCI stuff ****************************/
121 extern int amd_pci_get_num_boost_states(int *active, int *states);
122 extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
123                                     int *dev_ids);
124
125 /* PCI stuff ****************************/
126
127 /* AMD HW pstate decoding **************************/
128
129 extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
130                           int boost_states, unsigned long *pstates, int *no);
131
132 /* AMD HW pstate decoding **************************/
133
134 extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
135                                      int *active, int * states);
136 /*
137  * CPUID functions returning a single datum
138  */
139 unsigned int cpuid_eax(unsigned int op);
140 unsigned int cpuid_ebx(unsigned int op);
141 unsigned int cpuid_ecx(unsigned int op);
142 unsigned int cpuid_edx(unsigned int op);
143
144 /* cpuid and cpuinfo helpers  **************************/
145 /* X86 ONLY ********************************************/
146 #else
147 static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
148                                  int boost_states, unsigned long *pstates,
149                                  int *no)
150 { return -1; };
151
152 static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
153 { return -1; };
154 static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
155 { return -1; };
156 static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
157 { return -1; };
158 static inline int msr_intel_get_perf_bias(unsigned int cpu)
159 { return -1; };
160
161 static inline int msr_intel_has_boost_support(unsigned int cpu)
162 { return -1; };
163 static inline int msr_intel_boost_is_active(unsigned int cpu)
164 { return -1; };
165
166 /* Read/Write msr ****************************/
167
168 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
169                                             int *active, int * states)
170 { return -1; }
171
172 /* cpuid and cpuinfo helpers  **************************/
173
174 static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
175 static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
176 static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
177 static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
178 #endif /* defined(__i386__) || defined(__x86_64__) */
179
180 #endif /* __CPUPOWERUTILS_HELPERS__ */