Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / asr-ds / asr-ds.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: asr-ds.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)asr-ds.fth 1.2 07/04/10
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
491 value asr-major
500 value asr-minor
51h# 4153524f4250 value asr-svc-handle \ ASROBP
52
53\ ASR Query Request
54struct
55 /l field >asr-cmd
56constant /asr-hdr
57
58\ ASR Query Response
59struct
60 /l field >query-result
61 /l field >query-status
62constant /query-response
63
64
65d# 1024 /asr-hdr + constant /max-asr-response
66/max-asr-response buffer: asr-buf
67
68: asr-cmd! ( cmd pkt -- ) >asr-cmd l! ;
69: asr-cmd@ ( pkt -- cmd ) >asr-cmd l@ ;
70: >asr-payload ( pkt -- payload-adr ) /asr-hdr + ;
71
72\ message types
739 constant ASR-QUERY-REQ
74h# 19 constant ASR-QUERY-RES
75
76\ ASR Result Codes
770 constant ASR-CMD-OK
781 constant ASR-CMD-FAILED
79
80\ Query Response Status Codes
810 constant ASR-QUERY-ENABLED
821 constant ASR-QUERY-DISABLED
83
84\ To coordinate handoffs between Solaris and OBP the state of the
85\ domain-service channel is stored away. If OBP needs to use the channel
86\ after it has been closed it will attempt to re-register its needed service
870 constant ASR-CLOSED
881 constant ASR-OPEN
892 constant ASR-ERROR
90
91ASR-CLOSED value asr-service-state
92
93\ Domain-service interfaces
94\ Send buffer on the given service channel
95: send-ds-data ( buf len svc-handle -- error? )
96 [ also domain-services ] send-ds-data [ previous ]
97;
98
99\ Receive a packet of at most len from the given service channel
100: receive-ds-data ( buf len svc-handle -- len' 0 | error )
101 [ also domain-services ] receive-ds-data [ previous ]
102;
103
104\ Attempt to register $svc-id with svc-handle. Returns error/ack/nack
105: register-domain-service ( maj min svc-han $svc-id -- maj/min ack? 0 | -1 )
106 [ also domain-services ] register-domain-service [ previous ]
107;
108
109\ Unregister the domain service negotiated on svc-handle
110: unregister-domain-service ( svc-handle -- error? )
111 [ also domain-services ] unregister-domain-service [ previous ]
112;
113
114also ldc
115
116\ service IDs with Null Character embedded
117\ Note: for now only asr-backup service to VBSC is used...
118: $asr ( -- $ ) " asr"(00)" ;
119: $asr-backup ( -- $ ) " asr-backup"(00)" ;
120
121: init-service ( -- error? )
122 asr-major asr-minor asr-svc-handle $asr-backup
123 register-domain-service ?dup 0= if ( maj/min ack? )
124 nip 0= ( nack? )
125 then
126;
127
128\ Attempt to Register asr service
129: asr-init ( -- error? )
130 init-service ( error? )
131 dup if
132 ASR-CLOSED to asr-service-state
133 else
134 ASR-OPEN to asr-service-state
135 then
136;
137
138\ Unregister the asr service
139: asr-close ( -- )
140 asr-svc-handle unregister-domain-service ?dup if ( )
141 \ If LDC is not up then it has been reset, treat this as closed LDC
142 \ which can be re-opened for later operations.
143 LDC-NOTUP = if ( )
144 ASR-CLOSED to asr-service-state ( )
145 else ( )
146 ASR-ERROR to asr-service-state ( )
147 then ( )
148 else ( )
149 ASR-CLOSED to asr-service-state ( )
150 then
151 asr-svc-handle 1+ to asr-svc-handle \ new handle in case of re-register
152;
153
154\ Bring up the asr channel unless it is in the ERROR state
155: check-asr-channel-state ( -- error? )
156 asr-service-state case
157 ASR-OPEN of 0 endof
158 ASR-CLOSED of asr-init endof
159 ASR-ERROR of -1 endof
160 endcase
161;
162
163: asr-response? ( cmd -- asr-response? )
164 dup ASR-QUERY-RES =
165;
166
167\ Wait for asr response request
168: receive-asr-response ( -- buf len 0 | error )
169 asr-buf dup /max-asr-response asr-svc-handle ( buf buf len handle )
170 receive-ds-data ?dup if ( buf len' | buf error )
171 dup LDC-NOTUP = if ( buf error )
172 cmn-warn[ " Waiting for ASR response but LDC is Not Up!" ]cmn-end
173 ASR-CLOSED to asr-service-state
174 then ( buf error )
175 nip ( error )
176 else ( buf len' )
177 dup 0= if ( buf len' )
178 cmn-warn[ " No ASR response from Domain Service Providor " ]cmn-end
179 2drop -1 exit ( -1 )
180 then
181 0 ( buf len 0 )
182 then ( buf len 0 | error )
183;
184
185: $cstrput ( str len dest-adr -- end-adr )
186 swap 2dup ca+ >r move 0 r@ c! r> ca1+
187;
188
189d# 1024 buffer: str-buf
190
191\ " foo" " bar" becomes " foo"(00)"bar"(00)"
192: cat-with-nulls ( str len str2 len2 -- str' len' )
193 2swap ( str2 len2 str len )
194 dup 3 pick + >r ( str2 len2 str len ) ( r: len' )
195 str-buf $cstrput $cstrput drop ( ) ( r: len' )
196 str-buf r> 2+ ( str' len' )
197;
198
199
200\ Wrap query data to be sent to the domain services layer
201: assemble-query-pkt ( $nexus $unit -- pkt len )
202 cat-with-nulls ( $data )
203 tuck asr-buf ( data-len $data pkt )
204 ASR-QUERY-REQ over asr-cmd! ( data-len $name pkt )
205 >asr-payload swap move ( data-len )
206 asr-buf swap /asr-hdr + ( pkt len )
207;
208
209: asr-query ( $nexus $unit -- $response 0 | -1 )
210 check-asr-channel-state if ( $nexus $unit )
211 2drop 2drop true exit ( true )
212 then ( $nexus $unit )
213 assemble-query-pkt ( buf len )
214 asr-svc-handle send-ds-data ?dup if ( error | )
215 LDC-NOTUP = if
216 cmn-warn[ " Sending ASR Query packets but LDC is Not Up!" ]cmn-end
217 \ Mark state to closed so that it can be re-opened later
218 ASR-CLOSED to asr-service-state
219 then
220 cmn-warn[ " Error sending ASR Query packets - transaction failed" ]cmn-end
221 -1 exit
222 then
223 receive-asr-response ?dup if ( $pkt status )
224 cmn-warn[ " Error receiving ASR Query Response" ]cmn-end
225 else
226 drop dup asr-cmd@ ASR-QUERY-RES = if ( pktbuf )
227 >asr-payload /query-response 0 ( $response 0 )
228 else ( pktbuf )
229 drop -1 ( -1 )
230 then ( $response 0 | -1 )
231 then ( $response 0 | -1 )
232;
233
234previous \ LDC
235
236headers
237
238\ 0 The device corresponding to the key is OK.
239\ (There is no asr-entry in the asr-db for the device.)
240\ -1 The device corresponding to the key is disabled
241
242: query ( nexus$ unit$ -- status )
243 asr-query if ( )
244 cmn-warn[ " ASR Query Failed - No Response" ]cmn-end
245 0 \ probe the device anyway ( 0 )
246 else ( $response )
247 drop dup >query-result l@ ( buf result )
248 ASR-CMD-FAILED = if ( buf )
249 cmn-warn[ " ASR Query Failed - Command Failed" ]cmn-end
250 drop 0 \ probe the device anyway ( 0 )
251 else ( buf )
252 >query-status l@ ( status )
253
254 \ At this time, VBSC only returns 0 for enabled and 1 for disabled
255 \ OBP probing code treats status < 0 as "device disabled". The previous
256 \ implementation of ASR had a very complex scheme for changing the 1
257 \ from vbsc into a -1. That complexity was premature as VBSC never
258 \ returned enough information to make complex decisions. Until it does
259 \ this code just treats any non-zero return status as "DISABLED"
260
261 if -1 else 0 then ( status' )
262 then ( status' )
263 then ( status' )
264;
265
266: open ( -- okay? )
267 check-asr-channel-state 0=
268;
269
270: close ( -- )
271 asr-close
272;