Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: hub-control.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 ============================================ | |
42 | id: @(#)hub-control.fth 1.11 03/06/10 | |
43 | purpose: | |
44 | copyright: Copyright 1997-2001, 2003 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | \ XXX Code presumes these are needed only at power-on, probe time, and that | |
48 | \ they can do dma-alloc, free, etc. | |
49 | ||
50 | -1 value #ports \ read from descriptor; global | |
51 | ||
52 | -1 value power-on-time \ in ms -- NOT 2 ms chunks; | |
53 | \ from descriptor; global | |
54 | ||
55 | \ XXX power-switch indicator -- gang, individual port, or no power switch | |
56 | ||
57 | \ XXX port power switch not affected by gang indicators. need setportfeature | |
58 | \ if not ganged. from descriptor | |
59 | ||
60 | \ XXX N.B. standard hub: the status change endpoint is interrupt in, poll | |
61 | \ interval ff. | |
62 | ||
63 | \ XXX need to fiddle c-port-enable? | |
64 | : disable-port ( port# -- ) | |
65 | port-enable swap clear-port-feature ( hw-err? | stat 0 ) | |
66 | \ XXX error recovery instead of this: | |
67 | ?dup 2drop | |
68 | ; | |
69 | ||
70 | \ XXX need to fiddle c-port-enable? | |
71 | \ Illegal command. don't use this -- just reset the port. reset includes enable. | |
72 | \ : enable-port ( port# -- ) | |
73 | \ port-enable swap set-port-feature | |
74 | \ XXX error recovery instead of this: | |
75 | \ ?dup 2drop | |
76 | \ ; | |
77 | ||
78 | \ Nominally 10 ms for non-root ports. usb1.1 7.1.7.3? | |
79 | : 1reset-port ( port# -- ) \ Also enables port atomically | |
80 | port-reset swap set-port-feature | |
81 | \ XXX error recovery instead of this: | |
82 | ?dup 2drop | |
83 | ; | |
84 | ||
85 | : port-reset-done? ( port# -- done? ) | |
86 | get-port-status ( addr hw-err? | addr stat 0 ) | |
87 | \ XXX error recovery instead of this: | |
88 | ?dup 2drop ( addr ) | |
89 | 2 + le-w@ h# 10 and | |
90 | ; | |
91 | ||
92 | : clear-port-reset ( port# -- ) | |
93 | c-port-reset swap clear-port-feature ( hw-err? | stat 0 ) | |
94 | \ XXX error recovery instead of this: | |
95 | ?dup 2drop | |
96 | ; | |
97 | ||
98 | 0 value reset-time \ XXX per instance? | |
99 | ||
100 | \ XXX problem around 0 | |
101 | : reset-timed-out? ( -- timed-out? ) | |
102 | get-msecs reset-time u> | |
103 | ; | |
104 | ||
105 | \ should take only 10 ms; book says it could take 50 ms or more | |
106 | : wait-for-reset ( port -- ) | |
107 | get-msecs d# 100 + is reset-time | |
108 | begin | |
109 | 1 ms | |
110 | dup port-reset-done? | |
111 | reset-timed-out? or | |
112 | until | |
113 | drop | |
114 | ; | |
115 | ||
116 | \ do multiple times to get 50 ms reset. May not be needed. | |
117 | : reset-port ( port# -- ) | |
118 | 5 0 do | |
119 | dup clear-port-reset | |
120 | dup 1reset-port | |
121 | dup wait-for-reset | |
122 | loop | |
123 | drop | |
124 | d# 200 ms \ XXX balky device reset; | |
125 | \ shouldn't have to wait this long | |
126 | \ nominally 10 ms, usb1.1 7.1.7.3 | |
127 | ; | |
128 | ||
129 | \ If ganged, the port goes off when all ports have been unpowered | |
130 | \ (AND function). | |
131 | \ If already off, unpowering again should be ok. | |
132 | : unpower-port ( port# -- ) | |
133 | port-power swap clear-port-feature ( hw-err? | stat 0 ) | |
134 | \ XXX error recovery instead of this: | |
135 | ?dup 2drop | |
136 | ; | |
137 | ||
138 | \ in case the ports are gang-powered but individually controlled | |
139 | : unpower-ports ( -- ) | |
140 | #ports 1+ 1 do | |
141 | i unpower-port | |
142 | loop | |
143 | ; | |
144 | ||
145 | : port-connected? ( port# -- connected? ) | |
146 | get-port-status ( addr hw-err? | addr stat 0 ) | |
147 | \ XXX error recovery instead of this: | |
148 | ?dup 2drop ( addr ) | |
149 | le-l@ 1 and | |
150 | ; | |
151 | ||
152 | : port-powered? ( port# -- power-on? ) | |
153 | get-port-status ( addr hw-err? | addr stat 0 ) | |
154 | \ XXX error recovery instead of this: | |
155 | ?dup 2drop ( addr ) | |
156 | le-l@ h# 100 and | |
157 | ; | |
158 | ||
159 | \ Turn on any port to turn all on with ganged power (OR function). | |
160 | \ Multiple turn-on commands should work. So the ganged power aspect is | |
161 | \ really relevant for unpower-port. | |
162 | \ Device could take 200 ms beyond the hub port power time before it is | |
163 | \ ready to reset | |
164 | ||
165 | 0 value power-time \ can be global; used only at probe time. | |
166 | ||
167 | : power-timed-out? ( -- timed-out? ) | |
168 | get-msecs power-time u> | |
169 | ; | |
170 | ||
171 | : power-port ( port# -- ) | |
172 | port-power over set-port-feature | |
173 | \ XXX error recovery instead of this: | |
174 | ?dup 2drop | |
175 | get-msecs power-on-time + is power-time | |
176 | begin | |
177 | 1 ms | |
178 | dup port-powered? | |
179 | power-timed-out? or | |
180 | until | |
181 | drop | |
182 | d# 200 ms \ more delay for balky devices | |
183 | ; | |
184 | ||
185 | : suspend-port ( port# -- ) | |
186 | port-suspend swap set-port-feature | |
187 | \ XXX error recovery instead of this: | |
188 | ?dup 2drop | |
189 | ; | |
190 | ||
191 | : resume-port ( port# -- ) | |
192 | port-suspend swap clear-port-feature | |
193 | \ XXX error recovery instead of this: | |
194 | ?dup 2drop | |
195 | ; | |
196 | ||
197 | : port-low-speed? ( port# -- low-speed? ) | |
198 | get-port-status ( addr hw-err? | addr stat 0 ) | |
199 | \ XXX error recovery instead of this: | |
200 | ?dup 2drop ( addr ) | |
201 | le-l@ h# 200 and if 1 else 0 then | |
202 | ; | |
203 | ||
204 | : clear-connect-change ( port# -- ) | |
205 | c-port-connection swap clear-port-feature ( hw-err? | stat 0 ) | |
206 | \ XXX error recovery instead of this: | |
207 | ?dup 2drop | |
208 | ; | |
209 | ||
210 | : clear-port-enable ( port# -- ) | |
211 | c-port-enable swap clear-port-feature ( hw-err? | stat 0 ) | |
212 | \ XXX error recovery instead of this: | |
213 | ?dup 2drop | |
214 | ; | |
215 | ||
216 | : clear-port-suspend ( port# -- ) | |
217 | c-port-suspend swap clear-port-feature ( hw-err? | stat 0 ) | |
218 | \ XXX error recovery instead of this: | |
219 | ?dup 2drop | |
220 | ; |