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 19 /* Values for secondary_data.status */ 20 #define CPU_STUCK_REASON_SHIFT (8) 21 #define CPU_BOOT_STATUS_MASK ((1U << CPU_STUCK_REASON_SHIFT) - 1) 22 23 #define CPU_MMU_OFF (-1) 24 #define CPU_BOOT_SUCCESS (0) 25 /* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */ 26 #define CPU_KILL_ME (1) 27 /* The cpu couldn't die gracefully and is looping in the kernel */ 28 #define CPU_STUCK_IN_KERNEL (2) 29 /* Fatal system error detected by secondary CPU, crash the system */ 30 #define CPU_PANIC_KERNEL (3) 31 32 #define CPU_STUCK_REASON_52_BIT_VA (1U << CPU_STUCK_REASON_SHIFT) 33 #define CPU_STUCK_REASON_NO_GRAN (2U << CPU_STUCK_REASON_SHIFT) 34 35 #ifndef __ASSEMBLY__ 36 37 #include <asm/percpu.h> 38 39 #include <linux/threads.h> 40 #include <linux/cpumask.h> 41 #include <linux/thread_info.h> 42 43 DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number); 44 45 /* 46 * We don't use this_cpu_read(cpu_number) as that has implicit writes to 47 * preempt_count, and associated (compiler) barriers, that we'd like to avoid 48 * the expense of. If we're preemptible, the value can be stale at use anyway. 49 * And we can't use this_cpu_ptr() either, as that winds up recursing back 50 * here under CONFIG_DEBUG_PREEMPT=y. 51 */ 52 #define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number)) 53 54 struct seq_file; 55 56 /* 57 * generate IPI list text 58 */ 59 extern void show_ipi_list(struct seq_file *p, int prec); 60 61 /* 62 * Called from C code, this handles an IPI. 63 */ 64 extern void handle_IPI(int ipinr, struct pt_regs *regs); 65 66 /* 67 * Discover the set of possible CPUs and determine their 68 * SMP operations. 69 */ 70 extern void smp_init_cpus(void); 71 72 /* 73 * Provide a function to raise an IPI cross call on CPUs in callmap. 74 */ 75 extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int)); 76 77 extern void (*__smp_cross_call)(const struct cpumask *, unsigned int); 78 79 /* 80 * Called from the secondary holding pen, this is the secondary CPU entry point. 81 */ 82 asmlinkage void secondary_start_kernel(void); 83 84 /* 85 * Initial data for bringing up a secondary CPU. 86 * @stack - sp for the secondary CPU 87 * @status - Result passed back from the secondary CPU to 88 * indicate failure. 89 */ 90 struct secondary_data { 91 void *stack; 92 struct task_struct *task; 93 long status; 94 }; 95 96 extern struct secondary_data secondary_data; 97 extern long __early_cpu_boot_status; 98 extern void secondary_entry(void); 99 100 extern void arch_send_call_function_single_ipi(int cpu); 101 extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); 102 103 #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL 104 extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask); 105 #else 106 static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask) 107 { 108 BUILD_BUG(); 109 } 110 #endif 111 112 extern int __cpu_disable(void); 113 114 extern void __cpu_die(unsigned int cpu); 115 extern void cpu_die(void); 116 extern void cpu_die_early(void); 117 118 static inline void cpu_park_loop(void) 119 { 120 for (;;) { 121 wfe(); 122 wfi(); 123 } 124 } 125 126 static inline void update_cpu_boot_status(int val) 127 { 128 WRITE_ONCE(secondary_data.status, val); 129 /* Ensure the visibility of the status update */ 130 dsb(ishst); 131 } 132 133 /* 134 * The calling secondary CPU has detected serious configuration mismatch, 135 * which calls for a kernel panic. Update the boot status and park the calling 136 * CPU. 137 */ 138 static inline void cpu_panic_kernel(void) 139 { 140 update_cpu_boot_status(CPU_PANIC_KERNEL); 141 cpu_park_loop(); 142 } 143 144 /* 145 * If a secondary CPU enters the kernel but fails to come online, 146 * (e.g. due to mismatched features), and cannot exit the kernel, 147 * we increment cpus_stuck_in_kernel and leave the CPU in a 148 * quiesecent loop within the kernel text. The memory containing 149 * this loop must not be re-used for anything else as the 'stuck' 150 * core is executing it. 151 * 152 * This function is used to inhibit features like kexec and hibernate. 153 */ 154 bool cpus_are_stuck_in_kernel(void); 155 156 extern void crash_smp_send_stop(void); 157 extern bool smp_crash_stop_failed(void); 158 159 #endif /* ifndef __ASSEMBLY__ */ 160 161 #endif /* ifndef __ASM_SMP_H */ 162