2 * drivers/base/power/domain.c - Common code related to device power domains.
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
6 * This file is released under the GPLv2.
9 #include <linux/init.h>
10 #include <linux/kernel.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/pm_domain.h>
14 #include <linux/slab.h>
15 #include <linux/err.h>
16 #include <linux/sched.h>
17 #include <linux/suspend.h>
18 #include <linux/export.h>
20 #define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \
22 type (*__routine)(struct device *__d); \
23 type __ret = (type)0; \
25 __routine = genpd->dev_ops.callback; \
27 __ret = __routine(dev); \
29 __routine = dev_gpd_data(dev)->ops.callback; \
31 __ret = __routine(dev); \
36 #define GENPD_DEV_TIMED_CALLBACK(genpd, type, callback, dev, field, name) \
38 ktime_t __start = ktime_get(); \
39 type __retval = GENPD_DEV_CALLBACK(genpd, type, callback, dev); \
40 s64 __elapsed = ktime_to_ns(ktime_sub(ktime_get(), __start)); \
41 struct generic_pm_domain_data *__gpd_data = dev_gpd_data(dev); \
42 if (__elapsed > __gpd_data->td.field) { \
43 __gpd_data->td.field = __elapsed; \
44 dev_warn(dev, name " latency exceeded, new value %lld ns\n", \
50 static LIST_HEAD(gpd_list);
51 static DEFINE_MUTEX(gpd_list_lock);
55 struct generic_pm_domain *dev_to_genpd(struct device *dev)
57 if (IS_ERR_OR_NULL(dev->pm_domain))
58 return ERR_PTR(-EINVAL);
60 return pd_to_genpd(dev->pm_domain);
63 static int genpd_stop_dev(struct generic_pm_domain *genpd, struct device *dev)
65 return GENPD_DEV_TIMED_CALLBACK(genpd, int, stop, dev,
66 stop_latency_ns, "stop");
69 static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev)
71 return GENPD_DEV_TIMED_CALLBACK(genpd, int, start, dev,
72 start_latency_ns, "start");
75 static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev)
77 return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev,
78 save_state_latency_ns, "state save");
81 static int genpd_restore_dev(struct generic_pm_domain *genpd, struct device *dev)
83 return GENPD_DEV_TIMED_CALLBACK(genpd, int, restore_state, dev,
84 restore_state_latency_ns,
88 static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd)
92 if (!WARN_ON(atomic_read(&genpd->sd_count) == 0))
93 ret = !!atomic_dec_and_test(&genpd->sd_count);
98 static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
100 atomic_inc(&genpd->sd_count);
101 smp_mb__after_atomic_inc();
104 static void genpd_acquire_lock(struct generic_pm_domain *genpd)
108 mutex_lock(&genpd->lock);
110 * Wait for the domain to transition into either the active,
111 * or the power off state.
114 prepare_to_wait(&genpd->status_wait_queue, &wait,
115 TASK_UNINTERRUPTIBLE);
116 if (genpd->status == GPD_STATE_ACTIVE
117 || genpd->status == GPD_STATE_POWER_OFF)
119 mutex_unlock(&genpd->lock);
123 mutex_lock(&genpd->lock);
125 finish_wait(&genpd->status_wait_queue, &wait);
128 static void genpd_release_lock(struct generic_pm_domain *genpd)
130 mutex_unlock(&genpd->lock);
133 static void genpd_set_active(struct generic_pm_domain *genpd)
135 if (genpd->resume_count == 0)
136 genpd->status = GPD_STATE_ACTIVE;
140 * __pm_genpd_poweron - Restore power to a given PM domain and its masters.
141 * @genpd: PM domain to power up.
143 * Restore power to @genpd and all of its masters so that it is possible to
144 * resume a device belonging to it.
146 int __pm_genpd_poweron(struct generic_pm_domain *genpd)
147 __releases(&genpd->lock) __acquires(&genpd->lock)
149 struct gpd_link *link;
153 /* If the domain's master is being waited for, we have to wait too. */
155 prepare_to_wait(&genpd->status_wait_queue, &wait,
156 TASK_UNINTERRUPTIBLE);
157 if (genpd->status != GPD_STATE_WAIT_MASTER)
159 mutex_unlock(&genpd->lock);
163 mutex_lock(&genpd->lock);
165 finish_wait(&genpd->status_wait_queue, &wait);
167 if (genpd->status == GPD_STATE_ACTIVE
168 || (genpd->prepared_count > 0 && genpd->suspend_power_off))
171 if (genpd->status != GPD_STATE_POWER_OFF) {
172 genpd_set_active(genpd);
177 * The list is guaranteed not to change while the loop below is being
178 * executed, unless one of the masters' .power_on() callbacks fiddles
181 list_for_each_entry(link, &genpd->slave_links, slave_node) {
182 genpd_sd_counter_inc(link->master);
183 genpd->status = GPD_STATE_WAIT_MASTER;
185 mutex_unlock(&genpd->lock);
187 ret = pm_genpd_poweron(link->master);
189 mutex_lock(&genpd->lock);
192 * The "wait for parent" status is guaranteed not to change
193 * while the master is powering on.
195 genpd->status = GPD_STATE_POWER_OFF;
196 wake_up_all(&genpd->status_wait_queue);
198 genpd_sd_counter_dec(link->master);
203 if (genpd->power_on) {
204 ktime_t time_start = ktime_get();
207 ret = genpd->power_on(genpd);
211 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
212 if (elapsed_ns > genpd->power_on_latency_ns) {
213 genpd->power_on_latency_ns = elapsed_ns;
215 pr_warning("%s: Power-on latency exceeded, "
216 "new value %lld ns\n", genpd->name,
221 genpd_set_active(genpd);
226 list_for_each_entry_continue_reverse(link, &genpd->slave_links, slave_node)
227 genpd_sd_counter_dec(link->master);
233 * pm_genpd_poweron - Restore power to a given PM domain and its masters.
234 * @genpd: PM domain to power up.
236 int pm_genpd_poweron(struct generic_pm_domain *genpd)
240 mutex_lock(&genpd->lock);
241 ret = __pm_genpd_poweron(genpd);
242 mutex_unlock(&genpd->lock);
246 #endif /* CONFIG_PM */
248 #ifdef CONFIG_PM_RUNTIME
251 * __pm_genpd_save_device - Save the pre-suspend state of a device.
252 * @pdd: Domain data of the device to save the state of.
253 * @genpd: PM domain the device belongs to.
255 static int __pm_genpd_save_device(struct pm_domain_data *pdd,
256 struct generic_pm_domain *genpd)
257 __releases(&genpd->lock) __acquires(&genpd->lock)
259 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
260 struct device *dev = pdd->dev;
263 if (gpd_data->need_restore)
266 mutex_unlock(&genpd->lock);
268 genpd_start_dev(genpd, dev);
269 ret = genpd_save_dev(genpd, dev);
270 genpd_stop_dev(genpd, dev);
272 mutex_lock(&genpd->lock);
275 gpd_data->need_restore = true;
281 * __pm_genpd_restore_device - Restore the pre-suspend state of a device.
282 * @pdd: Domain data of the device to restore the state of.
283 * @genpd: PM domain the device belongs to.
285 static void __pm_genpd_restore_device(struct pm_domain_data *pdd,
286 struct generic_pm_domain *genpd)
287 __releases(&genpd->lock) __acquires(&genpd->lock)
289 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
290 struct device *dev = pdd->dev;
292 if (!gpd_data->need_restore)
295 mutex_unlock(&genpd->lock);
297 genpd_start_dev(genpd, dev);
298 genpd_restore_dev(genpd, dev);
299 genpd_stop_dev(genpd, dev);
301 mutex_lock(&genpd->lock);
303 gpd_data->need_restore = false;
307 * genpd_abort_poweroff - Check if a PM domain power off should be aborted.
308 * @genpd: PM domain to check.
310 * Return true if a PM domain's status changed to GPD_STATE_ACTIVE during
311 * a "power off" operation, which means that a "power on" has occured in the
312 * meantime, or if its resume_count field is different from zero, which means
313 * that one of its devices has been resumed in the meantime.
315 static bool genpd_abort_poweroff(struct generic_pm_domain *genpd)
317 return genpd->status == GPD_STATE_WAIT_MASTER
318 || genpd->status == GPD_STATE_ACTIVE || genpd->resume_count > 0;
322 * genpd_queue_power_off_work - Queue up the execution of pm_genpd_poweroff().
323 * @genpd: PM domait to power off.
325 * Queue up the execution of pm_genpd_poweroff() unless it's already been done
328 void genpd_queue_power_off_work(struct generic_pm_domain *genpd)
330 if (!work_pending(&genpd->power_off_work))
331 queue_work(pm_wq, &genpd->power_off_work);
335 * pm_genpd_poweroff - Remove power from a given PM domain.
336 * @genpd: PM domain to power down.
338 * If all of the @genpd's devices have been suspended and all of its subdomains
339 * have been powered down, run the runtime suspend callbacks provided by all of
340 * the @genpd's devices' drivers and remove power from @genpd.
342 static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
343 __releases(&genpd->lock) __acquires(&genpd->lock)
345 struct pm_domain_data *pdd;
346 struct gpd_link *link;
347 unsigned int not_suspended;
352 * Do not try to power off the domain in the following situations:
353 * (1) The domain is already in the "power off" state.
354 * (2) The domain is waiting for its master to power up.
355 * (3) One of the domain's devices is being resumed right now.
356 * (4) System suspend is in progress.
358 if (genpd->status == GPD_STATE_POWER_OFF
359 || genpd->status == GPD_STATE_WAIT_MASTER
360 || genpd->resume_count > 0 || genpd->prepared_count > 0)
363 if (atomic_read(&genpd->sd_count) > 0)
367 list_for_each_entry(pdd, &genpd->dev_list, list_node)
368 if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev)
369 || pdd->dev->power.irq_safe || to_gpd_data(pdd)->always_on))
372 if (not_suspended > genpd->in_progress)
375 if (genpd->poweroff_task) {
377 * Another instance of pm_genpd_poweroff() is executing
378 * callbacks, so tell it to start over and return.
380 genpd->status = GPD_STATE_REPEAT;
384 if (genpd->gov && genpd->gov->power_down_ok) {
385 if (!genpd->gov->power_down_ok(&genpd->domain))
389 genpd->status = GPD_STATE_BUSY;
390 genpd->poweroff_task = current;
392 list_for_each_entry_reverse(pdd, &genpd->dev_list, list_node) {
393 ret = atomic_read(&genpd->sd_count) == 0 ?
394 __pm_genpd_save_device(pdd, genpd) : -EBUSY;
396 if (genpd_abort_poweroff(genpd))
400 genpd_set_active(genpd);
404 if (genpd->status == GPD_STATE_REPEAT) {
405 genpd->poweroff_task = NULL;
410 if (genpd->power_off) {
414 if (atomic_read(&genpd->sd_count) > 0) {
419 time_start = ktime_get();
422 * If sd_count > 0 at this point, one of the subdomains hasn't
423 * managed to call pm_genpd_poweron() for the master yet after
424 * incrementing it. In that case pm_genpd_poweron() will wait
425 * for us to drop the lock, so we can call .power_off() and let
426 * the pm_genpd_poweron() restore power for us (this shouldn't
427 * happen very often).
429 ret = genpd->power_off(genpd);
431 genpd_set_active(genpd);
435 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
436 if (elapsed_ns > genpd->power_off_latency_ns) {
437 genpd->power_off_latency_ns = elapsed_ns;
439 pr_warning("%s: Power-off latency exceeded, "
440 "new value %lld ns\n", genpd->name,
445 genpd->status = GPD_STATE_POWER_OFF;
446 genpd->power_off_time = ktime_get();
448 /* Update PM QoS information for devices in the domain. */
449 list_for_each_entry_reverse(pdd, &genpd->dev_list, list_node) {
450 struct gpd_timing_data *td = &to_gpd_data(pdd)->td;
452 pm_runtime_update_max_time_suspended(pdd->dev,
453 td->start_latency_ns +
454 td->restore_state_latency_ns +
455 genpd->power_on_latency_ns);
458 list_for_each_entry(link, &genpd->slave_links, slave_node) {
459 genpd_sd_counter_dec(link->master);
460 genpd_queue_power_off_work(link->master);
464 genpd->poweroff_task = NULL;
465 wake_up_all(&genpd->status_wait_queue);
470 * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0.
471 * @work: Work structure used for scheduling the execution of this function.
473 static void genpd_power_off_work_fn(struct work_struct *work)
475 struct generic_pm_domain *genpd;
477 genpd = container_of(work, struct generic_pm_domain, power_off_work);
479 genpd_acquire_lock(genpd);
480 pm_genpd_poweroff(genpd);
481 genpd_release_lock(genpd);
485 * pm_genpd_runtime_suspend - Suspend a device belonging to I/O PM domain.
486 * @dev: Device to suspend.
488 * Carry out a runtime suspend of a device under the assumption that its
489 * pm_domain field points to the domain member of an object of type
490 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
492 static int pm_genpd_runtime_suspend(struct device *dev)
494 struct generic_pm_domain *genpd;
495 bool (*stop_ok)(struct device *__dev);
498 dev_dbg(dev, "%s()\n", __func__);
500 genpd = dev_to_genpd(dev);
504 might_sleep_if(!genpd->dev_irq_safe);
506 if (dev_gpd_data(dev)->always_on)
509 dev_gpd_data(dev)->td.effective_constraint_ns = -1;
510 stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL;
511 if (stop_ok && !stop_ok(dev))
514 ret = genpd_stop_dev(genpd, dev);
518 pm_runtime_update_max_time_suspended(dev,
519 dev_gpd_data(dev)->td.start_latency_ns);
522 * If power.irq_safe is set, this routine will be run with interrupts
523 * off, so it can't use mutexes.
525 if (dev->power.irq_safe)
528 mutex_lock(&genpd->lock);
529 genpd->in_progress++;
530 pm_genpd_poweroff(genpd);
531 genpd->in_progress--;
532 mutex_unlock(&genpd->lock);
538 * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain.
539 * @dev: Device to resume.
541 * Carry out a runtime resume of a device under the assumption that its
542 * pm_domain field points to the domain member of an object of type
543 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
545 static int pm_genpd_runtime_resume(struct device *dev)
547 struct generic_pm_domain *genpd;
551 dev_dbg(dev, "%s()\n", __func__);
553 genpd = dev_to_genpd(dev);
557 might_sleep_if(!genpd->dev_irq_safe);
559 /* If power.irq_safe, the PM domain is never powered off. */
560 if (dev->power.irq_safe)
563 mutex_lock(&genpd->lock);
564 ret = __pm_genpd_poweron(genpd);
566 mutex_unlock(&genpd->lock);
569 genpd->status = GPD_STATE_BUSY;
570 genpd->resume_count++;
572 prepare_to_wait(&genpd->status_wait_queue, &wait,
573 TASK_UNINTERRUPTIBLE);
575 * If current is the powering off task, we have been called
576 * reentrantly from one of the device callbacks, so we should
579 if (!genpd->poweroff_task || genpd->poweroff_task == current)
581 mutex_unlock(&genpd->lock);
585 mutex_lock(&genpd->lock);
587 finish_wait(&genpd->status_wait_queue, &wait);
588 __pm_genpd_restore_device(dev->power.subsys_data->domain_data, genpd);
589 genpd->resume_count--;
590 genpd_set_active(genpd);
591 wake_up_all(&genpd->status_wait_queue);
592 mutex_unlock(&genpd->lock);
595 genpd_start_dev(genpd, dev);
601 * pm_genpd_poweroff_unused - Power off all PM domains with no devices in use.
603 void pm_genpd_poweroff_unused(void)
605 struct generic_pm_domain *genpd;
607 mutex_lock(&gpd_list_lock);
609 list_for_each_entry(genpd, &gpd_list, gpd_list_node)
610 genpd_queue_power_off_work(genpd);
612 mutex_unlock(&gpd_list_lock);
617 static inline void genpd_power_off_work_fn(struct work_struct *work) {}
619 #define pm_genpd_runtime_suspend NULL
620 #define pm_genpd_runtime_resume NULL
622 #endif /* CONFIG_PM_RUNTIME */
624 #ifdef CONFIG_PM_SLEEP
626 static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd,
629 return GENPD_DEV_CALLBACK(genpd, bool, active_wakeup, dev);
632 static int genpd_suspend_dev(struct generic_pm_domain *genpd, struct device *dev)
634 return GENPD_DEV_CALLBACK(genpd, int, suspend, dev);
637 static int genpd_suspend_late(struct generic_pm_domain *genpd, struct device *dev)
639 return GENPD_DEV_CALLBACK(genpd, int, suspend_late, dev);
642 static int genpd_resume_early(struct generic_pm_domain *genpd, struct device *dev)
644 return GENPD_DEV_CALLBACK(genpd, int, resume_early, dev);
647 static int genpd_resume_dev(struct generic_pm_domain *genpd, struct device *dev)
649 return GENPD_DEV_CALLBACK(genpd, int, resume, dev);
652 static int genpd_freeze_dev(struct generic_pm_domain *genpd, struct device *dev)
654 return GENPD_DEV_CALLBACK(genpd, int, freeze, dev);
657 static int genpd_freeze_late(struct generic_pm_domain *genpd, struct device *dev)
659 return GENPD_DEV_CALLBACK(genpd, int, freeze_late, dev);
662 static int genpd_thaw_early(struct generic_pm_domain *genpd, struct device *dev)
664 return GENPD_DEV_CALLBACK(genpd, int, thaw_early, dev);
667 static int genpd_thaw_dev(struct generic_pm_domain *genpd, struct device *dev)
669 return GENPD_DEV_CALLBACK(genpd, int, thaw, dev);
673 * pm_genpd_sync_poweroff - Synchronously power off a PM domain and its masters.
674 * @genpd: PM domain to power off, if possible.
676 * Check if the given PM domain can be powered off (during system suspend or
677 * hibernation) and do that if so. Also, in that case propagate to its masters.
679 * This function is only called in "noirq" stages of system power transitions,
680 * so it need not acquire locks (all of the "noirq" callbacks are executed
681 * sequentially, so it is guaranteed that it will never run twice in parallel).
683 static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd)
685 struct gpd_link *link;
687 if (genpd->status == GPD_STATE_POWER_OFF)
690 if (genpd->suspended_count != genpd->device_count
691 || atomic_read(&genpd->sd_count) > 0)
694 if (genpd->power_off)
695 genpd->power_off(genpd);
697 genpd->status = GPD_STATE_POWER_OFF;
699 list_for_each_entry(link, &genpd->slave_links, slave_node) {
700 genpd_sd_counter_dec(link->master);
701 pm_genpd_sync_poweroff(link->master);
706 * resume_needed - Check whether to resume a device before system suspend.
707 * @dev: Device to check.
708 * @genpd: PM domain the device belongs to.
710 * There are two cases in which a device that can wake up the system from sleep
711 * states should be resumed by pm_genpd_prepare(): (1) if the device is enabled
712 * to wake up the system and it has to remain active for this purpose while the
713 * system is in the sleep state and (2) if the device is not enabled to wake up
714 * the system from sleep states and it generally doesn't generate wakeup signals
715 * by itself (those signals are generated on its behalf by other parts of the
716 * system). In the latter case it may be necessary to reconfigure the device's
717 * wakeup settings during system suspend, because it may have been set up to
718 * signal remote wakeup from the system's working state as needed by runtime PM.
719 * Return 'true' in either of the above cases.
721 static bool resume_needed(struct device *dev, struct generic_pm_domain *genpd)
725 if (!device_can_wakeup(dev))
728 active_wakeup = genpd_dev_active_wakeup(genpd, dev);
729 return device_may_wakeup(dev) ? active_wakeup : !active_wakeup;
733 * pm_genpd_prepare - Start power transition of a device in a PM domain.
734 * @dev: Device to start the transition of.
736 * Start a power transition of a device (during a system-wide power transition)
737 * under the assumption that its pm_domain field points to the domain member of
738 * an object of type struct generic_pm_domain representing a PM domain
739 * consisting of I/O devices.
741 static int pm_genpd_prepare(struct device *dev)
743 struct generic_pm_domain *genpd;
746 dev_dbg(dev, "%s()\n", __func__);
748 genpd = dev_to_genpd(dev);
753 * If a wakeup request is pending for the device, it should be woken up
754 * at this point and a system wakeup event should be reported if it's
755 * set up to wake up the system from sleep states.
757 pm_runtime_get_noresume(dev);
758 if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
759 pm_wakeup_event(dev, 0);
761 if (pm_wakeup_pending()) {
762 pm_runtime_put_sync(dev);
766 if (resume_needed(dev, genpd))
767 pm_runtime_resume(dev);
769 genpd_acquire_lock(genpd);
771 if (genpd->prepared_count++ == 0) {
772 genpd->suspended_count = 0;
773 genpd->suspend_power_off = genpd->status == GPD_STATE_POWER_OFF;
776 genpd_release_lock(genpd);
778 if (genpd->suspend_power_off) {
779 pm_runtime_put_noidle(dev);
784 * The PM domain must be in the GPD_STATE_ACTIVE state at this point,
785 * so pm_genpd_poweron() will return immediately, but if the device
786 * is suspended (e.g. it's been stopped by genpd_stop_dev()), we need
787 * to make it operational.
789 pm_runtime_resume(dev);
790 __pm_runtime_disable(dev, false);
792 ret = pm_generic_prepare(dev);
794 mutex_lock(&genpd->lock);
796 if (--genpd->prepared_count == 0)
797 genpd->suspend_power_off = false;
799 mutex_unlock(&genpd->lock);
800 pm_runtime_enable(dev);
803 pm_runtime_put_sync(dev);
808 * pm_genpd_suspend - Suspend a device belonging to an I/O PM domain.
809 * @dev: Device to suspend.
811 * Suspend a device under the assumption that its pm_domain field points to the
812 * domain member of an object of type struct generic_pm_domain representing
813 * a PM domain consisting of I/O devices.
815 static int pm_genpd_suspend(struct device *dev)
817 struct generic_pm_domain *genpd;
819 dev_dbg(dev, "%s()\n", __func__);
821 genpd = dev_to_genpd(dev);
825 return genpd->suspend_power_off ? 0 : genpd_suspend_dev(genpd, dev);
829 * pm_genpd_suspend_late - Late suspend of a device from an I/O PM domain.
830 * @dev: Device to suspend.
832 * Carry out a late suspend of a device under the assumption that its
833 * pm_domain field points to the domain member of an object of type
834 * struct generic_pm_domain representing a PM domain consisting of I/O devices.
836 static int pm_genpd_suspend_late(struct device *dev)
838 struct generic_pm_domain *genpd;
840 dev_dbg(dev, "%s()\n", __func__);
842 genpd = dev_to_genpd(dev);
846 return genpd->suspend_power_off ? 0 : genpd_suspend_late(genpd, dev);
850 * pm_genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain.
851 * @dev: Device to suspend.
853 * Stop the device and remove power from the domain if all devices in it have
856 static int pm_genpd_suspend_noirq(struct device *dev)
858 struct generic_pm_domain *genpd;
860 dev_dbg(dev, "%s()\n", __func__);
862 genpd = dev_to_genpd(dev);
866 if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on
867 || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev)))
870 genpd_stop_dev(genpd, dev);
873 * Since all of the "noirq" callbacks are executed sequentially, it is
874 * guaranteed that this function will never run twice in parallel for
875 * the same PM domain, so it is not necessary to use locking here.
877 genpd->suspended_count++;
878 pm_genpd_sync_poweroff(genpd);
884 * pm_genpd_resume_noirq - Start of resume of device in an I/O PM domain.
885 * @dev: Device to resume.
887 * Restore power to the device's PM domain, if necessary, and start the device.
889 static int pm_genpd_resume_noirq(struct device *dev)
891 struct generic_pm_domain *genpd;
893 dev_dbg(dev, "%s()\n", __func__);
895 genpd = dev_to_genpd(dev);
899 if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on
900 || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev)))
904 * Since all of the "noirq" callbacks are executed sequentially, it is
905 * guaranteed that this function will never run twice in parallel for
906 * the same PM domain, so it is not necessary to use locking here.
908 pm_genpd_poweron(genpd);
909 genpd->suspended_count--;
911 return genpd_start_dev(genpd, dev);
915 * pm_genpd_resume_early - Early resume of a device in an I/O PM domain.
916 * @dev: Device to resume.
918 * Carry out an early resume of a device under the assumption that its
919 * pm_domain field points to the domain member of an object of type
920 * struct generic_pm_domain representing a power domain consisting of I/O
923 static int pm_genpd_resume_early(struct device *dev)
925 struct generic_pm_domain *genpd;
927 dev_dbg(dev, "%s()\n", __func__);
929 genpd = dev_to_genpd(dev);
933 return genpd->suspend_power_off ? 0 : genpd_resume_early(genpd, dev);
937 * pm_genpd_resume - Resume of device in an I/O PM domain.
938 * @dev: Device to resume.
940 * Resume a device under the assumption that its pm_domain field points to the
941 * domain member of an object of type struct generic_pm_domain representing
942 * a power domain consisting of I/O devices.
944 static int pm_genpd_resume(struct device *dev)
946 struct generic_pm_domain *genpd;
948 dev_dbg(dev, "%s()\n", __func__);
950 genpd = dev_to_genpd(dev);
954 return genpd->suspend_power_off ? 0 : genpd_resume_dev(genpd, dev);
958 * pm_genpd_freeze - Freezing a device in an I/O PM domain.
959 * @dev: Device to freeze.
961 * Freeze a device under the assumption that its pm_domain field points to the
962 * domain member of an object of type struct generic_pm_domain representing
963 * a power domain consisting of I/O devices.
965 static int pm_genpd_freeze(struct device *dev)
967 struct generic_pm_domain *genpd;
969 dev_dbg(dev, "%s()\n", __func__);
971 genpd = dev_to_genpd(dev);
975 return genpd->suspend_power_off ? 0 : genpd_freeze_dev(genpd, dev);
979 * pm_genpd_freeze_late - Late freeze of a device in an I/O PM domain.
980 * @dev: Device to freeze.
982 * Carry out a late freeze of a device under the assumption that its
983 * pm_domain field points to the domain member of an object of type
984 * struct generic_pm_domain representing a power domain consisting of I/O
987 static int pm_genpd_freeze_late(struct device *dev)
989 struct generic_pm_domain *genpd;
991 dev_dbg(dev, "%s()\n", __func__);
993 genpd = dev_to_genpd(dev);
997 return genpd->suspend_power_off ? 0 : genpd_freeze_late(genpd, dev);
1001 * pm_genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain.
1002 * @dev: Device to freeze.
1004 * Carry out a late freeze of a device under the assumption that its
1005 * pm_domain field points to the domain member of an object of type
1006 * struct generic_pm_domain representing a power domain consisting of I/O
1009 static int pm_genpd_freeze_noirq(struct device *dev)
1011 struct generic_pm_domain *genpd;
1013 dev_dbg(dev, "%s()\n", __func__);
1015 genpd = dev_to_genpd(dev);
1019 return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ?
1020 0 : genpd_stop_dev(genpd, dev);
1024 * pm_genpd_thaw_noirq - Early thaw of device in an I/O PM domain.
1025 * @dev: Device to thaw.
1027 * Start the device, unless power has been removed from the domain already
1028 * before the system transition.
1030 static int pm_genpd_thaw_noirq(struct device *dev)
1032 struct generic_pm_domain *genpd;
1034 dev_dbg(dev, "%s()\n", __func__);
1036 genpd = dev_to_genpd(dev);
1040 return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ?
1041 0 : genpd_start_dev(genpd, dev);
1045 * pm_genpd_thaw_early - Early thaw of device in an I/O PM domain.
1046 * @dev: Device to thaw.
1048 * Carry out an early thaw of a device under the assumption that its
1049 * pm_domain field points to the domain member of an object of type
1050 * struct generic_pm_domain representing a power domain consisting of I/O
1053 static int pm_genpd_thaw_early(struct device *dev)
1055 struct generic_pm_domain *genpd;
1057 dev_dbg(dev, "%s()\n", __func__);
1059 genpd = dev_to_genpd(dev);
1063 return genpd->suspend_power_off ? 0 : genpd_thaw_early(genpd, dev);
1067 * pm_genpd_thaw - Thaw a device belonging to an I/O power domain.
1068 * @dev: Device to thaw.
1070 * Thaw a device under the assumption that its pm_domain field points to the
1071 * domain member of an object of type struct generic_pm_domain representing
1072 * a power domain consisting of I/O devices.
1074 static int pm_genpd_thaw(struct device *dev)
1076 struct generic_pm_domain *genpd;
1078 dev_dbg(dev, "%s()\n", __func__);
1080 genpd = dev_to_genpd(dev);
1084 return genpd->suspend_power_off ? 0 : genpd_thaw_dev(genpd, dev);
1088 * pm_genpd_restore_noirq - Start of restore of device in an I/O PM domain.
1089 * @dev: Device to resume.
1091 * Make sure the domain will be in the same power state as before the
1092 * hibernation the system is resuming from and start the device if necessary.
1094 static int pm_genpd_restore_noirq(struct device *dev)
1096 struct generic_pm_domain *genpd;
1098 dev_dbg(dev, "%s()\n", __func__);
1100 genpd = dev_to_genpd(dev);
1105 * Since all of the "noirq" callbacks are executed sequentially, it is
1106 * guaranteed that this function will never run twice in parallel for
1107 * the same PM domain, so it is not necessary to use locking here.
1109 * At this point suspended_count == 0 means we are being run for the
1110 * first time for the given domain in the present cycle.
1112 if (genpd->suspended_count++ == 0) {
1114 * The boot kernel might put the domain into arbitrary state,
1115 * so make it appear as powered off to pm_genpd_poweron(), so
1116 * that it tries to power it on in case it was really off.
1118 genpd->status = GPD_STATE_POWER_OFF;
1119 if (genpd->suspend_power_off) {
1121 * If the domain was off before the hibernation, make
1122 * sure it will be off going forward.
1124 if (genpd->power_off)
1125 genpd->power_off(genpd);
1131 if (genpd->suspend_power_off)
1134 pm_genpd_poweron(genpd);
1136 return dev_gpd_data(dev)->always_on ? 0 : genpd_start_dev(genpd, dev);
1140 * pm_genpd_complete - Complete power transition of a device in a power domain.
1141 * @dev: Device to complete the transition of.
1143 * Complete a power transition of a device (during a system-wide power
1144 * transition) under the assumption that its pm_domain field points to the
1145 * domain member of an object of type struct generic_pm_domain representing
1146 * a power domain consisting of I/O devices.
1148 static void pm_genpd_complete(struct device *dev)
1150 struct generic_pm_domain *genpd;
1153 dev_dbg(dev, "%s()\n", __func__);
1155 genpd = dev_to_genpd(dev);
1159 mutex_lock(&genpd->lock);
1161 run_complete = !genpd->suspend_power_off;
1162 if (--genpd->prepared_count == 0)
1163 genpd->suspend_power_off = false;
1165 mutex_unlock(&genpd->lock);
1168 pm_generic_complete(dev);
1169 pm_runtime_set_active(dev);
1170 pm_runtime_enable(dev);
1171 pm_runtime_idle(dev);
1177 #define pm_genpd_prepare NULL
1178 #define pm_genpd_suspend NULL
1179 #define pm_genpd_suspend_late NULL
1180 #define pm_genpd_suspend_noirq NULL
1181 #define pm_genpd_resume_early NULL
1182 #define pm_genpd_resume_noirq NULL
1183 #define pm_genpd_resume NULL
1184 #define pm_genpd_freeze NULL
1185 #define pm_genpd_freeze_late NULL
1186 #define pm_genpd_freeze_noirq NULL
1187 #define pm_genpd_thaw_early NULL
1188 #define pm_genpd_thaw_noirq NULL
1189 #define pm_genpd_thaw NULL
1190 #define pm_genpd_restore_noirq NULL
1191 #define pm_genpd_complete NULL
1193 #endif /* CONFIG_PM_SLEEP */
1196 * __pm_genpd_add_device - Add a device to an I/O PM domain.
1197 * @genpd: PM domain to add the device to.
1198 * @dev: Device to be added.
1199 * @td: Set of PM QoS timing parameters to attach to the device.
1201 int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1202 struct gpd_timing_data *td)
1204 struct generic_pm_domain_data *gpd_data;
1205 struct pm_domain_data *pdd;
1208 dev_dbg(dev, "%s()\n", __func__);
1210 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1213 genpd_acquire_lock(genpd);
1215 if (genpd->status == GPD_STATE_POWER_OFF) {
1220 if (genpd->prepared_count > 0) {
1225 list_for_each_entry(pdd, &genpd->dev_list, list_node)
1226 if (pdd->dev == dev) {
1231 gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL);
1237 genpd->device_count++;
1239 dev->pm_domain = &genpd->domain;
1240 dev_pm_get_subsys_data(dev);
1241 dev->power.subsys_data->domain_data = &gpd_data->base;
1242 gpd_data->base.dev = dev;
1243 gpd_data->need_restore = false;
1244 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1249 genpd_release_lock(genpd);
1255 * __pm_genpd_of_add_device - Add a device to an I/O PM domain.
1256 * @genpd_node: Device tree node pointer representing a PM domain to which the
1257 * the device is added to.
1258 * @dev: Device to be added.
1259 * @td: Set of PM QoS timing parameters to attach to the device.
1261 int __pm_genpd_of_add_device(struct device_node *genpd_node, struct device *dev,
1262 struct gpd_timing_data *td)
1264 struct generic_pm_domain *genpd = NULL, *gpd;
1266 dev_dbg(dev, "%s()\n", __func__);
1268 if (IS_ERR_OR_NULL(genpd_node) || IS_ERR_OR_NULL(dev))
1271 mutex_lock(&gpd_list_lock);
1272 list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
1273 if (gpd->of_node == genpd_node) {
1278 mutex_unlock(&gpd_list_lock);
1283 return __pm_genpd_add_device(genpd, dev, td);
1287 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
1288 * @genpd: PM domain to remove the device from.
1289 * @dev: Device to be removed.
1291 int pm_genpd_remove_device(struct generic_pm_domain *genpd,
1294 struct pm_domain_data *pdd;
1297 dev_dbg(dev, "%s()\n", __func__);
1299 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1302 genpd_acquire_lock(genpd);
1304 if (genpd->prepared_count > 0) {
1309 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
1310 if (pdd->dev != dev)
1313 list_del_init(&pdd->list_node);
1315 dev_pm_put_subsys_data(dev);
1316 dev->pm_domain = NULL;
1317 kfree(to_gpd_data(pdd));
1319 genpd->device_count--;
1326 genpd_release_lock(genpd);
1332 * pm_genpd_dev_always_on - Set/unset the "always on" flag for a given device.
1333 * @dev: Device to set/unset the flag for.
1334 * @val: The new value of the device's "always on" flag.
1336 void pm_genpd_dev_always_on(struct device *dev, bool val)
1338 struct pm_subsys_data *psd;
1339 unsigned long flags;
1341 spin_lock_irqsave(&dev->power.lock, flags);
1343 psd = dev_to_psd(dev);
1344 if (psd && psd->domain_data)
1345 to_gpd_data(psd->domain_data)->always_on = val;
1347 spin_unlock_irqrestore(&dev->power.lock, flags);
1349 EXPORT_SYMBOL_GPL(pm_genpd_dev_always_on);
1352 * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain.
1353 * @genpd: Master PM domain to add the subdomain to.
1354 * @subdomain: Subdomain to be added.
1356 int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
1357 struct generic_pm_domain *subdomain)
1359 struct gpd_link *link;
1362 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
1366 genpd_acquire_lock(genpd);
1367 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
1369 if (subdomain->status != GPD_STATE_POWER_OFF
1370 && subdomain->status != GPD_STATE_ACTIVE) {
1371 mutex_unlock(&subdomain->lock);
1372 genpd_release_lock(genpd);
1376 if (genpd->status == GPD_STATE_POWER_OFF
1377 && subdomain->status != GPD_STATE_POWER_OFF) {
1382 list_for_each_entry(link, &genpd->slave_links, slave_node) {
1383 if (link->slave == subdomain && link->master == genpd) {
1389 link = kzalloc(sizeof(*link), GFP_KERNEL);
1394 link->master = genpd;
1395 list_add_tail(&link->master_node, &genpd->master_links);
1396 link->slave = subdomain;
1397 list_add_tail(&link->slave_node, &subdomain->slave_links);
1398 if (subdomain->status != GPD_STATE_POWER_OFF)
1399 genpd_sd_counter_inc(genpd);
1402 mutex_unlock(&subdomain->lock);
1403 genpd_release_lock(genpd);
1409 * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain.
1410 * @genpd: Master PM domain to remove the subdomain from.
1411 * @subdomain: Subdomain to be removed.
1413 int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
1414 struct generic_pm_domain *subdomain)
1416 struct gpd_link *link;
1419 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain))
1423 genpd_acquire_lock(genpd);
1425 list_for_each_entry(link, &genpd->master_links, master_node) {
1426 if (link->slave != subdomain)
1429 mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING);
1431 if (subdomain->status != GPD_STATE_POWER_OFF
1432 && subdomain->status != GPD_STATE_ACTIVE) {
1433 mutex_unlock(&subdomain->lock);
1434 genpd_release_lock(genpd);
1438 list_del(&link->master_node);
1439 list_del(&link->slave_node);
1441 if (subdomain->status != GPD_STATE_POWER_OFF)
1442 genpd_sd_counter_dec(genpd);
1444 mutex_unlock(&subdomain->lock);
1450 genpd_release_lock(genpd);
1456 * pm_genpd_add_callbacks - Add PM domain callbacks to a given device.
1457 * @dev: Device to add the callbacks to.
1458 * @ops: Set of callbacks to add.
1459 * @td: Timing data to add to the device along with the callbacks (optional).
1461 int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops,
1462 struct gpd_timing_data *td)
1464 struct pm_domain_data *pdd;
1467 if (!(dev && dev->power.subsys_data && ops))
1470 pm_runtime_disable(dev);
1473 pdd = dev->power.subsys_data->domain_data;
1475 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1477 gpd_data->ops = *ops;
1485 pm_runtime_enable(dev);
1489 EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks);
1492 * __pm_genpd_remove_callbacks - Remove PM domain callbacks from a given device.
1493 * @dev: Device to remove the callbacks from.
1494 * @clear_td: If set, clear the device's timing data too.
1496 int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
1498 struct pm_domain_data *pdd;
1501 if (!(dev && dev->power.subsys_data))
1504 pm_runtime_disable(dev);
1507 pdd = dev->power.subsys_data->domain_data;
1509 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1511 gpd_data->ops = (struct gpd_dev_ops){ 0 };
1513 gpd_data->td = (struct gpd_timing_data){ 0 };
1519 pm_runtime_enable(dev);
1523 EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks);
1525 /* Default device callbacks for generic PM domains. */
1528 * pm_genpd_default_save_state - Default "save device state" for PM domians.
1529 * @dev: Device to handle.
1531 static int pm_genpd_default_save_state(struct device *dev)
1533 int (*cb)(struct device *__dev);
1534 struct device_driver *drv = dev->driver;
1536 cb = dev_gpd_data(dev)->ops.save_state;
1540 if (drv && drv->pm && drv->pm->runtime_suspend)
1541 return drv->pm->runtime_suspend(dev);
1547 * pm_genpd_default_restore_state - Default PM domians "restore device state".
1548 * @dev: Device to handle.
1550 static int pm_genpd_default_restore_state(struct device *dev)
1552 int (*cb)(struct device *__dev);
1553 struct device_driver *drv = dev->driver;
1555 cb = dev_gpd_data(dev)->ops.restore_state;
1559 if (drv && drv->pm && drv->pm->runtime_resume)
1560 return drv->pm->runtime_resume(dev);
1565 #ifdef CONFIG_PM_SLEEP
1568 * pm_genpd_default_suspend - Default "device suspend" for PM domians.
1569 * @dev: Device to handle.
1571 static int pm_genpd_default_suspend(struct device *dev)
1573 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.suspend;
1575 return cb ? cb(dev) : pm_generic_suspend(dev);
1579 * pm_genpd_default_suspend_late - Default "late device suspend" for PM domians.
1580 * @dev: Device to handle.
1582 static int pm_genpd_default_suspend_late(struct device *dev)
1584 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.suspend_late;
1586 return cb ? cb(dev) : pm_generic_suspend_late(dev);
1590 * pm_genpd_default_resume_early - Default "early device resume" for PM domians.
1591 * @dev: Device to handle.
1593 static int pm_genpd_default_resume_early(struct device *dev)
1595 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.resume_early;
1597 return cb ? cb(dev) : pm_generic_resume_early(dev);
1601 * pm_genpd_default_resume - Default "device resume" for PM domians.
1602 * @dev: Device to handle.
1604 static int pm_genpd_default_resume(struct device *dev)
1606 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.resume;
1608 return cb ? cb(dev) : pm_generic_resume(dev);
1612 * pm_genpd_default_freeze - Default "device freeze" for PM domians.
1613 * @dev: Device to handle.
1615 static int pm_genpd_default_freeze(struct device *dev)
1617 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.freeze;
1619 return cb ? cb(dev) : pm_generic_freeze(dev);
1623 * pm_genpd_default_freeze_late - Default "late device freeze" for PM domians.
1624 * @dev: Device to handle.
1626 static int pm_genpd_default_freeze_late(struct device *dev)
1628 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.freeze_late;
1630 return cb ? cb(dev) : pm_generic_freeze_late(dev);
1634 * pm_genpd_default_thaw_early - Default "early device thaw" for PM domians.
1635 * @dev: Device to handle.
1637 static int pm_genpd_default_thaw_early(struct device *dev)
1639 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.thaw_early;
1641 return cb ? cb(dev) : pm_generic_thaw_early(dev);
1645 * pm_genpd_default_thaw - Default "device thaw" for PM domians.
1646 * @dev: Device to handle.
1648 static int pm_genpd_default_thaw(struct device *dev)
1650 int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.thaw;
1652 return cb ? cb(dev) : pm_generic_thaw(dev);
1655 #else /* !CONFIG_PM_SLEEP */
1657 #define pm_genpd_default_suspend NULL
1658 #define pm_genpd_default_suspend_late NULL
1659 #define pm_genpd_default_resume_early NULL
1660 #define pm_genpd_default_resume NULL
1661 #define pm_genpd_default_freeze NULL
1662 #define pm_genpd_default_freeze_late NULL
1663 #define pm_genpd_default_thaw_early NULL
1664 #define pm_genpd_default_thaw NULL
1666 #endif /* !CONFIG_PM_SLEEP */
1669 * pm_genpd_init - Initialize a generic I/O PM domain object.
1670 * @genpd: PM domain object to initialize.
1671 * @gov: PM domain governor to associate with the domain (may be NULL).
1672 * @is_off: Initial value of the domain's power_is_off field.
1674 void pm_genpd_init(struct generic_pm_domain *genpd,
1675 struct dev_power_governor *gov, bool is_off)
1677 if (IS_ERR_OR_NULL(genpd))
1680 INIT_LIST_HEAD(&genpd->master_links);
1681 INIT_LIST_HEAD(&genpd->slave_links);
1682 INIT_LIST_HEAD(&genpd->dev_list);
1683 mutex_init(&genpd->lock);
1685 INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
1686 genpd->in_progress = 0;
1687 atomic_set(&genpd->sd_count, 0);
1688 genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE;
1689 init_waitqueue_head(&genpd->status_wait_queue);
1690 genpd->poweroff_task = NULL;
1691 genpd->resume_count = 0;
1692 genpd->device_count = 0;
1693 genpd->max_off_time_ns = -1;
1694 genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
1695 genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;
1696 genpd->domain.ops.runtime_idle = pm_generic_runtime_idle;
1697 genpd->domain.ops.prepare = pm_genpd_prepare;
1698 genpd->domain.ops.suspend = pm_genpd_suspend;
1699 genpd->domain.ops.suspend_late = pm_genpd_suspend_late;
1700 genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq;
1701 genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq;
1702 genpd->domain.ops.resume_early = pm_genpd_resume_early;
1703 genpd->domain.ops.resume = pm_genpd_resume;
1704 genpd->domain.ops.freeze = pm_genpd_freeze;
1705 genpd->domain.ops.freeze_late = pm_genpd_freeze_late;
1706 genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq;
1707 genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq;
1708 genpd->domain.ops.thaw_early = pm_genpd_thaw_early;
1709 genpd->domain.ops.thaw = pm_genpd_thaw;
1710 genpd->domain.ops.poweroff = pm_genpd_suspend;
1711 genpd->domain.ops.poweroff_late = pm_genpd_suspend_late;
1712 genpd->domain.ops.poweroff_noirq = pm_genpd_suspend_noirq;
1713 genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq;
1714 genpd->domain.ops.restore_early = pm_genpd_resume_early;
1715 genpd->domain.ops.restore = pm_genpd_resume;
1716 genpd->domain.ops.complete = pm_genpd_complete;
1717 genpd->dev_ops.save_state = pm_genpd_default_save_state;
1718 genpd->dev_ops.restore_state = pm_genpd_default_restore_state;
1719 genpd->dev_ops.suspend = pm_genpd_default_suspend;
1720 genpd->dev_ops.suspend_late = pm_genpd_default_suspend_late;
1721 genpd->dev_ops.resume_early = pm_genpd_default_resume_early;
1722 genpd->dev_ops.resume = pm_genpd_default_resume;
1723 genpd->dev_ops.freeze = pm_genpd_default_freeze;
1724 genpd->dev_ops.freeze_late = pm_genpd_default_freeze_late;
1725 genpd->dev_ops.thaw_early = pm_genpd_default_thaw_early;
1726 genpd->dev_ops.thaw = pm_genpd_default_thaw;
1727 mutex_lock(&gpd_list_lock);
1728 list_add(&genpd->gpd_list_node, &gpd_list);
1729 mutex_unlock(&gpd_list_lock);