wsdisplay_compat_usl.c revision 1.33.4.3 1 1.33.4.3 ad /* $NetBSD: wsdisplay_compat_usl.c,v 1.33.4.3 2007/01/19 09:39:58 ad Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1998
5 1.1 drochner * Matthias Drochner. All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Redistribution and use in source and binary forms, with or without
8 1.1 drochner * modification, are permitted provided that the following conditions
9 1.1 drochner * are met:
10 1.1 drochner * 1. Redistributions of source code must retain the above copyright
11 1.1 drochner * notice, this list of conditions and the following disclaimer.
12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 drochner * notice, this list of conditions and the following disclaimer in the
14 1.1 drochner * documentation and/or other materials provided with the distribution.
15 1.1 drochner *
16 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 drochner *
27 1.1 drochner */
28 1.17 lukem
29 1.17 lukem #include <sys/cdefs.h>
30 1.33.4.3 ad __KERNEL_RCSID(0, "$NetBSD: wsdisplay_compat_usl.c,v 1.33.4.3 2007/01/19 09:39:58 ad Exp $");
31 1.4 thorpej
32 1.4 thorpej #include "opt_compat_freebsd.h"
33 1.5 jonathan #include "opt_compat_netbsd.h"
34 1.1 drochner
35 1.1 drochner #include <sys/param.h>
36 1.1 drochner #include <sys/systm.h>
37 1.12 thorpej #include <sys/callout.h>
38 1.1 drochner #include <sys/ioctl.h>
39 1.1 drochner #include <sys/kernel.h>
40 1.1 drochner #include <sys/proc.h>
41 1.1 drochner #include <sys/signalvar.h>
42 1.1 drochner #include <sys/malloc.h>
43 1.1 drochner #include <sys/errno.h>
44 1.32 elad #include <sys/kauth.h>
45 1.1 drochner
46 1.1 drochner #include <dev/wscons/wsconsio.h>
47 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
48 1.1 drochner #include <dev/wscons/wscons_callbacks.h>
49 1.1 drochner #include <dev/wscons/wsdisplay_usl_io.h>
50 1.1 drochner
51 1.1 drochner #include "opt_wsdisplay_compat.h"
52 1.1 drochner
53 1.1 drochner struct usl_syncdata {
54 1.1 drochner struct wsscreen *s_scr;
55 1.1 drochner struct proc *s_proc;
56 1.1 drochner pid_t s_pid;
57 1.1 drochner int s_flags;
58 1.1 drochner #define SF_DETACHPENDING 1
59 1.1 drochner #define SF_ATTACHPENDING 2
60 1.1 drochner int s_acqsig, s_relsig;
61 1.1 drochner int s_frsig; /* unused */
62 1.16 augustss void (*s_callback)(void *, int, int);
63 1.1 drochner void *s_cbarg;
64 1.12 thorpej struct callout s_attach_ch;
65 1.12 thorpej struct callout s_detach_ch;
66 1.1 drochner };
67 1.1 drochner
68 1.16 augustss static int usl_sync_init(struct wsscreen *, struct usl_syncdata **,
69 1.16 augustss struct proc *, int, int, int);
70 1.16 augustss static void usl_sync_done(struct usl_syncdata *);
71 1.16 augustss static int usl_sync_check(struct usl_syncdata *);
72 1.16 augustss static struct usl_syncdata *usl_sync_get(struct wsscreen *);
73 1.16 augustss
74 1.16 augustss static int usl_detachproc(void *, int, void (*)(void *, int, int), void *);
75 1.16 augustss static int usl_detachack(struct usl_syncdata *, int);
76 1.16 augustss static void usl_detachtimeout(void *);
77 1.16 augustss static int usl_attachproc(void *, int, void (*)(void *, int, int), void *);
78 1.16 augustss static int usl_attachack(struct usl_syncdata *, int);
79 1.16 augustss static void usl_attachtimeout(void *);
80 1.1 drochner
81 1.1 drochner static const struct wscons_syncops usl_syncops = {
82 1.1 drochner usl_detachproc,
83 1.1 drochner usl_attachproc,
84 1.16 augustss #define _usl_sync_check ((int (*)(void *))usl_sync_check)
85 1.1 drochner _usl_sync_check,
86 1.16 augustss #define _usl_sync_destroy ((void (*)(void *))usl_sync_done)
87 1.1 drochner _usl_sync_destroy
88 1.1 drochner };
89 1.1 drochner
90 1.7 drochner #ifndef WSCOMPAT_USL_SYNCTIMEOUT
91 1.7 drochner #define WSCOMPAT_USL_SYNCTIMEOUT 5 /* seconds */
92 1.7 drochner #endif
93 1.7 drochner static int wscompat_usl_synctimeout = WSCOMPAT_USL_SYNCTIMEOUT;
94 1.7 drochner
95 1.1 drochner static int
96 1.16 augustss usl_sync_init(struct wsscreen *scr, struct usl_syncdata **sdp,
97 1.16 augustss struct proc *p, int acqsig, int relsig, int frsig)
98 1.1 drochner {
99 1.1 drochner struct usl_syncdata *sd;
100 1.1 drochner int res;
101 1.1 drochner
102 1.1 drochner sd = malloc(sizeof(struct usl_syncdata), M_DEVBUF, M_WAITOK);
103 1.1 drochner if (!sd)
104 1.1 drochner return (ENOMEM);
105 1.1 drochner sd->s_scr = scr;
106 1.3 drochner sd->s_proc = p;
107 1.3 drochner sd->s_pid = p->p_pid;
108 1.2 drochner sd->s_flags = 0;
109 1.3 drochner sd->s_acqsig = acqsig;
110 1.3 drochner sd->s_relsig = relsig;
111 1.3 drochner sd->s_frsig = frsig;
112 1.12 thorpej callout_init(&sd->s_attach_ch);
113 1.12 thorpej callout_init(&sd->s_detach_ch);
114 1.1 drochner res = wsscreen_attach_sync(scr, &usl_syncops, sd);
115 1.1 drochner if (res) {
116 1.1 drochner free(sd, M_DEVBUF);
117 1.1 drochner return (res);
118 1.1 drochner }
119 1.1 drochner *sdp = sd;
120 1.1 drochner return (0);
121 1.1 drochner }
122 1.1 drochner
123 1.1 drochner static void
124 1.16 augustss usl_sync_done(struct usl_syncdata *sd)
125 1.1 drochner {
126 1.2 drochner if (sd->s_flags & SF_DETACHPENDING) {
127 1.12 thorpej callout_stop(&sd->s_detach_ch);
128 1.6 drochner (*sd->s_callback)(sd->s_cbarg, 0, 0);
129 1.2 drochner }
130 1.6 drochner if (sd->s_flags & SF_ATTACHPENDING) {
131 1.12 thorpej callout_stop(&sd->s_attach_ch);
132 1.6 drochner (*sd->s_callback)(sd->s_cbarg, ENXIO, 0);
133 1.6 drochner }
134 1.1 drochner wsscreen_detach_sync(sd->s_scr);
135 1.1 drochner free(sd, M_DEVBUF);
136 1.1 drochner }
137 1.1 drochner
138 1.1 drochner static int
139 1.16 augustss usl_sync_check(struct usl_syncdata *sd)
140 1.1 drochner {
141 1.1 drochner if (sd->s_proc == pfind(sd->s_pid))
142 1.1 drochner return (1);
143 1.1 drochner printf("usl_sync_check: process %d died\n", sd->s_pid);
144 1.1 drochner usl_sync_done(sd);
145 1.1 drochner return (0);
146 1.1 drochner }
147 1.1 drochner
148 1.1 drochner static struct usl_syncdata *
149 1.16 augustss usl_sync_get(struct wsscreen *scr)
150 1.1 drochner {
151 1.20 fvdl void *sd;
152 1.1 drochner
153 1.20 fvdl if (wsscreen_lookup_sync(scr, &usl_syncops, &sd))
154 1.1 drochner return (0);
155 1.20 fvdl return (struct usl_syncdata *)sd;
156 1.1 drochner }
157 1.1 drochner
158 1.1 drochner static int
159 1.33.4.1 ad usl_detachproc(void *cookie, int waitok,
160 1.33.4.1 ad void (*callback)(void *, int, int), void *cbarg)
161 1.1 drochner {
162 1.1 drochner struct usl_syncdata *sd = cookie;
163 1.1 drochner
164 1.1 drochner if (!usl_sync_check(sd))
165 1.1 drochner return (0);
166 1.1 drochner
167 1.11 drochner /* we really need a callback */
168 1.11 drochner if (!callback)
169 1.11 drochner return (EINVAL);
170 1.11 drochner
171 1.1 drochner /*
172 1.1 drochner * Normally, this is called from the controlling process.
173 1.1 drochner * Is is supposed to reply with a VT_RELDISP ioctl(), so
174 1.1 drochner * it is not useful to tsleep() here.
175 1.1 drochner */
176 1.1 drochner sd->s_callback = callback;
177 1.1 drochner sd->s_cbarg = cbarg;
178 1.1 drochner sd->s_flags |= SF_DETACHPENDING;
179 1.33.4.3 ad mutex_enter(&proclist_mutex);
180 1.1 drochner psignal(sd->s_proc, sd->s_relsig);
181 1.33.4.3 ad mutex_exit(&proclist_mutex);
182 1.12 thorpej callout_reset(&sd->s_detach_ch, wscompat_usl_synctimeout * hz,
183 1.12 thorpej usl_detachtimeout, sd);
184 1.1 drochner
185 1.1 drochner return (EAGAIN);
186 1.1 drochner }
187 1.1 drochner
188 1.1 drochner static int
189 1.16 augustss usl_detachack(struct usl_syncdata *sd, int ack)
190 1.1 drochner {
191 1.1 drochner if (!(sd->s_flags & SF_DETACHPENDING)) {
192 1.1 drochner printf("usl_detachack: not detaching\n");
193 1.1 drochner return (EINVAL);
194 1.1 drochner }
195 1.1 drochner
196 1.12 thorpej callout_stop(&sd->s_detach_ch);
197 1.1 drochner sd->s_flags &= ~SF_DETACHPENDING;
198 1.1 drochner
199 1.6 drochner if (sd->s_callback)
200 1.6 drochner (*sd->s_callback)(sd->s_cbarg, (ack ? 0 : EIO), 1);
201 1.1 drochner
202 1.1 drochner return (0);
203 1.1 drochner }
204 1.1 drochner
205 1.1 drochner static void
206 1.16 augustss usl_detachtimeout(void *arg)
207 1.1 drochner {
208 1.1 drochner struct usl_syncdata *sd = arg;
209 1.1 drochner
210 1.1 drochner printf("usl_detachtimeout\n");
211 1.1 drochner
212 1.1 drochner if (!(sd->s_flags & SF_DETACHPENDING)) {
213 1.1 drochner printf("usl_detachtimeout: not detaching\n");
214 1.1 drochner return;
215 1.1 drochner }
216 1.1 drochner
217 1.1 drochner sd->s_flags &= ~SF_DETACHPENDING;
218 1.6 drochner
219 1.6 drochner if (sd->s_callback)
220 1.6 drochner (*sd->s_callback)(sd->s_cbarg, EIO, 0);
221 1.6 drochner
222 1.1 drochner (void) usl_sync_check(sd);
223 1.1 drochner }
224 1.1 drochner
225 1.1 drochner static int
226 1.33.4.1 ad usl_attachproc(void *cookie, int waitok,
227 1.33.4.1 ad void (*callback)(void *, int, int), void *cbarg)
228 1.1 drochner {
229 1.1 drochner struct usl_syncdata *sd = cookie;
230 1.1 drochner
231 1.1 drochner if (!usl_sync_check(sd))
232 1.1 drochner return (0);
233 1.11 drochner
234 1.11 drochner /* we really need a callback */
235 1.11 drochner if (!callback)
236 1.11 drochner return (EINVAL);
237 1.1 drochner
238 1.6 drochner sd->s_callback = callback;
239 1.6 drochner sd->s_cbarg = cbarg;
240 1.1 drochner sd->s_flags |= SF_ATTACHPENDING;
241 1.33.4.3 ad mutex_enter(&proclist_mutex);
242 1.1 drochner psignal(sd->s_proc, sd->s_acqsig);
243 1.33.4.3 ad mutex_exit(&proclist_mutex);
244 1.12 thorpej callout_reset(&sd->s_attach_ch, wscompat_usl_synctimeout * hz,
245 1.12 thorpej usl_attachtimeout, sd);
246 1.1 drochner
247 1.1 drochner return (EAGAIN);
248 1.1 drochner }
249 1.1 drochner
250 1.1 drochner static int
251 1.16 augustss usl_attachack(struct usl_syncdata *sd, int ack)
252 1.1 drochner {
253 1.1 drochner if (!(sd->s_flags & SF_ATTACHPENDING)) {
254 1.1 drochner printf("usl_attachack: not attaching\n");
255 1.1 drochner return (EINVAL);
256 1.1 drochner }
257 1.1 drochner
258 1.12 thorpej callout_stop(&sd->s_attach_ch);
259 1.1 drochner sd->s_flags &= ~SF_ATTACHPENDING;
260 1.6 drochner
261 1.6 drochner if (sd->s_callback)
262 1.6 drochner (*sd->s_callback)(sd->s_cbarg, (ack ? 0 : EIO), 1);
263 1.6 drochner
264 1.1 drochner return (0);
265 1.1 drochner }
266 1.1 drochner
267 1.1 drochner static void
268 1.16 augustss usl_attachtimeout(void *arg)
269 1.1 drochner {
270 1.1 drochner struct usl_syncdata *sd = arg;
271 1.1 drochner
272 1.1 drochner printf("usl_attachtimeout\n");
273 1.1 drochner
274 1.1 drochner if (!(sd->s_flags & SF_ATTACHPENDING)) {
275 1.1 drochner printf("usl_attachtimeout: not attaching\n");
276 1.1 drochner return;
277 1.1 drochner }
278 1.1 drochner
279 1.1 drochner sd->s_flags &= ~SF_ATTACHPENDING;
280 1.6 drochner
281 1.6 drochner if (sd->s_callback)
282 1.6 drochner (*sd->s_callback)(sd->s_cbarg, EIO, 0);
283 1.6 drochner
284 1.1 drochner (void) usl_sync_check(sd);
285 1.1 drochner }
286 1.1 drochner
287 1.1 drochner int
288 1.16 augustss wsdisplay_usl_ioctl1(struct wsdisplay_softc *sc, u_long cmd, caddr_t data,
289 1.33.4.1 ad int flag, struct lwp *l)
290 1.10 mycroft {
291 1.10 mycroft int idx, maxidx;
292 1.10 mycroft
293 1.10 mycroft switch (cmd) {
294 1.10 mycroft case VT_OPENQRY:
295 1.10 mycroft maxidx = wsdisplay_maxscreenidx(sc);
296 1.10 mycroft for (idx = 0; idx <= maxidx; idx++) {
297 1.10 mycroft if (wsdisplay_screenstate(sc, idx) == 0) {
298 1.10 mycroft *(int *)data = idx + 1;
299 1.10 mycroft return (0);
300 1.10 mycroft }
301 1.10 mycroft }
302 1.10 mycroft return (ENXIO);
303 1.10 mycroft case VT_GETACTIVE:
304 1.10 mycroft idx = wsdisplay_getactivescreen(sc);
305 1.10 mycroft *(int *)data = idx + 1;
306 1.10 mycroft return (0);
307 1.10 mycroft case VT_ACTIVATE:
308 1.27 macallan /*
309 1.27 macallan * a gross and disgusting hack to make this abused up ioctl,
310 1.27 macallan * which is a gross and disgusting hack on its own, work on
311 1.27 macallan * LP64/BE - we want the lower 32bit so we simply dereference
312 1.27 macallan * the argument pointer as long. May cause problems with 32bit
313 1.27 macallan * kernels on sparc64?
314 1.27 macallan */
315 1.27 macallan
316 1.27 macallan idx = *(long *)data - 1;
317 1.14 takemura if (idx < 0)
318 1.14 takemura return (EINVAL);
319 1.10 mycroft return (wsdisplay_switch((struct device *)sc, idx, 1));
320 1.10 mycroft case VT_WAITACTIVE:
321 1.27 macallan idx = *(long *)data - 1;
322 1.14 takemura if (idx < 0)
323 1.14 takemura return (EINVAL);
324 1.10 mycroft return (wsscreen_switchwait(sc, idx));
325 1.10 mycroft case VT_GETSTATE:
326 1.10 mycroft #define ss ((struct vt_stat *)data)
327 1.10 mycroft idx = wsdisplay_getactivescreen(sc);
328 1.10 mycroft ss->v_active = idx + 1;
329 1.10 mycroft ss->v_state = 0;
330 1.10 mycroft maxidx = wsdisplay_maxscreenidx(sc);
331 1.10 mycroft for (idx = 0; idx <= maxidx; idx++)
332 1.10 mycroft if (wsdisplay_screenstate(sc, idx) == EBUSY)
333 1.10 mycroft ss->v_state |= (1 << (idx + 1));
334 1.26 martin #undef ss
335 1.10 mycroft return (0);
336 1.10 mycroft
337 1.10 mycroft #ifdef WSDISPLAY_COMPAT_PCVT
338 1.10 mycroft case VGAPCVTID:
339 1.10 mycroft #define id ((struct pcvtid *)data)
340 1.25 itojun strlcpy(id->name, "pcvt", sizeof(id->name));
341 1.10 mycroft id->rmajor = 3;
342 1.10 mycroft id->rminor = 32;
343 1.10 mycroft #undef id
344 1.10 mycroft return (0);
345 1.10 mycroft #endif
346 1.10 mycroft #ifdef WSDISPLAY_COMPAT_SYSCONS
347 1.10 mycroft case CONS_GETVERS:
348 1.10 mycroft *(int *)data = 0x200; /* version 2.0 */
349 1.10 mycroft return (0);
350 1.10 mycroft #endif
351 1.10 mycroft
352 1.10 mycroft default:
353 1.18 atatat return (EPASSTHROUGH);
354 1.10 mycroft }
355 1.10 mycroft }
356 1.10 mycroft
357 1.10 mycroft int
358 1.16 augustss wsdisplay_usl_ioctl2(struct wsdisplay_softc *sc, struct wsscreen *scr,
359 1.30 christos u_long cmd, caddr_t data, int flag, struct lwp *l)
360 1.1 drochner {
361 1.30 christos struct proc *p = l->l_proc;
362 1.31 jmcneill int intarg = 0, res;
363 1.13 simonb u_long req;
364 1.15 simonb void *arg;
365 1.1 drochner struct usl_syncdata *sd;
366 1.1 drochner struct wskbd_bell_data bd;
367 1.1 drochner
368 1.1 drochner switch (cmd) {
369 1.1 drochner case VT_SETMODE:
370 1.1 drochner #define newmode ((struct vt_mode *)data)
371 1.1 drochner if (newmode->mode == VT_PROCESS) {
372 1.3 drochner res = usl_sync_init(scr, &sd, p, newmode->acqsig,
373 1.3 drochner newmode->relsig, newmode->frsig);
374 1.1 drochner if (res)
375 1.1 drochner return (res);
376 1.1 drochner } else {
377 1.1 drochner sd = usl_sync_get(scr);
378 1.1 drochner if (sd)
379 1.1 drochner usl_sync_done(sd);
380 1.1 drochner }
381 1.1 drochner #undef newmode
382 1.1 drochner return (0);
383 1.1 drochner case VT_GETMODE:
384 1.1 drochner #define cmode ((struct vt_mode *)data)
385 1.1 drochner sd = usl_sync_get(scr);
386 1.1 drochner if (sd) {
387 1.1 drochner cmode->mode = VT_PROCESS;
388 1.1 drochner cmode->relsig = sd->s_relsig;
389 1.1 drochner cmode->acqsig = sd->s_acqsig;
390 1.1 drochner cmode->frsig = sd->s_frsig;
391 1.1 drochner } else
392 1.1 drochner cmode->mode = VT_AUTO;
393 1.1 drochner #undef cmode
394 1.1 drochner return (0);
395 1.1 drochner case VT_RELDISP:
396 1.27 macallan #define d (*(long *)data)
397 1.1 drochner sd = usl_sync_get(scr);
398 1.1 drochner if (!sd)
399 1.1 drochner return (EINVAL);
400 1.1 drochner switch (d) {
401 1.1 drochner case VT_FALSE:
402 1.1 drochner case VT_TRUE:
403 1.1 drochner return (usl_detachack(sd, (d == VT_TRUE)));
404 1.1 drochner case VT_ACKACQ:
405 1.1 drochner return (usl_attachack(sd, 1));
406 1.1 drochner default:
407 1.1 drochner return (EINVAL);
408 1.1 drochner }
409 1.1 drochner #undef d
410 1.10 mycroft
411 1.1 drochner case KDENABIO:
412 1.33.4.1 ad #if defined(__i386__) && (defined(COMPAT_11) || defined(COMPAT_FREEBSD))
413 1.33.4.2 ad if (kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_IOPL,
414 1.33.4.2 ad NULL, NULL, NULL, NULL) != 0)
415 1.1 drochner return (EPERM);
416 1.33.4.1 ad #endif
417 1.1 drochner /* FALLTHRU */
418 1.1 drochner case KDDISABIO:
419 1.33.4.1 ad #if defined(__i386__) && (defined(COMPAT_11) || defined(COMPAT_FREEBSD))
420 1.1 drochner {
421 1.21 thorpej /* XXX NJWLWP */
422 1.21 thorpej struct trapframe *fp = (struct trapframe *)curlwp->l_md.md_regs;
423 1.1 drochner if (cmd == KDENABIO)
424 1.1 drochner fp->tf_eflags |= PSL_IOPL;
425 1.1 drochner else
426 1.1 drochner fp->tf_eflags &= ~PSL_IOPL;
427 1.1 drochner }
428 1.1 drochner #endif
429 1.1 drochner return (0);
430 1.1 drochner case KDSETRAD:
431 1.1 drochner /* XXX ignore for now */
432 1.1 drochner return (0);
433 1.1 drochner
434 1.1 drochner default:
435 1.18 atatat return (EPASSTHROUGH);
436 1.1 drochner
437 1.1 drochner /*
438 1.1 drochner * the following are converted to wsdisplay ioctls
439 1.1 drochner */
440 1.1 drochner case KDSETMODE:
441 1.1 drochner req = WSDISPLAYIO_SMODE;
442 1.29 macallan #define d (*(int *)data)
443 1.1 drochner switch (d) {
444 1.1 drochner case KD_GRAPHICS:
445 1.1 drochner intarg = WSDISPLAYIO_MODE_MAPPED;
446 1.1 drochner break;
447 1.1 drochner case KD_TEXT:
448 1.1 drochner intarg = WSDISPLAYIO_MODE_EMUL;
449 1.1 drochner break;
450 1.1 drochner default:
451 1.1 drochner return (EINVAL);
452 1.1 drochner }
453 1.1 drochner #undef d
454 1.1 drochner arg = &intarg;
455 1.1 drochner break;
456 1.1 drochner case KDMKTONE:
457 1.1 drochner req = WSKBDIO_COMPLEXBELL;
458 1.1 drochner #define d (*(int *)data)
459 1.1 drochner if (d) {
460 1.8 christos #define PCVT_SYSBEEPF 1193182
461 1.8 christos if (d >> 16) {
462 1.8 christos bd.which = WSKBD_BELL_DOPERIOD;
463 1.8 christos bd.period = d >> 16; /* ms */
464 1.8 christos }
465 1.9 christos else
466 1.9 christos bd.which = 0;
467 1.8 christos if (d & 0xffff) {
468 1.8 christos bd.which |= WSKBD_BELL_DOPITCH;
469 1.8 christos bd.pitch = PCVT_SYSBEEPF/(d & 0xffff); /* Hz */
470 1.8 christos }
471 1.1 drochner } else
472 1.1 drochner bd.which = 0; /* default */
473 1.1 drochner #undef d
474 1.1 drochner arg = &bd;
475 1.1 drochner break;
476 1.1 drochner case KDSETLED:
477 1.1 drochner req = WSKBDIO_SETLEDS;
478 1.1 drochner intarg = 0;
479 1.29 macallan #define d (*(int *)data)
480 1.1 drochner if (d & LED_CAP)
481 1.1 drochner intarg |= WSKBD_LED_CAPS;
482 1.1 drochner if (d & LED_NUM)
483 1.1 drochner intarg |= WSKBD_LED_NUM;
484 1.1 drochner if (d & LED_SCR)
485 1.1 drochner intarg |= WSKBD_LED_SCROLL;
486 1.1 drochner #undef d
487 1.1 drochner arg = &intarg;
488 1.1 drochner break;
489 1.1 drochner case KDGETLED:
490 1.1 drochner req = WSKBDIO_GETLEDS;
491 1.1 drochner arg = &intarg;
492 1.1 drochner break;
493 1.1 drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
494 1.1 drochner case KDSKBMODE:
495 1.1 drochner req = WSKBDIO_SETMODE;
496 1.29 macallan switch (*(int *)data) {
497 1.1 drochner case K_RAW:
498 1.1 drochner intarg = WSKBD_RAW;
499 1.1 drochner break;
500 1.1 drochner case K_XLATE:
501 1.1 drochner intarg = WSKBD_TRANSLATED;
502 1.1 drochner break;
503 1.1 drochner default:
504 1.1 drochner return (EINVAL);
505 1.1 drochner }
506 1.1 drochner arg = &intarg;
507 1.1 drochner break;
508 1.1 drochner case KDGKBMODE:
509 1.1 drochner req = WSKBDIO_GETMODE;
510 1.1 drochner arg = &intarg;
511 1.1 drochner break;
512 1.1 drochner #endif
513 1.1 drochner }
514 1.1 drochner
515 1.30 christos res = wsdisplay_internal_ioctl(sc, scr, req, arg, flag, l);
516 1.18 atatat if (res != EPASSTHROUGH)
517 1.1 drochner return (res);
518 1.1 drochner
519 1.1 drochner switch (cmd) {
520 1.1 drochner case KDGETLED:
521 1.1 drochner #define d (*(int *)data)
522 1.1 drochner d = 0;
523 1.1 drochner if (intarg & WSKBD_LED_CAPS)
524 1.1 drochner d |= LED_CAP;
525 1.1 drochner if (intarg & WSKBD_LED_NUM)
526 1.1 drochner d |= LED_NUM;
527 1.1 drochner if (intarg & WSKBD_LED_SCROLL)
528 1.1 drochner d |= LED_SCR;
529 1.1 drochner #undef d
530 1.1 drochner break;
531 1.1 drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
532 1.1 drochner case KDGKBMODE:
533 1.1 drochner *(int *)data = (intarg == WSKBD_RAW ? K_RAW : K_XLATE);
534 1.1 drochner break;
535 1.1 drochner #endif
536 1.1 drochner }
537 1.1 drochner
538 1.1 drochner return (0);
539 1.1 drochner }
540