smp.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_SMP_H
  6. #define __ASM_SMP_H
  7. #include <linux/const.h>
  8. /* Values for secondary_data.status */
  9. #define CPU_STUCK_REASON_SHIFT (8)
  10. #define CPU_BOOT_STATUS_MASK ((UL(1) << CPU_STUCK_REASON_SHIFT) - 1)
  11. #define CPU_MMU_OFF (-1)
  12. #define CPU_BOOT_SUCCESS (0)
  13. /* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */
  14. #define CPU_KILL_ME (1)
  15. /* The cpu couldn't die gracefully and is looping in the kernel */
  16. #define CPU_STUCK_IN_KERNEL (2)
  17. /* Fatal system error detected by secondary CPU, crash the system */
  18. #define CPU_PANIC_KERNEL (3)
  19. #define CPU_STUCK_REASON_52_BIT_VA (UL(1) << CPU_STUCK_REASON_SHIFT)
  20. #define CPU_STUCK_REASON_NO_GRAN (UL(2) << CPU_STUCK_REASON_SHIFT)
  21. #ifndef __ASSEMBLY__
  22. #include <linux/threads.h>
  23. #include <linux/cpumask.h>
  24. #include <linux/thread_info.h>
  25. #define raw_smp_processor_id() (current_thread_info()->cpu)
  26. /*
  27. * Logical CPU mapping.
  28. */
  29. extern u64 __cpu_logical_map[NR_CPUS];
  30. extern u64 cpu_logical_map(unsigned int cpu);
  31. static inline void set_cpu_logical_map(unsigned int cpu, u64 hwid)
  32. {
  33. __cpu_logical_map[cpu] = hwid;
  34. }
  35. struct seq_file;
  36. /*
  37. * Discover the set of possible CPUs and determine their
  38. * SMP operations.
  39. */
  40. extern void smp_init_cpus(void);
  41. /*
  42. * Register IPI interrupts with the arch SMP code
  43. */
  44. extern void set_smp_ipi_range(int ipi_base, int nr_ipi);
  45. /*
  46. * Called from the secondary holding pen, this is the secondary CPU entry point.
  47. */
  48. asmlinkage void secondary_start_kernel(void);
  49. /*
  50. * Initial data for bringing up a secondary CPU.
  51. * @status - Result passed back from the secondary CPU to
  52. * indicate failure.
  53. */
  54. struct secondary_data {
  55. struct task_struct *task;
  56. long status;
  57. };
  58. extern struct secondary_data secondary_data;
  59. extern long __early_cpu_boot_status;
  60. extern void secondary_entry(void);
  61. extern void arch_send_call_function_single_ipi(int cpu);
  62. extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
  63. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  64. extern void arch_send_wakeup_ipi(unsigned int cpu);
  65. #else
  66. static inline void arch_send_wakeup_ipi(unsigned int cpu)
  67. {
  68. BUILD_BUG();
  69. }
  70. #endif
  71. extern int __cpu_disable(void);
  72. static inline void __cpu_die(unsigned int cpu) { }
  73. extern void __noreturn cpu_die(void);
  74. extern void __noreturn cpu_die_early(void);
  75. static inline void __noreturn cpu_park_loop(void)
  76. {
  77. for (;;) {
  78. wfe();
  79. wfi();
  80. }
  81. }
  82. static inline void update_cpu_boot_status(int val)
  83. {
  84. WRITE_ONCE(secondary_data.status, val);
  85. /* Ensure the visibility of the status update */
  86. dsb(ishst);
  87. }
  88. /*
  89. * The calling secondary CPU has detected serious configuration mismatch,
  90. * which calls for a kernel panic. Update the boot status and park the calling
  91. * CPU.
  92. */
  93. static inline void __noreturn cpu_panic_kernel(void)
  94. {
  95. update_cpu_boot_status(CPU_PANIC_KERNEL);
  96. cpu_park_loop();
  97. }
  98. /*
  99. * If a secondary CPU enters the kernel but fails to come online,
  100. * (e.g. due to mismatched features), and cannot exit the kernel,
  101. * we increment cpus_stuck_in_kernel and leave the CPU in a
  102. * quiesecent loop within the kernel text. The memory containing
  103. * this loop must not be re-used for anything else as the 'stuck'
  104. * core is executing it.
  105. *
  106. * This function is used to inhibit features like kexec and hibernate.
  107. */
  108. bool cpus_are_stuck_in_kernel(void);
  109. extern void crash_smp_send_stop(void);
  110. extern bool smp_crash_stop_failed(void);
  111. #endif /* ifndef __ASSEMBLY__ */
  112. #endif /* ifndef __ASM_SMP_H */