mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Denis Orlov <denorl2009@gmail.com>,
	str@pengutronix.de, lst@pengutronix.de,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/4] dma: factor out dma map generic implementations into file
Date: Wed, 29 Nov 2023 07:17:55 +0100	[thread overview]
Message-ID: <20231129061758.1781732-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231129061758.1781732-1-a.fatoum@pengutronix.de>

In preparation for adding optional debugging code for the DMA mapping
API, move the definition out of the header file into a source file.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/dma/Makefile |  1 +
 drivers/dma/map.c    | 32 +++++++++++++++++++++++
 include/dma.h        | 61 ++++++++++++++------------------------------
 3 files changed, 52 insertions(+), 42 deletions(-)
 create mode 100644 drivers/dma/map.c

diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index 8e1aac9f6f67..e45476c23f14 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_HAS_DMA)		+= map.o
 obj-$(CONFIG_MXS_APBH_DMA)	+= apbh_dma.o
diff --git a/drivers/dma/map.c b/drivers/dma/map.c
new file mode 100644
index 000000000000..270a4899fd05
--- /dev/null
+++ b/drivers/dma/map.c
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#include <dma.h>
+
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
+			     size_t size, enum dma_data_direction dir)
+{
+	void *ptr = dma_to_cpu(dev, address);
+
+	arch_sync_dma_for_cpu(ptr, size, dir);
+}
+
+void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
+					      size_t size, enum dma_data_direction dir)
+{
+	void *ptr = dma_to_cpu(dev, address);
+
+	arch_sync_dma_for_device(ptr, size, dir);
+}
+
+dma_addr_t dma_map_single(struct device *dev, void *ptr,
+					size_t size, enum dma_data_direction dir)
+{
+	arch_sync_dma_for_device(ptr, size, dir);
+
+	return cpu_to_dma(dev, ptr);
+}
+
+void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
+				    size_t size, enum dma_data_direction dir)
+{
+	dma_sync_single_for_cpu(dev, dma_addr, size, dir);
+}
diff --git a/include/dma.h b/include/dma.h
index 2a09b747d1e2..6eef55a7325d 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -68,8 +68,6 @@ static inline void *dma_to_cpu(struct device *dev, dma_addr_t addr)
 	return phys_to_virt(addr);
 }
 
-#ifndef __PBL__
-/* streaming DMA - implement the below calls to support HAS_DMA */
 #ifndef arch_sync_dma_for_cpu
 void arch_sync_dma_for_cpu(void *vaddr, size_t size,
 			   enum dma_data_direction dir);
@@ -79,57 +77,36 @@ void arch_sync_dma_for_cpu(void *vaddr, size_t size,
 void arch_sync_dma_for_device(void *vaddr, size_t size,
 			      enum dma_data_direction dir);
 #endif
+
+#ifndef __PBL__
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
+			     size_t size, enum dma_data_direction dir);
+
+void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
+				size_t size, enum dma_data_direction dir);
 #else
-#ifndef arch_sync_dma_for_cpu
 /*
  * assumes buffers are in coherent/uncached memory, e.g. because
  * MMU is only enabled in barebox_arm_entry which hasn't run yet.
  */
-static inline void arch_sync_dma_for_cpu(void *vaddr, size_t size,
-					 enum dma_data_direction dir)
+static inline void dma_sync_single_for_cpu(void *vaddr, size_t size,
+					   enum dma_data_direction dir)
+{
+	barrier_data(vaddr);
+}
+
+static inline void dma_sync_single_for_device(void *vaddr, size_t size,
+					      enum dma_data_direction dir)
 {
 	barrier_data(vaddr);
 }
 #endif
 
-#ifndef arch_sync_dma_for_device
-static inline void arch_sync_dma_for_device(void *vaddr, size_t size,
-					    enum dma_data_direction dir)
-{
-	barrier_data(vaddr);
-}
-#endif
-#endif
+dma_addr_t dma_map_single(struct device *dev, void *ptr,
+			  size_t size, enum dma_data_direction dir);
 
-static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
-					   size_t size, enum dma_data_direction dir)
-{
-	void *ptr = dma_to_cpu(dev, address);
-
-	arch_sync_dma_for_cpu(ptr, size, dir);
-}
-
-static inline void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
-					      size_t size, enum dma_data_direction dir)
-{
-	void *ptr = dma_to_cpu(dev, address);
-
-	arch_sync_dma_for_device(ptr, size, dir);
-}
-
-static inline dma_addr_t dma_map_single(struct device *dev, void *ptr,
-					size_t size, enum dma_data_direction dir)
-{
-	arch_sync_dma_for_device(ptr, size, dir);
-
-	return cpu_to_dma(dev, ptr);
-}
-
-static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
-				    size_t size, enum dma_data_direction dir)
-{
-	dma_sync_single_for_cpu(dev, dma_addr, size, dir);
-}
+void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
+		      size_t size, enum dma_data_direction dir);
 
 #ifndef dma_alloc_coherent
 void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle);
-- 
2.39.2




  reply	other threads:[~2023-11-29  6:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-29  6:17 [PATCH 0/4] dma: catch mistakes with CONFIG_DMA_API_DEBUG Ahmad Fatoum
2023-11-29  6:17 ` Ahmad Fatoum [this message]
2023-12-05  8:37   ` [PATCH 1/4] dma: factor out dma map generic implementations into file Sascha Hauer
2023-12-05  8:42     ` Ahmad Fatoum
2023-11-29  6:17 ` [PATCH 2/4] dma: add DMA API debugging support Ahmad Fatoum
2023-11-29  6:17 ` [PATCH 3/4] mci: core: remove broken, unneeded write bounce buffer Ahmad Fatoum
2023-11-29  6:17 ` [PATCH 4/4] mci: stm32_sdmmc2: correct usage of DMA API Ahmad Fatoum
2023-12-05  7:52 ` [PATCH 0/4] dma: catch mistakes with CONFIG_DMA_API_DEBUG Sascha Hauer

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=20231129061758.1781732-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=denorl2009@gmail.com \
    --cc=lst@pengutronix.de \
    --cc=str@pengutronix.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