All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports
@ 2025-01-23  9:11 Yao Zi
  2025-01-23  9:11 ` [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux() Yao Zi
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Yao Zi @ 2025-01-23  9:11 UTC (permalink / raw)
  To: Rick Chen, Leo, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass
  Cc: u-boot, Yao Zi

This series introduces a generic version of cleanup_before_linux(),
because most RISC-V SoCs have similar implementation. Ports for generic
platforms and JH7110 are converted to use it for now: these devices are
available to me and I have verified that Linux boots with these changes.

With a quick look at the codebase, I think this could be done for all
RISC-V ports ultimately. Thanks for your feedback and review.

Yao Zi (3):
  riscv: add a generic implementation for cleanup_before_linux()
  riscv: cpu: generic: fallback to generic cleanup_before_linux()
  riscv: cpu: jh7110: fallback to generic cleanup_before_linux()

 arch/riscv/cpu/cpu.c            | 17 +++++++++++++++++
 arch/riscv/cpu/generic/Makefile |  1 -
 arch/riscv/cpu/generic/cpu.c    | 22 ----------------------
 arch/riscv/cpu/jh7110/Makefile  |  1 -
 arch/riscv/cpu/jh7110/cpu.c     | 23 -----------------------
 5 files changed, 17 insertions(+), 47 deletions(-)
 delete mode 100644 arch/riscv/cpu/generic/cpu.c
 delete mode 100644 arch/riscv/cpu/jh7110/cpu.c

-- 
2.48.0


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

* [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux()
  2025-01-23  9:11 [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yao Zi
@ 2025-01-23  9:11 ` Yao Zi
  2025-02-03  3:51   ` Leo Liang
  2025-01-23  9:11 ` [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux() Yao Zi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Yao Zi @ 2025-01-23  9:11 UTC (permalink / raw)
  To: Rick Chen, Leo, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass
  Cc: u-boot, Yao Zi

Most RISC-V SoCs have similar cleanup_before_linux() functions. Let's
provide a weak symbol as fallback to reduce duplicated code.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 arch/riscv/cpu/cpu.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
index 06ecd92b9bc..5b31da64cbd 100644
--- a/arch/riscv/cpu/cpu.c
+++ b/arch/riscv/cpu/cpu.c
@@ -11,11 +11,13 @@
 #include <event.h>
 #include <hang.h>
 #include <init.h>
+#include <irq_func.h>
 #include <log.h>
 #include <asm/encoding.h>
 #include <asm/system.h>
 #include <asm/hwcap.h>
 #include <asm/cpufeature.h>
+#include <asm/cache.h>
 #include <dm/uclass-internal.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
@@ -729,3 +731,18 @@ void reset_cpu(void)
 	hang();
 }
 #endif
+
+/*
+ * cleanup_before_linux() is called just before we call linux, which prepares
+ * the processor for linux.
+ * this weak implementation is used by default. we disable interrupts and flush
+ * the cache.
+ */
+__weak int cleanup_before_linux(void)
+{
+	disable_interrupts();
+
+	cache_flush();
+
+	return 0;
+}
-- 
2.48.0


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

* [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux()
  2025-01-23  9:11 [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yao Zi
  2025-01-23  9:11 ` [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux() Yao Zi
@ 2025-01-23  9:11 ` Yao Zi
  2025-02-03  3:52   ` Leo Liang
  2025-01-23  9:11 ` [RFC PATCH 3/3] riscv: cpu: jh7110: " Yao Zi
  2025-01-29 11:28 ` [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yixun Lan
  3 siblings, 1 reply; 8+ messages in thread
From: Yao Zi @ 2025-01-23  9:11 UTC (permalink / raw)
  To: Rick Chen, Leo, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass
  Cc: u-boot, Yao Zi

The current implementation is equivalent to the fallback one, so
this shouldn't change any behaviour but cleans the code up only.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 arch/riscv/cpu/generic/Makefile |  1 -
 arch/riscv/cpu/generic/cpu.c    | 22 ----------------------
 2 files changed, 23 deletions(-)
 delete mode 100644 arch/riscv/cpu/generic/cpu.c

diff --git a/arch/riscv/cpu/generic/Makefile b/arch/riscv/cpu/generic/Makefile
index 258e4620dd4..a9be44ec387 100644
--- a/arch/riscv/cpu/generic/Makefile
+++ b/arch/riscv/cpu/generic/Makefile
@@ -3,4 +3,3 @@
 # Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
 
 obj-y += dram.o
-obj-y += cpu.o
diff --git a/arch/riscv/cpu/generic/cpu.c b/arch/riscv/cpu/generic/cpu.c
deleted file mode 100644
index f13c18942f3..00000000000
--- a/arch/riscv/cpu/generic/cpu.c
+++ /dev/null
@@ -1,22 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
- */
-
-#include <irq_func.h>
-#include <asm/cache.h>
-
-/*
- * cleanup_before_linux() is called just before we call linux
- * it prepares the processor for linux
- *
- * we disable interrupt and caches.
- */
-int cleanup_before_linux(void)
-{
-	disable_interrupts();
-
-	cache_flush();
-
-	return 0;
-}
-- 
2.48.0


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

* [RFC PATCH 3/3] riscv: cpu: jh7110: fallback to generic cleanup_before_linux()
  2025-01-23  9:11 [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yao Zi
  2025-01-23  9:11 ` [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux() Yao Zi
  2025-01-23  9:11 ` [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux() Yao Zi
@ 2025-01-23  9:11 ` Yao Zi
  2025-02-03  3:53   ` Leo Liang
  2025-01-29 11:28 ` [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yixun Lan
  3 siblings, 1 reply; 8+ messages in thread
From: Yao Zi @ 2025-01-23  9:11 UTC (permalink / raw)
  To: Rick Chen, Leo, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass
  Cc: u-boot, Yao Zi

JH7110 SoC requires no specific handling before entering Linux kernel.
Let's drop the specific implementation to avoid duplication.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 arch/riscv/cpu/jh7110/Makefile |  1 -
 arch/riscv/cpu/jh7110/cpu.c    | 23 -----------------------
 2 files changed, 24 deletions(-)
 delete mode 100644 arch/riscv/cpu/jh7110/cpu.c

diff --git a/arch/riscv/cpu/jh7110/Makefile b/arch/riscv/cpu/jh7110/Makefile
index 0939c1061d0..4f91aafa9da 100644
--- a/arch/riscv/cpu/jh7110/Makefile
+++ b/arch/riscv/cpu/jh7110/Makefile
@@ -5,6 +5,5 @@
 ifeq ($(CONFIG_XPL_BUILD),y)
 obj-y += spl.o
 else
-obj-y += cpu.o
 obj-y += dram.o
 endif
diff --git a/arch/riscv/cpu/jh7110/cpu.c b/arch/riscv/cpu/jh7110/cpu.c
deleted file mode 100644
index 1d7c026584a..00000000000
--- a/arch/riscv/cpu/jh7110/cpu.c
+++ /dev/null
@@ -1,23 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2022 StarFive Technology Co., Ltd.
- * Author: Yanhong Wang <yanhong.wang@starfivetech.com>
- */
-
-#include <asm/cache.h>
-#include <irq_func.h>
-
-/*
- * cleanup_before_linux() is called just before we call linux
- * it prepares the processor for linux
- *
- * we disable interrupt and caches.
- */
-int cleanup_before_linux(void)
-{
-	disable_interrupts();
-
-	cache_flush();
-
-	return 0;
-}
-- 
2.48.0


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

* Re: [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports
  2025-01-23  9:11 [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yao Zi
                   ` (2 preceding siblings ...)
  2025-01-23  9:11 ` [RFC PATCH 3/3] riscv: cpu: jh7110: " Yao Zi
@ 2025-01-29 11:28 ` Yixun Lan
  3 siblings, 0 replies; 8+ messages in thread
From: Yixun Lan @ 2025-01-29 11:28 UTC (permalink / raw)
  To: Yao Zi
  Cc: Rick Chen, Leo, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass, u-boot

Hi Yao:

I think you can just drop "RFC" in next version

On 09:11 Thu 23 Jan     , Yao Zi wrote:
> This series introduces a generic version of cleanup_before_linux(),
> because most RISC-V SoCs have similar implementation. Ports for generic
> platforms and JH7110 are converted to use it for now: these devices are
> available to me and I have verified that Linux boots with these changes.
> 
thanks, generally I like this direction

> With a quick look at the codebase, I think this could be done for all
> RISC-V ports ultimately. Thanks for your feedback and review.
> 
can you go ahead and further cleanup other boards?

> Yao Zi (3):
>   riscv: add a generic implementation for cleanup_before_linux()
>   riscv: cpu: generic: fallback to generic cleanup_before_linux()
>   riscv: cpu: jh7110: fallback to generic cleanup_before_linux()
> 
>  arch/riscv/cpu/cpu.c            | 17 +++++++++++++++++
>  arch/riscv/cpu/generic/Makefile |  1 -
>  arch/riscv/cpu/generic/cpu.c    | 22 ----------------------
>  arch/riscv/cpu/jh7110/Makefile  |  1 -
>  arch/riscv/cpu/jh7110/cpu.c     | 23 -----------------------
>  5 files changed, 17 insertions(+), 47 deletions(-)
>  delete mode 100644 arch/riscv/cpu/generic/cpu.c
>  delete mode 100644 arch/riscv/cpu/jh7110/cpu.c
> 
> -- 
> 2.48.0
> 

-- 
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55

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

* Re: [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux()
  2025-01-23  9:11 ` [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux() Yao Zi
@ 2025-02-03  3:51   ` Leo Liang
  0 siblings, 0 replies; 8+ messages in thread
From: Leo Liang @ 2025-02-03  3:51 UTC (permalink / raw)
  To: Yao Zi
  Cc: Rick Chen, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass, u-boot

On Thu, Jan 23, 2025 at 09:11:33AM +0000, Yao Zi wrote:
> Most RISC-V SoCs have similar cleanup_before_linux() functions. Let's
> provide a weak symbol as fallback to reduce duplicated code.
> 
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  arch/riscv/cpu/cpu.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

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

* Re: [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux()
  2025-01-23  9:11 ` [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux() Yao Zi
@ 2025-02-03  3:52   ` Leo Liang
  0 siblings, 0 replies; 8+ messages in thread
From: Leo Liang @ 2025-02-03  3:52 UTC (permalink / raw)
  To: Yao Zi
  Cc: Rick Chen, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass, u-boot

On Thu, Jan 23, 2025 at 09:11:34AM +0000, Yao Zi wrote:
> The current implementation is equivalent to the fallback one, so
> this shouldn't change any behaviour but cleans the code up only.
> 
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  arch/riscv/cpu/generic/Makefile |  1 -
>  arch/riscv/cpu/generic/cpu.c    | 22 ----------------------
>  2 files changed, 23 deletions(-)
>  delete mode 100644 arch/riscv/cpu/generic/cpu.c

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

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

* Re: [RFC PATCH 3/3] riscv: cpu: jh7110: fallback to generic cleanup_before_linux()
  2025-01-23  9:11 ` [RFC PATCH 3/3] riscv: cpu: jh7110: " Yao Zi
@ 2025-02-03  3:53   ` Leo Liang
  0 siblings, 0 replies; 8+ messages in thread
From: Leo Liang @ 2025-02-03  3:53 UTC (permalink / raw)
  To: Yao Zi
  Cc: Rick Chen, Tom Rini, Conor Dooley, Mayuresh Chitale,
	Heinrich Schuchardt, Simon Glass, u-boot

On Thu, Jan 23, 2025 at 09:11:35AM +0000, Yao Zi wrote:
> JH7110 SoC requires no specific handling before entering Linux kernel.
> Let's drop the specific implementation to avoid duplication.
> 
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  arch/riscv/cpu/jh7110/Makefile |  1 -
>  arch/riscv/cpu/jh7110/cpu.c    | 23 -----------------------
>  2 files changed, 24 deletions(-)
>  delete mode 100644 arch/riscv/cpu/jh7110/cpu.c

Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

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

end of thread, other threads:[~2025-02-03  3:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-23  9:11 [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yao Zi
2025-01-23  9:11 ` [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux() Yao Zi
2025-02-03  3:51   ` Leo Liang
2025-01-23  9:11 ` [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux() Yao Zi
2025-02-03  3:52   ` Leo Liang
2025-01-23  9:11 ` [RFC PATCH 3/3] riscv: cpu: jh7110: " Yao Zi
2025-02-03  3:53   ` Leo Liang
2025-01-29 11:28 ` [RFC PATCH 0/3] Unify implementation of cleanup_before_linux() for RISC-V ports Yixun Lan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.