blob: 3e9da22a2779628c893bef349a0c77f60787c383 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Kumar Gala620165f2009-02-12 13:54:53 +00002/*
Yang Li8a56e1e2012-11-01 18:53:42 +00003 * Copyright 2009 Freescale Semiconductor, Inc.
Kumar Gala620165f2009-02-12 13:54:53 +00004 *
Kumar Gala620165f2009-02-12 13:54:53 +00005 * provides masks and opcode images for use by code generation, emulation
6 * and for instructions that older assemblers might not know about
7 */
8#ifndef _ASM_POWERPC_DBELL_H
9#define _ASM_POWERPC_DBELL_H
10
11#include <linux/smp.h>
12#include <linux/threads.h>
13
Nicholas Piggin1f0ce492020-07-26 13:51:53 +100014#include <asm/cputhreads.h>
Kumar Gala620165f2009-02-12 13:54:53 +000015#include <asm/ppc-opcode.h>
Christophe Leroy2c86cd12018-07-05 16:25:01 +000016#include <asm/feature-fixups.h>
Nicholas Piggin1f0ce492020-07-26 13:51:53 +100017#include <asm/kvm_ppc.h>
Kumar Gala620165f2009-02-12 13:54:53 +000018
19#define PPC_DBELL_MSG_BRDCAST (0x04000000)
Michael Neulingdc285182011-06-05 16:48:47 +000020#define PPC_DBELL_TYPE(x) (((x) & 0xf) << (63-36))
Alexander Graf4ab96912012-02-15 13:28:48 +000021#define PPC_DBELL_TYPE_MASK PPC_DBELL_TYPE(0xf)
Scott Woodd30f6e42011-12-20 15:34:43 +000022#define PPC_DBELL_LPID(x) ((x) << (63 - 49))
Alexander Graf4ab96912012-02-15 13:28:48 +000023#define PPC_DBELL_PIR_MASK 0x3fff
Kumar Gala620165f2009-02-12 13:54:53 +000024enum ppc_dbell {
25 PPC_DBELL = 0, /* doorbell */
26 PPC_DBELL_CRIT = 1, /* critical doorbell */
27 PPC_G_DBELL = 2, /* guest doorbell */
28 PPC_G_DBELL_CRIT = 3, /* guest critical doorbell */
29 PPC_G_DBELL_MC = 4, /* guest mcheck doorbell */
Ian Munsie42d02b82012-11-14 18:49:44 +000030 PPC_DBELL_SERVER = 5, /* doorbell on server */
Kumar Gala620165f2009-02-12 13:54:53 +000031};
32
Ian Munsie42d02b82012-11-14 18:49:44 +000033#ifdef CONFIG_PPC_BOOK3S
34
35#define PPC_DBELL_MSGTYPE PPC_DBELL_SERVER
Ian Munsie42d02b82012-11-14 18:49:44 +000036
Ian Munsie919ca862012-11-14 18:49:47 +000037static inline void _ppc_msgsnd(u32 msg)
38{
Nicholas Piggina5adf282017-04-13 20:16:23 +100039 __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGSND(%1), PPC_MSGSNDP(%1), %0)
40 : : "i" (CPU_FTR_HVMODE), "r" (msg));
Ian Munsie919ca862012-11-14 18:49:47 +000041}
42
Nicholas Pigginb87ac022017-04-13 20:16:22 +100043/* sync before sending message */
44static inline void ppc_msgsnd_sync(void)
45{
46 __asm__ __volatile__ ("sync" : : : "memory");
47}
48
49/* sync after taking message interrupt */
50static inline void ppc_msgsync(void)
51{
Nicholas Piggin6b3edef2017-04-13 20:16:24 +100052 /* sync is not required when taking messages from the same core */
53 __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGSYNC " ; lwsync", "", %0)
54 : : "i" (CPU_FTR_HVMODE|CPU_FTR_ARCH_300));
Nicholas Pigginb87ac022017-04-13 20:16:22 +100055}
56
Nicholas Piggina9af97a2017-06-13 23:05:48 +100057static inline void _ppc_msgclr(u32 msg)
58{
59 __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGCLR(%1), PPC_MSGCLRP(%1), %0)
60 : : "i" (CPU_FTR_HVMODE), "r" (msg));
61}
62
63static inline void ppc_msgclr(enum ppc_dbell type)
64{
65 u32 msg = PPC_DBELL_TYPE(type);
66
67 _ppc_msgclr(msg);
68}
69
Ian Munsie42d02b82012-11-14 18:49:44 +000070#else /* CONFIG_PPC_BOOK3S */
71
72#define PPC_DBELL_MSGTYPE PPC_DBELL
Ian Munsie42d02b82012-11-14 18:49:44 +000073
Ian Munsie919ca862012-11-14 18:49:47 +000074static inline void _ppc_msgsnd(u32 msg)
75{
76 __asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
77}
78
Nicholas Pigginb87ac022017-04-13 20:16:22 +100079/* sync before sending message */
80static inline void ppc_msgsnd_sync(void)
81{
82 __asm__ __volatile__ ("sync" : : : "memory");
83}
84
85/* sync after taking message interrupt */
86static inline void ppc_msgsync(void)
87{
88}
89
Ian Munsie42d02b82012-11-14 18:49:44 +000090#endif /* CONFIG_PPC_BOOK3S */
91
Benjamin Herrenschmidtb9f1cd72010-07-09 15:29:53 +100092extern void doorbell_exception(struct pt_regs *regs);
Kumar Gala620165f2009-02-12 13:54:53 +000093
94static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag)
95{
96 u32 msg = PPC_DBELL_TYPE(type) | (flags & PPC_DBELL_MSG_BRDCAST) |
97 (tag & 0x07ffffff);
98
Ian Munsie919ca862012-11-14 18:49:47 +000099 _ppc_msgsnd(msg);
Kumar Gala620165f2009-02-12 13:54:53 +0000100}
101
Nicholas Piggin1f0ce492020-07-26 13:51:53 +1000102#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 */
115static 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 */
130static 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 */
144static 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
Kumar Gala620165f2009-02-12 13:54:53 +0000161#endif /* _ASM_POWERPC_DBELL_H */