processor.h 11 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5
#ifndef __ACPI_PROCESSOR_H
#define __ACPI_PROCESSOR_H

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

10 11 12
#define ACPI_PROCESSOR_CLASS		"processor"
#define ACPI_PROCESSOR_DEVICE_NAME	"Processor"
#define ACPI_PROCESSOR_DEVICE_HID	"ACPI0007"
13
#define ACPI_PROCESSOR_CONTAINER_HID	"ACPI0010"
14

Linus Torvalds's avatar
Linus Torvalds committed
15 16 17 18 19 20 21 22 23 24
#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

25 26
#define ACPI_PDC_REVISION_ID		0x1

Len Brown's avatar
Len Brown committed
27
#define ACPI_PSD_REV0_REVISION		0	/* Support for _PSD as in ACPI 3.0 */
28 29
#define ACPI_PSD_REV0_ENTRIES		5

30 31
#define ACPI_TSD_REV0_REVISION		0	/* Support for _PSD as in ACPI 3.0 */
#define ACPI_TSD_REV0_ENTRIES		5
32 33 34 35 36 37 38 39
/*
 * 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

40 41 42
#define ACPI_CSTATE_SYSTEMIO	0
#define ACPI_CSTATE_FFH		1
#define ACPI_CSTATE_HALT	2
43
#define ACPI_CSTATE_INTEGER	3
44 45

#define ACPI_CX_DESC_LEN	32
46

Linus Torvalds's avatar
Linus Torvalds committed
47 48 49 50 51
/* Power Management */

struct acpi_processor_cx;

struct acpi_power_register {
52 53 54 55 56
	u8 descriptor;
	u16 length;
	u8 space_id;
	u8 bit_width;
	u8 bit_offset;
57
	u8 access_size;
58
	u64 address;
59
} __packed;
Linus Torvalds's avatar
Linus Torvalds committed
60 61

struct acpi_processor_cx {
62 63 64
	u8 valid;
	u8 type;
	u32 address;
65
	u8 entry_method;
66
	u8 index;
67
	u32 latency;
68
	u8 bm_sts_skip;
69
	char desc[ACPI_CX_DESC_LEN];
Linus Torvalds's avatar
Linus Torvalds committed
70 71
};

72 73 74 75 76 77 78 79 80 81 82 83 84
struct acpi_lpi_state {
	u32 min_residency;
	u32 wake_latency; /* worst case */
	u32 flags;
	u32 arch_flags;
	u32 res_cnt_freq;
	u32 enable_parent_state;
	u64 address;
	u8 index;
	u8 entry_method;
	char desc[ACPI_CX_DESC_LEN];
};

Linus Torvalds's avatar
Linus Torvalds committed
85
struct acpi_processor_power {
86
	int count;
87 88 89 90
	union {
		struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
		struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER];
	};
91
	int timer_broadcast_on_state;
Linus Torvalds's avatar
Linus Torvalds committed
92 93 94 95
};

/* Performance Management */

96
struct acpi_psd_package {
97 98 99 100 101
	u64 num_entries;
	u64 revision;
	u64 domain;
	u64 coord_type;
	u64 num_processors;
102
} __packed;
103

Linus Torvalds's avatar
Linus Torvalds committed
104
struct acpi_pct_register {
105 106 107 108 109 110 111
	u8 descriptor;
	u16 length;
	u8 space_id;
	u8 bit_width;
	u8 bit_offset;
	u8 reserved;
	u64 address;
112
} __packed;
Linus Torvalds's avatar
Linus Torvalds committed
113 114

struct acpi_processor_px {
115 116 117 118 119 120
	u64 core_frequency;	/* megahertz */
	u64 power;	/* milliWatts */
	u64 transition_latency;	/* microseconds */
	u64 bus_master_latency;	/* microseconds */
	u64 control;	/* control value */
	u64 status;	/* success indicator */
Linus Torvalds's avatar
Linus Torvalds committed
121 122 123
};

struct acpi_processor_performance {
124 125
	unsigned int state;
	unsigned int platform_limit;
Linus Torvalds's avatar
Linus Torvalds committed
126 127
	struct acpi_pct_register control_register;
	struct acpi_pct_register status_register;
128
	unsigned int state_count;
Linus Torvalds's avatar
Linus Torvalds committed
129
	struct acpi_processor_px *states;
130
	struct acpi_psd_package domain_info;
131
	cpumask_var_t shared_cpu_map;
132
	unsigned int shared_type;
Linus Torvalds's avatar
Linus Torvalds committed
133 134 135 136
};

/* Throttling Control */

137
struct acpi_tsd_package {
138 139 140 141 142
	u64 num_entries;
	u64 revision;
	u64 domain;
	u64 coord_type;
	u64 num_processors;
143
} __packed;
144 145 146 147 148 149 150 151 152

struct acpi_ptc_register {
	u8 descriptor;
	u16 length;
	u8 space_id;
	u8 bit_width;
	u8 bit_offset;
	u8 reserved;
	u64 address;
153
} __packed;
154 155

struct acpi_processor_tx_tss {
156 157 158 159 160
	u64 freqpercentage;	/* */
	u64 power;	/* milliWatts */
	u64 transition_latency;	/* microseconds */
	u64 control;	/* control value */
	u64 status;	/* success indicator */
161
};
Linus Torvalds's avatar
Linus Torvalds committed
162
struct acpi_processor_tx {
163 164
	u16 power;
	u16 performance;
Linus Torvalds's avatar
Linus Torvalds committed
165 166
};

167
struct acpi_processor;
Linus Torvalds's avatar
Linus Torvalds committed
168
struct acpi_processor_throttling {
169 170 171 172 173 174 175
	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;
176
	cpumask_var_t shared_cpu_map;
177 178
	int (*acpi_processor_get_throttling) (struct acpi_processor * pr);
	int (*acpi_processor_set_throttling) (struct acpi_processor * pr,
179
					      int state, bool force);
180

181 182 183
	u32 address;
	u8 duty_offset;
	u8 duty_width;
184 185
	u8 tsd_valid_flag;
	unsigned int shared_type;
Linus Torvalds's avatar
Linus Torvalds committed
186 187 188 189 190 191
	struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
};

/* Limit Interface */

struct acpi_processor_lx {
192
	int px;			/* performance state */
193
	int tx;			/* throttle level */
Linus Torvalds's avatar
Linus Torvalds committed
194 195 196
};

struct acpi_processor_limit {
197
	struct acpi_processor_lx state;	/* current limit */
Linus Torvalds's avatar
Linus Torvalds committed
198
	struct acpi_processor_lx thermal;	/* thermal limit */
199
	struct acpi_processor_lx user;	/* user limit */
Linus Torvalds's avatar
Linus Torvalds committed
200 201 202
};

struct acpi_processor_flags {
203 204 205 206 207 208 209
	u8 power:1;
	u8 performance:1;
	u8 throttling:1;
	u8 limit:1;
	u8 bm_control:1;
	u8 bm_check:1;
	u8 has_cst:1;
210
	u8 has_lpi:1;
211
	u8 power_setup_done:1;
212
	u8 bm_rld_set:1;
213
	u8 need_hotplug_init:1;
Linus Torvalds's avatar
Linus Torvalds committed
214 215 216
};

struct acpi_processor {
217 218
	acpi_handle handle;
	u32 acpi_id;
219
	phys_cpuid_t phys_id;	/* CPU hardware ID such as APIC ID for x86 */
220
	u32 id;		/* CPU logical ID allocated by OS */
221 222
	u32 pblk;
	int performance_platform_limit;
223
	int throttling_platform_limit;
224
	/* 0 - states 0..n-th state available */
225

Linus Torvalds's avatar
Linus Torvalds committed
226 227 228 229 230
	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;
231
	struct thermal_cooling_device *cdev;
232
	struct device *dev; /* Processor device. */
Linus Torvalds's avatar
Linus Torvalds committed
233 234 235
};

struct acpi_processor_errata {
236
	u8 smp;
Linus Torvalds's avatar
Linus Torvalds committed
237
	struct {
238 239 240 241 242
		u8 throttle:1;
		u8 fdma:1;
		u8 reserved:6;
		u32 bmisx;
	} piix4;
Linus Torvalds's avatar
Linus Torvalds committed
243 244
};

Len Brown's avatar
Len Brown committed
245 246
extern int acpi_processor_preregister_performance(struct
						  acpi_processor_performance
247
						  __percpu *performance);
248

249 250
extern int acpi_processor_register_performance(struct acpi_processor_performance
					       *performance, unsigned int cpu);
251
extern void acpi_processor_unregister_performance(unsigned int cpu);
Linus Torvalds's avatar
Linus Torvalds committed
252

253
int acpi_processor_pstate_control(void);
Linus Torvalds's avatar
Linus Torvalds committed
254 255 256
/* 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);
257 258
int acpi_processor_get_psd(acpi_handle handle,
			   struct acpi_psd_package *pdomain);
Linus Torvalds's avatar
Linus Torvalds committed
259

260 261 262
/* parsing the _P* objects. */
extern int acpi_processor_get_performance_info(struct acpi_processor *pr);

Linus Torvalds's avatar
Linus Torvalds committed
263
/* for communication between multiple parts of the processor kernel module */
264
DECLARE_PER_CPU(struct acpi_processor *, processors);
Linus Torvalds's avatar
Linus Torvalds committed
265 266
extern struct acpi_processor_errata errata;

267
#if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
268
void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
269
					unsigned int cpu);
270
int acpi_processor_ffh_cstate_probe(unsigned int cpu,
Len Brown's avatar
Len Brown committed
271 272
				    struct acpi_processor_cx *cx,
				    struct acpi_power_register *reg);
273
void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
274
#else
275 276 277
static inline void acpi_processor_power_init_bm_check(struct
						      acpi_processor_flags
						      *flags, unsigned int cpu)
278 279 280 281
{
	flags->bm_check = 1;
	return;
}
282
static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
Len Brown's avatar
Len Brown committed
283 284 285
						  struct acpi_processor_cx *cx,
						  struct acpi_power_register
						  *reg)
286 287 288
{
	return -1;
}
Len Brown's avatar
Len Brown committed
289 290
static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
						   *cstate)
291 292 293
{
	return;
}
294 295
#endif

Linus Torvalds's avatar
Linus Torvalds committed
296
/* in processor_perflib.c */
297

Linus Torvalds's avatar
Linus Torvalds committed
298 299 300
#ifdef CONFIG_CPU_FREQ
void acpi_processor_ppc_init(void);
void acpi_processor_ppc_exit(void);
301
void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag);
302
extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit);
Linus Torvalds's avatar
Linus Torvalds committed
303
#else
304 305 306 307 308 309 310 311
static inline void acpi_processor_ppc_init(void)
{
	return;
}
static inline void acpi_processor_ppc_exit(void)
{
	return;
}
312
static inline void acpi_processor_ppc_has_changed(struct acpi_processor *pr,
313
								int event_flag)
314
{
Linus Torvalds's avatar
Linus Torvalds committed
315 316
	static unsigned int printout = 1;
	if (printout) {
317 318 319 320
		printk(KERN_WARNING
		       "Warning: Processor Platform Limit event detected, but not handled.\n");
		printk(KERN_WARNING
		       "Consider compiling CPUfreq support into your kernel.\n");
Linus Torvalds's avatar
Linus Torvalds committed
321 322 323
		printout = 0;
	}
}
324 325 326 327 328
static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
{
	return -ENODEV;
}

329
#endif				/* CONFIG_CPU_FREQ */
Linus Torvalds's avatar
Linus Torvalds committed
330

331
/* in processor_core.c */
332
phys_cpuid_t acpi_get_phys_id(acpi_handle, int type, u32 acpi_id);
333
phys_cpuid_t acpi_map_madt_entry(u32 acpi_id);
334
int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id);
335
int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
336

337 338 339 340 341 342 343 344 345 346 347 348 349 350
#ifdef CONFIG_ACPI_CPPC_LIB
extern int acpi_cppc_processor_probe(struct acpi_processor *pr);
extern void acpi_cppc_processor_exit(struct acpi_processor *pr);
#else
static inline int acpi_cppc_processor_probe(struct acpi_processor *pr)
{
	return 0;
}
static inline void acpi_cppc_processor_exit(struct acpi_processor *pr)
{
	return;
}
#endif	/* CONFIG_ACPI_CPPC_LIB */

351 352 353
/* in processor_pdc.c */
void acpi_processor_set_pdc(acpi_handle handle);

Linus Torvalds's avatar
Linus Torvalds committed
354
/* in processor_throttling.c */
355
#ifdef CONFIG_ACPI_CPU_FREQ_PSS
356
int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
357
int acpi_processor_get_throttling_info(struct acpi_processor *pr);
358 359
extern int acpi_processor_set_throttling(struct acpi_processor *pr,
					 int state, bool force);
360 361 362 363 364
/*
 * 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,
365
			bool is_dead);
366
extern const struct file_operations acpi_processor_throttling_fops;
367
extern void acpi_processor_throttling_init(void);
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
#else
static inline int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
{
	return 0;
}

static inline int acpi_processor_get_throttling_info(struct acpi_processor *pr)
{
	return -ENODEV;
}

static inline int acpi_processor_set_throttling(struct acpi_processor *pr,
					 int state, bool force)
{
	return -ENODEV;
}

static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
386
			bool is_dead) {}
387 388 389 390

static inline void acpi_processor_throttling_init(void) {}
#endif	/* CONFIG_ACPI_CPU_FREQ_PSS */

Linus Torvalds's avatar
Linus Torvalds committed
391
/* in processor_idle.c */
392 393
extern struct cpuidle_driver acpi_idle_driver;
#ifdef CONFIG_ACPI_PROCESSOR_IDLE
394 395
int acpi_processor_power_init(struct acpi_processor *pr);
int acpi_processor_power_exit(struct acpi_processor *pr);
396
int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
397
int acpi_processor_hotplug(struct acpi_processor *pr);
398 399 400 401 402 403 404 405 406 407 408
#else
static inline int acpi_processor_power_init(struct acpi_processor *pr)
{
	return -ENODEV;
}

static inline int acpi_processor_power_exit(struct acpi_processor *pr)
{
	return -ENODEV;
}

409
static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
410 411 412 413 414 415 416 417 418
{
	return -ENODEV;
}

static inline int acpi_processor_hotplug(struct acpi_processor *pr)
{
	return -ENODEV;
}
#endif /* CONFIG_ACPI_PROCESSOR_IDLE */
Linus Torvalds's avatar
Linus Torvalds committed
419 420

/* in processor_thermal.c */
421
int acpi_processor_get_limit_info(struct acpi_processor *pr);
422
extern const struct thermal_cooling_device_ops processor_cooling_ops;
423
#if defined(CONFIG_ACPI_CPU_FREQ_PSS) & defined(CONFIG_CPU_FREQ)
Linus Torvalds's avatar
Linus Torvalds committed
424 425 426
void acpi_thermal_cpufreq_init(void);
void acpi_thermal_cpufreq_exit(void);
#else
427 428 429 430 431 432 433 434
static inline void acpi_thermal_cpufreq_init(void)
{
	return;
}
static inline void acpi_thermal_cpufreq_exit(void)
{
	return;
}
435
#endif	/* CONFIG_ACPI_CPU_FREQ_PSS */
Linus Torvalds's avatar
Linus Torvalds committed
436 437

#endif