From: Frank Li <Frank.Li@nxp.com>
To: tglx@linutronix.de
Cc: aisheng.dong@nxp.com, bhelgaas@google.com,
devicetree@vger.kernel.org, festevam@gmail.com, frank.li@nxp.com,
imx@lists.linux.dev, jdmason@kudzu.us, kernel@pengutronix.de,
kishon@ti.com, krzysztof.kozlowski+dt@linaro.org, kw@linux.com,
linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
lorenzo.pieralisi@arm.com, lpieralisi@kernel.org,
manivannan.sadhasivam@linaro.org, maz@kernel.org,
ntb@lists.linux.dev, peng.fan@nxp.com, robh+dt@kernel.org,
s.hauer@pengutronix.de, shawnguo@kernel.org
Subject: [PATCH 1/3] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller
Date: Wed, 26 Apr 2023 16:34:34 -0400 [thread overview]
Message-ID: <20230426203436.1277307-2-Frank.Li@nxp.com> (raw)
In-Reply-To: <20230426203436.1277307-1-Frank.Li@nxp.com>
This commit introduces a common method for sending messages from the Root Complex
(RC) to the Endpoint (EP) by utilizing the platform MSI interrupt controller,
such as ARM GIC, as an EP doorbell. Maps the memory assigned for the BAR region
by the PCI host to the message address of the platform MSI interrupt controller
in the PCI EP. As a result, when the PCI RC writes to the BAR region, it triggers
an IRQ at the EP. This implementation serves as a common method for all endpoint
function drivers.
However, it currently supports only one EP physical function due to limitations
in ARM MSI/IMS readiness.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
drivers/pci/endpoint/pci-epf-core.c | 109 ++++++++++++++++++++++++++++
include/linux/pci-epf.h | 16 ++++
2 files changed, 125 insertions(+)
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 355a6f56fcea..94ac82bf84c5 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -6,10 +6,12 @@
* Author: Kishon Vijay Abraham I <kishon@ti.com>
*/
+#include <linux/irqreturn.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include <linux/msi.h>
#include <linux/pci-epc.h>
#include <linux/pci-epf.h>
@@ -300,6 +302,113 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
}
EXPORT_SYMBOL_GPL(pci_epf_alloc_space);
+static enum irqreturn pci_epf_interrupt_handler(int irq, void *data)
+{
+ struct pci_epf *epf = data;
+
+ if (epf->event_ops && epf->event_ops->doorbell)
+ epf->event_ops->doorbell(epf, irq - epf->virq_base);
+
+ return IRQ_HANDLED;
+}
+
+static void pci_epf_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg)
+{
+ struct pci_epc *epc = container_of(desc->dev, struct pci_epc, dev);
+ struct pci_epf *epf;
+
+ /* Todo: Need check correct epf if multi epf supported */
+ list_for_each_entry(epf, &epc->pci_epf, list) {
+ if (epf->msg && desc->msi_index < epf->num_msgs)
+ epf->msg[desc->msi_index] = *msg;
+ }
+}
+
+int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_msgs)
+{
+ struct irq_domain *domain;
+ struct pci_epc *epc;
+ struct device *dev;
+ int virq;
+ int ret;
+ int i;
+
+ epc = epf->epc;
+ dev = &epc->dev;
+
+ /*
+ * Current only support 1 function.
+ * PCI IMS(interrupt message store) ARM support have not been
+ * ready yet.
+ */
+ if (epc->function_num_map != 1)
+ return -EOPNOTSUPP;
+
+ domain = dev_get_msi_domain(dev->parent);
+ if (!domain)
+ return -EOPNOTSUPP;
+ dev_set_msi_domain(dev, domain);
+
+ /* use parent of_node to get device id information */
+ dev->of_node = dev->parent->of_node;
+
+ epf->msg = kcalloc(num_msgs, sizeof(struct msi_msg), GFP_KERNEL);
+ if (!epf->msg)
+ return -ENOMEM;
+
+ epf->num_msgs = num_msgs;
+
+ ret = platform_msi_domain_alloc_irqs(dev, num_msgs, pci_epf_write_msi_msg);
+ if (ret) {
+ dev_err(dev, "Can't allocate MSI from system MSI controller\n");
+ goto err_mem;
+ }
+
+ for (i = 0; i < num_msgs; i++) {
+ virq = msi_get_virq(dev, i);
+ if (i == 0)
+ epf->virq_base = virq;
+
+ ret = request_irq(virq, pci_epf_interrupt_handler, 0,
+ "pci-epf-doorbell", epf);
+
+ if (ret) {
+ dev_err(dev, "Failure request doorbell IRQ\n");
+ goto err_irq;
+ }
+ }
+
+ epf->num_msgs = num_msgs;
+ return ret;
+
+err_irq:
+ platform_msi_domain_free_irqs(dev);
+err_mem:
+ kfree(epf->msg);
+ epf->msg = NULL;
+ epf->num_msgs = 0;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell);
+
+void pci_epf_free_doorbell(struct pci_epf *epf)
+{
+ struct pci_epc *epc;
+ int i;
+
+ epc = epf->epc;
+
+ for (i = 0; i < epf->num_msgs; i++)
+ free_irq(epf->virq_base + i, epf);
+
+ platform_msi_domain_free_irqs(&epc->dev);
+ kfree(epf->msg);
+ epf->msg = NULL;
+ epf->num_msgs = 0;
+}
+EXPORT_SYMBOL_GPL(pci_epf_free_doorbell);
+
static void pci_epf_remove_cfs(struct pci_epf_driver *driver)
{
struct config_group *group, *tmp;
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index b8441db2fa52..e187e3ee48d2 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -75,6 +75,7 @@ struct pci_epf_ops {
struct pci_epc_event_ops {
int (*core_init)(struct pci_epf *epf);
int (*link_up)(struct pci_epf *epf);
+ int (*doorbell)(struct pci_epf *epf, int index);
};
/**
@@ -173,6 +174,9 @@ struct pci_epf {
unsigned long vfunction_num_map;
struct list_head pci_vepf;
const struct pci_epc_event_ops *event_ops;
+ struct msi_msg *msg;
+ u16 num_msgs;
+ int virq_base;
};
/**
@@ -216,4 +220,16 @@ int pci_epf_bind(struct pci_epf *epf);
void pci_epf_unbind(struct pci_epf *epf);
int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf);
+int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums);
+void pci_epf_free_doorbell(struct pci_epf *epf);
+
+static inline struct msi_msg *epf_get_msg(struct pci_epf *epf)
+{
+ return epf->msg;
+}
+
+static inline u16 epf_get_msg_num(struct pci_epf *epf)
+{
+ return epf->num_msgs;
+}
#endif /* __LINUX_PCI_EPF_H */
--
2.34.1
next prev parent reply other threads:[~2023-04-26 20:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 20:34 [PATCH 0/3] Add RC-to-EP doorbell with platform MSI controller Frank Li
2023-04-26 20:34 ` Frank Li [this message]
2023-09-02 4:52 ` [PATCH 1/3] PCI: endpoint: Add RC-to-EP doorbell support using " Manivannan Sadhasivam
2023-09-02 4:53 ` Manivannan Sadhasivam
2023-09-06 4:24 ` Frank Li
2023-09-06 12:26 ` Manivannan Sadhasivam
2023-09-06 14:33 ` Frank Li
2023-09-06 14:52 ` Manivannan Sadhasivam
2023-09-06 15:00 ` Frank Li
2023-09-06 15:27 ` Manivannan Sadhasivam
2023-09-06 15:36 ` Frank Li
2023-04-26 20:34 ` [PATCH 2/3] misc: pci_endpoint_test: Add doorbell test case Frank Li
2023-09-02 5:11 ` Manivannan Sadhasivam
2023-04-26 20:34 ` [PATCH 3/3] tools: PCI: Add 'B' option for test doorbell Frank Li
2023-05-12 14:45 ` [PATCH 0/3] Add RC-to-EP doorbell with platform MSI controller Frank Li
2023-06-12 16:17 ` Frank Li
2023-07-17 14:06 ` Frank Li
2023-08-24 19:01 ` Frank Li
2023-08-25 8:34 ` Manivannan Sadhasivam
2023-08-30 7:36 ` Li Chen
2023-08-30 18:27 ` Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230426203436.1277307-2-Frank.Li@nxp.com \
--to=frank.li@nxp.com \
--cc=aisheng.dong@nxp.com \
--cc=bhelgaas@google.com \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=jdmason@kudzu.us \
--cc=kernel@pengutronix.de \
--cc=kishon@ti.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kw@linux.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=maz@kernel.org \
--cc=ntb@lists.linux.dev \
--cc=peng.fan@nxp.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).