cpu-hotplug.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020 Western Digital Corporation or its affiliates.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/mm.h>
  7. #include <linux/sched.h>
  8. #include <linux/err.h>
  9. #include <linux/irq.h>
  10. #include <linux/cpu.h>
  11. #include <linux/sched/hotplug.h>
  12. #include <asm/irq.h>
  13. #include <asm/cpu_ops.h>
  14. #include <asm/numa.h>
  15. #include <asm/sbi.h>
  16. bool cpu_has_hotplug(unsigned int cpu)
  17. {
  18. if (cpu_ops[cpu]->cpu_stop)
  19. return true;
  20. return false;
  21. }
  22. /*
  23. * __cpu_disable runs on the processor to be shutdown.
  24. */
  25. int __cpu_disable(void)
  26. {
  27. int ret = 0;
  28. unsigned int cpu = smp_processor_id();
  29. if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop)
  30. return -EOPNOTSUPP;
  31. if (cpu_ops[cpu]->cpu_disable)
  32. ret = cpu_ops[cpu]->cpu_disable(cpu);
  33. if (ret)
  34. return ret;
  35. remove_cpu_topology(cpu);
  36. numa_remove_cpu(cpu);
  37. set_cpu_online(cpu, false);
  38. irq_migrate_all_off_this_cpu();
  39. return ret;
  40. }
  41. /*
  42. * Called on the thread which is asking for a CPU to be shutdown.
  43. */
  44. void __cpu_die(unsigned int cpu)
  45. {
  46. int ret = 0;
  47. if (!cpu_wait_death(cpu, 5)) {
  48. pr_err("CPU %u: didn't die\n", cpu);
  49. return;
  50. }
  51. pr_notice("CPU%u: off\n", cpu);
  52. /* Verify from the firmware if the cpu is really stopped*/
  53. if (cpu_ops[cpu]->cpu_is_stopped)
  54. ret = cpu_ops[cpu]->cpu_is_stopped(cpu);
  55. if (ret)
  56. pr_warn("CPU%d may not have stopped: %d\n", cpu, ret);
  57. }
  58. /*
  59. * Called from the idle thread for the CPU which has been shutdown.
  60. */
  61. void arch_cpu_idle_dead(void)
  62. {
  63. idle_task_exit();
  64. (void)cpu_report_death();
  65. cpu_ops[smp_processor_id()]->cpu_stop();
  66. /* It should never reach here */
  67. BUG();
  68. }