blob: df1f7c4cd4337be6fff336642d152eb0e6261f09 [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 Regents of the University of California
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5
6#ifndef _ASM_RISCV_SMP_H
7#define _ASM_RISCV_SMP_H
8
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009#include <linux/cpumask.h>
10#include <linux/irqreturn.h>
David Brazdil0f672f62019-12-10 10:32:29 +000011#include <linux/thread_info.h>
12
13#define INVALID_HARTID ULONG_MAX
14
15struct seq_file;
16extern unsigned long boot_cpu_hartid;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017
Olivier Deprez157378f2022-04-04 15:47:50 +020018struct riscv_ipi_ops {
19 void (*ipi_inject)(const struct cpumask *target);
20 void (*ipi_clear)(void);
21};
22
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000023#ifdef CONFIG_SMP
David Brazdil0f672f62019-12-10 10:32:29 +000024/*
25 * Mapping between linux logical cpu index and hartid.
26 */
27extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
28#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu]
29
30/* print IPI stats */
31void show_ipi_stats(struct seq_file *p, int prec);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000032
33/* SMP initialization hook for setup_arch */
34void __init setup_smp(void);
35
Olivier Deprez157378f2022-04-04 15:47:50 +020036/* Called from C code, this handles an IPI. */
37void handle_IPI(struct pt_regs *regs);
38
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039/* Hook for the generic smp_call_function_many() routine. */
40void arch_send_call_function_ipi_mask(struct cpumask *mask);
41
42/* Hook for the generic smp_call_function_single() routine. */
43void arch_send_call_function_single_ipi(int cpu);
44
David Brazdil0f672f62019-12-10 10:32:29 +000045int riscv_hartid_to_cpuid(int hartid);
46void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
47
Olivier Deprez157378f2022-04-04 15:47:50 +020048/* Set custom IPI operations */
49void riscv_set_ipi_ops(struct riscv_ipi_ops *ops);
50
51/* Clear IPI for current CPU */
52void riscv_clear_ipi(void);
53
54/* Secondary hart entry */
55asmlinkage void smp_callin(void);
56
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000057/*
David Brazdil0f672f62019-12-10 10:32:29 +000058 * Obtains the hart ID of the currently executing task. This relies on
59 * THREAD_INFO_IN_TASK, but we define that unconditionally.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000060 */
David Brazdil0f672f62019-12-10 10:32:29 +000061#define raw_smp_processor_id() (current_thread_info()->cpu)
62
Olivier Deprez157378f2022-04-04 15:47:50 +020063#if defined CONFIG_HOTPLUG_CPU
64int __cpu_disable(void);
65void __cpu_die(unsigned int cpu);
66void cpu_stop(void);
67#else
68#endif /* CONFIG_HOTPLUG_CPU */
69
David Brazdil0f672f62019-12-10 10:32:29 +000070#else
71
72static inline void show_ipi_stats(struct seq_file *p, int prec)
73{
74}
75
76static inline int riscv_hartid_to_cpuid(int hartid)
77{
78 if (hartid == boot_cpu_hartid)
79 return 0;
80
81 return -1;
82}
83static inline unsigned long cpuid_to_hartid_map(int cpu)
84{
85 return boot_cpu_hartid;
86}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000087
Olivier Deprez157378f2022-04-04 15:47:50 +020088static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
89 struct cpumask *out)
90{
91 cpumask_clear(out);
92 cpumask_set_cpu(boot_cpu_hartid, out);
93}
94
95static inline void riscv_set_ipi_ops(struct riscv_ipi_ops *ops)
96{
97}
98
99static inline void riscv_clear_ipi(void)
100{
101}
102
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000103#endif /* CONFIG_SMP */
Olivier Deprez157378f2022-04-04 15:47:50 +0200104
105#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
106bool cpu_has_hotplug(unsigned int cpu);
107#else
108static inline bool cpu_has_hotplug(unsigned int cpu)
109{
110 return false;
111}
112#endif
113
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000114#endif /* _ASM_RISCV_SMP_H */