Lines Matching +full:drv +full:- +full:0
2 * driver.c - driver support
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
30 * __cpuidle_get_cpu_driver - return the cpuidle driver tied to a CPU.
42 * __cpuidle_unset_driver - unset per CPU driver variables.
43 * @drv: a valid pointer to a struct cpuidle_driver
46 * variable. If @drv is different from the registered driver, the corresponding
49 static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv) in __cpuidle_unset_driver() argument
53 for_each_cpu(cpu, drv->cpumask) { in __cpuidle_unset_driver()
55 if (drv != __cpuidle_get_cpu_driver(cpu)) in __cpuidle_unset_driver()
63 * __cpuidle_set_driver - set per CPU driver variables for the given driver.
64 * @drv: a valid pointer to a struct cpuidle_driver
66 * Returns 0 on success, -EBUSY if any CPU in the cpumask have a driver
67 * different from drv already.
69 static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) in __cpuidle_set_driver() argument
73 for_each_cpu(cpu, drv->cpumask) { in __cpuidle_set_driver()
77 if (old_drv && old_drv != drv) in __cpuidle_set_driver()
78 return -EBUSY; in __cpuidle_set_driver()
81 for_each_cpu(cpu, drv->cpumask) in __cpuidle_set_driver()
82 per_cpu(cpuidle_drivers, cpu) = drv; in __cpuidle_set_driver()
84 return 0; in __cpuidle_set_driver()
92 * __cpuidle_get_cpu_driver - return the global cpuidle driver pointer.
104 * __cpuidle_set_driver - assign the global cpuidle driver variable.
105 * @drv: pointer to a struct cpuidle_driver object
107 * Returns 0 on success, -EBUSY if the driver is already registered.
109 static inline int __cpuidle_set_driver(struct cpuidle_driver *drv) in __cpuidle_set_driver() argument
112 return -EBUSY; in __cpuidle_set_driver()
114 cpuidle_curr_driver = drv; in __cpuidle_set_driver()
116 return 0; in __cpuidle_set_driver()
120 * __cpuidle_unset_driver - unset the global cpuidle driver variable.
121 * @drv: a pointer to a struct cpuidle_driver
123 * Reset the global cpuidle variable to NULL. If @drv does not match the
126 static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv) in __cpuidle_unset_driver() argument
128 if (drv == cpuidle_curr_driver) in __cpuidle_unset_driver()
135 * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer on a cpu
152 * __cpuidle_driver_init - initialize the driver's internal data
153 * @drv: a valid pointer to a struct cpuidle_driver
155 static void __cpuidle_driver_init(struct cpuidle_driver *drv) in __cpuidle_driver_init() argument
164 if (!drv->cpumask) in __cpuidle_driver_init()
165 drv->cpumask = (struct cpumask *)cpu_possible_mask; in __cpuidle_driver_init()
167 for (i = 0; i < drv->state_count; i++) { in __cpuidle_driver_init()
168 struct cpuidle_state *s = &drv->states[i]; in __cpuidle_driver_init()
175 if (s->flags & CPUIDLE_FLAG_TIMER_STOP) in __cpuidle_driver_init()
176 drv->bctimer = 1; in __cpuidle_driver_init()
183 if (s->target_residency > 0) in __cpuidle_driver_init()
184 s->target_residency_ns = s->target_residency * NSEC_PER_USEC; in __cpuidle_driver_init()
185 else if (s->target_residency_ns < 0) in __cpuidle_driver_init()
186 s->target_residency_ns = 0; in __cpuidle_driver_init()
188 s->target_residency = div_u64(s->target_residency_ns, NSEC_PER_USEC); in __cpuidle_driver_init()
190 if (s->exit_latency > 0) in __cpuidle_driver_init()
191 s->exit_latency_ns = mul_u32_u32(s->exit_latency, NSEC_PER_USEC); in __cpuidle_driver_init()
192 else if (s->exit_latency_ns < 0) in __cpuidle_driver_init()
193 s->exit_latency_ns = 0; in __cpuidle_driver_init()
195 s->exit_latency = div_u64(s->exit_latency_ns, NSEC_PER_USEC); in __cpuidle_driver_init()
201 * @drv: a valid pointer to a struct cpuidle_driver
207 * Returns 0 on success, a negative error code otherwise:
208 * * -EINVAL if the driver pointer is NULL or no idle states are available
209 * * -ENODEV if the cpuidle framework is disabled
210 * * -EBUSY if the driver is already assigned to the global variable(s)
212 static int __cpuidle_register_driver(struct cpuidle_driver *drv) in __cpuidle_register_driver() argument
216 if (!drv || !drv->state_count) in __cpuidle_register_driver()
217 return -EINVAL; in __cpuidle_register_driver()
219 ret = cpuidle_coupled_state_verify(drv); in __cpuidle_register_driver()
224 return -ENODEV; in __cpuidle_register_driver()
226 __cpuidle_driver_init(drv); in __cpuidle_register_driver()
228 ret = __cpuidle_set_driver(drv); in __cpuidle_register_driver()
232 if (drv->bctimer) in __cpuidle_register_driver()
233 on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer, in __cpuidle_register_driver()
236 return 0; in __cpuidle_register_driver()
240 * __cpuidle_unregister_driver - unregister the driver
241 * @drv: a valid pointer to a struct cpuidle_driver
248 static void __cpuidle_unregister_driver(struct cpuidle_driver *drv) in __cpuidle_unregister_driver() argument
250 if (drv->bctimer) { in __cpuidle_unregister_driver()
251 drv->bctimer = 0; in __cpuidle_unregister_driver()
252 on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer, in __cpuidle_unregister_driver()
256 __cpuidle_unset_driver(drv); in __cpuidle_unregister_driver()
260 * cpuidle_register_driver - registers a driver
261 * @drv: a pointer to a valid struct cpuidle_driver
266 * Returns 0 on success, a negative error code (returned by
269 int cpuidle_register_driver(struct cpuidle_driver *drv) in cpuidle_register_driver() argument
275 ret = __cpuidle_register_driver(drv); in cpuidle_register_driver()
278 if (!ret && !strlen(param_governor) && drv->governor && in cpuidle_register_driver()
279 (cpuidle_get_driver() == drv)) { in cpuidle_register_driver()
281 gov = cpuidle_find_governor(drv->governor); in cpuidle_register_driver()
284 if (cpuidle_switch_governor(gov) < 0) in cpuidle_register_driver()
295 * cpuidle_unregister_driver - unregisters a driver
296 * @drv: a pointer to a valid struct cpuidle_driver
299 * to [un]register the driver from occuring at the same time. @drv has to
302 void cpuidle_unregister_driver(struct cpuidle_driver *drv) in cpuidle_unregister_driver() argument
304 bool enabled = (cpuidle_get_driver() == drv); in cpuidle_unregister_driver()
307 __cpuidle_unregister_driver(drv); in cpuidle_unregister_driver()
323 * cpuidle_get_driver - return the driver tied to the current CPU.
329 struct cpuidle_driver *drv; in cpuidle_get_driver() local
333 drv = __cpuidle_get_cpu_driver(cpu); in cpuidle_get_driver()
336 return drv; in cpuidle_get_driver()
341 * cpuidle_get_cpu_driver - return the driver registered for a CPU.
352 return __cpuidle_get_cpu_driver(dev->cpu); in cpuidle_get_cpu_driver()
357 * cpuidle_driver_state_disabled - Disable or enable an idle state
358 * @drv: cpuidle driver owning the state
362 void cpuidle_driver_state_disabled(struct cpuidle_driver *drv, int idx, in cpuidle_driver_state_disabled() argument
371 if (!drv->cpumask) { in cpuidle_driver_state_disabled()
372 drv->states[idx].flags |= CPUIDLE_FLAG_UNUSABLE; in cpuidle_driver_state_disabled()
376 for_each_cpu(cpu, drv->cpumask) { in cpuidle_driver_state_disabled()
383 dev->states_usage[idx].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER; in cpuidle_driver_state_disabled()
385 dev->states_usage[idx].disable &= ~CPUIDLE_STATE_DISABLED_BY_DRIVER; in cpuidle_driver_state_disabled()