Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: usbkbd.tok | |
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: @(#)usbkbd.tok 1.7 06/12/15 | |
43 | purpose: | |
44 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | Fcode-version2 | |
48 | ||
49 | : disable-int-transactions ( token -- toggle ) | |
50 | " disable-int-transactions" $call-parent | |
51 | ; | |
52 | ||
53 | : enable-int-transactions | |
54 | ( ms tgl lo-spd? dir max-pkt buf-len endp usb-adr -- token ) | |
55 | " enable-int-transactions" $call-parent | |
56 | ; | |
57 | ||
58 | : execute-control | |
59 | ( lo-spd? dir max-pkt buf-adr buf-len req-adr req-len endp usb-adr | |
60 | -- hw-err? | stat 0 ) | |
61 | " execute-control" $call-parent | |
62 | ; | |
63 | ||
64 | : execute-1-interrupt | |
65 | ( tgl1 lo-spd? dir max-pkt buf-adr buf-len endp usb-adr | |
66 | -- tgl2 hw-err? | tgl2 stat 0 ) | |
67 | " execute-1-interrupt" $call-parent | |
68 | ; | |
69 | ||
70 | : int-transaction-status ( buf-adr token -- hw-err? | stat 0 ) | |
71 | " int-transaction-status" $call-parent | |
72 | ; | |
73 | ||
74 | \ XXX should have stubs for the other usb words too, I suppose. | |
75 | ||
76 | ||
77 | headerless | |
78 | ||
79 | 0 instance value kbd-package | |
80 | ||
81 | \ We didn't use interpose so we use call-methods instead. | |
82 | \ This sucks.. but until the pathname part of interpose works | |
83 | \ properly we need to live with this ick. | |
84 | \ | |
85 | : .call-kbd ( str,len -- XXX? ) kbd-package $call-method ; | |
86 | ||
87 | : kbd-convert ( key# alt shft -- entry ) | |
88 | " convert" .call-kbd | |
89 | ; | |
90 | ||
91 | external | |
92 | ||
93 | \ Interfaces into keyboard translator package for setting keyboard layouts | |
94 | : set-keyboard-layout ( $layout-name -- failure?) | |
95 | kbd-package if | |
96 | " set-keyboard-layout" .call-kbd | |
97 | else | |
98 | 2drop true | |
99 | then | |
100 | ; | |
101 | ||
102 | : get-layout-names ( buffer size -- size ) | |
103 | kbd-package if | |
104 | " get-layout-names" .call-kbd | |
105 | else | |
106 | 2drop 0 | |
107 | then | |
108 | ; | |
109 | ||
110 | \ Parent dma interfaces | |
111 | : dma-alloc ( size -- virt ) " dma-alloc" $call-parent ; | |
112 | : dma-free ( virt size -- ) " dma-free" $call-parent ; | |
113 | \ No dma-map-in for the bus on which this lives can return a 0 address, | |
114 | \ or code and chip will break. | |
115 | ||
116 | : dma-map-in ( virt size cacheable? -- devadr ) | |
117 | " dma-map-in" $call-parent | |
118 | ; | |
119 | ||
120 | : dma-map-out ( virt devadr size -- ) | |
121 | " dma-map-out" $call-parent | |
122 | ; | |
123 | ||
124 | : dma-sync ( virt devadr size -- ) | |
125 | " dma-sync" $call-parent | |
126 | ; | |
127 | ||
128 | ||
129 | : le-w@ ( addr -- w ) dup c@ swap char+ c@ bwjoin ; | |
130 | ||
131 | : le-w! ( w addr -- ) >r wbsplit r@ char+ c! r> c! ; | |
132 | ||
133 | : le-l@ ( addr -- l ) dup le-w@ swap wa1+ le-w@ wljoin ; | |
134 | ||
135 | : le-l! ( l addr -- ) >r lwsplit r@ wa1+ le-w! r> le-w! ; | |
136 | ||
137 | headerless | |
138 | ||
139 | : $= ( adr,len adr,len -- flag ) | |
140 | rot tuck = if ( adr1 adr2 len ) | |
141 | comp invert ( flag ) | |
142 | else ( adr1 adr2 len ) | |
143 | 3drop false ( false ) | |
144 | then ( flag ) | |
145 | ; | |
146 | ||
147 | : silent-type-cr | |
148 | diagnostic-mode? if type cr else 2drop then | |
149 | ; | |
150 | ||
151 | fload ${BP}/dev/serial/keyboard/buffer.fth | |
152 | fload ${BP}/dev/serial/keyboard/options.fth | |
153 | fload ${BP}/dev/serial/keyboard/mutex.fth | |
154 | fload ${BP}/pkg/keyboard/keycodes.fth | |
155 | ||
156 | fload ${BP}/dev/usb-devices/kbd/usbdefs.fth | |
157 | fload ${BP}/dev/usb-devices/kbd/usbdescr.fth | |
158 | fload ${BP}/dev/usb-devices/kbd/usbdebug.fth | |
159 | ||
160 | fload ${BP}/dev/usb-devices/kbd/usbkeyin.fth | |
161 | fload ${BP}/dev/usb-devices/kbd/usbutils.fth | |
162 | ||
163 | fload ${BP}/dev/usb-devices/kbd/kbdutils.fth | |
164 | fload ${BP}/dev/usb-devices/kbd/probe.fth | |
165 | ||
166 | ||
167 | instance variable kbd-alarm-running? | |
168 | ||
169 | : poll-input ( -- ) | |
170 | mutex-enter if exit then ( ) | |
171 | ||
172 | poll-usb if | |
173 | false to forced-keyboard-mode? | |
174 | clear-keyboard | |
175 | mutex-exit | |
176 | user-abort | |
177 | else | |
178 | mutex-exit | |
179 | then ( ) | |
180 | ; | |
181 | ||
182 | ||
183 | : set-alarm ( interval -- ) | |
184 | kbd-alarm-running? over if on else off then ( interval ) | |
185 | ['] poll-input swap alarm | |
186 | ; | |
187 | ||
188 | ||
189 | \ Return true if there were no errors during the open process, | |
190 | \ otherwise return false. | |
191 | \ | |
192 | : usb-keyboard-open ( -- okay? ) | |
193 | ||
194 | false to forced-keyboard-mode? ( ) | |
195 | kbd-alarm-running? off ( ) | |
196 | mutex-enter drop mutex-exit ( ) | |
197 | ||
198 | my-args ( str,len ) | |
199 | dup if ( str,len ) | |
200 | \ We have some args to scan | |
201 | 2dup " forcemode" $= if ( str,len ) | |
202 | " Force Keyboard Mode: Using input device USB keyboard anyway." | |
203 | silent-type-cr | |
204 | true to forced-keyboard-mode? ( str,len ) | |
205 | then ( str,len ) | |
206 | then 2drop ( ) | |
207 | ||
208 | alloc-vaddr-buffs ( ) | |
209 | set-oftused-buf-offsets ( ) | |
210 | ||
211 | install-device ( everything-ok? ) | |
212 | ; | |
213 | ||
214 | : usb-keyboard-close ( -- ) | |
215 | makesure-kbdints-off ( ) | |
216 | dealloc-vaddr-buffs | |
217 | ; | |
218 | ||
219 | headers | |
220 | ||
221 | : init-kbd-package ( -- okay? ) | |
222 | my-args " kbd-translator" $open-package to kbd-package | |
223 | kbd-package if | |
224 | true | |
225 | else | |
226 | ." Can't open USB keyboard package" cr false | |
227 | then | |
228 | ; | |
229 | ||
230 | external | |
231 | ||
232 | : read ( adr len -- #read ) read-bytes ; | |
233 | \ : write ( adr len -- #written ) " write" kbd-package $call-method ; | |
234 | : write ( adr len -- #written ) ; | |
235 | ||
236 | : open ( -- ok? ) | |
237 | usb-keyboard-open if | |
238 | init-kbd-package | |
239 | else | |
240 | false | |
241 | then | |
242 | ; | |
243 | ||
244 | : close ( -- ) | |
245 | kbd-package close-package | |
246 | usb-keyboard-close | |
247 | ; | |
248 | ||
249 | : reset ( -- ) ; | |
250 | : selftest ( -- error ) false ; | |
251 | ||
252 | : remove-abort ( -- ) kbd-alarm-running? @ if 0 set-alarm then ; | |
253 | : install-abort ( -- ) remove-abort d# 10 set-alarm ; | |
254 | ||
255 | : ring-bell ( -- ) ring-keyboard-bell ; | |
256 | ||
257 | : kbd-dropin&id ( -- magic$ dropin$ layoutid ) | |
258 | " UKBD" " usbkbds" get-kbd-cntry-id | |
259 | ; | |
260 | ||
261 | ' kbd-convert is convert | |
262 | ||
263 | headers | |
264 | ||
265 | : ss ( -- ) \ XXX for debugging | |
266 | cr ." quit " | |
267 | " quit" $find drop execute | |
268 | ; | |
269 | ||
270 | end0 |