public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* riscv: asm update for building ubifs
@ 2023-05-05  8:02 Ben Dooks
  2023-05-05  8:02 ` [PATCH 1/3] riscv: add generic link for <asm/atomic.h> Ben Dooks
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Ben Dooks @ 2023-05-05  8:02 UTC (permalink / raw)
  To: u-boot; +Cc: Rick Chen, Leo, 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.

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

-- 
2.39.2


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

* [PATCH 1/3] riscv: add generic link for <asm/atomic.h>
  2023-05-05  8:02 riscv: asm update for building ubifs Ben Dooks
@ 2023-05-05  8:02 ` Ben Dooks
  2023-06-12  7:31   ` Leo Liang
  2023-05-05  8:02 ` [PATCH 2/3] riscv: implement local_irq_{save,restore} macros Ben Dooks
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Ben Dooks @ 2023-05-05  8:02 UTC (permalink / raw)
  To: u-boot; +Cc: Rick Chen, Leo, 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 <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
-- 
2.39.2


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

* [PATCH 2/3] riscv: implement local_irq_{save,restore} macros
  2023-05-05  8:02 riscv: asm update for building ubifs Ben Dooks
  2023-05-05  8:02 ` [PATCH 1/3] riscv: add generic link for <asm/atomic.h> Ben Dooks
@ 2023-05-05  8:02 ` Ben Dooks
  2023-06-12  7:47   ` Leo Liang
  2023-05-05  8:02 ` [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h Ben Dooks
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Ben Dooks @ 2023-05-05  8:02 UTC (permalink / raw)
  To: u-boot; +Cc: Rick Chen, Leo, 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 <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);
 
-- 
2.39.2


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

* [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h
  2023-05-05  8:02 riscv: asm update for building ubifs Ben Dooks
  2023-05-05  8:02 ` [PATCH 1/3] riscv: add generic link for <asm/atomic.h> Ben Dooks
  2023-05-05  8:02 ` [PATCH 2/3] riscv: implement local_irq_{save,restore} macros Ben Dooks
@ 2023-05-05  8:02 ` Ben Dooks
  2023-06-12  7:48   ` Leo Liang
  2023-05-11 11:56 ` riscv: asm update for building ubifs Conor Dooley
  2023-05-25 11:01 ` Ben Dooks
  4 siblings, 1 reply; 10+ messages in thread
From: Ben Dooks @ 2023-05-05  8:02 UTC (permalink / raw)
  To: u-boot; +Cc: Rick Chen, Leo, 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 <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
-- 
2.39.2


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

* Re: riscv: asm update for building ubifs
  2023-05-05  8:02 riscv: asm update for building ubifs Ben Dooks
                   ` (2 preceding siblings ...)
  2023-05-05  8:02 ` [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h Ben Dooks
@ 2023-05-11 11:56 ` Conor Dooley
  2023-05-25 11:01 ` Ben Dooks
  4 siblings, 0 replies; 10+ messages in thread
From: Conor Dooley @ 2023-05-11 11:56 UTC (permalink / raw)
  To: Ben Dooks; +Cc: u-boot, Rick Chen, Leo

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

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.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: riscv: asm update for building ubifs
  2023-05-05  8:02 riscv: asm update for building ubifs Ben Dooks
                   ` (3 preceding siblings ...)
  2023-05-11 11:56 ` riscv: asm update for building ubifs Conor Dooley
@ 2023-05-25 11:01 ` Ben Dooks
  4 siblings, 0 replies; 10+ messages in thread
From: Ben Dooks @ 2023-05-25 11:01 UTC (permalink / raw)
  To: Ben Dooks, u-boot; +Cc: Rick Chen, Leo, Ben Dooks

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
> 

-- 
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html


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

* Re: [PATCH 1/3] riscv: add generic link for <asm/atomic.h>
  2023-05-05  8:02 ` [PATCH 1/3] riscv: add generic link for <asm/atomic.h> Ben Dooks
@ 2023-06-12  7:31   ` Leo Liang
  0 siblings, 0 replies; 10+ messages in thread
From: Leo Liang @ 2023-06-12  7:31 UTC (permalink / raw)
  To: Ben Dooks; +Cc: u-boot, Rick Chen

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>

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

* Re: [PATCH 2/3] riscv: implement local_irq_{save,restore} macros
  2023-05-05  8:02 ` [PATCH 2/3] riscv: implement local_irq_{save,restore} macros Ben Dooks
@ 2023-06-12  7:47   ` Leo Liang
  2023-06-23  9:57     ` Ben Dooks
  0 siblings, 1 reply; 10+ messages in thread
From: Leo Liang @ 2023-06-12  7:47 UTC (permalink / raw)
  To: Ben Dooks; +Cc: u-boot, Rick Chen, ben.dooks

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
> 

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

* Re: [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h
  2023-05-05  8:02 ` [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h Ben Dooks
@ 2023-06-12  7:48   ` Leo Liang
  0 siblings, 0 replies; 10+ messages in thread
From: Leo Liang @ 2023-06-12  7:48 UTC (permalink / raw)
  To: Ben Dooks; +Cc: u-boot, Rick Chen, ben.dooks

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> 

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

* Re: [PATCH 2/3] riscv: implement local_irq_{save,restore} macros
  2023-06-12  7:47   ` Leo Liang
@ 2023-06-23  9:57     ` Ben Dooks
  0 siblings, 0 replies; 10+ messages in thread
From: Ben Dooks @ 2023-06-23  9:57 UTC (permalink / raw)
  To: Leo Liang; +Cc: Ben Dooks, u-boot, Rick Chen



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.

-- 
Ben

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

end of thread, other threads:[~2023-06-23  9:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-05  8:02 riscv: asm update for building ubifs Ben Dooks
2023-05-05  8:02 ` [PATCH 1/3] riscv: add generic link for <asm/atomic.h> Ben Dooks
2023-06-12  7:31   ` Leo Liang
2023-05-05  8:02 ` [PATCH 2/3] riscv: implement local_irq_{save,restore} macros Ben Dooks
2023-06-12  7:47   ` Leo Liang
2023-06-23  9:57     ` Ben Dooks
2023-05-05  8:02 ` [PATCH 3/3] riscv: define test_and_{set,clear}_bit in asm/bitops.h Ben Dooks
2023-06-12  7:48   ` Leo Liang
2023-05-11 11:56 ` riscv: asm update for building ubifs Conor Dooley
2023-05-25 11:01 ` Ben Dooks

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