[PATCH 1/3] PCI: Add helper to check if any of ancestor device support D3cold
From: Kai-Heng Feng
Date: Thu Aug 24 2023 - 00:48:15 EST
In addition to nearest upstream bridge, driver may want to know if the
entire hierarchy can be powered off to perform different action.
So walk higher up the hierarchy to find out if any device has valid
_PR3.
The user will be introduced in next patch.
Signed-off-by: Kai-Heng Feng <kai.heng.feng@xxxxxxxxxxxxx>
---
drivers/pci/pci.c | 16 ++++++++++++++++
include/linux/pci.h | 2 ++
2 files changed, 18 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 60230da957e0..79961936ed1b 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6500,6 +6500,22 @@ bool pci_pr3_present(struct pci_dev *pdev)
acpi_has_method(adev->handle, "_PR3");
}
EXPORT_SYMBOL_GPL(pci_pr3_present);
+
+bool pci_ancestor_pr3_present(struct pci_dev *pdev)
+{
+ struct pci_dev *parent = pdev;
+
+ if (acpi_disabled)
+ return false;
+
+ while ((parent = pci_upstream_bridge(parent))) {
+ if (pci_pr3_present(pdev))
+ return true;
+ }
+
+ return false;
+}
+EXPORT_SYMBOL_GPL(pci_ancestor_pr3_present);
#endif
/**
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c69a2cc1f412..1f30c20753a3 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2512,10 +2512,12 @@ struct irq_domain *pci_host_bridge_acpi_msi_domain(struct pci_bus *bus);
void
pci_msi_register_fwnode_provider(struct fwnode_handle *(*fn)(struct device *));
bool pci_pr3_present(struct pci_dev *pdev);
+bool pci_ancestor_pr3_present(struct pci_dev *pdev);
#else
static inline struct irq_domain *
pci_host_bridge_acpi_msi_domain(struct pci_bus *bus) { return NULL; }
static inline bool pci_pr3_present(struct pci_dev *pdev) { return false; }
+static inline bool pci_ancestor_pr3_present(struct pci_dev *pdev) { return false; }
#endif
#ifdef CONFIG_EEH
--
2.34.1