riscv: asm update for building ubifs

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

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 ben.dooks@sifive.com --- arch/riscv/include/asm/atomic.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 arch/riscv/include/asm/atomic.h
diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h new file mode 100644 index 0000000000..f541fb4daa --- /dev/null +++ b/arch/riscv/include/asm/atomic.h @@ -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

On Fri, May 05, 2023 at 09:02:05AM +0100, Ben Dooks wrote:
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 ben.dooks@sifive.com
arch/riscv/include/asm/atomic.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 arch/riscv/include/asm/atomic.h
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

Add implementations of the local_irq_{save,restore} macros so that <asm/atomic.h> can be used with riscv.
Signed-off-by: Ben Dooks ben.dooks@sifive.com --- arch/riscv/include/asm/system.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/include/asm/system.h b/arch/riscv/include/asm/system.h index 9d8e43e394..78093681e5 100644 --- a/arch/riscv/include/asm/system.h +++ b/arch/riscv/include/asm/system.h @@ -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);

Hi Ben,
On Fri, May 05, 2023 at 09:02:06AM +0100, Ben Dooks wrote:
Add implementations of the local_irq_{save,restore} macros so that <asm/atomic.h> can be used with riscv.
Signed-off-by: Ben Dooks ben.dooks@sifive.com
arch/riscv/include/asm/system.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/include/asm/system.h b/arch/riscv/include/asm/system.h index 9d8e43e394..78093681e5 100644 --- a/arch/riscv/include/asm/system.h +++ b/arch/riscv/include/asm/system.h @@ -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 { \
Can we have this "do" in a new line just like what kernel does?
- __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
/* 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
-- 2.39.2

On 2023-06-12 08:47, Leo Liang wrote:
Hi Ben,
On Fri, May 05, 2023 at 09:02:06AM +0100, Ben Dooks wrote:
Add implementations of the local_irq_{save,restore} macros so that <asm/atomic.h> can be used with riscv.
Signed-off-by: Ben Dooks ben.dooks@sifive.com
arch/riscv/include/asm/system.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/include/asm/system.h b/arch/riscv/include/asm/system.h index 9d8e43e394..78093681e5 100644 --- a/arch/riscv/include/asm/system.h +++ b/arch/riscv/include/asm/system.h @@ -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 { \
Can we have this "do" in a new line just like what kernel does?
- __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
/* 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
Yes that's fine, this got buried under a lot of other work.
Thank you.

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 ben.dooks@sifive.com --- arch/riscv/include/asm/bitops.h | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitops.h index 536629bbec..35f1368b83 100644 --- a/arch/riscv/include/asm/bitops.h +++ b/arch/riscv/include/asm/bitops.h @@ -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

On Fri, May 05, 2023 at 09:02:07AM +0100, Ben Dooks wrote:
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 ben.dooks@sifive.com
arch/riscv/include/asm/bitops.h | 3 +++ 1 file changed, 3 insertions(+)
Reviewed-by: Leo Yu-Chi Liang ycliang@andestech.com

Hey Ben,
On Fri, May 05, 2023 at 09:02:04AM +0100, Ben Dooks wrote:
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:
Reviewed-by: Conor Dooley conor.dooley@microchip.com
Thanks for doing this.

On 05/05/2023 09:02, Ben Dooks wrote:
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 ben.dooks@sifive.com address soon, so please cc ben.dooks@codethink.co.uk in further discussions
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
participants (4)
-
Ben Dooks
-
Ben Dooks
-
Conor Dooley
-
Leo Liang