Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 ARM Ltd. |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __ASM_SMP_H |
| 6 | #define __ASM_SMP_H |
| 7 | |
Shaokun Zhang | 1236cd2 | 2018-12-29 09:43:17 +0800 | [diff] [blame] | 8 | #include <linux/const.h> |
| 9 | |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 10 | /* Values for secondary_data.status */ |
Will Deacon | 66f16a2 | 2018-12-10 14:21:13 +0000 | [diff] [blame] | 11 | #define CPU_STUCK_REASON_SHIFT (8) |
Shaokun Zhang | 1236cd2 | 2018-12-29 09:43:17 +0800 | [diff] [blame] | 12 | #define CPU_BOOT_STATUS_MASK ((UL(1) << CPU_STUCK_REASON_SHIFT) - 1) |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 13 | |
Will Deacon | 66f16a2 | 2018-12-10 14:21:13 +0000 | [diff] [blame] | 14 | #define CPU_MMU_OFF (-1) |
| 15 | #define CPU_BOOT_SUCCESS (0) |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 16 | /* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */ |
Will Deacon | 66f16a2 | 2018-12-10 14:21:13 +0000 | [diff] [blame] | 17 | #define CPU_KILL_ME (1) |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 18 | /* The cpu couldn't die gracefully and is looping in the kernel */ |
Will Deacon | 66f16a2 | 2018-12-10 14:21:13 +0000 | [diff] [blame] | 19 | #define CPU_STUCK_IN_KERNEL (2) |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 20 | /* Fatal system error detected by secondary CPU, crash the system */ |
Will Deacon | 66f16a2 | 2018-12-10 14:21:13 +0000 | [diff] [blame] | 21 | #define CPU_PANIC_KERNEL (3) |
| 22 | |
Shaokun Zhang | 1236cd2 | 2018-12-29 09:43:17 +0800 | [diff] [blame] | 23 | #define CPU_STUCK_REASON_52_BIT_VA (UL(1) << CPU_STUCK_REASON_SHIFT) |
| 24 | #define CPU_STUCK_REASON_NO_GRAN (UL(2) << CPU_STUCK_REASON_SHIFT) |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 25 | |
| 26 | #ifndef __ASSEMBLY__ |
| 27 | |
Mark Rutland | 57c8295 | 2016-11-03 20:23:11 +0000 | [diff] [blame] | 28 | #include <asm/percpu.h> |
| 29 | |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 30 | #include <linux/threads.h> |
| 31 | #include <linux/cpumask.h> |
| 32 | #include <linux/thread_info.h> |
| 33 | |
Mark Rutland | 57c8295 | 2016-11-03 20:23:11 +0000 | [diff] [blame] | 34 | DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number); |
| 35 | |
| 36 | /* |
| 37 | * We don't use this_cpu_read(cpu_number) as that has implicit writes to |
| 38 | * preempt_count, and associated (compiler) barriers, that we'd like to avoid |
| 39 | * the expense of. If we're preemptible, the value can be stale at use anyway. |
Robin Murphy | 34a6980 | 2016-12-01 15:55:13 +0000 | [diff] [blame] | 40 | * And we can't use this_cpu_ptr() either, as that winds up recursing back |
| 41 | * here under CONFIG_DEBUG_PREEMPT=y. |
Mark Rutland | 57c8295 | 2016-11-03 20:23:11 +0000 | [diff] [blame] | 42 | */ |
Robin Murphy | 34a6980 | 2016-12-01 15:55:13 +0000 | [diff] [blame] | 43 | #define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number)) |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 44 | |
Florian Fainelli | 262afe92f | 2019-06-03 16:18:29 -0700 | [diff] [blame] | 45 | /* |
| 46 | * Logical CPU mapping. |
| 47 | */ |
| 48 | extern u64 __cpu_logical_map[NR_CPUS]; |
| 49 | #define cpu_logical_map(cpu) __cpu_logical_map[cpu] |
| 50 | |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 51 | struct seq_file; |
| 52 | |
| 53 | /* |
| 54 | * generate IPI list text |
| 55 | */ |
| 56 | extern void show_ipi_list(struct seq_file *p, int prec); |
| 57 | |
| 58 | /* |
| 59 | * Called from C code, this handles an IPI. |
| 60 | */ |
| 61 | extern void handle_IPI(int ipinr, struct pt_regs *regs); |
| 62 | |
| 63 | /* |
Hanjun Guo | fccb9a8 | 2015-03-24 22:02:45 +0800 | [diff] [blame] | 64 | * Discover the set of possible CPUs and determine their |
| 65 | * SMP operations. |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 66 | */ |
Lorenzo Pieralisi | 0f07833 | 2015-05-13 14:12:47 +0100 | [diff] [blame] | 67 | extern void smp_init_cpus(void); |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Provide a function to raise an IPI cross call on CPUs in callmap. |
| 71 | */ |
| 72 | extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int)); |
| 73 | |
Frederic Weisbecker | 3631073 | 2014-08-16 18:48:05 +0200 | [diff] [blame] | 74 | extern void (*__smp_cross_call)(const struct cpumask *, unsigned int); |
| 75 | |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 76 | /* |
| 77 | * Called from the secondary holding pen, this is the secondary CPU entry point. |
| 78 | */ |
| 79 | asmlinkage void secondary_start_kernel(void); |
| 80 | |
| 81 | /* |
| 82 | * Initial data for bringing up a secondary CPU. |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 83 | * @stack - sp for the secondary CPU |
| 84 | * @status - Result passed back from the secondary CPU to |
| 85 | * indicate failure. |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 86 | */ |
| 87 | struct secondary_data { |
| 88 | void *stack; |
Mark Rutland | c02433d | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 89 | struct task_struct *task; |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 90 | long status; |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 91 | }; |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 92 | |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 93 | extern struct secondary_data secondary_data; |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 94 | extern long __early_cpu_boot_status; |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 95 | extern void secondary_entry(void); |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 96 | |
| 97 | extern void arch_send_call_function_single_ipi(int cpu); |
| 98 | extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); |
| 99 | |
Lorenzo Pieralisi | 5e89c55 | 2016-01-26 11:10:38 +0000 | [diff] [blame] | 100 | #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL |
| 101 | extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask); |
| 102 | #else |
| 103 | static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask) |
| 104 | { |
| 105 | BUILD_BUG(); |
| 106 | } |
| 107 | #endif |
| 108 | |
Mark Rutland | 9327e2c | 2013-10-24 20:30:18 +0100 | [diff] [blame] | 109 | extern int __cpu_disable(void); |
| 110 | |
| 111 | extern void __cpu_die(unsigned int cpu); |
| 112 | extern void cpu_die(void); |
Suzuki K Poulose | fce6361 | 2016-02-23 10:31:41 +0000 | [diff] [blame] | 113 | extern void cpu_die_early(void); |
Mark Rutland | 9327e2c | 2013-10-24 20:30:18 +0100 | [diff] [blame] | 114 | |
Suzuki K Poulose | c4bc34d | 2016-02-23 10:31:39 +0000 | [diff] [blame] | 115 | static inline void cpu_park_loop(void) |
| 116 | { |
| 117 | for (;;) { |
| 118 | wfe(); |
| 119 | wfi(); |
| 120 | } |
| 121 | } |
| 122 | |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 123 | static inline void update_cpu_boot_status(int val) |
| 124 | { |
| 125 | WRITE_ONCE(secondary_data.status, val); |
| 126 | /* Ensure the visibility of the status update */ |
| 127 | dsb(ishst); |
| 128 | } |
| 129 | |
Suzuki K Poulose | 17eebd1 | 2016-04-12 15:46:00 +0100 | [diff] [blame] | 130 | /* |
| 131 | * The calling secondary CPU has detected serious configuration mismatch, |
| 132 | * which calls for a kernel panic. Update the boot status and park the calling |
| 133 | * CPU. |
| 134 | */ |
| 135 | static inline void cpu_panic_kernel(void) |
| 136 | { |
| 137 | update_cpu_boot_status(CPU_PANIC_KERNEL); |
| 138 | cpu_park_loop(); |
| 139 | } |
| 140 | |
James Morse | 5c492c3 | 2016-06-22 10:06:12 +0100 | [diff] [blame] | 141 | /* |
| 142 | * If a secondary CPU enters the kernel but fails to come online, |
| 143 | * (e.g. due to mismatched features), and cannot exit the kernel, |
| 144 | * we increment cpus_stuck_in_kernel and leave the CPU in a |
| 145 | * quiesecent loop within the kernel text. The memory containing |
| 146 | * this loop must not be re-used for anything else as the 'stuck' |
| 147 | * core is executing it. |
| 148 | * |
| 149 | * This function is used to inhibit features like kexec and hibernate. |
| 150 | */ |
| 151 | bool cpus_are_stuck_in_kernel(void); |
| 152 | |
Hoeun Ryu | a88ce63 | 2017-08-17 11:24:27 +0900 | [diff] [blame] | 153 | extern void crash_smp_send_stop(void); |
AKASHI Takahiro | 78fd584 | 2017-04-03 11:24:36 +0900 | [diff] [blame] | 154 | extern bool smp_crash_stop_failed(void); |
| 155 | |
Suzuki K Poulose | bb90527 | 2016-02-23 10:31:42 +0000 | [diff] [blame] | 156 | #endif /* ifndef __ASSEMBLY__ */ |
| 157 | |
Catalin Marinas | 08e875c | 2012-03-05 11:49:30 +0000 | [diff] [blame] | 158 | #endif /* ifndef __ASM_SMP_H */ |