参照元

説明

引数

返り値

参考

実装

/**
 * __pm_runtime_resume - Carry out run-time resume of given device.
 * @dev: Device to resume.
 * @from_wq: If set, the function has been called via pm_wq.
 *
 * Check if the device can be woken up and run the ->runtime_resume() callback
 * provided by its bus type.  If another resume has been started earlier, wait
 * for it to finish.  If there's a suspend running in parallel with this
 * function, wait for it to finish and resume the device.  Cancel any scheduled
 * or pending requests.
 *
 * This function must be called under dev->power.lock with interrupts disabled.
 */
int __pm_runtime_resume(struct device *dev, bool from_wq)
	__releases(&dev->power.lock) __acquires(&dev->power.lock)
{
	struct device *parent = NULL;
	int retval = 0;

	dev_dbg(dev, "__pm_runtime_resume()%s!\n",
		from_wq ? " from workqueue" : "");

 repeat:
	if (dev->power.runtime_error) {
		retval = -EINVAL;
		goto out;
	}

	pm_runtime_cancel_pending(dev);

	if (dev->power.runtime_status == RPM_ACTIVE)
		retval = 1;
	else if (dev->power.disable_depth > 0)
		retval = -EAGAIN;
	if (retval)
		goto out;

	if (dev->power.runtime_status == RPM_RESUMING
	    || dev->power.runtime_status == RPM_SUSPENDING) {
		DEFINE_WAIT(wait);

		if (from_wq) {
			if (dev->power.runtime_status == RPM_SUSPENDING)
				dev->power.deferred_resume = true;
			retval = -EINPROGRESS;
			goto out;
		}

		/* Wait for the operation carried out in parallel with us. */
		for (;;) {
			prepare_to_wait(&dev->power.wait_queue, &wait,
					TASK_UNINTERRUPTIBLE);
			if (dev->power.runtime_status != RPM_RESUMING
			    && dev->power.runtime_status != RPM_SUSPENDING)
				break;

			spin_unlock_irq(&dev->power.lock);

			schedule();

			spin_lock_irq(&dev->power.lock);
		}
		finish_wait(&dev->power.wait_queue, &wait);
		goto repeat;
	}

	if (!parent && dev->parent) {
		/*
		 * Increment the parent's resume counter and resume it if
		 * necessary.
		 */
		parent = dev->parent;
		spin_unlock(&dev->power.lock);

		pm_runtime_get_noresume(parent);

		spin_lock(&parent->power.lock);
		/*
		 * We can resume if the parent's run-time PM is disabled or it
		 * is set to ignore children.
		 */
		if (!parent->power.disable_depth
		    && !parent->power.ignore_children) {
			__pm_runtime_resume(parent, false);
			if (parent->power.runtime_status != RPM_ACTIVE)
				retval = -EBUSY;
		}
		spin_unlock(&parent->power.lock);

		spin_lock(&dev->power.lock);
		if (retval)
			goto out;
		goto repeat;
	}

	dev->power.runtime_status = RPM_RESUMING;

	if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume) {
		spin_unlock_irq(&dev->power.lock);

		retval = dev->bus->pm->runtime_resume(dev);

		spin_lock_irq(&dev->power.lock);
		dev->power.runtime_error = retval;
	} else if (dev->type && dev->type->pm
	    && dev->type->pm->runtime_resume) {
		spin_unlock_irq(&dev->power.lock);

		retval = dev->type->pm->runtime_resume(dev);

		spin_lock_irq(&dev->power.lock);
		dev->power.runtime_error = retval;
	} else if (dev->class && dev->class->pm
	    && dev->class->pm->runtime_resume) {
		spin_unlock_irq(&dev->power.lock);

		retval = dev->class->pm->runtime_resume(dev);

		spin_lock_irq(&dev->power.lock);
		dev->power.runtime_error = retval;
	} else {
		retval = -ENOSYS;
	}

	if (retval) {
		dev->power.runtime_status = RPM_SUSPENDED;
		pm_runtime_cancel_pending(dev);
	} else {
		dev->power.runtime_status = RPM_ACTIVE;
		if (parent)
			atomic_inc(&parent->power.child_count);
	}
	wake_up_all(&dev->power.wait_queue);

	if (!retval)
		__pm_request_idle(dev);

 out:
	if (parent) {
		spin_unlock_irq(&dev->power.lock);

		pm_runtime_put(parent);

		spin_lock_irq(&dev->power.lock);
	}

	dev_dbg(dev, "__pm_runtime_resume() returns %d!\n", retval);

	return retval;
}

コメント


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS