smp.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 <asm/percpu.h>
  23. #include <linux/threads.h>
  24. #include <linux/cpumask.h>
  25. #include <linux/thread_info.h>
  26. DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  27. /*
  28. * We don't use this_cpu_read(cpu_number) as that has implicit writes to
  29. * preempt_count, and associated (compiler) barriers, that we'd like to avoid
  30. * the expense of. If we're preemptible, the value can be stale at use anyway.
  31. * And we can't use this_cpu_ptr() either, as that winds up recursing back
  32. * here under CONFIG_DEBUG_PREEMPT=y.
  33. */
  34. #define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number))
  35. /*
  36. * Logical CPU mapping.
  37. */
  38. extern u64 __cpu_logical_map[NR_CPUS];
  39. extern u64 cpu_logical_map(unsigned int cpu);
  40. static inline void set_cpu_logical_map(unsigned int cpu, u64 hwid)
  41. {
  42. __cpu_logical_map[cpu] = hwid;
  43. }
  44. struct seq_file;
  45. /*
  46. * Discover the set of possible CPUs and determine their
  47. * SMP operations.
  48. */
  49. extern void smp_init_cpus(void);
  50. /*
  51. * Register IPI interrupts with the arch SMP code
  52. */
  53. extern void set_smp_ipi_range(int ipi_base, int nr_ipi);
  54. /*
  55. * Called from the secondary holding pen, this is the secondary CPU entry point.
  56. */
  57. asmlinkage void secondary_start_kernel(void);
  58. /*
  59. * Initial data for bringing up a secondary CPU.
  60. * @status - Result passed back from the secondary CPU to
  61. * indicate failure.
  62. */
  63. struct secondary_data {
  64. struct task_struct *task;
  65. long status;
  66. };
  67. extern struct secondary_data secondary_data;
  68. extern long __early_cpu_boot_status;
  69. extern void secondary_entry(void);
  70. extern void arch_send_call_function_single_ipi(int cpu);
  71. extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
  72. extern int nr_ipi_get(void);
  73. extern struct irq_desc **ipi_desc_get(void);
  74. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  75. extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask);
  76. #else
  77. static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
  78. {
  79. BUILD_BUG();
  80. }
  81. #endif
  82. extern int __cpu_disable(void);
  83. extern void __cpu_die(unsigned int cpu);
  84. extern void cpu_die(void);
  85. extern void cpu_die_early(void);
  86. static inline void cpu_park_loop(void)
  87. {
  88. for (;;) {
  89. wfe();
  90. wfi();
  91. }
  92. }
  93. static inline void update_cpu_boot_status(int val)
  94. {
  95. WRITE_ONCE(secondary_data.status, val);
  96. /* Ensure the visibility of the status update */
  97. dsb(ishst);
  98. }
  99. /*
  100. * The calling secondary CPU has detected serious configuration mismatch,
  101. * which calls for a kernel panic. Update the boot status and park the calling
  102. * CPU.
  103. */
  104. static inline void cpu_panic_kernel(void)
  105. {
  106. update_cpu_boot_status(CPU_PANIC_KERNEL);
  107. cpu_park_loop();
  108. }
  109. /*
  110. * If a secondary CPU enters the kernel but fails to come online,
  111. * (e.g. due to mismatched features), and cannot exit the kernel,
  112. * we increment cpus_stuck_in_kernel and leave the CPU in a
  113. * quiesecent loop within the kernel text. The memory containing
  114. * this loop must not be re-used for anything else as the 'stuck'
  115. * core is executing it.
  116. *
  117. * This function is used to inhibit features like kexec and hibernate.
  118. */
  119. bool cpus_are_stuck_in_kernel(void);
  120. extern void crash_smp_send_stop(void);
  121. extern bool smp_crash_stop_failed(void);
  122. extern void panic_smp_self_stop(void);
  123. #endif /* ifndef __ASSEMBLY__ */
  124. #endif /* ifndef __ASM_SMP_H */