Skip to content

Commit adf0949

Browse files
rjwysockigregkh
authored andcommitted
PM: Simplify the new suspend/hibernation framework for devices
PM: Simplify the new suspend/hibernation framework for devices Following the discussion at the Kernel Summit, simplify the new device PM framework by merging 'struct pm_ops' and 'struct pm_ext_ops' and removing pointers to 'struct pm_ext_ops' from 'struct platform_driver' and 'struct pci_driver'. After this change, the suspend/hibernation callbacks will only reside in 'struct device_driver' as well as at the bus type/ device class/device type level. Accordingly, PCI and platform device drivers are now expected to put their suspend/hibernation callbacks into the 'struct device_driver' embedded in 'struct pci_driver' or 'struct platform_driver', respectively. Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Pavel Machek <[email protected]> Cc: Jesse Barnes <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 238c6d5 commit adf0949

File tree

8 files changed

+119
-151
lines changed

8 files changed

+119
-151
lines changed

drivers/base/platform.c

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,6 @@ int platform_driver_register(struct platform_driver *drv)
503503
drv->driver.suspend = platform_drv_suspend;
504504
if (drv->resume)
505505
drv->driver.resume = platform_drv_resume;
506-
if (drv->pm)
507-
drv->driver.pm = &drv->pm->base;
508506
return driver_register(&drv->driver);
509507
}
510508
EXPORT_SYMBOL_GPL(platform_driver_register);
@@ -686,7 +684,10 @@ static int platform_pm_suspend(struct device *dev)
686684
struct device_driver *drv = dev->driver;
687685
int ret = 0;
688686

689-
if (drv && drv->pm) {
687+
if (!drv)
688+
return 0;
689+
690+
if (drv->pm) {
690691
if (drv->pm->suspend)
691692
ret = drv->pm->suspend(dev);
692693
} else {
@@ -698,16 +699,15 @@ static int platform_pm_suspend(struct device *dev)
698699

699700
static int platform_pm_suspend_noirq(struct device *dev)
700701
{
701-
struct platform_driver *pdrv;
702+
struct device_driver *drv = dev->driver;
702703
int ret = 0;
703704

704-
if (!dev->driver)
705+
if (!drv)
705706
return 0;
706707

707-
pdrv = to_platform_driver(dev->driver);
708-
if (pdrv->pm) {
709-
if (pdrv->pm->suspend_noirq)
710-
ret = pdrv->pm->suspend_noirq(dev);
708+
if (drv->pm) {
709+
if (drv->pm->suspend_noirq)
710+
ret = drv->pm->suspend_noirq(dev);
711711
} else {
712712
ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND);
713713
}
@@ -720,7 +720,10 @@ static int platform_pm_resume(struct device *dev)
720720
struct device_driver *drv = dev->driver;
721721
int ret = 0;
722722

723-
if (drv && drv->pm) {
723+
if (!drv)
724+
return 0;
725+
726+
if (drv->pm) {
724727
if (drv->pm->resume)
725728
ret = drv->pm->resume(dev);
726729
} else {
@@ -732,16 +735,15 @@ static int platform_pm_resume(struct device *dev)
732735

733736
static int platform_pm_resume_noirq(struct device *dev)
734737
{
735-
struct platform_driver *pdrv;
738+
struct device_driver *drv = dev->driver;
736739
int ret = 0;
737740

738-
if (!dev->driver)
741+
if (!drv)
739742
return 0;
740743

741-
pdrv = to_platform_driver(dev->driver);
742-
if (pdrv->pm) {
743-
if (pdrv->pm->resume_noirq)
744-
ret = pdrv->pm->resume_noirq(dev);
744+
if (drv->pm) {
745+
if (drv->pm->resume_noirq)
746+
ret = drv->pm->resume_noirq(dev);
745747
} else {
746748
ret = platform_legacy_resume_early(dev);
747749
}
@@ -780,16 +782,15 @@ static int platform_pm_freeze(struct device *dev)
780782

781783
static int platform_pm_freeze_noirq(struct device *dev)
782784
{
783-
struct platform_driver *pdrv;
785+
struct device_driver *drv = dev->driver;
784786
int ret = 0;
785787

786-
if (!dev->driver)
788+
if (!drv)
787789
return 0;
788790

789-
pdrv = to_platform_driver(dev->driver);
790-
if (pdrv->pm) {
791-
if (pdrv->pm->freeze_noirq)
792-
ret = pdrv->pm->freeze_noirq(dev);
791+
if (drv->pm) {
792+
if (drv->pm->freeze_noirq)
793+
ret = drv->pm->freeze_noirq(dev);
793794
} else {
794795
ret = platform_legacy_suspend_late(dev, PMSG_FREEZE);
795796
}
@@ -802,7 +803,10 @@ static int platform_pm_thaw(struct device *dev)
802803
struct device_driver *drv = dev->driver;
803804
int ret = 0;
804805

805-
if (drv && drv->pm) {
806+
if (!drv)
807+
return 0;
808+
809+
if (drv->pm) {
806810
if (drv->pm->thaw)
807811
ret = drv->pm->thaw(dev);
808812
} else {
@@ -814,16 +818,15 @@ static int platform_pm_thaw(struct device *dev)
814818

815819
static int platform_pm_thaw_noirq(struct device *dev)
816820
{
817-
struct platform_driver *pdrv;
821+
struct device_driver *drv = dev->driver;
818822
int ret = 0;
819823

820-
if (!dev->driver)
824+
if (!drv)
821825
return 0;
822826

823-
pdrv = to_platform_driver(dev->driver);
824-
if (pdrv->pm) {
825-
if (pdrv->pm->thaw_noirq)
826-
ret = pdrv->pm->thaw_noirq(dev);
827+
if (drv->pm) {
828+
if (drv->pm->thaw_noirq)
829+
ret = drv->pm->thaw_noirq(dev);
827830
} else {
828831
ret = platform_legacy_resume_early(dev);
829832
}
@@ -836,7 +839,10 @@ static int platform_pm_poweroff(struct device *dev)
836839
struct device_driver *drv = dev->driver;
837840
int ret = 0;
838841

839-
if (drv && drv->pm) {
842+
if (!drv)
843+
return 0;
844+
845+
if (drv->pm) {
840846
if (drv->pm->poweroff)
841847
ret = drv->pm->poweroff(dev);
842848
} else {
@@ -848,16 +854,15 @@ static int platform_pm_poweroff(struct device *dev)
848854

849855
static int platform_pm_poweroff_noirq(struct device *dev)
850856
{
851-
struct platform_driver *pdrv;
857+
struct device_driver *drv = dev->driver;
852858
int ret = 0;
853859

854-
if (!dev->driver)
860+
if (!drv)
855861
return 0;
856862

857-
pdrv = to_platform_driver(dev->driver);
858-
if (pdrv->pm) {
859-
if (pdrv->pm->poweroff_noirq)
860-
ret = pdrv->pm->poweroff_noirq(dev);
863+
if (drv->pm) {
864+
if (drv->pm->poweroff_noirq)
865+
ret = drv->pm->poweroff_noirq(dev);
861866
} else {
862867
ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE);
863868
}
@@ -870,7 +875,10 @@ static int platform_pm_restore(struct device *dev)
870875
struct device_driver *drv = dev->driver;
871876
int ret = 0;
872877

873-
if (drv && drv->pm) {
878+
if (!drv)
879+
return 0;
880+
881+
if (drv->pm) {
874882
if (drv->pm->restore)
875883
ret = drv->pm->restore(dev);
876884
} else {
@@ -882,16 +890,15 @@ static int platform_pm_restore(struct device *dev)
882890

883891
static int platform_pm_restore_noirq(struct device *dev)
884892
{
885-
struct platform_driver *pdrv;
893+
struct device_driver *drv = dev->driver;
886894
int ret = 0;
887895

888-
if (!dev->driver)
896+
if (!drv)
889897
return 0;
890898

891-
pdrv = to_platform_driver(dev->driver);
892-
if (pdrv->pm) {
893-
if (pdrv->pm->restore_noirq)
894-
ret = pdrv->pm->restore_noirq(dev);
899+
if (drv->pm) {
900+
if (drv->pm->restore_noirq)
901+
ret = drv->pm->restore_noirq(dev);
895902
} else {
896903
ret = platform_legacy_resume_early(dev);
897904
}
@@ -912,17 +919,15 @@ static int platform_pm_restore_noirq(struct device *dev)
912919

913920
#endif /* !CONFIG_HIBERNATION */
914921

915-
static struct pm_ext_ops platform_pm_ops = {
916-
.base = {
917-
.prepare = platform_pm_prepare,
918-
.complete = platform_pm_complete,
919-
.suspend = platform_pm_suspend,
920-
.resume = platform_pm_resume,
921-
.freeze = platform_pm_freeze,
922-
.thaw = platform_pm_thaw,
923-
.poweroff = platform_pm_poweroff,
924-
.restore = platform_pm_restore,
925-
},
922+
static struct dev_pm_ops platform_dev_pm_ops = {
923+
.prepare = platform_pm_prepare,
924+
.complete = platform_pm_complete,
925+
.suspend = platform_pm_suspend,
926+
.resume = platform_pm_resume,
927+
.freeze = platform_pm_freeze,
928+
.thaw = platform_pm_thaw,
929+
.poweroff = platform_pm_poweroff,
930+
.restore = platform_pm_restore,
926931
.suspend_noirq = platform_pm_suspend_noirq,
927932
.resume_noirq = platform_pm_resume_noirq,
928933
.freeze_noirq = platform_pm_freeze_noirq,
@@ -931,7 +936,7 @@ static struct pm_ext_ops platform_pm_ops = {
931936
.restore_noirq = platform_pm_restore_noirq,
932937
};
933938

934-
#define PLATFORM_PM_OPS_PTR &platform_pm_ops
939+
#define PLATFORM_PM_OPS_PTR (&platform_dev_pm_ops)
935940

936941
#else /* !CONFIG_PM_SLEEP */
937942

drivers/base/power/main.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ void device_pm_remove(struct device *dev)
112112
* @ops: PM operations to choose from.
113113
* @state: PM transition of the system being carried out.
114114
*/
115-
static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state)
115+
static int pm_op(struct device *dev, struct dev_pm_ops *ops,
116+
pm_message_t state)
116117
{
117118
int error = 0;
118119

@@ -174,7 +175,7 @@ static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state)
174175
* The operation is executed with interrupts disabled by the only remaining
175176
* functional CPU in the system.
176177
*/
177-
static int pm_noirq_op(struct device *dev, struct pm_ext_ops *ops,
178+
static int pm_noirq_op(struct device *dev, struct dev_pm_ops *ops,
178179
pm_message_t state)
179180
{
180181
int error = 0;
@@ -354,7 +355,7 @@ static int resume_device(struct device *dev, pm_message_t state)
354355
if (dev->bus) {
355356
if (dev->bus->pm) {
356357
pm_dev_dbg(dev, state, "");
357-
error = pm_op(dev, &dev->bus->pm->base, state);
358+
error = pm_op(dev, dev->bus->pm, state);
358359
} else if (dev->bus->resume) {
359360
pm_dev_dbg(dev, state, "legacy ");
360361
error = dev->bus->resume(dev);
@@ -451,9 +452,9 @@ static void complete_device(struct device *dev, pm_message_t state)
451452
dev->type->pm->complete(dev);
452453
}
453454

454-
if (dev->bus && dev->bus->pm && dev->bus->pm->base.complete) {
455+
if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
455456
pm_dev_dbg(dev, state, "completing ");
456-
dev->bus->pm->base.complete(dev);
457+
dev->bus->pm->complete(dev);
457458
}
458459

459460
up(&dev->sem);
@@ -624,7 +625,7 @@ static int suspend_device(struct device *dev, pm_message_t state)
624625
if (dev->bus) {
625626
if (dev->bus->pm) {
626627
pm_dev_dbg(dev, state, "");
627-
error = pm_op(dev, &dev->bus->pm->base, state);
628+
error = pm_op(dev, dev->bus->pm, state);
628629
} else if (dev->bus->suspend) {
629630
pm_dev_dbg(dev, state, "legacy ");
630631
error = dev->bus->suspend(dev, state);
@@ -685,10 +686,10 @@ static int prepare_device(struct device *dev, pm_message_t state)
685686

686687
down(&dev->sem);
687688

688-
if (dev->bus && dev->bus->pm && dev->bus->pm->base.prepare) {
689+
if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
689690
pm_dev_dbg(dev, state, "preparing ");
690-
error = dev->bus->pm->base.prepare(dev);
691-
suspend_report_result(dev->bus->pm->base.prepare, error);
691+
error = dev->bus->pm->prepare(dev);
692+
suspend_report_result(dev->bus->pm->prepare, error);
692693
if (error)
693694
goto End;
694695
}

0 commit comments

Comments
 (0)