Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: hub-requests.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-requests.fth 1.9 02/04/10 | |
43 | purpose: | |
44 | copyright: Copyright 1998-2002 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | -1 instance value request-blank ( -- addr ) \ XXX assumes can be allocated at open | |
48 | -1 instance value common-buffer ( -- addr ) \ XXX ditto; also assumes it will be | |
49 | \ large enough | |
50 | 1000 constant /common-buffer \ XXX is it large enough? too large? | |
51 | ||
52 | d# 64 instance value child-max ( -- n ) \ use to talk to child device endpt 0 | |
53 | ||
54 | \ XXX The following is for 2.0 hubs; benign for 1.0 hubs | |
55 | d# 64 value 0max-packet ( -- n ) \ for my endpoint 0; from descriptor; | |
56 | \ global ok | |
57 | ||
58 | d# 64 instance value max-packet ( -- n ) \ must be set before usb transactions | |
59 | ||
60 | : clean-request-blank ( -- addr ) | |
61 | request-blank /request erase | |
62 | request-blank | |
63 | ; | |
64 | ||
65 | : clean-common-buffer ( -- addr ) | |
66 | common-buffer /common-buffer erase | |
67 | common-buffer | |
68 | ; | |
69 | ||
70 | : descript-form ( len -- addr ) | |
71 | clean-request-blank | |
72 | get-descript-req over request-type w! | |
73 | swap over req-len le-w! | |
74 | ; | |
75 | ||
76 | : get-dev-descript-form ( len -- addr ) | |
77 | descript-form | |
78 | device-descript over req-value 1+ c! | |
79 | ; | |
80 | ||
81 | : get-config-descript-form ( len -- addr ) | |
82 | descript-form | |
83 | config-descript over req-value 1+ c! \ need index as well | |
84 | ; | |
85 | ||
86 | : set-address-form ( usb-addr -- addr ) | |
87 | clean-request-blank | |
88 | set-address-req over request-type w! | |
89 | swap over req-value le-w! | |
90 | ; | |
91 | ||
92 | : speed ( -- low-speed? ) \ could do once and save | |
93 | " low-speed" get-my-property if | |
94 | false | |
95 | else 2drop true | |
96 | then | |
97 | ; | |
98 | ||
99 | : my-usb-addr ( -- usb-addr ) \ could do once and save | |
100 | " assigned-address" get-inherited-property if | |
101 | " No assigned-address property" diag-crtype \ XXX for debugging; | |
102 | \ totally bad situation | |
103 | else decode-int nip nip | |
104 | then | |
105 | ; | |
106 | ||
107 | \ No data transfer, hub only, endpoint 0: | |
108 | : simple-control ( req-addr -- hw-err? | stat 0 ) | |
109 | max-packet >r | |
110 | 0max-packet to max-packet | |
111 | >r | |
112 | speed 1 | |
113 | max-packet 0 0 | |
114 | r> /request | |
115 | 0 my-usb-addr | |
116 | execute-control | |
117 | r> to max-packet | |
118 | ; | |
119 | ||
120 | \ Always uses common-buffer, hub only, endpoint 0: | |
121 | : data-in-control ( req-addr len -- addr hw-err? | addr stat 0 ) | |
122 | max-packet >r | |
123 | 0max-packet to max-packet | |
124 | swap >r >r | |
125 | clean-common-buffer | |
126 | speed 0 \ data in transfer | |
127 | max-packet | |
128 | common-buffer r> | |
129 | r> /request | |
130 | 0 my-usb-addr | |
131 | execute-control | |
132 | r> to max-packet | |
133 | ; | |
134 | ||
135 | \ Submit requests over USB, so these all turn into USB transactions, | |
136 | \ all to endpoint 0 via control transfers: | |
137 | ||
138 | : clear-hub-feature ( feature# -- hw-err? | stat 0 ) | |
139 | clean-request-blank | |
140 | clear-hub-feature-req over request-type w! | |
141 | swap over req-value le-w! ( req-addr ) | |
142 | simple-control | |
143 | ; | |
144 | ||
145 | : clear-port-feature ( feature# port# -- hw-err? | stat 0 ) | |
146 | clean-request-blank | |
147 | clear-port-feature-req over request-type w! | |
148 | swap over req-index le-w! | |
149 | swap over req-value le-w! ( req-addr ) | |
150 | simple-control | |
151 | ; | |
152 | ||
153 | : get-hub-descript ( len -- addr hw-err? | addr stat 0 ) | |
154 | dup >r | |
155 | clean-request-blank \ fill request blank | |
156 | get-hub-descript-req over request-type w! | |
157 | swap over req-len le-w! | |
158 | hub-descript over req-value 1+ c! ( req-addr ) ( R: len ) | |
159 | r> data-in-control | |
160 | ; | |
161 | ||
162 | : get-hub-status ( -- addr hw-err? | addr stat 0 ) | |
163 | clean-request-blank | |
164 | get-hub-status-req over request-type w! | |
165 | 4 over req-len le-w! ( req-addr ) | |
166 | 4 data-in-control | |
167 | ; | |
168 | ||
169 | : get-port-status ( port# -- addr hw-err? | addr stat 0 ) | |
170 | clean-request-blank | |
171 | get-port-status-req over request-type w! | |
172 | 4 over req-len le-w! | |
173 | swap over req-index le-w! ( req-addr ) | |
174 | 4 data-in-control | |
175 | ; | |
176 | ||
177 | \ : set-hub-feature ( XXX -- XXX ) | |
178 | \ ; | |
179 | ||
180 | : set-port-feature ( feature# port# -- hw-err? | stat 0 ) | |
181 | clean-request-blank | |
182 | set-port-feature-req over request-type w! | |
183 | swap over req-index le-w! | |
184 | swap over req-value le-w! | |
185 | simple-control | |
186 | ; | |
187 | ||
188 | \ status change endpoint 1 is interrupt. It reports the hub and port | |
189 | \ status change bitmap, 11.8.3, at max polling interval ff. | |
190 | ||
191 | \ For error recovery -- stalls | |
192 | \ endp* is endpoint number with direction bit in high order bit. | |
193 | \ In = 1; | |
194 | \ Out = 0 | |
195 | \ status bytes left at addr. uses common-buffer | |
196 | : endpoint-status ( endp* -- addr hw-err? | addr stat 0 ) | |
197 | >r | |
198 | clean-common-buffer | |
199 | get-status-req h# 200 or clean-request-blank request-type w! | |
200 | r@ request-blank req-index le-w! | |
201 | 2 request-blank req-len le-w! ( buf-adr ) ( R: endp* ) | |
202 | speed 0 max-packet common-buffer 2 | |
203 | request-blank /request | |
204 | r> 0f and \ cut off direction bit | |
205 | my-usb-addr | |
206 | execute-control | |
207 | ; | |
208 | ||
209 | : stalled? ( endp* -- stalled? ) | |
210 | endpoint-status | |
211 | ?dup 2drop | |
212 | le-w@ 1 and | |
213 | ; | |
214 | ||
215 | \ For debugging. Force an endpoint stall. | |
216 | \ uses request-blank | |
217 | : stall-endpoint ( endpoint -- hw-err? | stat 0 ) | |
218 | set-feature-req h# 200 or clean-request-blank request-type w! | |
219 | endpoint-stall request-blank req-value le-w! | |
220 | dup request-blank req-index le-w! | |
221 | >r | |
222 | speed 1 max-packet 0 0 \ no data transfer | |
223 | request-blank /request | |
224 | r> my-usb-addr | |
225 | execute-control | |
226 | ; | |
227 | ||
228 | \ must set max-packet before using. | |
229 | \ uses request-blank; no dma-free needed | |
230 | : clear-stall ( speed endpoint usb-adr -- hw-err? | stat 0 ) | |
231 | >r | |
232 | clear-feature-req h# 200 or clean-request-blank request-type w! | |
233 | endpoint-stall request-blank req-value le-w! | |
234 | request-blank req-index le-w! | |
235 | 1 max-packet 0 0 \ no data transfer | |
236 | request-blank /request | |
237 | 0 r> | |
238 | execute-control | |
239 | ; |