diff mbox series

[3/5] PCI: endpoint: Add PME notifier support

Message ID 20210616115913.138778-4-manivannan.sadhasivam@linaro.org
State New
Headers show
Series PCI: endpoint: Add support for additional notifiers | expand

Commit Message

Manivannan Sadhasivam June 16, 2021, 11:59 a.m. UTC
Add support to notify the EPF device about the Power Management Event
(PME) received by the EPC device from the Root complex.

Usage:
-- 
2.25.1
diff mbox series

Patch

======

EPC
---

```
static irqreturn_t pcie_ep_irq(int irq, void *data)
{
...
	case PCIE_EP_INT_PM_TURNOFF:
		pci_epc_pme_notify(epc, PCIE_EP_PM_TURNOFF);
		break;
...
}
```

EPF
---

```
static int pci_epf_notifier(struct notifier_block *nb, unsigned long val,
			    void *data)
{
...
	case PME:
		pm_state = data;
		if (pm_state == PCIE_EP_PM_TURNOFF)
			/* Handle PM Turnoff event */
		break;
...
}
```

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/pci/endpoint/pci-epc-core.c | 18 ++++++++++++++++++
 include/linux/pci-epc.h             |  1 +
 include/linux/pci-epf.h             |  1 +
 3 files changed, 20 insertions(+)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index 7e42a83a4877..63fe90dbbba2 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -692,6 +692,24 @@  void pci_epc_bme_notify(struct pci_epc *epc)
 }
 EXPORT_SYMBOL_GPL(pci_epc_bme_notify);
 
+/**
+ * pci_epc_pme_notify() - Notify the EPF device that the EPC device has received
+ *			  the PME from the Root complex
+ * @epc: the EPC device that received the PME
+ * @data: Data for the PME notifier
+ *
+ * Invoke to Notify the EPF device that the EPC device has received the Power
+ * Management Event (PME) from the Root complex
+ */
+void pci_epc_pme_notify(struct pci_epc *epc, void *data)
+{
+	if (!epc || IS_ERR(epc))
+		return;
+
+	atomic_notifier_call_chain(&epc->notifier, PME, data);
+}
+EXPORT_SYMBOL_GPL(pci_epc_pme_notify);
+
 /**
  * pci_epc_destroy() - destroy the EPC device
  * @epc: the EPC device that has to be destroyed
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index 6c2cff33f670..37dbcade1780 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -205,6 +205,7 @@  void pci_epc_linkup(struct pci_epc *epc);
 void pci_epc_linkdown(struct pci_epc *epc);
 void pci_epc_init_notify(struct pci_epc *epc);
 void pci_epc_bme_notify(struct pci_epc *epc);
+void pci_epc_pme_notify(struct pci_epc *epc, void *data);
 void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
 			enum pci_epc_interface_type type);
 int pci_epc_write_header(struct pci_epc *epc, u8 func_no,
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 063a59a58e3c..c162a73eb836 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -22,6 +22,7 @@  enum pci_notify_event {
 	LINK_UP,
 	LINK_DOWN,
 	BME,
+	PME,
 };
 
 enum pci_barno {