* [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp
@ 2021-03-05 18:33 Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 2/5] kvx: Implement dcache invalidation primitive Jules Maselbas
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Jules Maselbas @ 2021-03-05 18:33 UTC (permalink / raw)
To: barebox; +Cc: Yann Sionneau, Jules Maselbas, Ahmad Fatoum
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
changes v1 -> v2: nothing
---
arch/kvx/Kconfig | 1 +
arch/kvx/include/asm/setjmp.h | 15 +++++++
arch/kvx/lib/Makefile | 2 +-
arch/kvx/lib/setjmp.S | 85 +++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+), 1 deletion(-)
create mode 100644 arch/kvx/include/asm/setjmp.h
create mode 100644 arch/kvx/lib/setjmp.S
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 3327021e1..8483ae6e6 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -11,6 +11,7 @@ config KVX
select ELF
select FLEXIBLE_BOOTARGS
select GENERIC_FIND_NEXT_BIT
+ select HAS_ARCH_SJLJ
select LIBFDT
select MFD_SYSCON
select OF_BAREBOX_DRIVERS
diff --git a/arch/kvx/include/asm/setjmp.h b/arch/kvx/include/asm/setjmp.h
new file mode 100644
index 000000000..3cfc698d9
--- /dev/null
+++ b/arch/kvx/include/asm/setjmp.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* SPDX-FileCopyrightText: 2021 Jules Maselbas <jmaselbas@kalray.eu>, Kalray Inc. */
+
+#ifndef _ASM_KVX_SETJMP_H_
+#define _ASM_KVX_SETJMP_H_
+
+#include <linux/types.h>
+
+typedef u64 jmp_buf[22];
+
+int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
+int setjmp(jmp_buf jmp) __attribute__((returns_twice));
+void longjmp(jmp_buf jmp, int ret) __attribute__((noreturn));
+
+#endif /* _ASM_KVX_SETJMP_H_ */
diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
index 6e56462da..cee08b0fa 100644
--- a/arch/kvx/lib/Makefile
+++ b/arch/kvx/lib/Makefile
@@ -3,4 +3,4 @@
# Copyright (C) 2019 Kalray Inc.
#
-obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o
+obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o setjmp.o
diff --git a/arch/kvx/lib/setjmp.S b/arch/kvx/lib/setjmp.S
new file mode 100644
index 000000000..829299711
--- /dev/null
+++ b/arch/kvx/lib/setjmp.S
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+/* SPDX-FileCopyrightText: 2021 Jules Maselbas <jmaselbas@kalray.eu>, Kalray Inc. */
+
+#define REG_SIZE 8
+
+#include <linux/linkage.h>
+
+/* jmp_buf layout:
+ * [0] = $ra, $sp, $cs, $r14,
+ * [4] = $r20, $r21, $r22, $r23,
+ * [8] = $r24, $r25, $r26, $r27,
+ * [12] = $r28, $r29, $r30, $r31,
+ * [16] = $r18, $r19,
+ * [18] = $lc, $le, $ls, xxxx
+ */
+
+/**
+ * int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
+ */
+ENTRY(initjmp)
+ /* store $ra */
+ sd (0 * REG_SIZE)[$r0] = $r1
+ ;;
+ /* store $sp */
+ sd (1 * REG_SIZE)[$r0] = $r2
+ make $r0 = 0
+ ret
+ ;;
+ENDPROC(initjmp)
+
+/**
+ * int setjmp(jmp_buf jmp);
+ */
+ENTRY(setjmp)
+ sq (16 * REG_SIZE)[$r0] = $r18r19
+ get $r40 = $ra
+ copyd $r41 = $sp
+ ;;
+ so (4 * REG_SIZE)[$r0] = $r20r21r22r23
+ get $r42 = $cs
+ copyd $r43 = $r14
+ ;;
+ so (0 * REG_SIZE)[$r0] = $r40r41r42r43
+ get $r40 = $lc
+ ;;
+ so (8 * REG_SIZE)[$r0] = $r24r25r26r27
+ get $r41 = $le
+ ;;
+ so (12 * REG_SIZE)[$r0] = $r28r29r30r31
+ get $r42 = $ls
+ ;;
+ so (18 * REG_SIZE)[$r0] = $r40r41r42r43
+ make $r0 = 0
+ ret
+ ;;
+ENDPROC(setjmp)
+
+/**
+ * void longjmp(jmp_buf jmp, int ret);
+ */
+ENTRY(longjmp)
+ lo $r40r41r42r43 = (0 * REG_SIZE)[$r0]
+ ;;
+ lo $r44r45r46r47 = (18 * REG_SIZE)[$r0]
+ set $ra = $r40
+ copyd $sp = $r41
+ ;;
+ lo $r20r21r22r23 = (4 * REG_SIZE)[$r0]
+ set $cs = $r42
+ copyd $r14 = $r43
+ ;;
+ lo $r24r25r26r27 = (8 * REG_SIZE)[$r0]
+ set $lc = $r44
+ ;;
+ lo $r28r29r30r31 = (12 * REG_SIZE)[$r0]
+ set $le = $r45
+ ;;
+ lq $r18r19 = (16 * REG_SIZE)[$r0]
+ set $ls = $r46
+ ;;
+ /* According to man, if retval is equal to 0, then we should return 1 */
+ maxud $r0 = $r1, 1
+ ret
+ ;;
+ENDPROC(longjmp)
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/5] kvx: Implement dcache invalidation primitive
2021-03-05 18:33 [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
@ 2021-03-05 18:33 ` Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 3/5] kvx: Implement dma handling primitives Jules Maselbas
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2021-03-05 18:33 UTC (permalink / raw)
To: barebox; +Cc: Yann Sionneau, Jules Maselbas, Ahmad Fatoum
From: Yann Sionneau <ysionneau@kalray.eu>
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
changes v1 -> v2:
- renamed kvx_dcache_invalidate_mem_area to invalidate_dcache_range
- replace the implemetation with a simpler version
---
arch/kvx/Kconfig | 1 +
arch/kvx/include/asm/cache.h | 13 +++++++++++++
arch/kvx/lib/Makefile | 2 +-
arch/kvx/lib/cache.c | 25 +++++++++++++++++++++++++
4 files changed, 40 insertions(+), 1 deletion(-)
create mode 100644 arch/kvx/lib/cache.c
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 8483ae6e6..4e02613ec 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -12,6 +12,7 @@ config KVX
select FLEXIBLE_BOOTARGS
select GENERIC_FIND_NEXT_BIT
select HAS_ARCH_SJLJ
+ select HAS_CACHE
select LIBFDT
select MFD_SYSCON
select OF_BAREBOX_DRIVERS
diff --git a/arch/kvx/include/asm/cache.h b/arch/kvx/include/asm/cache.h
index 3be176725..0bf3c8f06 100644
--- a/arch/kvx/include/asm/cache.h
+++ b/arch/kvx/include/asm/cache.h
@@ -8,6 +8,8 @@
#include <linux/types.h>
+void invalidate_dcache_range(unsigned long addr, unsigned long stop);
+
static inline void sync_caches_for_execution(void)
{
__builtin_kvx_fence();
@@ -15,4 +17,15 @@ static inline void sync_caches_for_execution(void)
__builtin_kvx_barrier();
}
+static inline void sync_dcache_icache(void)
+{
+ sync_caches_for_execution();
+}
+
+static inline void dcache_inval(void)
+{
+ __builtin_kvx_fence();
+ __builtin_kvx_dinval();
+}
+
#endif /* __KVX_CACHE_H */
diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
index cee08b0fa..d271ebccf 100644
--- a/arch/kvx/lib/Makefile
+++ b/arch/kvx/lib/Makefile
@@ -3,4 +3,4 @@
# Copyright (C) 2019 Kalray Inc.
#
-obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o setjmp.o
+obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o setjmp.o cache.o
diff --git a/arch/kvx/lib/cache.c b/arch/kvx/lib/cache.c
new file mode 100644
index 000000000..bd074de79
--- /dev/null
+++ b/arch/kvx/lib/cache.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2021 Yann Sionneau <ysionneau@kalray.eu>, Kalray Inc.
+
+#include <asm/cache.h>
+#include <linux/kernel.h>
+
+#define KVX_DCACHE_LINE_SIZE (64)
+#define KVX_DCACHE_SIZE (128*1024)
+
+void invalidate_dcache_range(unsigned long addr, unsigned long stop)
+{
+ long size;
+
+ addr = ALIGN_DOWN(addr, KVX_DCACHE_LINE_SIZE);
+ size = stop - addr;
+
+ if (size < KVX_DCACHE_SIZE) {
+ while (addr < stop) {
+ __builtin_kvx_dinvall((void *)addr);
+ addr += KVX_DCACHE_LINE_SIZE;
+ }
+ } else {
+ __builtin_kvx_dinval();
+ }
+}
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 3/5] kvx: Implement dma handling primitives
2021-03-05 18:33 [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 2/5] kvx: Implement dcache invalidation primitive Jules Maselbas
@ 2021-03-05 18:33 ` Jules Maselbas
2021-05-17 10:42 ` Ahmad Fatoum
2021-03-05 18:33 ` [PATCH v2 4/5] kvx: Request enough privilege to boot Linux Jules Maselbas
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Jules Maselbas @ 2021-03-05 18:33 UTC (permalink / raw)
To: barebox; +Cc: Yann Sionneau, Jules Maselbas, Ahmad Fatoum
From: Yann Sionneau <ysionneau@kalray.eu>
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
changes v1 -> v2:
- add BUILD_BUG_ON_MSG in dma_alloc_coherent
- renamed kvx_dcache_invalidate_mem_area to invalidate_dcache_range
- add comment on dcache beeing write-through
---
arch/kvx/Kconfig | 1 +
arch/kvx/include/asm/dma.h | 32 +++++++++++
arch/kvx/include/asm/sys_arch.h | 3 ++
arch/kvx/lib/Makefile | 2 +-
arch/kvx/lib/dma-default.c | 94 +++++++++++++++++++++++++++++++++
5 files changed, 131 insertions(+), 1 deletion(-)
create mode 100644 arch/kvx/include/asm/dma.h
create mode 100644 arch/kvx/lib/dma-default.c
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index 4e02613ec..093444088 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -13,6 +13,7 @@ config KVX
select GENERIC_FIND_NEXT_BIT
select HAS_ARCH_SJLJ
select HAS_CACHE
+ select HAS_DMA
select LIBFDT
select MFD_SYSCON
select OF_BAREBOX_DRIVERS
diff --git a/arch/kvx/include/asm/dma.h b/arch/kvx/include/asm/dma.h
new file mode 100644
index 000000000..a7ecf279a
--- /dev/null
+++ b/arch/kvx/include/asm/dma.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* SPDX-FileCopyrightText: 2021 Yann Sionneau <ysionneau@kalray.eu>, Kalray Inc. */
+
+#ifndef __ASM_DMA_H
+#define __ASM_DMA_H
+
+#include <common.h>
+
+#define KVX_DDR_32BIT_RAM_WINDOW_BA (0x80000000ULL)
+#define KVX_DDR_64BIT_RAM_WINDOW_BA (0x100000000ULL)
+#define MAX_32BIT_ADDR (0xffffffffULL)
+
+#define dma_alloc dma_alloc
+static inline void *dma_alloc(size_t size)
+{
+ return xmemalign(64, ALIGN(size, 64));
+}
+
+static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
+{
+ BUILD_BUG_ON_MSG(1, "dma_alloc_coherent not supported: "
+ "MMU support is required to map uncached pages");
+ return NULL;
+}
+
+static inline void dma_free_coherent(void *mem, dma_addr_t dma_handle,
+ size_t size)
+{
+ free(mem);
+}
+
+#endif /* __ASM_DMA_H */
diff --git a/arch/kvx/include/asm/sys_arch.h b/arch/kvx/include/asm/sys_arch.h
index 9df32c4e7..ce07a5598 100644
--- a/arch/kvx/include/asm/sys_arch.h
+++ b/arch/kvx/include/asm/sys_arch.h
@@ -11,6 +11,9 @@
#define EXCEPTION_STRIDE 0x40
#define EXCEPTION_ALIGNMENT 0x100
+#define kvx_cluster_id() ((int) \
+ ((kvx_sfr_get(PCR) & KVX_SFR_PCR_CID_MASK) \
+ >> KVX_SFR_PCR_CID_SHIFT))
#define KVX_SFR_START(__sfr_reg) \
(KVX_SFR_## __sfr_reg ## _SHIFT)
diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
index d271ebccf..c730e1c23 100644
--- a/arch/kvx/lib/Makefile
+++ b/arch/kvx/lib/Makefile
@@ -3,4 +3,4 @@
# Copyright (C) 2019 Kalray Inc.
#
-obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o setjmp.o cache.o
+obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o setjmp.o cache.o dma-default.o
diff --git a/arch/kvx/lib/dma-default.c b/arch/kvx/lib/dma-default.c
new file mode 100644
index 000000000..2a4144696
--- /dev/null
+++ b/arch/kvx/lib/dma-default.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2021 Yann Sionneau <ysionneau@kalray.eu>, Kalray Inc.
+
+#include <dma.h>
+#include <asm/barrier.h>
+#include <asm/io.h>
+#include <asm/cache.h>
+#include <asm/sfr.h>
+#include <asm/sys_arch.h>
+
+/*
+ * The implementation of arch should follow the following rules:
+ * map for_cpu for_device unmap
+ * TO_DEV writeback none writeback none
+ * FROM_DEV invalidate invalidate(*) invalidate invalidate(*)
+ * BIDIR writeback invalidate writeback invalidate
+ *
+ * (*) - only necessary if the CPU speculatively prefetches.
+ *
+ * (see https://lkml.org/lkml/2018/5/18/979)
+ */
+
+void dma_sync_single_for_device(dma_addr_t addr, size_t size,
+ enum dma_data_direction dir)
+{
+ /* dcache is Write-Through: no need to flush to force writeback */
+ switch (dir) {
+ case DMA_FROM_DEVICE:
+ invalidate_dcache_range(addr, addr + size);
+ break;
+ case DMA_TO_DEVICE:
+ case DMA_BIDIRECTIONAL:
+ /* allow device to read buffer written by CPU */
+ wmb();
+ break;
+ default:
+ BUG();
+ }
+}
+
+void dma_sync_single_for_cpu(dma_addr_t addr, size_t size,
+ enum dma_data_direction dir)
+{
+ /* CPU does not speculatively prefetches */
+ switch (dir) {
+ case DMA_FROM_DEVICE:
+ /* invalidate has been done during map/for_device */
+ case DMA_TO_DEVICE:
+ break;
+ case DMA_BIDIRECTIONAL:
+ invalidate_dcache_range(addr, addr + size);
+ break;
+ default:
+ BUG();
+ }
+}
+
+#define KVX_DDR_ALIAS_OFFSET \
+ (KVX_DDR_64BIT_RAM_WINDOW_BA - KVX_DDR_32BIT_RAM_WINDOW_BA)
+#define KVX_DDR_ALIAS_WINDOW \
+ (KVX_DDR_64BIT_RAM_WINDOW_BA + KVX_DDR_ALIAS_OFFSET)
+
+/* Local smem is aliased between 0 and 16MB */
+#define KVX_SMEM_LOCAL_ALIAS 0x1000000ULL
+
+dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
+ enum dma_data_direction dir)
+{
+ uintptr_t addr = (uintptr_t) ptr;
+
+ dma_sync_single_for_device(addr, size, dir);
+
+ /* Local smem alias should never be used for dma */
+ if (addr < KVX_SMEM_LOCAL_ALIAS)
+ return addr + (1 + kvx_cluster_id()) * KVX_SMEM_LOCAL_ALIAS;
+
+ if (dev->dma_mask && addr <= dev->dma_mask)
+ return addr;
+
+ if (addr >= KVX_DDR_ALIAS_WINDOW)
+ return DMA_ERROR_CODE;
+
+ addr -= KVX_DDR_ALIAS_OFFSET;
+ if (dev->dma_mask && addr > dev->dma_mask)
+ return DMA_ERROR_CODE;
+
+ return addr;
+}
+
+void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
+ enum dma_data_direction dir)
+{
+ dma_sync_single_for_cpu(addr, size, dir);
+}
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 4/5] kvx: Request enough privilege to boot Linux
2021-03-05 18:33 [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 2/5] kvx: Implement dcache invalidation primitive Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 3/5] kvx: Implement dma handling primitives Jules Maselbas
@ 2021-03-05 18:33 ` Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 5/5] kvx: lib: dtb: Remove unused variable Jules Maselbas
2021-03-15 8:35 ` [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2021-03-05 18:33 UTC (permalink / raw)
To: barebox; +Cc: Yann Sionneau, Jules Maselbas, Ahmad Fatoum
At startup barebox must take all the privileges that will be
requested by Linux.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
changes v1 -> v2: nothing
---
arch/kvx/cpu/start.S | 4 ++++
arch/kvx/include/asm/privilege.h | 16 ++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/arch/kvx/cpu/start.S b/arch/kvx/cpu/start.S
index d90272c71..a647e8a51 100644
--- a/arch/kvx/cpu/start.S
+++ b/arch/kvx/cpu/start.S
@@ -115,6 +115,10 @@ ENDPROC(kvx_start)
wfxl $psow = $r21 ;\
;; ;\
wfxm $psow = $r22 ;\
+ ;; ;\
+ make $r21 = DO_WFXL_VALUE_##__pl ;\
+ ;; ;\
+ wfxl $dow = $r21 ;\
;;
/**
diff --git a/arch/kvx/include/asm/privilege.h b/arch/kvx/include/asm/privilege.h
index 36b9ade49..f183b24d4 100644
--- a/arch/kvx/include/asm/privilege.h
+++ b/arch/kvx/include/asm/privilege.h
@@ -113,6 +113,21 @@
#define ITO_WFXM_VALUE_PL_CUR_PLUS_1 ITO_WFXM_VALUE(PL_CUR_PLUS_1)
#define ITO_WFXM_VALUE_PL_CUR ITO_WFXM_VALUE(PL_CUR)
+/**
+ * Debug Owner configuration
+ */
+
+#define DO_WFXL_OWN(__field, __pl) \
+ SFR_SET_VAL_WFXL(DO, __field, __pl)
+
+#define DO_WFXL_VALUE(__pl) (DO_WFXL_OWN(B0, __pl) | \
+ DO_WFXL_OWN(B1, __pl) | \
+ DO_WFXL_OWN(W0, __pl) | \
+ DO_WFXL_OWN(W1, __pl))
+
+#define DO_WFXL_VALUE_PL_CUR_PLUS_1 DO_WFXL_VALUE(PL_CUR_PLUS_1)
+#define DO_WFXL_VALUE_PL_CUR DO_WFXL_VALUE(PL_CUR)
+
/**
* Misc owner configuration
*/
@@ -160,6 +175,7 @@
PSO_WFXL_OWN(IE, __pl) | \
PSO_WFXL_OWN(HLE, __pl) | \
PSO_WFXL_OWN(SRE, __pl) | \
+ PSO_WFXL_OWN(DAUS, __pl) | \
PSO_WFXL_OWN(ICE, __pl) | \
PSO_WFXL_OWN(USE, __pl) | \
PSO_WFXL_OWN(DCE, __pl) | \
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 5/5] kvx: lib: dtb: Remove unused variable
2021-03-05 18:33 [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
` (2 preceding siblings ...)
2021-03-05 18:33 ` [PATCH v2 4/5] kvx: Request enough privilege to boot Linux Jules Maselbas
@ 2021-03-05 18:33 ` Jules Maselbas
2021-03-15 8:35 ` [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2021-03-05 18:33 UTC (permalink / raw)
To: barebox; +Cc: Yann Sionneau, Jules Maselbas, Ahmad Fatoum
Local variables `root` and `ret` are not used anymore, remove them.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
changes v1 -> v2: nothing
---
arch/kvx/lib/dtb.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/arch/kvx/lib/dtb.c b/arch/kvx/lib/dtb.c
index 54ffddaf0..09898017c 100644
--- a/arch/kvx/lib/dtb.c
+++ b/arch/kvx/lib/dtb.c
@@ -9,9 +9,6 @@
static int of_kvx_init(void)
{
- int ret;
- struct device_node *root;
-
barebox_register_fdt(boot_dtb);
return 0;
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp
2021-03-05 18:33 [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
` (3 preceding siblings ...)
2021-03-05 18:33 ` [PATCH v2 5/5] kvx: lib: dtb: Remove unused variable Jules Maselbas
@ 2021-03-15 8:35 ` Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2021-03-15 8:35 UTC (permalink / raw)
To: Jules Maselbas; +Cc: barebox, Yann Sionneau, Ahmad Fatoum
On Fri, Mar 05, 2021 at 07:33:23PM +0100, Jules Maselbas wrote:
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
> changes v1 -> v2: nothing
> ---
> arch/kvx/Kconfig | 1 +
> arch/kvx/include/asm/setjmp.h | 15 +++++++
> arch/kvx/lib/Makefile | 2 +-
> arch/kvx/lib/setjmp.S | 85 +++++++++++++++++++++++++++++++++++
> 4 files changed, 102 insertions(+), 1 deletion(-)
> create mode 100644 arch/kvx/include/asm/setjmp.h
> create mode 100644 arch/kvx/lib/setjmp.S
Applied, thanks
Sascha
>
> diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
> index 3327021e1..8483ae6e6 100644
> --- a/arch/kvx/Kconfig
> +++ b/arch/kvx/Kconfig
> @@ -11,6 +11,7 @@ config KVX
> select ELF
> select FLEXIBLE_BOOTARGS
> select GENERIC_FIND_NEXT_BIT
> + select HAS_ARCH_SJLJ
> select LIBFDT
> select MFD_SYSCON
> select OF_BAREBOX_DRIVERS
> diff --git a/arch/kvx/include/asm/setjmp.h b/arch/kvx/include/asm/setjmp.h
> new file mode 100644
> index 000000000..3cfc698d9
> --- /dev/null
> +++ b/arch/kvx/include/asm/setjmp.h
> @@ -0,0 +1,15 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/* SPDX-FileCopyrightText: 2021 Jules Maselbas <jmaselbas@kalray.eu>, Kalray Inc. */
> +
> +#ifndef _ASM_KVX_SETJMP_H_
> +#define _ASM_KVX_SETJMP_H_
> +
> +#include <linux/types.h>
> +
> +typedef u64 jmp_buf[22];
> +
> +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
> +int setjmp(jmp_buf jmp) __attribute__((returns_twice));
> +void longjmp(jmp_buf jmp, int ret) __attribute__((noreturn));
> +
> +#endif /* _ASM_KVX_SETJMP_H_ */
> diff --git a/arch/kvx/lib/Makefile b/arch/kvx/lib/Makefile
> index 6e56462da..cee08b0fa 100644
> --- a/arch/kvx/lib/Makefile
> +++ b/arch/kvx/lib/Makefile
> @@ -3,4 +3,4 @@
> # Copyright (C) 2019 Kalray Inc.
> #
>
> -obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o
> +obj-y += cpuinfo.o board.o dtb.o poweroff.o bootm.o setjmp.o
> diff --git a/arch/kvx/lib/setjmp.S b/arch/kvx/lib/setjmp.S
> new file mode 100644
> index 000000000..829299711
> --- /dev/null
> +++ b/arch/kvx/lib/setjmp.S
> @@ -0,0 +1,85 @@
> +/* SPDX-License-Identifier: LGPL-2.1 */
> +/* SPDX-FileCopyrightText: 2021 Jules Maselbas <jmaselbas@kalray.eu>, Kalray Inc. */
> +
> +#define REG_SIZE 8
> +
> +#include <linux/linkage.h>
> +
> +/* jmp_buf layout:
> + * [0] = $ra, $sp, $cs, $r14,
> + * [4] = $r20, $r21, $r22, $r23,
> + * [8] = $r24, $r25, $r26, $r27,
> + * [12] = $r28, $r29, $r30, $r31,
> + * [16] = $r18, $r19,
> + * [18] = $lc, $le, $ls, xxxx
> + */
> +
> +/**
> + * int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top);
> + */
> +ENTRY(initjmp)
> + /* store $ra */
> + sd (0 * REG_SIZE)[$r0] = $r1
> + ;;
> + /* store $sp */
> + sd (1 * REG_SIZE)[$r0] = $r2
> + make $r0 = 0
> + ret
> + ;;
> +ENDPROC(initjmp)
> +
> +/**
> + * int setjmp(jmp_buf jmp);
> + */
> +ENTRY(setjmp)
> + sq (16 * REG_SIZE)[$r0] = $r18r19
> + get $r40 = $ra
> + copyd $r41 = $sp
> + ;;
> + so (4 * REG_SIZE)[$r0] = $r20r21r22r23
> + get $r42 = $cs
> + copyd $r43 = $r14
> + ;;
> + so (0 * REG_SIZE)[$r0] = $r40r41r42r43
> + get $r40 = $lc
> + ;;
> + so (8 * REG_SIZE)[$r0] = $r24r25r26r27
> + get $r41 = $le
> + ;;
> + so (12 * REG_SIZE)[$r0] = $r28r29r30r31
> + get $r42 = $ls
> + ;;
> + so (18 * REG_SIZE)[$r0] = $r40r41r42r43
> + make $r0 = 0
> + ret
> + ;;
> +ENDPROC(setjmp)
> +
> +/**
> + * void longjmp(jmp_buf jmp, int ret);
> + */
> +ENTRY(longjmp)
> + lo $r40r41r42r43 = (0 * REG_SIZE)[$r0]
> + ;;
> + lo $r44r45r46r47 = (18 * REG_SIZE)[$r0]
> + set $ra = $r40
> + copyd $sp = $r41
> + ;;
> + lo $r20r21r22r23 = (4 * REG_SIZE)[$r0]
> + set $cs = $r42
> + copyd $r14 = $r43
> + ;;
> + lo $r24r25r26r27 = (8 * REG_SIZE)[$r0]
> + set $lc = $r44
> + ;;
> + lo $r28r29r30r31 = (12 * REG_SIZE)[$r0]
> + set $le = $r45
> + ;;
> + lq $r18r19 = (16 * REG_SIZE)[$r0]
> + set $ls = $r46
> + ;;
> + /* According to man, if retval is equal to 0, then we should return 1 */
> + maxud $r0 = $r1, 1
> + ret
> + ;;
> +ENDPROC(longjmp)
> --
> 2.17.1
>
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
>
--
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 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/5] kvx: Implement dma handling primitives
2021-03-05 18:33 ` [PATCH v2 3/5] kvx: Implement dma handling primitives Jules Maselbas
@ 2021-05-17 10:42 ` Ahmad Fatoum
2021-05-17 10:56 ` Jules Maselbas
0 siblings, 1 reply; 8+ messages in thread
From: Ahmad Fatoum @ 2021-05-17 10:42 UTC (permalink / raw)
To: Jules Maselbas, barebox; +Cc: Yann Sionneau
Hello Jules, Yann,
On 05.03.21 19:33, Jules Maselbas wrote:
> From: Yann Sionneau <ysionneau@kalray.eu>
>
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
[snip]
> diff --git a/arch/kvx/lib/dma-default.c b/arch/kvx/lib/dma-default.c
> new file mode 100644
> index 000000000..2a4144696
> --- /dev/null
> +++ b/arch/kvx/lib/dma-default.c
> @@ -0,0 +1,94 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +// SPDX-FileCopyrightText: 2021 Yann Sionneau <ysionneau@kalray.eu>, Kalray Inc.
> +
> +#include <dma.h>
> +#include <asm/barrier.h>
> +#include <asm/io.h>
> +#include <asm/cache.h>
> +#include <asm/sfr.h>
> +#include <asm/sys_arch.h>
> +
> +/*
> + * The implementation of arch should follow the following rules:
> + * map for_cpu for_device unmap
> + * TO_DEV writeback none writeback none
> + * FROM_DEV invalidate invalidate(*) invalidate invalidate(*)
> + * BIDIR writeback invalidate writeback invalidate
> + *
> + * (*) - only necessary if the CPU speculatively prefetches.
> + *
> + * (see https://lkml.org/lkml/2018/5/18/979)
> + */
> +
> +void dma_sync_single_for_device(dma_addr_t addr, size_t size,
> + enum dma_data_direction dir)
> +{
> + /* dcache is Write-Through: no need to flush to force writeback */
> + switch (dir) {
> + case DMA_FROM_DEVICE:
> + invalidate_dcache_range(addr, addr + size);
> + break;
> + case DMA_TO_DEVICE:
> + case DMA_BIDIRECTIONAL:
> + /* allow device to read buffer written by CPU */
> + wmb();
> + break;
> + default:
> + BUG();
> + }
> +}
> +
> +void dma_sync_single_for_cpu(dma_addr_t addr, size_t size,
> + enum dma_data_direction dir)
> +{
> + /* CPU does not speculatively prefetches */
> + switch (dir) {
> + case DMA_FROM_DEVICE:
> + /* invalidate has been done during map/for_device */
> + case DMA_TO_DEVICE:
> + break;
> + case DMA_BIDIRECTIONAL:
> + invalidate_dcache_range(addr, addr + size);
> + break;
> + default:
> + BUG();
> + }
> +}
Both of these work on CPU pointers.
> +
> +#define KVX_DDR_ALIAS_OFFSET \
> + (KVX_DDR_64BIT_RAM_WINDOW_BA - KVX_DDR_32BIT_RAM_WINDOW_BA)
> +#define KVX_DDR_ALIAS_WINDOW \
> + (KVX_DDR_64BIT_RAM_WINDOW_BA + KVX_DDR_ALIAS_OFFSET)
> +
> +/* Local smem is aliased between 0 and 16MB */
> +#define KVX_SMEM_LOCAL_ALIAS 0x1000000ULL
> +
> +dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
> + enum dma_data_direction dir)
> +{
> + uintptr_t addr = (uintptr_t) ptr;
> +
> + dma_sync_single_for_device(addr, size, dir);
So this is correct.
> +
> + /* Local smem alias should never be used for dma */
> + if (addr < KVX_SMEM_LOCAL_ALIAS)
> + return addr + (1 + kvx_cluster_id()) * KVX_SMEM_LOCAL_ALIAS;
> +
> + if (dev->dma_mask && addr <= dev->dma_mask)
> + return addr;
> +
> + if (addr >= KVX_DDR_ALIAS_WINDOW)
> + return DMA_ERROR_CODE;
> +
> + addr -= KVX_DDR_ALIAS_OFFSET;
> + if (dev->dma_mask && addr > dev->dma_mask)
> + return DMA_ERROR_CODE;
> +
> + return addr;
> +}
Now you compute a dma_addr_t as CPU pointer - KVX_DDR_ALIAS_OFFSET.
> +
> +void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
> + enum dma_data_direction dir)
> +{
> + dma_sync_single_for_cpu(addr, size, dir);
And then that dma_addr_t is passed here without + KVX_DDR_ALIAS_OFFSET
to get a CPU pointer out.
So for DMA_BIDIRECTIONAL you'd invalidate the wrong cache region.
I stumbled upon this, because I noticed that that kvx whould've failed to
build starting with v2021.04.0, because following commits conflict with each other:
3f975f810bd3 ("dma: move dma_map/unmap_single from ARM to common code") commited on 2021-03-03
4808d6f80073 ("kvx: Implement dma handling primitives") commited on 2021-03-05
Now, dma_map_single() is defined twice for kvx.
As dma_(un?)map_single is always called with a dev argument, couldn't you define the
DMA offsets in the device tree and use the common drivers/dma/map.c implementation
for these two functions?
Cheers,
Ahmad
> +}
>
--
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 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/5] kvx: Implement dma handling primitives
2021-05-17 10:42 ` Ahmad Fatoum
@ 2021-05-17 10:56 ` Jules Maselbas
0 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2021-05-17 10:56 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: Yann Sionneau, barebox
Hi Ahmad,
On Mon, May 17, 2021 at 12:42:21PM +0200, Ahmad Fatoum wrote:
> Hello Jules, Yann,
>
> On 05.03.21 19:33, Jules Maselbas wrote:
> > From: Yann Sionneau <ysionneau@kalray.eu>
> >
> > Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
>
> [snip]
>
> > diff --git a/arch/kvx/lib/dma-default.c b/arch/kvx/lib/dma-default.c
> > new file mode 100644
> > index 000000000..2a4144696
> > --- /dev/null
> > +++ b/arch/kvx/lib/dma-default.c
> > @@ -0,0 +1,94 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +// SPDX-FileCopyrightText: 2021 Yann Sionneau <ysionneau@kalray.eu>, Kalray Inc.
> > +
> > +#include <dma.h>
> > +#include <asm/barrier.h>
> > +#include <asm/io.h>
> > +#include <asm/cache.h>
> > +#include <asm/sfr.h>
> > +#include <asm/sys_arch.h>
> > +
> > +/*
> > + * The implementation of arch should follow the following rules:
> > + * map for_cpu for_device unmap
> > + * TO_DEV writeback none writeback none
> > + * FROM_DEV invalidate invalidate(*) invalidate invalidate(*)
> > + * BIDIR writeback invalidate writeback invalidate
> > + *
> > + * (*) - only necessary if the CPU speculatively prefetches.
> > + *
> > + * (see https://lkml.org/lkml/2018/5/18/979)
> > + */
> > +
> > +void dma_sync_single_for_device(dma_addr_t addr, size_t size,
> > + enum dma_data_direction dir)
> > +{
> > + /* dcache is Write-Through: no need to flush to force writeback */
> > + switch (dir) {
> > + case DMA_FROM_DEVICE:
> > + invalidate_dcache_range(addr, addr + size);
> > + break;
> > + case DMA_TO_DEVICE:
> > + case DMA_BIDIRECTIONAL:
> > + /* allow device to read buffer written by CPU */
> > + wmb();
> > + break;
> > + default:
> > + BUG();
> > + }
> > +}
> > +
> > +void dma_sync_single_for_cpu(dma_addr_t addr, size_t size,
> > + enum dma_data_direction dir)
> > +{
> > + /* CPU does not speculatively prefetches */
> > + switch (dir) {
> > + case DMA_FROM_DEVICE:
> > + /* invalidate has been done during map/for_device */
> > + case DMA_TO_DEVICE:
> > + break;
> > + case DMA_BIDIRECTIONAL:
> > + invalidate_dcache_range(addr, addr + size);
> > + break;
> > + default:
> > + BUG();
> > + }
> > +}
>
> Both of these work on CPU pointers.
>
> > +
> > +#define KVX_DDR_ALIAS_OFFSET \
> > + (KVX_DDR_64BIT_RAM_WINDOW_BA - KVX_DDR_32BIT_RAM_WINDOW_BA)
> > +#define KVX_DDR_ALIAS_WINDOW \
> > + (KVX_DDR_64BIT_RAM_WINDOW_BA + KVX_DDR_ALIAS_OFFSET)
> > +
> > +/* Local smem is aliased between 0 and 16MB */
> > +#define KVX_SMEM_LOCAL_ALIAS 0x1000000ULL
> > +
> > +dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
> > + enum dma_data_direction dir)
> > +{
> > + uintptr_t addr = (uintptr_t) ptr;
> > +
> > + dma_sync_single_for_device(addr, size, dir);
>
> So this is correct.
>
> > +
> > + /* Local smem alias should never be used for dma */
> > + if (addr < KVX_SMEM_LOCAL_ALIAS)
> > + return addr + (1 + kvx_cluster_id()) * KVX_SMEM_LOCAL_ALIAS;
> > +
> > + if (dev->dma_mask && addr <= dev->dma_mask)
> > + return addr;
> > +
> > + if (addr >= KVX_DDR_ALIAS_WINDOW)
> > + return DMA_ERROR_CODE;
> > +
> > + addr -= KVX_DDR_ALIAS_OFFSET;
> > + if (dev->dma_mask && addr > dev->dma_mask)
> > + return DMA_ERROR_CODE;
> > +
> > + return addr;
> > +}
>
> Now you compute a dma_addr_t as CPU pointer - KVX_DDR_ALIAS_OFFSET.
>
> > +
> > +void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
> > + enum dma_data_direction dir)
> > +{
> > + dma_sync_single_for_cpu(addr, size, dir);
>
> And then that dma_addr_t is passed here without + KVX_DDR_ALIAS_OFFSET
> to get a CPU pointer out.
> So for DMA_BIDIRECTIONAL you'd invalidate the wrong cache region.
Yes, this is bogus but I believe in our case dma_unmap_single is never
called with DMA_BIDIRECTIONAL.
>
> I stumbled upon this, because I noticed that that kvx whould've failed to
> build starting with v2021.04.0, because following commits conflict with each other:
> 3f975f810bd3 ("dma: move dma_map/unmap_single from ARM to common code") commited on 2021-03-03
> 4808d6f80073 ("kvx: Implement dma handling primitives") commited on 2021-03-05
>
> Now, dma_map_single() is defined twice for kvx.
Yes, I noticed this as well when rebasing on barebox v2021.04.
> As dma_(un?)map_single is always called with a dev argument, couldn't you define the
> DMA offsets in the device tree and use the common drivers/dma/map.c implementation
> for these two functions?
Our custom implementation will be removed in favor of the common
implementation and the uses of dma-range.
I had to add a dma-range to the dwc2 device nodes in our device tree, so
when the driver does dma_map/unmap the common implementation will do the
correct remap to the aliased region (so addresses fits in 32bit).
However I do not know how Linux handle a mix of dma-range and iommu.
Since I didn't had much time to test this we are still using v2021.03.
Thanks,
Jules
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-05-17 11:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05 18:33 [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 2/5] kvx: Implement dcache invalidation primitive Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 3/5] kvx: Implement dma handling primitives Jules Maselbas
2021-05-17 10:42 ` Ahmad Fatoum
2021-05-17 10:56 ` Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 4/5] kvx: Request enough privilege to boot Linux Jules Maselbas
2021-03-05 18:33 ` [PATCH v2 5/5] kvx: lib: dtb: Remove unused variable Jules Maselbas
2021-03-15 8:35 ` [PATCH v2 1/5] kvx: Implement setjmp/longjmp/initjmp Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox