xref: /linux/arch/powerpc/include/asm/exception-64s.h (revision 08685be7761d69914f08c3d6211c543a385a5b9c)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
28aa34ab8SBenjamin Herrenschmidt #ifndef _ASM_POWERPC_EXCEPTION_H
38aa34ab8SBenjamin Herrenschmidt #define _ASM_POWERPC_EXCEPTION_H
48aa34ab8SBenjamin Herrenschmidt /*
58aa34ab8SBenjamin Herrenschmidt  * Extracted from head_64.S
68aa34ab8SBenjamin Herrenschmidt  *
78aa34ab8SBenjamin Herrenschmidt  *  PowerPC version
88aa34ab8SBenjamin Herrenschmidt  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
98aa34ab8SBenjamin Herrenschmidt  *
108aa34ab8SBenjamin Herrenschmidt  *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
118aa34ab8SBenjamin Herrenschmidt  *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
128aa34ab8SBenjamin Herrenschmidt  *  Adapted for Power Macintosh by Paul Mackerras.
138aa34ab8SBenjamin Herrenschmidt  *  Low-level exception handlers and MMU support
148aa34ab8SBenjamin Herrenschmidt  *  rewritten by Paul Mackerras.
158aa34ab8SBenjamin Herrenschmidt  *    Copyright (C) 1996 Paul Mackerras.
168aa34ab8SBenjamin Herrenschmidt  *
178aa34ab8SBenjamin Herrenschmidt  *  Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
188aa34ab8SBenjamin Herrenschmidt  *    Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
198aa34ab8SBenjamin Herrenschmidt  *
208aa34ab8SBenjamin Herrenschmidt  *  This file contains the low-level support and setup for the
218aa34ab8SBenjamin Herrenschmidt  *  PowerPC-64 platform, including trap and interrupt dispatch.
228aa34ab8SBenjamin Herrenschmidt  */
238aa34ab8SBenjamin Herrenschmidt /*
248aa34ab8SBenjamin Herrenschmidt  * The following macros define the code that appears as
258aa34ab8SBenjamin Herrenschmidt  * the prologue to each of the exception handlers.  They
268aa34ab8SBenjamin Herrenschmidt  * are split into two parts to allow a single kernel binary
278aa34ab8SBenjamin Herrenschmidt  * to be used for pSeries and iSeries.
288aa34ab8SBenjamin Herrenschmidt  *
298aa34ab8SBenjamin Herrenschmidt  * We make as much of the exception code common between native
308aa34ab8SBenjamin Herrenschmidt  * exception handlers (including pSeries LPAR) and iSeries LPAR
318aa34ab8SBenjamin Herrenschmidt  * implementations as possible.
328aa34ab8SBenjamin Herrenschmidt  */
332c86cd18SChristophe Leroy #include <asm/feature-fixups.h>
348aa34ab8SBenjamin Herrenschmidt 
3515820091SNicholas Piggin /* PACA save area size in u64 units (exgen, exmc, etc) */
3615820091SNicholas Piggin #define EX_SIZE		10
37dbeea1d6SNicholas Piggin 
38dbeea1d6SNicholas Piggin /*
39ba41e1e1SBalbir Singh  * maximum recursive depth of MCE exceptions
40ba41e1e1SBalbir Singh  */
41ba41e1e1SBalbir Singh #define MAX_MCE_DEPTH	4
42ba41e1e1SBalbir Singh 
434508a74aSNicholas Piggin #ifdef __ASSEMBLY__
44635942aeSNicholas Piggin 
45a048a07dSNicholas Piggin #define STF_ENTRY_BARRIER_SLOT						\
46a048a07dSNicholas Piggin 	STF_ENTRY_BARRIER_FIXUP_SECTION;				\
47a048a07dSNicholas Piggin 	nop;								\
48a048a07dSNicholas Piggin 	nop;								\
49a048a07dSNicholas Piggin 	nop
50a048a07dSNicholas Piggin 
51a048a07dSNicholas Piggin #define STF_EXIT_BARRIER_SLOT						\
52a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_FIXUP_SECTION;					\
53a048a07dSNicholas Piggin 	nop;								\
54a048a07dSNicholas Piggin 	nop;								\
55a048a07dSNicholas Piggin 	nop;								\
56a048a07dSNicholas Piggin 	nop;								\
57a048a07dSNicholas Piggin 	nop;								\
58a048a07dSNicholas Piggin 	nop
59a048a07dSNicholas Piggin 
60f7964378SNicholas Piggin #define ENTRY_FLUSH_SLOT						\
61f7964378SNicholas Piggin 	ENTRY_FLUSH_FIXUP_SECTION;					\
62f7964378SNicholas Piggin 	nop;								\
63f7964378SNicholas Piggin 	nop;								\
64f7964378SNicholas Piggin 	nop;
65f7964378SNicholas Piggin 
66*08685be7SNicholas Piggin #define SCV_ENTRY_FLUSH_SLOT						\
67*08685be7SNicholas Piggin 	SCV_ENTRY_FLUSH_FIXUP_SECTION;					\
68*08685be7SNicholas Piggin 	nop;								\
69*08685be7SNicholas Piggin 	nop;								\
70*08685be7SNicholas Piggin 	nop;
71*08685be7SNicholas Piggin 
72a048a07dSNicholas Piggin /*
73a048a07dSNicholas Piggin  * r10 must be free to use, r13 must be paca
74a048a07dSNicholas Piggin  */
75a048a07dSNicholas Piggin #define INTERRUPT_TO_KERNEL						\
76f7964378SNicholas Piggin 	STF_ENTRY_BARRIER_SLOT;						\
77f7964378SNicholas Piggin 	ENTRY_FLUSH_SLOT
78a048a07dSNicholas Piggin 
79aa8a5e00SMichael Ellerman /*
80*08685be7SNicholas Piggin  * r10, ctr must be free to use, r13 must be paca
81*08685be7SNicholas Piggin  */
82*08685be7SNicholas Piggin #define SCV_INTERRUPT_TO_KERNEL						\
83*08685be7SNicholas Piggin 	STF_ENTRY_BARRIER_SLOT;						\
84*08685be7SNicholas Piggin 	SCV_ENTRY_FLUSH_SLOT
85*08685be7SNicholas Piggin 
86*08685be7SNicholas Piggin /*
87aa8a5e00SMichael Ellerman  * Macros for annotating the expected destination of (h)rfid
88aa8a5e00SMichael Ellerman  *
89aa8a5e00SMichael Ellerman  * The nop instructions allow us to insert one or more instructions to flush the
90aa8a5e00SMichael Ellerman  * L1-D cache when returning to userspace or a guest.
912384b36fSNicholas Piggin  *
922384b36fSNicholas Piggin  * powerpc relies on return from interrupt/syscall being context synchronising
932384b36fSNicholas Piggin  * (which hrfid, rfid, and rfscv are) to support ARCH_HAS_MEMBARRIER_SYNC_CORE
942384b36fSNicholas Piggin  * without additional synchronisation instructions.
952384b36fSNicholas Piggin  *
962384b36fSNicholas Piggin  * soft-masked interrupt replay does not include a context-synchronising rfid,
972384b36fSNicholas Piggin  * but those always return to kernel, the sync is only required when returning
982384b36fSNicholas Piggin  * to user.
99aa8a5e00SMichael Ellerman  */
100aa8a5e00SMichael Ellerman #define RFI_FLUSH_SLOT							\
101aa8a5e00SMichael Ellerman 	RFI_FLUSH_FIXUP_SECTION;					\
102aa8a5e00SMichael Ellerman 	nop;								\
103aa8a5e00SMichael Ellerman 	nop;								\
104aa8a5e00SMichael Ellerman 	nop
10550e51c13SNicholas Piggin 
10650e51c13SNicholas Piggin #define RFI_TO_KERNEL							\
10750e51c13SNicholas Piggin 	rfid
10850e51c13SNicholas Piggin 
10950e51c13SNicholas Piggin #define RFI_TO_USER							\
110a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
111aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
112aa8a5e00SMichael Ellerman 	rfid;								\
113aa8a5e00SMichael Ellerman 	b	rfi_flush_fallback
11450e51c13SNicholas Piggin 
11550e51c13SNicholas Piggin #define RFI_TO_USER_OR_KERNEL						\
116a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
117aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
118aa8a5e00SMichael Ellerman 	rfid;								\
119aa8a5e00SMichael Ellerman 	b	rfi_flush_fallback
12050e51c13SNicholas Piggin 
12150e51c13SNicholas Piggin #define RFI_TO_GUEST							\
122a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
123aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
124aa8a5e00SMichael Ellerman 	rfid;								\
125aa8a5e00SMichael Ellerman 	b	rfi_flush_fallback
12650e51c13SNicholas Piggin 
12750e51c13SNicholas Piggin #define HRFI_TO_KERNEL							\
12850e51c13SNicholas Piggin 	hrfid
12950e51c13SNicholas Piggin 
13050e51c13SNicholas Piggin #define HRFI_TO_USER							\
131a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
132aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
133aa8a5e00SMichael Ellerman 	hrfid;								\
134aa8a5e00SMichael Ellerman 	b	hrfi_flush_fallback
13550e51c13SNicholas Piggin 
13650e51c13SNicholas Piggin #define HRFI_TO_USER_OR_KERNEL						\
137a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
138aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
139aa8a5e00SMichael Ellerman 	hrfid;								\
140aa8a5e00SMichael Ellerman 	b	hrfi_flush_fallback
14150e51c13SNicholas Piggin 
14250e51c13SNicholas Piggin #define HRFI_TO_GUEST							\
143a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
144aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
145aa8a5e00SMichael Ellerman 	hrfid;								\
146aa8a5e00SMichael Ellerman 	b	hrfi_flush_fallback
14750e51c13SNicholas Piggin 
14850e51c13SNicholas Piggin #define HRFI_TO_UNKNOWN							\
149a048a07dSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
150aa8a5e00SMichael Ellerman 	RFI_FLUSH_SLOT;							\
151aa8a5e00SMichael Ellerman 	hrfid;								\
152aa8a5e00SMichael Ellerman 	b	hrfi_flush_fallback
15350e51c13SNicholas Piggin 
1547fa95f9aSNicholas Piggin #define RFSCV_TO_USER							\
1557fa95f9aSNicholas Piggin 	STF_EXIT_BARRIER_SLOT;						\
1567fa95f9aSNicholas Piggin 	RFI_FLUSH_SLOT;							\
1577fa95f9aSNicholas Piggin 	RFSCV;								\
1587fa95f9aSNicholas Piggin 	b	rfscv_flush_fallback
1597fa95f9aSNicholas Piggin 
1609a32a7e7SNicholas Piggin #else /* __ASSEMBLY__ */
1619a32a7e7SNicholas Piggin /* Prototype for function defined in exceptions-64s.S */
1629a32a7e7SNicholas Piggin void do_uaccess_flush(void);
1634508a74aSNicholas Piggin #endif /* __ASSEMBLY__ */
1648aa34ab8SBenjamin Herrenschmidt 
1658aa34ab8SBenjamin Herrenschmidt #endif	/* _ASM_POWERPC_EXCEPTION_H */
166