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/of.h>
8 #include <linux/string.h>
9 #include <asm/cpu_ops.h>
10 #include <asm/sbi.h>
11 #include <asm/smp.h>
12 
13 const struct cpu_operations cpu_ops_spinwait;
14 
15 static int spinwait_cpu_prepare(unsigned int cpuid)
16 {
17 	if (!cpu_ops_spinwait.cpu_start) {
18 		pr_err("cpu start method not defined for CPU [%d]\n", cpuid);
19 		return -ENODEV;
20 	}
21 	return 0;
22 }
23 
24 static int spinwait_cpu_start(unsigned int cpuid, struct task_struct *tidle)
25 {
26 	/*
27 	 * In this protocol, all cpus boot on their own accord.  _start
28 	 * selects the first cpu to boot the kernel and causes the remainder
29 	 * of the cpus to spin in a loop waiting for their stack pointer to be
30 	 * setup by that main cpu.  Writing to bootdata
31 	 * (i.e __cpu_up_stack_pointer) signals to the spinning cpus that they
32 	 * can continue the boot process.
33 	 */
34 	cpu_update_secondary_bootdata(cpuid, tidle);
35 
36 	return 0;
37 }
38 
39 const struct cpu_operations cpu_ops_spinwait = {
40 	.name		= "spinwait",
41 	.cpu_prepare	= spinwait_cpu_prepare,
42 	.cpu_start	= spinwait_cpu_start,
43 };
44