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 38*04ece7b6SNicholas Piggin /* PACA save area offsets */ 39*04ece7b6SNicholas Piggin #define EX_R9 0 40*04ece7b6SNicholas Piggin #define EX_R10 8 41*04ece7b6SNicholas Piggin #define EX_R11 16 42*04ece7b6SNicholas Piggin #define EX_R12 24 43*04ece7b6SNicholas Piggin #define EX_R13 32 44*04ece7b6SNicholas Piggin #define EX_DAR 40 45*04ece7b6SNicholas Piggin #define EX_DSISR 48 46*04ece7b6SNicholas Piggin #define EX_CCR 52 47*04ece7b6SNicholas Piggin #define EX_CFAR 56 48*04ece7b6SNicholas Piggin #define EX_PPR 64 49*04ece7b6SNicholas Piggin #define EX_CTR 72 50*04ece7b6SNicholas Piggin 51dbeea1d6SNicholas Piggin /* 52ba41e1e1SBalbir Singh * maximum recursive depth of MCE exceptions 53ba41e1e1SBalbir Singh */ 54ba41e1e1SBalbir Singh #define MAX_MCE_DEPTH 4 55ba41e1e1SBalbir Singh 564508a74aSNicholas Piggin #ifdef __ASSEMBLY__ 57635942aeSNicholas Piggin 58a048a07dSNicholas Piggin #define STF_ENTRY_BARRIER_SLOT \ 59a048a07dSNicholas Piggin STF_ENTRY_BARRIER_FIXUP_SECTION; \ 60a048a07dSNicholas Piggin nop; \ 61a048a07dSNicholas Piggin nop; \ 62a048a07dSNicholas Piggin nop 63a048a07dSNicholas Piggin 64a048a07dSNicholas Piggin #define STF_EXIT_BARRIER_SLOT \ 65a048a07dSNicholas Piggin STF_EXIT_BARRIER_FIXUP_SECTION; \ 66a048a07dSNicholas Piggin nop; \ 67a048a07dSNicholas Piggin nop; \ 68a048a07dSNicholas Piggin nop; \ 69a048a07dSNicholas Piggin nop; \ 70a048a07dSNicholas Piggin nop; \ 71a048a07dSNicholas Piggin nop 72a048a07dSNicholas Piggin 73f7964378SNicholas Piggin #define ENTRY_FLUSH_SLOT \ 74f7964378SNicholas Piggin ENTRY_FLUSH_FIXUP_SECTION; \ 75f7964378SNicholas Piggin nop; \ 76f7964378SNicholas Piggin nop; \ 77f7964378SNicholas Piggin nop; 78f7964378SNicholas Piggin 7908685be7SNicholas Piggin #define SCV_ENTRY_FLUSH_SLOT \ 8008685be7SNicholas Piggin SCV_ENTRY_FLUSH_FIXUP_SECTION; \ 8108685be7SNicholas Piggin nop; \ 8208685be7SNicholas Piggin nop; \ 8308685be7SNicholas Piggin nop; 8408685be7SNicholas Piggin 85a048a07dSNicholas Piggin /* 86a048a07dSNicholas Piggin * r10 must be free to use, r13 must be paca 87a048a07dSNicholas Piggin */ 88a048a07dSNicholas Piggin #define INTERRUPT_TO_KERNEL \ 89f7964378SNicholas Piggin STF_ENTRY_BARRIER_SLOT; \ 90f7964378SNicholas Piggin ENTRY_FLUSH_SLOT 91a048a07dSNicholas Piggin 92aa8a5e00SMichael Ellerman /* 9308685be7SNicholas Piggin * r10, ctr must be free to use, r13 must be paca 9408685be7SNicholas Piggin */ 9508685be7SNicholas Piggin #define SCV_INTERRUPT_TO_KERNEL \ 9608685be7SNicholas Piggin STF_ENTRY_BARRIER_SLOT; \ 9708685be7SNicholas Piggin SCV_ENTRY_FLUSH_SLOT 9808685be7SNicholas Piggin 9908685be7SNicholas Piggin /* 100aa8a5e00SMichael Ellerman * Macros for annotating the expected destination of (h)rfid 101aa8a5e00SMichael Ellerman * 102aa8a5e00SMichael Ellerman * The nop instructions allow us to insert one or more instructions to flush the 103aa8a5e00SMichael Ellerman * L1-D cache when returning to userspace or a guest. 1042384b36fSNicholas Piggin * 1052384b36fSNicholas Piggin * powerpc relies on return from interrupt/syscall being context synchronising 1062384b36fSNicholas Piggin * (which hrfid, rfid, and rfscv are) to support ARCH_HAS_MEMBARRIER_SYNC_CORE 1072384b36fSNicholas Piggin * without additional synchronisation instructions. 1082384b36fSNicholas Piggin * 1092384b36fSNicholas Piggin * soft-masked interrupt replay does not include a context-synchronising rfid, 1102384b36fSNicholas Piggin * but those always return to kernel, the sync is only required when returning 1112384b36fSNicholas Piggin * to user. 112aa8a5e00SMichael Ellerman */ 113aa8a5e00SMichael Ellerman #define RFI_FLUSH_SLOT \ 114aa8a5e00SMichael Ellerman RFI_FLUSH_FIXUP_SECTION; \ 115aa8a5e00SMichael Ellerman nop; \ 116aa8a5e00SMichael Ellerman nop; \ 117aa8a5e00SMichael Ellerman nop 11850e51c13SNicholas Piggin 11950e51c13SNicholas Piggin #define RFI_TO_KERNEL \ 12050e51c13SNicholas Piggin rfid 12150e51c13SNicholas Piggin 12250e51c13SNicholas Piggin #define RFI_TO_USER \ 123a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 124aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 125aa8a5e00SMichael Ellerman rfid; \ 126aa8a5e00SMichael Ellerman b rfi_flush_fallback 12750e51c13SNicholas Piggin 12850e51c13SNicholas Piggin #define RFI_TO_USER_OR_KERNEL \ 129a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 130aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 131aa8a5e00SMichael Ellerman rfid; \ 132aa8a5e00SMichael Ellerman b rfi_flush_fallback 13350e51c13SNicholas Piggin 13450e51c13SNicholas Piggin #define RFI_TO_GUEST \ 135a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 136aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 137aa8a5e00SMichael Ellerman rfid; \ 138aa8a5e00SMichael Ellerman b rfi_flush_fallback 13950e51c13SNicholas Piggin 14050e51c13SNicholas Piggin #define HRFI_TO_KERNEL \ 14150e51c13SNicholas Piggin hrfid 14250e51c13SNicholas Piggin 14350e51c13SNicholas Piggin #define HRFI_TO_USER \ 144a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 145aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 146aa8a5e00SMichael Ellerman hrfid; \ 147aa8a5e00SMichael Ellerman b hrfi_flush_fallback 14850e51c13SNicholas Piggin 14950e51c13SNicholas Piggin #define HRFI_TO_USER_OR_KERNEL \ 150a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 151aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 152aa8a5e00SMichael Ellerman hrfid; \ 153aa8a5e00SMichael Ellerman b hrfi_flush_fallback 15450e51c13SNicholas Piggin 15550e51c13SNicholas Piggin #define HRFI_TO_GUEST \ 156a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 157aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 158aa8a5e00SMichael Ellerman hrfid; \ 159aa8a5e00SMichael Ellerman b hrfi_flush_fallback 16050e51c13SNicholas Piggin 16150e51c13SNicholas Piggin #define HRFI_TO_UNKNOWN \ 162a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 163aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 164aa8a5e00SMichael Ellerman hrfid; \ 165aa8a5e00SMichael Ellerman b hrfi_flush_fallback 16650e51c13SNicholas Piggin 1677fa95f9aSNicholas Piggin #define RFSCV_TO_USER \ 1687fa95f9aSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 1697fa95f9aSNicholas Piggin RFI_FLUSH_SLOT; \ 1707fa95f9aSNicholas Piggin RFSCV; \ 1717fa95f9aSNicholas Piggin b rfscv_flush_fallback 1727fa95f9aSNicholas Piggin 1739a32a7e7SNicholas Piggin #else /* __ASSEMBLY__ */ 1749a32a7e7SNicholas Piggin /* Prototype for function defined in exceptions-64s.S */ 1759a32a7e7SNicholas Piggin void do_uaccess_flush(void); 1764508a74aSNicholas Piggin #endif /* __ASSEMBLY__ */ 1778aa34ab8SBenjamin Herrenschmidt 1788aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 179