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.18 02/12/11 | |
43 | purpose: | |
44 | copyright: Copyright 1998-2002 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | : assign-address ( speed usb-addr -- hw-err? | stat 0 ) | |
48 | \ next-usb-address ?dup if | |
49 | set-address-form >r ( R: pkt-addr ) | |
50 | ( speed ) 1 max-packet 0 0 r@ /request 0 0 execute-control | |
51 | r> /request give-chunk | |
52 | \ else no-more-addresses | |
53 | \ then | |
54 | d# 10 ms \ allow assignment to take effect | |
55 | \ should need only 2 ms | |
56 | ; | |
57 | ||
58 | : set-configuration ( speed usb-addr config -- hw-err? | stat 0 ) | |
59 | 1 max-packet 2swap 0 0 2swap | |
60 | ( speed dir max-pkt dat-adr dat-len usb-addr config ) | |
61 | 0 -rot \ endpoint | |
62 | request-blank dup >r | |
63 | set-config-req over request-type w! | |
64 | swap over req-value le-w! | |
65 | /request 2swap ( speed dir max-pkt dat-adr dat-len req-adr req-len ) | |
66 | execute-control | |
67 | r> /request give-chunk | |
68 | ; | |
69 | ||
70 | : proto-get-configuration ( -- addr ) | |
71 | 1 0 max-packet | |
72 | h# 100 get-chunk dup h# 100 5a fill \ data in buffer | |
73 | dup >r | |
74 | 1 | |
75 | request-blank | |
76 | get-config-req over request-type w! | |
77 | 1 over req-len le-w! | |
78 | dup >r ( R: b-adr p-adr ) | |
79 | /request | |
80 | 0 2 execute-control | |
81 | ?dup 2drop | |
82 | r> /request give-chunk | |
83 | r> | |
84 | ; | |
85 | ||
86 | \ XXX ugly stack, very ugly. ditto for the other descrip getters | |
87 | : get-dev-descrip ( speed usb-adr -- dev-descrip-addr dcnt hw-err? | stat 0 ) | |
88 | 0 swap max-packet swap | |
89 | /dev-descriptor get-chunk | |
90 | dup >r swap | |
91 | /dev-descriptor swap | |
92 | /dev-descriptor get-dev-descript-form | |
93 | dup >r swap | |
94 | /request swap | |
95 | 0 swap execute-control | |
96 | r> /request give-chunk | |
97 | ?dup | |
98 | r> /dev-descriptor | |
99 | 2swap | |
100 | 0= if 0 then | |
101 | ; | |
102 | ||
103 | : get-config-descrip ( speed usb-adr n cnt | |
104 | -- config-n-descrip-addr cnt hw-err? | stat 0 ) | |
105 | swap rot >r >r >r ( R: usb-addr n cnt ) | |
106 | 0 max-packet | |
107 | r@ get-chunk ( speed in max c-d-addr ) | |
108 | r> r> r> ( speed in max c-d-addr cnt n u-addr ) | |
109 | 2over >r >r >r >r ( R: cnt c-addr u-addr n ) | |
110 | dup get-config-descript-form | |
111 | r> over req-value c! ( speed in max c-addr cnt pak-adr ) | |
112 | r> over >r >r ( R: cnt config-desc packet-addr usb-addr ) | |
113 | /request 0 r> execute-control | |
114 | r> /request give-chunk | |
115 | ?dup | |
116 | r> r> | |
117 | 2swap | |
118 | 0= if 0 then | |
119 | ; | |
120 | ||
121 | : get-config1-descrip ( speed usb-adr | |
122 | -- config1-descrip-addr ccnt hw-err? | stat 0 ) | |
123 | 0 /config-descriptor get-config-descrip | |
124 | ; | |
125 | ||
126 | : ?create-speed ( lo-speed? -- ) | |
127 | if 0 0 " low-speed" property then | |
128 | ; | |
129 | ||
130 | : create-address ( usb-addr -- ) | |
131 | encode-int " assigned-address" property | |
132 | ; | |
133 | ||
134 | : combined-node? ( config-desc dev-desc -- combined? ) | |
135 | dup d-descript-class c@ | |
136 | dup 9 = swap 0= or ( c-desc d-desc dev-ok? ) | |
137 | swap d-descript-#configs c@ 1 = and | |
138 | swap c-descript-#interfaces c@ 1 = and | |
139 | ; | |
140 | ||
141 | : make-child ( fcode-adr unit-str unit-len speed usb-adr -- ) | |
142 | max-packet | |
143 | new-device | |
144 | ( max-packet ) encode-int " 0max-packet" property | |
145 | create-address ?create-speed | |
146 | " " 2swap set-args | |
147 | 1 byte-load | |
148 | finish-device | |
149 | ; | |
150 | ||
151 | : .usb ( stat -- ) | |
152 | usb-debug? 0= if drop exit then | |
153 | case 2 of noop endof \ patchable | |
154 | 6 of cr ." usb-nak" endof | |
155 | e of cr ." usb-stall" endof | |
156 | cr ." usb-unknown: " dup . | |
157 | endcase | |
158 | ; | |
159 | ||
160 | : stall-or-nak? ( stat -- stall-or-nak? ) | |
161 | dup .usb | |
162 | dup 6 = swap e = or | |
163 | ; | |
164 | ||
165 | : set-default-max-packet ( speed -- ) | |
166 | if 8 to max-packet \ lo speed device | |
167 | else d# 64 to max-packet \ reg speed | |
168 | then | |
169 | ; | |
170 | ||
171 | defer complete-probe ( port speed -- ) | |
172 | ' 2drop is complete-probe \ for a good node already created | |
173 | ||
174 | \ Start with a new device at usb 0, port, and known speed (low or normal). | |
175 | \ no-retry? (non-zero) if really fatal or succeeded. retry (zero) if want to | |
176 | \ go back to reset-port | |
177 | : probe-once ( port speed -- no-retry? ) | |
178 | ['] 2drop is complete-probe \ default to good device node on each pass | |
179 | dup set-default-max-packet | |
180 | \ XXX can this delay be removed? 200 ms already in reset-port | |
181 | d# 150 ms \ wait for Microsoft devices to settle; may | |
182 | \ only be needed for hot-plugging devices | |
183 | \ book says to get device descrip here for max packet, then reset device. | |
184 | " dev-descrip" diag-crtype | |
185 | dup 0 get-dev-descrip ( port speed dev-d-addr dcnt hw-err? | stat 0 ) | |
186 | dup no-response-error = if \ wait for slow device; try again | |
187 | drop give-chunk | |
188 | over clean-port | |
189 | d# 2000 ms | |
190 | dup 0 get-dev-descrip ( port speed dev-d-addr dcnt hw-err? | stat 0 ) | |
191 | then | |
192 | ?dup if | |
193 | data-overrun-error <> if \ data-over is benign here | |
194 | give-chunk 2drop | |
195 | ['] won't-send-descriptor is complete-probe | |
196 | false exit ( retry ) | |
197 | then | |
198 | else stall-or-nak? if | |
199 | give-chunk 2drop | |
200 | ['] won't-send-descriptor is complete-probe | |
201 | false exit ( retry ) | |
202 | then | |
203 | then ( port speed dev-d-addr dcnt ) | |
204 | over d-descript-maxpkt c@ \ get max-packet | |
205 | to max-packet | |
206 | give-chunk | |
207 | over clean-port | |
208 | " next-add" diag-crtype | |
209 | next-usb-address 2dup assign-address ( port speed usb-adr hw-err? | stat 0 ) | |
210 | ?dup if | |
211 | drop \ XXX some hw-err; already printed | |
212 | drop \ XXX will use up usb-adrs | |
213 | 2drop | |
214 | ['] won't-take-address is complete-probe | |
215 | false exit ( retry ) | |
216 | else stall-or-nak? if | |
217 | drop \ XXX will use up usb-adrs | |
218 | 2drop | |
219 | ['] won't-take-address is complete-probe | |
220 | false exit ( retry ) | |
221 | then | |
222 | then ( port speed usb-adr ) | |
223 | \ XXX book says some errors can occur here that can only be detected by | |
224 | \ attempting to talk to the device. | |
225 | ||
226 | " get-config1" diag-crtype | |
227 | 2dup get-config1-descrip | |
228 | ( port spd usb-addr cnfg-addr cnt hw-err? | stat 0 ) | |
229 | ?dup if | |
230 | drop \ XXX some hw-error; already printed | |
231 | give-chunk | |
232 | drop \ XXX will use up usb-adrs | |
233 | 2drop | |
234 | ['] won't-send-config is complete-probe | |
235 | false exit ( retry ) | |
236 | else stall-or-nak? if | |
237 | give-chunk | |
238 | drop \ XXX will use up usb-adrs | |
239 | 2drop | |
240 | ['] won't-send-config is complete-probe | |
241 | false exit ( retry ) | |
242 | then | |
243 | then ( port spd usb-addr cnfg-addr cnt ) | |
244 | over c-descript-config-id c@ >r \ get config value | |
245 | give-chunk ( port spd usb-addr ) ( R: cnfg-id ) | |
246 | " set-config" diag-crtype | |
247 | 2dup r> set-configuration \ config index 1, using bConfigurationValue | |
248 | ( port spd usb-addr hw-err? | stat 0 ) | |
249 | ?dup if | |
250 | drop \ XXX some hw-error; already printed | |
251 | drop 2drop | |
252 | ['] won't-take-config is complete-probe | |
253 | true exit ( no-retry ) | |
254 | else stall-or-nak? if | |
255 | drop 2drop | |
256 | ['] won't-take-config is complete-probe | |
257 | true exit ( no-retry ) | |
258 | then | |
259 | then ( port spd usb-addr ) | |
260 | " get-config1-descript" diag-crtype | |
261 | 2dup get-config1-descrip ( port spd usb-adr cadr ccnt hw-err? | stat 0 ) | |
262 | ?dup if | |
263 | drop \ XXX some hw-error; already printed | |
264 | give-chunk | |
265 | drop 2drop | |
266 | ['] won't-send-descriptor is complete-probe | |
267 | true exit ( no-retry ) | |
268 | else stall-or-nak? if | |
269 | give-chunk | |
270 | drop 2drop | |
271 | ['] won't-send-descriptor is complete-probe | |
272 | true exit ( no-retry ) | |
273 | then | |
274 | then ( port spd usb-adr cadr ccnt ) | |
275 | " get-dev-descrip" diag-crtype | |
276 | 2over get-dev-descrip | |
277 | ( port spd usb-adr cadr ccnt dadr dcnt hw-err? | stat 0 ) | |
278 | ?dup if | |
279 | drop \ XXX some hw-error; already printed | |
280 | give-chunk give-chunk | |
281 | drop 2drop | |
282 | ['] won't-send-descriptor is complete-probe | |
283 | true exit ( no-retry ) | |
284 | else stall-or-nak? if | |
285 | give-chunk give-chunk | |
286 | drop 2drop | |
287 | ['] won't-send-descriptor is complete-probe | |
288 | true exit ( no-retry ) | |
289 | then | |
290 | then | |
291 | " descripts" diag-crtype | |
292 | ( port speed usb-adr config-desc ccnt dev-desc dcnt ) | |
293 | 3 pick 2 pick combined-node? if | |
294 | find-combined-fcode | |
295 | else | |
296 | find-device-fcode | |
297 | then | |
298 | >r >r | |
299 | give-chunk give-chunk | |
300 | r@ ( port speed usb-adr fcode-adr ) ( R: f-len f-adr ) | |
301 | -rot >r >r swap | |
302 | encode-unit r> r> | |
303 | make-child | |
304 | r> r> dma-free \ toss fcode | |
305 | " node made" diag-crtype | |
306 | true ( no-retry ) | |
307 | ; | |
308 | ||
309 | \ probe-self? $find execute? evaluate? byte-load? recurse? | |
310 | ||
311 | \ interface hub call-parents could rely on the parent to add in the | |
312 | \ speed, as they don't really have a speed. |