Skip to contentSkip to conversation

MIPS: add empty arch/clk.h

PATCH New Ramon Fried 2 participants 7 messages Jun 10, 2019 – Oct 18, 2019 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 MIPS: add empty arch/clk.h

The file is needed for compilation of various
drivers (IE. macb).
Add empty implementation so compilation succeeds.

---
v2: Moved the new file to the correct location.

 arch/mips/include/asm/arch/clk.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 arch/mips/include/asm/arch/clk.h
arch/mips/include/asm/arch/clk.h new file +11 -0
new file mode 100644
index 0000000000..c01e0973cd
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) Ramon Fried <[email protected]>
+ */
+
+#ifndef __ASM_MIPS_ARCH_CLK_H
+#define __ASM_MIPS_ARCH_CLK_H
+
+/* Note: This is a placeholder header for driver compilation. */
+
+#endif
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 2/2 MIPS: add dma-mapping.h implementation

add implementation for dma_alloc_coherent(), dma_free_coherent(), dma_map_single() and dma_free_single()

---
v2: fix warning caused by missing casts.

 arch/mips/include/asm/dma-mapping.h | 48 +++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 arch/mips/include/asm/dma-mapping.h
arch/mips/include/asm/dma-mapping.h new file +48 -0
new file mode 100644
index 0000000000..387427c13b
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2019
+ * Ramon Fried <[email protected]>
+ */
+
+#ifndef __ASM_MIPS_DMA_MAPPING_H
+#define __ASM_MIPS_DMA_MAPPING_H
+
+#include <linux/dma-direction.h>
+#include <asm/addrspace.h>
+#define	dma_mapping_error(x, y)	0
+
+static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
+{
+	void *vaddr = memalign(ARCH_DMA_MINALIGN,
+			       ROUND(len, ARCH_DMA_MINALIGN));
+
+	*handle = CPHYSADDR((unsigned long)vaddr);
+	return (void *)(CKSEG1ADDR((unsigned long)vaddr));
+}
+
+static inline void dma_free_coherent(void *addr)
+{
+	free((void *)CPHYSADDR((unsigned long)addr));
+}
+
+static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
+					   enum dma_data_direction dir)
+{
+	unsigned long dma_addr = CPHYSADDR((unsigned long)vaddr);
+
+	if (dir == DMA_TO_DEVICE)
+		flush_dcache_range((unsigned long)vaddr,
+				   (unsigned long)vaddr + len);
+	if (dir == DMA_FROM_DEVICE)
+		invalidate_dcache_range((unsigned long)vaddr,
+					(unsigned long)vaddr + len);
+
+	return dma_addr;
+}
+
+static inline void dma_unmap_single(volatile void *vaddr, size_t len,
+				    unsigned long paddr)
+{
+}
+
+#endif /* __ASM_MIPS_DMA_MAPPING_H */
Signature · 1 line
2.21.0
#3 lore raw

PATCH 1/1 MIPS: add compile time definition of L2 cache size

In reply to Ramon Fried

If configuration is set to skip low level init, automatic probe of L2 cache size is not performed and the size is set to 0. Flushing or invalidating the L2 cache will fail in this case.

Add a static configuration (SYS_DCACHE_LINE_SIZE) with default set to 0.

---
 arch/mips/Kconfig     | 10 +++++++++-
 arch/mips/lib/cache.c |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)
arch/mips/Kconfig +9 -1
index 5cb9bdf2ee..235bb5b7e6 100644
@@ -408,9 +408,17 @@ config SYS_ICACHE_LINE_SIZE
 	help
 	  The size of L1 Icache lines, if known at compile time.
 
+config SYS_SCACHE_LINE_SIZE
+	int
+	default 0
+	help
+	  The size of L2 cache lines, if known at compile time.
+
+
 config SYS_CACHE_SIZE_AUTO
 	def_bool y if SYS_DCACHE_SIZE = 0 && SYS_ICACHE_SIZE = 0 && \
-		SYS_DCACHE_LINE_SIZE = 0 && SYS_ICACHE_LINE_SIZE = 0
+		SYS_DCACHE_LINE_SIZE = 0 && SYS_ICACHE_LINE_SIZE = 0 && \
+		SYS_SCACHE_LINE_SIZE = 0
 	help
 	  Select this (or let it be auto-selected by not defining any cache
 	  sizes) in order to allow U-Boot to automatically detect the sizes
arch/mips/lib/cache.c +1 -1
index d56fd1e0f4..0ddae30f2c 100644
@@ -87,7 +87,7 @@ static inline unsigned long scache_line_size(void)
 #ifdef CONFIG_MIPS_L2_CACHE
 	return gd->arch.l2_line_size;
 #else
-	return 0;
+	return CONFIG_SYS_SCACHE_LINE_SIZE;
 #endif
 }
 
Signature · 1 line
2.21.0
#5 lore raw

PATCH v2 1/2 MIPS: add empty arch/clk.h

In reply to Ramon Fried

Am Mo., 10. Juni 2019 um 20:05 Uhr schrieb Ramon Fried <[email protected]>:

Quoted 31 lines

The file is needed for compilation of various
drivers (IE. macb).
Add empty implementation so compilation succeeds.

---
v2: Moved the new file to the correct location.

 arch/mips/include/asm/arch/clk.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 arch/mips/include/asm/arch/clk.h
arch/mips/include/asm/arch/clk.h new file +11 -1
new file mode 100644
index 0000000000..c01e0973cd
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) Ramon Fried <[email protected]>
+ */
+
+#ifndef __ASM_MIPS_ARCH_CLK_H
+#define __ASM_MIPS_ARCH_CLK_H
+
+/* Note: This is a placeholder header for driver compilation. */
+
+#endif
--
Quoted 2 lines

2.21.0

the macb driver pulls only some SoC specific enums or functions. This shouldn't be required anymore with driver model or clock framework. Especially if this driver is shared between different SoCs and architectures. Maybe you should rather fix the macb driver to not force asm/arch/clk.h e.g. by wrapping it with #ifndef CONFIG_CLK.

Signature · 1 line
- Daniel
#2 lore raw

PATCH v2 2/2 MIPS: add dma-mapping.h implementation

In reply to Ramon Fried

Am Mo., 10. Juni 2019 um 20:05 Uhr schrieb Ramon Fried <[email protected]>:

Quoted 67 lines

add implementation for dma_alloc_coherent(), dma_free_coherent(), dma_map_single() and dma_free_single()

---
v2: fix warning caused by missing casts.

 arch/mips/include/asm/dma-mapping.h | 48 +++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 arch/mips/include/asm/dma-mapping.h
arch/mips/include/asm/dma-mapping.h new file +48 -1
new file mode 100644
index 0000000000..387427c13b
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2019
+ * Ramon Fried <[email protected]>
+ */
+
+#ifndef __ASM_MIPS_DMA_MAPPING_H
+#define __ASM_MIPS_DMA_MAPPING_H
+
+#include <linux/dma-direction.h>
+#include <asm/addrspace.h>
+#define        dma_mapping_error(x, y) 0
+
+static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
+{
+       void *vaddr = memalign(ARCH_DMA_MINALIGN,
+                              ROUND(len, ARCH_DMA_MINALIGN));
+
+       *handle = CPHYSADDR((unsigned long)vaddr);
+       return (void *)(CKSEG1ADDR((unsigned long)vaddr));
+}
+
+static inline void dma_free_coherent(void *addr)
+{
+       free((void *)CPHYSADDR((unsigned long)addr));
+}
+
+static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
+                                          enum dma_data_direction dir)
+{
+       unsigned long dma_addr = CPHYSADDR((unsigned long)vaddr);
+
+       if (dir == DMA_TO_DEVICE)
+               flush_dcache_range((unsigned long)vaddr,
+                                  (unsigned long)vaddr + len);
+       if (dir == DMA_FROM_DEVICE)
+               invalidate_dcache_range((unsigned long)vaddr,
+                                       (unsigned long)vaddr + len);
+
+       return dma_addr;
+}
+
+static inline void dma_unmap_single(volatile void *vaddr, size_t len,
+                                   unsigned long paddr)
+{
+}
+
+#endif /* __ASM_MIPS_DMA_MAPPING_H */
--
Quoted 2 lines

2.21.0

this doesn't match all requirements for a generic MIPS DMA interface. It doesn't handle 64 Bit, coherent DMA or different kinds of memory mapping. I would rather fix the macb driver to use existing U-Boot API.

Alternatively you could port the generic dma-mapping.h from Linux so you could either have empty function bodies or an architecture can optionally provide an implementation.

Signature · 1 line
- Daniel
#6 lore raw

PATCH v2 1/2 MIPS: add empty arch/clk.h

In reply to Daniel Schwierzeck
Quoted 34 lines · Daniel Schwierzeck

Am Mo., 10. Juni 2019 um 20:05 Uhr schrieb Ramon Fried < rfried.dev at gmail.com>:

Quoted 6 lines

The file is needed for compilation of various
drivers (IE. macb).
Add empty implementation so compilation succeeds.

Review

Quoted 8 lines

---
v2: Moved the new file to the correct location.

 arch/mips/include/asm/arch/clk.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 arch/mips/include/asm/arch/clk.h
(quoted diff) +0 -0

b/arch/mips/include/asm/arch/clk.h

Quoted 17 lines

new file mode 100644
index 0000000000..c01e0973cd

arch/mips/include/asm/arch/clk.h new file +11 -1
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) Ramon Fried <[email protected]>
+ */
+
+#ifndef __ASM_MIPS_ARCH_CLK_H
+#define __ASM_MIPS_ARCH_CLK_H
+
+/* Note: This is a placeholder header for driver compilation. */
+
+#endif
--
Quoted 9 lines
Quoted 2 lines

2.21.0

the macb driver pulls only some SoC specific enums or functions. This shouldn't be required anymore with driver model or clock framework. Especially if this driver is shared between different SoCs and architectures. Maybe you should rather fix the macb driver to not force asm/arch/clk.h e.g. by wrapping it with #ifndef CONFIG_CLK.

I totally agree with you, I created this patch as I thought this is what I was expected to do:
I followed what RISCV did:
/arch/riscv/include/asm/arch-generic/clk.h
Thanks,
Ramon.

Quoted 4 lines

--
- Daniel

#4 lore raw

PATCH 1/1 MIPS: add compile time definition of L2 cache size

In reply to Ramon Fried

Am 10.06.19 um 20:05 schrieb Ramon Fried:

Quoted 41 lines

If configuration is set to skip low level init, automatic probe of L2 cache size is not performed and the size is set to 0. Flushing or invalidating the L2 cache will fail in this case.

Add a static configuration (SYS_DCACHE_LINE_SIZE) with default set to 0.

---
 arch/mips/Kconfig     | 10 +++++++++-
 arch/mips/lib/cache.c |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)
arch/mips/Kconfig +9 -1
index 5cb9bdf2ee..235bb5b7e6 100644
@@ -408,9 +408,17 @@ config SYS_ICACHE_LINE_SIZE
 	help
 	  The size of L1 Icache lines, if known at compile time.
 
+config SYS_SCACHE_LINE_SIZE
+	int
+	default 0
+	help
+	  The size of L2 cache lines, if known at compile time.
+
+
 config SYS_CACHE_SIZE_AUTO
 	def_bool y if SYS_DCACHE_SIZE = 0 && SYS_ICACHE_SIZE = 0 && \
-		SYS_DCACHE_LINE_SIZE = 0 && SYS_ICACHE_LINE_SIZE = 0
+		SYS_DCACHE_LINE_SIZE = 0 && SYS_ICACHE_LINE_SIZE = 0 && \
+		SYS_SCACHE_LINE_SIZE = 0
 	help
 	  Select this (or let it be auto-selected by not defining any cache
 	  sizes) in order to allow U-Boot to automatically detect the sizes
arch/mips/lib/cache.c +0 -0
index d56fd1e0f4..0ddae30f2c 100644

arch/mips/lib/cache.c static inline unsigned long scache_line_size(void) · line 93

Quoted 8 lines
arch/mips/lib/cache.c +1 -1
@@ -87,7 +87,7 @@ static inline unsigned long scache_line_size(void)
 #ifdef CONFIG_MIPS_L2_CACHE
 	return gd->arch.l2_line_size;
 #else
-	return 0;
+	return CONFIG_SYS_SCACHE_LINE_SIZE;
 #endif
 }
 

applied to u-boot-mips, thanks.

Signature · 1 line
- Daniel