Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: probe.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: @(#)probe.fth 1.25 05/09/30 | |
43 | purpose: | |
44 | copyright: Copyright 2005 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | \ must do dma-free on adr2 len2 after fcode is used: | |
48 | : find-fcode ( adr1 len1 -- adr2 len2 true | false ) | |
49 | " sunw,find-fcode" get-inherited-property drop | |
50 | decode-int nip nip | |
51 | execute | |
52 | ; | |
53 | ||
54 | : find-device-fcode ( -- addr len ) " device" find-fcode drop ; | |
55 | ||
56 | : find-combined-fcode ( -- addr len ) " combined" find-fcode drop ; | |
57 | ||
58 | : assign-address ( speed usb-addr -- hw-err? | stat 0 ) | |
59 | \ next-usb-address ?dup if | |
60 | set-address-form >r \ uses request-blank | |
61 | ( speed ) 1 max-packet 0 0 r> /request 0 0 execute-control | |
62 | \ else no-more-addresses | |
63 | \ then | |
64 | d# 10 ms \ allow assignment to take effect | |
65 | \ should need only 2 ms | |
66 | ; | |
67 | ||
68 | : set-configuration ( speed usb-addr config -- hw-err? | stat 0 ) | |
69 | 1 max-packet 2swap 0 0 2swap | |
70 | ( speed dir max-pkt dat-adr dat-len usb-addr config ) | |
71 | 0 -rot \ endpoint | |
72 | clean-request-blank \ dma-free at end of probe or close | |
73 | set-config-req over request-type w! | |
74 | swap over req-value le-w! | |
75 | /request 2swap ( speed dir max-pkt dat-adr dat-len req-adr req-len ) | |
76 | execute-control | |
77 | ; | |
78 | ||
79 | \ dma-alloc because of get-descriptors | |
80 | : get-dev-descrip ( speed usb-adr -- dev-descrip-addr dcnt hw-err? | stat 0 ) | |
81 | 0 swap max-packet swap | |
82 | /dev-descriptor dma-alloc \ only needed at probe time | |
83 | dup >r swap | |
84 | /dev-descriptor swap | |
85 | /dev-descriptor get-dev-descript-form | |
86 | swap | |
87 | /request swap | |
88 | 0 swap execute-control | |
89 | ?dup | |
90 | r> /dev-descriptor | |
91 | 2swap | |
92 | 0= if 0 then | |
93 | ; | |
94 | ||
95 | \ dma-alloc data area because of get-descriptors | |
96 | : get-config-descrip ( speed usb-adr n cnt | |
97 | -- config-n-descrip-addr cnt hw-err? | stat 0 ) | |
98 | swap rot >r >r >r ( R: usb-addr n cnt ) | |
99 | 0 max-packet | |
100 | r@ dma-alloc ( speed in max c-d-addr ) \ only used at probe time | |
101 | r> r> r> ( speed in max c-d-addr cnt n u-addr ) | |
102 | 2over >r >r >r >r ( R: cnt c-d-addr u-addr n ) | |
103 | dup get-config-descript-form | |
104 | r> over req-value c! ( speed in max c-d-addr cnt pak-adr ) | |
105 | ( R: cnt c-d-addr usb-addr ) | |
106 | /request 0 r> execute-control | |
107 | ?dup | |
108 | r> r> | |
109 | 2swap | |
110 | 0= if 0 then | |
111 | ; | |
112 | ||
113 | : get-config1-descrip ( speed usb-adr | |
114 | -- config1-descrip-addr ccnt hw-err? | stat 0 ) | |
115 | 0 /config-descriptor get-config-descrip | |
116 | ; | |
117 | ||
118 | : ?create-speed ( lo-speed? -- ) | |
119 | if 0 0 " low-speed" property then | |
120 | ; | |
121 | ||
122 | : create-address ( usb-addr -- ) | |
123 | encode-int " assigned-address" property | |
124 | ; | |
125 | ||
126 | : combined-node? ( config-desc dev-desc -- combined? ) | |
127 | dup d-descript-class c@ | |
128 | dup 9 = swap 0= or ( c-desc d-desc dev-ok? ) | |
129 | swap d-descript-#configs c@ 1 = and | |
130 | swap c-descript-#interfaces c@ 1 = and | |
131 | ; | |
132 | ||
133 | : make-child ( fcode-adr unit-str unit-len speed usb-adr -- ) | |
134 | child-max | |
135 | new-device | |
136 | ( child-max ) encode-int " 0max-packet" property | |
137 | create-address ?create-speed | |
138 | " " 2swap set-args | |
139 | 1 byte-load | |
140 | finish-device | |
141 | ; | |
142 | ||
143 | : .usb ( stat -- ) | |
144 | case 2 of noop endof \ patchable | |
145 | 6 of cr ." usb-nak" endof | |
146 | e of cr ." usb-stall" endof | |
147 | cr ." usb-unknown" | |
148 | endcase | |
149 | ; | |
150 | ||
151 | : stall-or-nak? ( stat -- stall-or-nak? ) | |
152 | dup .usb | |
153 | dup e = swap 6 = or | |
154 | ; | |
155 | ||
156 | : idump ( adr len -- ) \ XXX debug | |
157 | " dump" $find drop execute | |
158 | ; | |
159 | ||
160 | : clean-port ( port -- ) \ acts on the hub | |
161 | dup reset-port \ includes enable-port | |
162 | dup clear-connect-change | |
163 | dup clear-port-reset | |
164 | dup clear-port-enable | |
165 | clear-port-suspend | |
166 | ; | |
167 | ||
168 | : set-default-max-packet ( speed -- ) | |
169 | if \ low speed | |
170 | 8 to child-max | |
171 | 8 to max-packet | |
172 | else \ reg. speed | |
173 | d# 64 to child-max | |
174 | d# 64 to max-packet | |
175 | then | |
176 | ; | |
177 | ||
178 | defer complete-probe ( port speed ) | |
179 | ' 2drop is complete-probe \ for a good node already created | |
180 | ||
181 | \ Start with a new device at usb 0, port, and known speed (low or normal). | |
182 | \ no-retry? (non-zero) if really fatal or succeeded. retry (zero) if want to | |
183 | \ go back to reset-port | |
184 | : probe-once ( port speed -- no-retry? ) | |
185 | ['] 2drop is complete-probe \ default to good device node on each pass | |
186 | dup set-default-max-packet | |
187 | \ d# 150 ms \ for Microsoft device settling; only hot-plug? | |
188 | " dev-descrip" diag-crtype | |
189 | dup 0 get-dev-descrip ( port speed dev-d-adr dcnt hw-err? | stat 0 ) | |
190 | dup no-response-error = if \ wait for device that powers up slowly | |
191 | drop dma-free | |
192 | over clean-port | |
193 | d# 2000 ms \ maybe only 500 needed? | |
194 | dup 0 get-dev-descrip ( port speed dev-d-adr dcnt hw-err? | stat 0 ) | |
195 | then | |
196 | ?dup if | |
197 | data-overrun-error <> if \ data-over benign here | |
198 | dma-free | |
199 | 2drop | |
200 | ['] won't-send-descriptor is complete-probe | |
201 | false exit ( retry ) | |
202 | then | |
203 | else stall-or-nak? if | |
204 | dma-free 2drop | |
205 | ['] won't-send-descriptor is complete-probe | |
206 | false exit ( retry ) | |
207 | then | |
208 | then ( port speed dev-d-adr dcnt ) | |
209 | over d-descript-maxpkt c@ to child-max | |
210 | dma-free | |
211 | over clean-port | |
212 | " next-add" diag-crtype | |
213 | child-max to max-packet | |
214 | next-usb-address 2dup assign-address ( port speed usb-adr hw-err? | stat 0 ) | |
215 | ?dup if | |
216 | drop \ XXX the error code; already printed | |
217 | drop \ XXX will use up usb-adrs | |
218 | 2drop | |
219 | ['] won't-take-address is complete-probe | |
220 | false exit ( retry ) | |
221 | else stall-or-nak? if | |
222 | drop \ XXX will use up usb-adrs | |
223 | 2drop | |
224 | ['] won't-take-address is complete-probe | |
225 | false exit ( retry ) | |
226 | then | |
227 | then ( port speed usb-adr ) | |
228 | " get-config1" diag-crtype | |
229 | 2dup get-config1-descrip | |
230 | ( port spd usb-addr cnfg-adr cnt hw-err? | stat 0 ) | |
231 | ?dup if | |
232 | drop \ XXX some hw-err; already printed | |
233 | dma-free | |
234 | drop \ XXX will use up usb-adrs | |
235 | 2drop | |
236 | ['] won't-send-config is complete-probe | |
237 | false exit ( retry ) | |
238 | else stall-or-nak? if | |
239 | dma-free | |
240 | drop \ XXX will use up usb-adrs | |
241 | 2drop | |
242 | ['] won't-send-config is complete-probe | |
243 | false exit ( retry ) | |
244 | then | |
245 | then ( port spd usb-addr cnfg-adr cnt ) | |
246 | over c-descript-config-id c@ >r \ get bconfigvalue | |
247 | dma-free | |
248 | " set-config" diag-crtype | |
249 | 2dup r> set-configuration \ config index 1, using bconfigvalue | |
250 | ?dup if ( port spd usb-addr hw-err? ) | |
251 | drop \ XXX hw-err; already printed | |
252 | drop 2drop | |
253 | ['] won't-take-config is complete-probe | |
254 | true exit ( no-retry ) | |
255 | else stall-or-nak? if | |
256 | drop 2drop | |
257 | ['] won't-take-config is complete-probe | |
258 | true exit ( no-retry ) | |
259 | then | |
260 | then ( port spd usb-adr ) | |
261 | " get-config1-descript" diag-crtype | |
262 | 2dup get-config1-descrip | |
263 | ( port speed usb-adr config-desc ccnt hw-err? | stat 0 ) | |
264 | ?dup if | |
265 | drop \ XXX some hw-err; already printed | |
266 | dma-free | |
267 | drop 2drop | |
268 | ['] won't-send-descriptor is complete-probe | |
269 | true exit ( no-retry ) | |
270 | else stall-or-nak? if | |
271 | dma-free | |
272 | drop 2drop | |
273 | ['] won't-send-descriptor is complete-probe | |
274 | true exit ( no-retry ) | |
275 | then | |
276 | then ( port spd usb-adr cadr ccnt ) | |
277 | " get-dev-descrip" diag-crtype | |
278 | 2over get-dev-descrip | |
279 | ( port spd usb-adr cadr ccnt dadr dcnt hw-err? | stat 0 ) | |
280 | ?dup if | |
281 | drop \ XXX hw-err; already printed | |
282 | dma-free dma-free | |
283 | drop 2drop | |
284 | ['] won't-send-descriptor is complete-probe | |
285 | true exit ( no-retry ) | |
286 | else stall-or-nak? if | |
287 | dma-free dma-free | |
288 | drop 2drop | |
289 | ['] won't-send-descriptor is complete-probe | |
290 | true exit ( no-retry ) | |
291 | then | |
292 | then | |
293 | " descripts" diag-crtype | |
294 | ( port spd usb-adr config-desc ccnt dev-desc dcnt ) | |
295 | \ 2dup cr ." dev descrip" cr idump \ XXX debug | |
296 | \ 2over cr ." con descrip" cr idump \ XXX debug | |
297 | 3 pick 2 pick combined-node? if | |
298 | " finding combined" diag-crtype | |
299 | find-combined-fcode | |
300 | else | |
301 | " finding device" diag-crtype | |
302 | find-device-fcode | |
303 | then | |
304 | >r >r | |
305 | dma-free dma-free | |
306 | r@ ( port speed usb-adr fcode-adr ) ( R: f-len f-adr ) | |
307 | -rot >r >r swap | |
308 | encode-unit r> r> | |
309 | make-child | |
310 | r> r> dma-free \ toss fcode; only at probe time | |
311 | " node made" diag-crtype | |
312 | true ( no-retry ) | |
313 | ; | |
314 | ||
315 | \ give a device two chances. if not enumerated ok after two tries, make a | |
316 | \ bad device node. leave open the option for other actions, depending on the | |
317 | \ precise failure. | |
318 | : probe-port ( port -- ) | |
319 | 2 0 do | |
320 | dup clean-port | |
321 | dup dup port-low-speed? \ bug 6261224, for Cypress hub chip | |
322 | probe-once | |
323 | if leave then | |
324 | loop | |
325 | dup port-low-speed? | |
326 | complete-probe | |
327 | ; | |
328 | ||
329 | : probe-ports ( -- ) | |
330 | #ports 1+ 1 do | |
331 | i power-port \ leave port on -- possible hot-plug | |
332 | i port-connected? if \ unpowered is not connected | |
333 | i probe-port | |
334 | then | |
335 | loop | |
336 | ; | |
337 | ||
338 | \ looks like not needed | |
339 | : read-power-bits ( hub-descript -- ) drop ; | |
340 | ||
341 | : read-my-data ( -- went-ok? ) \ read descriptors and figure out what's what | |
342 | 0max-packet to max-packet | |
343 | speed my-usb-addr get-dev-descrip ( dadr dcnt hw-err? | stat 0 ) | |
344 | ?dup if | |
345 | drop | |
346 | dma-free | |
347 | " disabled" encode-string " status" property | |
348 | false exit | |
349 | else stall-or-nak? if | |
350 | dma-free | |
351 | " disabled" encode-string " status" property | |
352 | false exit | |
353 | then | |
354 | then | |
355 | over d-descript-maxpkt c@ to 0max-packet | |
356 | \ would need endpt descriptor for max packet for endpt. <> 0 | |
357 | dma-free | |
358 | 0max-packet to max-packet | |
359 | 7 get-hub-descript \ get the real descript size | |
360 | ?dup if | |
361 | drop | |
362 | drop \ common-buffer; no dma-free here | |
363 | " disabled" encode-string " status" property | |
364 | false exit | |
365 | else stall-or-nak? if | |
366 | drop \ common-buffer; no dma-free here | |
367 | " disabled" encode-string " status" property | |
368 | false exit | |
369 | then | |
370 | then | |
371 | h-descript-len c@ get-hub-descript | |
372 | ?dup if | |
373 | drop | |
374 | drop \ common-buffer; no dma-free here | |
375 | " disabled" encode-string " status" property | |
376 | false exit | |
377 | else stall-or-nak? if | |
378 | drop \ common-buffer; no dma-free here | |
379 | " disabled" encode-string " status" property | |
380 | false exit | |
381 | then | |
382 | then | |
383 | dup h-descript-#ports c@ to #ports | |
384 | dup read-power-bits | |
385 | h-descript-power-on c@ 2* to power-on-time | |
386 | true | |
387 | ; | |
388 | ||
389 | \ XXX hub status data -- 32 bits or so | |
390 | \ port status data -- 32 bits or so | |
391 | ||
392 | \ probe deeper if recurse? is not 0. involves a dependency on main OBP. | |
393 | \ this word works with max-recursion in the host adapter fcode, and with | |
394 | \ onboard-usb-max-depth and onboard-usb-recurse? in SUNW,builtin-drivers. | |
395 | : go-deeper? ( -- recurse? ) | |
396 | " onboard-usb-recurse?" | |
397 | " SUNW,builtin-drivers" find-package drop \ must be present | |
398 | find-method if | |
399 | execute 0<> | |
400 | else true \ default to go deeper | |
401 | then | |
402 | ; | |
403 | ||
404 | : power-on ( -- ) | |
405 | /request dma-alloc to request-blank \ get memory | |
406 | /common-buffer dma-alloc to common-buffer | |
407 | read-my-data go-deeper? and if | |
408 | unpower-ports \ magic | |
409 | probe-ports | |
410 | then | |
411 | common-buffer /common-buffer dma-free \ free memory | |
412 | -1 to common-buffer | |
413 | request-blank /request dma-free | |
414 | -1 to request-blank | |
415 | ; | |
416 | ||
417 | power-on |