Unify implementation of cleanup_before_linux() for RISC-V ports
cover Unify implementation of cleanup_before_linux() for RISC-V ports
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
Signature · 1 line
2.48.0
RFC PATCH 1/3 riscv: add a generic implementation for cleanup_before_linux()
Most RISC-V SoCs have similar cleanup_before_linux() functions. Let's provide a weak symbol as fallback to reduce duplicated code.
--- arch/riscv/cpu/cpu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/riscv/cpu/cpu.c +17 -0
@@ -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 ; +}
Signature · 1 line
2.48.0
Re: [RFC PATCH 1/3] riscv: add a generic implementation for cleanup_before_linux()
Quoted 7 lines · 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 <[email protected]>--- arch/riscv/cpu/cpu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
RFC PATCH 2/3 riscv: cpu: generic: fallback to generic cleanup_before_linux()
In reply to Yao ZiThe current implementation is equivalent to the fallback one, so this shouldn't change any behaviour but cleans the code up only.
--- 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
arch/riscv/cpu/generic/Makefile +0 -1
@@ -3,4 +3,3 @@ # Copyright (C) 2018, Bin Meng <[email protected]> obj-y += dram.o -obj-y += cpu.o
arch/riscv/cpu/generic/cpu.c deleted +0 -22
@@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* -* Copyright (C) 2018, Bin Meng <[email protected]> -*/ - -#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 ; -}
Signature · 1 line
2.48.0
Re: [RFC PATCH 2/3] riscv: cpu: generic: fallback to generic cleanup_before_linux()
Quoted 9 lines · 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 <[email protected]>--- 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
RFC PATCH 3/3 riscv: cpu: jh7110: fallback to generic cleanup_before_linux()
In reply to Yao ZiJH7110 SoC requires no specific handling before entering Linux kernel. Let's drop the specific implementation to avoid duplication.
--- 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
arch/riscv/cpu/jh7110/Makefile +0 -1
@@ -5,6 +5,5 @@ ifeq ($(CONFIG_XPL_BUILD),y) obj-y += spl.o else -obj-y += cpu.o obj-y += dram.o endif
arch/riscv/cpu/jh7110/cpu.c deleted +0 -23
@@ -1,23 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* -* Copyright (C) 2022 StarFive Technology Co., Ltd. -* Author: Yanhong Wang <[email protected]> -*/ - -#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 ; -}
Signature · 1 line
2.48.0
Re: [RFC PATCH 3/3] riscv: cpu: jh7110: fallback to generic cleanup_before_linux()
Quoted 9 lines · 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 <[email protected]>--- 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
Hi Yao:
I think you can just drop "RFC" in next version
Quoted 5 lines · 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.
thanks, generally I like this direction
Quoted 3 lines
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?
Quoted 17 lines
Yao Zi (3):
riscv: add a generic implementation forcleanup_before_linux()
riscv: cpu: generic: fallback to genericcleanup_before_linux()
riscv: cpu: jh7110: fallback to genericcleanup_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.cSignature · 1 line
2.48.0
Signature · 3 lines
Yixun Lan (dlan) Gentoo Linux Developer GPG Key ID AABEFD55