psci_smp.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 psci_boot_secondary(unsigned int cpu, struct task_struct *idle)
  45. {
  46. if (psci_ops.cpu_on)
  47. return psci_ops.cpu_on(cpu_logical_map(cpu),
  48. __pa(secondary_startup));
  49. return -ENODEV;
  50. }
  51. #ifdef CONFIG_HOTPLUG_CPU
  52. void __ref psci_cpu_die(unsigned int cpu)
  53. {
  54. const struct psci_power_state ps = {
  55. .type = PSCI_POWER_STATE_TYPE_POWER_DOWN,
  56. };
  57. if (psci_ops.cpu_off)
  58. psci_ops.cpu_off(ps);
  59. /* We should never return */
  60. panic("psci: cpu %d failed to shutdown\n", cpu);
  61. }
  62. #endif
  63. bool __init psci_smp_available(void)
  64. {
  65. /* is cpu_on available at least? */
  66. return (psci_ops.cpu_on != NULL);
  67. }
  68. struct smp_operations __initdata psci_smp_ops = {
  69. .smp_boot_secondary = psci_boot_secondary,
  70. #ifdef CONFIG_HOTPLUG_CPU
  71. .cpu_die = psci_cpu_die,
  72. #endif
  73. };