mcpm_platsmp.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-vexpress/mcpm_platsmp.c
  4. *
  5. * Created by: Nicolas Pitre, November 2012
  6. * Copyright: (C) 2012-2013 Linaro Limited
  7. *
  8. * Code to handle secondary CPU bringup and hotplug for the cluster power API.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/smp.h>
  12. #include <linux/spinlock.h>
  13. #include <asm/mcpm.h>
  14. #include <asm/smp.h>
  15. #include <asm/smp_plat.h>
  16. static void cpu_to_pcpu(unsigned int cpu,
  17. unsigned int *pcpu, unsigned int *pcluster)
  18. {
  19. unsigned int mpidr;
  20. mpidr = cpu_logical_map(cpu);
  21. *pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  22. *pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  23. }
  24. static int mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle)
  25. {
  26. unsigned int pcpu, pcluster, ret;
  27. extern void secondary_startup(void);
  28. cpu_to_pcpu(cpu, &pcpu, &pcluster);
  29. pr_debug("%s: logical CPU %d is physical CPU %d cluster %d\n",
  30. __func__, cpu, pcpu, pcluster);
  31. mcpm_set_entry_vector(pcpu, pcluster, NULL);
  32. ret = mcpm_cpu_power_up(pcpu, pcluster);
  33. if (ret)
  34. return ret;
  35. mcpm_set_entry_vector(pcpu, pcluster, secondary_startup);
  36. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  37. dsb_sev();
  38. return 0;
  39. }
  40. static void mcpm_secondary_init(unsigned int cpu)
  41. {
  42. mcpm_cpu_powered_up();
  43. }
  44. #ifdef CONFIG_HOTPLUG_CPU
  45. static int mcpm_cpu_kill(unsigned int cpu)
  46. {
  47. unsigned int pcpu, pcluster;
  48. cpu_to_pcpu(cpu, &pcpu, &pcluster);
  49. return !mcpm_wait_for_cpu_powerdown(pcpu, pcluster);
  50. }
  51. static bool mcpm_cpu_can_disable(unsigned int cpu)
  52. {
  53. /* We assume all CPUs may be shut down. */
  54. return true;
  55. }
  56. static void mcpm_cpu_die(unsigned int cpu)
  57. {
  58. unsigned int mpidr, pcpu, pcluster;
  59. mpidr = read_cpuid_mpidr();
  60. pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  61. pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  62. mcpm_set_entry_vector(pcpu, pcluster, NULL);
  63. mcpm_cpu_power_down();
  64. }
  65. #endif
  66. static const struct smp_operations mcpm_smp_ops __initconst = {
  67. .smp_boot_secondary = mcpm_boot_secondary,
  68. .smp_secondary_init = mcpm_secondary_init,
  69. #ifdef CONFIG_HOTPLUG_CPU
  70. .cpu_kill = mcpm_cpu_kill,
  71. .cpu_can_disable = mcpm_cpu_can_disable,
  72. .cpu_die = mcpm_cpu_die,
  73. #endif
  74. };
  75. void __init mcpm_smp_set_ops(void)
  76. {
  77. smp_set_ops(&mcpm_smp_ops);
  78. }