blob: 7a83022733b2e49b2162f0eb14187756f4305ee6 [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;
Thomas Renninger7c74d2b2011-08-12 01:11:37 +020099
100 /* flags */
101 unsigned int is_online:1;
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200102 } *core_info;
103};
104
105extern int get_cpu_topology(struct cpupower_topology *cpu_top);
106extern void cpu_topology_release(struct cpupower_topology cpu_top);
107/* CPU topology/hierarchy parsing ******************/
108
109/* X86 ONLY ****************************************/
110#if defined(__i386__) || defined(__x86_64__)
111
112#include <pci/pci.h>
113
114/* Read/Write msr ****************************/
115extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
116extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
117
118extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
119extern int msr_intel_get_perf_bias(unsigned int cpu);
Thomas Renninger8fb2e442011-07-21 11:54:53 +0200120extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200121
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200122/* Read/Write msr ****************************/
123
124/* PCI stuff ****************************/
125extern int amd_pci_get_num_boost_states(int *active, int *states);
126extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
127 int *dev_ids);
128
129/* PCI stuff ****************************/
130
131/* AMD HW pstate decoding **************************/
132
133extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
134 int boost_states, unsigned long *pstates, int *no);
135
136/* AMD HW pstate decoding **************************/
137
138extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
139 int *active, int * states);
140/*
141 * CPUID functions returning a single datum
142 */
143unsigned int cpuid_eax(unsigned int op);
144unsigned int cpuid_ebx(unsigned int op);
145unsigned int cpuid_ecx(unsigned int op);
146unsigned int cpuid_edx(unsigned int op);
147
148/* cpuid and cpuinfo helpers **************************/
149/* X86 ONLY ********************************************/
150#else
151static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
152 int boost_states, unsigned long *pstates,
153 int *no)
154{ return -1; };
155
156static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
157{ return -1; };
158static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
159{ return -1; };
160static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
161{ return -1; };
162static inline int msr_intel_get_perf_bias(unsigned int cpu)
163{ return -1; };
Thomas Renninger8fb2e442011-07-21 11:54:53 +0200164static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
165{ return 0; };
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200166
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200167/* Read/Write msr ****************************/
168
169static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
170 int *active, int * states)
171{ return -1; }
172
173/* cpuid and cpuinfo helpers **************************/
174
175static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
176static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
177static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
178static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
179#endif /* defined(__i386__) || defined(__x86_64__) */
180
181#endif /* __CPUPOWERUTILS_HELPERS__ */