cpu_ops_spinwait.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  4. */
  5. #include <linux/errno.h>
  6. #include <linux/of.h>
  7. #include <linux/string.h>
  8. #include <asm/cpu_ops.h>
  9. #include <asm/sbi.h>
  10. #include <asm/smp.h>
  11. const struct cpu_operations cpu_ops_spinwait;
  12. static int spinwait_cpu_prepare(unsigned int cpuid)
  13. {
  14. if (!cpu_ops_spinwait.cpu_start) {
  15. pr_err("cpu start method not defined for CPU [%d]\n", cpuid);
  16. return -ENODEV;
  17. }
  18. return 0;
  19. }
  20. static int spinwait_cpu_start(unsigned int cpuid, struct task_struct *tidle)
  21. {
  22. /*
  23. * In this protocol, all cpus boot on their own accord. _start
  24. * selects the first cpu to boot the kernel and causes the remainder
  25. * of the cpus to spin in a loop waiting for their stack pointer to be
  26. * setup by that main cpu. Writing to bootdata
  27. * (i.e __cpu_up_stack_pointer) signals to the spinning cpus that they
  28. * can continue the boot process.
  29. */
  30. cpu_update_secondary_bootdata(cpuid, tidle);
  31. sbi_ecall(0x09000003, 0, cpuid_to_hartid_map(cpuid), 0, 0, 0, 0, 0);
  32. return 0;
  33. }
  34. const struct cpu_operations cpu_ops_spinwait = {
  35. .name = "spinwait",
  36. .cpu_prepare = spinwait_cpu_prepare,
  37. .cpu_start = spinwait_cpu_start,
  38. };