blob: a0c8a0b652593b66fb8e909627d92af15c0f2cde [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Catalin Marinas08e875c2012-03-05 11:49:30 +00002/*
3 * Copyright (C) 2012 ARM Ltd.
Catalin Marinas08e875c2012-03-05 11:49:30 +00004 */
5#ifndef __ASM_SMP_H
6#define __ASM_SMP_H
7
Shaokun Zhang1236cd22018-12-29 09:43:17 +08008#include <linux/const.h>
9
Suzuki K Poulosebb905272016-02-23 10:31:42 +000010/* Values for secondary_data.status */
Will Deacon66f16a22018-12-10 14:21:13 +000011#define CPU_STUCK_REASON_SHIFT (8)
Shaokun Zhang1236cd22018-12-29 09:43:17 +080012#define CPU_BOOT_STATUS_MASK ((UL(1) << CPU_STUCK_REASON_SHIFT) - 1)
Suzuki K Poulosebb905272016-02-23 10:31:42 +000013
Will Deacon66f16a22018-12-10 14:21:13 +000014#define CPU_MMU_OFF (-1)
15#define CPU_BOOT_SUCCESS (0)
Suzuki K Poulosebb905272016-02-23 10:31:42 +000016/* The cpu invoked ops->cpu_die, synchronise it with cpu_kill */
Will Deacon66f16a22018-12-10 14:21:13 +000017#define CPU_KILL_ME (1)
Suzuki K Poulosebb905272016-02-23 10:31:42 +000018/* The cpu couldn't die gracefully and is looping in the kernel */
Will Deacon66f16a22018-12-10 14:21:13 +000019#define CPU_STUCK_IN_KERNEL (2)
Suzuki K Poulosebb905272016-02-23 10:31:42 +000020/* Fatal system error detected by secondary CPU, crash the system */
Will Deacon66f16a22018-12-10 14:21:13 +000021#define CPU_PANIC_KERNEL (3)
22
Shaokun Zhang1236cd22018-12-29 09:43:17 +080023#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)
Suzuki K Poulosebb905272016-02-23 10:31:42 +000025
26#ifndef __ASSEMBLY__
27
Mark Rutland57c82952016-11-03 20:23:11 +000028#include <asm/percpu.h>
29
Catalin Marinas08e875c2012-03-05 11:49:30 +000030#include <linux/threads.h>
31#include <linux/cpumask.h>
32#include <linux/thread_info.h>
33
Mark Rutland57c82952016-11-03 20:23:11 +000034DECLARE_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.
Robin Murphy34a69802016-12-01 15:55:13 +000040 * And we can't use this_cpu_ptr() either, as that winds up recursing back
41 * here under CONFIG_DEBUG_PREEMPT=y.
Mark Rutland57c82952016-11-03 20:23:11 +000042 */
Robin Murphy34a69802016-12-01 15:55:13 +000043#define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number))
Catalin Marinas08e875c2012-03-05 11:49:30 +000044
Florian Fainelli262afe92f2019-06-03 16:18:29 -070045/*
46 * Logical CPU mapping.
47 */
48extern u64 __cpu_logical_map[NR_CPUS];
49#define cpu_logical_map(cpu) __cpu_logical_map[cpu]
50
Catalin Marinas08e875c2012-03-05 11:49:30 +000051struct seq_file;
52
53/*
54 * generate IPI list text
55 */
56extern void show_ipi_list(struct seq_file *p, int prec);
57
58/*
59 * Called from C code, this handles an IPI.
60 */
61extern void handle_IPI(int ipinr, struct pt_regs *regs);
62
63/*
Hanjun Guofccb9a82015-03-24 22:02:45 +080064 * Discover the set of possible CPUs and determine their
65 * SMP operations.
Catalin Marinas08e875c2012-03-05 11:49:30 +000066 */
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +010067extern void smp_init_cpus(void);
Catalin Marinas08e875c2012-03-05 11:49:30 +000068
69/*
70 * Provide a function to raise an IPI cross call on CPUs in callmap.
71 */
72extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
73
Frederic Weisbecker36310732014-08-16 18:48:05 +020074extern void (*__smp_cross_call)(const struct cpumask *, unsigned int);
75
Catalin Marinas08e875c2012-03-05 11:49:30 +000076/*
77 * Called from the secondary holding pen, this is the secondary CPU entry point.
78 */
79asmlinkage void secondary_start_kernel(void);
80
81/*
82 * Initial data for bringing up a secondary CPU.
Suzuki K Poulosebb905272016-02-23 10:31:42 +000083 * @stack - sp for the secondary CPU
84 * @status - Result passed back from the secondary CPU to
85 * indicate failure.
Catalin Marinas08e875c2012-03-05 11:49:30 +000086 */
87struct secondary_data {
88 void *stack;
Mark Rutlandc02433d2016-11-03 20:23:13 +000089 struct task_struct *task;
Suzuki K Poulosebb905272016-02-23 10:31:42 +000090 long status;
Catalin Marinas08e875c2012-03-05 11:49:30 +000091};
Suzuki K Poulosebb905272016-02-23 10:31:42 +000092
Catalin Marinas08e875c2012-03-05 11:49:30 +000093extern struct secondary_data secondary_data;
Suzuki K Poulosebb905272016-02-23 10:31:42 +000094extern long __early_cpu_boot_status;
Mark Rutland652af892013-10-24 20:30:16 +010095extern void secondary_entry(void);
Catalin Marinas08e875c2012-03-05 11:49:30 +000096
97extern void arch_send_call_function_single_ipi(int cpu);
98extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
99
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +0000100#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
101extern void arch_send_wakeup_ipi_mask(const struct cpumask *mask);
102#else
103static inline void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
104{
105 BUILD_BUG();
106}
107#endif
108
Mark Rutland9327e2c2013-10-24 20:30:18 +0100109extern int __cpu_disable(void);
110
111extern void __cpu_die(unsigned int cpu);
112extern void cpu_die(void);
Suzuki K Poulosefce63612016-02-23 10:31:41 +0000113extern void cpu_die_early(void);
Mark Rutland9327e2c2013-10-24 20:30:18 +0100114
Suzuki K Poulosec4bc34d2016-02-23 10:31:39 +0000115static inline void cpu_park_loop(void)
116{
117 for (;;) {
118 wfe();
119 wfi();
120 }
121}
122
Suzuki K Poulosebb905272016-02-23 10:31:42 +0000123static inline void update_cpu_boot_status(int val)
124{
125 WRITE_ONCE(secondary_data.status, val);
126 /* Ensure the visibility of the status update */
127 dsb(ishst);
128}
129
Suzuki K Poulose17eebd12016-04-12 15:46:00 +0100130/*
131 * The calling secondary CPU has detected serious configuration mismatch,
132 * which calls for a kernel panic. Update the boot status and park the calling
133 * CPU.
134 */
135static inline void cpu_panic_kernel(void)
136{
137 update_cpu_boot_status(CPU_PANIC_KERNEL);
138 cpu_park_loop();
139}
140
James Morse5c492c32016-06-22 10:06:12 +0100141/*
142 * If a secondary CPU enters the kernel but fails to come online,
143 * (e.g. due to mismatched features), and cannot exit the kernel,
144 * we increment cpus_stuck_in_kernel and leave the CPU in a
145 * quiesecent loop within the kernel text. The memory containing
146 * this loop must not be re-used for anything else as the 'stuck'
147 * core is executing it.
148 *
149 * This function is used to inhibit features like kexec and hibernate.
150 */
151bool cpus_are_stuck_in_kernel(void);
152
Hoeun Ryua88ce632017-08-17 11:24:27 +0900153extern void crash_smp_send_stop(void);
AKASHI Takahiro78fd5842017-04-03 11:24:36 +0900154extern bool smp_crash_stop_failed(void);
155
Suzuki K Poulosebb905272016-02-23 10:31:42 +0000156#endif /* ifndef __ASSEMBLY__ */
157
Catalin Marinas08e875c2012-03-05 11:49:30 +0000158#endif /* ifndef __ASM_SMP_H */