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 66a048a07dSNicholas Piggin /* 67a048a07dSNicholas Piggin * r10 must be free to use, r13 must be paca 68a048a07dSNicholas Piggin */ 69a048a07dSNicholas Piggin #define INTERRUPT_TO_KERNEL \ 70f7964378SNicholas Piggin STF_ENTRY_BARRIER_SLOT; \ 71f7964378SNicholas Piggin ENTRY_FLUSH_SLOT 72a048a07dSNicholas Piggin 73aa8a5e00SMichael Ellerman /* 74aa8a5e00SMichael Ellerman * Macros for annotating the expected destination of (h)rfid 75aa8a5e00SMichael Ellerman * 76aa8a5e00SMichael Ellerman * The nop instructions allow us to insert one or more instructions to flush the 77aa8a5e00SMichael Ellerman * L1-D cache when returning to userspace or a guest. 782384b36fSNicholas Piggin * 792384b36fSNicholas Piggin * powerpc relies on return from interrupt/syscall being context synchronising 802384b36fSNicholas Piggin * (which hrfid, rfid, and rfscv are) to support ARCH_HAS_MEMBARRIER_SYNC_CORE 812384b36fSNicholas Piggin * without additional synchronisation instructions. 822384b36fSNicholas Piggin * 832384b36fSNicholas Piggin * soft-masked interrupt replay does not include a context-synchronising rfid, 842384b36fSNicholas Piggin * but those always return to kernel, the sync is only required when returning 852384b36fSNicholas Piggin * to user. 86aa8a5e00SMichael Ellerman */ 87aa8a5e00SMichael Ellerman #define RFI_FLUSH_SLOT \ 88aa8a5e00SMichael Ellerman RFI_FLUSH_FIXUP_SECTION; \ 89aa8a5e00SMichael Ellerman nop; \ 90aa8a5e00SMichael Ellerman nop; \ 91aa8a5e00SMichael Ellerman nop 9250e51c13SNicholas Piggin 9350e51c13SNicholas Piggin #define RFI_TO_KERNEL \ 9450e51c13SNicholas Piggin rfid 9550e51c13SNicholas Piggin 9650e51c13SNicholas Piggin #define RFI_TO_USER \ 97a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 98aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 99aa8a5e00SMichael Ellerman rfid; \ 100aa8a5e00SMichael Ellerman b rfi_flush_fallback 10150e51c13SNicholas Piggin 10250e51c13SNicholas Piggin #define RFI_TO_USER_OR_KERNEL \ 103a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 104aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 105aa8a5e00SMichael Ellerman rfid; \ 106aa8a5e00SMichael Ellerman b rfi_flush_fallback 10750e51c13SNicholas Piggin 10850e51c13SNicholas Piggin #define RFI_TO_GUEST \ 109a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 110aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 111aa8a5e00SMichael Ellerman rfid; \ 112aa8a5e00SMichael Ellerman b rfi_flush_fallback 11350e51c13SNicholas Piggin 11450e51c13SNicholas Piggin #define HRFI_TO_KERNEL \ 11550e51c13SNicholas Piggin hrfid 11650e51c13SNicholas Piggin 11750e51c13SNicholas Piggin #define HRFI_TO_USER \ 118a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 119aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 120aa8a5e00SMichael Ellerman hrfid; \ 121aa8a5e00SMichael Ellerman b hrfi_flush_fallback 12250e51c13SNicholas Piggin 12350e51c13SNicholas Piggin #define HRFI_TO_USER_OR_KERNEL \ 124a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 125aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 126aa8a5e00SMichael Ellerman hrfid; \ 127aa8a5e00SMichael Ellerman b hrfi_flush_fallback 12850e51c13SNicholas Piggin 12950e51c13SNicholas Piggin #define HRFI_TO_GUEST \ 130a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 131aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 132aa8a5e00SMichael Ellerman hrfid; \ 133aa8a5e00SMichael Ellerman b hrfi_flush_fallback 13450e51c13SNicholas Piggin 13550e51c13SNicholas Piggin #define HRFI_TO_UNKNOWN \ 136a048a07dSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 137aa8a5e00SMichael Ellerman RFI_FLUSH_SLOT; \ 138aa8a5e00SMichael Ellerman hrfid; \ 139aa8a5e00SMichael Ellerman b hrfi_flush_fallback 14050e51c13SNicholas Piggin 1417fa95f9aSNicholas Piggin #define RFSCV_TO_USER \ 1427fa95f9aSNicholas Piggin STF_EXIT_BARRIER_SLOT; \ 1437fa95f9aSNicholas Piggin RFI_FLUSH_SLOT; \ 1447fa95f9aSNicholas Piggin RFSCV; \ 1457fa95f9aSNicholas Piggin b rfscv_flush_fallback 1467fa95f9aSNicholas Piggin 147*9a32a7e7SNicholas Piggin #else /* __ASSEMBLY__ */ 148*9a32a7e7SNicholas Piggin /* Prototype for function defined in exceptions-64s.S */ 149*9a32a7e7SNicholas Piggin void do_uaccess_flush(void); 1504508a74aSNicholas Piggin #endif /* __ASSEMBLY__ */ 1518aa34ab8SBenjamin Herrenschmidt 1528aa34ab8SBenjamin Herrenschmidt #endif /* _ASM_POWERPC_EXCEPTION_H */ 153