1
2
3
4
5
6
7
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
19#ifdef NLS
20
21#define _(String) gettext(String)
22#ifndef gettext_noop
23#define gettext_noop(String) String
24#endif
25#define N_(String) gettext_noop(String)
26
27#else
28
29#define _(String) String
30#define N_(String) String
31
32#endif
33
34
35extern int run_as_root;
36extern struct bitmask *cpus_chosen;
37
38
39
40
41
42
43
44
45#ifdef DEBUG
46extern int be_verbose;
47
48#define dprint(fmt, ...) { \
49 if (be_verbose) { \
50 fprintf(stderr, "%s: " fmt, \
51 __func__, ##__VA_ARGS__); \
52 } \
53 }
54#else
55static inline void dprint(const char *fmt, ...) { }
56#endif
57extern int be_verbose;
58
59
60
61enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
62 X86_VENDOR_AMD, X86_VENDOR_MAX};
63
64#define CPUPOWER_CAP_INV_TSC 0x00000001
65#define CPUPOWER_CAP_APERF 0x00000002
66#define CPUPOWER_CAP_AMD_CBP 0x00000004
67#define CPUPOWER_CAP_PERF_BIAS 0x00000008
68#define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
69#define CPUPOWER_CAP_IS_SNB 0x00000020
70#define CPUPOWER_CAP_INTEL_IDA 0x00000040
71
72#define MAX_HW_PSTATES 10
73
74struct cpupower_cpu_info {
75 enum cpupower_cpu_vendor vendor;
76 unsigned int family;
77 unsigned int model;
78 unsigned int stepping;
79
80 unsigned long long caps;
81};
82
83
84
85
86
87
88
89
90
91extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
92extern struct cpupower_cpu_info cpupower_cpu_info;
93
94
95struct cpuid_core_info {
96 int pkg;
97 int core;
98 int cpu;
99
100
101 unsigned int is_online:1;
102};
103
104
105struct cpupower_topology {
106
107 unsigned int cores;
108 unsigned int pkgs;
109 unsigned int threads;
110
111
112 struct cpuid_core_info *core_info;
113};
114
115extern int get_cpu_topology(struct cpupower_topology *cpu_top);
116extern void cpu_topology_release(struct cpupower_topology cpu_top);
117
118
119
120
121#if defined(__i386__) || defined(__x86_64__)
122
123#include <pci/pci.h>
124
125
126extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
127extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
128
129extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
130extern int msr_intel_get_perf_bias(unsigned int cpu);
131extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
132
133
134
135
136extern int amd_pci_get_num_boost_states(int *active, int *states);
137extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain,
138 int bus, int slot, int func, int vendor,
139 int dev);
140extern struct pci_dev *pci_slot_func_init(struct pci_access **pacc,
141 int slot, int func);
142
143
144
145
146
147extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
148 int boost_states, unsigned long *pstates, int *no);
149
150
151
152extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
153 int *active, int * states);
154
155
156
157unsigned int cpuid_eax(unsigned int op);
158unsigned int cpuid_ebx(unsigned int op);
159unsigned int cpuid_ecx(unsigned int op);
160unsigned int cpuid_edx(unsigned int op);
161
162
163
164#else
165static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
166 int boost_states, unsigned long *pstates,
167 int *no)
168{ return -1; };
169
170static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
171{ return -1; };
172static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
173{ return -1; };
174static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
175{ return -1; };
176static inline int msr_intel_get_perf_bias(unsigned int cpu)
177{ return -1; };
178static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
179{ return 0; };
180
181
182
183static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
184 int *active, int * states)
185{ return -1; }
186
187
188
189static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
190static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
191static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
192static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
193#endif
194
195#endif
196