2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2013
7 * Jan Kiszka <jan.kiszka@siemens.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #ifndef _JAILHOUSE_ASM_PROCESSOR_H
14 #define _JAILHOUSE_ASM_PROCESSOR_H
16 #include <jailhouse/types.h>
17 #include <jailhouse/utils.h>
19 #define PSR_MODE_MASK 0xf
20 #define PSR_USR_MODE 0x0
21 #define PSR_FIQ_MODE 0x1
22 #define PSR_IRQ_MODE 0x2
23 #define PSR_SVC_MODE 0x3
24 #define PSR_MON_MODE 0x6
25 #define PSR_ABT_MODE 0x7
26 #define PSR_HYP_MODE 0xa
27 #define PSR_UND_MODE 0xb
28 #define PSR_SYS_MODE 0xf
30 #define PSR_32_BIT (1 << 4)
31 #define PSR_T_BIT (1 << 5)
32 #define PSR_F_BIT (1 << 6)
33 #define PSR_I_BIT (1 << 7)
34 #define PSR_A_BIT (1 << 8)
35 #define PSR_E_BIT (1 << 9)
36 #define PSR_J_BIT (1 << 24)
37 #define PSR_IT_MASK(it) (((it) & 0x3) << 25 | ((it) & 0xfc) << 8)
38 #define PSR_IT(psr) (((psr) >> 25 & 0x3) | ((psr) >> 8 & 0xfc))
40 #define RESET_PSR (PSR_I_BIT | PSR_F_BIT | PSR_A_BIT | PSR_SVC_MODE \
43 #define MPIDR_CPUID_MASK 0x00ffffff
44 #define MPIDR_MP_BIT (1 << 31)
45 #define MPIDR_U_BIT (1 << 30)
47 #define PFR1_VIRT(pfr) ((pfr) >> 12 & 0xf)
49 #define SCTLR_M_BIT (1 << 0)
50 #define SCTLR_A_BIT (1 << 1)
51 #define SCTLR_C_BIT (1 << 2)
52 #define SCTLR_CP15B_BIT (1 << 5)
53 #define SCTLR_ITD_BIT (1 << 7)
54 #define SCTLR_SED_BIT (1 << 8)
55 #define SCTLR_I_BIT (1 << 12)
56 #define SCTLR_V_BIT (1 << 13)
57 #define SCTLR_nTWI (1 << 16)
58 #define SCTLR_nTWE (1 << 18)
59 #define SCTLR_WXN_BIT (1 << 19)
60 #define SCTLR_UWXN_BIT (1 << 20)
61 #define SCTLR_FI_BIT (1 << 21)
62 #define SCTLR_EE_BIT (1 << 25)
63 #define SCTLR_TRE_BIT (1 << 28)
64 #define SCTLR_AFE_BIT (1 << 29)
65 #define SCTLR_TE_BIT (1 << 30)
67 /* Bits to wipe on cell reset */
68 #define SCTLR_MASK (SCTLR_M_BIT | SCTLR_A_BIT | SCTLR_C_BIT \
69 | SCTLR_I_BIT | SCTLR_V_BIT | SCTLR_WXN_BIT \
70 | SCTLR_UWXN_BIT | SCTLR_FI_BIT | SCTLR_EE_BIT \
71 | SCTLR_TRE_BIT | SCTLR_AFE_BIT | SCTLR_TE_BIT)
73 #define HCR_TRVM_BIT (1 << 30)
74 #define HCR_TVM_BIT (1 << 26)
75 #define HCR_HDC_BIT (1 << 29)
76 #define HCR_TGE_BIT (1 << 27)
77 #define HCR_TTLB_BIT (1 << 25)
78 #define HCR_TPU_BIT (1 << 24)
79 #define HCR_TPC_BIT (1 << 23)
80 #define HCR_TSW_BIT (1 << 22)
81 #define HCR_TAC_BIT (1 << 21)
82 #define HCR_TIDCP_BIT (1 << 20)
83 #define HCR_TSC_BIT (1 << 19)
84 #define HCR_TID3_BIT (1 << 18)
85 #define HCR_TID2_BIT (1 << 17)
86 #define HCR_TID1_BIT (1 << 16)
87 #define HCR_TID0_BIT (1 << 15)
88 #define HCR_TWE_BIT (1 << 14)
89 #define HCR_TWI_BIT (1 << 13)
90 #define HCR_DC_BIT (1 << 12)
91 #define HCR_BSU_BITS (3 << 10)
92 #define HCR_BSU_INNER (1 << 10)
93 #define HCR_BSU_OUTER (2 << 10)
94 #define HCR_BSU_FULL HCR_BSU_BITS
95 #define HCR_FB_BIT (1 << 9)
96 #define HCR_VA_BIT (1 << 8)
97 #define HCR_VI_BIT (1 << 7)
98 #define HCR_VF_BIT (1 << 6)
99 #define HCR_AMO_BIT (1 << 5)
100 #define HCR_IMO_BIT (1 << 4)
101 #define HCR_FMO_BIT (1 << 3)
102 #define HCR_PTW_BIT (1 << 2)
103 #define HCR_SWIO_BIT (1 << 1)
104 #define HCR_VM_BIT (1 << 0)
106 #define PAR_F_BIT 0x1
107 #define PAR_FST_SHIFT 1
108 #define PAR_FST_MASK 0x3f
109 #define PAR_SHA_SHIFT 7
110 #define PAR_SHA_MASK 0x3
111 #define PAR_NS_BIT (0x1 << 9)
112 #define PAR_LPAE_BIT (0x1 << 11)
113 #define PAR_PA_MASK BIT_MASK(39, 12)
114 #define PAR_ATTR_SHIFT 56
115 #define PAR_ATTR_MASK 0xff
117 /* exception class */
118 #define ESR_EC_SHIFT 26
119 #define ESR_EC(hsr) ((hsr) >> ESR_EC_SHIFT & 0x3f)
120 /* instruction length */
121 #define ESR_IL_SHIFT 25
122 #define ESR_IL(hsr) ((hsr) >> ESR_IL_SHIFT & 0x1)
123 /* Instruction specific */
124 #define ESR_ICC_MASK 0x1ffffff
125 #define ESR_ICC(hsr) ((hsr) & ESR_ICC_MASK)
126 /* Exception classes values */
127 #define ESR_EC_UNK 0x00
128 #define ESR_EC_WFI 0x01
129 #define ESR_EC_CP15_32 0x03
130 #define ESR_EC_CP15_64 0x04
131 #define ESR_EC_CP14_32 0x05
132 #define ESR_EC_CP14_LC 0x06
133 #define ESR_EC_HCPTR 0x07
134 #define ESR_EC_CP10 0x08
135 #define ESR_EC_CP14_64 0x0c
136 #define ESR_EC_SVC_HYP 0x11
137 #define ESR_EC_HVC 0x12
138 #define ESR_EC_SMC 0x13
139 #define ESR_EC_IABT 0x20
140 #define ESR_EC_IABT_HYP 0x21
141 #define ESR_EC_PCALIGN 0x22
142 #define ESR_EC_DABT 0x24
143 #define ESR_EC_DABT_HYP 0x25
145 #define ESR_ICC_CV_BIT (1 << 24)
146 #define ESR_ICC_COND(icc) ((icc) >> 20 & 0xf)
148 #define EXIT_REASON_UNDEF 0x1
149 #define EXIT_REASON_HVC 0x2
150 #define EXIT_REASON_PABT 0x3
151 #define EXIT_REASON_DABT 0x4
152 #define EXIT_REASON_TRAP 0x5
153 #define EXIT_REASON_IRQ 0x6
154 #define EXIT_REASON_FIQ 0x7
156 #define NUM_USR_REGS 14
161 unsigned long exit_reason;
162 /* r0 - r12 and lr. The other registers are banked. */
163 unsigned long usr[NUM_USR_REGS];
166 #define dmb(domain) asm volatile("dmb " #domain ::: "memory")
167 #define dsb(domain) asm volatile("dsb " #domain ::: "memory")
168 #define isb() asm volatile("isb")
170 #define wfe() asm volatile("wfe")
171 #define wfi() asm volatile("wfi")
172 #define sev() asm volatile("sev")
174 unsigned int smc(unsigned int r0, ...);
175 unsigned int hvc(unsigned int r0, ...);
177 static inline void cpu_relax(void)
179 asm volatile("" : : : "memory");
182 static inline void memory_barrier(void)
187 static inline void memory_load_barrier(void)
191 static inline bool is_el2(void)
195 asm volatile ("mrs %0, cpsr" : "=r" (psr));
197 return (psr & PSR_MODE_MASK) == PSR_HYP_MODE;
200 #endif /* !__ASSEMBLY__ */
202 #endif /* !_JAILHOUSE_ASM_PROCESSOR_H */