xref: /openbmc/linux/arch/arm64/include/asm/traps.h (revision e13d32e9)
1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
260ffc30dSCatalin Marinas /*
360ffc30dSCatalin Marinas  * Based on arch/arm/include/asm/traps.h
460ffc30dSCatalin Marinas  *
560ffc30dSCatalin Marinas  * Copyright (C) 2012 ARM Ltd.
660ffc30dSCatalin Marinas  */
760ffc30dSCatalin Marinas #ifndef __ASM_TRAP_H
860ffc30dSCatalin Marinas #define __ASM_TRAP_H
960ffc30dSCatalin Marinas 
109b79f52dSPunit Agrawal #include <linux/list.h>
116bf0dcfdSJames Morse #include <asm/esr.h>
12ee78fdc7SJames Morse #include <asm/sections.h>
139b79f52dSPunit Agrawal 
149b79f52dSPunit Agrawal struct pt_regs;
159b79f52dSPunit Agrawal 
16124c49b1SMark Rutland #ifdef CONFIG_ARMV8_DEPRECATED
17124c49b1SMark Rutland bool try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn);
18124c49b1SMark Rutland #else
19124c49b1SMark Rutland static inline bool
try_emulate_armv8_deprecated(struct pt_regs * regs,u32 insn)20124c49b1SMark Rutland try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn)
21124c49b1SMark Rutland {
22124c49b1SMark Rutland 	return false;
23124c49b1SMark Rutland }
24124c49b1SMark Rutland #endif /* CONFIG_ARMV8_DEPRECATED */
259b79f52dSPunit Agrawal 
268d56e5c5SAlexandru Elisei void force_signal_inject(int signal, int code, unsigned long address, unsigned long err);
272c9120f3SWill Deacon void arm64_notify_segfault(unsigned long addr);
28dceec3ffSPeter Collingbourne void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str);
29dceec3ffSPeter Collingbourne void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str);
30dceec3ffSPeter Collingbourne void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str);
31390bf177SAndre Przywara 
32*e13d32e9SArnd Bergmann int early_brk64(unsigned long addr, unsigned long esr, struct pt_regs *regs);
33*e13d32e9SArnd Bergmann 
346436beeeSJulien Thierry /*
356436beeeSJulien Thierry  * Move regs->pc to next instruction and do necessary setup before it
366436beeeSJulien Thierry  * is executed.
376436beeeSJulien Thierry  */
386436beeeSJulien Thierry void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size);
396436beeeSJulien Thierry 
__in_irqentry_text(unsigned long ptr)409a5ad7d0SJungseok Lee static inline int __in_irqentry_text(unsigned long ptr)
419a5ad7d0SJungseok Lee {
429a5ad7d0SJungseok Lee 	return ptr >= (unsigned long)&__irqentry_text_start &&
439a5ad7d0SJungseok Lee 	       ptr < (unsigned long)&__irqentry_text_end;
449a5ad7d0SJungseok Lee }
459a5ad7d0SJungseok Lee 
in_entry_text(unsigned long ptr)4673267498SArd Biesheuvel static inline int in_entry_text(unsigned long ptr)
4773267498SArd Biesheuvel {
4873267498SArd Biesheuvel 	return ptr >= (unsigned long)&__entry_text_start &&
4973267498SArd Biesheuvel 	       ptr < (unsigned long)&__entry_text_end;
5073267498SArd Biesheuvel }
516bf0dcfdSJames Morse 
526bf0dcfdSJames Morse /*
536bf0dcfdSJames Morse  * CPUs with the RAS extensions have an Implementation-Defined-Syndrome bit
546bf0dcfdSJames Morse  * to indicate whether this ESR has a RAS encoding. CPUs without this feature
556bf0dcfdSJames Morse  * have a ISS-Valid bit in the same position.
566bf0dcfdSJames Morse  * If this bit is set, we know its not a RAS SError.
576bf0dcfdSJames Morse  * If its clear, we need to know if the CPU supports RAS. Uncategorized RAS
586bf0dcfdSJames Morse  * errors share the same encoding as an all-zeros encoding from a CPU that
596bf0dcfdSJames Morse  * doesn't support RAS.
606bf0dcfdSJames Morse  */
arm64_is_ras_serror(unsigned long esr)618d56e5c5SAlexandru Elisei static inline bool arm64_is_ras_serror(unsigned long esr)
626bf0dcfdSJames Morse {
636bf0dcfdSJames Morse 	WARN_ON(preemptible());
646bf0dcfdSJames Morse 
656bf0dcfdSJames Morse 	if (esr & ESR_ELx_IDS)
666bf0dcfdSJames Morse 		return false;
676bf0dcfdSJames Morse 
686bf0dcfdSJames Morse 	if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN))
696bf0dcfdSJames Morse 		return true;
706bf0dcfdSJames Morse 	else
716bf0dcfdSJames Morse 		return false;
726bf0dcfdSJames Morse }
736bf0dcfdSJames Morse 
746bf0dcfdSJames Morse /*
756bf0dcfdSJames Morse  * Return the AET bits from a RAS SError's ESR.
766bf0dcfdSJames Morse  *
776bf0dcfdSJames Morse  * It is implementation defined whether Uncategorized errors are containable.
786bf0dcfdSJames Morse  * We treat them as Uncontainable.
796bf0dcfdSJames Morse  * Non-RAS SError's are reported as Uncontained/Uncategorized.
806bf0dcfdSJames Morse  */
arm64_ras_serror_get_severity(unsigned long esr)818d56e5c5SAlexandru Elisei static inline unsigned long arm64_ras_serror_get_severity(unsigned long esr)
826bf0dcfdSJames Morse {
838d56e5c5SAlexandru Elisei 	unsigned long aet = esr & ESR_ELx_AET;
846bf0dcfdSJames Morse 
856bf0dcfdSJames Morse 	if (!arm64_is_ras_serror(esr)) {
866bf0dcfdSJames Morse 		/* Not a RAS error, we can't interpret the ESR. */
876bf0dcfdSJames Morse 		return ESR_ELx_AET_UC;
886bf0dcfdSJames Morse 	}
896bf0dcfdSJames Morse 
906bf0dcfdSJames Morse 	/*
916bf0dcfdSJames Morse 	 * AET is RES0 if 'the value returned in the DFSC field is not
926bf0dcfdSJames Morse 	 * [ESR_ELx_FSC_SERROR]'
936bf0dcfdSJames Morse 	 */
946bf0dcfdSJames Morse 	if ((esr & ESR_ELx_FSC) != ESR_ELx_FSC_SERROR) {
956bf0dcfdSJames Morse 		/* No severity information : Uncategorized */
966bf0dcfdSJames Morse 		return ESR_ELx_AET_UC;
976bf0dcfdSJames Morse 	}
986bf0dcfdSJames Morse 
996bf0dcfdSJames Morse 	return aet;
1006bf0dcfdSJames Morse }
1016bf0dcfdSJames Morse 
1028d56e5c5SAlexandru Elisei bool arm64_is_fatal_ras_serror(struct pt_regs *regs, unsigned long esr);
1038d56e5c5SAlexandru Elisei void __noreturn arm64_serror_panic(struct pt_regs *regs, unsigned long esr);
10460ffc30dSCatalin Marinas #endif
105