1 /*
2 * xen/include/acpi/cpufreq/cpufreq.h
3 *
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 *
7 * $Id: cpufreq.h,v 1.36 2003/01/20 17:31:48 db Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14 #ifndef __XEN_CPUFREQ_PM_H__
15 #define __XEN_CPUFREQ_PM_H__
16
17 #include <xen/types.h>
18 #include <xen/list.h>
19 #include <xen/cpumask.h>
20
21 #include "processor_perf.h"
22
23 extern bool cpufreq_verbose;
24
25 enum cpufreq_xen_opt {
26 CPUFREQ_none,
27 CPUFREQ_xen,
28 CPUFREQ_hwp,
29 };
30 extern enum cpufreq_xen_opt cpufreq_xen_opts[2];
31 extern unsigned int cpufreq_xen_cnt;
32 struct cpufreq_governor;
33
34 struct acpi_cpufreq_data {
35 struct processor_performance *acpi_data;
36 struct cpufreq_frequency_table *freq_table;
37 unsigned int arch_cpu_flags;
38 };
39
40 extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS];
41
42 struct cpufreq_cpuinfo {
43 unsigned int max_freq;
44 unsigned int second_max_freq; /* P1 if Turbo Mode is on */
45 unsigned int perf_freq; /* Scaling freq for aperf/mpref.
46 acpi-cpufreq uses max_freq, but HWP uses
47 base_freq.*/
48 unsigned int min_freq;
49 unsigned int transition_latency; /* in 10^(-9) s = nanoseconds */
50 };
51
52 struct perf_limits {
53 bool no_turbo;
54 bool turbo_disabled;
55 uint32_t turbo_pct;
56 uint32_t max_perf_pct; /* max performance in percentage */
57 uint32_t min_perf_pct; /* min performance in percentage */
58 uint32_t max_perf;
59 uint32_t min_perf;
60 uint32_t max_policy_pct;
61 uint32_t min_policy_pct;
62 };
63
64 struct cpufreq_policy {
65 cpumask_var_t cpus; /* affected CPUs */
66 unsigned int shared_type; /* ANY or ALL affected CPUs
67 should set cpufreq */
68 unsigned int cpu; /* cpu nr of registered CPU */
69 struct cpufreq_cpuinfo cpuinfo;
70
71 unsigned int min; /* in kHz */
72 unsigned int max; /* in kHz */
73 unsigned int cur; /* in kHz, only needed if cpufreq
74 * governors are used */
75 struct perf_limits limits;
76 struct cpufreq_governor *governor;
77
78 bool resume; /* flag for cpufreq 1st run
79 * S3 wakeup, hotplug cpu, etc */
80 int8_t turbo; /* tristate flag: 0 for unsupported
81 * -1 for disable, 1 for enabled
82 * See CPUFREQ_TURBO_* below for defines */
83 };
84 DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);
85
86 extern int __cpufreq_set_policy(struct cpufreq_policy *data,
87 struct cpufreq_policy *policy);
88
89 #define CPUFREQ_SHARED_TYPE_HW XEN_CPUPERF_SHARED_TYPE_HW
90 #define CPUFREQ_SHARED_TYPE_ALL XEN_CPUPERF_SHARED_TYPE_ALL
91 #define CPUFREQ_SHARED_TYPE_ANY XEN_CPUPERF_SHARED_TYPE_ANY
92
93 /******************** cpufreq transition notifiers *******************/
94
95 struct cpufreq_freqs {
96 unsigned int cpu; /* cpu nr */
97 unsigned int old;
98 unsigned int new;
99 u8 flags; /* flags of cpufreq_driver, see below. */
100 };
101
102
103 /*********************************************************************
104 * CPUFREQ GOVERNORS *
105 *********************************************************************/
106
107 #define CPUFREQ_GOV_START 1
108 #define CPUFREQ_GOV_STOP 2
109 #define CPUFREQ_GOV_LIMITS 3
110
111 struct cpufreq_governor {
112 char name[CPUFREQ_NAME_LEN];
113 int (*governor)(struct cpufreq_policy *policy,
114 unsigned int event);
115 bool (*handle_option)(const char *name, const char *value);
116 struct list_head governor_list;
117 };
118
119 extern struct cpufreq_governor *cpufreq_opt_governor;
120 extern struct cpufreq_governor cpufreq_gov_dbs;
121 extern struct cpufreq_governor cpufreq_gov_userspace;
122 extern struct cpufreq_governor cpufreq_gov_performance;
123 extern struct cpufreq_governor cpufreq_gov_powersave;
124
125 extern struct list_head cpufreq_governor_list;
126
127 extern bool cpufreq_governor_internal;
128
129 extern int cpufreq_register_governor(struct cpufreq_governor *governor);
130 extern struct cpufreq_governor *__find_governor(const char *governor);
131 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs
132
133 /* pass a target to the cpufreq driver */
134 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
135 unsigned int target_freq,
136 unsigned int relation);
137
138 #define GOV_GETAVG 1
139 #define USR_GETAVG 2
140 extern int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag);
141
142 #define CPUFREQ_TURBO_DISABLED -1
143 #define CPUFREQ_TURBO_UNSUPPORTED 0
144 #define CPUFREQ_TURBO_ENABLED 1
145
146 static inline int
__cpufreq_governor(struct cpufreq_policy * policy,unsigned int event)147 __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
148 {
149 return policy->governor->governor(policy, event);
150 }
151
152
153 /*********************************************************************
154 * CPUFREQ DRIVER INTERFACE *
155 *********************************************************************/
156
157 #define CPUFREQ_RELATION_L 0 /* lowest frequency at or above target */
158 #define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */
159
160 struct cpufreq_driver {
161 const char *name;
162 int (*init)(struct cpufreq_policy *policy);
163 int (*verify)(struct cpufreq_policy *policy);
164 int (*setpolicy)(struct cpufreq_policy *policy);
165 int (*update)(unsigned int cpu, struct cpufreq_policy *policy);
166 int (*target)(struct cpufreq_policy *policy,
167 unsigned int target_freq,
168 unsigned int relation);
169 unsigned int (*get)(unsigned int cpu);
170 int (*exit)(struct cpufreq_policy *policy);
171 };
172
173 extern struct cpufreq_driver cpufreq_driver;
174
175 int cpufreq_register_driver(const struct cpufreq_driver *driver_data);
176
177 static inline
cpufreq_verify_within_limits(struct cpufreq_policy * policy,unsigned int min,unsigned int max)178 void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
179 unsigned int min, unsigned int max)
180 {
181 if (policy->min < min)
182 policy->min = min;
183 if (policy->max < min)
184 policy->max = min;
185 if (policy->min > max)
186 policy->min = max;
187 if (policy->max > max)
188 policy->max = max;
189 if (policy->min > policy->max)
190 policy->min = policy->max;
191 return;
192 }
193
194
195 /*********************************************************************
196 * FREQUENCY TABLE HELPERS *
197 *********************************************************************/
198
199 #define CPUFREQ_ENTRY_INVALID ~0
200 #define CPUFREQ_TABLE_END ~1
201
202 struct cpufreq_frequency_table {
203 unsigned int index; /* any */
204 unsigned int frequency; /* kHz - doesn't need to be in ascending
205 * order */
206 };
207
208 int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
209 struct cpufreq_frequency_table *table);
210
211 int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
212 struct cpufreq_frequency_table *table);
213
214 int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
215 struct cpufreq_frequency_table *table,
216 unsigned int target_freq,
217 unsigned int relation,
218 unsigned int *index);
219
220
221 /*********************************************************************
222 * UNIFIED DEBUG HELPERS *
223 *********************************************************************/
224
225 struct cpu_dbs_info_s {
226 uint64_t prev_cpu_idle;
227 uint64_t prev_cpu_wall;
228 struct cpufreq_policy *cur_policy;
229 struct cpufreq_frequency_table *freq_table;
230 int cpu;
231 unsigned int enable:1;
232 unsigned int turbo_enabled:1;
233 int8_t stoppable;
234 };
235
236 int get_cpufreq_ondemand_para(uint32_t *sampling_rate_max,
237 uint32_t *sampling_rate_min,
238 uint32_t *sampling_rate,
239 uint32_t *up_threshold);
240 int write_ondemand_sampling_rate(unsigned int sampling_rate);
241 int write_ondemand_up_threshold(unsigned int up_threshold);
242
243 int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq);
244
245 void cpufreq_dbs_timer_suspend(void);
246 void cpufreq_dbs_timer_resume(void);
247
248 void intel_feature_detect(struct cpufreq_policy *policy);
249
250 /*
251 * If Energy Performance Preference(epp) is supported in the platform,
252 * OSPM may write a range of values from 0(performance preference)
253 * to 0xFF(energy efficiency perference) to control the platform's
254 * energy efficiency and performance optimization policies
255 */
256 #define CPPC_ENERGY_PERF_MAX_PERFORMANCE 0
257 #define CPPC_ENERGY_PERF_BALANCE 0x80
258 #define CPPC_ENERGY_PERF_MAX_POWERSAVE 0xff
259
260 int hwp_cmdline_parse(const char *s, const char *e);
261 int hwp_register_driver(void);
262 #ifdef CONFIG_INTEL
263 bool hwp_active(void);
264 #else
hwp_active(void)265 static inline bool hwp_active(void) { return false; }
266 #endif
267
268 int get_hwp_para(unsigned int cpu,
269 struct xen_cppc_para *cppc_para);
270 int set_hwp_para(struct cpufreq_policy *policy,
271 struct xen_set_cppc_para *set_cppc);
272
273 int acpi_cpufreq_register(void);
274
275 #endif /* __XEN_CPUFREQ_PM_H__ */
276