mcpm_platsmp.c 2.3 KB

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