Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: bulk.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: @(#)bulk.fth 1.1 07/01/24 | |
43 | purpose: OHCI USB Controller bulk pipes transaction processing | |
44 | \ See license at end of file | |
45 | ||
46 | hex | |
47 | headers | |
48 | ||
49 | d# 500 instance value bulk-in-timeout | |
50 | d# 500 constant bulk-out-timeout | |
51 | ||
52 | 0 instance value bulk-in-pipe | |
53 | 0 instance value bulk-out-pipe | |
54 | ||
55 | 0 instance value bulk-in-ed \ Instance variables for begin-bulk-in, bulk-in?, | |
56 | 0 instance value bulk-in-td \ restart-bulk-in and end-bulk-in. | |
57 | ||
58 | : disable-bulk ( -- ) 20 hc-cntl-clr next-frame 0 28 ohci-reg! ; | |
59 | : enable-bulk ( -- ) | |
60 | ed-bulk >ed-phys l@ 28 ohci-reg! \ Set HcBulkHeadED | |
61 | 4 hc-cmd! \ Mark TD added in bulk list | |
62 | 20 hc-cntl-set \ Enable bulk list processing | |
63 | ; | |
64 | ||
65 | : insert-bulk ( ed -- ) | |
66 | ed-bulk if disable-bulk then | |
67 | ( ed ) insert-bulk-ed | |
68 | enable-bulk | |
69 | ; | |
70 | : remove-bulk ( ed -- ) | |
71 | disable-bulk | |
72 | ( ed ) remove-bulk-ed | |
73 | ed-bulk if enable-bulk then | |
74 | ; | |
75 | ||
76 | : bulk-in-data@ ( -- n ) bulk-in-pipe target di-in-data@ di-data>ed-data ; | |
77 | : bulk-out-data@ ( -- n ) bulk-out-pipe target di-out-data@ di-data>ed-data ; | |
78 | : bulk-in-data! ( n -- ) ed-data>di-data bulk-in-pipe target di-in-data! ; | |
79 | : bulk-out-data! ( n -- ) ed-data>di-data bulk-out-pipe target di-out-data! ; | |
80 | : fixup-bulk-in-data ( ed -- ) | |
81 | usb-error USB_ERR_STALL and if | |
82 | drop bulk-in-pipe h# 80 or unstall-pipe | |
83 | ED_TOGGLE_DATA0 | |
84 | else | |
85 | >hced-tdhead le-l@ | |
86 | then | |
87 | bulk-in-data! | |
88 | ; | |
89 | : fixup-bulk-out-data ( ed -- ) | |
90 | usb-error USB_ERR_STALL and if | |
91 | drop bulk-out-pipe unstall-pipe | |
92 | ED_TOGGLE_DATA0 | |
93 | else | |
94 | >hced-tdhead le-l@ | |
95 | then | |
96 | bulk-out-data! | |
97 | ; | |
98 | ||
99 | : process-bulk-args ( buf len pipe timeout -- ) | |
100 | to timeout | |
101 | clear-usb-error | |
102 | set-my-dev | |
103 | ( pipe ) set-my-char | |
104 | 2dup hcd-map-in to my-buf-phys to /my-buf to my-buf | |
105 | ; | |
106 | : alloc-bulk-edtds ( -- ed td ) | |
107 | /my-buf if 2 else 1 then | |
108 | ( #tds ) alloc-edtds | |
109 | ; | |
110 | : fill-bulk-io-tds ( td -- ) | |
111 | /my-buf ?dup 0= if drop exit then ( td len ) | |
112 | over >td-/cbp-all l! ( td ) | |
113 | TD_CC_NOTACCESSED TD_INTR_OFF or TD_ROUND_ON or TD_TOGGLE_USE_ED or | |
114 | ( td control ) | |
115 | fill-io-tds | |
116 | ; | |
117 | : fill-bulk-ed ( dir ed -- ) | |
118 | over my-dev/pipe or my-speed or ED_SKIP_OFF or ED_FORMAT_G or | |
119 | my-maxpayload d# 16 << or | |
120 | over >hced-control le-l! | |
121 | ( ed ) dup >hced-tdhead le-l@ ( dir ed head ) | |
122 | rot ED_DIR_IN = if bulk-in-data@ else bulk-out-data@ then or | |
123 | over >hced-tdhead le-l! ( ed ) | |
124 | ( ed ) sync-edtds | |
125 | ; | |
126 | : insert-my-bulk ( ed dir -- ) over fill-bulk-ed insert-bulk ; | |
127 | : insert-my-bulk-in ( ed -- ) ED_DIR_IN insert-my-bulk ; | |
128 | : insert-my-bulk-out ( ed -- ) ED_DIR_OUT insert-my-bulk ; | |
129 | : remove-my-bulk ( ed -- ) dup remove-bulk free-edtds ; | |
130 | ||
131 | external | |
132 | ||
133 | : set-bulk-in-timeout ( t -- ) ?dup if to bulk-in-timeout then ; | |
134 | ||
135 | : begin-bulk-in ( buf len pipe -- ) | |
136 | debug? if ." begin-bulk-in" cr then | |
137 | bulk-in-ed if 3drop exit then \ Already started | |
138 | ||
139 | dup to bulk-in-pipe | |
140 | bulk-in-timeout process-bulk-args | |
141 | alloc-bulk-edtds to bulk-in-td to bulk-in-ed | |
142 | ||
143 | \ IN TD | |
144 | bulk-in-td fill-bulk-io-tds | |
145 | ||
146 | \ Start bulk in transaction | |
147 | bulk-in-ed insert-my-bulk-in | |
148 | ; | |
149 | ||
150 | : bulk-in? ( -- actual usberr ) | |
151 | bulk-in-ed 0= if 0 USB_ERR_INV_OP exit then | |
152 | clear-usb-error ( ) | |
153 | process-hc-status ( ) | |
154 | bulk-in-ed dup sync-edtds ( ed ) | |
155 | ed-done? if ( ) | |
156 | bulk-in-td error? if | |
157 | 0 ( actual ) | |
158 | else | |
159 | bulk-in-td dup get-actual ( td actual ) | |
160 | over >td-cbp l@ rot >td-pcbp l@ 2 pick dma-sync ( actual ) | |
161 | then | |
162 | usb-error ( actual usberr ) | |
163 | bulk-in-ed fixup-bulk-in-data ( actual usberr ) | |
164 | else | |
165 | 0 usb-error ( actual usberr ) | |
166 | then | |
167 | ; | |
168 | ||
169 | headers | |
170 | : restart-bulk-in-td ( td -- ) | |
171 | begin ?dup while | |
172 | dup >td-next l@ if | |
173 | TD_CC_NOTACCESSED TD_DIR_IN or TD_INTR_OFF or TD_ROUND_ON or | |
174 | over >hctd-control le-l! | |
175 | dup >td-pcbp l@ over >hctd-cbp le-l! | |
176 | dup >td-next l@ >td-phys l@ over >hctd-next le-l! | |
177 | then | |
178 | >td-next l@ | |
179 | repeat | |
180 | ; | |
181 | ||
182 | external | |
183 | : restart-bulk-in ( -- ) | |
184 | debug? if ." restart-bulk-in" cr then | |
185 | bulk-in-ed 0= if exit then | |
186 | bulk-in-ed ed-set-skip | |
187 | ||
188 | \ Setup TD again | |
189 | bulk-in-td restart-bulk-in-td | |
190 | ||
191 | \ Setup ED again | |
192 | bulk-in-td >td-phys l@ bulk-in-data@ or bulk-in-ed >hced-tdhead le-l! | |
193 | bulk-in-ed dup sync-edtds | |
194 | ed-unset-skip | |
195 | enable-bulk | |
196 | ; | |
197 | ||
198 | : end-bulk-in ( -- ) | |
199 | debug? if ." end-bulk-in" cr then | |
200 | bulk-in-ed 0= if exit then | |
201 | bulk-in-td map-out-cbp | |
202 | bulk-in-ed remove-my-bulk | |
203 | 0 to bulk-in-ed 0 to bulk-in-td | |
204 | ; | |
205 | ||
206 | : bulk-in ( buf len pipe -- actual usberr ) | |
207 | debug? if ." bulk-in" cr then | |
208 | dup to bulk-in-pipe | |
209 | bulk-in-timeout process-bulk-args ( ) | |
210 | alloc-bulk-edtds to my-td to my-ed ( ) | |
211 | ||
212 | \ IN TDs | |
213 | my-td fill-bulk-io-tds ( ) | |
214 | ||
215 | \ Start bulk in transaction | |
216 | my-ed insert-my-bulk-in ( ) | |
217 | ||
218 | \ Process results | |
219 | my-ed done? if | |
220 | 0 ( actual ) \ System error, timeout | |
221 | else | |
222 | my-td error? if | |
223 | 0 ( actual ) \ USB error | |
224 | else | |
225 | my-td dup get-actual ( td actual ) | |
226 | over >td-cbp l@ rot >td-pcbp l@ 2 pick dma-sync ( actual ) | |
227 | then | |
228 | then | |
229 | ||
230 | usb-error ( actual usberr ) | |
231 | my-ed dup fixup-bulk-in-data ( actual usberr ed ) | |
232 | my-td map-out-cbp ( actual usberr ed ) | |
233 | remove-my-bulk ( actual usberr ) | |
234 | ; | |
235 | ||
236 | : bulk-out ( buf len pipe -- usberr ) | |
237 | debug? if ." bulk-out" cr then | |
238 | dup to bulk-out-pipe | |
239 | bulk-out-timeout process-bulk-args | |
240 | alloc-bulk-edtds to my-td to my-ed | |
241 | ||
242 | \ OUT TDs | |
243 | my-td fill-bulk-io-tds | |
244 | ||
245 | \ Start bulk out transaction | |
246 | my-ed insert-my-bulk-out | |
247 | ||
248 | \ Process results | |
249 | my-ed done? 0= if my-td error? drop then | |
250 | ||
251 | usb-error ( actual usberr ) | |
252 | my-ed dup fixup-bulk-out-data | |
253 | my-td map-out-cbp | |
254 | remove-my-bulk | |
255 | ; | |
256 | ||
257 | headers | |
258 | ||
259 | : (end-extra) ( -- ) end-bulk-in ; | |
260 | ||
261 | ||
262 | \ LICENSE_BEGIN | |
263 | \ Copyright (c) 2006 FirmWorks | |
264 | \ | |
265 | \ Permission is hereby granted, free of charge, to any person obtaining | |
266 | \ a copy of this software and associated documentation files (the | |
267 | \ "Software"), to deal in the Software without restriction, including | |
268 | \ without limitation the rights to use, copy, modify, merge, publish, | |
269 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
270 | \ permit persons to whom the Software is furnished to do so, subject to | |
271 | \ the following conditions: | |
272 | \ | |
273 | \ The above copyright notice and this permission notice shall be | |
274 | \ included in all copies or substantial portions of the Software. | |
275 | \ | |
276 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
277 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
278 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
279 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
280 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
281 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
282 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
283 | \ | |
284 | \ LICENSE_END |