smp.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_SMP_H
  17. #define __ASM_SMP_H
  18. /* Values for secondary_data.status */
  19. #define CPU_MMU_OFF (-1)
  20. #define CPU_BOOT_SUCCESS (0)
  21. /* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */
  22. #define CPU_KILL_ME (1)
  23. /* The cpu couldn't die gracefully and is looping in the kernel */
  24. #define CPU_STUCK_IN_KERNEL (2)
  25. /* Fatal system error detected by secondary CPU, crash the system */
  26. #define CPU_PANIC_KERNEL (3)
  27. #ifndef __ASSEMBLY__
  28. #include <linux/threads.h>
  29. #include <linux/cpumask.h>
  30. #include <linux/thread_info.h>
  31. #define raw_smp_processor_id() (current_thread_info()->cpu)
  32. struct seq_file;
  33. /*
  34. * generate IPI list text
  35. */
  36. extern void show_ipi_list(struct seq_file *p, int prec);
  37. /*
  38. * Called from C code, this handles an IPI.
  39. */
  40. extern void handle_IPI(int ipinr, struct pt_regs *regs);
  41. /*
  42. * Discover the set of possible CPUs and determine their
  43. * SMP operations.
  44. */
  45. extern void smp_init_cpus(void);
  46. /*
  47. * Provide a function to raise an IPI cross call on CPUs in callmap.
  48. */
  49. extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
  50. extern void (*__smp_cross_call)(const struct cpumask *, unsigned int);
  51. /*
  52. * Called from the secondary holding pen, this is the secondary CPU entry point.
  53. */
  54. asmlinkage void secondary_start_kernel(void);
  55. /*
  56. * Initial data for bringing up a secondary CPU.
  57. * @stack - sp for the secondary CPU
  58. * @status - Result passed back from the secondary CPU to
  59. * indicate failure.
  60. */
  61. struct secondary_data {
  62. void *stack;
  63. long status;
  64. };
  65. extern struct secondary_data secondary_data;
  66. extern long __early_cpu_boot_status;
  67. extern void secondary_entry(void);
  68. extern void arch_send_call_function_single_ipi(int cpu);
  69. extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
  70. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  71. extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask);
  72. #else
  73. static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
  74. {
  75. BUILD_BUG();
  76. }
  77. #endif
  78. extern int __cpu_disable(void);
  79. extern void __cpu_die(unsigned int cpu);
  80. extern void cpu_die(void);
  81. extern void cpu_die_early(void);
  82. static inline void cpu_park_loop(void)
  83. {
  84. for (;;) {
  85. wfe();
  86. wfi();
  87. }
  88. }
  89. static inline void update_cpu_boot_status(int val)
  90. {
  91. WRITE_ONCE(secondary_data.status, val);
  92. /* Ensure the visibility of the status update */
  93. dsb(ishst);
  94. }
  95. /*
  96. * The calling secondary CPU has detected serious configuration mismatch,
  97. * which calls for a kernel panic. Update the boot status and park the calling
  98. * CPU.
  99. */
  100. static inline void cpu_panic_kernel(void)
  101. {
  102. update_cpu_boot_status(CPU_PANIC_KERNEL);
  103. cpu_park_loop();
  104. }
  105. /*
  106. * If a secondary CPU enters the kernel but fails to come online,
  107. * (e.g. due to mismatched features), and cannot exit the kernel,
  108. * we increment cpus_stuck_in_kernel and leave the CPU in a
  109. * quiesecent loop within the kernel text. The memory containing
  110. * this loop must not be re-used for anything else as the 'stuck'
  111. * core is executing it.
  112. *
  113. * This function is used to inhibit features like kexec and hibernate.
  114. */
  115. bool cpus_are_stuck_in_kernel(void);
  116. #endif /* ifndef __ASSEMBLY__ */
  117. #endif /* ifndef __ASM_SMP_H */