riscv: asm update for building ubifs
Subsystems (3)
Fix misisng atomic and test_and_{set,clear}_bit macros to allow the ubi/ubifs code to be built for riscv. These are fairly simple but are not being used outside of ubifs on our builds.
Ben Dooks (3):
riscv: add generic link for <asm/atomic.h>
riscv: implement local_irq_{save,restore} macros
riscv: define test_and_{set,clear}_bit in asm/bitops.h
arch/riscv/include/asm/atomic.h | 14 ++++++++++++++ arch/riscv/include/asm/bitops.h | 3 +++ arch/riscv/include/asm/system.h | 15 +++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 arch/riscv/include/asm/atomic.h
Signature · 1 line
2.39.2
PATCH 1/3 riscv: add generic link for <asm/atomic.h>
Add a link from <asm/atomic.h> to the generic one to allow things like ubifs to be built. This can be extended with riscv AMO ops at a later date.
--- arch/riscv/include/asm/atomic.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 arch/riscv/include/asm/atomic.h
arch/riscv/include/asm/atomic.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2023 SiFive, Inc. +*/ + +#ifndef __RISCV_ATOMIC_H +#define __RISCV_ATOMIC_H + +/* use the generic asm/atomic.h until we define a better one */ + +#include <asm/system.h> +#include <asm-generic/atomic.h> + +#endif
Signature · 1 line
2.39.2
Re: [PATCH 1/3] riscv: add generic link for <asm/atomic.h>
Quoted 10 lines · Ben Dooks
Add a link from <
asm/atomic.h> to the generic one to allow things like ubifs to be built. This can be extended with riscv AMO ops at a later date.Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/include/asm/atomic.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 arch/riscv/include/asm/atomic.h
PATCH 2/3 riscv: implement local_irq_{save,restore} macros
In reply to Ben DooksAdd implementations of the local_irq_{save,restore} macros so that <asm/atomic.h> can be used with riscv.
--- arch/riscv/include/asm/system.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
arch/riscv/include/asm/system.h +11 -4
@@ -7,15 +7,22 @@#ifndef __ASM_RISCV_SYSTEM_H#define __ASM_RISCV_SYSTEM_H +#include <asm/csr.h> +struct event ;/* -* Interrupt configuring macros. -* -* TODO -* +* Interupt configuration macros */ +#define local_irq_save (__flags) do { \ + __flags = csr_read_clear(CSR_SSTATUS, SR_SIE) & SR_SIE; \ + } while (0) + +#define local_irq_restore (__flags) do { \ + csr_set(CSR_SSTATUS, __flags & SR_SIE); \ + } while(0) +/* Hook to set up the CPU (called from SPL too) */ int riscv_cpu_setup (void *ctx,struct event *event);
Signature · 1 line
2.39.2
Re: [PATCH 2/3] riscv: implement local_irq_{save,restore} macros
Hi Ben,
Quoted 19 lines · Ben Dooks
Add implementations of the local_irq_{save,restore} macros so that <
asm/atomic.h> can be used with riscv.Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/include/asm/system.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)arch/riscv/include/asm/system.h +2
-0@@ -7,15 +7,22 @@#ifndef __ASM_RISCV_SYSTEM_H#define __ASM_RISCV_SYSTEM_H +#include <asm/csr.h> +struct event ;
arch/riscv/include/asm/system.h line 18
Quoted 10 lines
arch/riscv/include/asm/system.h +2
-4/* -* Interrupt configuring macros. -* -* TODO -* +* Interupt configuration macros */ +#define local_irq_save (__flags) do { \
Can we have this "do" in a new line just like what kernel does?
arch/riscv/include/asm/system.h line 24
Quoted 6 lines
arch/riscv/include/asm/system.h +6
-0+ __flags =csr_read_clear (CSR_SSTATUS ,SR_SIE ) &SR_SIE ; \ + } while (0) + +#define local_irq_restore (__flags) do { \ + csr_set(CSR_SSTATUS, __flags & SR_SIE); \ + } while(0)
^
a space missing
arch/riscv/include/asm/system.h line 28
Quoted 4 lines
arch/riscv/include/asm/system.h +1
-0+/* Hook to set up the CPU (called from SPL too) */ int riscv_cpu_setup (void *ctx,struct event *event);
If you don't mind, I could make these format modification on my side, so you don't have to spin another patch set.
Best regards,
Leo
Quoted 3 lines
Signature · 1 line
2.39.2
Re: [PATCH 2/3] riscv: implement local_irq_{save,restore} macros
Quoted 48 lines · Leo Liang
Hi Ben,
Quoted 19 lines · Ben Dooks
Add implementations of the local_irq_{save,restore} macros so that <
asm/atomic.h> can be used with riscv.Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/include/asm/system.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)arch/riscv/include/asm/system.h +2
-0@@ -7,15 +7,22 @@#ifndef __ASM_RISCV_SYSTEM_H#define __ASM_RISCV_SYSTEM_H +#include <asm/csr.h> +struct event ;arch/riscv/include/asm/system.h line 18
Quoted 10 lines
arch/riscv/include/asm/system.h +2
-4/* -* Interrupt configuring macros. -* -* TODO -* +* Interupt configuration macros */ +#define local_irq_save (__flags) do { \Can we have this "do" in a new line just like what kernel does?
arch/riscv/include/asm/system.h line 24
Quoted 6 lines
arch/riscv/include/asm/system.h +6
-0+ __flags =csr_read_clear (CSR_SSTATUS ,SR_SIE ) &SR_SIE ; \ + } while (0) + +#define local_irq_restore (__flags) do { \ + csr_set(CSR_SSTATUS, __flags & SR_SIE); \ + } while(0)^
a space missingarch/riscv/include/asm/system.h line 28
Quoted 4 lines
arch/riscv/include/asm/system.h +1
-0+/* Hook to set up the CPU (called from SPL too) */ int riscv_cpu_setup (void *ctx,struct event *event);
Quoted 5 lines
If you don't mind, I could make these format modification on my side, so you don't have to spin another patch set.
Best regards,
Leo
Yes that's fine, this got buried under a lot of other work.
Thank you.
Signature · 1 line
Ben
PATCH 3/3 riscv: define test_and_{set,clear}_bit in asm/bitops.h
In reply to Ben DooksThese seem to be missing, and trying to build ubifs without them is causing errors due to these being missing.
--- arch/riscv/include/asm/bitops.h | 3 +++ 1 file changed, 3 insertions(+)
arch/riscv/include/asm/bitops.h +3 -0
@@ -158,6 +158,9 @@ static inline unsigned long ffz(unsigned long word)#define hweight16 (x) generic_hweight16(x)#define hweight8 (x) generic_hweight8(x) +#define test_and_set_bit __test_and_set_bit +#define test_and_clear_bit __test_and_clear_bit +#define ext2_set_bit test_and_set_bit#define ext2_clear_bit test_and_clear_bit#define ext2_test_bit test_bit
Signature · 1 line
2.39.2
Re: [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h
Quoted 7 lines · Ben Dooks
These seem to be missing, and trying to build ubifs without them is causing errors due to these being missing.
Signed-off-by Ben Dooks <[email protected]>--- arch/riscv/include/asm/bitops.h | 3 +++ 1 file changed, 3 insertions(+)
Conor Dooley
Reviewed-byHey Ben,
Quoted 3 lines · Ben Dooks
Fix misisng atomic and test_and_{set,clear}_bit macros to allow the ubi/ubifs code to be built for riscv. These are fairly simple but are not being used outside of ubifs on our builds.
We've been running something a fair hackier & probably should have already sent something by now :/ What you have here is either the same as what we have, or an improvement:
Thanks for doing this.
Quoted 3 lines · Ben Dooks
Fix misisng atomic and test_and_{set,clear}_bit macros to allow the ubi/ubifs code to be built for riscv. These are fairly simple but are not being used outside of ubifs on our builds.
Has anyone had a chance to review these for merging?
I may be losing the [email protected] address soon, so please cc [email protected] in further discussions
Quoted 11 lines
Ben Dooks (3):
riscv: add generic link for <asm/atomic.h>
riscv: implement local_irq_{save,restore} macros
riscv: define test_and_{set,clear}_bit inasm/bitops.harch/riscv/include/asm/atomic.h | 14 ++++++++++++++ arch/riscv/include/asm/bitops.h | 3 +++ arch/riscv/include/asm/system.h | 15 +++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-)create mode 100644
arch/riscv/include/asm/atomic.h
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html