blob: 0eadbf933e3592353d6337db9d85aca681d2c4c5 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2012 ARM Ltd.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5#ifndef __ASM_SMP_H
6#define __ASM_SMP_H
7
David Brazdil0f672f62019-12-10 10:32:29 +00008#include <linux/const.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009
David Brazdil0f672f62019-12-10 10:32:29 +000010/* 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)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000016/* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */
David Brazdil0f672f62019-12-10 10:32:29 +000017#define CPU_KILL_ME (1)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000018/* The cpu couldn't die gracefully and is looping in the kernel */
David Brazdil0f672f62019-12-10 10:32:29 +000019#define CPU_STUCK_IN_KERNEL (2)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020/* Fatal system error detected by secondary CPU, crash the system */
David Brazdil0f672f62019-12-10 10:32:29 +000021#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)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025
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
34DECLARE_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
David Brazdil0f672f62019-12-10 10:32:29 +000045/*
46 * Logical CPU mapping.
47 */
48extern u64 __cpu_logical_map[NR_CPUS];
Olivier Deprez0e641232021-09-23 10:07:05 +020049extern u64 cpu_logical_map(int cpu);
50
51static inline void set_cpu_logical_map(int cpu, u64 hwid)
52{
53 __cpu_logical_map[cpu] = hwid;
54}
David Brazdil0f672f62019-12-10 10:32:29 +000055
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000056struct seq_file;
57
58/*
59 * generate IPI list text
60 */
61extern void show_ipi_list(struct seq_file *p, int prec);
62
63/*
64 * Called from C code, this handles an IPI.
65 */
66extern void handle_IPI(int ipinr, struct pt_regs *regs);
67
68/*
69 * Discover the set of possible CPUs and determine their
70 * SMP operations.
71 */
72extern void smp_init_cpus(void);
73
74/*
75 * Provide a function to raise an IPI cross call on CPUs in callmap.
76 */
77extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
78
79extern void (*__smp_cross_call)(const struct cpumask *, unsigned int);
80
81/*
82 * Called from the secondary holding pen, this is the secondary CPU entry point.
83 */
84asmlinkage void secondary_start_kernel(void);
85
86/*
87 * Initial data for bringing up a secondary CPU.
88 * @stack - sp for the secondary CPU
89 * @status - Result passed back from the secondary CPU to
90 * indicate failure.
91 */
92struct secondary_data {
93 void *stack;
94 struct task_struct *task;
95 long status;
96};
97
98extern struct secondary_data secondary_data;
99extern long __early_cpu_boot_status;
100extern void secondary_entry(void);
101
102extern void arch_send_call_function_single_ipi(int cpu);
103extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
104
105#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
106extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask);
107#else
108static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
109{
110 BUILD_BUG();
111}
112#endif
113
114extern int __cpu_disable(void);
115
116extern void __cpu_die(unsigned int cpu);
117extern void cpu_die(void);
118extern void cpu_die_early(void);
119
120static inline void cpu_park_loop(void)
121{
122 for (;;) {
123 wfe();
124 wfi();
125 }
126}
127
128static inline void update_cpu_boot_status(int val)
129{
130 WRITE_ONCE(secondary_data.status, val);
131 /* Ensure the visibility of the status update */
132 dsb(ishst);
133}
134
135/*
136 * The calling secondary CPU has detected serious configuration mismatch,
137 * which calls for a kernel panic. Update the boot status and park the calling
138 * CPU.
139 */
140static inline void cpu_panic_kernel(void)
141{
142 update_cpu_boot_status(CPU_PANIC_KERNEL);
143 cpu_park_loop();
144}
145
146/*
147 * If a secondary CPU enters the kernel but fails to come online,
148 * (e.g. due to mismatched features), and cannot exit the kernel,
149 * we increment cpus_stuck_in_kernel and leave the CPU in a
150 * quiesecent loop within the kernel text. The memory containing
151 * this loop must not be re-used for anything else as the 'stuck'
152 * core is executing it.
153 *
154 * This function is used to inhibit features like kexec and hibernate.
155 */
156bool cpus_are_stuck_in_kernel(void);
157
158extern void crash_smp_send_stop(void);
159extern bool smp_crash_stop_failed(void);
160
161#endif /* ifndef __ASSEMBLY__ */
162
163#endif /* ifndef __ASM_SMP_H */