xref: /linux/arch/hexagon/include/asm/hexagon_vm.h (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Declarations for to Hexagon Virtal Machine.
4  *
5  * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
6  */
7 
8 #ifndef ASM_HEXAGON_VM_H
9 #define ASM_HEXAGON_VM_H
10 
11 /*
12  * In principle, a Linux kernel for the VM could
13  * selectively define the virtual instructions
14  * as inline assembler macros, but for a first pass,
15  * we'll use subroutines for both the VM and the native
16  * kernels.  It's costing a subroutine call/return,
17  * but it makes for a single set of entry points
18  * for tracing/debugging.
19  */
20 
21 #define HVM_TRAP1_VMVERSION		0
22 #define HVM_TRAP1_VMRTE			1
23 #define HVM_TRAP1_VMSETVEC		2
24 #define HVM_TRAP1_VMSETIE		3
25 #define HVM_TRAP1_VMGETIE		4
26 #define HVM_TRAP1_VMINTOP		5
27 #define HVM_TRAP1_VMCLRMAP		10
28 #define HVM_TRAP1_VMNEWMAP		11
29 #define HVM_TRAP1_FORMERLY_VMWIRE	12
30 #define HVM_TRAP1_VMCACHE		13
31 #define HVM_TRAP1_VMGETTIME		14
32 #define HVM_TRAP1_VMSETTIME		15
33 #define HVM_TRAP1_VMWAIT		16
34 #define HVM_TRAP1_VMYIELD		17
35 #define HVM_TRAP1_VMSTART		18
36 #define HVM_TRAP1_VMSTOP		19
37 #define HVM_TRAP1_VMVPID		20
38 #define HVM_TRAP1_VMSETREGS		21
39 #define HVM_TRAP1_VMGETREGS		22
40 #define HVM_TRAP1_VMTIMEROP		24
41 
42 #ifndef __ASSEMBLY__
43 
44 enum VM_CACHE_OPS {
45 	hvmc_ickill,
46 	hvmc_dckill,
47 	hvmc_l2kill,
48 	hvmc_dccleaninva,
49 	hvmc_icinva,
50 	hvmc_idsync,
51 	hvmc_fetch_cfg
52 };
53 
54 enum VM_INT_OPS {
55 	hvmi_nop,
56 	hvmi_globen,
57 	hvmi_globdis,
58 	hvmi_locen,
59 	hvmi_locdis,
60 	hvmi_affinity,
61 	hvmi_get,
62 	hvmi_peek,
63 	hvmi_status,
64 	hvmi_post,
65 	hvmi_clear
66 };
67 
68 extern void _K_VM_event_vector(void);
69 
70 void __vmrte(void);
71 long __vmsetvec(void *);
72 long __vmsetie(long);
73 long __vmgetie(void);
74 long __vmintop(enum VM_INT_OPS, long, long, long, long);
75 long __vmclrmap(void *, unsigned long);
76 long __vmnewmap(void *);
77 long __vmcache(enum VM_CACHE_OPS op, unsigned long addr, unsigned long len);
78 unsigned long long __vmgettime(void);
79 long __vmsettime(unsigned long long);
80 long __vmstart(void *, void *);
81 void __vmstop(void);
82 long __vmwait(void);
83 void __vmyield(void);
84 long __vmvpid(void);
85 
86 static inline long __vmcache_ickill(void)
87 {
88 	return __vmcache(hvmc_ickill, 0, 0);
89 }
90 
91 static inline long __vmcache_dckill(void)
92 {
93 	return __vmcache(hvmc_dckill, 0, 0);
94 }
95 
96 static inline long __vmcache_l2kill(void)
97 {
98 	return __vmcache(hvmc_l2kill, 0, 0);
99 }
100 
101 static inline long __vmcache_dccleaninva(unsigned long addr, unsigned long len)
102 {
103 	return __vmcache(hvmc_dccleaninva, addr, len);
104 }
105 
106 static inline long __vmcache_icinva(unsigned long addr, unsigned long len)
107 {
108 	return __vmcache(hvmc_icinva, addr, len);
109 }
110 
111 static inline long __vmcache_idsync(unsigned long addr,
112 					   unsigned long len)
113 {
114 	return __vmcache(hvmc_idsync, addr, len);
115 }
116 
117 static inline long __vmcache_fetch_cfg(unsigned long val)
118 {
119 	return __vmcache(hvmc_fetch_cfg, val, 0);
120 }
121 
122 /* interrupt operations  */
123 
124 static inline long __vmintop_nop(void)
125 {
126 	return __vmintop(hvmi_nop, 0, 0, 0, 0);
127 }
128 
129 static inline long __vmintop_globen(long i)
130 {
131 	return __vmintop(hvmi_globen, i, 0, 0, 0);
132 }
133 
134 static inline long __vmintop_globdis(long i)
135 {
136 	return __vmintop(hvmi_globdis, i, 0, 0, 0);
137 }
138 
139 static inline long __vmintop_locen(long i)
140 {
141 	return __vmintop(hvmi_locen, i, 0, 0, 0);
142 }
143 
144 static inline long __vmintop_locdis(long i)
145 {
146 	return __vmintop(hvmi_locdis, i, 0, 0, 0);
147 }
148 
149 static inline long __vmintop_affinity(long i, long cpu)
150 {
151 	return __vmintop(hvmi_affinity, i, cpu, 0, 0);
152 }
153 
154 static inline long __vmintop_get(void)
155 {
156 	return __vmintop(hvmi_get, 0, 0, 0, 0);
157 }
158 
159 static inline long __vmintop_peek(void)
160 {
161 	return __vmintop(hvmi_peek, 0, 0, 0, 0);
162 }
163 
164 static inline long __vmintop_status(long i)
165 {
166 	return __vmintop(hvmi_status, i, 0, 0, 0);
167 }
168 
169 static inline long __vmintop_post(long i)
170 {
171 	return __vmintop(hvmi_post, i, 0, 0, 0);
172 }
173 
174 static inline long __vmintop_clear(long i)
175 {
176 	return __vmintop(hvmi_clear, i, 0, 0, 0);
177 }
178 
179 #else /* Only assembly code should reference these */
180 
181 #endif /* __ASSEMBLY__ */
182 
183 /*
184  * Constants for virtual instruction parameters and return values
185  */
186 
187 /* vmnewmap arguments */
188 
189 #define VM_TRANS_TYPE_LINEAR 0
190 #define VM_TRANS_TYPE_TABLE 1
191 #define VM_TLB_INVALIDATE_FALSE 0
192 #define VM_TLB_INVALIDATE_TRUE 1
193 
194 /* vmsetie arguments */
195 
196 #define VM_INT_DISABLE	0
197 #define VM_INT_ENABLE	1
198 
199 /* vmsetimask arguments */
200 
201 #define VM_INT_UNMASK	0
202 #define VM_INT_MASK	1
203 
204 #define VM_NEWMAP_TYPE_LINEAR	0
205 #define VM_NEWMAP_TYPE_PGTABLES	1
206 
207 
208 /*
209  * Event Record definitions useful to both C and Assembler
210  */
211 
212 /* VMEST Layout */
213 
214 #define HVM_VMEST_UM_SFT	31
215 #define HVM_VMEST_UM_MSK	1
216 #define HVM_VMEST_IE_SFT	30
217 #define HVM_VMEST_IE_MSK	1
218 #define HVM_VMEST_SS_SFT	29
219 #define HVM_VMEST_SS_MSK	1
220 #define HVM_VMEST_EVENTNUM_SFT	16
221 #define HVM_VMEST_EVENTNUM_MSK	0xff
222 #define HVM_VMEST_CAUSE_SFT	0
223 #define HVM_VMEST_CAUSE_MSK	0xffff
224 
225 /*
226  * The initial program gets to find a system environment descriptor
227  * on its stack when it begins execution. The first word is a version
228  * code to indicate what is there.  Zero means nothing more.
229  */
230 
231 #define HEXAGON_VM_SED_NULL	0
232 
233 /*
234  * Event numbers for vector binding
235  */
236 
237 #define HVM_EV_RESET		0
238 #define HVM_EV_MACHCHECK	1
239 #define HVM_EV_GENEX		2
240 #define HVM_EV_TRAP		8
241 #define HVM_EV_INTR		15
242 /* These shoud be nuked as soon as we know the VM is up to spec v0.1.1 */
243 #define HVM_EV_INTR_0		16
244 #define HVM_MAX_INTR		240
245 
246 /*
247  * Cause values for General Exception
248  */
249 
250 #define HVM_GE_C_BUS	0x01
251 #define HVM_GE_C_XPROT	0x11
252 #define HVM_GE_C_XUSER	0x14
253 #define HVM_GE_C_INVI	0x15
254 #define HVM_GE_C_PRIVI	0x1B
255 #define HVM_GE_C_XMAL	0x1C
256 #define HVM_GE_C_WREG	0x1D
257 #define HVM_GE_C_PCAL	0x1E
258 #define HVM_GE_C_RMAL	0x20
259 #define HVM_GE_C_WMAL	0x21
260 #define HVM_GE_C_RPROT	0x22
261 #define HVM_GE_C_WPROT	0x23
262 #define HVM_GE_C_RUSER	0x24
263 #define HVM_GE_C_WUSER	0x25
264 #define HVM_GE_C_CACHE	0x28
265 
266 /*
267  * Cause codes for Machine Check
268  */
269 
270 #define	HVM_MCHK_C_DOWN		0x00
271 #define	HVM_MCHK_C_BADSP	0x01
272 #define	HVM_MCHK_C_BADEX	0x02
273 #define	HVM_MCHK_C_BADPT	0x03
274 #define	HVM_MCHK_C_REGWR	0x29
275 
276 #endif
277