xref: /openbmc/linux/arch/powerpc/include/asm/dbell.h (revision b830f94f)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright 2009 Freescale Semiconductor, Inc.
4  *
5  * 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 
14 #include <asm/ppc-opcode.h>
15 #include <asm/feature-fixups.h>
16 
17 #define PPC_DBELL_MSG_BRDCAST	(0x04000000)
18 #define PPC_DBELL_TYPE(x)	(((x) & 0xf) << (63-36))
19 #define PPC_DBELL_TYPE_MASK	PPC_DBELL_TYPE(0xf)
20 #define PPC_DBELL_LPID(x)	((x) << (63 - 49))
21 #define PPC_DBELL_PIR_MASK	0x3fff
22 enum ppc_dbell {
23 	PPC_DBELL = 0,		/* doorbell */
24 	PPC_DBELL_CRIT = 1,	/* critical doorbell */
25 	PPC_G_DBELL = 2,	/* guest doorbell */
26 	PPC_G_DBELL_CRIT = 3,	/* guest critical doorbell */
27 	PPC_G_DBELL_MC = 4,	/* guest mcheck doorbell */
28 	PPC_DBELL_SERVER = 5,	/* doorbell on server */
29 };
30 
31 #ifdef CONFIG_PPC_BOOK3S
32 
33 #define PPC_DBELL_MSGTYPE		PPC_DBELL_SERVER
34 
35 static inline void _ppc_msgsnd(u32 msg)
36 {
37 	__asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGSND(%1), PPC_MSGSNDP(%1), %0)
38 				: : "i" (CPU_FTR_HVMODE), "r" (msg));
39 }
40 
41 /* sync before sending message */
42 static inline void ppc_msgsnd_sync(void)
43 {
44 	__asm__ __volatile__ ("sync" : : : "memory");
45 }
46 
47 /* sync after taking message interrupt */
48 static inline void ppc_msgsync(void)
49 {
50 	/* sync is not required when taking messages from the same core */
51 	__asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGSYNC " ; lwsync", "", %0)
52 				: : "i" (CPU_FTR_HVMODE|CPU_FTR_ARCH_300));
53 }
54 
55 static inline void _ppc_msgclr(u32 msg)
56 {
57 	__asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGCLR(%1), PPC_MSGCLRP(%1), %0)
58 				: : "i" (CPU_FTR_HVMODE), "r" (msg));
59 }
60 
61 static inline void ppc_msgclr(enum ppc_dbell type)
62 {
63 	u32 msg = PPC_DBELL_TYPE(type);
64 
65 	_ppc_msgclr(msg);
66 }
67 
68 #else /* CONFIG_PPC_BOOK3S */
69 
70 #define PPC_DBELL_MSGTYPE		PPC_DBELL
71 
72 static inline void _ppc_msgsnd(u32 msg)
73 {
74 	__asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
75 }
76 
77 /* sync before sending message */
78 static inline void ppc_msgsnd_sync(void)
79 {
80 	__asm__ __volatile__ ("sync" : : : "memory");
81 }
82 
83 /* sync after taking message interrupt */
84 static inline void ppc_msgsync(void)
85 {
86 }
87 
88 #endif /* CONFIG_PPC_BOOK3S */
89 
90 extern void doorbell_global_ipi(int cpu);
91 extern void doorbell_core_ipi(int cpu);
92 extern int doorbell_try_core_ipi(int cpu);
93 extern void doorbell_exception(struct pt_regs *regs);
94 
95 static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag)
96 {
97 	u32 msg = PPC_DBELL_TYPE(type) | (flags & PPC_DBELL_MSG_BRDCAST) |
98 			(tag & 0x07ffffff);
99 
100 	_ppc_msgsnd(msg);
101 }
102 
103 #endif /* _ASM_POWERPC_DBELL_H */
104