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