Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: device.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: @(#)device.fth 1.1 07/01/04 | |
43 | purpose: USB device node | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ See license at end of file | |
46 | ||
47 | hex | |
48 | headers | |
49 | ||
50 | defer make-dev-property-hook ( speed dev port -- ) | |
51 | ' 3drop to make-dev-property-hook | |
52 | ||
53 | \ Buffers for descriptor manipulation | |
54 | 0 value cfg-desc-buf \ Configuration Descriptor | |
55 | 0 value dev-desc-buf \ Device Descriptor | |
56 | 0 value gen-desc-buf \ Any Descriptor | |
57 | 0 value d$-desc-buf \ Device String Descriptor | |
58 | 0 value v$-desc-buf \ Vendor String Descriptor | |
59 | 0 value s$-desc-buf \ Serial Number String Descriptor | |
60 | ||
61 | 0 value /cfg-desc-buf \ Length of data in cfg-desc-buf | |
62 | 0 value /dev-desc-buf \ Length of data in dev-desc-buf | |
63 | 0 value /d$-desc-buf \ Length of data in d$-desc-buf | |
64 | 0 value /v$-desc-buf \ Length of data in v$-desc-buf | |
65 | 0 value /s$-desc-buf \ Length of data in s$-desc-buf | |
66 | ||
67 | : alloc-pkt-buf ( -- ) | |
68 | cfg-desc-buf 0= if | |
69 | /cfg alloc-mem dup to cfg-desc-buf /cfg erase | |
70 | /cfg alloc-mem dup to dev-desc-buf /cfg erase | |
71 | /cfg alloc-mem dup to gen-desc-buf /cfg erase | |
72 | /str alloc-mem dup to d$-desc-buf /str erase | |
73 | /str alloc-mem dup to v$-desc-buf /str erase | |
74 | /str alloc-mem dup to s$-desc-buf /str erase | |
75 | then | |
76 | ; | |
77 | : free-pkt-buf ( -- ) | |
78 | cfg-desc-buf ?dup if /cfg free-mem 0 to cfg-desc-buf then | |
79 | dev-desc-buf ?dup if /cfg free-mem 0 to dev-desc-buf then | |
80 | gen-desc-buf ?dup if /cfg free-mem 0 to gen-desc-buf then | |
81 | d$-desc-buf ?dup if /str free-mem 0 to d$-desc-buf then | |
82 | v$-desc-buf ?dup if /str free-mem 0 to v$-desc-buf then | |
83 | s$-desc-buf ?dup if /str free-mem 0 to s$-desc-buf then | |
84 | ; | |
85 | ||
86 | : make-class-properties ( intf -- ) | |
87 | dev-desc-buf cfg-desc-buf rot ( dev-buf cfg-buf intf ) | |
88 | get-class ( class subclass protocol ) | |
89 | " protocol" int-property | |
90 | " subclass" int-property | |
91 | " class" int-property | |
92 | ; | |
93 | ||
94 | : make-name-property ( -- ) | |
95 | get-class-properties ( class subclass protocol ) | |
96 | swap rot ( protocol subclass class ) | |
97 | case | |
98 | 1 of 2drop " audio" endof ( name$ ) | |
99 | 2 of 2drop " network" endof ( name$ ) | |
100 | 3 of case | |
101 | 1 of case | |
102 | 1 of " keyboard" endof | |
103 | 2 of " mouse" endof | |
104 | 4 of " joystick" endof | |
105 | 5 of " gamepad" endof | |
106 | 39 of " hatswitch" endof | |
107 | ( default ) " device" rot | |
108 | endcase | |
109 | endof | |
110 | ( default ) nip " hid" rot | |
111 | endcase | |
112 | endof | |
113 | 7 of 2drop " printer" endof ( name$ ) | |
114 | 8 of case | |
115 | 1 of drop " flash" endof | |
116 | 2 of drop " cdrom" endof | |
117 | 3 of drop " tape" endof | |
118 | 4 of drop " floppy" endof | |
119 | 5 of drop " storage" endof | |
120 | 6 of drop " storage" endof | |
121 | ( default ) nip " storage" rot | |
122 | endcase | |
123 | endof | |
124 | 9 of 2drop " hub" endof ( name$ ) | |
125 | ( default ) nip nip " device" rot ( name$ ) | |
126 | endcase | |
127 | device-name | |
128 | ; | |
129 | ||
130 | : make-vendor-properties ( -- ) | |
131 | dev-desc-buf get-vid ( vendor product rev ) | |
132 | " release" int-property | |
133 | " device-id" int-property | |
134 | " vendor-id" int-property | |
135 | ; | |
136 | ||
137 | \ A little tool so "make-compatible-property" reads better | |
138 | 0 value sadr | |
139 | 0 value slen | |
140 | : +$ ( add$ -- ) | |
141 | sadr slen 2swap encode-string encode+ to slen to sadr | |
142 | ; | |
143 | : usb,class#> ( n -- ) " usb,class" $hold 0 u#> ; \ Prepends: usb,class | |
144 | : #usb,class#> ( n -- ) u#s drop usb,class#> ; \ Prepends: usb,classN | |
145 | : usbif#> ( n -- ) " usbif" $hold 0 u#> ; \ Prepends: usbif | |
146 | : #usbif#> ( n -- ) u#s drop usbif#> ; \ Prepends: usbifN | |
147 | : usbif,class#> ( n -- ) " usbif,class" $hold 0 u#> ; \ Prepends: usbif,class | |
148 | : #usbif,class#> ( n -- ) u#s drop usbif,class#> ; \ Prepends: usbif,classN | |
149 | : #class, ( n -- ) u#s drop " ,class" $hold ; \ Prepends: class,N | |
150 | ||
151 | : make-compatible-property ( -- ) | |
152 | 0 0 encode-bytes to slen to sadr \ Initial empty string | |
153 | ||
154 | push-hex | |
155 | ||
156 | get-vendor-properties ( vendor product rev ) | |
157 | 3dup <# #. #, #usb#> +$ ( v p r ) \ usbV,product.rev | |
158 | drop 2dup <# #, #usb#> +$ ( v p ) \ usbV,product | |
159 | drop ( vendor ) | |
160 | ||
161 | get-class-properties ( vendor class subclass protocol ) | |
162 | 2 pick 0<> if ( vendor class subclass protocol ) | |
163 | class-in-dev? if | |
164 | 4dup <# #. #. #class, #usb#> +$ ( v c s p ) \ usbV,classC.S.P | |
165 | 4dup drop <# #. #class, #usb#> +$ ( v c s p ) \ usbV,classC,S | |
166 | 4dup 2drop <# #class, #usb#> +$ ( v c s p ) \ usbV,classC | |
167 | 3dup <# #. #. #usb,class#> +$ ( v c s p ) \ usb,classC.S.P | |
168 | 2 pick 2 pick <# #. #usb,class#> +$ ( v c s p ) \ usb,classC,S | |
169 | 2 pick <# #usb,class#> +$ ( v c s p ) \ usb,classC | |
170 | else | |
171 | 4dup <# #. #. #class, #usbif#> +$ ( v c s p ) \ usbifV,classC.S.P | |
172 | 4dup drop <# #. #class, #usbif#> +$ ( v c s p ) \ usbifV,classC,S | |
173 | 4dup 2drop <# #class, #usbif#> +$ ( v c s p ) \ usbifV,classC | |
174 | 3dup <# #. #. #usbif,class#> +$ ( v c s p ) \ usbif,classC.S.P | |
175 | 2 pick 2 pick <# #. #usbif,class#> +$ ( v c s p ) \ usbif,classC,S | |
176 | 2 pick <# #usbif,class#> +$ ( v c s p ) \ usbif,classC | |
177 | then | |
178 | then ( vendor class subclass protocol ) | |
179 | 4drop ( ) | |
180 | " usb,device" +$ | |
181 | sadr slen " compatible" property | |
182 | pop-base | |
183 | ; | |
184 | ||
185 | : make-string-properties ( -- ) | |
186 | v$-desc-buf /v$-desc-buf " vendor$" str-property | |
187 | d$-desc-buf /d$-desc-buf " device$" str-property | |
188 | s$-desc-buf /s$-desc-buf " serial$" str-property | |
189 | ; | |
190 | ||
191 | : make-misc-properties ( -- ) | |
192 | cfg-desc-buf 5 + c@ " configuration#" int-property | |
193 | ; | |
194 | ||
195 | : register-pipe ( pipe size -- ) | |
196 | swap h# 0f and ( size pipe' ) | |
197 | " assigned-address" get-my-property 0= if | |
198 | decode-int nip nip di-maxpayload! ( ) | |
199 | else | |
200 | 2drop | |
201 | then | |
202 | ; | |
203 | ||
204 | : make-ctrl-pipe-property ( pipe size interval -- ) | |
205 | drop 2dup register-pipe ( pipe size ) | |
206 | over h# f and rot h# 80 and if ( size pipe ) | |
207 | " control-in-pipe" int-property | |
208 | " control-in-size" | |
209 | else | |
210 | " control-out-pipe" int-property | |
211 | " control-out-size" | |
212 | then int-property | |
213 | ; | |
214 | : make-iso-pipe-property ( pipe size interval -- ) | |
215 | drop 2dup register-pipe ( pipe size ) | |
216 | over h# 0f and rot h# 80 and if ( size pipe ) | |
217 | " iso-in-pipe" int-property | |
218 | " iso-in-size" | |
219 | else | |
220 | " iso-out-pipe" int-property | |
221 | " iso-out-size" | |
222 | then int-property | |
223 | ; | |
224 | : make-bulk-pipe-property ( pipe size interval -- ) | |
225 | drop 2dup register-pipe ( pipe size ) | |
226 | over h# f and rot h# 80 and if ( size pipe ) | |
227 | " bulk-in-pipe" int-property | |
228 | " bulk-in-size" | |
229 | else | |
230 | " bulk-out-pipe" int-property | |
231 | " bulk-out-size" | |
232 | then int-property | |
233 | ; | |
234 | : make-intr-pipe-property ( pipe size interval -- ) | |
235 | -rot 2dup register-pipe rot ( pipe size interval ) | |
236 | rot dup h# f and swap h# 80 and if ( size interval pipe ) | |
237 | " intr-in-pipe" int-property | |
238 | " intr-in-interval" int-property | |
239 | " intr-in-size" | |
240 | else | |
241 | " intr-out-pipe" int-property | |
242 | " intr-out-interval" int-property | |
243 | " intr-out-size" | |
244 | then int-property | |
245 | ; | |
246 | : make-pipe-properties ( adr -- ) | |
247 | dup c@ over + swap 4 + c@ ( adr' #endpoints ) | |
248 | swap ENDPOINT find-desc swap 0 ?do ( adr' ) | |
249 | dup 2 + c@ ( adr pipe ) | |
250 | over 4 + le-w@ ( adr pipe size ) | |
251 | 2 pick 6 + c@ ( adr pipe size interval ) | |
252 | 3 pick 3 + c@ 3 and case ( adr pipe size interval type ) | |
253 | 0 of make-ctrl-pipe-property endof | |
254 | 1 of make-iso-pipe-property endof | |
255 | 2 of make-bulk-pipe-property endof | |
256 | 3 of make-intr-pipe-property endof | |
257 | endcase | |
258 | dup c@ + ( adr' ) | |
259 | loop drop | |
260 | ; | |
261 | ||
262 | : make-descriptor-properties ( intf -- ) | |
263 | dup make-class-properties \ Must make class properties first | |
264 | make-name-property ( intf ) | |
265 | make-vendor-properties ( intf ) | |
266 | make-compatible-property \ Must come after vendor and class | |
267 | make-string-properties ( intf ) | |
268 | cfg-desc-buf swap find-intf-desc ( adr ) | |
269 | make-pipe-properties ( ) | |
270 | make-misc-properties | |
271 | ; | |
272 | ||
273 | : make-common-properties ( dev -- ) | |
274 | 1 " #address-cells" int-property | |
275 | 0 " #size-cells" int-property | |
276 | \ SUN Note - Modified for single-cell unit-address | |
277 | my-space encode-phys " reg" property \ my-space=port | |
278 | dup " assigned-address" int-property | |
279 | ( dev ) di-speed@ case | |
280 | speed-low of " low-speed" endof | |
281 | speed-full of " full-speed" endof | |
282 | ( default ) " high-speed" rot | |
283 | endcase | |
284 | 0 0 2swap str-property | |
285 | ; | |
286 | ||
287 | : make-combined-node ( dev port -- ) | |
288 | dup >r encode-unit " " 2swap new-device set-args ( dev )( R: port ) | |
289 | dup dup di-speed@ swap r> make-dev-property-hook ( dev ) | |
290 | make-common-properties \ Make non-descriptor based properties | |
291 | 0 make-descriptor-properties \ Combined has single interface, use 0. | |
292 | load-fcode-driver \ Find and load fcode driver | |
293 | finish-device | |
294 | ; | |
295 | ||
296 | \ Get all the descriptors we need in making properties now because target is | |
297 | \ questionable in the child's context. | |
298 | ||
299 | h# 409 constant language \ Unicode id | |
300 | : get-string ( lang idx adr -- actual ) | |
301 | over 0= if 3drop 0 exit then \ No string index | |
302 | -rot get-str-desc | |
303 | ; | |
304 | : get-str-descriptors ( -- ) | |
305 | language ( lang ) | |
306 | dup dev-desc-buf d# 14 + c@ v$-desc-buf get-string to /v$-desc-buf | |
307 | dup dev-desc-buf d# 15 + c@ d$-desc-buf get-string to /d$-desc-buf | |
308 | dev-desc-buf d# 16 + c@ s$-desc-buf get-string to /s$-desc-buf | |
309 | ; | |
310 | : refresh-desc-bufs ( -- ) | |
311 | dev-desc-buf 12 get-dev-desc to /dev-desc-buf \ Refresh dev-desc-buf | |
312 | cfg-desc-buf 0 get-cfg-desc to /cfg-desc-buf \ Refresh cfg-desc-buf | |
313 | get-str-descriptors | |
314 | ; | |
315 | ||
316 | : set-maxpayload ( dev -- ) | |
317 | dev-desc-buf /pipe0 get-dev-desc if | |
318 | dev-desc-buf 7 + c@ 0 rot di-maxpayload! | |
319 | else | |
320 | drop | |
321 | then | |
322 | ; | |
323 | ||
324 | ||
325 | : make-device-node ( port dev -- ) | |
326 | dup set-maxpayload ( port dev ) | |
327 | cfg-desc-buf 0 get-cfg-desc dup to /cfg-desc-buf | |
328 | 0= if 2drop exit then | |
329 | swap ( dev port ) | |
330 | cfg-desc-buf 4 + c@ ( dev port ifaces ) | |
331 | dup 1 = if | |
332 | \ Create a combined node | |
333 | drop over set-target ( dev port ) \ Refresh target | |
334 | refresh-desc-bufs ( dev port ) | |
335 | make-combined-node ( ) \ one-based port# | |
336 | ||
337 | else ( dev port ifaces ) | |
338 | \ Create a device node and interface nodes | |
339 | over encode-unit " " 2swap new-device set-args ( dev port ifaces ) | |
340 | ||
341 | \ Create generic "device" properties and bring in generic device driver | |
342 | " device" encode-string " name" property | |
343 | " usbdevice" encode-string " compatible" property | |
344 | 2 encode-int " #address-cells" property | |
345 | 0 encode-int " #size-cells" property | |
346 | over encode-int " reg" property ( dev port ifaces ) | |
347 | ||
348 | load-fcode-driver ( dev port ifaces ) | |
349 | ||
350 | ||
351 | \ Loop creating each interface under device node | |
352 | ( ifaces ) 0 ?do ( dev port ) | |
353 | over set-target \ Refresh target | |
354 | refresh-desc-bufs ( dev port ) | |
355 | 0 i " encode-unit" $call-self ( dev port $unit-address ) | |
356 | " " 2swap new-device set-args ( dev port ) | |
357 | dup >r over dup di-speed@ swap r> make-dev-property-hook | |
358 | my-address my-space encode-phys " reg" property | |
359 | over " assigned-address" int-property ( dev port ) | |
360 | over di-speed@ case ( dev port ) | |
361 | speed-low of " low-speed" endof | |
362 | speed-full of " full-speed" endof | |
363 | ( default ) " high-speed" rot | |
364 | endcase ( dev port $speed ) | |
365 | 0 0 2swap str-property ( dev port ) | |
366 | my-space make-descriptor-properties \ Make descriptor based properties | |
367 | load-fcode-driver \ Find and load fcode driver | |
368 | finish-device ( dev port ) | |
369 | loop ( dev port ) | |
370 | 2drop ( ) | |
371 | finish-device | |
372 | then | |
373 | ; | |
374 | ||
375 | headers | |
376 | ||
377 | \ LICENSE_BEGIN | |
378 | \ Copyright (c) 2006 FirmWorks | |
379 | \ | |
380 | \ Permission is hereby granted, free of charge, to any person obtaining | |
381 | \ a copy of this software and associated documentation files (the | |
382 | \ "Software"), to deal in the Software without restriction, including | |
383 | \ without limitation the rights to use, copy, modify, merge, publish, | |
384 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
385 | \ permit persons to whom the Software is furnished to do so, subject to | |
386 | \ the following conditions: | |
387 | \ | |
388 | \ The above copyright notice and this permission notice shall be | |
389 | \ included in all copies or substantial portions of the Software. | |
390 | \ | |
391 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
392 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
393 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
394 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
395 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
396 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
397 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
398 | \ | |
399 | \ LICENSE_END |