Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: hcd.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: @(#)hcd.fth 1.1 07/01/04 | |
43 | purpose: Generic HCD Driver | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ See license at end of file | |
46 | ||
47 | hex | |
48 | ||
49 | external | |
50 | defer unstall-pipe ( pipe -- ) ' drop to unstall-pipe | |
51 | headers | |
52 | ||
53 | d# 50 constant nodata-timeout | |
54 | d# 500 constant data-timeout | |
55 | ||
56 | : int-property ( n name$ -- ) rot encode-int 2swap property ; | |
57 | : str-property ( str$ name$ -- ) 2swap encode-string 2swap property ; | |
58 | ||
59 | " usb" device-name | |
60 | ||
61 | \ Sun note - per USB binding, must be one address cell | |
62 | 1 " #address-cells" int-property | |
63 | 0 " #size-cells" int-property | |
64 | ||
65 | \ --------------------------------------------------------------------------- | |
66 | \ Common variables | |
67 | \ --------------------------------------------------------------------------- | |
68 | ||
69 | 0 instance value target | |
70 | false value debug? | |
71 | ||
72 | \ Setup and descriptor DMA data buffers | |
73 | 0 value setup-buf \ SETUP packet buffer | |
74 | 0 value setup-buf-phys | |
75 | 0 value cfg-buf \ Descriptor packet buffer | |
76 | 0 value cfg-buf-phys | |
77 | ||
78 | : alloc-dma-buf ( -- ) | |
79 | setup-buf 0= if | |
80 | /dr dma-alloc dup to setup-buf | |
81 | /dr true dma-map-in to setup-buf-phys | |
82 | then | |
83 | cfg-buf 0= if | |
84 | /cfg dma-alloc dup to cfg-buf | |
85 | /cfg true dma-map-in to cfg-buf-phys | |
86 | then | |
87 | ; | |
88 | : free-dma-buf ( -- ) | |
89 | setup-buf if | |
90 | setup-buf setup-buf-phys /dr dma-map-out | |
91 | setup-buf /dr dma-free | |
92 | 0 to setup-buf 0 to setup-buf-phys | |
93 | then | |
94 | cfg-buf if | |
95 | cfg-buf cfg-buf-phys /cfg dma-map-out | |
96 | cfg-buf /cfg dma-free | |
97 | 0 to cfg-buf 0 to cfg-buf-phys | |
98 | then | |
99 | ; | |
100 | ||
101 | \ --------------------------------------------------------------------------- | |
102 | \ Common routines | |
103 | \ --------------------------------------------------------------------------- | |
104 | ||
105 | : my-b@ ( offset -- b ) my-space + " config-b@" $call-parent ; | |
106 | : my-b! ( b offset -- ) my-space + " config-b!" $call-parent ; | |
107 | : my-w@ ( offset -- w ) my-space + " config-w@" $call-parent ; | |
108 | : my-w! ( w offset -- ) my-space + " config-w!" $call-parent ; | |
109 | : my-l@ ( offset -- l ) my-space + " config-l@" $call-parent ; | |
110 | : my-l! ( l offset -- ) my-space + " config-l!" $call-parent ; | |
111 | ||
112 | : map-in ( phys.lo,md,hi len -- vaddr ) " map-in" $call-parent ; | |
113 | : map-out ( vaddr size -- ) " map-out" $call-parent ; | |
114 | ||
115 | \ XXX Room for improvement: keep tab of hcd-map-in's to improve performance. | |
116 | : hcd-map-in ( virt size -- phys ) false dma-map-in ; | |
117 | : hcd-map-out ( virt phys size -- ) dma-map-out ; | |
118 | ||
119 | ||
120 | : $= ( adr len adr len -- =? ) | |
121 | rot tuck <> if | |
122 | 3drop false exit | |
123 | then comp 0= | |
124 | ; | |
125 | ||
126 | : log2 ( n -- log2-of-n ) | |
127 | 0 begin ( n log ) | |
128 | swap 2/ ( log n' ) | |
129 | ?dup while ( log n' ) | |
130 | swap 1+ ( n' log' ) | |
131 | repeat ( log ) | |
132 | ; | |
133 | : exp2 ( n -- 2**n ) 1 swap 0 ?do 2* loop ; | |
134 | : interval ( interval -- interval' ) log2 exp2 ; | |
135 | ||
136 | : 3dup ( n1 n2 n3 -- n1 n2 n3 n1 n2 n3 ) 2 pick 2 pick 2 pick ; | |
137 | : 3drop ( n1 n2 n3 -- ) 2drop drop ; | |
138 | ||
139 | : 4dup ( n1 n2 n3 n4 -- n1 n2 n3 n4 n1 n2 n3 n4 ) 2over 2over ; | |
140 | : 4drop ( n1 n2 n3 n4 -- ) 2drop 2drop ; | |
141 | ||
142 | : 5dup ( n1 n2 n3 n4 n5 -- n1 n2 n3 n4 n5 n1 n2 n3 n4 n5 ) | |
143 | 4 pick 4 pick 4 pick 4 pick 4 pick | |
144 | ; | |
145 | : 5drop ( n1 n2 n3 n4 n5 -- ) 2drop 3drop ; | |
146 | ||
147 | \ --------------------------------------------------------------------------- | |
148 | \ Exported methods | |
149 | \ --------------------------------------------------------------------------- | |
150 | ||
151 | external | |
152 | ||
153 | : debug-on ( -- ) true to debug? ; | |
154 | ||
155 | : set-target ( target -- ) to target ; | |
156 | ||
157 | \ A usb device node defines an address space of the form | |
158 | \ "port,interface". port and interface are both integers. | |
159 | \ parse-2int converts a text string (e.g. "3,1") into a pair of | |
160 | \ binary integers. | |
161 | ||
162 | \ : decode-unit ( addr len -- interface port ) parse-2int ; | |
163 | \ : encode-unit ( interface port -- adr len ) | |
164 | \ >r <# u#s drop ascii , hold r> u#s u#> \ " port,interface" | |
165 | \ ; | |
166 | ||
167 | \ SUN note - per USB binding, single cell unit-address and single value in text | |
168 | : decode-unit ( addr len -- lun ) push-hex $number if 0 then pop-base ; | |
169 | : encode-unit ( lun -- adr len ) push-hex (u.) pop-base ; | |
170 | ||
171 | headers | |
172 | ||
173 | : parse-my-args ( -- ) | |
174 | my-args " debug" $= if debug-on then | |
175 | ; | |
176 | ||
177 | headers | |
178 | ||
179 | \ LICENSE_BEGIN | |
180 | \ Copyright (c) 2006 FirmWorks | |
181 | \ | |
182 | \ Permission is hereby granted, free of charge, to any person obtaining | |
183 | \ a copy of this software and associated documentation files (the | |
184 | \ "Software"), to deal in the Software without restriction, including | |
185 | \ without limitation the rights to use, copy, modify, merge, publish, | |
186 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
187 | \ permit persons to whom the Software is furnished to do so, subject to | |
188 | \ the following conditions: | |
189 | \ | |
190 | \ The above copyright notice and this permission notice shall be | |
191 | \ included in all copies or substantial portions of the Software. | |
192 | \ | |
193 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
194 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
195 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
196 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
197 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
198 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
199 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
200 | \ | |
201 | \ LICENSE_END |