Skip to content

Commit d97c5d4

Browse files
committed
PCI: ACPI: PM: Do not use pci_platform_pm_ops for ACPI
Using struct pci_platform_pm_ops for ACPI adds unnecessary indirection to the interactions between the PCI core and ACPI PM, which is also subject to retpolines. Moreover, it is not particularly clear from the current code that, as far as PCI PM is concerned, "platform" really means just ACPI except for the special casess when Intel MID PCI PM is used or when ACPI support is disabled (through the kernel config or command line, or because there are no usable ACPI tables on the system). To address the above, rework the PCI PM code to invoke ACPI PM functions directly as needed and drop the acpi_pci_platform_pm object that is not necessary any more. Accordingly, update some of the ACPI PM functions in question to do extra checks in case the ACPI support is disabled (which previously was taken care of by avoiding to set the pci_platform_ops pointer in those cases). Signed-off-by: Rafael J. Wysocki <[email protected]> Tested-by: Ferry Toth <[email protected]>
1 parent d5b0d88 commit d97c5d4

File tree

3 files changed

+66
-36
lines changed

3 files changed

+66
-36
lines changed

drivers/pci/pci-acpi.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,13 @@ acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
906906
* choose highest power _SxD or any lower power
907907
*/
908908

909-
static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
909+
pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
910910
{
911911
int acpi_state, d_max;
912912

913+
if (acpi_pci_disabled)
914+
return PCI_POWER_ERROR;
915+
913916
if (pdev->no_d3cold)
914917
d_max = ACPI_STATE_D3_HOT;
915918
else
@@ -965,7 +968,7 @@ int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
965968
return 0;
966969
}
967970

968-
static bool acpi_pci_power_manageable(struct pci_dev *dev)
971+
bool acpi_pci_power_manageable(struct pci_dev *dev)
969972
{
970973
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
971974

@@ -974,13 +977,13 @@ static bool acpi_pci_power_manageable(struct pci_dev *dev)
974977
return acpi_device_power_manageable(adev);
975978
}
976979

977-
static bool acpi_pci_bridge_d3(struct pci_dev *dev)
980+
bool acpi_pci_bridge_d3(struct pci_dev *dev)
978981
{
979982
const union acpi_object *obj;
980983
struct acpi_device *adev;
981984
struct pci_dev *rpdev;
982985

983-
if (!dev->is_hotplug_bridge)
986+
if (acpi_pci_disabled || !dev->is_hotplug_bridge)
984987
return false;
985988

986989
/* Assume D3 support if the bridge is power-manageable by ACPI. */
@@ -1008,7 +1011,7 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev)
10081011
return obj->integer.value == 1;
10091012
}
10101013

1011-
static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
1014+
int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
10121015
{
10131016
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
10141017
static const u8 state_conv[] = {
@@ -1046,7 +1049,7 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
10461049
return error;
10471050
}
10481051

1049-
static pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
1052+
pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
10501053
{
10511054
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
10521055
static const pci_power_t state_conv[] = {
@@ -1068,7 +1071,7 @@ static pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
10681071
return state_conv[state];
10691072
}
10701073

1071-
static void acpi_pci_refresh_power_state(struct pci_dev *dev)
1074+
void acpi_pci_refresh_power_state(struct pci_dev *dev)
10721075
{
10731076
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
10741077

@@ -1093,17 +1096,23 @@ static int acpi_pci_propagate_wakeup(struct pci_bus *bus, bool enable)
10931096
return 0;
10941097
}
10951098

1096-
static int acpi_pci_wakeup(struct pci_dev *dev, bool enable)
1099+
int acpi_pci_wakeup(struct pci_dev *dev, bool enable)
10971100
{
1101+
if (acpi_pci_disabled)
1102+
return 0;
1103+
10981104
if (acpi_pm_device_can_wakeup(&dev->dev))
10991105
return acpi_pm_set_device_wakeup(&dev->dev, enable);
11001106

11011107
return acpi_pci_propagate_wakeup(dev->bus, enable);
11021108
}
11031109

1104-
static bool acpi_pci_need_resume(struct pci_dev *dev)
1110+
bool acpi_pci_need_resume(struct pci_dev *dev)
11051111
{
1106-
struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
1112+
struct acpi_device *adev;
1113+
1114+
if (acpi_pci_disabled)
1115+
return false;
11071116

11081117
/*
11091118
* In some cases (eg. Samsung 305V4A) leaving a bridge in suspend over
@@ -1115,6 +1124,7 @@ static bool acpi_pci_need_resume(struct pci_dev *dev)
11151124
if (pci_is_bridge(dev) && acpi_target_system_state() != ACPI_STATE_S0)
11161125
return true;
11171126

1127+
adev = ACPI_COMPANION(&dev->dev);
11181128
if (!adev || !acpi_device_power_manageable(adev))
11191129
return false;
11201130

@@ -1128,17 +1138,6 @@ static bool acpi_pci_need_resume(struct pci_dev *dev)
11281138
return !!adev->power.flags.dsw_present;
11291139
}
11301140

1131-
static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
1132-
.bridge_d3 = acpi_pci_bridge_d3,
1133-
.is_manageable = acpi_pci_power_manageable,
1134-
.set_state = acpi_pci_set_power_state,
1135-
.get_state = acpi_pci_get_power_state,
1136-
.refresh_state = acpi_pci_refresh_power_state,
1137-
.choose_state = acpi_pci_choose_state,
1138-
.set_wakeup = acpi_pci_wakeup,
1139-
.need_resume = acpi_pci_need_resume,
1140-
};
1141-
11421141
void acpi_pci_add_bus(struct pci_bus *bus)
11431142
{
11441143
union acpi_object *obj;
@@ -1448,7 +1447,6 @@ static int __init acpi_pci_init(void)
14481447
if (acpi_pci_disabled)
14491448
return 0;
14501449

1451-
pci_set_platform_pm(&acpi_pci_platform_pm);
14521450
acpi_pci_slot_init();
14531451
acpiphp_init();
14541452

drivers/pci/pci.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ static inline bool platform_pci_power_manageable(struct pci_dev *dev)
988988
if (pci_use_mid_pm())
989989
return true;
990990

991-
return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false;
991+
return acpi_pci_power_manageable(dev);
992992
}
993993

994994
static inline int platform_pci_set_power_state(struct pci_dev *dev,
@@ -997,57 +997,53 @@ static inline int platform_pci_set_power_state(struct pci_dev *dev,
997997
if (pci_use_mid_pm())
998998
return mid_pci_set_power_state(dev, t);
999999

1000-
return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS;
1000+
return acpi_pci_set_power_state(dev, t);
10011001
}
10021002

10031003
static inline pci_power_t platform_pci_get_power_state(struct pci_dev *dev)
10041004
{
10051005
if (pci_use_mid_pm())
10061006
return mid_pci_get_power_state(dev);
10071007

1008-
return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN;
1008+
return acpi_pci_get_power_state(dev);
10091009
}
10101010

10111011
static inline void platform_pci_refresh_power_state(struct pci_dev *dev)
10121012
{
1013-
if (!pci_use_mid_pm() && pci_platform_pm && pci_platform_pm->refresh_state)
1014-
pci_platform_pm->refresh_state(dev);
1013+
if (!pci_use_mid_pm())
1014+
acpi_pci_refresh_power_state(dev);
10151015
}
10161016

10171017
static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
10181018
{
10191019
if (pci_use_mid_pm())
10201020
return PCI_POWER_ERROR;
10211021

1022-
return pci_platform_pm ?
1023-
pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR;
1022+
return acpi_pci_choose_state(dev);
10241023
}
10251024

10261025
static inline int platform_pci_set_wakeup(struct pci_dev *dev, bool enable)
10271026
{
10281027
if (pci_use_mid_pm())
10291028
return PCI_POWER_ERROR;
10301029

1031-
return pci_platform_pm ?
1032-
pci_platform_pm->set_wakeup(dev, enable) : -ENODEV;
1030+
return acpi_pci_wakeup(dev, enable);
10331031
}
10341032

10351033
static inline bool platform_pci_need_resume(struct pci_dev *dev)
10361034
{
10371035
if (pci_use_mid_pm())
10381036
return false;
10391037

1040-
return pci_platform_pm ? pci_platform_pm->need_resume(dev) : false;
1038+
return acpi_pci_need_resume(dev);
10411039
}
10421040

10431041
static inline bool platform_pci_bridge_d3(struct pci_dev *dev)
10441042
{
10451043
if (pci_use_mid_pm())
10461044
return false;
10471045

1048-
if (pci_platform_pm && pci_platform_pm->bridge_d3)
1049-
return pci_platform_pm->bridge_d3(dev);
1050-
return false;
1046+
return acpi_pci_bridge_d3(dev);
10511047
}
10521048

10531049
/**

drivers/pci/pci.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,17 +725,53 @@ int pci_acpi_program_hp_params(struct pci_dev *dev);
725725
extern const struct attribute_group pci_dev_acpi_attr_group;
726726
void pci_set_acpi_fwnode(struct pci_dev *dev);
727727
int pci_dev_acpi_reset(struct pci_dev *dev, bool probe);
728+
bool acpi_pci_power_manageable(struct pci_dev *dev);
729+
bool acpi_pci_bridge_d3(struct pci_dev *dev);
730+
int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state);
731+
pci_power_t acpi_pci_get_power_state(struct pci_dev *dev);
732+
void acpi_pci_refresh_power_state(struct pci_dev *dev);
733+
int acpi_pci_wakeup(struct pci_dev *dev, bool enable);
734+
bool acpi_pci_need_resume(struct pci_dev *dev);
735+
pci_power_t acpi_pci_choose_state(struct pci_dev *pdev);
728736
#else
729737
static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
730738
{
731739
return -ENOTTY;
732740
}
733-
734741
static inline void pci_set_acpi_fwnode(struct pci_dev *dev) {}
735742
static inline int pci_acpi_program_hp_params(struct pci_dev *dev)
736743
{
737744
return -ENODEV;
738745
}
746+
static inline bool acpi_pci_power_manageable(struct pci_dev *dev)
747+
{
748+
return false;
749+
}
750+
static inline bool acpi_pci_bridge_d3(struct pci_dev *dev)
751+
{
752+
return false;
753+
}
754+
static inline int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
755+
{
756+
return -ENODEV;
757+
}
758+
static inline pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
759+
{
760+
return PCI_UNKNOWN;
761+
}
762+
static inline void acpi_pci_refresh_power_state(struct pci_dev *dev) {}
763+
static inline int acpi_pci_wakeup(struct pci_dev *dev, bool enable)
764+
{
765+
return -ENODEV;
766+
}
767+
static inline bool acpi_pci_need_resume(struct pci_dev *dev)
768+
{
769+
return false;
770+
}
771+
static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
772+
{
773+
return PCI_POWER_ERROR;
774+
}
739775
#endif
740776

741777
#ifdef CONFIG_PCIEASPM

0 commit comments

Comments
 (0)