From 6427759b33c9ac4e2c75f968d80291cb811dfc15 Mon Sep 17 00:00:00 2001
From: Heiko Stuebner <heiko@sntech.de>
Date: Wed, 12 Jan 2022 21:15:04 +0100
Subject: [PATCH 08/14] riscv: move boot alternatives to a slightly earlier
 position

Move the application of boot alternatives to soc_early_init().
This allows to catch more generic cases of code needing patches
than doing it in smp_prepare_boot_cpu() and also makes it actually
work if CONFIG_SMP is disabled for whatever reason.

The position is chosen mainly as it is before the actual soc early
init runs but also already allows accessing the devicetree
via fdt_* functions.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 arch/riscv/kernel/smpboot.c | 2 --
 arch/riscv/kernel/soc.c     | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index a6d13dca1403..f1e4948a4b52 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -32,7 +32,6 @@
 #include <asm/sections.h>
 #include <asm/sbi.h>
 #include <asm/smp.h>
-#include <asm/alternative.h>
 
 #include "head.h"
 
@@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
 void __init smp_prepare_boot_cpu(void)
 {
 	init_cpu_topology();
-	apply_boot_alternatives();
 }
 
 void __init smp_prepare_cpus(unsigned int max_cpus)
diff --git a/arch/riscv/kernel/soc.c b/arch/riscv/kernel/soc.c
index a0516172a33c..b4e8aae59b82 100644
--- a/arch/riscv/kernel/soc.c
+++ b/arch/riscv/kernel/soc.c
@@ -5,6 +5,7 @@
 #include <linux/init.h>
 #include <linux/libfdt.h>
 #include <linux/pgtable.h>
+#include <asm/alternative.h>
 #include <asm/soc.h>
 
 /*
@@ -17,6 +18,8 @@ void __init soc_early_init(void)
 	const struct of_device_id *s;
 	const void *fdt = dtb_early_va;
 
+	apply_boot_alternatives();
+
 	for (s = (void *)&__soc_early_init_table_start;
 	     (void *)s < (void *)&__soc_early_init_table_end; s++) {
 		if (!fdt_node_check_compatible(fdt, 0, s->compatible)) {
-- 
2.30.2

