Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun4v / domain-services.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: domain-services.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: @(#)domain-services.fth 1.8 07/06/22
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ FWARC 2006/055
48
49vocabulary domain-services
50also domain-services definitions
51
52headerless
53
54fload ${BP}/arch/sun4v/ds-h.fth
55
56also ldc
57
58-1 value cached-ldc-id
59
60\ node = domain-services-port
61\ return pointer to the id property in the accociated channel endpoint
62: get-endpoint-id ( node -- id | -1 )
63 " fwd" ascii a md-find-prop ?dup if ( arc )
64 md-decode-prop drop " id" ascii v md-find-prop ?dup if ( prop )
65 md-decode-prop drop exit ( id )
66 then
67 then
68 -1 \ error
69;
70
710 value found-channel?
72
73\ if this is a domain-service port attempt to open it unless we've already
74\ opened a port. node = domain-service-port
75: open-ds-channel ( node -- )
76 cached-ldc-id -1 <> if drop exit then ( node )
77 dup md-node-name " domain-services-port" $= if ( node )
78 get-endpoint-id dup -1 <> if ( id )
79 true to found-channel?
80 dup ldc-mode-reliable ldc-open if ( id )
81 to cached-ldc-id exit ( )
82 then ( id )
83 then ( id )
84 then ( node )
85 drop ( )
86;
87
88\ When operating on the default MDs OBP uses a private channel
89: try-openboot-channel ( -- error? )
90 md-root-node " openboot" md-find-node ?dup if ( node )
91 ['] open-ds-channel swap md-applyto-fwds ( )
92 then ( )
93 \ if we haven't cached an id then the open failed
94 cached-ldc-id -1 = ( error? )
95;
96
97\ When operating on zeus MDs Openboot may use 1 of 2 centrally located
98\ channels depending on whether it is the primary domain or a guest
99: try-other-channels ( -- error? )
100 md-root-node " domain-services" md-find-node ?dup if ( node )
101 ['] open-ds-channel swap md-applyto-fwds ( )
102 then ( )
103 \ if we haven't cached an id then the opens failed
104 cached-ldc-id -1 = ( error? )
105;
106
107\ Find and bring up the domain services LDC channel
108\ if we are reopening, the channel will be cached so skip the search
109: init-ldc-channel ( -- error? )
110 cached-ldc-id -1 <> if ( )
111 cached-ldc-id ldc-mode-reliable ldc-open 0= ( error? )
112 else ( )
113 0 to found-channel?
114 try-openboot-channel dup if ( error? )
115 found-channel? 0= if
116 try-other-channels and ( error? )
117 then
118 then ( error? )
119 then ( error? )
120;
121
122: ldc-channel-reconfigured? ( -- reconfigured? )
123 channel-reconfigured?
124;
125
126\ send a domain service packet over the ldc channel
127: send-ds-pkt ( buf len -- error? )
128 tuck ldc-write ?dup if ( len len' status )
129 dup LDC-NOTUP = if ( len len' status )
130 DS-CLOSED to domain-service-state ( len len' status )
131 then ( len len' status )
132 -rot 2drop ( error )
133 else ( len len' )
134 <> ( error? )
135 then ( error? )
136;
137
138\ receive a domain service packet from the ldc channel
139\ wait up to 1 second for a response
140: receive-ds-pkt ( buf len -- error? )
141 \ Re-try 10 times, @ 10 seconds as lower layer tries for 1 sec
142 d# 10 ( buf len timeout )
143 begin ( buf len timeout )
144 1 ms 1- dup ( buf len timeout timeout )
145 while
146 -rot 2dup ldc-read ?dup if ( timeout buf len len' status )
147 nip ( timeout buf len status )
148 LDC-NOTUP = if ( timeout buf len )
149 DS-CLOSED to domain-service-state ( )
150 3drop LDC-NOTUP exit ( LDC-NOTUP )
151 then ( timeout buf len )
152 else ( timeout buf len len' )
153 if ( timeout buf len )
154 3drop 0 exit ( 0 )
155 then ( timeout buf len )
156 then ( timeout buf len )
157 rot ( buf len timeout )
158 repeat
159 3drop -1 ( error )
160;
161
162\ assemble a domain service version packet
163: assemble-init-req ( major minor -- size )
164 ds-pkt-buffer ( major minor buf )
165 DS-INIT-REQ over msg-type! ( major minor buf )
166 /ds-init-req over payload-len! ( major minor buf )
167 >payload ( major minor payload )
168 tuck >init-minor-ver w! ( major payload )
169 tuck >init-major-ver w! ( buf )
170 payload>pkt dup pkt-size@ ( buf size )
171;
172
173\ wait for a domain service version response
174: wait-for-init-resp ( -- buf len error? )
175 ds-pkt-buffer /ds-hdr /ds-init-ack + ( buf len )
176 begin
177 2dup receive-ds-pkt dup ( buf len error? error? )
178 LDC-NOTUP = if ( buf len error? )
179 cmn-warn[
180 " Waiting for DS init response but LDC is Not Up!"
181 ]cmn-end ( buf len error? )
182 exit ( buf len LDC-NOTUP )
183 then ( buf len error? )
184 0=
185 while
186 over >msg-type l@ ( buf len type )
187 dup DS-INIT-ACK = if drop 0 exit then ( buf len 0 )
188 DS-INIT-NACK = if -1 exit then ( buf len -1 )
189 repeat
190 -1 ( buf len -1 )
191;
192
193: init-ack? ( type -- ack? ) DS-INIT-ACK = ;
194
195\ parse domain service version response
196: parse-init-req ( pkt len -- major/minor type )
197 drop dup >msg-type l@ tuck ( type pkt type )
198 init-ack? if
199 >payload >init-ack-minor-vers w@ ( type minor )
200 else
201 >payload >init-nack-major-vers w@ ( type major )
202 then
203 swap ( major/minor type )
204;
205
206\ assemble and send a domain service version request
207: ds-init-request ( major minor -- major/minor type 0 | error )
208 assemble-init-req ( buf size )
209 send-ds-pkt ?dup if ( error )
210 dup LDC-NOTUP = if
211 cmn-warn[ " Sending DS Init request but LDC is NOT Up!" ]cmn-end
212 then ( LDC-NOTUP )
213 exit ( error )
214 then ( error )
215 wait-for-init-resp ?dup 0= if ( buf len )
216 parse-init-req 0 ( major/minor type 0 )
217 else ( buf len error? )
218 -rot 2drop ( error )
219 then ( major/minor type 0 | error )
220;
221
222\ This can later be turned into a begin while loop that handles
223\ multiple versions... however right now only 1.0 is supported
224: ds-init-handshake ( -- error? )
225 ds-major ds-minor ( major minor )
226 ds-init-request ?dup if exit then ( major/minor type | error? )
227 init-ack? if
228 to ds-minor 0 ( 0 )
229 else
230 drop -1 ( error )
231 then
232;
233
234\ initialize domain-services protocal link
235: ds-init ( -- error? )
236 init-ldc-channel ?dup 0= if
237 ds-init-handshake dup if
238 cmn-note[
239 " Unable to complete Domain Service protocol version handshake"
240 ]cmn-end
241 then
242 then
243 dup if
244 \ If error is LDC reset then leave the state as DS-CLOSE
245 dup LDC-NOTUP <> if
246 DS-ERROR to domain-service-state
247 then
248 cmn-warn[ " Unable to connect to Domain Service providers" ]cmn-end
249 else
250 DS-OPEN to domain-service-state
251 then
252;
253
254\ assemble a particular service registration version request
255: assemble-reg-req ( major minor svc-handle $svc-id -- buf len )
256 ds-pkt-buffer ( major minor svc-handle $svc-id pkt )
257 DS-REG-REQ over msg-type! ( major minor svc-handle $svc-id pkt )
258 over /ds-reg-req + over payload-len! ( major minor svc-handle $svc-id pkt )
259 >payload ( major minor svc-handle $svc-id pay )
260 -rot 2 pick >reg-svc-id swap move ( major minor svc-handle payload )
261 tuck >reg-svc-handle x! ( major minor payload )
262 tuck >reg-minor-ver w! ( major payload )
263 tuck >reg-major-ver w! ( payload )
264 payload>pkt dup pkt-size@ ( buf len )
265;
266
267\ wait for a service registration version response
268: wait-for-reg-resp ( -- buf len error? )
269 ds-pkt-buffer /ds-hdr /ds-reg-ack + ( buf len )
270 begin
271 2dup receive-ds-pkt dup ( buf len error? error? )
272 LDC-NOTUP = if ( buf len error? )
273 cmn-warn[
274 " Waiting for DS registration response but LDC is Not Up!"
275 ]cmn-end ( buf len error? )
276 exit ( buf len LDC-NOTUP )
277 then ( buf len error? )
278 0=
279 while
280 over >msg-type l@ ( buf len type )
281 dup DS-REG-ACK = if drop 0 exit then ( buf len 0 )
282 DS-REG-NACK = if -1 exit then ( buf len -1 )
283 repeat
284 -1 ( buf len -1 )
285;
286
287\ assemble a service unregistration request
288: assemble-unreg-req ( svc-handle -- pkt size )
289 ds-pkt-buffer ( svc-handle pkt )
290 DS-UNREG over msg-type! ( svc-handle pkt )
291 /ds-unreg-req over payload-len! ( svc-handle pkt )
292 tuck >payload >unreg-svc-handle x! ( pkt )
293 dup pkt-size@ ( pkt len )
294;
295
296\ wait for service unregistration response
297: wait-for-unreg-resp ( -- error? )
298 ds-pkt-buffer /ds-hdr /ds-unreg-req + ( buf len )
299 begin
300 2dup receive-ds-pkt dup ( buf len error? error? )
301 LDC-NOTUP = if ( buf len error? )
302 cmn-warn[
303 " Waiting for DS unregister response but LDC is Not Up!"
304 ]cmn-end ( buf len error? )
305 -rot 2drop exit ( LDC-NOTUP )
306 then ( buf len error? )
307 0=
308 while
309 over >msg-type l@ ( buf len type )
310 dup DS-UNREG-ACK = if 3drop 0 exit then ( 0 )
311 DS-UNREG-NACK = if 2drop -1 exit then ( -1 )
312 repeat
313 2drop -1 ( -1 )
314;
315
316: reg-ack? ( type -- ack? ) DS-REG-ACK = ;
317
318\ parse a service registration request-response
319: parse-reg-req ( pkt len -- major/minor type )
320 drop dup >msg-type l@ tuck ( type pkt type )
321 reg-ack? if
322 >payload >regack-minor-vers w@ ( type minor )
323 else
324 >payload >regnack-major-vers w@ ( type major )
325 then
326 swap ( major/minor type )
327;
328
329\ assemble and send a service registration request
330: ds-reg-request ( $svc-id svc-handle major minor -- major/minor type 0 | error )
331 assemble-reg-req ( buf size )
332 send-ds-pkt ?dup if
333 dup LDC-NOTUP = if ( LDC-NOTUP )
334 cmn-warn[ " Sending DS Reg request but LDC is Not Up!" ]cmn-end
335 then ( LDC-NOTUP )
336 exit ( error )
337 then ( error )
338 wait-for-reg-resp ?dup if ( buf len error )
339 -rot 2drop ( error )
340 else
341 parse-reg-req reg-ack? 0 ( major/minor ack? 0 )
342 then
343;
344
345\ assemble a domain service data packet
346: assemble-data-pkt ( buf len svc-handle -- pkt len' )
347 ds-pkt-buffer ( buf len svc-handle pkt )
348 DS-DATA over msg-type! ( buf len svc-handle pkt )
349 tuck >payload >data-svc-handle x! ( buf len pkt )
350 over /ds-data + over payload-len! ( buf len pkt )
351 >payload /ds-data + swap move ( )
352 ds-pkt-buffer ( pkt )
353 dup pkt-size@ ( pkt len )
354;
355
356\ extracts start and length of a Data pkt
357: data-payload ( pkt -- payload-buf payload-len )
358 dup >payload /ds-data + ( pkt payload-buf )
359 swap payload-len@ /ds-data - ( payload-buf payload-len )
360;
361
362\ receive a data packet from the domain-service channel
363\ (only copy payload to buf)
364: wait-for-data-pkt ( buf len svc-handle -- len' 0 | error )
365 ds-pkt-buffer rot ( buf svc-handle pkt len )
366 /ds-hdr + /ds-data + ( buf svc-handle pkt len' )
367 begin
368 2dup receive-ds-pkt ?dup if ( buf svc-handle pkt len status )
369 >r 2drop 2drop r> exit ( error )
370 then ( buf svc-handle pkt len )
371 over msg-type@ DS-DATA = if ( buf svc-handle pkt len )
372 -rot 2dup >payload ( buf len svc-handle pkt svc-h pay )
373 >data-svc-handle x@ = if ( buf len svc-handle pkt )
374 rot -1 ( buf svc-handle pkt len -1 )
375 else
376 rot 0 ( buf svc-handle pkt len 0 )
377 then
378 else
379 0 ( buf svc-handle pkt len 0 )
380 then ( buf svc-handle pkt len good? )
381 until ( buf svc-handle pkt len )
382 drop nip data-payload ( buf payload payload-len )
383 >r swap r@ move r> 0 ( len' 0 )
384;
385
386\ Bring up domain service channel unless it's in the ERROR state
387: check-domain-service-state ( -- error? )
388 \ If we think the channel is open, but some other entity (Solaris)
389 \ has reconfigured it, we play it safe and tranistion to an error state
390 domain-service-state DS-OPEN = if
391 ldc-channel-reconfigured? if
392 DS-ERROR to domain-service-state
393 then
394 then
395
396 domain-service-state case
397 DS-OPEN of 0 endof
398 DS-CLOSED of ds-init endof
399 DS-ERROR of -1 endof
400 endcase
401;
402
403headers
404
405\ Wrap buffer in a domain service packet and send it on the specified channel
406: send-ds-data ( buf len svc-handle -- error? )
407 check-domain-service-state if
408 3drop -1 exit ( -1 )
409 then
410 assemble-data-pkt ( pkt len )
411 send-ds-pkt ( error? )
412;
413
414\ Receive a data packet from the specified channel
415: receive-ds-data ( buf len svc-handle -- len' 0 | error )
416 check-domain-service-state if
417 3drop -1 exit ( -1 )
418 then ( buf len svc-handle )
419 wait-for-data-pkt ( len' 0 | error )
420;
421
422\ Register a particular domain service
423\ Don't print an error message because there may be a backup service available
424: register-domain-service ( maj min svc-han $svc-id -- maj/min ack? 0 | error )
425 check-domain-service-state if
426 3drop 2drop -1 exit ( -1 )
427 then ( maj min svc-han $svc-id )
428 ds-reg-request ( maj/min ack? 0 | error )
429;
430
431\ unregister a particular domain service
432: unregister-domain-service ( svc-handle -- error? )
433 check-domain-service-state if
434 drop -1 exit ( -1 )
435 then ( svc-handle )
436 assemble-unreg-req ( pkt size )
437 send-ds-pkt ?dup 0= if ( )
438 wait-for-unreg-resp ( error? )
439 else
440 dup LDC-NOTUP = if ( LDC-NOTUP )
441 cmn-warn[ " Sending Unreg request but LDC is Not Up!" ]cmn-end
442 then ( LDC-NOTUP )
443 then ( error? )
444;
445
446previous \ ldc
447
448previous definitions \ domain-services
449