18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_EXCEPTION_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_EXCEPTION_H
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci * Extracted from head_64.S
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  PowerPC version
88c2ecf20Sopenharmony_ci *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
118c2ecf20Sopenharmony_ci *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
128c2ecf20Sopenharmony_ci *  Adapted for Power Macintosh by Paul Mackerras.
138c2ecf20Sopenharmony_ci *  Low-level exception handlers and MMU support
148c2ecf20Sopenharmony_ci *  rewritten by Paul Mackerras.
158c2ecf20Sopenharmony_ci *    Copyright (C) 1996 Paul Mackerras.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci *  Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
188c2ecf20Sopenharmony_ci *    Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *  This file contains the low-level support and setup for the
218c2ecf20Sopenharmony_ci *  PowerPC-64 platform, including trap and interrupt dispatch.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * The following macros define the code that appears as
258c2ecf20Sopenharmony_ci * the prologue to each of the exception handlers.  They
268c2ecf20Sopenharmony_ci * are split into two parts to allow a single kernel binary
278c2ecf20Sopenharmony_ci * to be used for pSeries and iSeries.
288c2ecf20Sopenharmony_ci *
298c2ecf20Sopenharmony_ci * We make as much of the exception code common between native
308c2ecf20Sopenharmony_ci * exception handlers (including pSeries LPAR) and iSeries LPAR
318c2ecf20Sopenharmony_ci * implementations as possible.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci#include <asm/feature-fixups.h>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* PACA save area size in u64 units (exgen, exmc, etc) */
368c2ecf20Sopenharmony_ci#define EX_SIZE		10
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * maximum recursive depth of MCE exceptions
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci#define MAX_MCE_DEPTH	4
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#ifdef __ASSEMBLY__
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define STF_ENTRY_BARRIER_SLOT						\
468c2ecf20Sopenharmony_ci	STF_ENTRY_BARRIER_FIXUP_SECTION;				\
478c2ecf20Sopenharmony_ci	nop;								\
488c2ecf20Sopenharmony_ci	nop;								\
498c2ecf20Sopenharmony_ci	nop
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define STF_EXIT_BARRIER_SLOT						\
528c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_FIXUP_SECTION;					\
538c2ecf20Sopenharmony_ci	nop;								\
548c2ecf20Sopenharmony_ci	nop;								\
558c2ecf20Sopenharmony_ci	nop;								\
568c2ecf20Sopenharmony_ci	nop;								\
578c2ecf20Sopenharmony_ci	nop;								\
588c2ecf20Sopenharmony_ci	nop
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define ENTRY_FLUSH_SLOT						\
618c2ecf20Sopenharmony_ci	ENTRY_FLUSH_FIXUP_SECTION;					\
628c2ecf20Sopenharmony_ci	nop;								\
638c2ecf20Sopenharmony_ci	nop;								\
648c2ecf20Sopenharmony_ci	nop;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define SCV_ENTRY_FLUSH_SLOT						\
678c2ecf20Sopenharmony_ci	SCV_ENTRY_FLUSH_FIXUP_SECTION;					\
688c2ecf20Sopenharmony_ci	nop;								\
698c2ecf20Sopenharmony_ci	nop;								\
708c2ecf20Sopenharmony_ci	nop;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/*
738c2ecf20Sopenharmony_ci * r10 must be free to use, r13 must be paca
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_ci#define INTERRUPT_TO_KERNEL						\
768c2ecf20Sopenharmony_ci	STF_ENTRY_BARRIER_SLOT;						\
778c2ecf20Sopenharmony_ci	ENTRY_FLUSH_SLOT
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/*
808c2ecf20Sopenharmony_ci * r10, ctr must be free to use, r13 must be paca
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_ci#define SCV_INTERRUPT_TO_KERNEL						\
838c2ecf20Sopenharmony_ci	STF_ENTRY_BARRIER_SLOT;						\
848c2ecf20Sopenharmony_ci	SCV_ENTRY_FLUSH_SLOT
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/*
878c2ecf20Sopenharmony_ci * Macros for annotating the expected destination of (h)rfid
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * The nop instructions allow us to insert one or more instructions to flush the
908c2ecf20Sopenharmony_ci * L1-D cache when returning to userspace or a guest.
918c2ecf20Sopenharmony_ci *
928c2ecf20Sopenharmony_ci * powerpc relies on return from interrupt/syscall being context synchronising
938c2ecf20Sopenharmony_ci * (which hrfid, rfid, and rfscv are) to support ARCH_HAS_MEMBARRIER_SYNC_CORE
948c2ecf20Sopenharmony_ci * without additional synchronisation instructions.
958c2ecf20Sopenharmony_ci *
968c2ecf20Sopenharmony_ci * soft-masked interrupt replay does not include a context-synchronising rfid,
978c2ecf20Sopenharmony_ci * but those always return to kernel, the sync is only required when returning
988c2ecf20Sopenharmony_ci * to user.
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci#define RFI_FLUSH_SLOT							\
1018c2ecf20Sopenharmony_ci	RFI_FLUSH_FIXUP_SECTION;					\
1028c2ecf20Sopenharmony_ci	nop;								\
1038c2ecf20Sopenharmony_ci	nop;								\
1048c2ecf20Sopenharmony_ci	nop
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define RFI_TO_KERNEL							\
1078c2ecf20Sopenharmony_ci	rfid
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define RFI_TO_USER							\
1108c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1118c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1128c2ecf20Sopenharmony_ci	rfid;								\
1138c2ecf20Sopenharmony_ci	b	rfi_flush_fallback
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define RFI_TO_USER_OR_KERNEL						\
1168c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1178c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1188c2ecf20Sopenharmony_ci	rfid;								\
1198c2ecf20Sopenharmony_ci	b	rfi_flush_fallback
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#define RFI_TO_GUEST							\
1228c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1238c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1248c2ecf20Sopenharmony_ci	rfid;								\
1258c2ecf20Sopenharmony_ci	b	rfi_flush_fallback
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define HRFI_TO_KERNEL							\
1288c2ecf20Sopenharmony_ci	hrfid
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define HRFI_TO_USER							\
1318c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1328c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1338c2ecf20Sopenharmony_ci	hrfid;								\
1348c2ecf20Sopenharmony_ci	b	hrfi_flush_fallback
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define HRFI_TO_USER_OR_KERNEL						\
1378c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1388c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1398c2ecf20Sopenharmony_ci	hrfid;								\
1408c2ecf20Sopenharmony_ci	b	hrfi_flush_fallback
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define HRFI_TO_GUEST							\
1438c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1448c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1458c2ecf20Sopenharmony_ci	hrfid;								\
1468c2ecf20Sopenharmony_ci	b	hrfi_flush_fallback
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#define HRFI_TO_UNKNOWN							\
1498c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1508c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1518c2ecf20Sopenharmony_ci	hrfid;								\
1528c2ecf20Sopenharmony_ci	b	hrfi_flush_fallback
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define RFSCV_TO_USER							\
1558c2ecf20Sopenharmony_ci	STF_EXIT_BARRIER_SLOT;						\
1568c2ecf20Sopenharmony_ci	RFI_FLUSH_SLOT;							\
1578c2ecf20Sopenharmony_ci	RFSCV;								\
1588c2ecf20Sopenharmony_ci	b	rfscv_flush_fallback
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#else /* __ASSEMBLY__ */
1618c2ecf20Sopenharmony_ci/* Prototype for function defined in exceptions-64s.S */
1628c2ecf20Sopenharmony_civoid do_uaccess_flush(void);
1638c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#endif	/* _ASM_POWERPC_EXCEPTION_H */
166