Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: ehci.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: @(#)ehci.fth 1.1 07/01/24 | |
43 | purpose: Driver for EHCI USB Controller | |
44 | \ See license at end of file | |
45 | ||
46 | hex | |
47 | headers | |
48 | ||
49 | defer init-extra ' noop to init-extra | |
50 | defer end-extra ' noop to end-extra | |
51 | ||
52 | true value first-open? | |
53 | 0 value open-count | |
54 | 0 value ehci-reg | |
55 | 0 value op-reg-offset | |
56 | ||
57 | h# 100 constant /regs | |
58 | ||
59 | \ Configuration space registers | |
60 | my-address my-space encode-phys | |
61 | 0 encode-int encode+ 0 encode-int encode+ | |
62 | \ EHCI operational registers | |
63 | 0 0 my-space 0200.0010 + encode-phys encode+ | |
64 | 0 encode-int encode+ /regs encode-int encode+ | |
65 | " reg" property | |
66 | ||
67 | : map-regs ( -- ) | |
68 | 4 my-w@ 6 or 4 my-w! | |
69 | 0 0 my-space h# 0200.0010 + /regs map-in to ehci-reg | |
70 | ; | |
71 | : unmap-regs ( -- ) | |
72 | 4 my-w@ 7 invert and 4 my-w! | |
73 | ehci-reg /regs map-out 0 to ehci-reg | |
74 | ; | |
75 | ||
76 | : ehci-reg@ ( idx -- data ) ehci-reg + rl@ ; | |
77 | : ehci-reg! ( data idx -- ) ehci-reg + rl! ; | |
78 | ||
79 | : ll ( idx -- ) dup h# f and 0= if cr 2 u.r ." " else drop then ; | |
80 | : dump-ehci ( -- ) 100 0 do i ll i ehci-reg@ 8 u.r space 4 +loop ; | |
81 | ||
82 | \ Host controller capability registers | |
83 | : hcsparams@ ( -- data ) 4 ehci-reg@ ; | |
84 | : hccparams@ ( -- data ) 8 ehci-reg@ ; | |
85 | : (hcsp-portroute@) ( -- d.lo,hi ) h# c ehci-reg@ h# 10 ehci-reg@ ; | |
86 | : hcsp-portroute@ ( port -- data ) | |
87 | (hcsp-portroute@) rot | |
88 | dup >r 7 > if 8 - nip else drop then r> | |
89 | 4 * >> h# f and | |
90 | ; | |
91 | ||
92 | \ Host Controller operational registers | |
93 | : op-reg@ ( idx -- data ) op-reg-offset + ehci-reg@ ; | |
94 | : op-reg! ( data idx -- ) op-reg-offset + ehci-reg! ; | |
95 | ||
96 | : usbcmd@ ( -- data ) 0 op-reg@ ; | |
97 | : usbcmd! ( data -- ) 0 op-reg! ; | |
98 | : flush-reg ( -- ) usbcmd@ drop ; | |
99 | : usbsts@ ( -- data ) 4 op-reg@ ; | |
100 | : usbsts! ( data -- ) 4 op-reg! flush-reg ; | |
101 | : usbintr@ ( -- data ) 8 op-reg@ ; | |
102 | : usbintr! ( data -- ) 8 op-reg! ; | |
103 | : frindex@ ( -- data ) h# c op-reg@ ; | |
104 | : frindex! ( data -- ) h# c op-reg! ; | |
105 | : ctrldsseg@ ( -- data ) h# 10 op-reg@ ; | |
106 | : ctrldsseg! ( data -- ) h# 10 op-reg! ; | |
107 | : periodic@ ( -- data ) h# 14 op-reg@ ; | |
108 | : periodic! ( data -- ) h# 14 op-reg! ; | |
109 | : asynclist@ ( -- data ) h# 18 op-reg@ ; | |
110 | : asynclist! ( data -- ) h# 18 op-reg! ; | |
111 | ||
112 | : cfgflag@ ( -- data ) h# 40 op-reg@ ; | |
113 | : cfgflag! ( data -- ) h# 40 op-reg! flush-reg ; | |
114 | : portsc@ ( port -- data ) 4 * h# 44 + op-reg@ ; | |
115 | : portsc! ( data port -- ) 4 * h# 44 + op-reg! flush-reg ; | |
116 | ||
117 | : halted? ( -- flag ) usbsts@ h# 1000 and ; | |
118 | : halt-wait ( -- ) begin halted? until ; | |
119 | ||
120 | : process-hc-status ( -- ) | |
121 | usbsts@ dup usbsts! \ Clear interrupts and errors | |
122 | h# 10 and if " Host system error" USB_ERR_HCHALTED set-usb-error then | |
123 | ; | |
124 | ||
125 | : doorbell-wait ( -- ) | |
126 | begin usbsts@ h# 20 and until \ Wait until interrupt on async advance bit is set | |
127 | h# 20 usbsts! \ Clear status | |
128 | ; | |
129 | : ring-doorbell ( -- ) | |
130 | usbcmd@ h# 40 or usbcmd! \ Interrupt on async advance doorbell | |
131 | usbcmd@ drop | |
132 | doorbell-wait | |
133 | ; | |
134 | ||
135 | external | |
136 | ||
137 | : start-usb ( -- ) | |
138 | ehci-reg dup 0= if map-regs then | |
139 | halted? if usbcmd@ 1 or usbcmd! then | |
140 | 0= if unmap-regs then | |
141 | ; | |
142 | ||
143 | : stop-usb ( -- ) | |
144 | ehci-reg dup 0= if map-regs then | |
145 | usbcmd@ 31 invert and usbcmd! | |
146 | halt-wait | |
147 | 0= if unmap-regs then | |
148 | ; | |
149 | ||
150 | : reset-usb ( -- ) | |
151 | ehci-reg dup 0= if map-regs then | |
152 | usbcmd@ 2 or 1 invert and usbcmd! \ HCReset | |
153 | d# 10 0 do | |
154 | usbcmd@ 2 and 0= ?leave | |
155 | 1 ms | |
156 | loop | |
157 | 0= if unmap-regs then | |
158 | ; | |
159 | ||
160 | : test-port-begin ( port -- ) | |
161 | ehci-reg dup 0= if map-regs then | |
162 | swap dup portsc@ h# 4.0000 or swap portsc! | |
163 | 0= if unmap-regs then | |
164 | ; | |
165 | ||
166 | : test-port-end ( port -- ) | |
167 | ehci-reg dup 0= if map-regs then | |
168 | swap dup portsc@ h# 7.0000 invert and swap portsc! | |
169 | 0= if unmap-regs then | |
170 | ; | |
171 | ||
172 | headers | |
173 | ||
174 | : init-ehci-regs ( -- ) | |
175 | 0 ctrldsseg! | |
176 | 0 periodic! | |
177 | 0 asynclist! | |
178 | 0 usbintr! | |
179 | ; | |
180 | ||
181 | : reset-port ( port -- ) | |
182 | dup portsc@ h# 100 or 4 invert and over portsc! \ Reset port | |
183 | d# 50 ms | |
184 | dup portsc@ h# 100 invert and swap portsc! | |
185 | d# 10 ms | |
186 | ; | |
187 | ||
188 | : power-port ( port -- ) dup portsc@ h# 1000 or swap portsc! 2 ms ; | |
189 | ||
190 | : disown-port ( port -- ) dup portsc@ h# 2000 or swap portsc! ; | |
191 | ||
192 | : claim-ownership ( -- ) | |
193 | 1 cfgflag! \ Claim ownership to all ports | |
194 | 1 ms | |
195 | ||
196 | \ Power on ports if necessary | |
197 | hcsparams@ h# 10 and if | |
198 | hcsparams@ h# f and 0 ?do | |
199 | i power-port | |
200 | loop | |
201 | then | |
202 | ; | |
203 | ||
204 | external | |
205 | : open ( -- flag ) | |
206 | parse-my-args | |
207 | open-count 0= if | |
208 | map-regs | |
209 | first-open? if | |
210 | false to first-open? | |
211 | 0 ehci-reg@ h# ff and to op-reg-offset | |
212 | reset-usb | |
213 | init-ehci-regs | |
214 | start-usb | |
215 | claim-ownership | |
216 | init-struct | |
217 | init-extra | |
218 | then | |
219 | alloc-dma-buf | |
220 | then | |
221 | open-count 1+ to open-count | |
222 | true | |
223 | ; | |
224 | ||
225 | : close ( -- ) | |
226 | open-count 1- to open-count | |
227 | end-extra | |
228 | open-count 0= if free-dma-buf unmap-regs then | |
229 | ; | |
230 | ||
231 | headers | |
232 | ||
233 | \ LICENSE_BEGIN | |
234 | \ Copyright (c) 2006 FirmWorks | |
235 | \ | |
236 | \ Permission is hereby granted, free of charge, to any person obtaining | |
237 | \ a copy of this software and associated documentation files (the | |
238 | \ "Software"), to deal in the Software without restriction, including | |
239 | \ without limitation the rights to use, copy, modify, merge, publish, | |
240 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
241 | \ permit persons to whom the Software is furnished to do so, subject to | |
242 | \ the following conditions: | |
243 | \ | |
244 | \ The above copyright notice and this permission notice shall be | |
245 | \ included in all copies or substantial portions of the Software. | |
246 | \ | |
247 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
248 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
249 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
250 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
251 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
252 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
253 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
254 | \ | |
255 | \ LICENSE_END |