Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb-devices / interface / requests.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: 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 ============================================
42id: @(#)requests.fth 1.5 00/05/09
43purpose:
44copyright: Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved
45
46: request-blank ( -- addr ) /request dma-alloc ;
47
48: descript-form ( len -- addr )
49 request-blank
50 get-descript-req over request-type w!
51 swap over req-len le-w!
52;
53
54: get-dev-descript-form ( len -- addr )
55 descript-form
56 device-descript over req-value 1+ c!
57;
58
59: get-config-descript-form ( len -- addr )
60 descript-form
61 config-descript over req-value 1+ c! \ need index as well
62;
63
64: get-dev-descrip ( speed usb-adr -- dev-descrip-addr dcnt hw-err? | stat 0 )
65 0 swap 0max-packet swap
66 /dev-descriptor dma-alloc
67 dup >r swap
68 /dev-descriptor swap
69 /dev-descriptor get-dev-descript-form
70 dup >r swap
71 /request swap
72 0 swap execute-control
73 r> /request dma-free
74 ?dup
75 r> /dev-descriptor
76 2swap
77 0= if 0 then
78;
79
80: get-config-descrip ( speed usb-adr n cnt
81 -- config-n-descrip-addr cnt hw-err? | stat 0 )
82 swap rot >r >r >r ( R: usb-addr n cnt )
83 0 0max-packet
84 r@ dma-alloc ( speed in max c-d-addr )
85 r> r> r> ( speed in max c-d-addr cnt n u-addr )
86 2over >r >r >r >r ( R: cnt c-addr u-addr n )
87 dup get-config-descript-form
88 r> over req-value c! ( speed in max c-addr cnt pak-adr )
89 r> over >r >r ( R: cnt config-desc packet-addr usb-addr )
90 /request 0 r> execute-control
91 r> /request dma-free
92 ?dup
93 r> r>
94 2swap
95 0= if 0 then
96;
97
98\ XXX keyboard/mouse respond with expected stuff at 1
99: get-config1-descrip ( speed usb-adr
100 -- config1-descrip-addr ccnt hw-err? | stat 0 )
101 0 /config-descriptor get-config-descrip
102;
103
104: .usb ( stat -- )
105 case 2 of noop endof
106 6 of cr ." usb-nak" endof
107 e of cr ." usb-stall" endof
108 cr ." usb-unknown"
109 endcase
110;
111
112: stall-or-nak? ( stat -- stall-or-nak? )
113 dup .usb \ XXX debug
114 dup e = swap 6 = or
115;
116
117: idump ( adr cnt -- ) \ XXX debug
118 " dump" $find drop execute
119;
120
121\ get config1 descriptor for total count
122\ get the entire config1 descriptor. copy interfacen descriptor to buffer
123: get-int#-descriptor ( speed usb-adr i#
124 -- intn-descrip-addr icnt hw-err? | stat 0 )
125 " interface get-config1" diag-crtype \ XXX debug
126 >r 2dup get-config1-descrip
127 ( spd usb-adr c1-adr ccnt hw-err? | stat 0 ) ( R: i# )
128 dup if \ hw-err found; already printed
129 r> drop
130 >r 2swap 2drop r>
131 exit
132 else
133 over stall-or-nak? if
134 r> drop
135 2rot 2drop
136 exit
137 else 2drop \ ok so far
138 then
139 then
140\ cr 2dup idump \ XXX debug
141 over c-descript-total le-w@ \ count of total descriptor
142 -rot dma-free ( speed u-adr c-total ) ( R: i# )
143\ XXX keyboard/mouse respond with expected stuff at 1
144 " interface get-config-all" diag-crtype \ XXX debug
145 0 swap
146 get-config-descrip \ get entire config1 descriptor
147 dup if \ hw-err; already printed
148 r> drop
149 exit
150 else
151 over stall-or-nak? if
152 r> drop
153 exit
154 else 2drop \ went ok; status replaced below
155 then
156 then
157\ cr 2dup idump \ XXX debug
158 2dup r> find-int-start ( c-addr ccnt i-addr ccnt2 )
159 dup dma-alloc over >r dup >r ( R: icnt intn-descrip-addr )
160 swap move ( c-addr ccnt )
161 dma-free
162 r> r>
163 2 0 \ dummy good status replacement
164;
165
166: clear-stall ( speed endpoint usb-adr -- hw-err? | stat 0 )
167 >r
168 request-blank >r
169 clear-feature-req h# 200 or r@ request-type w!
170 endpoint-stall r@ req-value le-w!
171 r@ req-index le-w!
172 1 0max-packet 0 0
173 r> /request
174 0 r> 2over >r >r
175 execute-control
176 r> r> dma-free
177;