* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: vdev_intr.s
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
.ident "@(#)vdev_intr.s 1.13 07/05/03 SMI"
#include <sys/asm_linkage.h>
#include <sparcv9/misc.h>
#error "vdev_mapreg not properly sized (power of two)"
* vdev_init - initialize a guest's vdev state structure
* %i0 - &root, Config root data
/* XXX? get ign from CONFIG + CONFIG_VINTR, save */
GUEST2VDEVSTATE(%g1, %g2)
/* XXX initialize vinobase */
setx VDEV_STATE_VINOBASE, %g4, %g3
* All validity checks on config pa and dev ino have been
* performed before we get here. Just create the vino and
SET_SIZE(vdev_devino2vino)
* ret1 intr valid state (%o1)
ENTRY(vdev_intr_getvalid)
GUEST2VDEVSTATE(%g2, %g1)
!! %g1 = &guestp->vdev_state
VINO2MAPREG(%g1, %o0, %g2)
ldub [%g2 + MAPREG_VALID], %o1
SET_SIZE(vdev_intr_getvalid)
* arg1 intr valid state (%o1) 1: Valid 0: Invalid
ENTRY(vdev_intr_setvalid)
GUEST2VDEVSTATE(%g2, %g1)
!! %g1 = &guestp->vdev_state
VINO2MAPREG(%g1, %o0, %g2)
* XXX Initialize data0 here for now
stx %o0, [%g2 + MAPREG_DATA0]
! PRINT("vdev_intr_setvalid mapreg 0x")
stb %g3, [%g2 + MAPREG_INO]
* Fill in new valid status
stb %o1, [%g2 + MAPREG_VALID]
* If !vmapreg.v then skip interrupt generation
* Check for state IDLE, skip generating interrupt
ldub [%g2 + MAPREG_STATE], %g5
* Invoke driver's getstate callback if registered
mov %g2, %o0 ! Save vdev_mapregp
ldx [%o0 + MAPREG_GETSTATE], %g2
ldx [%o0 + MAPREG_DEVCOOKIE], %g1
jmp %g2 ! getstate_callback(cookie)
brnz,pt %g2, vdev_intr_generate
SET_SIZE(vdev_intr_setvalid)
ENTRY(vdev_intr_settarget)
VCPUID2CPUP(%g1, %o1, %g3, herr_nocpu, %g4)
VCPU2STRAND_STRUCT(%g3, %g3)
ldub [%g3 + STRAND_ID], %g3
GUEST2VDEVSTATE(%g1, %g4)
!! %g4 = &guestp->vdev_state
VINO2MAPREG(%g4, %o0, %g2)
sth %g3, [%g2 + MAPREG_PCPU]
sth %o1, [%g2 + MAPREG_VCPU]
SET_SIZE(vdev_intr_settarget)
ENTRY(vdev_intr_gettarget)
GUEST2VDEVSTATE(%g2, %g1)
!! %g1 = &guestp->vdev_state
VINO2MAPREG(%g1, %o0, %g2)
lduh [%g2 + MAPREG_VCPU], %o1
SET_SIZE(vdev_intr_gettarget)
ENTRY(vdev_intr_getstate)
GUEST2VDEVSTATE(%g2, %g1)
!! %g1 = &guestp->vdev_state
VINO2MAPREG(%g1, %o0, %g6)
ldub [%g6 + MAPREG_STATE], %o1
ldx [%g6 + MAPREG_GETSTATE], %g2
ldx [%g6 + MAPREG_DEVCOOKIE], %g1
jmp %g2 ! getstate_callback(cookie)
SET_SIZE(vdev_intr_getstate)
ENTRY(vdev_intr_setstate)
!! %g1 = &guestp->vdev_state
VINO2MAPREG(%g1, %o0, %g6)
/* Store new state, only check current state if the new state is IDLE */
stb %o1, [%g6 + MAPREG_STATE]
ldx [%g6 + MAPREG_SETSTATE], %g3
ldx [%g6 + MAPREG_DEVCOOKIE], %g1
jmp %g3 ! setstate_callback(cookie,new-state)
/* Call getstate callback */
ldx [%g6 + MAPREG_GETSTATE], %g2
ldx [%g6 + MAPREG_DEVCOOKIE], %g1
jmp %g2 ! getstate_callback(cookie)
brnz,pn %g2, vdev_intr_generate ! vdev_intr_generate(mapreg, state)
SET_SIZE(vdev_intr_setstate)
* vdev_intr_register - internal routine to allow drivers to register
* virtual interrupts. The driver provides a callback routine that
* returns the current "level" of its virtual interrupt pin. The callback
* routine is passed the driver's cookie in %g1 when it is invoked and is
* expected to return 0 or non-zero for the pin state.
* %g3 - driver's cookie (pointer to state structure, etc)
* %g4 - driver's getstate() callback address
* %g5 - driver's setstate() callback address
* %g1 - virtual interrupt handle (used by vdev_intr_generate)
ENTRY(vdev_intr_register)
GUEST2VDEVSTATE(%g6, %g1)
!! %g1 = vdev state pointer for the appropriate guest
VINO2MAPREG(%g1, %g2, %g6)
stx %g3, [%g6 + MAPREG_DEVCOOKIE]
stx %g4, [%g6 + MAPREG_GETSTATE]
stx %g5, [%g6 + MAPREG_SETSTATE]
setx VDEV_STATE_VINOBASE, %g4, %g5
stx %g5, [%g6 + MAPREG_DATA0]
mov %g6, %g1 ! return vdev_mapregp
SET_SIZE(vdev_intr_register)
* Wrapper around vdev_intr_register, so it can be called from C
* SPARC ABI requries only that g2,g3,g4 are preserved across
* %o2 = &config.maus[mau-id]
* %o3 = mau_intr_getstate
* %o4 = mau_intr_setstate
* void c_vdev_intr_register(strand_t targetp, hvm_t *msgp)
ENTRY(c_vdev_intr_register)
STRAND_PUSH(%g2, %g6, %g7)
STRAND_PUSH(%g3, %g6, %g7)
STRAND_PUSH(%g4, %g6, %g7)
HVCALL(vdev_intr_register)
SET_SIZE(c_vdev_intr_register)
* vdev_intr_generate - generate a virtual interrupt.
* %g1 - virtual interrupt handle
/* FIXME: need to handle case of more than one vcpu per strand */
ENTRY(vdev_intr_generate)
ldub [%g1 + MAPREG_VALID], %g2
ldub [%g1 + MAPREG_STATE], %g3
lduh [%g1 + MAPREG_PCPU], %g2
* Generate an interrupt if state is IDLE.
* Deliver locally if the current cpu is the same as the
PID2VCPUP(%g2, %g3, %g4, %g5)
* Update interrupt state to INTR_DELIVERED
stb %g2, [%g1 + MAPREG_STATE]
ldx [%g4 + MAPREG_DATA0], %g3
ba send_dev_mondo /* Returns to caller */
SET_SIZE(vdev_intr_generate)
* vdev_intr_redistribution
* Need to invalidate all of the virtual intrs that are
* mapped to the cpu passed in %g1
ENTRY_NP(vdev_intr_redistribution)
mov (NINOSPERDEV -1), %g3
! get this vino's cpu target
GUEST2VDEVSTATE(%g4, %g6)
!! %g6 = &guestp->vdev_state
VINO2MAPREG(%g6, %g3, %g5)
lduh [%g5 + MAPREG_PCPU], %g6
! compare with this cpu, if match, set to idle
bne,pt %xcc, .vdev_intr_redis_continue
* Fill in the Invalid status
mov INTR_DISABLED, %g6 ! Invalid
stb %g6, [%g5 + MAPREG_VALID]
.vdev_intr_redis_continue:
bgeu,pt %xcc, .vdev_intr_redis_loop
SET_SIZE(vdev_intr_redistribution)