1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4  */
5 
6 #ifndef ESR_H
7 #define ESR_H
8 
9 #include <arch.h>
10 #include <assert.h>
11 #include <stdbool.h>
12 #include <utils_def.h>
13 
esr_srt(unsigned long esr)14 static inline unsigned int esr_srt(unsigned long esr)
15 {
16 	return EXTRACT(ESR_EL2_ABORT_SRT, esr);
17 }
18 
esr_is_write(unsigned long esr)19 static inline bool esr_is_write(unsigned long esr)
20 {
21 	return ((esr & ESR_EL2_ABORT_WNR_BIT) != 0UL);
22 }
23 
esr_sign_extend(unsigned long esr)24 static inline bool esr_sign_extend(unsigned long esr)
25 {
26 	return ((esr & ESR_EL2_ABORT_SSE_BIT) != 0UL);
27 }
28 
esr_sixty_four(unsigned long esr)29 static inline bool esr_sixty_four(unsigned long esr)
30 {
31 	return ((esr & ESR_EL2_ABORT_SF_BIT) != 0UL);
32 }
33 
esr_sas(unsigned long esr)34 static inline unsigned int esr_sas(unsigned long esr)
35 {
36 	return EXTRACT(ESR_EL2_ABORT_SAS, esr);
37 }
38 
access_len(unsigned long esr)39 static inline unsigned int access_len(unsigned long esr)
40 {
41 	switch (esr_sas(esr)) {
42 	case ESR_EL2_ABORT_SAS_BYTE_VAL:
43 		return 1U;
44 	case ESR_EL2_ABORT_SAS_HWORD_VAL:
45 		return 2U;
46 	case ESR_EL2_ABORT_SAS_WORD_VAL:
47 		return 4U;
48 	default:
49 		assert(esr_sas(esr) == ESR_EL2_ABORT_SAS_DWORD_VAL);
50 		return 8U;
51 	}
52 }
53 
access_mask(unsigned long esr)54 static inline unsigned long access_mask(unsigned long esr)
55 {
56 	switch (esr_sas(esr)) {
57 	case ESR_EL2_ABORT_SAS_BYTE_VAL:
58 		return 0xffUL;
59 	case ESR_EL2_ABORT_SAS_HWORD_VAL:
60 		return 0xffffUL;
61 	case ESR_EL2_ABORT_SAS_WORD_VAL:
62 		return 0xffffffffUL;
63 	default:
64 		assert(esr_sas(esr) == ESR_EL2_ABORT_SAS_DWORD_VAL);
65 		return ~(0UL);
66 	}
67 }
68 
69 /*
70  * For a trapped msr/mrs sysreg access, get the transfer register in the
71  * ESR_EL2.
72  */
esr_sysreg_rt(unsigned long esr)73 static inline unsigned int esr_sysreg_rt(unsigned long esr)
74 {
75 	return EXTRACT(ESR_EL2_SYSREG_TRAP_RT, esr);
76 }
77 
78 #endif /* ESR_H */
79