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.3 07/06/22 | |
43 | purpose: EHCI USB Controller bulk pipes transaction processing | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ See license at end of file | |
46 | ||
47 | hex | |
48 | headers | |
49 | ||
50 | d# 500 instance value bulk-in-timeout | |
51 | d# 6000 constant bulk-out-timeout | |
52 | ||
53 | 0 instance value bulk-in-pipe | |
54 | 0 instance value bulk-out-pipe | |
55 | ||
56 | 0 instance value bulk-in-qh | |
57 | 0 instance value bulk-in-qtd | |
58 | ||
59 | : bulk-in-data@ ( -- n ) bulk-in-pipe target di-in-data@ di-data>td-data ; | |
60 | : bulk-out-data@ ( -- n ) bulk-out-pipe target di-out-data@ di-data>td-data ; | |
61 | : bulk-in-data! ( n -- ) td-data>di-data bulk-in-pipe target di-in-data! ; | |
62 | : bulk-out-data! ( n -- ) td-data>di-data bulk-out-pipe target di-out-data! ; | |
63 | : toggle-bulk-in-data ( -- ) bulk-in-pipe target di-in-data-toggle ; | |
64 | : toggle-bulk-out-data ( -- ) bulk-out-pipe target di-out-data-toggle ; | |
65 | : fixup-bulk-in-data ( qh -- data ) | |
66 | usb-error USB_ERR_STALL and if | |
67 | drop bulk-in-pipe h# 80 or unstall-pipe | |
68 | TD_TOGGLE_DATA0 | |
69 | else | |
70 | >hcqh-overlay >hcqtd-token le-l@ | |
71 | then | |
72 | bulk-in-data! | |
73 | ; | |
74 | : fixup-bulk-out-data ( qh -- data ) | |
75 | usb-error USB_ERR_STALL and if | |
76 | drop bulk-out-pipe unstall-pipe | |
77 | TD_TOGGLE_DATA0 | |
78 | else | |
79 | >hcqh-overlay >hcqtd-token le-l@ | |
80 | then | |
81 | bulk-out-data! | |
82 | ; | |
83 | ||
84 | : process-bulk-args ( buf len pipe timeout -- ) | |
85 | to timeout | |
86 | clear-usb-error | |
87 | set-my-dev | |
88 | set-my-char | |
89 | 2dup hcd-map-in to my-buf-phys to /my-buf to my-buf | |
90 | ; | |
91 | ||
92 | : alloc-bulk-qhqtds ( -- qh qtd ) | |
93 | my-buf-phys /my-buf cal-#qtd dup to my-#qtds | |
94 | alloc-qhqtds | |
95 | ; | |
96 | ||
97 | : fill-bulk-io-qtds ( dir qtd -- ) | |
98 | my-#qtds 0 do ( dir qtd ) | |
99 | my-buf my-buf-phys /my-buf 3 pick fill-qtd-bptrs | |
100 | ( dir qtd /bptr ) | |
101 | 2 pick over d# 16 << or ( dir qtd /bptr token ) | |
102 | TD_C_ERR3 or TD_STAT_ACTIVE or ( dir qtd /bptr token' ) | |
103 | 3 pick TD_PID_IN = if ( dir qtd /bptr token' ) | |
104 | bulk-in-data@ toggle-bulk-in-data | |
105 | else | |
106 | bulk-out-data@ toggle-bulk-out-data | |
107 | then or ( dir qtd /bptr token' ) | |
108 | 2 pick >hcqtd-token le-l! ( dir qtd /bptr ) | |
109 | my-buf++ ( dir qtd ) | |
110 | dup fixup-last-qtd ( dir qtd ) | |
111 | >qtd-next l@ ( dir qtd' ) | |
112 | loop 2drop ( ) | |
113 | ; | |
114 | ||
115 | external | |
116 | ||
117 | : set-bulk-in-timeout ( t -- ) ?dup if to bulk-in-timeout then ; | |
118 | ||
119 | : begin-bulk-in ( buf len pipe -- ) | |
120 | debug? if ." begin-bulk-in" cr then | |
121 | bulk-in-qh if 3drop exit then \ Already started | |
122 | ||
123 | dup to bulk-in-pipe | |
124 | bulk-in-timeout process-bulk-args | |
125 | alloc-bulk-qhqtds to bulk-in-qtd to bulk-in-qh | |
126 | ||
127 | \ IN qTDs | |
128 | TD_PID_IN bulk-in-qtd fill-bulk-io-qtds | |
129 | ||
130 | \ Start bulk in transaction | |
131 | bulk-in-qh pt-bulk fill-qh | |
132 | bulk-in-qh insert-qh | |
133 | ; | |
134 | ||
135 | : bulk-in? ( -- actual usberr ) | |
136 | bulk-in-qh 0= if 0 USB_ERR_INV_OP exit then | |
137 | clear-usb-error | |
138 | bulk-in-qh dup sync-qhqtds | |
139 | qh-done? if | |
140 | bulk-in-qh error? if | |
141 | 0 | |
142 | else | |
143 | bulk-in-qtd dup bulk-in-qh >qh-#qtds l@ get-actual | |
144 | over >qtd-buf rot >qtd-pbuf l@ 2 pick dma-sync | |
145 | then | |
146 | usb-error | |
147 | bulk-in-qh fixup-bulk-in-data | |
148 | \ XXX Ethernet does not like process-hc-status! | |
149 | \ process-hc-status | |
150 | else | |
151 | 0 usb-error | |
152 | then | |
153 | ; | |
154 | ||
155 | headers | |
156 | : restart-bulk-in-qtd ( qtd -- ) | |
157 | begin ?dup while | |
158 | dup >hcqtd-bptr0 dup le-l@ h# ffff.f000 and swap le-l! | |
159 | dup >qtd-/buf l@ d# 16 << | |
160 | TD_STAT_ACTIVE or TD_C_ERR3 or TD_PID_IN or | |
161 | bulk-in-data@ or toggle-bulk-in-data | |
162 | over >hcqtd-token le-l! | |
163 | >qtd-next l@ | |
164 | repeat | |
165 | ; | |
166 | ||
167 | external | |
168 | : restart-bulk-in ( -- ) | |
169 | debug? if ." restart-bulk-in" cr then | |
170 | bulk-in-qh 0= if exit then | |
171 | ||
172 | \ Setup qTD again | |
173 | bulk-in-qtd restart-bulk-in-qtd | |
174 | ||
175 | \ Setup QH again | |
176 | bulk-in-qh >hcqh-endp-char dup le-l@ QH_TD_TOGGLE invert and swap le-l! | |
177 | bulk-in-qtd >qtd-phys l@ bulk-in-qh >hcqh-overlay >hcqtd-next le-l! | |
178 | bulk-in-qh sync-qhqtds | |
179 | ; | |
180 | ||
181 | : end-bulk-in ( -- ) | |
182 | debug? if ." end-bulk-in" cr then | |
183 | bulk-in-qh 0= if exit then | |
184 | bulk-in-qtd map-out-bptrs | |
185 | bulk-in-qh dup fixup-bulk-in-data | |
186 | dup remove-qh free-qhqtds | |
187 | 0 to bulk-in-qh 0 to bulk-in-qtd | |
188 | ; | |
189 | ||
190 | : bulk-in ( buf len pipe -- actual usberr ) | |
191 | debug? if ." bulk-in" cr then | |
192 | dup to bulk-in-pipe | |
193 | bulk-in-timeout process-bulk-args | |
194 | alloc-bulk-qhqtds to my-qtd to my-qh | |
195 | ||
196 | \ IN qTDs | |
197 | TD_PID_IN my-qtd fill-bulk-io-qtds | |
198 | ||
199 | \ Start bulk in transaction | |
200 | my-qh pt-bulk fill-qh | |
201 | my-qh insert-qh | |
202 | ||
203 | \ Process results | |
204 | my-qh done? if | |
205 | 0 ( actual ) \ System error, timeout | |
206 | else | |
207 | my-qh error? if | |
208 | 0 ( actual ) \ USB error | |
209 | else | |
210 | my-qtd dup my-#qtds get-actual ( qtd actual ) | |
211 | over >qtd-buf l@ rot >qtd-pbuf l@ 2 pick dma-sync ( actual ) | |
212 | then | |
213 | then | |
214 | ||
215 | usb-error ( actual usberr ) | |
216 | my-qtd map-out-bptrs | |
217 | my-qh dup fixup-bulk-in-data | |
218 | dup remove-qh free-qhqtds | |
219 | ; | |
220 | ||
221 | : bulk-out ( buf len pipe -- usberr ) | |
222 | debug? if ." bulk-out" cr then | |
223 | dup to bulk-out-pipe | |
224 | bulk-out-timeout process-bulk-args | |
225 | alloc-bulk-qhqtds to my-qtd to my-qh | |
226 | ||
227 | \ OUT qTDs | |
228 | TD_PID_OUT my-qtd fill-bulk-io-qtds | |
229 | ||
230 | \ Start bulk out transaction | |
231 | my-qh pt-bulk fill-qh | |
232 | my-qh insert-qh | |
233 | ||
234 | \ Process results | |
235 | my-qh done? 0= if my-qh error? drop then | |
236 | ||
237 | usb-error ( actual usberr ) | |
238 | my-qtd map-out-bptrs | |
239 | my-qh dup fixup-bulk-out-data | |
240 | dup remove-qh free-qhqtds | |
241 | ; | |
242 | ||
243 | headers | |
244 | ||
245 | : (end-extra) ( -- ) end-bulk-in ; | |
246 | ||
247 | ||
248 | \ LICENSE_BEGIN | |
249 | \ Copyright (c) 2006 FirmWorks | |
250 | \ | |
251 | \ Permission is hereby granted, free of charge, to any person obtaining | |
252 | \ a copy of this software and associated documentation files (the | |
253 | \ "Software"), to deal in the Software without restriction, including | |
254 | \ without limitation the rights to use, copy, modify, merge, publish, | |
255 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
256 | \ permit persons to whom the Software is furnished to do so, subject to | |
257 | \ the following conditions: | |
258 | \ | |
259 | \ The above copyright notice and this permission notice shall be | |
260 | \ included in all copies or substantial portions of the Software. | |
261 | \ | |
262 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
263 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
264 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
265 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
266 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
267 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
268 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
269 | \ | |
270 | \ LICENSE_END |