Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb2 / hcd / 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: Common USB control pipe API
44\ See license at end of file
45
46hex
47headers
48
49: setup-buf-arg ( -- sbuf sphy slen ) setup-buf setup-buf-phys /dr ;
50: cfg-buf-arg ( -- cbuf cphy ) cfg-buf cfg-buf-phys ;
51
52: fill-setup-buf ( len idx value rtype req -- )
53 setup-buf dup /dr erase ( len idx value rtype req vpcbp )
54 tuck >dr-request c! ( len idx value rtype vpcbp )
55 tuck >dr-rtype c! ( len idx value vpcbp )
56 tuck >dr-value le-w! ( len idx vpcbp )
57 tuck >dr-index le-w! ( len vpcbp )
58 >dr-len le-w! ( )
59 setup-buf setup-buf-phys /dr dma-sync ( )
60;
61
62external
63: control-get ( adr len idx value rtype req -- actual usberr )
64 4 pick >r ( adr len idx value rtype req ) ( R: len )
65 fill-setup-buf ( adr ) ( R: len )
66 setup-buf-arg cfg-buf-arg r@ (control-get) ( adr actual usberr ) ( R: len )
67 dup if
68 r> drop nip nip 0 swap ( actual usberr )
69 else
70 -rot r> min tuck cfg-buf -rot move swap ( actual usberr )
71 then
72;
73
74: control-set ( adr len idx value rtype req -- usberr )
75 5 pick ?dup if cfg-buf 6 pick move then ( adr len idx value rtype req )
76 4 pick >r ( adr ) ( R: len )
77 fill-setup-buf drop ( ) ( R: len )
78 setup-buf-arg cfg-buf-arg r> (control-set) ( usberr )
79;
80
81: control-set-nostat ( adr len idx value rtype req -- usberr )
82 5 pick ?dup if cfg-buf 6 pick move then ( adr len idx value rtype req )
83 4 pick >r ( adr ) ( R: len )
84 fill-setup-buf drop ( ) ( R: len )
85 setup-buf-arg cfg-buf-arg r> (control-set-nostat) ( usberr )
86;
87
88headers
89
90: set-address ( dev -- usberr )
91 \ To get the right characteristics for dev in control-set, then normal
92 \ set-my-dev is nooped. We set my-dev and my-real-dev here instead.
93 ['] set-my-dev behavior swap ( xt dev ) \ Save set-my-dev
94 ['] noop to set-my-dev ( xt dev ) \ Make it noop
95 dup >r ( xt dev ) ( R: dev )
96 0 set-real-dev ( xt ) ( R: dev )
97
98 0 0 0 r@ DR_OUT DR_DEVICE or SET_ADDRESS control-set if
99 ." Failed to set device address: " r> u. cr
100 else
101 r> drop
102 d# 10 ms \ Let the SET_ADDRESS settle
103 then ( xt )
104
105 to set-my-dev \ Restore set-my-dev
106 usb-error
107;
108
109external
110
111: get-desc ( adr len lang didx dtype rtype -- actual usberr )
112 -rot bwjoin swap DR_IN or GET_DESCRIPTOR control-get
113;
114
115: get-status ( adr len intf/endp rtype -- actual usberr )
116 0 swap DR_IN or GET_STATUS control-get
117;
118
119: set-config ( cfg -- usberr )
120 >r 0 0 0 r> DR_DEVICE DR_OUT or SET_CONFIGURATION control-set
121;
122
123: set-interface ( alt intf -- usberr )
124 0 0 2swap DR_INTERFACE DR_OUT or SET_INTERFACE control-set
125;
126
127: clear-feature ( intf/endp feature rtype -- usberr )
128 >r 0 0 2swap r> DR_OUT or CLEAR_FEATURE control-set
129;
130: set-feature ( intf/endp feature rtype -- usberr )
131 >r 0 0 2swap r> DR_OUT or SET_FEATURE control-set
132;
133
134: set-pipe-maxpayload ( size pipe -- )
135 target di-maxpayload!
136;
137
138headers
139
140: (unstall-pipe) ( pipe -- ) 0 DR_ENDPOINT clear-feature drop ;
141' (unstall-pipe) to unstall-pipe
142
143: get-cfg-desc ( adr idx -- actual )
144 swap >r ( idx ) ( R: adr )
145 r@ 9 0 3 pick CONFIGURATION DR_DEVICE get-desc nip 0= if
146 r> dup 2 + le-w@ rot 0 swap CONFIGURATION DR_DEVICE get-desc drop ( actual )
147 else
148 r> 2drop 0 ( actual )
149 then
150;
151: get-dev-desc ( adr len -- actual )
152 0 0 DEVICE DR_DEVICE get-desc drop ( actual )
153;
154: (get-str-desc) ( adr len lang idx -- actual )
155 STRING DR_DEVICE get-desc drop ( actual )
156;
157: get-str-desc ( adr lang idx -- actual )
158 3dup 2 -rot (get-str-desc) 0= if 3drop 0 exit then \ Read the length
159 >r 2dup r> ( adr lang adr lang idx )
160 2 pick c@ -rot (get-str-desc) 0= if 2drop 0 exit then \ Then read the whole string
161 ( adr lang )
162 encoded$>ascii$ ( )
163;
164
165headers
166
167\ LICENSE_BEGIN
168\ Copyright (c) 2006 FirmWorks
169\
170\ Permission is hereby granted, free of charge, to any person obtaining
171\ a copy of this software and associated documentation files (the
172\ "Software"), to deal in the Software without restriction, including
173\ without limitation the rights to use, copy, modify, merge, publish,
174\ distribute, sublicense, and/or sell copies of the Software, and to
175\ permit persons to whom the Software is furnished to do so, subject to
176\ the following conditions:
177\
178\ The above copyright notice and this permission notice shall be
179\ included in all copies or substantial portions of the Software.
180\
181\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
182\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
183\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
184\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
185\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
186\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
187\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
188\
189\ LICENSE_END