xref: /openbmc/linux/arch/riscv/kernel/cpu_ops.c (revision cd3bc044)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2020 Western Digital Corporation or its affiliates.
4  */
5 
6 #include <linux/errno.h>
7 #include <linux/mm.h>
8 #include <linux/of.h>
9 #include <linux/string.h>
10 #include <linux/sched.h>
11 #include <asm/cpu_ops.h>
12 #include <asm/sbi.h>
13 #include <asm/smp.h>
14 
15 const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
16 
17 extern const struct cpu_operations cpu_ops_sbi;
18 #ifdef CONFIG_RISCV_BOOT_SPINWAIT
19 extern const struct cpu_operations cpu_ops_spinwait;
20 #else
21 const struct cpu_operations cpu_ops_spinwait = {
22 	.name		= "",
23 	.cpu_prepare	= NULL,
24 	.cpu_start	= NULL,
25 };
26 #endif
27 
28 void __init cpu_set_ops(int cpuid)
29 {
30 #if IS_ENABLED(CONFIG_RISCV_SBI)
31 	if (sbi_probe_extension(SBI_EXT_HSM) > 0) {
32 		if (!cpuid)
33 			pr_info("SBI HSM extension detected\n");
34 		cpu_ops[cpuid] = &cpu_ops_sbi;
35 	} else
36 #endif
37 		cpu_ops[cpuid] = &cpu_ops_spinwait;
38 }
39