psci_smp.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License version 2 as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * Copyright (C) 2012 ARM Limited
  12. *
  13. * Author: Will Deacon <will.deacon@arm.com>
  14. */
  15. #include <linux/init.h>
  16. #include <linux/irqchip/arm-gic.h>
  17. #include <linux/smp.h>
  18. #include <linux/of.h>
  19. #include <asm/psci.h>
  20. #include <asm/smp_plat.h>
  21. /*
  22. * psci_smp assumes that the following is true about PSCI:
  23. *
  24. * cpu_suspend Suspend the execution on a CPU
  25. * @state we don't currently describe affinity levels, so just pass 0.
  26. * @entry_point the first instruction to be executed on return
  27. * returns 0 success, < 0 on failure
  28. *
  29. * cpu_off Power down a CPU
  30. * @state we don't currently describe affinity levels, so just pass 0.
  31. * no return on successful call
  32. *
  33. * cpu_on Power up a CPU
  34. * @cpuid cpuid of target CPU, as from MPIDR
  35. * @entry_point the first instruction to be executed on return
  36. * returns 0 success, < 0 on failure
  37. *
  38. * migrate Migrate the context to a different CPU
  39. * @cpuid cpuid of target CPU, as from MPIDR
  40. * returns 0 success, < 0 on failure
  41. *
  42. */
  43. extern void secondary_startup(void);
  44. static int __cpuinit psci_boot_secondary(unsigned int cpu,
  45. struct task_struct *idle)
  46. {
  47. if (psci_ops.cpu_on)
  48. return psci_ops.cpu_on(cpu_logical_map(cpu),
  49. __pa(secondary_startup));
  50. return -ENODEV;
  51. }
  52. #ifdef CONFIG_HOTPLUG_CPU
  53. void __ref psci_cpu_die(unsigned int cpu)
  54. {
  55. const struct psci_power_state ps = {
  56. .type = PSCI_POWER_STATE_TYPE_POWER_DOWN,
  57. };
  58. if (psci_ops.cpu_off)
  59. psci_ops.cpu_off(ps);
  60. /* We should never return */
  61. panic("psci: cpu %d failed to shutdown\n", cpu);
  62. }
  63. #endif
  64. bool __init psci_smp_available(void)
  65. {
  66. /* is cpu_on available at least? */
  67. return (psci_ops.cpu_on != NULL);
  68. }
  69. struct smp_operations __initdata psci_smp_ops = {
  70. .smp_boot_secondary = psci_boot_secondary,
  71. #ifdef CONFIG_HOTPLUG_CPU
  72. .cpu_die = psci_cpu_die,
  73. #endif
  74. };