public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Harsh Jain <h.jain@amd•com>
To: <srini@kernel•org>, <linux-arm-kernel@lists•infradead.org>,
	<michal.simek@amd•com>, <sarat.chand.savitala@amd•com>,
	<harish.ediga@amd•com>
Cc: Harsh Jain <h.jain@amd•com>
Subject: [PATCH 2/3] nvmem: zynqmp_nvmem: Use streaming DMA with single kmalloc block
Date: Thu, 28 May 2026 12:13:22 +0530	[thread overview]
Message-ID: <20260528064323.596195-3-h.jain@amd.com> (raw)
In-Reply-To: <20260528064323.596195-1-h.jain@amd.com>

From: Harish Ediga <harish.ediga@amd•com>

Coherent buffers are required only when the device and host update
memory in parallel, which is not the case here. Replace the coherent
buffer with the streaming DMA API and combine the two allocations
into a single kmalloc block.

Signed-off-by: Harish Ediga <harish.ediga@amd•com>
Co-developed-by: Harsh Jain <h.jain@amd•com>
Signed-off-by: Harsh Jain <h.jain@amd•com>
---
 drivers/nvmem/zynqmp_nvmem.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/nvmem/zynqmp_nvmem.c b/drivers/nvmem/zynqmp_nvmem.c
index 6be00a2be9e4..e8ab4ce23fb9 100644
--- a/drivers/nvmem/zynqmp_nvmem.c
+++ b/drivers/nvmem/zynqmp_nvmem.c
@@ -60,14 +60,13 @@ static int zynqmp_efuse_access(void *context, unsigned int offset,
 			       void *val, size_t bytes, enum efuse_access flag,
 			       unsigned int pufflag)
 {
+	size_t words = bytes / WORD_INBYTES;
 	struct device *dev = context;
 	struct xilinx_efuse *efuse;
 	dma_addr_t dma_addr;
-	dma_addr_t dma_buf;
-	size_t words = bytes / WORD_INBYTES;
-	int ret;
 	unsigned int value;
 	char *data;
+	int ret;
 
 	if (bytes % WORD_INBYTES != 0) {
 		dev_err(dev, "Bytes requested should be word aligned\n");
@@ -95,18 +94,18 @@ static int zynqmp_efuse_access(void *context, unsigned int offset,
 		}
 	}
 
-	efuse = dma_alloc_coherent(dev, sizeof(struct xilinx_efuse),
-				   &dma_addr, GFP_KERNEL);
+	efuse = kmalloc(sizeof(*efuse) + bytes, GFP_KERNEL);
 	if (!efuse)
 		return -ENOMEM;
 
-	data = dma_alloc_coherent(dev, bytes,
-				  &dma_buf, GFP_KERNEL);
-	if (!data) {
-		ret = -ENOMEM;
-		goto efuse_data_fail;
+	dma_addr = dma_map_single(dev, efuse, sizeof(*efuse) + bytes,
+				  DMA_BIDIRECTIONAL);
+	if (dma_mapping_error(dev, dma_addr)) {
+		kfree(efuse);
+		return -ENOMEM;
 	}
 
+	data = (char *)efuse + sizeof(*efuse);
 	if (flag == EFUSE_WRITE) {
 		memcpy(data, val, bytes);
 		efuse->flag = EFUSE_WRITE;
@@ -114,12 +113,18 @@ static int zynqmp_efuse_access(void *context, unsigned int offset,
 		efuse->flag = EFUSE_READ;
 	}
 
-	efuse->src = dma_buf;
+	efuse->src = dma_addr + sizeof(*efuse);
 	efuse->size = words;
 	efuse->offset = offset;
 	efuse->pufuserfuse = pufflag;
 
+	/* Sync DMA address updated after mapping*/
+	dma_sync_single_for_device(dev, dma_addr, sizeof(*efuse) + bytes,
+				   DMA_BIDIRECTIONAL);
 	zynqmp_pm_efuse_access(dma_addr, (u32 *)&ret);
+	dma_unmap_single(dev, dma_addr, sizeof(*efuse) + bytes,
+			 DMA_BIDIRECTIONAL);
+
 	if (ret != 0) {
 		if (ret == EFUSE_NOT_ENABLED) {
 			dev_err(dev, "efuse access is not enabled\n");
@@ -133,12 +138,9 @@ static int zynqmp_efuse_access(void *context, unsigned int offset,
 
 	if (flag == EFUSE_READ)
 		memcpy(val, data, bytes);
+
 efuse_access_err:
-	dma_free_coherent(dev, bytes,
-			  data, dma_buf);
-efuse_data_fail:
-	dma_free_coherent(dev, sizeof(struct xilinx_efuse),
-			  efuse, dma_addr);
+	kfree(efuse);
 
 	return ret;
 }
-- 
2.34.1



  parent reply	other threads:[~2026-05-28  6:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28  6:43 [PATCH 0/3]nvmem: zynqmp_nvmem: Cleanup and bug fixes Harsh Jain
2026-05-28  6:43 ` [PATCH 1/3] nvmem: zynqmp_nvmem: Correct error message for PUF user fuse Harsh Jain
2026-05-28  6:43 ` Harsh Jain [this message]
2026-05-28  6:43 ` [PATCH 3/3] nvmem: zynqmp_nvmem: Drop add_legacy_fixed_of_cells flag Harsh Jain

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=20260528064323.596195-3-h.jain@amd.com \
    --to=h.jain@amd$(echo .)com \
    --cc=harish.ediga@amd$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=michal.simek@amd$(echo .)com \
    --cc=sarat.chand.savitala@amd$(echo .)com \
    --cc=srini@kernel$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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