blob: 2747e738efb04d3fa1a53e7686162240cfc7a7ec [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 ****************************/
Dominik Brodowski47c33632011-08-19 17:00:02 +020019#ifdef NLS
20
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020021#define _(String) gettext(String)
22#ifndef gettext_noop
23#define gettext_noop(String) String
24#endif
Dominik Brodowski2cd005c2011-04-19 20:16:05 +020025#define N_(String) gettext_noop(String)
Dominik Brodowski47c33632011-08-19 17:00:02 +020026
27#else /* !NLS */
28
29#define _(String) String
30#define N_(String) String
31
32#endif
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020033/* Internationalization ****************************/
34
35extern int run_as_root;
36extern struct bitmask *cpus_chosen;
37
38/* Global verbose (-d) stuff *********************************/
39/*
40 * define DEBUG via global Makefile variable
41 * Debug output is sent to stderr, do:
42 * cpupower monitor 2>/tmp/debug
43 * to split debug output away from normal output
44*/
45#ifdef DEBUG
46extern int be_verbose;
47
48#define dprint(fmt, ...) { \
49 if (be_verbose) { \
50 fprintf(stderr, "%s: " fmt, \
Dominik Brodowski2cd005c2011-04-19 20:16:05 +020051 __func__, ##__VA_ARGS__); \
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020052 } \
53 }
54#else
Dominik Brodowski2cd005c2011-04-19 20:16:05 +020055static inline void dprint(const char *fmt, ...) { }
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020056#endif
57extern int be_verbose;
58/* Global verbose (-v) stuff *********************************/
59
60/* cpuid and cpuinfo helpers **************************/
61enum cpupower_cpu_vendor {X86_VENDOR_UNKNOWN = 0, X86_VENDOR_INTEL,
62 X86_VENDOR_AMD, X86_VENDOR_MAX};
63
Thomas Renninger8fb2e442011-07-21 11:54:53 +020064#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 0x00000011
Thomas Renninger029e9f72011-07-21 11:54:54 +020070#define CPUPOWER_CAP_INTEL_IDA 0x00000012
Dominik Brodowski7fe2f632011-03-30 16:30:11 +020071
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 /* CPU capabilities read out from cpuid */
80 unsigned long long caps;
81};
82
83/* get_cpu_info
84 *
85 * Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
86 *
87 * Returns 0 on success or a negativ error code
88 * Only used on x86, below global's struct values are zero/unknown on
89 * other archs
90 */
91extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
92extern struct cpupower_cpu_info cpupower_cpu_info;
93/* cpuid and cpuinfo helpers **************************/
94
95
96/* CPU topology/hierarchy parsing ******************/
97struct cpupower_topology {
98 /* Amount of CPU cores, packages and threads per core in the system */
99 unsigned int cores;
100 unsigned int pkgs;
101 unsigned int threads; /* per core */
102
103 /* Array gets mallocated with cores entries, holding per core info */
104 struct {
105 int pkg;
106 int core;
107 int cpu;
Thomas Renninger7c74d2b2011-08-12 01:11:37 +0200108
109 /* flags */
110 unsigned int is_online:1;
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200111 } *core_info;
112};
113
114extern int get_cpu_topology(struct cpupower_topology *cpu_top);
115extern void cpu_topology_release(struct cpupower_topology cpu_top);
116/* CPU topology/hierarchy parsing ******************/
117
118/* X86 ONLY ****************************************/
119#if defined(__i386__) || defined(__x86_64__)
120
121#include <pci/pci.h>
122
123/* Read/Write msr ****************************/
124extern int read_msr(int cpu, unsigned int idx, unsigned long long *val);
125extern int write_msr(int cpu, unsigned int idx, unsigned long long val);
126
127extern int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val);
128extern int msr_intel_get_perf_bias(unsigned int cpu);
Thomas Renninger8fb2e442011-07-21 11:54:53 +0200129extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu);
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200130
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200131/* Read/Write msr ****************************/
132
133/* PCI stuff ****************************/
134extern int amd_pci_get_num_boost_states(int *active, int *states);
135extern struct pci_dev *pci_acc_init(struct pci_access **pacc, int vendor_id,
136 int *dev_ids);
137
138/* PCI stuff ****************************/
139
140/* AMD HW pstate decoding **************************/
141
142extern int decode_pstates(unsigned int cpu, unsigned int cpu_family,
143 int boost_states, unsigned long *pstates, int *no);
144
145/* AMD HW pstate decoding **************************/
146
147extern int cpufreq_has_boost_support(unsigned int cpu, int *support,
148 int *active, int * states);
149/*
150 * CPUID functions returning a single datum
151 */
152unsigned int cpuid_eax(unsigned int op);
153unsigned int cpuid_ebx(unsigned int op);
154unsigned int cpuid_ecx(unsigned int op);
155unsigned int cpuid_edx(unsigned int op);
156
157/* cpuid and cpuinfo helpers **************************/
158/* X86 ONLY ********************************************/
159#else
160static inline int decode_pstates(unsigned int cpu, unsigned int cpu_family,
161 int boost_states, unsigned long *pstates,
162 int *no)
163{ return -1; };
164
165static inline int read_msr(int cpu, unsigned int idx, unsigned long long *val)
166{ return -1; };
167static inline int write_msr(int cpu, unsigned int idx, unsigned long long val)
168{ return -1; };
169static inline int msr_intel_set_perf_bias(unsigned int cpu, unsigned int val)
170{ return -1; };
171static inline int msr_intel_get_perf_bias(unsigned int cpu)
172{ return -1; };
Thomas Renninger8fb2e442011-07-21 11:54:53 +0200173static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
174{ return 0; };
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200175
Dominik Brodowski7fe2f632011-03-30 16:30:11 +0200176/* Read/Write msr ****************************/
177
178static inline int cpufreq_has_boost_support(unsigned int cpu, int *support,
179 int *active, int * states)
180{ return -1; }
181
182/* cpuid and cpuinfo helpers **************************/
183
184static inline unsigned int cpuid_eax(unsigned int op) { return 0; };
185static inline unsigned int cpuid_ebx(unsigned int op) { return 0; };
186static inline unsigned int cpuid_ecx(unsigned int op) { return 0; };
187static inline unsigned int cpuid_edx(unsigned int op) { return 0; };
188#endif /* defined(__i386__) || defined(__x86_64__) */
189
190#endif /* __CPUPOWERUTILS_HELPERS__ */