]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __ACPI_PROCESSOR_H |
3 | #define __ACPI_PROCESSOR_H | |
4 | ||
5 | #include <linux/kernel.h> | |
3b2d9942 | 6 | #include <linux/cpu.h> |
d15ce412 VK |
7 | #include <linux/cpufreq.h> |
8 | #include <linux/pm_qos.h> | |
d9460fd2 | 9 | #include <linux/thermal.h> |
02df8b93 VP |
10 | #include <asm/acpi.h> |
11 | ||
ac212b69 RW |
12 | #define ACPI_PROCESSOR_CLASS "processor" |
13 | #define ACPI_PROCESSOR_DEVICE_NAME "Processor" | |
14 | #define ACPI_PROCESSOR_DEVICE_HID "ACPI0007" | |
db62fda3 | 15 | #define ACPI_PROCESSOR_CONTAINER_HID "ACPI0010" |
ac212b69 | 16 | |
1da177e4 LT |
17 | #define ACPI_PROCESSOR_BUSY_METRIC 10 |
18 | ||
19 | #define ACPI_PROCESSOR_MAX_POWER 8 | |
20 | #define ACPI_PROCESSOR_MAX_C2_LATENCY 100 | |
21 | #define ACPI_PROCESSOR_MAX_C3_LATENCY 1000 | |
22 | ||
23 | #define ACPI_PROCESSOR_MAX_THROTTLING 16 | |
24 | #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */ | |
25 | #define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4 | |
26 | ||
02df8b93 VP |
27 | #define ACPI_PDC_REVISION_ID 0x1 |
28 | ||
fd350943 | 29 | #define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ |
3b2d9942 VP |
30 | #define ACPI_PSD_REV0_ENTRIES 5 |
31 | ||
01854e69 LY |
32 | #define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ |
33 | #define ACPI_TSD_REV0_ENTRIES 5 | |
3b2d9942 VP |
34 | /* |
35 | * Types of coordination defined in ACPI 3.0. Same macros can be used across | |
36 | * P, C and T states | |
37 | */ | |
38 | #define DOMAIN_COORD_TYPE_SW_ALL 0xfc | |
39 | #define DOMAIN_COORD_TYPE_SW_ANY 0xfd | |
40 | #define DOMAIN_COORD_TYPE_HW_ALL 0xfe | |
41 | ||
4fcb2fcd VP |
42 | #define ACPI_CSTATE_SYSTEMIO 0 |
43 | #define ACPI_CSTATE_FFH 1 | |
44 | #define ACPI_CSTATE_HALT 2 | |
a36a7fec | 45 | #define ACPI_CSTATE_INTEGER 3 |
4fcb2fcd VP |
46 | |
47 | #define ACPI_CX_DESC_LEN 32 | |
991528d7 | 48 | |
1da177e4 LT |
49 | /* Power Management */ |
50 | ||
51 | struct acpi_processor_cx; | |
52 | ||
53 | struct acpi_power_register { | |
4be44fcd LB |
54 | u8 descriptor; |
55 | u16 length; | |
56 | u8 space_id; | |
57 | u8 bit_width; | |
58 | u8 bit_offset; | |
718be4aa | 59 | u8 access_size; |
4be44fcd | 60 | u64 address; |
92c4d2ad | 61 | } __packed; |
1da177e4 | 62 | |
1da177e4 | 63 | struct acpi_processor_cx { |
4be44fcd LB |
64 | u8 valid; |
65 | u8 type; | |
66 | u32 address; | |
bc71bec9 | 67 | u8 entry_method; |
991528d7 | 68 | u8 index; |
4be44fcd | 69 | u32 latency; |
718be4aa | 70 | u8 bm_sts_skip; |
4fcb2fcd | 71 | char desc[ACPI_CX_DESC_LEN]; |
1da177e4 LT |
72 | }; |
73 | ||
a36a7fec SH |
74 | struct acpi_lpi_state { |
75 | u32 min_residency; | |
76 | u32 wake_latency; /* worst case */ | |
77 | u32 flags; | |
78 | u32 arch_flags; | |
79 | u32 res_cnt_freq; | |
80 | u32 enable_parent_state; | |
81 | u64 address; | |
82 | u8 index; | |
83 | u8 entry_method; | |
84 | char desc[ACPI_CX_DESC_LEN]; | |
85 | }; | |
86 | ||
1da177e4 | 87 | struct acpi_processor_power { |
4be44fcd | 88 | int count; |
a36a7fec SH |
89 | union { |
90 | struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER]; | |
91 | struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER]; | |
92 | }; | |
169a0abb | 93 | int timer_broadcast_on_state; |
1da177e4 LT |
94 | }; |
95 | ||
96 | /* Performance Management */ | |
97 | ||
3b2d9942 | 98 | struct acpi_psd_package { |
439913ff LM |
99 | u64 num_entries; |
100 | u64 revision; | |
101 | u64 domain; | |
102 | u64 coord_type; | |
103 | u64 num_processors; | |
92c4d2ad | 104 | } __packed; |
3b2d9942 | 105 | |
1da177e4 | 106 | struct acpi_pct_register { |
4be44fcd LB |
107 | u8 descriptor; |
108 | u16 length; | |
109 | u8 space_id; | |
110 | u8 bit_width; | |
111 | u8 bit_offset; | |
112 | u8 reserved; | |
113 | u64 address; | |
92c4d2ad | 114 | } __packed; |
1da177e4 LT |
115 | |
116 | struct acpi_processor_px { | |
439913ff LM |
117 | u64 core_frequency; /* megahertz */ |
118 | u64 power; /* milliWatts */ | |
119 | u64 transition_latency; /* microseconds */ | |
120 | u64 bus_master_latency; /* microseconds */ | |
121 | u64 control; /* control value */ | |
122 | u64 status; /* success indicator */ | |
1da177e4 LT |
123 | }; |
124 | ||
1da177e4 | 125 | struct acpi_processor_performance { |
4be44fcd LB |
126 | unsigned int state; |
127 | unsigned int platform_limit; | |
1da177e4 LT |
128 | struct acpi_pct_register control_register; |
129 | struct acpi_pct_register status_register; | |
4be44fcd | 130 | unsigned int state_count; |
1da177e4 | 131 | struct acpi_processor_px *states; |
3b2d9942 | 132 | struct acpi_psd_package domain_info; |
2fdf66b4 | 133 | cpumask_var_t shared_cpu_map; |
3b2d9942 | 134 | unsigned int shared_type; |
1da177e4 LT |
135 | }; |
136 | ||
1da177e4 LT |
137 | /* Throttling Control */ |
138 | ||
01854e69 | 139 | struct acpi_tsd_package { |
439913ff LM |
140 | u64 num_entries; |
141 | u64 revision; | |
142 | u64 domain; | |
143 | u64 coord_type; | |
144 | u64 num_processors; | |
92c4d2ad | 145 | } __packed; |
01854e69 LY |
146 | |
147 | struct acpi_ptc_register { | |
148 | u8 descriptor; | |
149 | u16 length; | |
150 | u8 space_id; | |
151 | u8 bit_width; | |
152 | u8 bit_offset; | |
153 | u8 reserved; | |
154 | u64 address; | |
92c4d2ad | 155 | } __packed; |
01854e69 LY |
156 | |
157 | struct acpi_processor_tx_tss { | |
439913ff LM |
158 | u64 freqpercentage; /* */ |
159 | u64 power; /* milliWatts */ | |
160 | u64 transition_latency; /* microseconds */ | |
161 | u64 control; /* control value */ | |
162 | u64 status; /* success indicator */ | |
01854e69 | 163 | }; |
1da177e4 | 164 | struct acpi_processor_tx { |
4be44fcd LB |
165 | u16 power; |
166 | u16 performance; | |
1da177e4 LT |
167 | }; |
168 | ||
01854e69 | 169 | struct acpi_processor; |
1da177e4 | 170 | struct acpi_processor_throttling { |
01854e69 LY |
171 | unsigned int state; |
172 | unsigned int platform_limit; | |
173 | struct acpi_pct_register control_register; | |
174 | struct acpi_pct_register status_register; | |
175 | unsigned int state_count; | |
176 | struct acpi_processor_tx_tss *states_tss; | |
177 | struct acpi_tsd_package domain_info; | |
2fdf66b4 | 178 | cpumask_var_t shared_cpu_map; |
ff55a9ce LB |
179 | int (*acpi_processor_get_throttling) (struct acpi_processor * pr); |
180 | int (*acpi_processor_set_throttling) (struct acpi_processor * pr, | |
2a908002 | 181 | int state, bool force); |
01854e69 | 182 | |
4be44fcd LB |
183 | u32 address; |
184 | u8 duty_offset; | |
185 | u8 duty_width; | |
1180509f ZY |
186 | u8 tsd_valid_flag; |
187 | unsigned int shared_type; | |
1da177e4 LT |
188 | struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING]; |
189 | }; | |
190 | ||
191 | /* Limit Interface */ | |
192 | ||
193 | struct acpi_processor_lx { | |
aee07ba6 | 194 | int px; /* performance state */ |
4be44fcd | 195 | int tx; /* throttle level */ |
1da177e4 LT |
196 | }; |
197 | ||
198 | struct acpi_processor_limit { | |
4be44fcd | 199 | struct acpi_processor_lx state; /* current limit */ |
1da177e4 | 200 | struct acpi_processor_lx thermal; /* thermal limit */ |
4be44fcd | 201 | struct acpi_processor_lx user; /* user limit */ |
1da177e4 LT |
202 | }; |
203 | ||
1da177e4 | 204 | struct acpi_processor_flags { |
4be44fcd LB |
205 | u8 power:1; |
206 | u8 performance:1; | |
207 | u8 throttling:1; | |
208 | u8 limit:1; | |
209 | u8 bm_control:1; | |
210 | u8 bm_check:1; | |
211 | u8 has_cst:1; | |
a36a7fec | 212 | u8 has_lpi:1; |
4be44fcd | 213 | u8 power_setup_done:1; |
4f86d3a8 | 214 | u8 bm_rld_set:1; |
99b72508 | 215 | u8 need_hotplug_init:1; |
1da177e4 LT |
216 | }; |
217 | ||
218 | struct acpi_processor { | |
4be44fcd LB |
219 | acpi_handle handle; |
220 | u32 acpi_id; | |
828aef37 | 221 | phys_cpuid_t phys_id; /* CPU hardware ID such as APIC ID for x86 */ |
af8f3f51 | 222 | u32 id; /* CPU logical ID allocated by OS */ |
4be44fcd LB |
223 | u32 pblk; |
224 | int performance_platform_limit; | |
01854e69 | 225 | int throttling_platform_limit; |
ff55a9ce | 226 | /* 0 - states 0..n-th state available */ |
01854e69 | 227 | |
1da177e4 LT |
228 | struct acpi_processor_flags flags; |
229 | struct acpi_processor_power power; | |
230 | struct acpi_processor_performance *performance; | |
231 | struct acpi_processor_throttling throttling; | |
232 | struct acpi_processor_limit limit; | |
d9460fd2 | 233 | struct thermal_cooling_device *cdev; |
ac212b69 | 234 | struct device *dev; /* Processor device. */ |
d15ce412 VK |
235 | struct dev_pm_qos_request perflib_req; |
236 | struct dev_pm_qos_request thermal_req; | |
1da177e4 LT |
237 | }; |
238 | ||
239 | struct acpi_processor_errata { | |
4be44fcd | 240 | u8 smp; |
1da177e4 | 241 | struct { |
4be44fcd LB |
242 | u8 throttle:1; |
243 | u8 fdma:1; | |
244 | u8 reserved:6; | |
245 | u32 bmisx; | |
246 | } piix4; | |
1da177e4 LT |
247 | }; |
248 | ||
fd350943 LB |
249 | extern int acpi_processor_preregister_performance(struct |
250 | acpi_processor_performance | |
a29d8b8e | 251 | __percpu *performance); |
3b2d9942 | 252 | |
4be44fcd LB |
253 | extern int acpi_processor_register_performance(struct acpi_processor_performance |
254 | *performance, unsigned int cpu); | |
b2f8dc4c | 255 | extern void acpi_processor_unregister_performance(unsigned int cpu); |
1da177e4 | 256 | |
d0ea59e1 | 257 | int acpi_processor_pstate_control(void); |
1da177e4 LT |
258 | /* note: this locks both the calling module and the processor module |
259 | if a _PPC object exists, rmmod is disallowed then */ | |
260 | int acpi_processor_notify_smm(struct module *calling_module); | |
4d0f1ce6 JM |
261 | int acpi_processor_get_psd(acpi_handle handle, |
262 | struct acpi_psd_package *pdomain); | |
1da177e4 | 263 | |
c705c78c KRW |
264 | /* parsing the _P* objects. */ |
265 | extern int acpi_processor_get_performance_info(struct acpi_processor *pr); | |
266 | ||
1da177e4 | 267 | /* for communication between multiple parts of the processor kernel module */ |
706546d0 | 268 | DECLARE_PER_CPU(struct acpi_processor *, processors); |
1da177e4 LT |
269 | extern struct acpi_processor_errata errata; |
270 | ||
35ae7133 | 271 | #if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE) |
02df8b93 | 272 | void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags, |
4be44fcd | 273 | unsigned int cpu); |
991528d7 | 274 | int acpi_processor_ffh_cstate_probe(unsigned int cpu, |
fd350943 LB |
275 | struct acpi_processor_cx *cx, |
276 | struct acpi_power_register *reg); | |
991528d7 | 277 | void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate); |
02df8b93 | 278 | #else |
4be44fcd LB |
279 | static inline void acpi_processor_power_init_bm_check(struct |
280 | acpi_processor_flags | |
281 | *flags, unsigned int cpu) | |
02df8b93 VP |
282 | { |
283 | flags->bm_check = 1; | |
284 | return; | |
285 | } | |
991528d7 | 286 | static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu, |
fd350943 LB |
287 | struct acpi_processor_cx *cx, |
288 | struct acpi_power_register | |
289 | *reg) | |
991528d7 VP |
290 | { |
291 | return -1; | |
292 | } | |
fd350943 LB |
293 | static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx |
294 | *cstate) | |
991528d7 VP |
295 | { |
296 | return; | |
297 | } | |
02df8b93 VP |
298 | #endif |
299 | ||
1da177e4 | 300 | /* in processor_perflib.c */ |
02df8b93 | 301 | |
1da177e4 | 302 | #ifdef CONFIG_CPU_FREQ |
d15ce412 VK |
303 | extern bool acpi_processor_cpufreq_init; |
304 | void acpi_processor_ignore_ppc_init(void); | |
305 | void acpi_processor_ppc_init(int cpu); | |
306 | void acpi_processor_ppc_exit(int cpu); | |
bca5f557 | 307 | void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag); |
e2f74f35 | 308 | extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit); |
1da177e4 | 309 | #else |
d15ce412 | 310 | static inline void acpi_processor_ignore_ppc_init(void) |
4be44fcd LB |
311 | { |
312 | return; | |
313 | } | |
d15ce412 VK |
314 | static inline void acpi_processor_ppc_init(int cpu) |
315 | { | |
316 | return; | |
317 | } | |
318 | static inline void acpi_processor_ppc_exit(int cpu) | |
4be44fcd LB |
319 | { |
320 | return; | |
321 | } | |
a507a306 | 322 | static inline void acpi_processor_ppc_has_changed(struct acpi_processor *pr, |
d81c45e1 | 323 | int event_flag) |
4be44fcd | 324 | { |
1da177e4 LT |
325 | static unsigned int printout = 1; |
326 | if (printout) { | |
4be44fcd LB |
327 | printk(KERN_WARNING |
328 | "Warning: Processor Platform Limit event detected, but not handled.\n"); | |
329 | printk(KERN_WARNING | |
330 | "Consider compiling CPUfreq support into your kernel.\n"); | |
1da177e4 LT |
331 | printout = 0; |
332 | } | |
1da177e4 | 333 | } |
e2f74f35 TR |
334 | static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit) |
335 | { | |
336 | return -ENODEV; | |
337 | } | |
338 | ||
4be44fcd | 339 | #endif /* CONFIG_CPU_FREQ */ |
1da177e4 | 340 | |
4d5d4cd8 | 341 | /* in processor_core.c */ |
828aef37 | 342 | phys_cpuid_t acpi_get_phys_id(acpi_handle, int type, u32 acpi_id); |
fb7c2bae | 343 | phys_cpuid_t acpi_map_madt_entry(u32 acpi_id); |
828aef37 | 344 | int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id); |
2e9d5e4e | 345 | int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id); |
78f16996 | 346 | |
4f2f7573 AC |
347 | #ifdef CONFIG_ACPI_CPPC_LIB |
348 | extern int acpi_cppc_processor_probe(struct acpi_processor *pr); | |
349 | extern void acpi_cppc_processor_exit(struct acpi_processor *pr); | |
350 | #else | |
351 | static inline int acpi_cppc_processor_probe(struct acpi_processor *pr) | |
352 | { | |
353 | return 0; | |
354 | } | |
355 | static inline void acpi_cppc_processor_exit(struct acpi_processor *pr) | |
356 | { | |
357 | return; | |
358 | } | |
359 | #endif /* CONFIG_ACPI_CPPC_LIB */ | |
360 | ||
24119a88 HG |
361 | /* in processor_pdc.c */ |
362 | void acpi_processor_set_pdc(acpi_handle handle); | |
363 | ||
1da177e4 | 364 | /* in processor_throttling.c */ |
239708a3 | 365 | #ifdef CONFIG_ACPI_CPU_FREQ_PSS |
a66b34b2 | 366 | int acpi_processor_tstate_has_changed(struct acpi_processor *pr); |
4be44fcd | 367 | int acpi_processor_get_throttling_info(struct acpi_processor *pr); |
2a908002 FP |
368 | extern int acpi_processor_set_throttling(struct acpi_processor *pr, |
369 | int state, bool force); | |
5a344a50 ZY |
370 | /* |
371 | * Reevaluate whether the T-state is invalid after one cpu is | |
372 | * onlined/offlined. In such case the flags.throttling will be updated. | |
373 | */ | |
374 | extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, | |
64f3bf2f | 375 | bool is_dead); |
070d8eb1 | 376 | extern const struct file_operations acpi_processor_throttling_fops; |
1180509f | 377 | extern void acpi_processor_throttling_init(void); |
239708a3 AC |
378 | #else |
379 | static inline int acpi_processor_tstate_has_changed(struct acpi_processor *pr) | |
380 | { | |
381 | return 0; | |
382 | } | |
383 | ||
384 | static inline int acpi_processor_get_throttling_info(struct acpi_processor *pr) | |
385 | { | |
386 | return -ENODEV; | |
387 | } | |
388 | ||
389 | static inline int acpi_processor_set_throttling(struct acpi_processor *pr, | |
390 | int state, bool force) | |
391 | { | |
392 | return -ENODEV; | |
393 | } | |
394 | ||
395 | static inline void acpi_processor_reevaluate_tstate(struct acpi_processor *pr, | |
64f3bf2f | 396 | bool is_dead) {} |
239708a3 AC |
397 | |
398 | static inline void acpi_processor_throttling_init(void) {} | |
399 | #endif /* CONFIG_ACPI_CPU_FREQ_PSS */ | |
400 | ||
1da177e4 | 401 | /* in processor_idle.c */ |
5f05586c AC |
402 | extern struct cpuidle_driver acpi_idle_driver; |
403 | #ifdef CONFIG_ACPI_PROCESSOR_IDLE | |
38a991b6 DL |
404 | int acpi_processor_power_init(struct acpi_processor *pr); |
405 | int acpi_processor_power_exit(struct acpi_processor *pr); | |
a36a7fec | 406 | int acpi_processor_power_state_has_changed(struct acpi_processor *pr); |
46bcfad7 | 407 | int acpi_processor_hotplug(struct acpi_processor *pr); |
5f05586c AC |
408 | #else |
409 | static inline int acpi_processor_power_init(struct acpi_processor *pr) | |
410 | { | |
411 | return -ENODEV; | |
412 | } | |
413 | ||
414 | static inline int acpi_processor_power_exit(struct acpi_processor *pr) | |
415 | { | |
416 | return -ENODEV; | |
417 | } | |
418 | ||
a36a7fec | 419 | static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr) |
5f05586c AC |
420 | { |
421 | return -ENODEV; | |
422 | } | |
423 | ||
424 | static inline int acpi_processor_hotplug(struct acpi_processor *pr) | |
425 | { | |
426 | return -ENODEV; | |
427 | } | |
428 | #endif /* CONFIG_ACPI_PROCESSOR_IDLE */ | |
1da177e4 LT |
429 | |
430 | /* in processor_thermal.c */ | |
4be44fcd | 431 | int acpi_processor_get_limit_info(struct acpi_processor *pr); |
9c8b04be | 432 | extern const struct thermal_cooling_device_ops processor_cooling_ops; |
239708a3 | 433 | #if defined(CONFIG_ACPI_CPU_FREQ_PSS) & defined(CONFIG_CPU_FREQ) |
d15ce412 VK |
434 | void acpi_thermal_cpufreq_init(int cpu); |
435 | void acpi_thermal_cpufreq_exit(int cpu); | |
1da177e4 | 436 | #else |
d15ce412 | 437 | static inline void acpi_thermal_cpufreq_init(int cpu) |
4be44fcd LB |
438 | { |
439 | return; | |
440 | } | |
d15ce412 | 441 | static inline void acpi_thermal_cpufreq_exit(int cpu) |
4be44fcd LB |
442 | { |
443 | return; | |
444 | } | |
239708a3 | 445 | #endif /* CONFIG_ACPI_CPU_FREQ_PSS */ |
1da177e4 | 446 | |
1da177e4 | 447 | #endif |