Linux Documentation
 help / color / mirror / Atom feed
From: Aravind Thokala <aravind.thokala@amd.com>
To: <mdf@kernel.org>, <yilun.xu@intel.com>, <trix@redhat.com>,
	<sumit.semwal@linaro.org>, <christian.koenig@amd.com>
Cc: <corbet@lwn.net>, <skhan@linuxfoundation.org>,
	<linux-kernel@vger.kernel.org>, <linux-fpga@vger.kernel.org>,
	<linux-media@vger.kernel.org>, <dri-devel@lists.freedesktop.org>,
	<linaro-mm-sig@lists.linaro.org>, <linux-doc@vger.kernel.org>,
	<git@amd.com>, <aravind.thokala@amd.com>,
	<nava.kishore.manne@amd.com>
Subject: [PATCH 2/2] fpga: versal: add dma-buf programming support
Date: Sun, 16 Aug 2026 20:37:34 +0530	[thread overview]
Message-ID: <20260816150734.2092802-3-aravind.thokala@amd.com> (raw)
In-Reply-To: <20260816150734.2092802-1-aravind.thokala@amd.com>

The existing .write callback allocates a DMA-coherent buffer and
copies the image into it before passing the address to firmware. With
dma-buf, the buffer is already DMA-mapped by userspace.

Add a .write_sg callback that extracts the DMA address directly from
the scatter-gather table and passes it to zynqmp_pm_load_pdi(),
avoiding the intermediate copy. Register the dma-buf interface in
probe with devres-managed cleanup.

Co-developed-by: Nava kishore Manne <nava.kishore.manne@amd.com>
Signed-off-by: Nava kishore Manne <nava.kishore.manne@amd.com>
Signed-off-by: Aravind Thokala <aravind.thokala@amd.com>
---
 drivers/fpga/versal-fpga.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/fpga/versal-fpga.c b/drivers/fpga/versal-fpga.c
index e6189106c468..bdaa15a6c991 100644
--- a/drivers/fpga/versal-fpga.c
+++ b/drivers/fpga/versal-fpga.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/dma-mapping.h>
+#include <linux/fpga/fpga-dmabuf.h>
 #include <linux/fpga/fpga-mgr.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
@@ -37,11 +38,34 @@ static int versal_fpga_ops_write(struct fpga_manager *mgr,
 	return ret;
 }
 
+static int versal_fpga_ops_write_sg(struct fpga_manager *mgr,
+				    struct sg_table *sgt)
+{
+	dma_addr_t dma_addr;
+
+	/* zynqmp_pm_load_pdi() takes a single base address */
+	if (sgt->nents != 1) {
+		dev_err(&mgr->dev, "dma-buf has %u segments, need exactly 1\n",
+			sgt->nents);
+		return -EINVAL;
+	}
+
+	dma_addr = sg_dma_address(sgt->sgl);
+
+	return zynqmp_pm_load_pdi(PDI_SRC_DDR, dma_addr);
+}
+
 static const struct fpga_manager_ops versal_fpga_ops = {
 	.write_init = versal_fpga_ops_write_init,
 	.write = versal_fpga_ops_write,
+	.write_sg = versal_fpga_ops_write_sg,
 };
 
+static void versal_fpga_dmabuf_remove(void *data)
+{
+	fpga_dmabuf_unregister(data);
+}
+
 static int versal_fpga_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -56,7 +80,14 @@ static int versal_fpga_probe(struct platform_device *pdev)
 
 	mgr = devm_fpga_mgr_register(dev, "Xilinx Versal FPGA Manager",
 				     &versal_fpga_ops, NULL);
-	return PTR_ERR_OR_ZERO(mgr);
+	if (IS_ERR(mgr))
+		return PTR_ERR(mgr);
+
+	ret = fpga_dmabuf_register(mgr);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, versal_fpga_dmabuf_remove, mgr);
 }
 
 static const struct of_device_id versal_fpga_of_match[] = {
-- 
2.34.1


      parent reply	other threads:[~2026-08-16 15:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-16 15:07 [PATCH 0/2] fpga: add dma-buf based FPGA programming interface Aravind Thokala
2026-08-16 15:07 ` [PATCH 1/2] fpga: Add dma-buf interface for FPGA programming Aravind Thokala
2026-08-16 15:07 ` Aravind Thokala [this message]

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=20260816150734.2092802-3-aravind.thokala@amd.com \
    --to=aravind.thokala@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=corbet@lwn.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=git@amd.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=nava.kishore.manne@amd.com \
    --cc=skhan@linuxfoundation.org \
    --cc=sumit.semwal@linaro.org \
    --cc=trix@redhat.com \
    --cc=yilun.xu@intel.com \
    /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