ret = pm_runtime_is_irq_safe(dev) && !genpd_is_irq_safe(genpd);
/* * Warn once if an IRQ safe device is attached to a domain, which * callbacks are allowed to sleep. This indicates a suboptimal * configuration for PM, but it doesn't matter for an always on domain.
*/ if (genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd)) return ret;
if (ret)
dev_warn_once(dev, "PM domain %s will not be powered off\n",
dev_name(&genpd->dev));
/* * Get the generic PM domain for a particular struct device. * This validates the struct device pointer, the PM domain pointer, * and checks that the PM domain pointer is a real generic PM domain. * Any failure results in NULL being returned.
*/ staticstruct generic_pm_domain *dev_to_genpd_safe(struct device *dev)
{ if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain)) return NULL;
/* A genpd's always have its ->runtime_suspend() callback assigned. */ if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend) return pd_to_genpd(dev->pm_domain);
return NULL;
}
/* * This should only be used where we are certain that the pm_domain * attached to the device is a genpd domain.
*/ staticstruct generic_pm_domain *dev_to_genpd(struct device *dev)
{ if (IS_ERR_OR_NULL(dev->pm_domain)) return ERR_PTR(-EINVAL);
now = ktime_get_mono_fast_ns(); if (now <= genpd->accounting_time) return;
delta = now - genpd->accounting_time;
/* * If genpd->status is active, it means we are just * out of off and so update the idle time and vice * versa.
*/ if (genpd->status == GENPD_STATE_ON)
genpd->states[genpd->state_idx].idle_time += delta; else
genpd->on_time += delta;
/* New requested state is same as Max requested state */ if (state == genpd->performance_state) return state;
/* New requested state is higher than Max requested state */ if (state > genpd->performance_state) return state;
/* Traverse all devices within the domain */
list_for_each_entry(pdd, &genpd->dev_list, list_node) {
pd_data = to_gpd_data(pdd);
if (pd_data->performance_state > state)
state = pd_data->performance_state;
}
/* * Traverse all sub-domains within the domain. This can be * done without any additional locking as the link->performance_state * field is protected by the parent genpd->lock, which is already taken. * * Also note that link->performance_state (subdomain's performance state * requirement to parent domain) is different from * link->child->performance_state (current performance state requirement * of the devices/sub-domains of the subdomain) and so can have a * different value. * * Note that we also take vote from powered-off sub-domains into account * as the same is done for devices right now.
*/
list_for_each_entry(link, &genpd->parent_links, parent_node) { if (link->performance_state > state)
state = link->performance_state;
}
parent_state = _genpd_reeval_performance_state(parent, parent_state); if (_genpd_set_performance_state(parent, parent_state, depth + 1)) {
pr_err("%s: Failed to roll back to %d performance state\n",
parent->name, parent_state);
}
genpd_unlock(parent);
}
staticint _genpd_set_parent_state(struct generic_pm_domain *genpd, struct gpd_link *link, unsignedint state, int depth)
{ struct generic_pm_domain *parent = link->parent; int parent_state, ret;
/* Find parent's performance state */
ret = genpd_xlate_performance_state(genpd, parent, state); if (unlikely(ret < 0)) return ret;
parent_state = _genpd_reeval_performance_state(parent, parent_state);
ret = _genpd_set_performance_state(parent, parent_state, depth + 1); if (ret)
link->performance_state = link->prev_performance_state;
genpd_unlock(parent);
return ret;
}
staticint _genpd_set_performance_state(struct generic_pm_domain *genpd, unsignedint state, int depth)
{ struct gpd_link *link = NULL; int ret;
if (state == genpd->performance_state) return 0;
/* When scaling up, propagate to parents first in normal order */ if (state > genpd->performance_state) {
list_for_each_entry(link, &genpd->child_links, child_node) {
ret = _genpd_set_parent_state(genpd, link, state, depth); if (ret) goto rollback_parents_up;
}
}
if (genpd->set_performance_state) {
ret = genpd->set_performance_state(genpd, state); if (ret) { if (link) goto rollback_parents_up; return ret;
}
}
/* When scaling down, propagate to parents last in reverse order */ if (state < genpd->performance_state) {
list_for_each_entry_reverse(link, &genpd->child_links, child_node) {
ret = _genpd_set_parent_state(genpd, link, state, depth); if (ret) goto rollback_parents_down;
}
}
staticint genpd_dev_pm_set_performance_state(struct device *dev, unsignedint state)
{ struct generic_pm_domain *genpd = dev_to_genpd(dev); int ret = 0;
genpd_lock(genpd); if (pm_runtime_suspended(dev)) {
dev_gpd_data(dev)->rpm_pstate = state;
} else {
ret = genpd_set_performance_state(dev, state); if (!ret)
dev_gpd_data(dev)->rpm_pstate = 0;
}
genpd_unlock(genpd);
return ret;
}
/** * dev_pm_genpd_set_performance_state- Set performance state of device's power * domain. * * @dev: Device for which the performance-state needs to be set. * @state: Target performance state of the device. This can be set as 0 when the * device doesn't have any performance state constraints left (And so * the device wouldn't participate anymore to find the target * performance state of the genpd). * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Returns 0 on success and negative error values on failures.
*/ int dev_pm_genpd_set_performance_state(struct device *dev, unsignedint state)
{ struct generic_pm_domain *genpd;
genpd = dev_to_genpd_safe(dev); if (!genpd) return -ENODEV;
if (WARN_ON(!dev->power.subsys_data ||
!dev->power.subsys_data->domain_data)) return -EINVAL;
/** * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup. * * @dev: Device to handle * @next: impending interrupt/wakeup for the device * * * Allow devices to inform of the next wakeup. It's assumed that the users * guarantee that the genpd wouldn't be detached while this routine is getting * called. Additionally, it's also assumed that @dev isn't runtime suspended * (RPM_SUSPENDED)." * Although devices are expected to update the next_wakeup after the end of * their usecase as well, it is possible the devices themselves may not know * about that, so stale @next will be ignored when powering off the domain.
*/ void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next)
{ struct generic_pm_domain *genpd; struct gpd_timing_data *td;
genpd = dev_to_genpd_safe(dev); if (!genpd) return;
td = to_gpd_data(dev->power.subsys_data->domain_data)->td; if (td)
td->next_wakeup = next;
}
EXPORT_SYMBOL_GPL(dev_pm_genpd_set_next_wakeup);
/** * dev_pm_genpd_get_next_hrtimer - Return the next_hrtimer for the genpd * @dev: A device that is attached to the genpd. * * This routine should typically be called for a device, at the point of when a * GENPD_NOTIFY_PRE_OFF notification has been sent for it. * * Returns the aggregated value of the genpd's next hrtimer or KTIME_MAX if no * valid value have been set.
*/
ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev)
{ struct generic_pm_domain *genpd;
genpd = dev_to_genpd_safe(dev); if (!genpd) return KTIME_MAX;
/* * dev_pm_genpd_synced_poweroff - Next power off should be synchronous * * @dev: A device that is attached to the genpd. * * Allows a consumer of the genpd to notify the provider that the next power off * should be synchronous. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called.
*/ void dev_pm_genpd_synced_poweroff(struct device *dev)
{ struct generic_pm_domain *genpd;
genpd = dev_to_genpd_safe(dev); if (!genpd) return;
/** * dev_pm_genpd_set_hwmode() - Set the HW mode for the device and its PM domain. * * @dev: Device for which the HW-mode should be changed. * @enable: Value to set or unset the HW-mode. * * Some PM domains can rely on HW signals to control the power for a device. To * allow a consumer driver to switch the behaviour for its device in runtime, * which may be beneficial from a latency or energy point of view, this function * may be called. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Return: Returns 0 on success and negative error values on failures.
*/ int dev_pm_genpd_set_hwmode(struct device *dev, bool enable)
{ struct generic_pm_domain *genpd; int ret = 0;
genpd = dev_to_genpd_safe(dev); if (!genpd) return -ENODEV;
if (!genpd->set_hwmode_dev) return -EOPNOTSUPP;
genpd_lock(genpd);
if (dev_gpd_data(dev)->hw_mode == enable) goto out;
ret = genpd->set_hwmode_dev(genpd, dev, enable); if (!ret)
dev_gpd_data(dev)->hw_mode = enable;
/** * dev_pm_genpd_get_hwmode() - Get the HW mode setting for the device. * * @dev: Device for which the current HW-mode setting should be fetched. * * This helper function allows consumer drivers to fetch the current HW mode * setting of its the device. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Return: Returns the HW mode setting of device from SW cached hw_mode.
*/ bool dev_pm_genpd_get_hwmode(struct device *dev)
{ return dev_gpd_data(dev)->hw_mode;
}
EXPORT_SYMBOL_GPL(dev_pm_genpd_get_hwmode);
/** * dev_pm_genpd_rpm_always_on() - Control if the PM domain can be powered off. * * @dev: Device for which the PM domain may need to stay on for. * @on: Value to set or unset for the condition. * * For some usecases a consumer driver requires its device to remain power-on * from the PM domain perspective during runtime. This function allows the * behaviour to be dynamically controlled for a device attached to a genpd. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Return: Returns 0 on success and negative error values on failures.
*/ int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
{ struct generic_pm_domain *genpd;
genpd = dev_to_genpd_safe(dev); if (!genpd) return -ENODEV;
/** * dev_pm_genpd_is_on() - Get device's current power domain status * * @dev: Device to get the current power status * * This function checks whether the generic power domain associated with the * given device is on or not by verifying if genpd_status_on equals * GENPD_STATE_ON. * * Note: this function returns the power status of the genpd at the time of the * call. The power status may change after due to activity from other devices * sharing the same genpd. Therefore, this information should not be relied for * long-term decisions about the device power state. * * Return: 'true' if the device's power domain is on, 'false' otherwise.
*/ bool dev_pm_genpd_is_on(struct device *dev)
{ struct generic_pm_domain *genpd; bool is_on;
genpd = dev_to_genpd_safe(dev); if (!genpd) returnfalse;
/** * pm_genpd_inc_rejected() - Adjust the rejected/usage counts for an idle-state. * * @genpd: The PM domain the idle-state belongs to. * @state_idx: The index of the idle-state that failed. * * In some special cases the ->power_off() callback is asynchronously powering * off the PM domain, leading to that it may return zero to indicate success, * even though the actual power-off could fail. To account for this correctly in * the rejected/usage counts for the idle-state statistics, users can call this * function to adjust the values. * * It is assumed that the users guarantee that the genpd doesn't get removed * while this routine is getting called.
*/ void pm_genpd_inc_rejected(struct generic_pm_domain *genpd, unsignedint state_idx)
{
genpd_lock(genpd);
genpd->states[genpd->state_idx].rejected++;
genpd->states[genpd->state_idx].usage--;
genpd_unlock(genpd);
}
EXPORT_SYMBOL_GPL(pm_genpd_inc_rejected);
/* Notify consumers that we are about to power on. */
ret = raw_notifier_call_chain_robust(&genpd->power_notifiers,
GENPD_NOTIFY_PRE_ON,
GENPD_NOTIFY_OFF, NULL);
ret = notifier_to_errno(ret); if (ret) return ret;
if (!genpd->power_on) goto out;
timed = timed && genpd->gd && !genpd->states[state_idx].fwnode; if (!timed) {
ret = genpd->power_on(genpd); if (ret) goto err;
goto out;
}
time_start = ktime_get();
ret = genpd->power_on(genpd); if (ret) goto err;
elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns) goto out;
genpd->states[state_idx].power_on_latency_ns = elapsed_ns;
genpd->gd->max_off_time_changed = true;
pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
dev_name(&genpd->dev), "on", elapsed_ns);
/* Notify consumers that we are about to power off. */
ret = raw_notifier_call_chain_robust(&genpd->power_notifiers,
GENPD_NOTIFY_PRE_OFF,
GENPD_NOTIFY_ON, NULL);
ret = notifier_to_errno(ret); if (ret) return ret;
if (!genpd->power_off) goto out;
timed = timed && genpd->gd && !genpd->states[state_idx].fwnode; if (!timed) {
ret = genpd->power_off(genpd); if (ret) goto busy;
goto out;
}
time_start = ktime_get();
ret = genpd->power_off(genpd); if (ret) goto busy;
elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); if (elapsed_ns <= genpd->states[state_idx].power_off_latency_ns) goto out;
genpd->states[state_idx].power_off_latency_ns = elapsed_ns;
genpd->gd->max_off_time_changed = true;
pr_debug("%s: Power-%s latency exceeded, new value %lld ns\n",
dev_name(&genpd->dev), "off", elapsed_ns);
/** * genpd_queue_power_off_work - Queue up the execution of genpd_power_off(). * @genpd: PM domain to power off. * * Queue up the execution of genpd_power_off() unless it's already been done * before.
*/ staticvoid genpd_queue_power_off_work(struct generic_pm_domain *genpd)
{
queue_work(pm_wq, &genpd->power_off_work);
}
/** * genpd_power_off - Remove power from a given PM domain. * @genpd: PM domain to power down. * @one_dev_on: If invoked from genpd's ->runtime_suspend|resume() callback, the * RPM status of the releated device is in an intermediate state, not yet turned * into RPM_SUSPENDED. This means genpd_power_off() must allow one device to not * be RPM_SUSPENDED, while it tries to power off the PM domain. * @depth: nesting count for lockdep. * * If all of the @genpd's devices have been suspended and all of its subdomains * have been powered down, remove power from @genpd.
*/ staticvoid genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, unsignedint depth)
{ struct pm_domain_data *pdd; struct gpd_link *link; unsignedint not_suspended = 0;
/* * Do not try to power off the domain in the following situations: * The domain is already in the "power off" state. * System suspend is in progress. * The domain is configured as always on. * The domain was on at boot and still need to stay on. * The domain has a subdomain being powered on.
*/ if (!genpd_status_on(genpd) || genpd->prepared_count > 0 ||
genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd) ||
genpd->stay_on || atomic_read(&genpd->sd_count) > 0) return;
/* * The children must be in their deepest (powered-off) states to allow * the parent to be powered off. Note that, there's no need for * additional locking, as powering on a child, requires the parent's * lock to be acquired first.
*/
list_for_each_entry(link, &genpd->parent_links, parent_node) { struct generic_pm_domain *child = link->child; if (child->state_idx < child->state_count - 1) return;
}
list_for_each_entry(pdd, &genpd->dev_list, list_node) { /* * Do not allow PM domain to be powered off, when an IRQ safe * device is part of a non-IRQ safe domain.
*/ if (!pm_runtime_suspended(pdd->dev) ||
irq_safe_dev_in_sleep_domain(pdd->dev, genpd))
not_suspended++;
/* The device may need its PM domain to stay powered on. */ if (to_gpd_data(pdd)->rpm_always_on) return;
}
/** * genpd_power_on - Restore power to a given PM domain and its parents. * @genpd: PM domain to power up. * @depth: nesting count for lockdep. * * Restore power to @genpd and all of its parents so that it is possible to * resume a device belonging to it.
*/ staticint genpd_power_on(struct generic_pm_domain *genpd, unsignedint depth)
{ struct gpd_link *link; int ret = 0;
if (genpd_status_on(genpd)) return 0;
/* Reflect over the entered idle-states residency for debugfs. */
genpd_reflect_residency(genpd);
/* * The list is guaranteed not to change while the loop below is being * executed, unless one of the parents' .power_on() callbacks fiddles * with it.
*/
list_for_each_entry(link, &genpd->child_links, child_node) { struct generic_pm_domain *parent = link->parent;
if (!IS_ERR(genpd)) {
genpd_lock(genpd);
genpd->gd->max_off_time_changed = true;
genpd_unlock(genpd);
}
dev = dev->parent; if (!dev || dev->power.ignore_children) break;
}
return NOTIFY_DONE;
}
/** * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0. * @work: Work structure used for scheduling the execution of this function.
*/ staticvoid genpd_power_off_work_fn(struct work_struct *work)
{ struct generic_pm_domain *genpd;
/** * __genpd_runtime_suspend - walk the hierarchy of ->runtime_suspend() callbacks * @dev: Device to handle.
*/ staticint __genpd_runtime_suspend(struct device *dev)
{ int (*cb)(struct device *__dev);
if (!cb && dev->driver && dev->driver->pm)
cb = dev->driver->pm->runtime_suspend;
return cb ? cb(dev) : 0;
}
/** * __genpd_runtime_resume - walk the hierarchy of ->runtime_resume() callbacks * @dev: Device to handle.
*/ staticint __genpd_runtime_resume(struct device *dev)
{ int (*cb)(struct device *__dev);
if (!cb && dev->driver && dev->driver->pm)
cb = dev->driver->pm->runtime_resume;
return cb ? cb(dev) : 0;
}
/** * genpd_runtime_suspend - Suspend a device belonging to I/O PM domain. * @dev: Device to suspend. * * Carry out a runtime suspend of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a PM domain consisting of I/O devices.
*/ staticint genpd_runtime_suspend(struct device *dev)
{ struct generic_pm_domain *genpd; bool (*suspend_ok)(struct device *__dev); struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); struct gpd_timing_data *td = gpd_data->td; bool runtime_pm = pm_runtime_enabled(dev);
ktime_t time_start = 0;
s64 elapsed_ns; int ret;
dev_dbg(dev, "%s()\n", __func__);
genpd = dev_to_genpd(dev); if (IS_ERR(genpd)) return -EINVAL;
/* * A runtime PM centric subsystem/driver may re-use the runtime PM * callbacks for other purposes than runtime PM. In those scenarios * runtime PM is disabled. Under these circumstances, we shall skip * validating/measuring the PM QoS latency.
*/
suspend_ok = genpd->gov ? genpd->gov->suspend_ok : NULL; if (runtime_pm && suspend_ok && !suspend_ok(dev)) return -EBUSY;
ret = __genpd_runtime_suspend(dev); if (ret) return ret;
ret = genpd_stop_dev(genpd, dev); if (ret) {
__genpd_runtime_resume(dev); return ret;
}
/* Update suspend latency value if the measured time exceeds it. */ if (td && runtime_pm) {
elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); if (elapsed_ns > td->suspend_latency_ns) {
td->suspend_latency_ns = elapsed_ns;
dev_dbg(dev, "suspend latency exceeded, %lld ns\n",
elapsed_ns);
genpd->gd->max_off_time_changed = true;
td->constraint_changed = true;
}
}
/* * If power.irq_safe is set, this routine may be run with * IRQs disabled, so suspend only if the PM domain also is irq_safe.
*/ if (irq_safe_dev_in_sleep_domain(dev, genpd)) return 0;
/** * genpd_runtime_resume - Resume a device belonging to I/O PM domain. * @dev: Device to resume. * * Carry out a runtime resume of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a PM domain consisting of I/O devices.
*/ staticint genpd_runtime_resume(struct device *dev)
{ struct generic_pm_domain *genpd; struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); struct gpd_timing_data *td = gpd_data->td; bool timed = td && pm_runtime_enabled(dev);
ktime_t time_start = 0;
s64 elapsed_ns; int ret;
dev_dbg(dev, "%s()\n", __func__);
genpd = dev_to_genpd(dev); if (IS_ERR(genpd)) return -EINVAL;
/* * As we don't power off a non IRQ safe domain, which holds * an IRQ safe device, we don't need to restore power to it.
*/ if (irq_safe_dev_in_sleep_domain(dev, genpd)) goto out;
genpd_lock(genpd);
genpd_restore_performance_state(dev, gpd_data->rpm_pstate);
ret = genpd_power_on(genpd, 0);
genpd_unlock(genpd);
/** * genpd_power_off_unused - Power off all PM domains with no devices in use.
*/ staticint __init genpd_power_off_unused(void)
{ struct generic_pm_domain *genpd;
if (pd_ignore_unused) {
pr_warn("genpd: Not disabling unused power domains\n"); return 0;
}
pr_info("genpd: Disabling unused power domains\n");
mutex_lock(&gpd_list_lock);
/** * genpd_sync_power_off - Synchronously power off a PM domain and its parents. * @genpd: PM domain to power off, if possible. * @use_lock: use the lock. * @depth: nesting count for lockdep. * * Check if the given PM domain can be powered off (during system suspend or * hibernation) and do that if so. Also, in that case propagate to its parents. * * This function is only called in "noirq" and "syscore" stages of system power * transitions. The "noirq" callbacks may be executed asynchronously, thus in * these cases the lock must be held.
*/ staticvoid genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, unsignedint depth)
{ struct gpd_link *link;
if (!genpd_status_on(genpd) || genpd_is_always_on(genpd)) return;
if (genpd->suspended_count != genpd->device_count
|| atomic_read(&genpd->sd_count) > 0) return;
/* Check that the children are in their deepest (powered-off) state. */
list_for_each_entry(link, &genpd->parent_links, parent_node) { struct generic_pm_domain *child = link->child; if (child->state_idx < child->state_count - 1) return;
}
/* Choose the deepest state when suspending */
genpd->state_idx = genpd->state_count - 1; if (_genpd_power_off(genpd, false)) {
genpd->states[genpd->state_idx].rejected++; return;
} else {
genpd->states[genpd->state_idx].usage++;
}
/** * genpd_sync_power_on - Synchronously power on a PM domain and its parents. * @genpd: PM domain to power on. * @use_lock: use the lock. * @depth: nesting count for lockdep. * * This function is only called in "noirq" and "syscore" stages of system power * transitions. The "noirq" callbacks may be executed asynchronously, thus in * these cases the lock must be held.
*/ staticvoid genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock, unsignedint depth)
{ struct gpd_link *link;
/** * genpd_prepare - Start power transition of a device in a PM domain. * @dev: Device to start the transition of. * * Start a power transition of a device (during a system-wide power transition) * under the assumption that its pm_domain field points to the domain member of * an object of type struct generic_pm_domain representing a PM domain * consisting of I/O devices.
*/ staticint genpd_prepare(struct device *dev)
{ struct generic_pm_domain *genpd; int ret;
dev_dbg(dev, "%s()\n", __func__);
genpd = dev_to_genpd(dev); if (IS_ERR(genpd)) return -EINVAL;
ret = pm_generic_prepare(dev); if (ret < 0) {
genpd_lock(genpd);
genpd->prepared_count--;
genpd_unlock(genpd);
}
/* Never return 1, as genpd don't cope with the direct_complete path. */ return ret >= 0 ? 0 : ret;
}
/** * genpd_finish_suspend - Completion of suspend or hibernation of device in an * I/O pm domain. * @dev: Device to suspend. * @suspend_noirq: Generic suspend_noirq callback. * @resume_noirq: Generic resume_noirq callback. * * Stop the device and remove power from the domain if all devices in it have * been stopped.
*/ staticint genpd_finish_suspend(struct device *dev, int (*suspend_noirq)(struct device *dev), int (*resume_noirq)(struct device *dev))
{ struct generic_pm_domain *genpd; int ret = 0;
genpd = dev_to_genpd(dev); if (IS_ERR(genpd)) return -EINVAL;
ret = suspend_noirq(dev); if (ret) return ret;
if (device_awake_path(dev) && genpd_is_active_wakeup(genpd)) return 0;
if (genpd->dev_ops.stop && genpd->dev_ops.start &&
!pm_runtime_status_suspended(dev)) {
ret = genpd_stop_dev(genpd, dev); if (ret) {
resume_noirq(dev); return ret;
}
}
/** * genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain. * @dev: Device to suspend. * * Stop the device and remove power from the domain if all devices in it have * been stopped.
*/ staticint genpd_suspend_noirq(struct device *dev)
{
dev_dbg(dev, "%s()\n", __func__);
/** * genpd_finish_resume - Completion of resume of device in an I/O PM domain. * @dev: Device to resume. * @resume_noirq: Generic resume_noirq callback. * * Restore power to the device's PM domain, if necessary, and start the device.
*/ staticint genpd_finish_resume(struct device *dev, int (*resume_noirq)(struct device *dev))
{ struct generic_pm_domain *genpd; int ret;
dev_dbg(dev, "%s()\n", __func__);
genpd = dev_to_genpd(dev); if (IS_ERR(genpd)) return -EINVAL;
if (device_awake_path(dev) && genpd_is_active_wakeup(genpd)) return resume_noirq(dev);
if (genpd->dev_ops.stop && genpd->dev_ops.start &&
!pm_runtime_status_suspended(dev)) {
ret = genpd_start_dev(genpd, dev); if (ret) return ret;
}
return pm_generic_resume_noirq(dev);
}
/** * genpd_resume_noirq - Start of resume of device in an I/O PM domain. * @dev: Device to resume. * * Restore power to the device's PM domain, if necessary, and start the device.
*/ staticint genpd_resume_noirq(struct device *dev)
{
dev_dbg(dev, "%s()\n", __func__);
/** * genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain. * @dev: Device to freeze. * * Carry out a late freeze of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a power domain consisting of I/O * devices.
*/ staticint genpd_freeze_noirq(struct device *dev)
{
dev_dbg(dev, "%s()\n", __func__);
/** * genpd_thaw_noirq - Early thaw of device in an I/O PM domain. * @dev: Device to thaw. * * Start the device, unless power has been removed from the domain already * before the system transition.
*/ staticint genpd_thaw_noirq(struct device *dev)
{
dev_dbg(dev, "%s()\n", __func__);
/** * genpd_poweroff_noirq - Completion of hibernation of device in an * I/O PM domain. * @dev: Device to poweroff. * * Stop the device and remove power from the domain if all devices in it have * been stopped.
*/ staticint genpd_poweroff_noirq(struct device *dev)
{
dev_dbg(dev, "%s()\n", __func__);
/** * genpd_restore_noirq - Start of restore of device in an I/O PM domain. * @dev: Device to resume. * * Make sure the domain will be in the same power state as before the * hibernation the system is resuming from and start the device if necessary.
*/ staticint genpd_restore_noirq(struct device *dev)
{
dev_dbg(dev, "%s()\n", __func__);
/** * genpd_complete - Complete power transition of a device in a power domain. * @dev: Device to complete the transition of. * * Complete a power transition of a device (during a system-wide power * transition) under the assumption that its pm_domain field points to the * domain member of an object of type struct generic_pm_domain representing * a power domain consisting of I/O devices.
*/ staticvoid genpd_complete(struct device *dev)
{ struct generic_pm_domain *genpd;
dev_dbg(dev, "%s()\n", __func__);
genpd = dev_to_genpd(dev); if (IS_ERR(genpd)) return;
pm_generic_complete(dev);
genpd_lock(genpd);
genpd->prepared_count--; if (!genpd->prepared_count)
genpd_queue_power_off_work(genpd);
/** * dev_pm_genpd_suspend - Synchronously try to suspend the genpd for @dev * @dev: The device that is attached to the genpd, that can be suspended. * * This routine should typically be called for a device that needs to be * suspended during the syscore suspend phase. It may also be called during * suspend-to-idle to suspend a corresponding CPU device that is attached to a * genpd.
*/ void dev_pm_genpd_suspend(struct device *dev)
{
genpd_switch_state(dev, true);
}
EXPORT_SYMBOL_GPL(dev_pm_genpd_suspend);
/** * dev_pm_genpd_resume - Synchronously try to resume the genpd for @dev * @dev: The device that is attached to the genpd, which needs to be resumed. * * This routine should typically be called for a device that needs to be resumed * during the syscore resume phase. It may also be called during suspend-to-idle * to resume a corresponding CPU device that is attached to a genpd.
*/ void dev_pm_genpd_resume(struct device *dev)
{
genpd_switch_state(dev, false);
}
EXPORT_SYMBOL_GPL(dev_pm_genpd_resume);
/** * pm_genpd_add_device - Add a device to an I/O PM domain. * @genpd: PM domain to add the device to. * @dev: Device to be added.
*/ int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
{ int ret;
if (!genpd || !dev) return -EINVAL;
mutex_lock(&gpd_list_lock);
ret = genpd_add_device(genpd, dev, dev);
mutex_unlock(&gpd_list_lock);
/** * pm_genpd_remove_device - Remove a device from an I/O PM domain. * @dev: Device to be removed.
*/ int pm_genpd_remove_device(struct device *dev)
{ struct generic_pm_domain *genpd = dev_to_genpd_safe(dev);
/** * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev * * @dev: Device that should be associated with the notifier * @nb: The notifier block to register * * Users may call this function to add a genpd power on/off notifier for an * attached @dev. Only one notifier per device is allowed. The notifier is * sent when genpd is powering on/off the PM domain. * * It is assumed that the user guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Returns 0 on success and negative error values on failures.
*/ int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb)
{ struct generic_pm_domain *genpd; struct generic_pm_domain_data *gpd_data; int ret;
genpd = dev_to_genpd_safe(dev); if (!genpd) return -ENODEV;
if (WARN_ON(!dev->power.subsys_data ||
!dev->power.subsys_data->domain_data)) return -EINVAL;
gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); if (gpd_data->power_nb) return -EEXIST;
genpd_lock(genpd);
ret = raw_notifier_chain_register(&genpd->power_notifiers, nb);
genpd_unlock(genpd);
if (ret) {
dev_warn(dev, "failed to add notifier for PM domain %s\n",
dev_name(&genpd->dev)); return ret;
}
/** * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev * * @dev: Device that is associated with the notifier * * Users may call this function to remove a genpd power on/off notifier for an * attached @dev. * * It is assumed that the user guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Returns 0 on success and negative error values on failures.
*/ int dev_pm_genpd_remove_notifier(struct device *dev)
{ struct generic_pm_domain *genpd; struct generic_pm_domain_data *gpd_data; int ret;
genpd = dev_to_genpd_safe(dev); if (!genpd) return -ENODEV;
if (WARN_ON(!dev->power.subsys_data ||
!dev->power.subsys_data->domain_data)) return -EINVAL;
gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); if (!gpd_data->power_nb) return -ENODEV;
genpd_lock(genpd);
ret = raw_notifier_chain_unregister(&genpd->power_notifiers,
gpd_data->power_nb);
genpd_unlock(genpd);
if (ret) {
dev_warn(dev, "failed to remove notifier for PM domain %s\n",
dev_name(&genpd->dev)); return ret;
}
staticint genpd_add_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain)
{ struct gpd_link *link, *itr; int ret = 0;
if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)
|| genpd == subdomain) return -EINVAL;
/* * If the domain can be powered on/off in an IRQ safe * context, ensure that the subdomain can also be * powered on/off in that context.
*/ if (!genpd_is_irq_safe(genpd) && genpd_is_irq_safe(subdomain)) {
WARN(1, "Parent %s of subdomain %s must be IRQ safe\n",
dev_name(&genpd->dev), subdomain->name); return -EINVAL;
}
link = kzalloc(sizeof(*link), GFP_KERNEL); if (!link) return -ENOMEM;
out:
genpd_unlock(genpd);
genpd_unlock(subdomain); if (ret)
kfree(link); return ret;
}
/** * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain. * @genpd: Leader PM domain to add the subdomain to. * @subdomain: Subdomain to be added.
*/ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain)
{ int ret;
mutex_lock(&gpd_list_lock);
ret = genpd_add_subdomain(genpd, subdomain);
mutex_unlock(&gpd_list_lock);
/** * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. * @genpd: Leader PM domain to remove the subdomain from. * @subdomain: Subdomain to be removed.
*/ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain)
{ struct gpd_link *l, *link; int ret = -EINVAL;
if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)) return -EINVAL;
/* Use only one "off" state if there were no states declared */ if (genpd->state_count == 0) {
ret = genpd_set_default_power_state(genpd); if (ret) goto free;
}
/** * pm_genpd_init - Initialize a generic I/O PM domain object. * @genpd: PM domain object to initialize. * @gov: PM domain governor to associate with the domain (may be NULL). * @is_off: Initial value of the domain's power_is_off field. * * Returns 0 on successful initialization, else a negative error code.
*/ int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off)
{ int ret;
/* The always-on governor works better with the corresponding flag. */ if (gov == &pm_domain_always_on_gov)
genpd->flags |= GENPD_FLAG_RPM_ALWAYS_ON;
/* Always-on domains must be powered on at initialization. */ if ((genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd)) &&
!genpd_status_on(genpd)) {
pr_err("always-on PM domain %s is not on\n", genpd->name); return -EINVAL;
}
/* Multiple states but no governor doesn't make sense. */ if (!gov && genpd->state_count > 1)
pr_warn("%s: no governor for states\n", genpd->name);
ret = genpd_alloc_data(genpd); if (ret) return ret;
/** * pm_genpd_remove - Remove a generic I/O PM domain * @genpd: Pointer to PM domain that is to be removed. * * To remove the PM domain, this function: * - Removes the PM domain as a subdomain to any parent domains, * if it was added.
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.