Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / hypervisor / src / common / src / hcall_soft_state.s
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* Hypervisor Software File: hcall_soft_state.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 "@(#)hcall_soft_state.s 1.97 07/04/18 SMI"
50
51#include <sys/asm_linkage.h>
52#include <asi.h>
53#include <guest.h>
54#include <offsets.h>
55#include <util.h>
56
57/*
58 * soft_state_set - Set guest's soft state
59 *
60 * arg0 software state (%o0)
61 * arg1 software state description pointer (%o1)
62 * --
63 * ret0 error code (%o0)
64 */
65 ENTRY_NP(hcall_soft_state_set)
66 GUEST_STRUCT(%g6) ! %g6 = guestp
67
68 ! check for valid software state
69 ! must be one of SIS_NORMAL or SIS_TRANSITION
70 cmp %o0, SIS_NORMAL
71 be,pn %xcc, 1f
72 cmp %o0, SIS_TRANSITION
73 bne,pn %xcc, herr_inval
74 nop
751:
76 ! check that the software state description is aligned and
77 ! contained in guest mmeory
78 btst SOFT_STATE_ALIGNMENT - 1, %o1
79 bnz,pn %xcc, herr_badalign
80 nop
81
82 ! RA2PA_RANGE_CONV(guestp, raddr, size, fail_label, segp, paddr)
83
84 mov %o1, %g3
85 RA2PA_RANGE_CONV(%g6, %g3, SOFT_STATE_SIZE, herr_noraddr, %g2, %o1)
86
87 ! check for NUL termination of software state description
88 mov %o1, %g1 ! %g1 is buffer pointer
89 mov SOFT_STATE_SIZE, %g4 ! %g4 is loop counter
902:
91 ldub [%g1], %g5
92 brz,pn %g5, 1f ! found NUL
93 dec %g4
94 brnz,pt %g4, 2b
95 inc %g1 ! check next char
96 ba herr_inval ! missing NUL
97 nop
981:
99 ! get here when arguments are valid
100 ! acquire the guest's asynchronous soft state lock
101 set GUEST_ASYNC_LOCK, %g5
102 add %g5, (ENUM_HVctl_info_guest_soft_state * 8), %g5
103 add %g6, %g5, %g7
104 SPINLOCK_ENTER(%g7, %g2, %g5)
105
106 ! save software state in guest structure
107 stb %o0, [%g6 + GUEST_SOFT_STATE]
108
109 ! zero out end of software state description in guest structure
110 sub %g1, %o1, %g3 ! %g3 = index of NUL char
111 add %g6, GUEST_SOFT_STATE_STR, %g1
112 add %g1, %g3, %g1 ! bzero destination
113 add %g4, 1, %g2 ! bzero size (accounting for dec in delay slot)
114 HVCALL(bzero)
115
116 ! copy software state description (up to NUL) into guest structure
117 mov %o1, %g1 ! bcopy source
118 add %g6, GUEST_SOFT_STATE_STR, %g2 ! bcopy destination
119 ! %g3 already set up bcopy size
120 HVCALL(bcopy)
121
122 ! check if async notification for soft state is busy or not
123 set GUEST_ASYNC_BUSY, %g5
124 add %g6, %g5, %g3 ! %g3 = base of busy flags array
125 ldub [%g3 + ENUM_HVctl_info_guest_soft_state], %g1
126 brnz,pn %g1, 1f
127 ! not busy, set busy flag and send asynchronous notification
128 mov 1, %g1
129 stub %g1, [%g3 + ENUM_HVctl_info_guest_soft_state]
130 set GUEST_ASYNC_BUF, %g5
131 add %g6, %g5, %g3
132 add %g3, HVCTL_MSG_MSG, %g3 ! %g3 = base of hvctl msg field
133 ! zero out data part of message
134 add %g3, HVCTL_RES_STATUS_DATA, %g1
135 set HVCTL_RES_STATUS_DATA_SIZE, %g2
136 HVCALL(bzero)
137 ! fill in message fields
138 set ENUM_HVctl_res_guest, %g5
139 stuw %g5, [%g3 + HVCTL_RES_STATUS_RES] ! resource type
140 ldx [%g6 + GUEST_GID], %g5
141 stuw %g5, [%g3 + HVCTL_RES_STATUS_RESID] ! resource id
142 set ENUM_HVctl_info_guest_soft_state, %g5
143 stuw %g5, [%g3 + HVCTL_RES_STATUS_INFOID] ! info id
144 ! code field is initialized to zero in init_guest() and never changed
145 ! fill in the info specific data, i.e. the soft state
146 add %g3, HVCTL_RES_STATUS_DATA, %g3 ! g3 = base of data field
147 stub %o0, [%g3 + RS_GUEST_SOFT_STATE]
148 add %g6, GUEST_SOFT_STATE_STR, %g1
149 add %g3, RS_GUEST_SOFT_STATE_STR, %g2
150 set SOFT_STATE_SIZE, %g3
151 HVCALL(bcopy)
152 ! send the message
153 CONFIG_STRUCT(%g3)
154 ldx [%g3 + CONFIG_HVCTL_LDC], %g1
155 set GUEST_ASYNC_BUF, %g5
156 add %g6, %g5, %g2
157 add %g3, CONFIG_HVCTL_LDC_LOCK, %g7
158 SPINLOCK_ENTER(%g7, %g4, %g5)
159 HVCALL(hv_ldc_send_pkt)
160 CONFIG_STRUCT(%g3)
161 add %g3, CONFIG_HVCTL_LDC_LOCK, %g7
162 SPINLOCK_EXIT(%g7)
163 GUEST_STRUCT(%g6) ! restore %g6 = guestp
1641:
165 ! release guest's asynchronous notification lock
166 set GUEST_ASYNC_LOCK, %g5
167 add %g5, (ENUM_HVctl_info_guest_soft_state * 8), %g5
168 add %g6, %g5, %g7
169 SPINLOCK_EXIT(%g7)
170
171 HCALL_RET(EOK)
172 SET_SIZE(hcall_soft_state_set)
173
174/*
175 * soft_state_get - Get guest's soft state
176 *
177 * arg0 software state description pointer (%o0)
178 * --
179 * ret0 error code (%o0)
180 * ret1 software state (%o1)
181 */
182 ENTRY_NP(hcall_soft_state_get)
183 GUEST_STRUCT(%g6)
184
185 ! check that software state description is aligned and
186 ! contained in guest mmeory
187 btst SOFT_STATE_ALIGNMENT - 1, %o0
188 bnz,pn %xcc, herr_badalign
189 nop
190
191 ! RA2PA_RANGE_CONV(guestp, raddr, size, fail_label, segp, paddr)
192
193 RA2PA_RANGE_CONV(%g6, %o0, SOFT_STATE_SIZE, herr_noraddr, %g1, %g2)
194
195 set GUEST_ASYNC_LOCK, %g1
196 add %g1, (ENUM_HVctl_info_guest_soft_state * 8), %g1
197 add %g6, %g1, %g5
198 SPINLOCK_ENTER(%g5, %g1, %g3)
199
200 ! copy software state description from guest structure
201 !! %g2 bcopy destination
202
203 add %g6, GUEST_SOFT_STATE_STR, %g1 ! bcopy source
204 mov SOFT_STATE_SIZE, %g3 ! bcopy size
205 HVCALL(bcopy)
206
207 ! set software state return value
208 ldub [%g6 + GUEST_SOFT_STATE], %o1
209
210 SPINLOCK_EXIT(%g5)
211
212 HCALL_RET(EOK)
213 SET_SIZE(hcall_soft_state_get)