Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * Hypervisor Software File: vdev_intr.s | |
5 | * | |
6 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
7 | * | |
8 | * - Do no alter or remove copyright notices | |
9 | * | |
10 | * - Redistribution and use of this software in source and binary forms, with | |
11 | * or without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistribution of source code must retain the above copyright notice, | |
15 | * this list of conditions and the following disclaimer. | |
16 | * | |
17 | * - Redistribution in binary form must reproduce the above copyright notice, | |
18 | * this list of conditions and the following disclaimer in the | |
19 | * documentation and/or other materials provided with the distribution. | |
20 | * | |
21 | * Neither the name of Sun Microsystems, Inc. or the names of contributors | |
22 | * may be used to endorse or promote products derived from this software | |
23 | * without specific prior written permission. | |
24 | * | |
25 | * This software is provided "AS IS," without a warranty of any kind. | |
26 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
27 | * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
28 | * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
29 | * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
30 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
31 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
32 | * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
33 | * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
34 | * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
35 | * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
36 | * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
37 | * | |
38 | * You acknowledge that this software is not designed, licensed or | |
39 | * intended for use in the design, construction, operation or maintenance of | |
40 | * any nuclear facility. | |
41 | * | |
42 | * ========== Copyright Header End ============================================ | |
43 | */ | |
44 | /* | |
45 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
46 | * Use is subject to license terms. | |
47 | */ | |
48 | ||
49 | .ident "@(#)vdev_intr.s 1.13 07/05/03 SMI" | |
50 | ||
51 | #include <sys/asm_linkage.h> | |
52 | #include <sys/htypes.h> | |
53 | #include <hypervisor.h> | |
54 | #include <sparcv9/misc.h> | |
55 | #include <asi.h> | |
56 | #include <hprivregs.h> | |
57 | #include <sun4v/asi.h> | |
58 | #include <sun4v/intr.h> | |
59 | #include <abort.h> | |
60 | #include <strand.h> | |
61 | #include <offsets.h> | |
62 | #include <util.h> | |
63 | #include <debug.h> | |
64 | #include <vdev_intr.h> | |
65 | ||
66 | ||
67 | #ifndef MAPREG_SHIFT | |
68 | #error "vdev_mapreg not properly sized (power of two)" | |
69 | #endif | |
70 | ||
71 | ||
72 | /* | |
73 | * vdev_init - initialize a guest's vdev state structure | |
74 | * | |
75 | * %i0 - &root, Config root data | |
76 | * %g1 - guest | |
77 | * -- | |
78 | */ | |
79 | ENTRY(vdev_init) | |
80 | !! %g1 = guestp | |
81 | /* XXX? get ign from CONFIG + CONFIG_VINTR, save */ | |
82 | GUEST2VDEVSTATE(%g1, %g2) | |
83 | !! %g2 = vdevstatep | |
84 | ||
85 | /* XXX initialize vinobase */ | |
86 | setx VDEV_STATE_VINOBASE, %g4, %g3 | |
87 | add %g2, %g3, %g2 | |
88 | mov 0x100, %g3 | |
89 | sth %g3, [%g2] | |
90 | ||
91 | jmp %g7 + 4 | |
92 | nop | |
93 | SET_SIZE(vdev_init) | |
94 | ||
95 | ||
96 | /* | |
97 | * virtdevs_devino2vino | |
98 | * | |
99 | * arg0 dev config pa | |
100 | * arg1 dev ino | |
101 | * -- | |
102 | * ret0 status | |
103 | * ret1 virtual INO | |
104 | */ | |
105 | ENTRY(vdev_devino2vino) | |
106 | /* | |
107 | * All validity checks on config pa and dev ino have been | |
108 | * performed before we get here. Just create the vino and | |
109 | * and return. | |
110 | */ | |
111 | or %o0, %o1, %o1 | |
112 | HCALL_RET(EOK) | |
113 | SET_SIZE(vdev_devino2vino) | |
114 | ||
115 | /* | |
116 | * vdev_intr_getvalid | |
117 | * | |
118 | * %g1 vdev state pointer | |
119 | * arg0 Virtual INO (%o0) | |
120 | * -- | |
121 | * ret0 status (%o0) | |
122 | * ret1 intr valid state (%o1) | |
123 | */ | |
124 | ENTRY(vdev_intr_getvalid) | |
125 | GUEST_STRUCT(%g2) | |
126 | GUEST2VDEVSTATE(%g2, %g1) | |
127 | !! %g1 = &guestp->vdev_state | |
128 | VINO2MAPREG(%g1, %o0, %g2) | |
129 | !! %g2 = vdev_mapregp | |
130 | ldub [%g2 + MAPREG_VALID], %o1 | |
131 | HCALL_RET(EOK) | |
132 | SET_SIZE(vdev_intr_getvalid) | |
133 | ||
134 | /* | |
135 | * vdev_intr_setvalid | |
136 | * | |
137 | * %g1 vdev state pointer | |
138 | * arg0 Virtual INO (%o0) | |
139 | * arg1 intr valid state (%o1) 1: Valid 0: Invalid | |
140 | * -- | |
141 | * ret0 status (%o0) | |
142 | */ | |
143 | ENTRY(vdev_intr_setvalid) | |
144 | GUEST_STRUCT(%g2) | |
145 | GUEST2VDEVSTATE(%g2, %g1) | |
146 | !! %g1 = &guestp->vdev_state | |
147 | VINO2MAPREG(%g1, %o0, %g2) | |
148 | !! %g2 = vdev_mapregp | |
149 | ||
150 | /* | |
151 | * XXX Initialize data0 here for now | |
152 | */ | |
153 | stx %o0, [%g2 + MAPREG_DATA0] | |
154 | ||
155 | ! mov %g7, %g3 | |
156 | ! PRINT("vdev_intr_setvalid mapreg 0x") | |
157 | ! PRINTX(%g2) | |
158 | ! PRINT(" INO 0x") | |
159 | ! PRINTX(%o0) | |
160 | ! PRINT("\r\n") | |
161 | ! mov %g3, %g7 | |
162 | ||
163 | and %o0, DEVINOMASK, %g3 | |
164 | stb %g3, [%g2 + MAPREG_INO] | |
165 | ||
166 | /* | |
167 | * Fill in new valid status | |
168 | */ | |
169 | stb %o1, [%g2 + MAPREG_VALID] | |
170 | ||
171 | /* | |
172 | * If !vmapreg.v then skip interrupt generation | |
173 | */ | |
174 | brz,pn %o1, 1f | |
175 | nop | |
176 | ||
177 | /* | |
178 | * Check for state IDLE, skip generating interrupt | |
179 | * if not IDLE | |
180 | */ | |
181 | ldub [%g2 + MAPREG_STATE], %g5 | |
182 | cmp %g5, INTR_IDLE | |
183 | bne,pn %xcc, 1f | |
184 | nop | |
185 | ||
186 | /* | |
187 | * Invoke driver's getstate callback if registered | |
188 | */ | |
189 | mov %g2, %o0 ! Save vdev_mapregp | |
190 | ldx [%o0 + MAPREG_GETSTATE], %g2 | |
191 | brz,pn %g2, 1f | |
192 | ldx [%o0 + MAPREG_DEVCOOKIE], %g1 | |
193 | jmp %g2 ! getstate_callback(cookie) | |
194 | rd %pc, %g7 | |
195 | mov %g1, %g2 | |
196 | mov %o0, %g1 | |
197 | brnz,pt %g2, vdev_intr_generate | |
198 | rd %pc, %g7 | |
199 | ||
200 | 1: | |
201 | HCALL_RET(EOK) | |
202 | SET_SIZE(vdev_intr_setvalid) | |
203 | ||
204 | ||
205 | /* | |
206 | * vdev_intr_settarget | |
207 | * | |
208 | * %g1 vdev state pointer | |
209 | * arg0 Virtual INO (%o0) | |
210 | * arg1 cpuid (%o1) | |
211 | * -- | |
212 | * ret0 status (%o0) | |
213 | */ | |
214 | ENTRY(vdev_intr_settarget) | |
215 | GUEST_STRUCT(%g1) | |
216 | !! %g1 = guestp | |
217 | VCPUID2CPUP(%g1, %o1, %g3, herr_nocpu, %g4) | |
218 | !! %g3 = target cpup | |
219 | VCPU2STRAND_STRUCT(%g3, %g3) | |
220 | ldub [%g3 + STRAND_ID], %g3 | |
221 | !! %o0 = vino | |
222 | !! %o1 = target vcpuid | |
223 | !! %g3 = target pcpuid | |
224 | GUEST2VDEVSTATE(%g1, %g4) | |
225 | !! %g4 = &guestp->vdev_state | |
226 | VINO2MAPREG(%g4, %o0, %g2) | |
227 | !! %g2 = vdev_mapregp | |
228 | sth %g3, [%g2 + MAPREG_PCPU] | |
229 | sth %o1, [%g2 + MAPREG_VCPU] | |
230 | HCALL_RET(EOK) | |
231 | SET_SIZE(vdev_intr_settarget) | |
232 | ||
233 | ||
234 | /* | |
235 | * vdev_intr_gettarget | |
236 | * | |
237 | * %g1 vdev state pointer | |
238 | * arg0 Virtual INO (%o0) | |
239 | * -- | |
240 | * ret0 status (%o0) | |
241 | * ret1 target vcpu (%o1) | |
242 | */ | |
243 | ENTRY(vdev_intr_gettarget) | |
244 | GUEST_STRUCT(%g2) | |
245 | GUEST2VDEVSTATE(%g2, %g1) | |
246 | !! %g1 = &guestp->vdev_state | |
247 | VINO2MAPREG(%g1, %o0, %g2) | |
248 | !! %g2 = vdev_mapregp | |
249 | lduh [%g2 + MAPREG_VCPU], %o1 | |
250 | HCALL_RET(EOK) | |
251 | SET_SIZE(vdev_intr_gettarget) | |
252 | ||
253 | ||
254 | /* | |
255 | * vdev_intr_getstate | |
256 | * | |
257 | * %g1 vdev state pointer | |
258 | * arg0 Virtual INO (%o0) | |
259 | * -- | |
260 | * ret0 status (%o0) | |
261 | * ret1 intr state (%o1) | |
262 | */ | |
263 | ENTRY(vdev_intr_getstate) | |
264 | GUEST_STRUCT(%g2) | |
265 | GUEST2VDEVSTATE(%g2, %g1) | |
266 | !! %g1 = &guestp->vdev_state | |
267 | VINO2MAPREG(%g1, %o0, %g6) | |
268 | !! %g6 = mapreg | |
269 | ldub [%g6 + MAPREG_STATE], %o1 | |
270 | cmp %o1, INTR_RECEIVED | |
271 | be,pn %xcc, 1f | |
272 | nop | |
273 | ldx [%g6 + MAPREG_GETSTATE], %g2 | |
274 | brz,pn %g2, 1f | |
275 | ldx [%g6 + MAPREG_DEVCOOKIE], %g1 | |
276 | jmp %g2 ! getstate_callback(cookie) | |
277 | rd %pc, %g7 | |
278 | mov %g1, %o1 | |
279 | 1: | |
280 | HCALL_RET(EOK) | |
281 | SET_SIZE(vdev_intr_getstate) | |
282 | ||
283 | ||
284 | /* | |
285 | * vdev_intr_setstate | |
286 | * | |
287 | * %g1 vdev state pointer | |
288 | * arg0 vino (%o0) | |
289 | * arg1 new state (%o1) | |
290 | * -- | |
291 | * ret0 status (%o0) | |
292 | */ | |
293 | ENTRY(vdev_intr_setstate) | |
294 | GUEST_STRUCT(%g2) | |
295 | GUEST2VDEVSTATE(%g2,%g1) | |
296 | !! %g1 = &guestp->vdev_state | |
297 | VINO2MAPREG(%g1, %o0, %g6) | |
298 | !! %g6 = vdev_mapregp | |
299 | ||
300 | /* Store new state, only check current state if the new state is IDLE */ | |
301 | stb %o1, [%g6 + MAPREG_STATE] | |
302 | ||
303 | ldx [%g6 + MAPREG_SETSTATE], %g3 | |
304 | brz,pn %g3, 1f | |
305 | mov %o1, %g2 | |
306 | ldx [%g6 + MAPREG_DEVCOOKIE], %g1 | |
307 | mov %g6, %o5 ! XXX | |
308 | jmp %g3 ! setstate_callback(cookie,new-state) | |
309 | rd %pc, %g7 | |
310 | mov %o5, %g6 | |
311 | 1: | |
312 | cmp %o1, INTR_IDLE | |
313 | bne,pn %xcc, 2f | |
314 | /* Call getstate callback */ | |
315 | ldx [%g6 + MAPREG_GETSTATE], %g2 | |
316 | brz,pn %g2, 2f | |
317 | ldx [%g6 + MAPREG_DEVCOOKIE], %g1 | |
318 | mov %g6, %o5 ! XXX | |
319 | jmp %g2 ! getstate_callback(cookie) | |
320 | rd %pc, %g7 | |
321 | mov %g1, %g2 | |
322 | !! %g2 getstate result | |
323 | mov %o5, %g1 | |
324 | brnz,pn %g2, vdev_intr_generate ! vdev_intr_generate(mapreg, state) | |
325 | rd %pc, %g7 | |
326 | 2: | |
327 | HCALL_RET(EOK) | |
328 | SET_SIZE(vdev_intr_setstate) | |
329 | ||
330 | ||
331 | /* | |
332 | * vdev_intr_register - internal routine to allow drivers to register | |
333 | * virtual interrupts. The driver provides a callback routine that | |
334 | * returns the current "level" of its virtual interrupt pin. The callback | |
335 | * routine is passed the driver's cookie in %g1 when it is invoked and is | |
336 | * expected to return 0 or non-zero for the pin state. | |
337 | * | |
338 | * %i0 - global config | |
339 | * %g1 - guest | |
340 | * %g2 - ino | |
341 | * %g3 - driver's cookie (pointer to state structure, etc) | |
342 | * %g4 - driver's getstate() callback address | |
343 | * %g5 - driver's setstate() callback address | |
344 | * %g7 - return address | |
345 | * -- | |
346 | * %g1 - virtual interrupt handle (used by vdev_intr_generate) | |
347 | */ | |
348 | ENTRY(vdev_intr_register) | |
349 | mov %g1, %g6 | |
350 | GUEST2VDEVSTATE(%g6, %g1) | |
351 | !! %g1 = vdev state pointer for the appropriate guest | |
352 | cmp %g2, NINOSPERDEV | |
353 | bgeu,a,pn %xcc, 1f | |
354 | mov 0, %g1 | |
355 | VINO2MAPREG(%g1, %g2, %g6) | |
356 | !! %g6 = vdev_mapregp | |
357 | ||
358 | stx %g3, [%g6 + MAPREG_DEVCOOKIE] | |
359 | stx %g4, [%g6 + MAPREG_GETSTATE] | |
360 | stx %g5, [%g6 + MAPREG_SETSTATE] | |
361 | ||
362 | setx VDEV_STATE_VINOBASE, %g4, %g5 | |
363 | lduh [%g1 + %g5], %g5 | |
364 | add %g5, %g2, %g5 | |
365 | !! %g5 vino | |
366 | stx %g5, [%g6 + MAPREG_DATA0] | |
367 | mov %g6, %g1 ! return vdev_mapregp | |
368 | ||
369 | 1: jmp %g7 + 4 | |
370 | nop | |
371 | SET_SIZE(vdev_intr_register) | |
372 | ||
373 | /* | |
374 | * Wrapper around vdev_intr_register, so it can be called from C | |
375 | * SPARC ABI requries only that g2,g3,g4 are preserved across | |
376 | * function calls. | |
377 | * %o0 = guestp | |
378 | * %o1 = ino | |
379 | * %o2 = &config.maus[mau-id] | |
380 | * %o3 = mau_intr_getstate | |
381 | * %o4 = mau_intr_setstate | |
382 | * | |
383 | * Returns cookie in %o0 | |
384 | * | |
385 | * void c_vdev_intr_register(strand_t targetp, hvm_t *msgp) | |
386 | */ | |
387 | ||
388 | ENTRY(c_vdev_intr_register) | |
389 | ||
390 | STRAND_PUSH(%g2, %g6, %g7) | |
391 | STRAND_PUSH(%g3, %g6, %g7) | |
392 | STRAND_PUSH(%g4, %g6, %g7) | |
393 | ||
394 | mov %o0, %g1 | |
395 | mov %o1, %g2 | |
396 | mov %o2, %g3 | |
397 | mov %o3, %g4 | |
398 | mov %o4, %g5 | |
399 | HVCALL(vdev_intr_register) | |
400 | mov %g1, %o0 | |
401 | ||
402 | STRAND_POP(%g4, %g6) | |
403 | STRAND_POP(%g3, %g6) | |
404 | STRAND_POP(%g2, %g6) | |
405 | ||
406 | retl | |
407 | nop | |
408 | SET_SIZE(c_vdev_intr_register) | |
409 | ||
410 | ||
411 | /* | |
412 | * vdev_intr_generate - generate a virtual interrupt. | |
413 | * | |
414 | * %g1 - virtual interrupt handle | |
415 | * %g7 - return address | |
416 | * -- | |
417 | * | |
418 | * Clobbers: | |
419 | */ | |
420 | ||
421 | /* FIXME: need to handle case of more than one vcpu per strand */ | |
422 | ||
423 | ENTRY(vdev_intr_generate) | |
424 | ldub [%g1 + MAPREG_VALID], %g2 | |
425 | ldub [%g1 + MAPREG_STATE], %g3 | |
426 | brz,pn %g2, 1f | |
427 | lduh [%g1 + MAPREG_PCPU], %g2 | |
428 | !! %g2 target pcpuid | |
429 | !! %g3 state | |
430 | ||
431 | /* | |
432 | * Generate an interrupt if state is IDLE. | |
433 | * Deliver locally if the current cpu is the same as the | |
434 | * target. | |
435 | */ | |
436 | cmp %g3, INTR_IDLE | |
437 | bne,pn %xcc, 1f | |
438 | .empty | |
439 | ||
440 | !! %g1 = vmapreg | |
441 | !! %g2 = target pcpuid | |
442 | PID2VCPUP(%g2, %g3, %g4, %g5) | |
443 | !! %g3 target cpup | |
444 | /* | |
445 | * Update interrupt state to INTR_DELIVERED | |
446 | */ | |
447 | mov INTR_DELIVERED, %g2 | |
448 | stb %g2, [%g1 + MAPREG_STATE] | |
449 | ||
450 | mov %g1, %g4 | |
451 | mov %g3, %g1 | |
452 | ldx [%g4 + MAPREG_DATA0], %g3 | |
453 | ||
454 | ba send_dev_mondo /* Returns to caller */ | |
455 | mov 1 , %g2 | |
456 | ||
457 | 1: HVRET | |
458 | SET_SIZE(vdev_intr_generate) | |
459 | ||
460 | /* | |
461 | * vdev_intr_redistribution | |
462 | * | |
463 | * Need to invalidate all of the virtual intrs that are | |
464 | * mapped to the cpu passed in %g1 | |
465 | * | |
466 | * %g1 - this cpu id | |
467 | * %g2 - tgt cpu id | |
468 | */ | |
469 | ENTRY_NP(vdev_intr_redistribution) | |
470 | GUEST_STRUCT(%g4) | |
471 | ||
472 | mov (NINOSPERDEV -1), %g3 | |
473 | .vdev_intr_redis_loop: | |
474 | !! %g3 - vino | |
475 | !! %g4 - guest | |
476 | ! get this vino's cpu target | |
477 | GUEST2VDEVSTATE(%g4, %g6) | |
478 | !! %g6 = &guestp->vdev_state | |
479 | VINO2MAPREG(%g6, %g3, %g5) | |
480 | !! %g5 = vdev_mapregp | |
481 | lduh [%g5 + MAPREG_PCPU], %g6 | |
482 | ||
483 | !! %g1 - cpuid | |
484 | !! %g6 - vino's cpuid | |
485 | ! compare with this cpu, if match, set to idle | |
486 | cmp %g1, %g6 | |
487 | bne,pt %xcc, .vdev_intr_redis_continue | |
488 | nop | |
489 | ||
490 | /* | |
491 | * Fill in the Invalid status | |
492 | */ | |
493 | mov INTR_DISABLED, %g6 ! Invalid | |
494 | stb %g6, [%g5 + MAPREG_VALID] | |
495 | ||
496 | .vdev_intr_redis_continue: | |
497 | deccc %g3 | |
498 | bgeu,pt %xcc, .vdev_intr_redis_loop | |
499 | nop | |
500 | ||
501 | .vdev_redis_done: | |
502 | ||
503 | HVRET | |
504 | SET_SIZE(vdev_intr_redistribution) |