Skip to content

Commit d5b0d88

Browse files
committed
PCI: PM: Do not use pci_platform_pm_ops for Intel MID PM
There are only two users of struct pci_platform_pm_ops in the tree, one of which is Intel MID PM and the other one is ACPI. They are mutually exclusive and the MID PM should take precedence when they both are enabled, but whether or not this really is the case hinges on the specific ordering of arch_initcall() calls made by them. The struct pci_platform_pm_ops abstraction is not really necessary for just these two users, but it adds complexity and overhead because of retoplines involved in using all of the function pointers in there. It also makes following the code a bit more difficult than it would be otherwise. Moreover, Intel MID PCI PM doesn't even implement the majority of the function pointers in struct pci_platform_pm_ops in a meaningful way, so switch over the PCI core to calling the relevant MID PM routines, mid_pci_set_power_state() and mid_pci_set_power_state(), directly as needed and drop mid_pci_platform_pm. Signed-off-by: Rafael J. Wysocki <[email protected]> Tested-by: Ferry Toth <[email protected]>
1 parent 2ef5236 commit d5b0d88

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

drivers/pci/pci-mid.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,23 @@
1616

1717
#include "pci.h"
1818

19-
static bool mid_pci_power_manageable(struct pci_dev *dev)
19+
static bool pci_mid_pm_enabled __read_mostly;
20+
21+
bool pci_use_mid_pm(void)
2022
{
21-
return true;
23+
return pci_mid_pm_enabled;
2224
}
2325

24-
static int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state)
26+
int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state)
2527
{
2628
return intel_mid_pci_set_power_state(pdev, state);
2729
}
2830

29-
static pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
31+
pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
3032
{
3133
return intel_mid_pci_get_power_state(pdev);
3234
}
3335

34-
static pci_power_t mid_pci_choose_state(struct pci_dev *pdev)
35-
{
36-
return PCI_D3hot;
37-
}
38-
39-
static int mid_pci_wakeup(struct pci_dev *dev, bool enable)
40-
{
41-
return 0;
42-
}
43-
44-
static bool mid_pci_need_resume(struct pci_dev *dev)
45-
{
46-
return false;
47-
}
48-
49-
static const struct pci_platform_pm_ops mid_pci_platform_pm = {
50-
.is_manageable = mid_pci_power_manageable,
51-
.set_state = mid_pci_set_power_state,
52-
.get_state = mid_pci_get_power_state,
53-
.choose_state = mid_pci_choose_state,
54-
.set_wakeup = mid_pci_wakeup,
55-
.need_resume = mid_pci_need_resume,
56-
};
57-
5836
/*
5937
* This table should be in sync with the one in
6038
* arch/x86/platform/intel-mid/pwr.c.
@@ -71,7 +49,8 @@ static int __init mid_pci_init(void)
7149

7250
id = x86_match_cpu(lpss_cpu_ids);
7351
if (id)
74-
pci_set_platform_pm(&mid_pci_platform_pm);
52+
pci_mid_pm_enabled = true;
53+
7554
return 0;
7655
}
7756
arch_initcall(mid_pci_init);

drivers/pci/pci.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,45 +985,66 @@ int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
985985

986986
static inline bool platform_pci_power_manageable(struct pci_dev *dev)
987987
{
988+
if (pci_use_mid_pm())
989+
return true;
990+
988991
return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false;
989992
}
990993

991994
static inline int platform_pci_set_power_state(struct pci_dev *dev,
992995
pci_power_t t)
993996
{
997+
if (pci_use_mid_pm())
998+
return mid_pci_set_power_state(dev, t);
999+
9941000
return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS;
9951001
}
9961002

9971003
static inline pci_power_t platform_pci_get_power_state(struct pci_dev *dev)
9981004
{
1005+
if (pci_use_mid_pm())
1006+
return mid_pci_get_power_state(dev);
1007+
9991008
return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN;
10001009
}
10011010

10021011
static inline void platform_pci_refresh_power_state(struct pci_dev *dev)
10031012
{
1004-
if (pci_platform_pm && pci_platform_pm->refresh_state)
1013+
if (!pci_use_mid_pm() && pci_platform_pm && pci_platform_pm->refresh_state)
10051014
pci_platform_pm->refresh_state(dev);
10061015
}
10071016

10081017
static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
10091018
{
1019+
if (pci_use_mid_pm())
1020+
return PCI_POWER_ERROR;
1021+
10101022
return pci_platform_pm ?
10111023
pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;
10121024
}
10131025

10141026
static inline int platform_pci_set_wakeup(struct pci_dev *dev, bool enable)
10151027
{
1028+
if (pci_use_mid_pm())
1029+
return PCI_POWER_ERROR;
1030+
10161031
return pci_platform_pm ?
10171032
pci_platform_pm->set_wakeup(dev, enable) : -ENODEV;
10181033
}
10191034

10201035
static inline bool platform_pci_need_resume(struct pci_dev *dev)
10211036
{
1037+
if (pci_use_mid_pm())
1038+
return false;
1039+
10221040
return pci_platform_pm ? pci_platform_pm->need_resume(dev) : false;
10231041
}
10241042

10251043
static inline bool platform_pci_bridge_d3(struct pci_dev *dev)
10261044
{
1045+
if (pci_use_mid_pm())
1046+
return false;
1047+
10271048
if (pci_platform_pm && pci_platform_pm->bridge_d3)
10281049
return pci_platform_pm->bridge_d3(dev);
10291050
return false;

drivers/pci/pci.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,4 +744,23 @@ extern const struct attribute_group aspm_ctrl_attr_group;
744744

745745
extern const struct attribute_group pci_dev_reset_method_attr_group;
746746

747+
#ifdef CONFIG_X86_INTEL_MID
748+
bool pci_use_mid_pm(void);
749+
int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state);
750+
pci_power_t mid_pci_get_power_state(struct pci_dev *pdev);
751+
#else
752+
static inline bool pci_use_mid_pm(void)
753+
{
754+
return false;
755+
}
756+
static inline int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state)
757+
{
758+
return -ENODEV;
759+
}
760+
static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
761+
{
762+
return PCI_UNKNOWN;
763+
}
764+
#endif
765+
747766
#endif /* DRIVERS_PCI_H */

0 commit comments

Comments
 (0)