blob: 592ee362b877c92083d736d7699d7cb6d3e3250a [file] [log] [blame]
Dominik Brodowski7fe2f632011-03-30 16:30:11 +02001/*
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
Dominik Brodowski2cd005c2011-04-19 20:16:05 +020023#define N_(String) gettext_noop(String)
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020024/* Internationalization ****************************/
25
26extern int run_as_root;
27extern 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
37extern int be_verbose;
38
39#define dprint(fmt, ...) { \
40 if (be_verbose) { \
41 fprintf(stderr, "%s: " fmt, \
Dominik Brodowski2cd005c2011-04-19 20:16:05 +020042 __func__, ##__VA_ARGS__); \
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020043 } \
44 }
45#else
Dominik Brodowski2cd005c2011-04-19 20:16:05 +020046static inline void dprint(const char *fmt, ...) { }
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020047#endif
48extern int be_verbose;
49/* Global verbose (-v) stuff *********************************/
50
51/* cpuid and cpuinfo helpers **************************/
52enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
53 X86_VENDOR_AMD, X86_VENDOR_MAX};
54
Thomas Renninger8fb2e442011-07-21 11:54:53 +020055#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#define CPUPOWER_CAP_HAS_TURBO_RATIO 0x00000010
60#define CPUPOWER_CAP_IS_SNB 0x00000011
Thomas Renninger029e9f72011-07-21 11:54:54 +020061#define CPUPOWER_CAP_INTEL_IDA 0x00000012
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020062
63#define MAX_HW_PSTATES 10
64
65struct cpupower_cpu_info {
66 enum cpupower_cpu_vendor vendor;
67 unsigned int family;
68 unsigned int model;
69 unsigned int stepping;
70 /* CPU capabilities read out from cpuid */
71 unsigned long long caps;
72};
73
74/* get_cpu_info
75 *
76 * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
77 *
78 * Returns 0 on success or a negativ error code
79 * Only used on x86, below global's struct values are zero/unknown on
80 * other archs
81 */
82extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
83extern struct cpupower_cpu_info cpupower_cpu_info;
84/* cpuid and cpuinfo helpers **************************/
85
86
87/* CPU topology/hierarchy parsing ******************/
88struct cpupower_topology {
89 /* Amount of CPU cores, packages and threads per core in the system */
90 unsigned int cores;
91 unsigned int pkgs;
92 unsigned int threads; /* per core */
93
94 /* Array gets mallocated with cores entries, holding per core info */
95 struct {
96 int pkg;
97 int core;
98 int cpu;
99 } *core_info;
100};
101
102extern int get_cpu_topology(struct cpupower_topology *cpu_top);
103extern void cpu_topology_release(struct cpupower_topology cpu_top);
104/* CPU topology/hierarchy parsing ******************/
105
106/* X86 ONLY ****************************************/
107#if defined(__i386__) || defined(__x86_64__)
108
109#include <pci/pci.h>
110
111/* Read/Write msr ****************************/
112extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
113extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
114
115extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
116extern int msr_intel_get_perf_bias(unsigned int cpu);
Thomas Renninger8fb2e442011-07-21 11:54:53 +0200117extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200118
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200119/* Read/Write msr ****************************/
120
121/* PCI stuff ****************************/
122extern int amd_pci_get_num_boost_states(int *active, int *states);
123extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
124 int *dev_ids);
125
126/* PCI stuff ****************************/
127
128/* AMD HW pstate decoding **************************/
129
130extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
131 int boost_states, unsigned long *pstates, int *no);
132
133/* AMD HW pstate decoding **************************/
134
135extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
136 int *active, int * states);
137/*
138 * CPUID functions returning a single datum
139 */
140unsigned int cpuid_eax(unsigned int op);
141unsigned int cpuid_ebx(unsigned int op);
142unsigned int cpuid_ecx(unsigned int op);
143unsigned int cpuid_edx(unsigned int op);
144
145/* cpuid and cpuinfo helpers **************************/
146/* X86 ONLY ********************************************/
147#else
148static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
149 int boost_states, unsigned long *pstates,
150 int *no)
151{ return -1; };
152
153static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
154{ return -1; };
155static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
156{ return -1; };
157static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
158{ return -1; };
159static inline int msr_intel_get_perf_bias(unsigned int cpu)
160{ return -1; };
Thomas Renninger8fb2e442011-07-21 11:54:53 +0200161static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
162{ return 0; };
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200163
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200164/* Read/Write msr ****************************/
165
166static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
167 int *active, int * states)
168{ return -1; }
169
170/* cpuid and cpuinfo helpers **************************/
171
172static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
173static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
174static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
175static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
176#endif /* defined(__i386__) || defined(__x86_64__) */
177
178#endif /* __CPUPOWERUTILS_HELPERS__ */