OSDN Git Service

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