mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4] MIPS: dma: random fixes and improvements
@ 2023-02-10 14:47 Denis Orlov
  2023-02-10 14:47 ` [PATCH 1/4] MIPS: dma: fix nullptr handling in dma_free_coherent Denis Orlov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Denis Orlov @ 2023-02-10 14:47 UTC (permalink / raw)
  To: barebox; +Cc: Denis Orlov

Denis Orlov (4):
  MIPS: dma: fix nullptr handling in dma_free_coherent
  MIPS: dma: remove unnecessary ifdefs
  MIPS: dma: add arch-specific dma_alloc() implementation
  MIPS: dma: simplify source structure

 arch/mips/include/asm/dma-mapping.h | 40 ---------------------------
 arch/mips/include/asm/dma.h         | 43 ++++++++++++++++++++++++++++-
 arch/mips/lib/dma-default.c         |  8 ------
 3 files changed, 42 insertions(+), 49 deletions(-)
 delete mode 100644 arch/mips/include/asm/dma-mapping.h

-- 
2.30.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] MIPS: dma: fix nullptr handling in dma_free_coherent
  2023-02-10 14:47 [PATCH 0/4] MIPS: dma: random fixes and improvements Denis Orlov
@ 2023-02-10 14:47 ` Denis Orlov
  2023-02-10 14:47 ` [PATCH 2/4] MIPS: dma: remove unnecessary ifdefs Denis Orlov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Denis Orlov @ 2023-02-10 14:47 UTC (permalink / raw)
  To: barebox; +Cc: Denis Orlov

It is not an error to pass a null pointer to free() and as such it seems
that dma_free_coherent() should be able to handle this situation too.
Currently, if CONFIG_MMU option is enabled, we would convert this null
pointer into a pointer to the beginning of CKSEG0 memory segment before
passing it to free(), actually trying to deallocate stuff.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 arch/mips/include/asm/dma-mapping.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h
index 8e6ea08168..9f6ec03e3b 100644
--- a/arch/mips/include/asm/dma-mapping.h
+++ b/arch/mips/include/asm/dma-mapping.h
@@ -31,7 +31,7 @@ static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
 static inline void dma_free_coherent(void *vaddr, dma_addr_t dma_handle,
 				     size_t size)
 {
-	if (IS_ENABLED(CONFIG_MMU))
+	if (IS_ENABLED(CONFIG_MMU) && vaddr)
 		free((void *)CKSEG0ADDR(vaddr));
 	else
 		free(vaddr);
-- 
2.30.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] MIPS: dma: remove unnecessary ifdefs
  2023-02-10 14:47 [PATCH 0/4] MIPS: dma: random fixes and improvements Denis Orlov
  2023-02-10 14:47 ` [PATCH 1/4] MIPS: dma: fix nullptr handling in dma_free_coherent Denis Orlov
@ 2023-02-10 14:47 ` Denis Orlov
  2023-02-10 14:47 ` [PATCH 3/4] MIPS: dma: add arch-specific dma_alloc() implementation Denis Orlov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Denis Orlov @ 2023-02-10 14:47 UTC (permalink / raw)
  To: barebox; +Cc: Denis Orlov

We do not support any MIPS CPUs that are not MIPS32/MIPS64, so there is
no reason to check for those.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 arch/mips/lib/dma-default.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/mips/lib/dma-default.c b/arch/mips/lib/dma-default.c
index fbe627c24c..48176e5d28 100644
--- a/arch/mips/lib/dma-default.c
+++ b/arch/mips/lib/dma-default.c
@@ -6,8 +6,6 @@
 #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)
 {
@@ -28,12 +26,6 @@ static inline void __dma_sync_mips(unsigned long addr, size_t size,
 		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(dma_addr_t address, size_t size,
 			     enum dma_data_direction dir)
-- 
2.30.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] MIPS: dma: add arch-specific dma_alloc() implementation
  2023-02-10 14:47 [PATCH 0/4] MIPS: dma: random fixes and improvements Denis Orlov
  2023-02-10 14:47 ` [PATCH 1/4] MIPS: dma: fix nullptr handling in dma_free_coherent Denis Orlov
  2023-02-10 14:47 ` [PATCH 2/4] MIPS: dma: remove unnecessary ifdefs Denis Orlov
@ 2023-02-10 14:47 ` Denis Orlov
  2023-02-10 14:47 ` [PATCH 4/4] MIPS: dma: simplify source structure Denis Orlov
  2023-02-13  9:02 ` [PATCH 0/4] MIPS: dma: random fixes and improvements Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Denis Orlov @ 2023-02-10 14:47 UTC (permalink / raw)
  To: barebox; +Cc: Denis Orlov

DMA allocations should be aligned on a cache line size, at least on
cache non-coherent MIPS systems. Instead of using some hardcoded value
for an alignment from a generic implementation (which may be wrong for
us), we can get cache info from 'current_cpu_data' variable, so use it.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 arch/mips/include/asm/dma.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/mips/include/asm/dma.h b/arch/mips/include/asm/dma.h
index e0b4689172..49eeaac1a2 100644
--- a/arch/mips/include/asm/dma.h
+++ b/arch/mips/include/asm/dma.h
@@ -6,6 +6,18 @@
 #ifndef __ASM_DMA_H
 #define __ASM_DMA_H
 
+#include <common.h>
+#include <xfuncs.h>
+#include <asm/cpu-info.h>
+
+#define dma_alloc dma_alloc
+static inline void *dma_alloc(size_t size)
+{
+	unsigned long max_linesz = max(current_cpu_data.dcache.linesz,
+				       current_cpu_data.scache.linesz);
+	return xmemalign(max_linesz, ALIGN(size, max_linesz));
+}
+
 #include "asm/dma-mapping.h"
 
 #endif /* __ASM_DMA_H */
-- 
2.30.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] MIPS: dma: simplify source structure
  2023-02-10 14:47 [PATCH 0/4] MIPS: dma: random fixes and improvements Denis Orlov
                   ` (2 preceding siblings ...)
  2023-02-10 14:47 ` [PATCH 3/4] MIPS: dma: add arch-specific dma_alloc() implementation Denis Orlov
@ 2023-02-10 14:47 ` Denis Orlov
  2023-02-13  9:02 ` [PATCH 0/4] MIPS: dma: random fixes and improvements Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Denis Orlov @ 2023-02-10 14:47 UTC (permalink / raw)
  To: barebox; +Cc: Denis Orlov

There is no reason to keep code from 'dma-mapping.h' in a separate file,
so merge it into 'dma.h'.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 arch/mips/include/asm/dma-mapping.h | 40 -----------------------------
 arch/mips/include/asm/dma.h         | 31 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 41 deletions(-)
 delete mode 100644 arch/mips/include/asm/dma-mapping.h

diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h
deleted file mode 100644
index 9f6ec03e3b..0000000000
--- a/arch/mips/include/asm/dma-mapping.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#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>
-
-#define dma_alloc_coherent dma_alloc_coherent
-static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
-{
-	void *ret;
-
-	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);
-}
-
-#define dma_free_coherent dma_free_coherent
-static inline void dma_free_coherent(void *vaddr, dma_addr_t dma_handle,
-				     size_t size)
-{
-	if (IS_ENABLED(CONFIG_MMU) && vaddr)
-		free((void *)CKSEG0ADDR(vaddr));
-	else
-		free(vaddr);
-}
-
-#endif /* _ASM_DMA_MAPPING_H */
diff --git a/arch/mips/include/asm/dma.h b/arch/mips/include/asm/dma.h
index 49eeaac1a2..62d9c7c548 100644
--- a/arch/mips/include/asm/dma.h
+++ b/arch/mips/include/asm/dma.h
@@ -7,8 +7,12 @@
 #define __ASM_DMA_H
 
 #include <common.h>
+#include <malloc.h>
 #include <xfuncs.h>
+#include <asm/addrspace.h>
 #include <asm/cpu-info.h>
+#include <asm/io.h>
+#include <asm/types.h>
 
 #define dma_alloc dma_alloc
 static inline void *dma_alloc(size_t size)
@@ -18,6 +22,31 @@ static inline void *dma_alloc(size_t size)
 	return xmemalign(max_linesz, ALIGN(size, max_linesz));
 }
 
-#include "asm/dma-mapping.h"
+#define dma_alloc_coherent dma_alloc_coherent
+static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
+{
+	void *ret;
+
+	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);
+}
+
+#define dma_free_coherent dma_free_coherent
+static inline void dma_free_coherent(void *vaddr, dma_addr_t dma_handle,
+				     size_t size)
+{
+	if (IS_ENABLED(CONFIG_MMU) && vaddr)
+		free((void *)CKSEG0ADDR(vaddr));
+	else
+		free(vaddr);
+}
 
 #endif /* __ASM_DMA_H */
-- 
2.30.2




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] MIPS: dma: random fixes and improvements
  2023-02-10 14:47 [PATCH 0/4] MIPS: dma: random fixes and improvements Denis Orlov
                   ` (3 preceding siblings ...)
  2023-02-10 14:47 ` [PATCH 4/4] MIPS: dma: simplify source structure Denis Orlov
@ 2023-02-13  9:02 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2023-02-13  9:02 UTC (permalink / raw)
  To: Denis Orlov; +Cc: barebox

On Fri, Feb 10, 2023 at 05:47:41PM +0300, Denis Orlov wrote:
> Denis Orlov (4):
>   MIPS: dma: fix nullptr handling in dma_free_coherent
>   MIPS: dma: remove unnecessary ifdefs
>   MIPS: dma: add arch-specific dma_alloc() implementation
>   MIPS: dma: simplify source structure
> 
>  arch/mips/include/asm/dma-mapping.h | 40 ---------------------------
>  arch/mips/include/asm/dma.h         | 43 ++++++++++++++++++++++++++++-
>  arch/mips/lib/dma-default.c         |  8 ------
>  3 files changed, 42 insertions(+), 49 deletions(-)
>  delete mode 100644 arch/mips/include/asm/dma-mapping.h

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-13  9:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 14:47 [PATCH 0/4] MIPS: dma: random fixes and improvements Denis Orlov
2023-02-10 14:47 ` [PATCH 1/4] MIPS: dma: fix nullptr handling in dma_free_coherent Denis Orlov
2023-02-10 14:47 ` [PATCH 2/4] MIPS: dma: remove unnecessary ifdefs Denis Orlov
2023-02-10 14:47 ` [PATCH 3/4] MIPS: dma: add arch-specific dma_alloc() implementation Denis Orlov
2023-02-10 14:47 ` [PATCH 4/4] MIPS: dma: simplify source structure Denis Orlov
2023-02-13  9:02 ` [PATCH 0/4] MIPS: dma: random fixes and improvements Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox