\ ========== Copyright Header Begin ==========================================
\ Hypervisor Software File: probe.fth
\ 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 ============================================
id: @(#)probe.fth 1.25 05/09/30
copyright: Copyright 2005 Sun Microsystems, Inc. All Rights Reserved
copyright: Use is subject to license terms.
\ must do dma-free on adr2 len2 after fcode is used:
: find-fcode ( adr1 len1 -- adr2 len2 true | false )
" sunw,find-fcode" get-inherited-property drop
: find-device-fcode ( -- addr len ) " device" find-fcode drop ;
: find-combined-fcode ( -- addr len ) " combined" find-fcode drop ;
: assign-address ( speed usb-addr -- hw-err? | stat 0 )
\ next-usb-address ?dup if
set-address-form >r \ uses request-blank
( speed ) 1 max-packet 0 0 r> /request 0 0 execute-control
d# 10 ms \ allow assignment to take effect
: set-configuration ( speed usb-addr config -- hw-err? | stat 0 )
1 max-packet 2swap 0 0 2swap
( speed dir max-pkt dat-adr dat-len usb-addr config )
clean-request-blank \ dma-free at end of probe or close
set-config-req over request-type w!
swap over req-value le-w!
/request 2swap ( speed dir max-pkt dat-adr dat-len req-adr req-len )
\ dma-alloc because of get-descriptors
: get-dev-descrip ( speed usb-adr -- dev-descrip-addr dcnt hw-err? | stat 0 )
/dev-descriptor dma-alloc \ only needed at probe time
/dev-descriptor get-dev-descript-form
\ dma-alloc data area because of get-descriptors
: get-config-descrip ( speed usb-adr n cnt
-- config-n-descrip-addr cnt hw-err? | stat 0 )
swap rot >r >r >r ( R: usb-addr n cnt )
r@ dma-alloc ( speed in max c-d-addr ) \ only used at probe time
r> r> r> ( speed in max c-d-addr cnt n u-addr )
2over >r >r >r >r ( R: cnt c-d-addr u-addr n )
dup get-config-descript-form
r> over req-value c! ( speed in max c-d-addr cnt pak-adr )
( R: cnt c-d-addr usb-addr )
/request 0 r> execute-control
: get-config1-descrip ( speed usb-adr
-- config1-descrip-addr ccnt hw-err? | stat 0 )
0 /config-descriptor get-config-descrip
: ?create-speed ( lo-speed? -- )
if 0 0 " low-speed" property then
: create-address ( usb-addr -- )
encode-int " assigned-address" property
: combined-node? ( config-desc dev-desc -- combined? )
dup 9 = swap 0= or ( c-desc d-desc dev-ok? )
swap d-descript-#configs c@ 1 = and
swap c-descript-#interfaces c@ 1 = and
: make-child ( fcode-adr unit-str unit-len speed usb-adr -- )
( child-max ) encode-int " 0max-packet" property
create-address ?create-speed
case 2 of noop endof \ patchable
6 of cr ." usb-nak" endof
e of cr ." usb-stall" endof
: stall-or-nak? ( stat -- stall-or-nak? )
: idump ( adr len -- ) \ XXX debug
" dump" $find drop execute
: clean-port ( port -- ) \ acts on the hub
dup reset-port \ includes enable-port
: set-default-max-packet ( speed -- )
defer complete-probe ( port speed )
' 2drop is complete-probe \ for a good node already created
\ Start with a new device at usb 0, port, and known speed (low or normal).
\ no-retry? (non-zero) if really fatal or succeeded. retry (zero) if want to
: probe-once ( port speed -- no-retry? )
['] 2drop is complete-probe \ default to good device node on each pass
dup set-default-max-packet
\ d# 150 ms \ for Microsoft device settling; only hot-plug?
" dev-descrip" diag-crtype
dup 0 get-dev-descrip ( port speed dev-d-adr dcnt hw-err? | stat 0 )
dup no-response-error = if \ wait for device that powers up slowly
d# 2000 ms \ maybe only 500 needed?
dup 0 get-dev-descrip ( port speed dev-d-adr dcnt hw-err? | stat 0 )
data-overrun-error <> if \ data-over benign here
['] won't-send-descriptor is complete-probe
['] won't-send-descriptor is complete-probe
then ( port speed dev-d-adr dcnt )
over d-descript-maxpkt c@ to child-max
next-usb-address 2dup assign-address ( port speed usb-adr hw-err? | stat 0 )
drop \ XXX the error code; already printed
drop \ XXX will use up usb-adrs
['] won't-take-address is complete-probe
drop \ XXX will use up usb-adrs
['] won't-take-address is complete-probe
then ( port speed usb-adr )
" get-config1" diag-crtype
( port spd usb-addr cnfg-adr cnt hw-err? | stat 0 )
drop \ XXX some hw-err; already printed
drop \ XXX will use up usb-adrs
['] won't-send-config is complete-probe
drop \ XXX will use up usb-adrs
['] won't-send-config is complete-probe
then ( port spd usb-addr cnfg-adr cnt )
over c-descript-config-id c@ >r \ get bconfigvalue
" set-config" diag-crtype
2dup r> set-configuration \ config index 1, using bconfigvalue
?dup if ( port spd usb-addr hw-err? )
drop \ XXX hw-err; already printed
['] won't-take-config is complete-probe
['] won't-take-config is complete-probe
then ( port spd usb-adr )
" get-config1-descript" diag-crtype
( port speed usb-adr config-desc ccnt hw-err? | stat 0 )
drop \ XXX some hw-err; already printed
['] won't-send-descriptor is complete-probe
['] won't-send-descriptor is complete-probe
then ( port spd usb-adr cadr ccnt )
" get-dev-descrip" diag-crtype
( port spd usb-adr cadr ccnt dadr dcnt hw-err? | stat 0 )
drop \ XXX hw-err; already printed
['] won't-send-descriptor is complete-probe
['] won't-send-descriptor is complete-probe
( port spd usb-adr config-desc ccnt dev-desc dcnt )
\ 2dup cr ." dev descrip" cr idump \ XXX debug
\ 2over cr ." con descrip" cr idump \ XXX debug
3 pick 2 pick combined-node? if
" finding combined" diag-crtype
" finding device" diag-crtype
r@ ( port speed usb-adr fcode-adr ) ( R: f-len f-adr )
r> r> dma-free \ toss fcode; only at probe time
\ give a device two chances. if not enumerated ok after two tries, make a
\ bad device node. leave open the option for other actions, depending on the
dup dup port-low-speed? \ bug 6261224, for Cypress hub chip
i power-port \ leave port on -- possible hot-plug
i port-connected? if \ unpowered is not connected
: read-power-bits ( hub-descript -- ) drop ;
: read-my-data ( -- went-ok? ) \ read descriptors and figure out what's what
0max-packet to max-packet
speed my-usb-addr get-dev-descrip ( dadr dcnt hw-err? | stat 0 )
" disabled" encode-string " status" property
" disabled" encode-string " status" property
over d-descript-maxpkt c@ to 0max-packet
\ would need endpt descriptor for max packet for endpt. <> 0
0max-packet to max-packet
7 get-hub-descript \ get the real descript size
drop \ common-buffer; no dma-free here
" disabled" encode-string " status" property
drop \ common-buffer; no dma-free here
" disabled" encode-string " status" property
h-descript-len c@ get-hub-descript
drop \ common-buffer; no dma-free here
" disabled" encode-string " status" property
drop \ common-buffer; no dma-free here
" disabled" encode-string " status" property
dup h-descript-#ports c@ to #ports
h-descript-power-on c@ 2* to power-on-time
\ XXX hub status data -- 32 bits or so
\ port status data -- 32 bits or so
\ probe deeper if recurse? is not 0. involves a dependency on main OBP.
\ this word works with max-recursion in the host adapter fcode, and with
\ onboard-usb-max-depth and onboard-usb-recurse? in SUNW,builtin-drivers.
: go-deeper? ( -- recurse? )
" SUNW,builtin-drivers" find-package drop \ must be present
else true \ default to go deeper
/request dma-alloc to request-blank \ get memory
/common-buffer dma-alloc to common-buffer
read-my-data go-deeper? and if
common-buffer /common-buffer dma-free \ free memory
request-blank /request dma-free