hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pci/pci-driver.c
....@@ -12,12 +12,14 @@
1212 #include <linux/string.h>
1313 #include <linux/slab.h>
1414 #include <linux/sched.h>
15
+#include <linux/sched/isolation.h>
1516 #include <linux/cpu.h>
1617 #include <linux/pm_runtime.h>
1718 #include <linux/suspend.h>
1819 #include <linux/kexec.h>
1920 #include <linux/of_device.h>
2021 #include <linux/acpi.h>
22
+#include <linux/dma-map-ops.h>
2123 #include "pci.h"
2224 #include "pcie/portdrv.h"
2325
....@@ -100,7 +102,7 @@
100102 {
101103 struct pci_driver *pdrv = to_pci_driver(driver);
102104 const struct pci_device_id *ids = pdrv->id_table;
103
- __u32 vendor, device, subvendor = PCI_ANY_ID,
105
+ u32 vendor, device, subvendor = PCI_ANY_ID,
104106 subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
105107 unsigned long driver_data = 0;
106108 int fields = 0;
....@@ -168,7 +170,7 @@
168170 {
169171 struct pci_dynid *dynid, *n;
170172 struct pci_driver *pdrv = to_pci_driver(driver);
171
- __u32 vendor, device, subvendor = PCI_ANY_ID,
173
+ u32 vendor, device, subvendor = PCI_ANY_ID,
172174 subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
173175 int fields = 0;
174176 size_t retval = -ENODEV;
....@@ -315,7 +317,8 @@
315317 * Probe function should return < 0 for failure, 0 for success
316318 * Treat values > 0 as success, but warn.
317319 */
318
- dev_warn(dev, "Driver probe function unexpectedly returned %d\n", rc);
320
+ pci_warn(pci_dev, "Driver probe function unexpectedly returned %d\n",
321
+ rc);
319322 return 0;
320323 }
321324
....@@ -332,6 +335,7 @@
332335 const struct pci_device_id *id)
333336 {
334337 int error, node, cpu;
338
+ int hk_flags = HK_FLAG_DOMAIN | HK_FLAG_WQ;
335339 struct drv_dev_and_id ddi = { drv, dev, id };
336340
337341 /*
....@@ -352,7 +356,8 @@
352356 pci_physfn_is_probed(dev))
353357 cpu = nr_cpu_ids;
354358 else
355
- cpu = cpumask_any_and(cpumask_of_node(node), cpu_online_mask);
359
+ cpu = cpumask_any_and(cpumask_of_node(node),
360
+ housekeeping_cpumask(hk_flags));
356361
357362 if (cpu < nr_cpu_ids)
358363 error = work_on_cpu(cpu, local_pci_probe, &ddi);
....@@ -517,6 +522,12 @@
517522 return 0;
518523 }
519524
525
+static void pci_pm_default_resume(struct pci_dev *pci_dev)
526
+{
527
+ pci_fixup_device(pci_fixup_resume, pci_dev);
528
+ pci_enable_wake(pci_dev, PCI_D0, false);
529
+}
530
+
520531 #endif
521532
522533 #ifdef CONFIG_PM_SLEEP
....@@ -524,9 +535,9 @@
524535 static void pci_pm_default_resume_early(struct pci_dev *pci_dev)
525536 {
526537 pci_power_up(pci_dev);
538
+ pci_update_current_state(pci_dev, PCI_D0);
527539 pci_restore_state(pci_dev);
528540 pci_pme_restore(pci_dev);
529
- pci_fixup_device(pci_fixup_resume_early, pci_dev);
530541 }
531542
532543 /*
....@@ -579,9 +590,9 @@
579590
580591 if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0
581592 && pci_dev->current_state != PCI_UNKNOWN) {
582
- WARN_ONCE(pci_dev->current_state != prev,
583
- "PCI PM: Device state not saved by %pF\n",
584
- drv->suspend);
593
+ pci_WARN_ONCE(pci_dev, pci_dev->current_state != prev,
594
+ "PCI PM: Device state not saved by %pS\n",
595
+ drv->suspend);
585596 }
586597 }
587598
....@@ -593,44 +604,15 @@
593604 static int pci_legacy_suspend_late(struct device *dev, pm_message_t state)
594605 {
595606 struct pci_dev *pci_dev = to_pci_dev(dev);
596
- struct pci_driver *drv = pci_dev->driver;
597
-
598
- if (drv && drv->suspend_late) {
599
- pci_power_t prev = pci_dev->current_state;
600
- int error;
601
-
602
- error = drv->suspend_late(pci_dev, state);
603
- suspend_report_result(drv->suspend_late, error);
604
- if (error)
605
- return error;
606
-
607
- if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0
608
- && pci_dev->current_state != PCI_UNKNOWN) {
609
- WARN_ONCE(pci_dev->current_state != prev,
610
- "PCI PM: Device state not saved by %pF\n",
611
- drv->suspend_late);
612
- goto Fixup;
613
- }
614
- }
615607
616608 if (!pci_dev->state_saved)
617609 pci_save_state(pci_dev);
618610
619611 pci_pm_set_unknown_state(pci_dev);
620612
621
-Fixup:
622613 pci_fixup_device(pci_fixup_suspend_late, pci_dev);
623614
624615 return 0;
625
-}
626
-
627
-static int pci_legacy_resume_early(struct device *dev)
628
-{
629
- struct pci_dev *pci_dev = to_pci_dev(dev);
630
- struct pci_driver *drv = pci_dev->driver;
631
-
632
- return drv && drv->resume_early ?
633
- drv->resume_early(pci_dev) : 0;
634616 }
635617
636618 static int pci_legacy_resume(struct device *dev)
....@@ -646,12 +628,6 @@
646628
647629 /* Auxiliary functions used by the new power management framework */
648630
649
-static void pci_pm_default_resume(struct pci_dev *pci_dev)
650
-{
651
- pci_fixup_device(pci_fixup_resume, pci_dev);
652
- pci_enable_wake(pci_dev, PCI_D0, false);
653
-}
654
-
655631 static void pci_pm_default_suspend(struct pci_dev *pci_dev)
656632 {
657633 /* Disable non-bridge devices without PM support */
....@@ -662,16 +638,15 @@
662638 static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
663639 {
664640 struct pci_driver *drv = pci_dev->driver;
665
- bool ret = drv && (drv->suspend || drv->suspend_late || drv->resume
666
- || drv->resume_early);
641
+ bool ret = drv && (drv->suspend || drv->resume);
667642
668643 /*
669644 * Legacy PM support is used by default, so warn if the new framework is
670645 * supported as well. Drivers are supposed to support either the
671646 * former, or the latter, but not both at the same time.
672647 */
673
- WARN(ret && drv->driver.pm, "driver %s device %04x:%04x\n",
674
- drv->name, pci_dev->vendor, pci_dev->device);
648
+ pci_WARN(pci_dev, ret && drv->driver.pm, "device %04x:%04x\n",
649
+ pci_dev->vendor, pci_dev->device);
675650
676651 return ret;
677652 }
....@@ -680,17 +655,26 @@
680655
681656 static int pci_pm_prepare(struct device *dev)
682657 {
683
- struct device_driver *drv = dev->driver;
658
+ struct pci_dev *pci_dev = to_pci_dev(dev);
659
+ const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
684660
685
- if (drv && drv->pm && drv->pm->prepare) {
686
- int error = drv->pm->prepare(dev);
661
+ if (pm && pm->prepare) {
662
+ int error = pm->prepare(dev);
687663 if (error < 0)
688664 return error;
689665
690666 if (!error && dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_PREPARE))
691667 return 0;
692668 }
693
- return pci_dev_keep_suspended(to_pci_dev(dev));
669
+ if (pci_dev_need_resume(pci_dev))
670
+ return 0;
671
+
672
+ /*
673
+ * The PME setting needs to be adjusted here in case the direct-complete
674
+ * optimization is used with respect to this device.
675
+ */
676
+ pci_dev_adjust_pme(pci_dev);
677
+ return 1;
694678 }
695679
696680 static void pci_pm_complete(struct device *dev)
....@@ -704,7 +688,14 @@
704688 if (pm_runtime_suspended(dev) && pm_resume_via_firmware()) {
705689 pci_power_t pre_sleep_state = pci_dev->current_state;
706690
707
- pci_update_current_state(pci_dev, pci_dev->current_state);
691
+ pci_refresh_power_state(pci_dev);
692
+ /*
693
+ * On platforms with ACPI this check may also trigger for
694
+ * devices sharing power resources if one of those power
695
+ * resources has been activated as a result of a change of the
696
+ * power state of another device sharing it. However, in that
697
+ * case it is also better to resume the device, in general.
698
+ */
708699 if (pci_dev->current_state < pre_sleep_state)
709700 pm_request_resume(dev);
710701 }
....@@ -736,6 +727,8 @@
736727 struct pci_dev *pci_dev = to_pci_dev(dev);
737728 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
738729
730
+ pci_dev->skip_bus_pm = false;
731
+
739732 if (pci_has_legacy_pm_support(pci_dev))
740733 return pci_legacy_suspend(dev, PMSG_SUSPEND);
741734
....@@ -758,9 +751,11 @@
758751 * better to resume the device from runtime suspend here.
759752 */
760753 if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
761
- !pci_dev_keep_suspended(pci_dev)) {
754
+ pci_dev_need_resume(pci_dev)) {
762755 pm_runtime_resume(dev);
763756 pci_dev->state_saved = false;
757
+ } else {
758
+ pci_dev_adjust_pme(pci_dev);
764759 }
765760
766761 if (pm->suspend) {
....@@ -774,9 +769,9 @@
774769
775770 if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0
776771 && pci_dev->current_state != PCI_UNKNOWN) {
777
- WARN_ONCE(pci_dev->current_state != prev,
778
- "PCI PM: State of device not saved by %pF\n",
779
- pm->suspend);
772
+ pci_WARN_ONCE(pci_dev, pci_dev->current_state != prev,
773
+ "PCI PM: State of device not saved by %pS\n",
774
+ pm->suspend);
780775 }
781776 }
782777
....@@ -785,7 +780,7 @@
785780
786781 static int pci_pm_suspend_late(struct device *dev)
787782 {
788
- if (dev_pm_smart_suspend_and_suspended(dev))
783
+ if (dev_pm_skip_suspend(dev))
789784 return 0;
790785
791786 pci_fixup_device(pci_fixup_suspend, to_pci_dev(dev));
....@@ -798,10 +793,8 @@
798793 struct pci_dev *pci_dev = to_pci_dev(dev);
799794 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
800795
801
- if (dev_pm_smart_suspend_and_suspended(dev)) {
802
- dev->power.may_skip_resume = true;
796
+ if (dev_pm_skip_suspend(dev))
803797 return 0;
804
- }
805798
806799 if (pci_has_legacy_pm_support(pci_dev))
807800 return pci_legacy_suspend_late(dev, PMSG_SUSPEND);
....@@ -822,25 +815,48 @@
822815
823816 if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0
824817 && pci_dev->current_state != PCI_UNKNOWN) {
825
- WARN_ONCE(pci_dev->current_state != prev,
826
- "PCI PM: State of device not saved by %pF\n",
827
- pm->suspend_noirq);
818
+ pci_WARN_ONCE(pci_dev, pci_dev->current_state != prev,
819
+ "PCI PM: State of device not saved by %pS\n",
820
+ pm->suspend_noirq);
828821 goto Fixup;
829822 }
830823 }
831824
832
- /* if d3hot is not supported bail out */
833
- if (pci_dev->no_d3hot)
834
- return 0;
835
-
836
- if (!pci_dev->state_saved) {
825
+ if (pci_dev->skip_bus_pm) {
826
+ /*
827
+ * Either the device is a bridge with a child in D0 below it, or
828
+ * the function is running for the second time in a row without
829
+ * going through full resume, which is possible only during
830
+ * suspend-to-idle in a spurious wakeup case. The device should
831
+ * be in D0 at this point, but if it is a bridge, it may be
832
+ * necessary to save its state.
833
+ */
834
+ if (!pci_dev->state_saved)
835
+ pci_save_state(pci_dev);
836
+ } else if (!pci_dev->state_saved) {
837837 pci_save_state(pci_dev);
838838 if (pci_power_manageable(pci_dev))
839839 pci_prepare_to_sleep(pci_dev);
840840 }
841841
842
- dev_dbg(dev, "PCI PM: Suspend power state: %s\n",
842
+ pci_dbg(pci_dev, "PCI PM: Suspend power state: %s\n",
843843 pci_power_name(pci_dev->current_state));
844
+
845
+ if (pci_dev->current_state == PCI_D0) {
846
+ pci_dev->skip_bus_pm = true;
847
+ /*
848
+ * Per PCI PM r1.2, table 6-1, a bridge must be in D0 if any
849
+ * downstream device is in D0, so avoid changing the power state
850
+ * of the parent bridge by setting the skip_bus_pm flag for it.
851
+ */
852
+ if (pci_dev->bus->self)
853
+ pci_dev->bus->self->skip_bus_pm = true;
854
+ }
855
+
856
+ if (pci_dev->skip_bus_pm && pm_suspend_no_platform()) {
857
+ pci_dbg(pci_dev, "PCI PM: Skipped\n");
858
+ goto Fixup;
859
+ }
844860
845861 pci_pm_set_unknown_state(pci_dev);
846862
....@@ -866,8 +882,8 @@
866882 * pci_pm_complete() to take care of fixing up the device's state
867883 * anyway, if need be.
868884 */
869
- dev->power.may_skip_resume = device_may_wakeup(dev) ||
870
- !device_can_wakeup(dev);
885
+ if (device_can_wakeup(dev) && !device_may_wakeup(dev))
886
+ dev->power.may_skip_resume = false;
871887
872888 return 0;
873889 }
....@@ -875,39 +891,49 @@
875891 static int pci_pm_resume_noirq(struct device *dev)
876892 {
877893 struct pci_dev *pci_dev = to_pci_dev(dev);
878
- struct device_driver *drv = dev->driver;
879
- int error = 0;
894
+ const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
895
+ pci_power_t prev_state = pci_dev->current_state;
896
+ bool skip_bus_pm = pci_dev->skip_bus_pm;
880897
881
- if (dev_pm_may_skip_resume(dev))
898
+ if (dev_pm_skip_resume(dev))
882899 return 0;
883900
884901 /*
885
- * Devices with DPM_FLAG_SMART_SUSPEND may be left in runtime suspend
886
- * during system suspend, so update their runtime PM status to "active"
887
- * as they are going to be put into D0 shortly.
902
+ * In the suspend-to-idle case, devices left in D0 during suspend will
903
+ * stay in D0, so it is not necessary to restore or update their
904
+ * configuration here and attempting to put them into D0 again is
905
+ * pointless, so avoid doing that.
888906 */
889
- if (dev_pm_smart_suspend_and_suspended(dev))
890
- pm_runtime_set_active(dev);
891
-
892
- if (!pci_dev->no_d3hot)
907
+ if (!(skip_bus_pm && pm_suspend_no_platform()))
893908 pci_pm_default_resume_early(pci_dev);
894909
895
- if (pci_has_legacy_pm_support(pci_dev))
896
- return pci_legacy_resume_early(dev);
897
-
910
+ pci_fixup_device(pci_fixup_resume_early, pci_dev);
898911 pcie_pme_root_status_cleanup(pci_dev);
899912
900
- if (drv && drv->pm && drv->pm->resume_noirq)
901
- error = drv->pm->resume_noirq(dev);
913
+ if (!skip_bus_pm && prev_state == PCI_D3cold)
914
+ pci_bridge_wait_for_secondary_bus(pci_dev, "resume", PCI_RESET_WAIT);
902915
903
- return error;
916
+ if (pci_has_legacy_pm_support(pci_dev))
917
+ return 0;
918
+
919
+ if (pm && pm->resume_noirq)
920
+ return pm->resume_noirq(dev);
921
+
922
+ return 0;
923
+}
924
+
925
+static int pci_pm_resume_early(struct device *dev)
926
+{
927
+ if (dev_pm_skip_resume(dev))
928
+ return 0;
929
+
930
+ return pm_generic_resume_early(dev);
904931 }
905932
906933 static int pci_pm_resume(struct device *dev)
907934 {
908935 struct pci_dev *pci_dev = to_pci_dev(dev);
909936 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
910
- int error = 0;
911937
912938 /*
913939 * This is necessary for the suspend error path in which resume is
....@@ -923,12 +949,12 @@
923949
924950 if (pm) {
925951 if (pm->resume)
926
- error = pm->resume(dev);
952
+ return pm->resume(dev);
927953 } else {
928954 pci_pm_reenable_device(pci_dev);
929955 }
930956
931
- return error;
957
+ return 0;
932958 }
933959
934960 #else /* !CONFIG_SUSPEND */
....@@ -937,18 +963,12 @@
937963 #define pci_pm_suspend_late NULL
938964 #define pci_pm_suspend_noirq NULL
939965 #define pci_pm_resume NULL
966
+#define pci_pm_resume_early NULL
940967 #define pci_pm_resume_noirq NULL
941968
942969 #endif /* !CONFIG_SUSPEND */
943970
944971 #ifdef CONFIG_HIBERNATE_CALLBACKS
945
-
946
-
947
-/*
948
- * pcibios_pm_ops - provide arch-specific hooks when a PCI device is doing
949
- * a hibernate transition
950
- */
951
-struct dev_pm_ops __weak pcibios_pm_ops;
952972
953973 static int pci_pm_freeze(struct device *dev)
954974 {
....@@ -986,30 +1006,19 @@
9861006 return 0;
9871007 }
9881008
989
-static int pci_pm_freeze_late(struct device *dev)
990
-{
991
- if (dev_pm_smart_suspend_and_suspended(dev))
992
- return 0;
993
-
994
- return pm_generic_freeze_late(dev);
995
-}
996
-
9971009 static int pci_pm_freeze_noirq(struct device *dev)
9981010 {
9991011 struct pci_dev *pci_dev = to_pci_dev(dev);
1000
- struct device_driver *drv = dev->driver;
1001
-
1002
- if (dev_pm_smart_suspend_and_suspended(dev))
1003
- return 0;
1012
+ const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
10041013
10051014 if (pci_has_legacy_pm_support(pci_dev))
10061015 return pci_legacy_suspend_late(dev, PMSG_FREEZE);
10071016
1008
- if (drv && drv->pm && drv->pm->freeze_noirq) {
1017
+ if (pm && pm->freeze_noirq) {
10091018 int error;
10101019
1011
- error = drv->pm->freeze_noirq(dev);
1012
- suspend_report_result(drv->pm->freeze_noirq, error);
1020
+ error = pm->freeze_noirq(dev);
1021
+ suspend_report_result(pm->freeze_noirq, error);
10131022 if (error)
10141023 return error;
10151024 }
....@@ -1019,38 +1028,17 @@
10191028
10201029 pci_pm_set_unknown_state(pci_dev);
10211030
1022
- if (pcibios_pm_ops.freeze_noirq)
1023
- return pcibios_pm_ops.freeze_noirq(dev);
1024
-
10251031 return 0;
10261032 }
10271033
10281034 static int pci_pm_thaw_noirq(struct device *dev)
10291035 {
10301036 struct pci_dev *pci_dev = to_pci_dev(dev);
1031
- struct device_driver *drv = dev->driver;
1032
- int error = 0;
1037
+ const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
10331038
10341039 /*
1035
- * If the device is in runtime suspend, the code below may not work
1036
- * correctly with it, so skip that code and make the PM core skip all of
1037
- * the subsequent "thaw" callbacks for the device.
1038
- */
1039
- if (dev_pm_smart_suspend_and_suspended(dev)) {
1040
- dev_pm_skip_next_resume_phases(dev);
1041
- return 0;
1042
- }
1043
-
1044
- if (pcibios_pm_ops.thaw_noirq) {
1045
- error = pcibios_pm_ops.thaw_noirq(dev);
1046
- if (error)
1047
- return error;
1048
- }
1049
-
1050
- /*
1051
- * Both the legacy ->resume_early() and the new pm->thaw_noirq()
1052
- * callbacks assume the device has been returned to D0 and its
1053
- * config state has been restored.
1040
+ * The pm->thaw_noirq() callback assumes the device has been
1041
+ * returned to D0 and its config state has been restored.
10541042 *
10551043 * In addition, pci_restore_state() restores MSI-X state in MMIO
10561044 * space, which requires the device to be in D0, so return it to D0
....@@ -1061,12 +1049,12 @@
10611049 pci_restore_state(pci_dev);
10621050
10631051 if (pci_has_legacy_pm_support(pci_dev))
1064
- return pci_legacy_resume_early(dev);
1052
+ return 0;
10651053
1066
- if (drv && drv->pm && drv->pm->thaw_noirq)
1067
- error = drv->pm->thaw_noirq(dev);
1054
+ if (pm && pm->thaw_noirq)
1055
+ return pm->thaw_noirq(dev);
10681056
1069
- return error;
1057
+ return 0;
10701058 }
10711059
10721060 static int pci_pm_thaw(struct device *dev)
....@@ -1105,10 +1093,13 @@
11051093
11061094 /* The reason to do that is the same as in pci_pm_suspend(). */
11071095 if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
1108
- !pci_dev_keep_suspended(pci_dev))
1096
+ pci_dev_need_resume(pci_dev)) {
11091097 pm_runtime_resume(dev);
1098
+ pci_dev->state_saved = false;
1099
+ } else {
1100
+ pci_dev_adjust_pme(pci_dev);
1101
+ }
11101102
1111
- pci_dev->state_saved = false;
11121103 if (pm->poweroff) {
11131104 int error;
11141105
....@@ -1123,7 +1114,7 @@
11231114
11241115 static int pci_pm_poweroff_late(struct device *dev)
11251116 {
1126
- if (dev_pm_smart_suspend_and_suspended(dev))
1117
+ if (dev_pm_skip_suspend(dev))
11271118 return 0;
11281119
11291120 pci_fixup_device(pci_fixup_suspend, to_pci_dev(dev));
....@@ -1134,24 +1125,24 @@
11341125 static int pci_pm_poweroff_noirq(struct device *dev)
11351126 {
11361127 struct pci_dev *pci_dev = to_pci_dev(dev);
1137
- struct device_driver *drv = dev->driver;
1128
+ const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
11381129
1139
- if (dev_pm_smart_suspend_and_suspended(dev))
1130
+ if (dev_pm_skip_suspend(dev))
11401131 return 0;
11411132
1142
- if (pci_has_legacy_pm_support(to_pci_dev(dev)))
1133
+ if (pci_has_legacy_pm_support(pci_dev))
11431134 return pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
11441135
1145
- if (!drv || !drv->pm) {
1136
+ if (!pm) {
11461137 pci_fixup_device(pci_fixup_suspend_late, pci_dev);
11471138 return 0;
11481139 }
11491140
1150
- if (drv->pm->poweroff_noirq) {
1141
+ if (pm->poweroff_noirq) {
11511142 int error;
11521143
1153
- error = drv->pm->poweroff_noirq(dev);
1154
- suspend_report_result(drv->pm->poweroff_noirq, error);
1144
+ error = pm->poweroff_noirq(dev);
1145
+ suspend_report_result(pm->poweroff_noirq, error);
11551146 if (error)
11561147 return error;
11571148 }
....@@ -1168,44 +1159,30 @@
11681159
11691160 pci_fixup_device(pci_fixup_suspend_late, pci_dev);
11701161
1171
- if (pcibios_pm_ops.poweroff_noirq)
1172
- return pcibios_pm_ops.poweroff_noirq(dev);
1173
-
11741162 return 0;
11751163 }
11761164
11771165 static int pci_pm_restore_noirq(struct device *dev)
11781166 {
11791167 struct pci_dev *pci_dev = to_pci_dev(dev);
1180
- struct device_driver *drv = dev->driver;
1181
- int error = 0;
1182
-
1183
- /* This is analogous to the pci_pm_resume_noirq() case. */
1184
- if (dev_pm_smart_suspend_and_suspended(dev))
1185
- pm_runtime_set_active(dev);
1186
-
1187
- if (pcibios_pm_ops.restore_noirq) {
1188
- error = pcibios_pm_ops.restore_noirq(dev);
1189
- if (error)
1190
- return error;
1191
- }
1168
+ const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
11921169
11931170 pci_pm_default_resume_early(pci_dev);
1171
+ pci_fixup_device(pci_fixup_resume_early, pci_dev);
11941172
11951173 if (pci_has_legacy_pm_support(pci_dev))
1196
- return pci_legacy_resume_early(dev);
1174
+ return 0;
11971175
1198
- if (drv && drv->pm && drv->pm->restore_noirq)
1199
- error = drv->pm->restore_noirq(dev);
1176
+ if (pm && pm->restore_noirq)
1177
+ return pm->restore_noirq(dev);
12001178
1201
- return error;
1179
+ return 0;
12021180 }
12031181
12041182 static int pci_pm_restore(struct device *dev)
12051183 {
12061184 struct pci_dev *pci_dev = to_pci_dev(dev);
12071185 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1208
- int error = 0;
12091186
12101187 /*
12111188 * This is necessary for the hibernation error path in which restore is
....@@ -1221,18 +1198,17 @@
12211198
12221199 if (pm) {
12231200 if (pm->restore)
1224
- error = pm->restore(dev);
1201
+ return pm->restore(dev);
12251202 } else {
12261203 pci_pm_reenable_device(pci_dev);
12271204 }
12281205
1229
- return error;
1206
+ return 0;
12301207 }
12311208
12321209 #else /* !CONFIG_HIBERNATE_CALLBACKS */
12331210
12341211 #define pci_pm_freeze NULL
1235
-#define pci_pm_freeze_late NULL
12361212 #define pci_pm_freeze_noirq NULL
12371213 #define pci_pm_thaw NULL
12381214 #define pci_pm_thaw_noirq NULL
....@@ -1272,11 +1248,11 @@
12721248 * log level.
12731249 */
12741250 if (error == -EBUSY || error == -EAGAIN) {
1275
- dev_dbg(dev, "can't suspend now (%pf returned %d)\n",
1251
+ pci_dbg(pci_dev, "can't suspend now (%ps returned %d)\n",
12761252 pm->runtime_suspend, error);
12771253 return error;
12781254 } else if (error) {
1279
- dev_err(dev, "can't suspend (%pf returned %d)\n",
1255
+ pci_err(pci_dev, "can't suspend (%ps returned %d)\n",
12801256 pm->runtime_suspend, error);
12811257 return error;
12821258 }
....@@ -1287,15 +1263,11 @@
12871263 if (pm && pm->runtime_suspend
12881264 && !pci_dev->state_saved && pci_dev->current_state != PCI_D0
12891265 && pci_dev->current_state != PCI_UNKNOWN) {
1290
- WARN_ONCE(pci_dev->current_state != prev,
1291
- "PCI PM: State of device not saved by %pF\n",
1292
- pm->runtime_suspend);
1266
+ pci_WARN_ONCE(pci_dev, pci_dev->current_state != prev,
1267
+ "PCI PM: State of device not saved by %pS\n",
1268
+ pm->runtime_suspend);
12931269 return 0;
12941270 }
1295
-
1296
- /* if d3hot is not supported bail out */
1297
- if (pci_dev->no_d3hot)
1298
- return 0;
12991271
13001272 if (!pci_dev->state_saved) {
13011273 pci_save_state(pci_dev);
....@@ -1307,13 +1279,10 @@
13071279
13081280 static int pci_pm_runtime_resume(struct device *dev)
13091281 {
1310
- int rc = 0;
13111282 struct pci_dev *pci_dev = to_pci_dev(dev);
13121283 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1313
-
1314
- /* we skipped d3hot processing so skip re-init */
1315
- if (pci_dev->no_d3hot)
1316
- goto skip_restore;
1284
+ pci_power_t prev_state = pci_dev->current_state;
1285
+ int error = 0;
13171286
13181287 /*
13191288 * Restoring config space is necessary even if the device is not bound
....@@ -1326,23 +1295,23 @@
13261295 return 0;
13271296
13281297 pci_fixup_device(pci_fixup_resume_early, pci_dev);
1329
- pci_enable_wake(pci_dev, PCI_D0, false);
1330
- pci_fixup_device(pci_fixup_resume, pci_dev);
1298
+ pci_pm_default_resume(pci_dev);
13311299
1332
-skip_restore:
1300
+ if (prev_state == PCI_D3cold)
1301
+ pci_bridge_wait_for_secondary_bus(pci_dev, "resume", PCI_RESET_WAIT);
1302
+
13331303 if (pm && pm->runtime_resume)
1334
- rc = pm->runtime_resume(dev);
1304
+ error = pm->runtime_resume(dev);
13351305
13361306 pci_dev->runtime_d3cold = false;
13371307
1338
- return rc;
1308
+ return error;
13391309 }
13401310
13411311 static int pci_pm_runtime_idle(struct device *dev)
13421312 {
13431313 struct pci_dev *pci_dev = to_pci_dev(dev);
13441314 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1345
- int ret = 0;
13461315
13471316 /*
13481317 * If pci_dev->driver is not set (unbound), the device should
....@@ -1355,9 +1324,9 @@
13551324 return -ENOSYS;
13561325
13571326 if (pm->runtime_idle)
1358
- ret = pm->runtime_idle(dev);
1327
+ return pm->runtime_idle(dev);
13591328
1360
- return ret;
1329
+ return 0;
13611330 }
13621331
13631332 static const struct dev_pm_ops pci_dev_pm_ops = {
....@@ -1366,8 +1335,8 @@
13661335 .suspend = pci_pm_suspend,
13671336 .suspend_late = pci_pm_suspend_late,
13681337 .resume = pci_pm_resume,
1338
+ .resume_early = pci_pm_resume_early,
13691339 .freeze = pci_pm_freeze,
1370
- .freeze_late = pci_pm_freeze_late,
13711340 .thaw = pci_pm_thaw,
13721341 .poweroff = pci_pm_poweroff,
13731342 .poweroff_late = pci_pm_poweroff_late,
....@@ -1618,10 +1587,8 @@
16181587 ret = of_dma_configure(dev, bridge->parent->of_node, true);
16191588 } else if (has_acpi_companion(bridge)) {
16201589 struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
1621
- enum dev_dma_attr attr = acpi_get_dma_attr(adev);
16221590
1623
- if (attr != DEV_DMA_NOT_SUPPORTED)
1624
- ret = acpi_dma_configure(dev, attr);
1591
+ ret = acpi_dma_configure(dev, acpi_get_dma_attr(adev));
16251592 }
16261593
16271594 pci_put_host_bridge_device(bridge);