hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/arch/riscv/include/asm/smp.h
....@@ -1,31 +1,40 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2012 Regents of the University of California
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation, version 2.
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.
124 */
135
146 #ifndef _ASM_RISCV_SMP_H
157 #define _ASM_RISCV_SMP_H
168
17
-/* This both needs asm-offsets.h and is used when generating it. */
18
-#ifndef GENERATING_ASM_OFFSETS
19
-#include <asm/asm-offsets.h>
20
-#endif
21
-
229 #include <linux/cpumask.h>
2310 #include <linux/irqreturn.h>
11
+#include <linux/thread_info.h>
12
+
13
+#define INVALID_HARTID ULONG_MAX
14
+
15
+struct seq_file;
16
+extern unsigned long boot_cpu_hartid;
17
+
18
+struct riscv_ipi_ops {
19
+ void (*ipi_inject)(const struct cpumask *target);
20
+ void (*ipi_clear)(void);
21
+};
2422
2523 #ifdef CONFIG_SMP
24
+/*
25
+ * Mapping between linux logical cpu index and hartid.
26
+ */
27
+extern 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 */
31
+void show_ipi_stats(struct seq_file *p, int prec);
2632
2733 /* SMP initialization hook for setup_arch */
2834 void __init setup_smp(void);
35
+
36
+/* Called from C code, this handles an IPI. */
37
+void handle_IPI(struct pt_regs *regs);
2938
3039 /* Hook for the generic smp_call_function_many() routine. */
3140 void arch_send_call_function_ipi_mask(struct cpumask *mask);
....@@ -33,14 +42,73 @@
3342 /* Hook for the generic smp_call_function_single() routine. */
3443 void arch_send_call_function_single_ipi(int cpu);
3544
45
+int riscv_hartid_to_cpuid(int hartid);
46
+void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
47
+
48
+/* Set custom IPI operations */
49
+void riscv_set_ipi_ops(struct riscv_ipi_ops *ops);
50
+
51
+/* Clear IPI for current CPU */
52
+void riscv_clear_ipi(void);
53
+
54
+/* Secondary hart entry */
55
+asmlinkage void smp_callin(void);
56
+
3657 /*
37
- * This is particularly ugly: it appears we can't actually get the definition
38
- * of task_struct here, but we need access to the CPU this task is running on.
39
- * Instead of using C we're using asm-offsets.h to get the current processor
40
- * ID.
58
+ * Obtains the hart ID of the currently executing task. This relies on
59
+ * THREAD_INFO_IN_TASK, but we define that unconditionally.
4160 */
42
-#define raw_smp_processor_id() (*((int*)((char*)get_current() + TASK_TI_CPU)))
61
+#define raw_smp_processor_id() (current_thread_info()->cpu)
62
+
63
+#if defined CONFIG_HOTPLUG_CPU
64
+int __cpu_disable(void);
65
+void __cpu_die(unsigned int cpu);
66
+void cpu_stop(void);
67
+#else
68
+#endif /* CONFIG_HOTPLUG_CPU */
69
+
70
+#else
71
+
72
+static inline void show_ipi_stats(struct seq_file *p, int prec)
73
+{
74
+}
75
+
76
+static inline int riscv_hartid_to_cpuid(int hartid)
77
+{
78
+ if (hartid == boot_cpu_hartid)
79
+ return 0;
80
+
81
+ return -1;
82
+}
83
+static inline unsigned long cpuid_to_hartid_map(int cpu)
84
+{
85
+ return boot_cpu_hartid;
86
+}
87
+
88
+static 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
+
95
+static inline void riscv_set_ipi_ops(struct riscv_ipi_ops *ops)
96
+{
97
+}
98
+
99
+static inline void riscv_clear_ipi(void)
100
+{
101
+}
43102
44103 #endif /* CONFIG_SMP */
45104
105
+#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
106
+bool cpu_has_hotplug(unsigned int cpu);
107
+#else
108
+static inline bool cpu_has_hotplug(unsigned int cpu)
109
+{
110
+ return false;
111
+}
112
+#endif
113
+
46114 #endif /* _ASM_RISCV_SMP_H */