processor.h 8.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4
#ifndef __ACPI_PROCESSOR_H
#define __ACPI_PROCESSOR_H

#include <linux/kernel.h>
5
#include <linux/cpu.h>
6
#include <linux/cpuidle.h>
7
#include <linux/thermal.h>
8 9
#include <asm/acpi.h>

L
Linus Torvalds 已提交
10 11 12 13 14 15 16 17 18 19
#define ACPI_PROCESSOR_BUSY_METRIC	10

#define ACPI_PROCESSOR_MAX_POWER	8
#define ACPI_PROCESSOR_MAX_C2_LATENCY	100
#define ACPI_PROCESSOR_MAX_C3_LATENCY	1000

#define ACPI_PROCESSOR_MAX_THROTTLING	16
#define ACPI_PROCESSOR_MAX_THROTTLE	250	/* 25% */
#define ACPI_PROCESSOR_MAX_DUTY_WIDTH	4

20 21
#define ACPI_PDC_REVISION_ID		0x1

L
Len Brown 已提交
22
#define ACPI_PSD_REV0_REVISION		0	/* Support for _PSD as in ACPI 3.0 */
23 24
#define ACPI_PSD_REV0_ENTRIES		5

25 26
#define ACPI_TSD_REV0_REVISION		0	/* Support for _PSD as in ACPI 3.0 */
#define ACPI_TSD_REV0_ENTRIES		5
27 28 29 30 31 32 33 34
/*
 * Types of coordination defined in ACPI 3.0. Same macros can be used across
 * P, C and T states
 */
#define DOMAIN_COORD_TYPE_SW_ALL	0xfc
#define DOMAIN_COORD_TYPE_SW_ANY	0xfd
#define DOMAIN_COORD_TYPE_HW_ALL	0xfe

35 36 37 38 39
#define ACPI_CSTATE_SYSTEMIO	0
#define ACPI_CSTATE_FFH		1
#define ACPI_CSTATE_HALT	2

#define ACPI_CX_DESC_LEN	32
40

L
Linus Torvalds 已提交
41 42 43 44 45
/* Power Management */

struct acpi_processor_cx;

struct acpi_power_register {
L
Len Brown 已提交
46 47 48 49 50
	u8 descriptor;
	u16 length;
	u8 space_id;
	u8 bit_width;
	u8 bit_offset;
51
	u8 access_size;
L
Len Brown 已提交
52
	u64 address;
L
Linus Torvalds 已提交
53 54 55
} __attribute__ ((packed));

struct acpi_processor_cx {
L
Len Brown 已提交
56 57 58
	u8 valid;
	u8 type;
	u32 address;
59
	u8 entry_method;
60
	u8 index;
L
Len Brown 已提交
61 62 63 64
	u32 latency;
	u32 latency_ticks;
	u32 power;
	u32 usage;
65
	u64 time;
66
	u8 bm_sts_skip;
67
	char desc[ACPI_CX_DESC_LEN];
L
Linus Torvalds 已提交
68 69 70
};

struct acpi_processor_power {
71
	struct cpuidle_device dev;
L
Linus Torvalds 已提交
72
	struct acpi_processor_cx *state;
L
Len Brown 已提交
73 74 75
	unsigned long bm_check_timestamp;
	u32 default_state;
	int count;
L
Linus Torvalds 已提交
76
	struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
77
	int timer_broadcast_on_state;
L
Linus Torvalds 已提交
78 79 80 81
};

/* Performance Management */

82
struct acpi_psd_package {
L
Lin Ming 已提交
83 84 85 86 87
	u64 num_entries;
	u64 revision;
	u64 domain;
	u64 coord_type;
	u64 num_processors;
88 89
} __attribute__ ((packed));

L
Linus Torvalds 已提交
90
struct acpi_pct_register {
L
Len Brown 已提交
91 92 93 94 95 96 97
	u8 descriptor;
	u16 length;
	u8 space_id;
	u8 bit_width;
	u8 bit_offset;
	u8 reserved;
	u64 address;
L
Linus Torvalds 已提交
98 99 100
} __attribute__ ((packed));

struct acpi_processor_px {
L
Lin Ming 已提交
101 102 103 104 105 106
	u64 core_frequency;	/* megahertz */
	u64 power;	/* milliWatts */
	u64 transition_latency;	/* microseconds */
	u64 bus_master_latency;	/* microseconds */
	u64 control;	/* control value */
	u64 status;	/* success indicator */
L
Linus Torvalds 已提交
107 108 109
};

struct acpi_processor_performance {
L
Len Brown 已提交
110 111
	unsigned int state;
	unsigned int platform_limit;
L
Linus Torvalds 已提交
112 113
	struct acpi_pct_register control_register;
	struct acpi_pct_register status_register;
L
Len Brown 已提交
114
	unsigned int state_count;
L
Linus Torvalds 已提交
115
	struct acpi_processor_px *states;
116
	struct acpi_psd_package domain_info;
117
	cpumask_var_t shared_cpu_map;
118
	unsigned int shared_type;
L
Linus Torvalds 已提交
119 120 121 122
};

/* Throttling Control */

123
struct acpi_tsd_package {
L
Lin Ming 已提交
124 125 126 127 128
	u64 num_entries;
	u64 revision;
	u64 domain;
	u64 coord_type;
	u64 num_processors;
129 130 131 132 133 134 135 136 137 138 139 140 141
} __attribute__ ((packed));

struct acpi_ptc_register {
	u8 descriptor;
	u16 length;
	u8 space_id;
	u8 bit_width;
	u8 bit_offset;
	u8 reserved;
	u64 address;
} __attribute__ ((packed));

struct acpi_processor_tx_tss {
L
Lin Ming 已提交
142 143 144 145 146
	u64 freqpercentage;	/* */
	u64 power;	/* milliWatts */
	u64 transition_latency;	/* microseconds */
	u64 control;	/* control value */
	u64 status;	/* success indicator */
147
};
L
Linus Torvalds 已提交
148
struct acpi_processor_tx {
L
Len Brown 已提交
149 150
	u16 power;
	u16 performance;
L
Linus Torvalds 已提交
151 152
};

153
struct acpi_processor;
L
Linus Torvalds 已提交
154
struct acpi_processor_throttling {
155 156 157 158 159 160 161
	unsigned int state;
	unsigned int platform_limit;
	struct acpi_pct_register control_register;
	struct acpi_pct_register status_register;
	unsigned int state_count;
	struct acpi_processor_tx_tss *states_tss;
	struct acpi_tsd_package domain_info;
162
	cpumask_var_t shared_cpu_map;
163 164
	int (*acpi_processor_get_throttling) (struct acpi_processor * pr);
	int (*acpi_processor_set_throttling) (struct acpi_processor * pr,
165
					      int state, bool force);
166

L
Len Brown 已提交
167 168 169
	u32 address;
	u8 duty_offset;
	u8 duty_width;
170 171
	u8 tsd_valid_flag;
	unsigned int shared_type;
L
Linus Torvalds 已提交
172 173 174 175 176 177
	struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
};

/* Limit Interface */

struct acpi_processor_lx {
J
Joe Perches 已提交
178
	int px;			/* performance state */
L
Len Brown 已提交
179
	int tx;			/* throttle level */
L
Linus Torvalds 已提交
180 181 182
};

struct acpi_processor_limit {
L
Len Brown 已提交
183
	struct acpi_processor_lx state;	/* current limit */
L
Linus Torvalds 已提交
184
	struct acpi_processor_lx thermal;	/* thermal limit */
L
Len Brown 已提交
185
	struct acpi_processor_lx user;	/* user limit */
L
Linus Torvalds 已提交
186 187 188
};

struct acpi_processor_flags {
L
Len Brown 已提交
189 190 191 192 193 194 195 196
	u8 power:1;
	u8 performance:1;
	u8 throttling:1;
	u8 limit:1;
	u8 bm_control:1;
	u8 bm_check:1;
	u8 has_cst:1;
	u8 power_setup_done:1;
197
	u8 bm_rld_set:1;
L
Linus Torvalds 已提交
198 199 200
};

struct acpi_processor {
L
Len Brown 已提交
201 202 203 204 205
	acpi_handle handle;
	u32 acpi_id;
	u32 id;
	u32 pblk;
	int performance_platform_limit;
206
	int throttling_platform_limit;
207
	/* 0 - states 0..n-th state available */
208

L
Linus Torvalds 已提交
209 210 211 212 213
	struct acpi_processor_flags flags;
	struct acpi_processor_power power;
	struct acpi_processor_performance *performance;
	struct acpi_processor_throttling throttling;
	struct acpi_processor_limit limit;
214
	struct thermal_cooling_device *cdev;
L
Linus Torvalds 已提交
215 216 217
};

struct acpi_processor_errata {
L
Len Brown 已提交
218
	u8 smp;
L
Linus Torvalds 已提交
219
	struct {
L
Len Brown 已提交
220 221 222 223 224
		u8 throttle:1;
		u8 fdma:1;
		u8 reserved:6;
		u32 bmisx;
	} piix4;
L
Linus Torvalds 已提交
225 226
};

L
Len Brown 已提交
227 228
extern int acpi_processor_preregister_performance(struct
						  acpi_processor_performance
229
						  __percpu *performance);
230

L
Len Brown 已提交
231 232 233 234 235 236
extern int acpi_processor_register_performance(struct acpi_processor_performance
					       *performance, unsigned int cpu);
extern void acpi_processor_unregister_performance(struct
						  acpi_processor_performance
						  *performance,
						  unsigned int cpu);
L
Linus Torvalds 已提交
237 238 239 240 241 242

/* note: this locks both the calling module and the processor module
         if a _PPC object exists, rmmod is disallowed then */
int acpi_processor_notify_smm(struct module *calling_module);

/* for communication between multiple parts of the processor kernel module */
243
DECLARE_PER_CPU(struct acpi_processor *, processors);
L
Linus Torvalds 已提交
244 245
extern struct acpi_processor_errata errata;

246
#ifdef ARCH_HAS_POWER_INIT
247
void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
L
Len Brown 已提交
248
					unsigned int cpu);
249
int acpi_processor_ffh_cstate_probe(unsigned int cpu,
L
Len Brown 已提交
250 251
				    struct acpi_processor_cx *cx,
				    struct acpi_power_register *reg);
252
void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
253
#else
L
Len Brown 已提交
254 255 256
static inline void acpi_processor_power_init_bm_check(struct
						      acpi_processor_flags
						      *flags, unsigned int cpu)
257 258 259 260
{
	flags->bm_check = 1;
	return;
}
261
static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
L
Len Brown 已提交
262 263 264
						  struct acpi_processor_cx *cx,
						  struct acpi_power_register
						  *reg)
265 266 267
{
	return -1;
}
L
Len Brown 已提交
268 269
static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
						   *cstate)
270 271 272
{
	return;
}
273 274
#endif

L
Linus Torvalds 已提交
275
/* in processor_perflib.c */
276

L
Linus Torvalds 已提交
277 278 279
#ifdef CONFIG_CPU_FREQ
void acpi_processor_ppc_init(void);
void acpi_processor_ppc_exit(void);
280
int acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag);
281
extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit);
L
Linus Torvalds 已提交
282
#else
L
Len Brown 已提交
283 284 285 286 287 288 289 290
static inline void acpi_processor_ppc_init(void)
{
	return;
}
static inline void acpi_processor_ppc_exit(void)
{
	return;
}
291 292
static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr,
								int event_flag)
L
Len Brown 已提交
293
{
L
Linus Torvalds 已提交
294 295
	static unsigned int printout = 1;
	if (printout) {
L
Len Brown 已提交
296 297 298 299
		printk(KERN_WARNING
		       "Warning: Processor Platform Limit event detected, but not handled.\n");
		printk(KERN_WARNING
		       "Consider compiling CPUfreq support into your kernel.\n");
L
Linus Torvalds 已提交
300 301 302 303
		printout = 0;
	}
	return 0;
}
304 305 306 307 308
static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
{
	return -ENODEV;
}

L
Len Brown 已提交
309
#endif				/* CONFIG_CPU_FREQ */
L
Linus Torvalds 已提交
310

311
/* in processor_core.c */
312
void acpi_processor_set_pdc(acpi_handle handle);
313
int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
A
Alex Chiang 已提交
314

L
Linus Torvalds 已提交
315
/* in processor_throttling.c */
316
int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
L
Len Brown 已提交
317
int acpi_processor_get_throttling_info(struct acpi_processor *pr);
318 319
extern int acpi_processor_set_throttling(struct acpi_processor *pr,
					 int state, bool force);
320 321 322 323 324 325
/*
 * Reevaluate whether the T-state is invalid after one cpu is
 * onlined/offlined. In such case the flags.throttling will be updated.
 */
extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
			unsigned long action);
J
Jan Engelhardt 已提交
326
extern const struct file_operations acpi_processor_throttling_fops;
327
extern void acpi_processor_throttling_init(void);
L
Linus Torvalds 已提交
328
/* in processor_idle.c */
L
Len Brown 已提交
329 330 331
int acpi_processor_power_init(struct acpi_processor *pr,
			      struct acpi_device *device);
int acpi_processor_cst_has_changed(struct acpi_processor *pr);
332
int acpi_processor_hotplug(struct acpi_processor *pr);
L
Len Brown 已提交
333 334
int acpi_processor_power_exit(struct acpi_processor *pr,
			      struct acpi_device *device);
335 336
int acpi_processor_suspend(struct acpi_device * device, pm_message_t state);
int acpi_processor_resume(struct acpi_device * device);
337
extern struct cpuidle_driver acpi_idle_driver;
L
Linus Torvalds 已提交
338 339

/* in processor_thermal.c */
L
Len Brown 已提交
340
int acpi_processor_get_limit_info(struct acpi_processor *pr);
V
Vasiliy Kulikov 已提交
341
extern const struct thermal_cooling_device_ops processor_cooling_ops;
L
Linus Torvalds 已提交
342 343 344 345
#ifdef CONFIG_CPU_FREQ
void acpi_thermal_cpufreq_init(void);
void acpi_thermal_cpufreq_exit(void);
#else
L
Len Brown 已提交
346 347 348 349 350 351 352 353
static inline void acpi_thermal_cpufreq_init(void)
{
	return;
}
static inline void acpi_thermal_cpufreq_exit(void)
{
	return;
}
L
Linus Torvalds 已提交
354 355 356
#endif

#endif