All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH 4/9] dma: move dma_map/unmap_single from ARM to common code
Date: Sun, 28 Feb 2021 20:08:31 +0100	[thread overview]
Message-ID: <20210228190836.1451663-4-ahmad@a3f.at> (raw)
In-Reply-To: <20210228190836.1451663-1-ahmad@a3f.at>

There's nothing ARM specific about these functions. Move them to a
common location, so other arches can use them as well.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 arch/arm/cpu/mmu-common.c | 41 +-------------------------------------
 drivers/dma/Makefile      |  1 +
 drivers/dma/map.c         | 42 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 40 deletions(-)
 create mode 100644 drivers/dma/map.c

diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index 287622b20399..5cc5138cfa3d 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -10,27 +10,6 @@
 #include <memory.h>
 #include "mmu.h"
 
-
-static inline dma_addr_t cpu_to_dma(struct device_d *dev, unsigned long cpu_addr)
-{
-	dma_addr_t dma_addr = cpu_addr;
-
-	if (dev)
-		dma_addr -= dev->dma_offset;
-
-	return dma_addr;
-}
-
-static inline unsigned long dma_to_cpu(struct device_d *dev, dma_addr_t addr)
-{
-	unsigned long cpu_addr = addr;
-
-	if (dev)
-		cpu_addr += dev->dma_offset;
-
-	return cpu_addr;
-}
-
 void dma_sync_single_for_cpu(dma_addr_t address, size_t size,
 			     enum dma_data_direction dir)
 {
@@ -41,24 +20,6 @@ void dma_sync_single_for_cpu(dma_addr_t address, size_t size,
 		dma_inv_range((void *)address, size);
 }
 
-dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
-			  enum dma_data_direction dir)
-{
-	unsigned long addr = (unsigned long)ptr;
-
-	dma_sync_single_for_device(addr, size, dir);
-
-	return cpu_to_dma(dev, addr);
-}
-
-void dma_unmap_single(struct device_d *dev, dma_addr_t dma_addr, size_t size,
-		      enum dma_data_direction dir)
-{
-	unsigned long addr = dma_to_cpu(dev, dma_addr);
-
-	dma_sync_single_for_cpu(addr, size, dir);
-}
-
 void *dma_alloc_map(size_t size, dma_addr_t *dma_handle, unsigned flags)
 {
 	void *ret;
@@ -108,4 +69,4 @@ static int mmu_init(void)
 
 	return 0;
 }
-mmu_initcall(mmu_init);
\ No newline at end of file
+mmu_initcall(mmu_init);
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index 7a3a3b2bd85d..49d6d6573f4f 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_MXS_APBH_DMA)	+= apbh_dma.o
+obj-$(CONFIG_HAS_DMA)		+= map.o
diff --git a/drivers/dma/map.c b/drivers/dma/map.c
new file mode 100644
index 000000000000..a3e1b3b5b527
--- /dev/null
+++ b/drivers/dma/map.c
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* SPDX-FileCopyrightText: 2012 Marc Kleine-Budde <mkl@pengutronix.de> */
+
+#include <dma.h>
+
+static inline dma_addr_t cpu_to_dma(struct device_d *dev, unsigned long cpu_addr)
+{
+	dma_addr_t dma_addr = cpu_addr;
+
+	if (dev)
+		dma_addr -= dev->dma_offset;
+
+	return dma_addr;
+}
+
+static inline unsigned long dma_to_cpu(struct device_d *dev, dma_addr_t addr)
+{
+	unsigned long cpu_addr = addr;
+
+	if (dev)
+		cpu_addr += dev->dma_offset;
+
+	return cpu_addr;
+}
+
+dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
+			  enum dma_data_direction dir)
+{
+	unsigned long addr = (unsigned long)ptr;
+
+	dma_sync_single_for_device(addr, size, dir);
+
+	return cpu_to_dma(dev, addr);
+}
+
+void dma_unmap_single(struct device_d *dev, dma_addr_t dma_addr, size_t size,
+		      enum dma_data_direction dir)
+{
+	unsigned long addr = dma_to_cpu(dev, dma_addr);
+
+	dma_sync_single_for_cpu(addr, size, dir);
+}
-- 
2.30.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-02-28 19:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-28 19:08 [PATCH 1/9] virtio: align virtio_config_ops::generation return type with Linux Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 2/9] virtio: remove unused, left-over, virtio_config_ops::set_features Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 3/9] hw_random: virtio: simplify code Ahmad Fatoum
2021-02-28 19:08 ` Ahmad Fatoum [this message]
2021-03-03 12:08   ` [PATCH 4/9] dma: move dma_map/unmap_single from ARM to common code Sascha Hauer
2021-03-03 16:12   ` [PATCH] " Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 5/9] virtio: ring: fix erroneous behavior around caches and MMU Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 6/9] virtio: fix support for big-endian clients Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 7/9] PCI: port Linux pci_find_capability Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 8/9] virtio: support virtio-based device drivers over PCI Ahmad Fatoum
2021-02-28 19:08 ` [PATCH 9/9] virtio: virtio-pci: restrict MIPS support to MMU configuration Ahmad Fatoum
2021-03-02 14:28   ` Antony Pavlov
2021-03-03 17:10     ` Ahmad Fatoum
2021-03-01 16:29 ` [PATCH 1/9] virtio: align virtio_config_ops::generation return type with Linux 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=20210228190836.1451663-4-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=barebox@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.