hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/powerpc/include/asm/dbell.h
....@@ -1,10 +1,6 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Copyright 2009 Freescale Semiconductor, Inc.
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; either version
7
- * 2 of the License, or (at your option) any later version.
84 *
95 * provides masks and opcode images for use by code generation, emulation
106 * and for instructions that older assemblers might not know about
....@@ -15,8 +11,10 @@
1511 #include <linux/smp.h>
1612 #include <linux/threads.h>
1713
14
+#include <asm/cputhreads.h>
1815 #include <asm/ppc-opcode.h>
1916 #include <asm/feature-fixups.h>
17
+#include <asm/kvm_ppc.h>
2018
2119 #define PPC_DBELL_MSG_BRDCAST (0x04000000)
2220 #define PPC_DBELL_TYPE(x) (((x) & 0xf) << (63-36))
....@@ -91,9 +89,6 @@
9189
9290 #endif /* CONFIG_PPC_BOOK3S */
9391
94
-extern void doorbell_global_ipi(int cpu);
95
-extern void doorbell_core_ipi(int cpu);
96
-extern int doorbell_try_core_ipi(int cpu);
9792 extern void doorbell_exception(struct pt_regs *regs);
9893
9994 static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag)
....@@ -104,4 +99,63 @@
10499 _ppc_msgsnd(msg);
105100 }
106101
102
+#ifdef CONFIG_SMP
103
+
104
+/*
105
+ * Doorbells must only be used if CPU_FTR_DBELL is available.
106
+ * msgsnd is used in HV, and msgsndp is used in !HV.
107
+ *
108
+ * These should be used by platform code that is aware of restrictions.
109
+ * Other arch code should use ->cause_ipi.
110
+ *
111
+ * doorbell_global_ipi() sends a dbell to any target CPU.
112
+ * Must be used only by architectures that address msgsnd target
113
+ * by PIR/get_hard_smp_processor_id.
114
+ */
115
+static inline void doorbell_global_ipi(int cpu)
116
+{
117
+ u32 tag = get_hard_smp_processor_id(cpu);
118
+
119
+ kvmppc_set_host_ipi(cpu);
120
+ /* Order previous accesses vs. msgsnd, which is treated as a store */
121
+ ppc_msgsnd_sync();
122
+ ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag);
123
+}
124
+
125
+/*
126
+ * doorbell_core_ipi() sends a dbell to a target CPU in the same core.
127
+ * Must be used only by architectures that address msgsnd target
128
+ * by TIR/cpu_thread_in_core.
129
+ */
130
+static inline void doorbell_core_ipi(int cpu)
131
+{
132
+ u32 tag = cpu_thread_in_core(cpu);
133
+
134
+ kvmppc_set_host_ipi(cpu);
135
+ /* Order previous accesses vs. msgsnd, which is treated as a store */
136
+ ppc_msgsnd_sync();
137
+ ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag);
138
+}
139
+
140
+/*
141
+ * Attempt to cause a core doorbell if destination is on the same core.
142
+ * Returns 1 on success, 0 on failure.
143
+ */
144
+static inline int doorbell_try_core_ipi(int cpu)
145
+{
146
+ int this_cpu = get_cpu();
147
+ int ret = 0;
148
+
149
+ if (cpumask_test_cpu(cpu, cpu_sibling_mask(this_cpu))) {
150
+ doorbell_core_ipi(cpu);
151
+ ret = 1;
152
+ }
153
+
154
+ put_cpu();
155
+
156
+ return ret;
157
+}
158
+
159
+#endif /* CONFIG_SMP */
160
+
107161 #endif /* _ASM_POWERPC_DBELL_H */