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