arm64: split thread_info from task stack
[platform/kernel/linux-starfive.git] / arch / arm64 / include / asm / smp.h
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
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
32 #include <asm/percpu.h>
33
34 #include <linux/threads.h>
35 #include <linux/cpumask.h>
36 #include <linux/thread_info.h>
37
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.
44  */
45 #define raw_smp_processor_id() (*this_cpu_ptr(&cpu_number))
46
47 struct seq_file;
48
49 /*
50  * generate IPI list text
51  */
52 extern void show_ipi_list(struct seq_file *p, int prec);
53
54 /*
55  * Called from C code, this handles an IPI.
56  */
57 extern void handle_IPI(int ipinr, struct pt_regs *regs);
58
59 /*
60  * Discover the set of possible CPUs and determine their
61  * SMP operations.
62  */
63 extern void smp_init_cpus(void);
64
65 /*
66  * Provide a function to raise an IPI cross call on CPUs in callmap.
67  */
68 extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
69
70 extern void (*__smp_cross_call)(const struct cpumask *, unsigned int);
71
72 /*
73  * Called from the secondary holding pen, this is the secondary CPU entry point.
74  */
75 asmlinkage void secondary_start_kernel(void);
76
77 /*
78  * Initial data for bringing up a secondary CPU.
79  * @stack  - sp for the secondary CPU
80  * @status - Result passed back from the secondary CPU to
81  *           indicate failure.
82  */
83 struct secondary_data {
84         void *stack;
85         struct task_struct *task;
86         long status;
87 };
88
89 extern struct secondary_data secondary_data;
90 extern long __early_cpu_boot_status;
91 extern void secondary_entry(void);
92
93 extern void arch_send_call_function_single_ipi(int cpu);
94 extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
95
96 #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
97 extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask);
98 #else
99 static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
100 {
101         BUILD_BUG();
102 }
103 #endif
104
105 extern int __cpu_disable(void);
106
107 extern void __cpu_die(unsigned int cpu);
108 extern void cpu_die(void);
109 extern void cpu_die_early(void);
110
111 static inline void cpu_park_loop(void)
112 {
113         for (;;) {
114                 wfe();
115                 wfi();
116         }
117 }
118
119 static inline void update_cpu_boot_status(int val)
120 {
121         WRITE_ONCE(secondary_data.status, val);
122         /* Ensure the visibility of the status update */
123         dsb(ishst);
124 }
125
126 /*
127  * The calling secondary CPU has detected serious configuration mismatch,
128  * which calls for a kernel panic. Update the boot status and park the calling
129  * CPU.
130  */
131 static inline void cpu_panic_kernel(void)
132 {
133         update_cpu_boot_status(CPU_PANIC_KERNEL);
134         cpu_park_loop();
135 }
136
137 /*
138  * If a secondary CPU enters the kernel but fails to come online,
139  * (e.g. due to mismatched features), and cannot exit the kernel,
140  * we increment cpus_stuck_in_kernel and leave the CPU in a
141  * quiesecent loop within the kernel text. The memory containing
142  * this loop must not be re-used for anything else as the 'stuck'
143  * core is executing it.
144  *
145  * This function is used to inhibit features like kexec and hibernate.
146  */
147 bool cpus_are_stuck_in_kernel(void);
148
149 #endif /* ifndef __ASSEMBLY__ */
150
151 #endif /* ifndef __ASM_SMP_H */