Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / include / acpi / processor.h
1 #ifndef __ACPI_PROCESSOR_H
2 #define __ACPI_PROCESSOR_H
3
4 #include <linux/kernel.h>
5 #include <linux/cpu.h>
6 #include <linux/cpuidle.h>
7 #include <linux/thermal.h>
8 #include <asm/acpi.h>
9
10 #define ACPI_PROCESSOR_BUSY_METRIC      10
11
12 #define ACPI_PROCESSOR_MAX_POWER        8
13 #define ACPI_PROCESSOR_MAX_C2_LATENCY   100
14 #define ACPI_PROCESSOR_MAX_C3_LATENCY   1000
15
16 #define ACPI_PROCESSOR_MAX_THROTTLING   16
17 #define ACPI_PROCESSOR_MAX_THROTTLE     250     /* 25% */
18 #define ACPI_PROCESSOR_MAX_DUTY_WIDTH   4
19
20 #define ACPI_PDC_REVISION_ID            0x1
21
22 #define ACPI_PSD_REV0_REVISION          0       /* Support for _PSD as in ACPI 3.0 */
23 #define ACPI_PSD_REV0_ENTRIES           5
24
25 #define ACPI_TSD_REV0_REVISION          0       /* Support for _PSD as in ACPI 3.0 */
26 #define ACPI_TSD_REV0_ENTRIES           5
27 /*
28  * Types of coordination defined in ACPI 3.0. Same macros can be used across
29  * P, C and T states
30  */
31 #define DOMAIN_COORD_TYPE_SW_ALL        0xfc
32 #define DOMAIN_COORD_TYPE_SW_ANY        0xfd
33 #define DOMAIN_COORD_TYPE_HW_ALL        0xfe
34
35 #define ACPI_CSTATE_SYSTEMIO    0
36 #define ACPI_CSTATE_FFH         1
37 #define ACPI_CSTATE_HALT        2
38
39 #define ACPI_CX_DESC_LEN        32
40
41 /* Power Management */
42
43 struct acpi_processor_cx;
44
45 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
46 struct acpi_csd_package {
47         acpi_integer num_entries;
48         acpi_integer revision;
49         acpi_integer domain;
50         acpi_integer coord_type;
51         acpi_integer num_processors;
52         acpi_integer index;
53 } __attribute__ ((packed));
54 #endif
55
56 struct acpi_power_register {
57         u8 descriptor;
58         u16 length;
59         u8 space_id;
60         u8 bit_width;
61         u8 bit_offset;
62         u8 access_size;
63         u64 address;
64 } __attribute__ ((packed));
65
66 struct acpi_processor_cx {
67         u8 valid;
68         u8 type;
69         u32 address;
70         u8 entry_method;
71         u8 index;
72         u32 latency;
73         u32 latency_ticks;
74         u32 power;
75         u32 usage;
76         u64 time;
77 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
78         u8 bm_sts_skip;
79 #else
80         /* Require raw information for external control logic */
81         struct acpi_power_register reg;
82         u32 csd_count;
83         struct acpi_csd_package *domain_info;
84 #endif
85         char desc[ACPI_CX_DESC_LEN];
86 };
87
88 struct acpi_processor_power {
89 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
90         union { /* 'dev' is actually only used for taking its address. */
91 #endif
92         struct cpuidle_device dev;
93 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
94         struct acpi_processor_cx *state;
95         unsigned long bm_check_timestamp;
96         u32 default_state;
97 #else
98         struct {
99 #endif
100         int count;
101         struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
102 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
103         int timer_broadcast_on_state;
104 #else
105         }; };
106 #endif
107 };
108
109 /* Performance Management */
110
111 struct acpi_psd_package {
112         u64 num_entries;
113         u64 revision;
114         u64 domain;
115         u64 coord_type;
116         u64 num_processors;
117 } __attribute__ ((packed));
118
119 struct acpi_pct_register {
120         u8 descriptor;
121         u16 length;
122         u8 space_id;
123         u8 bit_width;
124         u8 bit_offset;
125         u8 reserved;
126         u64 address;
127 } __attribute__ ((packed));
128
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 */
136 };
137
138 struct acpi_processor_performance {
139         unsigned int state;
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;
148 };
149
150 /* Throttling Control */
151
152 struct acpi_tsd_package {
153         u64 num_entries;
154         u64 revision;
155         u64 domain;
156         u64 coord_type;
157         u64 num_processors;
158 } __attribute__ ((packed));
159
160 struct acpi_ptc_register {
161         u8 descriptor;
162         u16 length;
163         u8 space_id;
164         u8 bit_width;
165         u8 bit_offset;
166         u8 reserved;
167         u64 address;
168 } __attribute__ ((packed));
169
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 */
176 };
177 struct acpi_processor_tx {
178         u16 power;
179         u16 performance;
180 };
181
182 struct acpi_processor;
183 struct acpi_processor_throttling {
184         unsigned int state;
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);
195
196         u32 address;
197         u8 duty_offset;
198         u8 duty_width;
199         u8 tsd_valid_flag;
200         unsigned int shared_type;
201         struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
202 };
203
204 /* Limit Interface */
205
206 struct acpi_processor_lx {
207         int px;                 /* performance state */
208         int tx;                 /* throttle level */
209 };
210
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 */
215 };
216
217 struct acpi_processor_flags {
218         u8 power:1;
219         u8 performance:1;
220         u8 throttling:1;
221         u8 limit:1;
222         u8 bm_control:1;
223         u8 bm_check:1;
224         u8 has_cst:1;
225         u8 power_setup_done:1;
226         u8 bm_rld_set:1;
227         u8 need_hotplug_init:1;
228 };
229
230 struct acpi_processor {
231         acpi_handle handle;
232         u32 acpi_id;
233         u32 id;
234         u32 pblk;
235         int performance_platform_limit;
236         int throttling_platform_limit;
237         /* 0 - states 0..n-th state available */
238
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;
245 };
246
247 struct acpi_processor_errata {
248         u8 smp;
249         struct {
250                 u8 throttle:1;
251                 u8 fdma:1;
252                 u8 reserved:6;
253                 u32 bmisx;
254         } piix4;
255 };
256
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);
261
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
266                                                   *performance,
267                                                   unsigned int cpu);
268
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);
272
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;
276
277 #ifdef ARCH_HAS_POWER_INIT
278 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
279                                         unsigned int cpu);
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);
284 #else
285 static inline void acpi_processor_power_init_bm_check(struct
286                                                       acpi_processor_flags
287                                                       *flags, unsigned int cpu)
288 {
289         flags->bm_check = 1;
290         return;
291 }
292 static inline int acpi_processor_ffh_cstate_probe(unsigned int cpu,
293                                                   struct acpi_processor_cx *cx,
294                                                   struct acpi_power_register
295                                                   *reg)
296 {
297         return -1;
298 }
299 static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
300                                                    *cstate)
301 {
302         return;
303 }
304 #endif
305
306 /* in processor_perflib.c */
307
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);
313 #else
314 static inline void acpi_processor_ppc_init(void)
315 {
316         return;
317 }
318 static inline void acpi_processor_ppc_exit(void)
319 {
320         return;
321 }
322 #ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
323 int acpi_processor_ppc_has_changed(struct acpi_processor *, int event_flag);
324 #else
325 static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr,
326                                                                 int event_flag)
327 {
328         static unsigned int printout = 1;
329         if (printout) {
330                 printk(KERN_WARNING
331                        "Warning: Processor Platform Limit event detected, but not handled.\n");
332                 printk(KERN_WARNING
333                        "Consider compiling CPUfreq support into your kernel.\n");
334                 printout = 0;
335         }
336         return 0;
337 }
338 static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
339 {
340         return -ENODEV;
341 }
342 #endif                          /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */
343
344 #endif                          /* CONFIG_CPU_FREQ */
345
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);
349
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);
355 /*
356  * Reevaluate whether the T-state is invalid after one cpu is
357  * onlined/offlined. In such case the flags.throttling will be updated.
358  */
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;
373
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);
380 #else
381 static inline void acpi_thermal_cpufreq_init(void)
382 {
383         return;
384 }
385 static inline void acpi_thermal_cpufreq_exit(void)
386 {
387         return;
388 }
389 #endif
390
391 /*
392  * Following are interfaces geared to external processor PM control
393  * logic like a VMM
394  */
395 /* Events notified to external control logic */
396 #define PROCESSOR_PM_INIT       1
397 #define PROCESSOR_PM_CHANGE     2
398 #define PROCESSOR_HOTPLUG       3
399
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
405
406 /* Processor hotplug events */
407 #define HOTPLUG_TYPE_ADD        0
408 #define HOTPLUG_TYPE_REMOVE     1
409
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);
416 };
417 extern const struct processor_extcntl_ops *processor_extcntl_ops;
418
419 static inline int processor_cntl_external(void)
420 {
421         return (processor_extcntl_ops != NULL);
422 }
423
424 static inline int processor_pm_external(void)
425 {
426         return processor_cntl_external() &&
427                 (processor_extcntl_ops->pm_ops[PM_TYPE_IDLE] != NULL);
428 }
429
430 static inline int processor_pmperf_external(void)
431 {
432         return processor_cntl_external() &&
433                 (processor_extcntl_ops->pm_ops[PM_TYPE_PERF] != NULL);
434 }
435
436 static inline int processor_pmthr_external(void)
437 {
438         return processor_cntl_external() &&
439                 (processor_extcntl_ops->pm_ops[PM_TYPE_THR] != NULL);
440 }
441
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);
447 #else
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,
453                         int event, int type)
454 {
455         return 0;
456 }
457 static inline int processor_extcntl_prepare(struct acpi_processor *pr)
458 {
459         return 0;
460 }
461 #endif /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */
462
463 #ifdef CONFIG_XEN
464 static inline void xen_convert_pct_reg(struct xen_pct_register *xpct,
465         struct acpi_pct_register *apct)
466 {
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;
474 }
475
476 static inline void xen_convert_pss_states(struct xen_processor_px *xpss,
477         struct acpi_processor_px *apss, int state_count)
478 {
479         int i;
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;
487                 xpss++;
488                 apss++;
489         }
490 }
491
492 static inline void xen_convert_psd_pack(struct xen_psd_package *xpsd,
493         struct acpi_psd_package *apsd)
494 {
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;
500 }
501
502 extern int xen_pcpu_hotplug(int type);
503 extern int xen_pcpu_index(uint32_t id, bool is_acpiid);
504 #endif /* CONFIG_XEN */
505
506 #endif