// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (c) 2020 Western Digital Corporation or its affiliates.3*/45#include <linux/errno.h>6#include <linux/of.h>7#include <linux/string.h>8#include <linux/sched/task_stack.h>9#include <asm/cpu_ops.h>10#include <asm/sbi.h>11#include <asm/smp.h>1213#include "head.h"1415const struct cpu_operations cpu_ops_spinwait;16void *__cpu_spinwait_stack_pointer[NR_CPUS] __section(".data");17void *__cpu_spinwait_task_pointer[NR_CPUS] __section(".data");1819static void cpu_update_secondary_bootdata(unsigned int cpuid,20struct task_struct *tidle)21{22unsigned long hartid = cpuid_to_hartid_map(cpuid);2324/*25* The hartid must be less than NR_CPUS to avoid out-of-bound access26* errors for __cpu_spinwait_stack/task_pointer. That is not always possible27* for platforms with discontiguous hartid numbering scheme. That's why28* spinwait booting is not the recommended approach for any platforms29* booting Linux in S-mode and can be disabled in the future.30*/31if (hartid == INVALID_HARTID || hartid >= (unsigned long) NR_CPUS)32return;3334/* Make sure tidle is updated */35smp_mb();36WRITE_ONCE(__cpu_spinwait_stack_pointer[hartid], task_pt_regs(tidle));37WRITE_ONCE(__cpu_spinwait_task_pointer[hartid], tidle);38}3940static int spinwait_cpu_start(unsigned int cpuid, struct task_struct *tidle)41{42/*43* In this protocol, all cpus boot on their own accord. _start44* selects the first cpu to boot the kernel and causes the remainder45* of the cpus to spin in a loop waiting for their stack pointer to be46* setup by that main cpu. Writing to bootdata47* (i.e __cpu_spinwait_stack_pointer) signals to the spinning cpus that they48* can continue the boot process.49*/50cpu_update_secondary_bootdata(cpuid, tidle);5152return 0;53}5455const struct cpu_operations cpu_ops_spinwait = {56.cpu_start = spinwait_cpu_start,57};585960