1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ACPI_PROCESSOR_H
3 #define __ACPI_PROCESSOR_H
5 #include <linux/kernel.h>
7 #include <linux/cpufreq.h>
8 #include <linux/pm_qos.h>
9 #include <linux/thermal.h>
12 #define ACPI_PROCESSOR_CLASS "processor"
13 #define ACPI_PROCESSOR_DEVICE_NAME "Processor"
14 #define ACPI_PROCESSOR_DEVICE_HID "ACPI0007"
15 #define ACPI_PROCESSOR_CONTAINER_HID "ACPI0010"
17 #define ACPI_PROCESSOR_BUSY_METRIC 10
19 #define ACPI_PROCESSOR_MAX_POWER 8
20 #define ACPI_PROCESSOR_MAX_C2_LATENCY 100
21 #define ACPI_PROCESSOR_MAX_C3_LATENCY 1000
23 #define ACPI_PROCESSOR_MAX_THROTTLING 16
24 #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */
25 #define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4
27 #define ACPI_PDC_REVISION_ID 0x1
29 #define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
30 #define ACPI_PSD_REV0_ENTRIES 5
32 #define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
33 #define ACPI_TSD_REV0_ENTRIES 5
35 * Types of coordination defined in ACPI 3.0. Same macros can be used across
38 #define DOMAIN_COORD_TYPE_SW_ALL 0xfc
39 #define DOMAIN_COORD_TYPE_SW_ANY 0xfd
40 #define DOMAIN_COORD_TYPE_HW_ALL 0xfe
42 #define ACPI_CSTATE_SYSTEMIO 0
43 #define ACPI_CSTATE_FFH 1
44 #define ACPI_CSTATE_HALT 2
45 #define ACPI_CSTATE_INTEGER 3
47 #define ACPI_CX_DESC_LEN 32
49 /* Power Management */
51 struct acpi_processor_cx
;
53 struct acpi_power_register
{
63 struct acpi_processor_cx
{
71 char desc
[ACPI_CX_DESC_LEN
];
74 struct acpi_lpi_state
{
76 u32 wake_latency
; /* worst case */
80 u32 enable_parent_state
;
84 char desc
[ACPI_CX_DESC_LEN
];
87 struct acpi_processor_power
{
90 struct acpi_processor_cx states
[ACPI_PROCESSOR_MAX_POWER
];
91 struct acpi_lpi_state lpi_states
[ACPI_PROCESSOR_MAX_POWER
];
93 int timer_broadcast_on_state
;
96 /* Performance Management */
98 struct acpi_psd_package
{
106 struct acpi_pct_register
{
116 struct acpi_processor_px
{
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 */
125 struct acpi_processor_performance
{
127 unsigned int platform_limit
;
128 struct acpi_pct_register control_register
;
129 struct acpi_pct_register status_register
;
130 unsigned int state_count
;
131 struct acpi_processor_px
*states
;
132 struct acpi_psd_package domain_info
;
133 cpumask_var_t shared_cpu_map
;
134 unsigned int shared_type
;
137 /* Throttling Control */
139 struct acpi_tsd_package
{
147 struct acpi_ptc_register
{
157 struct acpi_processor_tx_tss
{
158 u64 freqpercentage
; /* */
159 u64 power
; /* milliWatts */
160 u64 transition_latency
; /* microseconds */
161 u64 control
; /* control value */
162 u64 status
; /* success indicator */
164 struct acpi_processor_tx
{
169 struct acpi_processor
;
170 struct acpi_processor_throttling
{
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
;
178 cpumask_var_t shared_cpu_map
;
179 int (*acpi_processor_get_throttling
) (struct acpi_processor
* pr
);
180 int (*acpi_processor_set_throttling
) (struct acpi_processor
* pr
,
181 int state
, bool force
);
187 unsigned int shared_type
;
188 struct acpi_processor_tx states
[ACPI_PROCESSOR_MAX_THROTTLING
];
191 /* Limit Interface */
193 struct acpi_processor_lx
{
194 int px
; /* performance state */
195 int tx
; /* throttle level */
198 struct acpi_processor_limit
{
199 struct acpi_processor_lx state
; /* current limit */
200 struct acpi_processor_lx thermal
; /* thermal limit */
201 struct acpi_processor_lx user
; /* user limit */
204 struct acpi_processor_flags
{
213 u8 power_setup_done
:1;
215 u8 need_hotplug_init
:1;
218 struct acpi_processor
{
221 phys_cpuid_t phys_id
; /* CPU hardware ID such as APIC ID for x86 */
222 u32 id
; /* CPU logical ID allocated by OS */
224 int performance_platform_limit
;
225 int throttling_platform_limit
;
226 /* 0 - states 0..n-th state available */
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
;
233 struct thermal_cooling_device
*cdev
;
234 struct device
*dev
; /* Processor device. */
235 struct freq_qos_request perflib_req
;
236 struct freq_qos_request thermal_req
;
239 struct acpi_processor_errata
{
249 extern int acpi_processor_preregister_performance(struct
250 acpi_processor_performance
251 __percpu
*performance
);
253 extern int acpi_processor_register_performance(struct acpi_processor_performance
254 *performance
, unsigned int cpu
);
255 extern void acpi_processor_unregister_performance(unsigned int cpu
);
257 int acpi_processor_pstate_control(void);
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
);
261 int acpi_processor_get_psd(acpi_handle handle
,
262 struct acpi_psd_package
*pdomain
);
264 /* parsing the _P* objects. */
265 extern int acpi_processor_get_performance_info(struct acpi_processor
*pr
);
267 /* for communication between multiple parts of the processor kernel module */
268 DECLARE_PER_CPU(struct acpi_processor
*, processors
);
269 extern struct acpi_processor_errata errata
;
271 #if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
272 void acpi_processor_power_init_bm_check(struct acpi_processor_flags
*flags
,
274 int acpi_processor_ffh_cstate_probe(unsigned int cpu
,
275 struct acpi_processor_cx
*cx
,
276 struct acpi_power_register
*reg
);
277 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
*cstate
);
279 static inline void acpi_processor_power_init_bm_check(struct
281 *flags
, unsigned int cpu
)
286 static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu
,
287 struct acpi_processor_cx
*cx
,
288 struct acpi_power_register
293 static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
300 static inline int call_on_cpu(int cpu
, long (*fn
)(void *), void *arg
,
303 if (direct
|| (is_percpu_thread() && cpu
== smp_processor_id()))
305 return work_on_cpu(cpu
, fn
, arg
);
308 /* in processor_perflib.c */
310 #ifdef CONFIG_CPU_FREQ
311 extern bool acpi_processor_cpufreq_init
;
312 void acpi_processor_ignore_ppc_init(void);
313 void acpi_processor_ppc_init(struct cpufreq_policy
*policy
);
314 void acpi_processor_ppc_exit(struct cpufreq_policy
*policy
);
315 void acpi_processor_ppc_has_changed(struct acpi_processor
*pr
, int event_flag
);
316 extern int acpi_processor_get_bios_limit(int cpu
, unsigned int *limit
);
318 static inline void acpi_processor_ignore_ppc_init(void)
322 static inline void acpi_processor_ppc_init(struct cpufreq_policy
*policy
)
326 static inline void acpi_processor_ppc_exit(struct cpufreq_policy
*policy
)
330 static inline void acpi_processor_ppc_has_changed(struct acpi_processor
*pr
,
333 static unsigned int printout
= 1;
336 "Warning: Processor Platform Limit event detected, but not handled.\n");
338 "Consider compiling CPUfreq support into your kernel.\n");
342 static inline int acpi_processor_get_bios_limit(int cpu
, unsigned int *limit
)
347 #endif /* CONFIG_CPU_FREQ */
349 /* in processor_core.c */
350 phys_cpuid_t
acpi_get_phys_id(acpi_handle
, int type
, u32 acpi_id
);
351 phys_cpuid_t
acpi_map_madt_entry(u32 acpi_id
);
352 int acpi_map_cpuid(phys_cpuid_t phys_id
, u32 acpi_id
);
353 int acpi_get_cpuid(acpi_handle
, int type
, u32 acpi_id
);
355 #ifdef CONFIG_ACPI_CPPC_LIB
356 extern int acpi_cppc_processor_probe(struct acpi_processor
*pr
);
357 extern void acpi_cppc_processor_exit(struct acpi_processor
*pr
);
359 static inline int acpi_cppc_processor_probe(struct acpi_processor
*pr
)
363 static inline void acpi_cppc_processor_exit(struct acpi_processor
*pr
)
367 #endif /* CONFIG_ACPI_CPPC_LIB */
369 /* in processor_pdc.c */
370 void acpi_processor_set_pdc(acpi_handle handle
);
372 /* in processor_throttling.c */
373 #ifdef CONFIG_ACPI_CPU_FREQ_PSS
374 int acpi_processor_tstate_has_changed(struct acpi_processor
*pr
);
375 int acpi_processor_get_throttling_info(struct acpi_processor
*pr
);
376 extern int acpi_processor_set_throttling(struct acpi_processor
*pr
,
377 int state
, bool force
);
379 * Reevaluate whether the T-state is invalid after one cpu is
380 * onlined/offlined. In such case the flags.throttling will be updated.
382 extern void acpi_processor_reevaluate_tstate(struct acpi_processor
*pr
,
384 extern const struct file_operations acpi_processor_throttling_fops
;
385 extern void acpi_processor_throttling_init(void);
387 static inline int acpi_processor_tstate_has_changed(struct acpi_processor
*pr
)
392 static inline int acpi_processor_get_throttling_info(struct acpi_processor
*pr
)
397 static inline int acpi_processor_set_throttling(struct acpi_processor
*pr
,
398 int state
, bool force
)
403 static inline void acpi_processor_reevaluate_tstate(struct acpi_processor
*pr
,
406 static inline void acpi_processor_throttling_init(void) {}
407 #endif /* CONFIG_ACPI_CPU_FREQ_PSS */
409 /* in processor_idle.c */
410 extern struct cpuidle_driver acpi_idle_driver
;
411 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
412 int acpi_processor_power_init(struct acpi_processor
*pr
);
413 int acpi_processor_power_exit(struct acpi_processor
*pr
);
414 int acpi_processor_power_state_has_changed(struct acpi_processor
*pr
);
415 int acpi_processor_hotplug(struct acpi_processor
*pr
);
417 static inline int acpi_processor_power_init(struct acpi_processor
*pr
)
422 static inline int acpi_processor_power_exit(struct acpi_processor
*pr
)
427 static inline int acpi_processor_power_state_has_changed(struct acpi_processor
*pr
)
432 static inline int acpi_processor_hotplug(struct acpi_processor
*pr
)
436 #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
438 /* in processor_thermal.c */
439 int acpi_processor_get_limit_info(struct acpi_processor
*pr
);
440 extern const struct thermal_cooling_device_ops processor_cooling_ops
;
441 #if defined(CONFIG_ACPI_CPU_FREQ_PSS) & defined(CONFIG_CPU_FREQ)
442 void acpi_thermal_cpufreq_init(struct cpufreq_policy
*policy
);
443 void acpi_thermal_cpufreq_exit(struct cpufreq_policy
*policy
);
445 static inline void acpi_thermal_cpufreq_init(struct cpufreq_policy
*policy
)
449 static inline void acpi_thermal_cpufreq_exit(struct cpufreq_policy
*policy
)
453 #endif /* CONFIG_ACPI_CPU_FREQ_PSS */