Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[deliverable/linux.git] / include / linux / cpuidle.h
CommitLineData
4f86d3a8
LB
1/*
2 * cpuidle.h - a generic framework for CPU idle power management
3 *
4 * (C) 2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
7 *
8 * This code is licenced under the GPL.
9 */
10
11#ifndef _LINUX_CPUIDLE_H
12#define _LINUX_CPUIDLE_H
13
14#include <linux/percpu.h>
15#include <linux/list.h>
16#include <linux/module.h>
17#include <linux/kobject.h>
18#include <linux/completion.h>
19
20#define CPUIDLE_STATE_MAX 8
21#define CPUIDLE_NAME_LEN 16
22
23struct cpuidle_device;
24
25
26/****************************
27 * CPUIDLE DEVICE INTERFACE *
28 ****************************/
29
30struct cpuidle_state {
31 char name[CPUIDLE_NAME_LEN];
32 void *driver_data;
33
34 unsigned int flags;
35 unsigned int exit_latency; /* in US */
36 unsigned int power_usage; /* in mW */
37 unsigned int target_residency; /* in US */
38
39 unsigned int usage;
40 unsigned int time; /* in US */
41
42 int (*enter) (struct cpuidle_device *dev,
43 struct cpuidle_state *state);
44};
45
46/* Idle State Flags */
47#define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
48#define CPUIDLE_FLAG_CHECK_BM (0x02) /* BM activity will exit state */
9a0b8415 49#define CPUIDLE_FLAG_POLL (0x10) /* no latency, no savings */
50#define CPUIDLE_FLAG_SHALLOW (0x20) /* low latency, minimal savings */
51#define CPUIDLE_FLAG_BALANCED (0x40) /* medium latency, moderate savings */
52#define CPUIDLE_FLAG_DEEP (0x80) /* high latency, large savings */
4f86d3a8
LB
53
54#define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
55
56/**
57 * cpuidle_get_statedata - retrieves private driver state data
58 * @state: the state
59 */
60static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
61{
62 return state->driver_data;
63}
64
65/**
66 * cpuidle_set_statedata - stores private driver state data
67 * @state: the state
68 * @data: the private data
69 */
70static inline void
71cpuidle_set_statedata(struct cpuidle_state *state, void *data)
72{
73 state->driver_data = data;
74}
75
76struct cpuidle_state_kobj {
77 struct cpuidle_state *state;
78 struct completion kobj_unregister;
79 struct kobject kobj;
80};
81
82struct cpuidle_device {
b5556a67 83 unsigned int enabled:1;
4f86d3a8
LB
84 unsigned int cpu;
85
86 int last_residency;
87 int state_count;
88 struct cpuidle_state states[CPUIDLE_STATE_MAX];
89 struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
90 struct cpuidle_state *last_state;
91
92 struct list_head device_list;
93 struct kobject kobj;
94 struct completion kobj_unregister;
95 void *governor_data;
ddc081a1 96 struct cpuidle_state *safe_state;
4f86d3a8
LB
97};
98
99DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
100
101/**
102 * cpuidle_get_last_residency - retrieves the last state's residency time
103 * @dev: the target CPU
104 *
105 * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
106 */
107static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
108{
109 return dev->last_residency;
110}
111
112
113/****************************
114 * CPUIDLE DRIVER INTERFACE *
115 ****************************/
116
117struct cpuidle_driver {
118 char name[CPUIDLE_NAME_LEN];
119 struct module *owner;
120};
121
122#ifdef CONFIG_CPU_IDLE
123
124extern int cpuidle_register_driver(struct cpuidle_driver *drv);
125extern void cpuidle_unregister_driver(struct cpuidle_driver *drv);
126extern int cpuidle_register_device(struct cpuidle_device *dev);
127extern void cpuidle_unregister_device(struct cpuidle_device *dev);
128
129extern void cpuidle_pause_and_lock(void);
130extern void cpuidle_resume_and_unlock(void);
131extern int cpuidle_enable_device(struct cpuidle_device *dev);
132extern void cpuidle_disable_device(struct cpuidle_device *dev);
133
134#else
135
136static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
137{return 0;}
138static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
139static inline int cpuidle_register_device(struct cpuidle_device *dev)
140{return 0;}
141static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
142
143static inline void cpuidle_pause_and_lock(void) { }
144static inline void cpuidle_resume_and_unlock(void) { }
145static inline int cpuidle_enable_device(struct cpuidle_device *dev)
146{return 0;}
147static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
148
149#endif
150
151/******************************
152 * CPUIDLE GOVERNOR INTERFACE *
153 ******************************/
154
155struct cpuidle_governor {
156 char name[CPUIDLE_NAME_LEN];
157 struct list_head governor_list;
158 unsigned int rating;
159
160 int (*enable) (struct cpuidle_device *dev);
161 void (*disable) (struct cpuidle_device *dev);
162
163 int (*select) (struct cpuidle_device *dev);
164 void (*reflect) (struct cpuidle_device *dev);
165
166 struct module *owner;
167};
168
169#ifdef CONFIG_CPU_IDLE
170
171extern int cpuidle_register_governor(struct cpuidle_governor *gov);
172extern void cpuidle_unregister_governor(struct cpuidle_governor *gov);
173
174#else
175
176static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
177{return 0;}
178static inline void cpuidle_unregister_governor(struct cpuidle_governor *gov) { }
179
180#endif
181
9a0b8415 182#ifdef CONFIG_ARCH_HAS_CPU_RELAX
183#define CPUIDLE_DRIVER_STATE_START 1
184#else
185#define CPUIDLE_DRIVER_STATE_START 0
186#endif
187
4f86d3a8 188#endif /* _LINUX_CPUIDLE_H */
This page took 0.061507 seconds and 5 git commands to generate.