xref: /openbmc/linux/arch/arm64/include/asm/smp.h (revision b3091f17)
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 
8 #include <linux/const.h>
9 
10 /* Values for secondary_data.status */
11 #define CPU_STUCK_REASON_SHIFT		(8)
12 #define CPU_BOOT_STATUS_MASK		((UL(1) << CPU_STUCK_REASON_SHIFT) - 1)
13 
14 #define CPU_MMU_OFF			(-1)
15 #define CPU_BOOT_SUCCESS		(0)
16 /* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */
17 #define CPU_KILL_ME			(1)
18 /* The cpu couldn't die gracefully and is looping in the kernel */
19 #define CPU_STUCK_IN_KERNEL		(2)
20 /* Fatal system error detected by secondary CPU, crash the system */
21 #define CPU_PANIC_KERNEL		(3)
22 
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)
25 
26 #ifndef __ASSEMBLY__
27 
28 #include <asm/percpu.h>
29 
30 #include <linux/threads.h>
31 #include <linux/cpumask.h>
32 #include <linux/thread_info.h>
33 
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.
40  * And we can't use this_cpu_ptr() either, as that winds up recursing back
41  * here under CONFIG_DEBUG_PREEMPT=y.
42  */
43 #define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number))
44 
45 /*
46  * Logical CPU mapping.
47  */
48 extern u64 __cpu_logical_map[NR_CPUS];
49 extern u64 cpu_logical_map(unsigned int cpu);
50 
set_cpu_logical_map(unsigned int cpu,u64 hwid)51 static inline void set_cpu_logical_map(unsigned int cpu, u64 hwid)
52 {
53 	__cpu_logical_map[cpu] = hwid;
54 }
55 
56 struct seq_file;
57 
58 /*
59  * Discover the set of possible CPUs and determine their
60  * SMP operations.
61  */
62 extern void smp_init_cpus(void);
63 
64 /*
65  * Register IPI interrupts with the arch SMP code
66  */
67 extern void set_smp_ipi_range(int ipi_base, int nr_ipi);
68 
69 /*
70  * Called from the secondary holding pen, this is the secondary CPU entry point.
71  */
72 asmlinkage void secondary_start_kernel(void);
73 
74 /*
75  * Initial data for bringing up a secondary CPU.
76  * @status - Result passed back from the secondary CPU to
77  *           indicate failure.
78  */
79 struct secondary_data {
80 	struct task_struct *task;
81 	long status;
82 };
83 
84 extern struct secondary_data secondary_data;
85 extern long __early_cpu_boot_status;
86 extern void secondary_entry(void);
87 
88 extern void arch_send_call_function_single_ipi(int cpu);
89 extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
90 
91 #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
92 extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask);
93 #else
arch_send_wakeup_ipi_mask(const struct cpumask * mask)94 static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
95 {
96 	BUILD_BUG();
97 }
98 #endif
99 
100 extern int __cpu_disable(void);
101 
__cpu_die(unsigned int cpu)102 static inline void __cpu_die(unsigned int cpu) { }
103 extern void __noreturn cpu_die(void);
104 extern void __noreturn cpu_die_early(void);
105 
cpu_park_loop(void)106 static inline void __noreturn cpu_park_loop(void)
107 {
108 	for (;;) {
109 		wfe();
110 		wfi();
111 	}
112 }
113 
update_cpu_boot_status(int val)114 static inline void update_cpu_boot_status(int val)
115 {
116 	WRITE_ONCE(secondary_data.status, val);
117 	/* Ensure the visibility of the status update */
118 	dsb(ishst);
119 }
120 
121 /*
122  * The calling secondary CPU has detected serious configuration mismatch,
123  * which calls for a kernel panic. Update the boot status and park the calling
124  * CPU.
125  */
cpu_panic_kernel(void)126 static inline void __noreturn cpu_panic_kernel(void)
127 {
128 	update_cpu_boot_status(CPU_PANIC_KERNEL);
129 	cpu_park_loop();
130 }
131 
132 /*
133  * If a secondary CPU enters the kernel but fails to come online,
134  * (e.g. due to mismatched features), and cannot exit the kernel,
135  * we increment cpus_stuck_in_kernel and leave the CPU in a
136  * quiesecent loop within the kernel text. The memory containing
137  * this loop must not be re-used for anything else as the 'stuck'
138  * core is executing it.
139  *
140  * This function is used to inhibit features like kexec and hibernate.
141  */
142 bool cpus_are_stuck_in_kernel(void);
143 
144 extern void crash_smp_send_stop(void);
145 extern bool smp_crash_stop_failed(void);
146 
147 #endif /* ifndef __ASSEMBLY__ */
148 
149 #endif /* ifndef __ASM_SMP_H */
150