1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
5 * Miscellaneous helpers which do not fit or are worth
6 * to put into separate headers
9 #ifndef __CPUPOWERUTILS_HELPERS__
10 #define __CPUPOWERUTILS_HELPERS__
15 #include "helpers/bitmask.h"
18 /* Internationalization ****************************/
21 #define _(String) gettext(String)
23 #define gettext_noop(String) String
25 #define N_(String) gettext_noop(String)
29 #define _(String) String
30 #define N_(String) String
33 /* Internationalization ****************************/
35 extern int run_as_root;
37 extern struct bitmask *cpus_chosen;
39 /* Global verbose (-d) stuff *********************************/
41 * define DEBUG via global Makefile variable
42 * Debug output is sent to stderr, do:
43 * cpupower monitor 2>/tmp/debug
44 * to split debug output away from normal output
47 extern int be_verbose;
49 #define dprint(fmt, ...) { \
51 fprintf(stderr, "%s: " fmt, \
52 __func__, ##__VA_ARGS__); \
56 static inline void dprint(const char *fmt, ...) { }
58 extern int be_verbose;
59 /* Global verbose (-v) stuff *********************************/
61 /* cpuid and cpuinfo helpers **************************/
62 enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
63 X86_VENDOR_AMD, X86_VENDOR_HYGON, X86_VENDOR_MAX};
65 #define CPUPOWER_CAP_INV_TSC 0x00000001
66 #define CPUPOWER_CAP_APERF 0x00000002
67 #define CPUPOWER_CAP_AMD_CBP 0x00000004
68 #define CPUPOWER_CAP_PERF_BIAS 0x00000008
69 #define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
70 #define CPUPOWER_CAP_IS_SNB 0x00000020
71 #define CPUPOWER_CAP_INTEL_IDA 0x00000040
73 #define CPUPOWER_AMD_CPBDIS 0x02000000
75 #define MAX_HW_PSTATES 10
77 struct cpupower_cpu_info {
78 enum cpupower_cpu_vendor vendor;
81 unsigned int stepping;
82 /* CPU capabilities read out from cpuid */
83 unsigned long long caps;
88 * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
90 * Returns 0 on success or a negative error code
91 * Only used on x86, below global's struct values are zero/unknown on
94 extern int get_cpu_info(struct cpupower_cpu_info *cpu_info);
95 extern struct cpupower_cpu_info cpupower_cpu_info;
96 /* cpuid and cpuinfo helpers **************************/
98 /* X86 ONLY ****************************************/
99 #if defined(__i386__) || defined(__x86_64__)
103 /* Read/Write msr ****************************/
104 extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
105 extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
107 extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
108 extern int msr_intel_get_perf_bias(unsigned int cpu);
109 extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
111 /* Read/Write msr ****************************/
113 /* PCI stuff ****************************/
114 extern int amd_pci_get_num_boost_states(int *active, int *states);
115 extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int domain,
116 int bus, int slot, int func, int vendor,
118 extern struct pci_dev *pci_slot_func_init(struct pci_access **pacc,
121 /* PCI stuff ****************************/
123 /* AMD HW pstate decoding **************************/
125 extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
126 int boost_states, unsigned long *pstates, int *no);
128 /* AMD HW pstate decoding **************************/
130 extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
131 int *active, int * states);
133 * CPUID functions returning a single datum
135 unsigned int cpuid_eax(unsigned int op);
136 unsigned int cpuid_ebx(unsigned int op);
137 unsigned int cpuid_ecx(unsigned int op);
138 unsigned int cpuid_edx(unsigned int op);
140 /* cpuid and cpuinfo helpers **************************/
141 /* X86 ONLY ********************************************/
143 static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
144 int boost_states, unsigned long *pstates,
148 static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
150 static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
152 static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
154 static inline int msr_intel_get_perf_bias(unsigned int cpu)
156 static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
159 /* Read/Write msr ****************************/
161 static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
162 int *active, int * states)
165 /* cpuid and cpuinfo helpers **************************/
167 static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
168 static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
169 static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
170 static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
171 #endif /* defined(__i386__) || defined(__x86_64__) */
173 #endif /* __CPUPOWERUTILS_HELPERS__ */