^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2020 Western Digital Corporation or its affiliates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/cpu_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/sbi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) void *__cpu_up_stack_pointer[NR_CPUS] __section(".data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) void *__cpu_up_task_pointer[NR_CPUS] __section(".data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) extern const struct cpu_operations cpu_ops_sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) extern const struct cpu_operations cpu_ops_spinwait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void cpu_update_secondary_bootdata(unsigned int cpuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct task_struct *tidle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int hartid = cpuid_to_hartid_map(cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Make sure tidle is updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) WRITE_ONCE(__cpu_up_stack_pointer[hartid],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) task_stack_page(tidle) + THREAD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) WRITE_ONCE(__cpu_up_task_pointer[hartid], tidle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) void __init cpu_set_ops(int cpuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #if IS_ENABLED(CONFIG_RISCV_SBI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (sbi_probe_extension(SBI_EXT_HSM) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (!cpuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) pr_info("SBI v0.2 HSM extension detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) cpu_ops[cpuid] = &cpu_ops_sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) cpu_ops[cpuid] = &cpu_ops_spinwait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }