Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb2 / hcd / ohci / control.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: control.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 ============================================
42id: @(#)control.fth 1.1 07/01/24
43purpose: OHCI USB Controller transaction processing
44\ See license at end of file
45
46hex
47headers
48
49: disable-control ( -- ) 10 hc-cntl-clr next-frame 0 20 ohci-reg! ;
50: enable-control ( -- )
51 ed-control >ed-phys l@ 20 ohci-reg! \ set HcControlHeadED
52 2 hc-cmd! \ mark TD added in control list
53 10 hc-cntl-set \ enable control list processing
54;
55
56: insert-control ( ed -- )
57 ed-control if disable-control then
58 ( ed ) insert-control-ed
59 enable-control
60;
61: remove-control ( ed -- )
62 disable-control
63 ( ed ) remove-control-ed
64 ed-control if enable-control then
65;
66
67\ Local temporary variables (common for control, bulk & interrupt)
68
69\ my-dev and my-real-dev are created here to deal with set-address.
70\ Normally my-dev and my-real-dev are both of the value of target.
71\ However, during set-address, target=my-dev=0, my-real-dev is the
72\ address to be assigned to my-real-dev. The correct path to get
73\ a device's characteristics is via my-real-dev.
74
750 value my-dev \ Equals to target
760 value my-real-dev \ Path to device's characteristics
770 value my-dev/pipe \ Device/pipe for ED
78
790 value my-speed \ Speed of my-real-dev
800 value my-maxpayload \ Pipe's max payload
81
820 value my-buf \ Virtual address of data buffer
830 value my-buf-phys \ Physical address of data buffer
840 value /my-buf \ Size of data buffer
85
860 value my-td \ Current TD head
870 value my-ed \ Current ED
88
89: set-real-dev ( real-dev target -- ) \ For set-address only
90 to my-dev to my-real-dev
91;
92: set-normal-dev ( -- ) \ Normal operation
93 target dup to my-dev to my-real-dev
94;
95defer set-my-dev ' set-normal-dev to set-my-dev
96
97: set-my-char ( pipe -- ) \ Set device's characteristics
98 dup 7 << my-dev or to my-dev/pipe ( pipe )
99 my-real-dev dup di-speed@ ( pipe dev speed )
100 speed-full = if ED_SPEED_FULL else ED_SPEED_LO then to my-speed
101 ( pipe dev )
102 di-maxpayload@ to my-maxpayload ( )
103;
104: process-control-args ( buf phy len -- )
105 to /my-buf to my-buf-phys to my-buf
106 clear-usb-error
107 set-my-dev
108 0 set-my-char
109;
110
111: alloc-control-edtds ( extra-tds -- )
112 /my-buf if 1+ data-timeout else nodata-timeout then to timeout
113 alloc-edtds to my-td to my-ed
114;
115
116: fill-setup-td ( sbuf sphy slen control -- )
117 TD_CC_NOTACCESSED or TD_DIR_SETUP or TD_INTR_OFF or TD_TOGGLE_USE_LSB0 or
118 my-td >hctd-control le-l!
119 over + 1- my-td >hctd-be le-l!
120 ( sphy ) my-td 2dup >hctd-cbp le-l!
121 ( sphy ) >td-pcbp l!
122 ( sbuf ) my-td >td-cbp l!
123;
124
125: fill-io-tds ( td control -- )
126 over >hctd-control le-l!
127 my-buf over >td-cbp l!
128 my-buf-phys over 2dup >hctd-cbp le-l!
129 >td-pcbp l!
130 my-buf-phys /my-buf + 1- swap >hctd-be le-l!
131;
132: fill-control-io-tds ( dir -- std )
133 my-td >td-next l@ ( dir td )
134 /my-buf 0= if nip exit then ( dir td )
135 dup rot ( td td dir )
136 TD_CC_NOTACCESSED or TD_INTR_OFF or TD_TOGGLE_USE_LSB1 or
137 ( td td control )
138 fill-io-tds ( td )
139 >td-next l@ ( std )
140;
141
142: fill-control-ed ( ed -- )
143 my-dev my-speed or ED_DIR_TD or ED_SKIP_OFF or ED_FORMAT_G or
144 my-maxpayload d# 16 << or
145 swap >hced-control le-l!
146;
147
148: insert-my-control ( -- )
149 my-ed dup fill-control-ed
150 dup sync-edtds
151 insert-control
152;
153
154: remove-my-control ( -- )
155 my-ed dup remove-control
156 free-edtds
157;
158
159
160\ ---------------------------------------------------------------------------
161\ CONTROL pipe operations
162\ ---------------------------------------------------------------------------
163
164: (control-get) ( sbuf sphy slen buf phy len -- actual usberr )
165 process-control-args ( sbuf sphy slen )
166 /my-buf 0= if 3drop 0 USB_ERR_INV_OP exit then
167 3 alloc-control-edtds ( sbuf sphy slen )
168
169 \ SETUP TD
170 TD_ROUND_ON fill-setup-td ( )
171
172 \ IN TD
173 TD_DIR_IN TD_ROUND_ON or fill-control-io-tds ( std )
174
175 \ Status TD (OUT)
176 TD_CC_NOTACCESSED TD_DIR_OUT or TD_INTR_MIN or TD_TOGGLE_USE_LSB1 or
177 TD_ROUND_ON or
178 swap >hctd-control le-l! ( )
179
180 \ Start control transaction
181 insert-my-control ( )
182
183 \ Process results
184 my-ed done? if ( )
185 0 ( actual ) \ System error, timeout
186 else
187 my-td error? if ( )
188 0 ( actual ) \ USB error
189 else
190 my-td >td-next l@ dup get-actual ( td actual )
191 over >td-cbp l@ rot >td-pcbp l@ 2 pick dma-sync ( actual )
192 then
193 then
194
195 remove-my-control ( actual )
196 usb-error ( actual usberr )
197;
198
199: (control-set) ( sbuf sphy slen buf phy len -- usberr )
200 process-control-args ( sbuf sphy slen )
201 3 alloc-control-edtds ( sbuf sphy slen )
202
203 \ SETUP TD
204 0 fill-setup-td ( )
205
206 \ OUT TD
207 TD_DIR_OUT fill-control-io-tds ( std )
208
209 \ Status TD (IN) ( std )
210 TD_CC_NOTACCESSED TD_DIR_IN or TD_INTR_MIN or TD_TOGGLE_USE_LSB1 or
211 ( TD_ROUND_ON or )
212 swap >hctd-control le-l! ( )
213
214 \ Start control transaction
215 insert-my-control
216
217 \ Process results
218 my-ed done? 0= if my-td error? drop then
219
220 remove-my-control ( )
221 usb-error ( usberr )
222;
223
224: (control-set-nostat) ( sbuf sphy slen buf phy len -- usberr )
225 process-control-args ( sbuf sphy slen )
226 2 alloc-control-edtds ( sbuf sphy slen )
227
228 \ SETUP TD
229 0 fill-setup-td ( )
230
231 \ OUT TD
232 TD_DIR_OUT fill-control-io-tds drop ( )
233
234 \ Start control transaction
235 insert-my-control ( )
236
237 \ Process results
238 my-ed done? 0= if my-td error? drop then
239
240 remove-my-control ( )
241 usb-error ( usberr )
242;
243
244headers
245
246
247\ LICENSE_BEGIN
248\ Copyright (c) 2006 FirmWorks
249\
250\ Permission is hereby granted, free of charge, to any person obtaining
251\ a copy of this software and associated documentation files (the
252\ "Software"), to deal in the Software without restriction, including
253\ without limitation the rights to use, copy, modify, merge, publish,
254\ distribute, sublicense, and/or sell copies of the Software, and to
255\ permit persons to whom the Software is furnished to do so, subject to
256\ the following conditions:
257\
258\ The above copyright notice and this permission notice shall be
259\ included in all copies or substantial portions of the Software.
260\
261\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
262\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
263\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
264\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
265\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
266\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
267\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
268\
269\ LICENSE_END