public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Andrew Davis <afd@ti.com>
To: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	Vignesh Raghavendra <vigneshr@ti.com>, <u-boot@lists.denx.de>
Cc: Andrew Davis <afd@ti.com>
Subject: [PATCH 1/3] dma: Use dma-mapping for cache ops and sync after write
Date: Fri, 7 Oct 2022 12:11:11 -0500	[thread overview]
Message-ID: <20221007171113.31577-1-afd@ti.com> (raw)

The DMA'd memory area needs cleaned and invalidated after the DMA
write so that any stale cache lines do not mask new data.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/dma/dma-uclass.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c
index 012609bb53..70f06f1f09 100644
--- a/drivers/dma/dma-uclass.c
+++ b/drivers/dma/dma-uclass.c
@@ -19,6 +19,7 @@
 #include <asm/cache.h>
 #include <dm/read.h>
 #include <dma-uclass.h>
+#include <linux/dma-mapping.h>
 #include <dt-structs.h>
 #include <errno.h>
 
@@ -235,6 +236,8 @@ int dma_memcpy(void *dst, void *src, size_t len)
 {
 	struct udevice *dev;
 	const struct dma_ops *ops;
+	dma_addr_t destination;
+	dma_addr_t source;
 	int ret;
 
 	ret = dma_get_device(DMA_SUPPORTS_MEM_TO_MEM, &dev);
@@ -245,11 +248,17 @@ int dma_memcpy(void *dst, void *src, size_t len)
 	if (!ops->transfer)
 		return -ENOSYS;
 
-	/* Invalidate the area, so no writeback into the RAM races with DMA */
-	invalidate_dcache_range((unsigned long)dst, (unsigned long)dst +
-				roundup(len, ARCH_DMA_MINALIGN));
+	/* Clean the areas, so no writeback into the RAM races with DMA */
+	destination = dma_map_single(dst, len, DMA_FROM_DEVICE);
+	source = dma_map_single(src, len, DMA_TO_DEVICE);
 
-	return ops->transfer(dev, DMA_MEM_TO_MEM, dst, src, len);
+	ret = ops->transfer(dev, DMA_MEM_TO_MEM, dst, src, len);
+
+	/* Clean+Invalidate the areas after, so we can see DMA'd data */
+	dma_unmap_single(destination, len, DMA_FROM_DEVICE);
+	dma_unmap_single(source, len, DMA_TO_DEVICE);
+
+	return ret;
 }
 
 UCLASS_DRIVER(dma) = {
-- 
2.37.3


             reply	other threads:[~2022-10-07 17:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07 17:11 Andrew Davis [this message]
2022-10-07 17:11 ` [PATCH 2/3] dma: ti-edma3: Add DMA map operations before and after transfers Andrew Davis
2022-10-18 22:15   ` Tom Rini
2022-10-07 17:11 ` [PATCH 3/3] dma: Transfer dma_ops should use DMA address types Andrew Davis
2022-10-18 22:15   ` Tom Rini
2022-10-18 22:15 ` [PATCH 1/3] dma: Use dma-mapping for cache ops and sync after write Tom Rini

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=20221007171113.31577-1-afd@ti.com \
    --to=afd@ti.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.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