1 #ifndef __ACPI_PROCESSOR_H
2 #define __ACPI_PROCESSOR_H
4 #include <linux/kernel.h>
6 #include <linux/cpuidle.h>
7 #include <linux/thermal.h>
10 #define ACPI_PROCESSOR_BUSY_METRIC 10
12 #define ACPI_PROCESSOR_MAX_POWER 8
13 #define ACPI_PROCESSOR_MAX_C2_LATENCY 100
14 #define ACPI_PROCESSOR_MAX_C3_LATENCY 1000
16 #define ACPI_PROCESSOR_MAX_THROTTLING 16
17 #define ACPI_PROCESSOR_MAX_THROTTLE 250 /* 25% */
18 #define ACPI_PROCESSOR_MAX_DUTY_WIDTH 4
20 #define ACPI_PDC_REVISION_ID 0x1
22 #define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
23 #define ACPI_PSD_REV0_ENTRIES 5
25 #define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
26 #define ACPI_TSD_REV0_ENTRIES 5
28 * Types of coordination defined in ACPI 3.0. Same macros can be used across
31 #define DOMAIN_COORD_TYPE_SW_ALL 0xfc
32 #define DOMAIN_COORD_TYPE_SW_ANY 0xfd
33 #define DOMAIN_COORD_TYPE_HW_ALL 0xfe
35 #define ACPI_CSTATE_SYSTEMIO 0
36 #define ACPI_CSTATE_FFH 1
37 #define ACPI_CSTATE_HALT 2
39 #define ACPI_CX_DESC_LEN 32
41 /* Power Management */
43 struct acpi_processor_cx;
45 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
46 struct acpi_csd_package {
47 acpi_integer num_entries;
48 acpi_integer revision;
50 acpi_integer coord_type;
51 acpi_integer num_processors;
53 } __attribute__ ((packed));
56 struct acpi_power_register {
64 } __attribute__ ((packed));
66 struct acpi_processor_cx {
77 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
80 /* Require raw information for external control logic */
81 struct acpi_power_register reg;
83 struct acpi_csd_package *domain_info;
85 char desc[ACPI_CX_DESC_LEN];
88 struct acpi_processor_power {
89 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
90 union { /* 'dev' is actually only used for taking its address. */
92 struct cpuidle_device dev;
93 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
94 struct acpi_processor_cx *state;
95 unsigned long bm_check_timestamp;
101 struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
102 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
103 int timer_broadcast_on_state;
109 /* Performance Management */
111 struct acpi_psd_package {
117 } __attribute__ ((packed));
119 struct acpi_pct_register {
127 } __attribute__ ((packed));
129 struct acpi_processor_px {
130 u64 core_frequency; /* megahertz */
131 u64 power; /* milliWatts */
132 u64 transition_latency; /* microseconds */
133 u64 bus_master_latency; /* microseconds */
134 u64 control; /* control value */
135 u64 status; /* success indicator */
138 struct acpi_processor_performance {
140 unsigned int platform_limit;
141 struct acpi_pct_register control_register;
142 struct acpi_pct_register status_register;
143 unsigned int state_count;
144 struct acpi_processor_px *states;
145 struct acpi_psd_package domain_info;
146 cpumask_var_t shared_cpu_map;
147 unsigned int shared_type;
150 /* Throttling Control */
152 struct acpi_tsd_package {
158 } __attribute__ ((packed));
160 struct acpi_ptc_register {
168 } __attribute__ ((packed));
170 struct acpi_processor_tx_tss {
171 u64 freqpercentage; /* */
172 u64 power; /* milliWatts */
173 u64 transition_latency; /* microseconds */
174 u64 control; /* control value */
175 u64 status; /* success indicator */
177 struct acpi_processor_tx {
182 struct acpi_processor;
183 struct acpi_processor_throttling {
185 unsigned int platform_limit;
186 struct acpi_pct_register control_register;
187 struct acpi_pct_register status_register;
188 unsigned int state_count;
189 struct acpi_processor_tx_tss *states_tss;
190 struct acpi_tsd_package domain_info;
191 cpumask_var_t shared_cpu_map;
192 int (*acpi_processor_get_throttling) (struct acpi_processor * pr);
193 int (*acpi_processor_set_throttling) (struct acpi_processor * pr,
194 int state, bool force);
200 unsigned int shared_type;
201 struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
204 /* Limit Interface */
206 struct acpi_processor_lx {
207 int px; /* performance state */
208 int tx; /* throttle level */
211 struct acpi_processor_limit {
212 struct acpi_processor_lx state; /* current limit */
213 struct acpi_processor_lx thermal; /* thermal limit */
214 struct acpi_processor_lx user; /* user limit */
217 struct acpi_processor_flags {
225 u8 power_setup_done:1;
227 u8 need_hotplug_init:1;
230 struct acpi_processor {
235 int performance_platform_limit;
236 int throttling_platform_limit;
237 /* 0 - states 0..n-th state available */
239 struct acpi_processor_flags flags;
240 struct acpi_processor_power power;
241 struct acpi_processor_performance *performance;
242 struct acpi_processor_throttling throttling;
243 struct acpi_processor_limit limit;
244 struct thermal_cooling_device *cdev;
247 struct acpi_processor_errata {
257 extern void acpi_processor_load_module(struct acpi_processor *pr);
258 extern int acpi_processor_preregister_performance(struct
259 acpi_processor_performance
260 __percpu *performance);
262 extern int acpi_processor_register_performance(struct acpi_processor_performance
263 *performance, unsigned int cpu);
264 extern void acpi_processor_unregister_performance(struct
265 acpi_processor_performance
269 /* note: this locks both the calling module and the processor module
270 if a _PPC object exists, rmmod is disallowed then */
271 int acpi_processor_notify_smm(struct module *calling_module);
273 /* for communication between multiple parts of the processor kernel module */
274 DECLARE_PER_CPU(struct acpi_processor *, processors);
275 extern struct acpi_processor_errata errata;
277 #ifdef ARCH_HAS_POWER_INIT
278 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
280 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
281 struct acpi_processor_cx *cx,
282 struct acpi_power_register *reg);
283 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cstate);
285 static inline void acpi_processor_power_init_bm_check(struct
287 *flags, unsigned int cpu)
292 static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
293 struct acpi_processor_cx *cx,
294 struct acpi_power_register
299 static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
306 /* in processor_perflib.c */
308 #ifdef CONFIG_CPU_FREQ
309 void acpi_processor_ppc_init(void);
310 void acpi_processor_ppc_exit(void);
311 int acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag);
312 extern int acpi_processor_get_bios_limit(int cpu, unsigned int *limit);
314 static inline void acpi_processor_ppc_init(void)
318 static inline void acpi_processor_ppc_exit(void)
322 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
323 int acpi_processor_ppc_has_changed(struct acpi_processor *, int event_flag);
325 static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr,
328 static unsigned int printout = 1;
331 "Warning: Processor Platform Limit event detected, but not handled.\n");
333 "Consider compiling CPUfreq support into your kernel.\n");
338 static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
342 #endif /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */
344 #endif /* CONFIG_CPU_FREQ */
346 /* in processor_core.c */
347 void acpi_processor_set_pdc(acpi_handle handle);
348 int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id);
350 /* in processor_throttling.c */
351 int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
352 int acpi_processor_get_throttling_info(struct acpi_processor *pr);
353 extern int acpi_processor_set_throttling(struct acpi_processor *pr,
354 int state, bool force);
356 * Reevaluate whether the T-state is invalid after one cpu is
357 * onlined/offlined. In such case the flags.throttling will be updated.
359 extern void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
360 unsigned long action);
361 extern const struct file_operations acpi_processor_throttling_fops;
362 extern void acpi_processor_throttling_init(void);
363 /* in processor_idle.c */
364 int acpi_processor_power_init(struct acpi_processor *pr,
365 struct acpi_device *device);
366 int acpi_processor_cst_has_changed(struct acpi_processor *pr);
367 int acpi_processor_hotplug(struct acpi_processor *pr);
368 int acpi_processor_power_exit(struct acpi_processor *pr,
369 struct acpi_device *device);
370 int acpi_processor_suspend(struct acpi_device * device, pm_message_t state);
371 int acpi_processor_resume(struct acpi_device * device);
372 extern struct cpuidle_driver acpi_idle_driver;
374 /* in processor_thermal.c */
375 int acpi_processor_get_limit_info(struct acpi_processor *pr);
376 extern const struct thermal_cooling_device_ops processor_cooling_ops;
377 #ifdef CONFIG_CPU_FREQ
378 void acpi_thermal_cpufreq_init(void);
379 void acpi_thermal_cpufreq_exit(void);
381 static inline void acpi_thermal_cpufreq_init(void)
385 static inline void acpi_thermal_cpufreq_exit(void)
392 * Following are interfaces geared to external processor PM control
395 /* Events notified to external control logic */
396 #define PROCESSOR_PM_INIT 1
397 #define PROCESSOR_PM_CHANGE 2
398 #define PROCESSOR_HOTPLUG 3
400 /* Objects for the PM events */
401 #define PM_TYPE_IDLE 0
402 #define PM_TYPE_PERF 1
403 #define PM_TYPE_THR 2
404 #define PM_TYPE_MAX 3
406 /* Processor hotplug events */
407 #define HOTPLUG_TYPE_ADD 0
408 #define HOTPLUG_TYPE_REMOVE 1
410 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
411 struct processor_extcntl_ops {
412 /* Transfer processor PM events to external control logic */
413 int (*pm_ops[PM_TYPE_MAX])(struct acpi_processor *pr, int event);
414 /* Notify physical processor status to external control logic */
415 int (*hotplug)(struct acpi_processor *pr, int type);
417 extern const struct processor_extcntl_ops *processor_extcntl_ops;
419 static inline int processor_cntl_external(void)
421 return (processor_extcntl_ops != NULL);
424 static inline int processor_pm_external(void)
426 return processor_cntl_external() &&
427 (processor_extcntl_ops->pm_ops[PM_TYPE_IDLE] != NULL);
430 static inline int processor_pmperf_external(void)
432 return processor_cntl_external() &&
433 (processor_extcntl_ops->pm_ops[PM_TYPE_PERF] != NULL);
436 static inline int processor_pmthr_external(void)
438 return processor_cntl_external() &&
439 (processor_extcntl_ops->pm_ops[PM_TYPE_THR] != NULL);
442 extern int processor_notify_external(struct acpi_processor *pr,
443 int event, int type);
444 extern int processor_extcntl_prepare(struct acpi_processor *pr);
445 extern int acpi_processor_get_performance_info(struct acpi_processor *pr);
446 extern int acpi_processor_get_psd(struct acpi_processor *pr);
448 static inline int processor_cntl_external(void) {return 0;}
449 static inline int processor_pm_external(void) {return 0;}
450 static inline int processor_pmperf_external(void) {return 0;}
451 static inline int processor_pmthr_external(void) {return 0;}
452 static inline int processor_notify_external(struct acpi_processor *pr,
457 static inline int processor_extcntl_prepare(struct acpi_processor *pr)
461 #endif /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */
464 static inline void xen_convert_pct_reg(struct xen_pct_register *xpct,
465 struct acpi_pct_register *apct)
467 xpct->descriptor = apct->descriptor;
468 xpct->length = apct->length;
469 xpct->space_id = apct->space_id;
470 xpct->bit_width = apct->bit_width;
471 xpct->bit_offset = apct->bit_offset;
472 xpct->reserved = apct->reserved;
473 xpct->address = apct->address;
476 static inline void xen_convert_pss_states(struct xen_processor_px *xpss,
477 struct acpi_processor_px *apss, int state_count)
480 for(i=0; i<state_count; i++) {
481 xpss->core_frequency = apss->core_frequency;
482 xpss->power = apss->power;
483 xpss->transition_latency = apss->transition_latency;
484 xpss->bus_master_latency = apss->bus_master_latency;
485 xpss->control = apss->control;
486 xpss->status = apss->status;
492 static inline void xen_convert_psd_pack(struct xen_psd_package *xpsd,
493 struct acpi_psd_package *apsd)
495 xpsd->num_entries = apsd->num_entries;
496 xpsd->revision = apsd->revision;
497 xpsd->domain = apsd->domain;
498 xpsd->coord_type = apsd->coord_type;
499 xpsd->num_processors = apsd->num_processors;
502 extern int xen_pcpu_hotplug(int type);
503 extern int xen_pcpu_index(uint32_t id, bool is_acpiid);
504 #endif /* CONFIG_XEN */