Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / hypervisor / src / greatlakes / common / src / hvctl.s
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* Hypervisor Software File: hvctl.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 "@(#)hvctl.s 1.5 07/05/03 SMI"
50
51/*
52 * Hypervisor control interface
53 */
54
55#include <config.h>
56#include <offsets.h>
57#include <hvctl.h>
58#include <vdev_intr.h>
59#include <guest.h>
60#include <strand.h>
61#include <vcpu.h>
62#include <abort.h>
63#include <util.h>
64#include <ldc.h>
65#include <debug.h>
66#include <sys/asm_linkage.h>
67#include <sys/htypes.h>
68#include <sparcv9/asi.h>
69#include <asi.h>
70#include <sun4v/queue.h>
71
72/* FIXME: fix the files where these #defs to be visible */
73#define IVDR_THREAD 8 /* XXX */
74
75
76/*
77 * callback for hv control
78 *
79 * %g1 = callback arg (config struct)
80 * %g2 = payload
81 * %g3 = size
82 * %g7 = return address
83 */
84 ENTRY_NP(hvctl_svc_callback)
85
86#define HVLDC_RD_IDATA(pload, conf, idx, tmp) \
87 ldx [pload + (idx*8)], tmp ;\
88 stx tmp, [conf + (CONFIG_HVCTL_IBUF+(idx*8))]
89
90 HVLDC_RD_IDATA(%g2, %g1, 0, %g3) ! load payload
91 HVLDC_RD_IDATA(%g2, %g1, 1, %g3)
92 HVLDC_RD_IDATA(%g2, %g1, 2, %g3)
93 HVLDC_RD_IDATA(%g2, %g1, 3, %g3)
94 HVLDC_RD_IDATA(%g2, %g1, 4, %g3)
95 HVLDC_RD_IDATA(%g2, %g1, 5, %g3)
96 HVLDC_RD_IDATA(%g2, %g1, 6, %g3)
97 HVLDC_RD_IDATA(%g2, %g1, 7, %g3)
98
99 STRAND_PUSH(%g7, %g2, %g3)
100
101 HVCALL(vcpu_state_save)
102
103 ! TODO: verify checksum match, drop packet on mismatch
104
105 !
106 ! zero reply buffer
107 !
108 ROOT_STRUCT(%g1)
109 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 0]
110 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 8]
111 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 16]
112 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 24]
113 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 32]
114 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 40]
115 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 48]
116 stx %g0, [%g1 + CONFIG_HVCTL_OBUF + 56]
117
118 wrpr %g0, 0, %tl
119 wrpr %g0, 0, %gl
120 HVCALL(setup_c_environ)
121 call hv_control_pkt
122 nop
123
124.try_again:
125 CONFIG_STRUCT(%g3)
126 add %g3, CONFIG_HVCTL_OBUF, %g2
127 ldx [%g3 + CONFIG_HVCTL_LDC], %g1
128
129 add %g3, CONFIG_HVCTL_LDC_LOCK, %g7
130 SPINLOCK_ENTER(%g7, %g4, %g5)
131
132 ! call hv_ldc_send_pkt(hvldc_idx, bufptr)
133 HVCALL(hv_ldc_send_pkt)
134
135 CONFIG_STRUCT(%g3)
136 add %g3, CONFIG_HVCTL_LDC_LOCK, %g7
137 SPINLOCK_EXIT(%g7)
138
139 ! Busy wait if can't deliver ...
140 ! FIXME: need a send queue instead.
141 cmp %g1, EWOULDBLOCK
142 be,pn %xcc, .try_again
143 cmp %g1, ETOOMANY
144 be,pn %xcc, .try_again
145 nop
146
147 HVCALL(vcpu_state_restore)
148
149 STRAND_POP(%g7, %g2)
150
151 HVRET
152 SET_SIZE(hvctl_svc_callback)