[RFC PATCH 0/3] 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

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; +}

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; -}

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; -}
participants (1)
-
Yao Zi