mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Cc: Peter Mamonov <pmamonov@gmail.com>
Subject: [PATCH 07/15] MIPS: implement dma_sync_* functions
Date: Mon,  7 Mar 2016 16:30:18 +0300	[thread overview]
Message-ID: <1457357426-9868-8-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1457357426-9868-1-git-send-email-antonynpavlov@gmail.com>

From: Peter Mamonov <pmamonov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 arch/mips/Kconfig                   |  1 +
 arch/mips/include/asm/dma-mapping.h | 11 ++++++-
 arch/mips/lib/Makefile              |  1 +
 arch/mips/lib/dma-default.c         | 57 +++++++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index fdf62e8..06a516d 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -6,6 +6,7 @@ config MIPS
 	select HAS_KALLSYMS
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
 	select HAVE_CONFIGURABLE_TEXT_BASE
+	select HAS_DMA
 	default y
 
 config SYS_SUPPORTS_BIG_ENDIAN
diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h
index 6395112..c71a087 100644
--- a/arch/mips/include/asm/dma-mapping.h
+++ b/arch/mips/include/asm/dma-mapping.h
@@ -1,10 +1,12 @@
 #ifndef _ASM_DMA_MAPPING_H
 #define _ASM_DMA_MAPPING_H
 
+#include <common.h>
 #include <xfuncs.h>
 #include <asm/addrspace.h>
 #include <asm/types.h>
 #include <malloc.h>
+#include <asm/io.h>
 
 static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
 {
@@ -12,16 +14,23 @@ static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
 
 	ret = xmemalign(PAGE_SIZE, size);
 
+	memset(ret, 0, size);
+
 	if (dma_handle)
 		*dma_handle = CPHYSADDR(ret);
 
+	dma_flush_range((unsigned long)ret, (unsigned long)(ret + size));
+
 	return (void *)CKSEG1ADDR(ret);
 }
 
 static inline void dma_free_coherent(void *vaddr, dma_addr_t dma_handle,
 				     size_t size)
 {
-	free(vaddr);
+	if (IS_ENABLED(CONFIG_MMU))
+		free((void *)CKSEG0ADDR(vaddr));
+	else
+		free(vaddr);
 }
 
 #endif /* _ASM_DMA_MAPPING_H */
diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile
index 43f7af7..d25d096 100644
--- a/arch/mips/lib/Makefile
+++ b/arch/mips/lib/Makefile
@@ -7,6 +7,7 @@ obj-y += cpu-probe.o
 obj-y += traps.o
 obj-y += genex.o
 obj-y += shutdown.o
+obj-y += dma-default.o
 
 obj-$(CONFIG_MIPS_OPTIMIZED_STRING_FUNCTIONS) += memcpy.o
 obj-$(CONFIG_MIPS_OPTIMIZED_STRING_FUNCTIONS) += memset.o
diff --git a/arch/mips/lib/dma-default.c b/arch/mips/lib/dma-default.c
new file mode 100644
index 0000000..9b2fe7d
--- /dev/null
+++ b/arch/mips/lib/dma-default.c
@@ -0,0 +1,57 @@
+/*
+ * (C) Copyright 2015, 2016 Peter Mamonov <pmamonov@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <dma.h>
+#include <asm/io.h>
+
+#if defined(CONFIG_CPU_MIPS32) || \
+	defined(CONFIG_CPU_MIPS64)
+static inline void __dma_sync_mips(unsigned long addr, size_t size,
+				   enum dma_data_direction direction)
+{
+	switch (direction) {
+	case DMA_TO_DEVICE:
+		dma_flush_range(addr, addr + size);
+		break;
+
+	case DMA_FROM_DEVICE:
+		dma_inv_range(addr, addr + size);
+		break;
+
+	case DMA_BIDIRECTIONAL:
+		dma_flush_range(addr, addr + size);
+		break;
+
+	default:
+		BUG();
+	}
+}
+#else
+static inline void __dma_sync_mips(void *addr, size_t size,
+	enum dma_data_direction direction)
+{
+}
+#endif
+
+void dma_sync_single_for_cpu(unsigned long address, size_t size,
+			     enum dma_data_direction dir)
+{
+	__dma_sync_mips(address, size, dir);
+}
+
+void dma_sync_single_for_device(unsigned long address, size_t size,
+				enum dma_data_direction dir)
+{
+	__dma_sync_mips(address, size, dir);
+}
-- 
2.7.0


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

  parent reply	other threads:[~2016-03-07 13:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 13:30 [PATCH 00/15] MIPS: ar9331: use cache and fix gpio Antony Pavlov
2016-03-07 13:30 ` [PATCH 01/15] MIPS: probe_scache(): use MIPS_CONF_M linux kernel macro Antony Pavlov
2016-03-07 13:30 ` [PATCH 02/15] MIPS: pbl: import cache init code from U-Boot v2016.01-212-ga3ab2ae Antony Pavlov
2016-03-07 13:30 ` [PATCH 03/15] MIPS: black-swift: pbl: init cache Antony Pavlov
2016-03-07 13:30 ` [PATCH 04/15] MIPS: tplink-mr3020: " Antony Pavlov
2016-03-07 13:30 ` [PATCH 05/15] MIPS: add initial R4000-style cache support Antony Pavlov
2016-03-09 13:28   ` Sascha Hauer
2016-03-09 14:23     ` Antony Pavlov
2016-03-09 16:12       ` Antony Pavlov
2016-03-10  8:44         ` Sascha Hauer
2016-03-07 13:30 ` [PATCH 06/15] MIPS: flush cache on shutdown Antony Pavlov
2016-03-07 13:30 ` Antony Pavlov [this message]
2016-03-07 13:30 ` [PATCH 08/15] MIPS: dtb: register only one memory bank Antony Pavlov
2016-03-07 13:30 ` [PATCH 09/15] MIPS: tplink-mr3020_defconfig: use cached memory region Antony Pavlov
2016-03-07 13:30 ` [PATCH 10/15] MIPS: black-swift_defconfig: " Antony Pavlov
2016-03-07 13:30 ` [PATCH 11/15] MIPS: ath79: pbl: add pbl_ar9331_mdio_gpio_enable macro Antony Pavlov
2016-03-07 13:30 ` [PATCH 12/15] MIPS: black-swift: enable GPIO LED Antony Pavlov
2016-03-07 13:30 ` [PATCH 13/15] MIPS: black-swift: enable GPIO key Antony Pavlov
2016-03-07 13:30 ` [PATCH 14/15] MIPS: black-swift_defconfig: enable gpio-related stuff Antony Pavlov
2016-03-07 13:30 ` [PATCH 15/15] MIPS: tplink-mr3020: fix "WPS" and "3G" LEDs Antony Pavlov
2016-03-09  7:31 ` [PATCH 00/15] MIPS: ar9331: use cache and fix gpio Sascha Hauer
2016-03-09  8:45   ` Yegor Yefremov
2016-03-09 10:34     ` Antony Pavlov

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=1457357426-9868-8-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=pmamonov@gmail.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