Home | History | Annotate | Line # | Download | only in wscons
wsdisplay_compat_usl.c revision 1.3
      1  1.3  drochner /* $NetBSD: wsdisplay_compat_usl.c,v 1.3 1998/06/16 13:31:59 drochner 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  * 3. All advertising materials mentioning features or use of this software
     16  1.1  drochner  *    must display the following acknowledgement:
     17  1.1  drochner  *	This product includes software developed for the NetBSD Project
     18  1.1  drochner  *	by Matthias Drochner.
     19  1.1  drochner  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  drochner  *    derived from this software without specific prior written permission.
     21  1.1  drochner  *
     22  1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  drochner  *
     33  1.1  drochner  */
     34  1.1  drochner 
     35  1.1  drochner #include <sys/param.h>
     36  1.1  drochner #include <sys/systm.h>
     37  1.1  drochner #include <sys/ioctl.h>
     38  1.1  drochner #include <sys/kernel.h>
     39  1.1  drochner #include <sys/proc.h>
     40  1.1  drochner #include <sys/signalvar.h>
     41  1.1  drochner #include <sys/malloc.h>
     42  1.1  drochner #include <sys/errno.h>
     43  1.1  drochner 
     44  1.1  drochner #include <dev/wscons/wsconsio.h>
     45  1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     46  1.1  drochner #include <dev/wscons/wscons_callbacks.h>
     47  1.1  drochner #include <dev/wscons/wsdisplay_usl_io.h>
     48  1.1  drochner 
     49  1.1  drochner #include "opt_wsdisplay_compat.h"
     50  1.1  drochner 
     51  1.1  drochner struct usl_syncdata {
     52  1.1  drochner 	struct wsscreen *s_scr;
     53  1.1  drochner 	struct proc *s_proc;
     54  1.1  drochner 	pid_t s_pid;
     55  1.1  drochner 	int s_flags;
     56  1.1  drochner #define SF_DETACHPENDING 1
     57  1.1  drochner #define SF_ATTACHPENDING 2
     58  1.1  drochner 	int s_acqsig, s_relsig;
     59  1.1  drochner 	int s_frsig; /* unused */
     60  1.1  drochner 	void (*s_callback) __P((void *, int));
     61  1.1  drochner 	void *s_cbarg;
     62  1.1  drochner };
     63  1.1  drochner 
     64  1.3  drochner static int usl_sync_init __P((struct wsscreen *, struct usl_syncdata **,
     65  1.3  drochner 			      struct proc *, int, int, int));
     66  1.1  drochner static void usl_sync_done __P((struct usl_syncdata *));
     67  1.1  drochner static int usl_sync_check __P((struct usl_syncdata *));
     68  1.1  drochner static struct usl_syncdata *usl_sync_get __P((struct wsscreen *));
     69  1.1  drochner 
     70  1.1  drochner static int usl_detachproc __P((void *, int, void (*)(void *, int), void *));
     71  1.1  drochner static int usl_detachack __P((struct usl_syncdata *, int));
     72  1.1  drochner static void usl_detachtimeout __P((void *));
     73  1.1  drochner static int usl_attachproc __P((void *, int));
     74  1.1  drochner static int usl_attachack __P((struct usl_syncdata *, int));
     75  1.1  drochner static void usl_attachtimeout __P((void *));
     76  1.1  drochner 
     77  1.1  drochner static const struct wscons_syncops usl_syncops = {
     78  1.1  drochner 	usl_detachproc,
     79  1.1  drochner 	usl_attachproc,
     80  1.1  drochner #define _usl_sync_check ((int (*) __P((void *)))usl_sync_check)
     81  1.1  drochner 	_usl_sync_check,
     82  1.1  drochner #define _usl_sync_destroy ((void (*) __P((void *)))usl_sync_done)
     83  1.1  drochner 	_usl_sync_destroy
     84  1.1  drochner };
     85  1.1  drochner 
     86  1.1  drochner static int
     87  1.3  drochner usl_sync_init(scr, sdp, p, acqsig, relsig, frsig)
     88  1.1  drochner 	struct wsscreen *scr;
     89  1.1  drochner 	struct usl_syncdata **sdp;
     90  1.3  drochner 	struct proc *p;
     91  1.3  drochner 	int acqsig, relsig, frsig;
     92  1.1  drochner {
     93  1.1  drochner 	struct usl_syncdata *sd;
     94  1.1  drochner 	int res;
     95  1.1  drochner 
     96  1.1  drochner 	sd = malloc(sizeof(struct usl_syncdata), M_DEVBUF, M_WAITOK);
     97  1.1  drochner 	if (!sd)
     98  1.1  drochner 		return (ENOMEM);
     99  1.1  drochner 	sd->s_scr = scr;
    100  1.3  drochner 	sd->s_proc = p;
    101  1.3  drochner 	sd->s_pid = p->p_pid;
    102  1.2  drochner 	sd->s_flags = 0;
    103  1.3  drochner 	sd->s_acqsig = acqsig;
    104  1.3  drochner 	sd->s_relsig = relsig;
    105  1.3  drochner 	sd->s_frsig = frsig;
    106  1.1  drochner 	res = wsscreen_attach_sync(scr, &usl_syncops, sd);
    107  1.1  drochner 	if (res) {
    108  1.1  drochner 		free(sd, M_DEVBUF);
    109  1.1  drochner 		return (res);
    110  1.1  drochner 	}
    111  1.1  drochner 	*sdp = sd;
    112  1.1  drochner 	return (0);
    113  1.1  drochner }
    114  1.1  drochner 
    115  1.1  drochner static void
    116  1.1  drochner usl_sync_done(sd)
    117  1.1  drochner 	struct usl_syncdata *sd;
    118  1.1  drochner {
    119  1.2  drochner 	if (sd->s_flags & SF_DETACHPENDING) {
    120  1.2  drochner 		untimeout(usl_detachtimeout, sd);
    121  1.1  drochner 		(*sd->s_callback)(sd->s_cbarg, 0);
    122  1.2  drochner 	}
    123  1.2  drochner 	if (sd->s_flags & SF_ATTACHPENDING)
    124  1.2  drochner 		untimeout(usl_attachtimeout, sd);
    125  1.1  drochner 	wsscreen_detach_sync(sd->s_scr);
    126  1.1  drochner 	free(sd, M_DEVBUF);
    127  1.1  drochner }
    128  1.1  drochner 
    129  1.1  drochner static int
    130  1.1  drochner usl_sync_check(sd)
    131  1.1  drochner 	struct usl_syncdata *sd;
    132  1.1  drochner {
    133  1.1  drochner 	if (sd->s_proc == pfind(sd->s_pid))
    134  1.1  drochner 		return (1);
    135  1.1  drochner 	printf("usl_sync_check: process %d died\n", sd->s_pid);
    136  1.1  drochner 	usl_sync_done(sd);
    137  1.1  drochner 	return (0);
    138  1.1  drochner }
    139  1.1  drochner 
    140  1.1  drochner static struct usl_syncdata *
    141  1.1  drochner usl_sync_get(scr)
    142  1.1  drochner 	struct wsscreen *scr;
    143  1.1  drochner {
    144  1.1  drochner 	struct usl_syncdata *sd;
    145  1.1  drochner 
    146  1.1  drochner 	if (wsscreen_lookup_sync(scr, &usl_syncops, (void **)&sd))
    147  1.1  drochner 		return (0);
    148  1.1  drochner 	return (sd);
    149  1.1  drochner }
    150  1.1  drochner 
    151  1.1  drochner static int
    152  1.1  drochner usl_detachproc(cookie, waitok, callback, cbarg)
    153  1.1  drochner 	void *cookie;
    154  1.1  drochner 	int waitok;
    155  1.1  drochner 	void (*callback) __P((void *, int));
    156  1.1  drochner 	void *cbarg;
    157  1.1  drochner {
    158  1.1  drochner 	struct usl_syncdata *sd = cookie;
    159  1.1  drochner 
    160  1.1  drochner 	if (!usl_sync_check(sd))
    161  1.1  drochner 		return (0);
    162  1.1  drochner 
    163  1.1  drochner 	/*
    164  1.1  drochner 	 * Normally, this is called from the controlling process.
    165  1.1  drochner 	 * Is is supposed to reply with a VT_RELDISP ioctl(), so
    166  1.1  drochner 	 * it is not useful to tsleep() here.
    167  1.1  drochner 	 */
    168  1.1  drochner 	sd->s_callback = callback;
    169  1.1  drochner 	sd->s_cbarg = cbarg;
    170  1.1  drochner 	sd->s_flags |= SF_DETACHPENDING;
    171  1.1  drochner 	psignal(sd->s_proc, sd->s_relsig);
    172  1.1  drochner 	timeout(usl_detachtimeout, sd, 5*hz);
    173  1.1  drochner 
    174  1.1  drochner 	return (EAGAIN);
    175  1.1  drochner }
    176  1.1  drochner 
    177  1.1  drochner static int
    178  1.1  drochner usl_detachack(sd, ack)
    179  1.1  drochner 	struct usl_syncdata *sd;
    180  1.1  drochner 	int ack;
    181  1.1  drochner {
    182  1.1  drochner 	if (!(sd->s_flags & SF_DETACHPENDING)) {
    183  1.1  drochner 		printf("usl_detachack: not detaching\n");
    184  1.1  drochner 		return (EINVAL);
    185  1.1  drochner 	}
    186  1.1  drochner 
    187  1.1  drochner 	untimeout(usl_detachtimeout, sd);
    188  1.1  drochner 	sd->s_flags &= ~SF_DETACHPENDING;
    189  1.1  drochner 
    190  1.1  drochner 	if (ack && sd->s_callback)
    191  1.1  drochner 		(*sd->s_callback)(sd->s_cbarg, 1);
    192  1.1  drochner 
    193  1.1  drochner 	return (0);
    194  1.1  drochner }
    195  1.1  drochner 
    196  1.1  drochner static void
    197  1.1  drochner usl_detachtimeout(arg)
    198  1.1  drochner 	void *arg;
    199  1.1  drochner {
    200  1.1  drochner 	struct usl_syncdata *sd = arg;
    201  1.1  drochner 
    202  1.1  drochner 	printf("usl_detachtimeout\n");
    203  1.1  drochner 
    204  1.1  drochner 	if (!(sd->s_flags & SF_DETACHPENDING)) {
    205  1.1  drochner 		printf("usl_detachtimeout: not detaching\n");
    206  1.1  drochner 		return;
    207  1.1  drochner 	}
    208  1.1  drochner 
    209  1.1  drochner 	sd->s_flags &= ~SF_DETACHPENDING;
    210  1.1  drochner #if 0
    211  1.1  drochner 	psignal(sd->s_proc, SIGKILL);
    212  1.1  drochner #endif
    213  1.1  drochner 	(void) usl_sync_check(sd);
    214  1.1  drochner }
    215  1.1  drochner 
    216  1.1  drochner static int
    217  1.1  drochner usl_attachproc(cookie, waitok)
    218  1.1  drochner 	void *cookie;
    219  1.1  drochner 	int waitok;
    220  1.1  drochner {
    221  1.1  drochner 	struct usl_syncdata *sd = cookie;
    222  1.1  drochner 
    223  1.1  drochner 	if (!usl_sync_check(sd))
    224  1.1  drochner 		return (0);
    225  1.1  drochner 
    226  1.1  drochner 	sd->s_flags |= SF_ATTACHPENDING;
    227  1.1  drochner 	psignal(sd->s_proc, sd->s_acqsig);
    228  1.1  drochner 	timeout(usl_attachtimeout, sd, 5*hz);
    229  1.1  drochner 
    230  1.1  drochner 	return (EAGAIN);
    231  1.1  drochner }
    232  1.1  drochner 
    233  1.1  drochner static int
    234  1.1  drochner usl_attachack(sd, ack)
    235  1.1  drochner 	struct usl_syncdata *sd;
    236  1.1  drochner 	int ack;
    237  1.1  drochner {
    238  1.1  drochner 	if (!(sd->s_flags & SF_ATTACHPENDING)) {
    239  1.1  drochner 		printf("usl_attachack: not attaching\n");
    240  1.1  drochner 		return (EINVAL);
    241  1.1  drochner 	}
    242  1.1  drochner 
    243  1.1  drochner 	untimeout(usl_attachtimeout, sd);
    244  1.1  drochner 	sd->s_flags &= ~SF_ATTACHPENDING;
    245  1.1  drochner 	return (0);
    246  1.1  drochner }
    247  1.1  drochner 
    248  1.1  drochner static void
    249  1.1  drochner usl_attachtimeout(arg)
    250  1.1  drochner 	void *arg;
    251  1.1  drochner {
    252  1.1  drochner 	struct usl_syncdata *sd = arg;
    253  1.1  drochner 
    254  1.1  drochner 	printf("usl_attachtimeout\n");
    255  1.1  drochner 
    256  1.1  drochner 	if (!(sd->s_flags & SF_ATTACHPENDING)) {
    257  1.1  drochner 		printf("usl_attachtimeout: not attaching\n");
    258  1.1  drochner 		return;
    259  1.1  drochner 	}
    260  1.1  drochner 
    261  1.1  drochner 	sd->s_flags &= ~SF_ATTACHPENDING;
    262  1.1  drochner #if 0
    263  1.1  drochner 	psignal(sd->s_proc, SIGKILL);
    264  1.1  drochner #endif
    265  1.1  drochner 	(void) usl_sync_check(sd);
    266  1.1  drochner }
    267  1.1  drochner 
    268  1.1  drochner int
    269  1.1  drochner wsdisplay_usl_ioctl(sc, scr, cmd, data, flag, p)
    270  1.1  drochner 	struct wsdisplay_softc *sc;
    271  1.1  drochner 	struct wsscreen *scr;
    272  1.1  drochner 	u_long cmd;
    273  1.1  drochner 	caddr_t data;
    274  1.1  drochner 	int flag;
    275  1.1  drochner 	struct proc *p;
    276  1.1  drochner {
    277  1.1  drochner 	int res, idx, maxidx;
    278  1.1  drochner 	struct usl_syncdata *sd;
    279  1.1  drochner 	int req, intarg;
    280  1.1  drochner 	struct wskbd_bell_data bd;
    281  1.1  drochner 	void *arg;
    282  1.1  drochner 
    283  1.1  drochner 	switch (cmd) {
    284  1.1  drochner 	    case VT_SETMODE:
    285  1.1  drochner #define newmode ((struct vt_mode *)data)
    286  1.1  drochner 		if (newmode->mode == VT_PROCESS) {
    287  1.3  drochner 			res = usl_sync_init(scr, &sd, p, newmode->acqsig,
    288  1.3  drochner 					    newmode->relsig, newmode->frsig);
    289  1.1  drochner 			if (res)
    290  1.1  drochner 				return (res);
    291  1.1  drochner 		} else {
    292  1.1  drochner 			sd = usl_sync_get(scr);
    293  1.1  drochner 			if (sd)
    294  1.1  drochner 				usl_sync_done(sd);
    295  1.1  drochner 		}
    296  1.1  drochner #undef newmode
    297  1.1  drochner 		return (0);
    298  1.1  drochner 	    case VT_GETMODE:
    299  1.1  drochner #define cmode ((struct vt_mode *)data)
    300  1.1  drochner 		sd = usl_sync_get(scr);
    301  1.1  drochner 		if (sd) {
    302  1.1  drochner 			cmode->mode = VT_PROCESS;
    303  1.1  drochner 			cmode->relsig = sd->s_relsig;
    304  1.1  drochner 			cmode->acqsig = sd->s_acqsig;
    305  1.1  drochner 			cmode->frsig = sd->s_frsig;
    306  1.1  drochner 		} else
    307  1.1  drochner 			cmode->mode = VT_AUTO;
    308  1.1  drochner #undef cmode
    309  1.1  drochner 		return (0);
    310  1.1  drochner 	    case VT_RELDISP:
    311  1.1  drochner #define d (*(int *)data)
    312  1.1  drochner 		sd = usl_sync_get(scr);
    313  1.1  drochner 		if (!sd)
    314  1.1  drochner 			return (EINVAL);
    315  1.1  drochner 		switch (d) {
    316  1.1  drochner 		    case VT_FALSE:
    317  1.1  drochner 		    case VT_TRUE:
    318  1.1  drochner 			return (usl_detachack(sd, (d == VT_TRUE)));
    319  1.1  drochner 		    case VT_ACKACQ:
    320  1.1  drochner 			return (usl_attachack(sd, 1));
    321  1.1  drochner 		    default:
    322  1.1  drochner 			return (EINVAL);
    323  1.1  drochner 		}
    324  1.1  drochner #undef d
    325  1.1  drochner 		return (0);
    326  1.1  drochner 	    case VT_OPENQRY:
    327  1.1  drochner 		maxidx = wsdisplay_maxscreenidx(sc);
    328  1.1  drochner 		for (idx = 0; idx <= maxidx; idx++) {
    329  1.1  drochner 			if (wsdisplay_screenstate(sc, idx) == 0) {
    330  1.1  drochner 				*(int *)data = idx + 1;
    331  1.1  drochner 				return (0);
    332  1.1  drochner 			}
    333  1.1  drochner 		}
    334  1.1  drochner 		return (ENXIO);
    335  1.1  drochner 	    case VT_GETACTIVE:
    336  1.1  drochner 		idx = wsdisplay_getactivescreen(sc);
    337  1.1  drochner 		*(int *)data = idx + 1;
    338  1.1  drochner 		return (0);
    339  1.1  drochner 	    case VT_ACTIVATE:
    340  1.1  drochner 		idx = *(int *)data - 1;
    341  1.1  drochner 		return (wsdisplay_switch((struct device *)sc, idx, 1));
    342  1.1  drochner 	    case VT_WAITACTIVE:
    343  1.1  drochner 		idx = *(int *)data - 1;
    344  1.1  drochner 		return (wsscreen_switchwait(sc, idx));
    345  1.1  drochner 	    case VT_GETSTATE:
    346  1.1  drochner #define ss ((struct vt_stat *)data)
    347  1.1  drochner 		idx = wsdisplay_getactivescreen(sc);
    348  1.1  drochner 		ss->v_active = idx + 1;
    349  1.1  drochner 		ss->v_state = 0;
    350  1.1  drochner 		maxidx = wsdisplay_maxscreenidx(sc);
    351  1.1  drochner 		for (idx = 0; idx <= maxidx; idx++)
    352  1.1  drochner 			if (wsdisplay_screenstate(sc, idx) == EBUSY)
    353  1.1  drochner 				ss->v_state |= (1 << (idx + 1));
    354  1.1  drochner #undef s
    355  1.1  drochner 		return (0);
    356  1.1  drochner 	    case KDENABIO:
    357  1.1  drochner 		if (suser(p->p_ucred, &p->p_acflag) || securelevel > 1)
    358  1.1  drochner 			return (EPERM);
    359  1.1  drochner 		/* FALLTHRU */
    360  1.1  drochner 	    case KDDISABIO:
    361  1.1  drochner #if defined(__i386__)
    362  1.1  drochner #if defined(COMPAT_10) || defined(COMPAT_11) || defined(COMPAT_FREEBSD)
    363  1.1  drochner 		{
    364  1.1  drochner 		struct trapframe *fp = (struct trapframe *)p->p_md.md_regs;
    365  1.1  drochner 		if (cmd == KDENABIO)
    366  1.1  drochner 			fp->tf_eflags |= PSL_IOPL;
    367  1.1  drochner 		else
    368  1.1  drochner 			fp->tf_eflags &= ~PSL_IOPL;
    369  1.1  drochner 		}
    370  1.1  drochner #endif
    371  1.1  drochner #endif
    372  1.1  drochner 		return (0);
    373  1.1  drochner 	    case KDSETRAD:
    374  1.1  drochner 		/* XXX ignore for now */
    375  1.1  drochner 		return (0);
    376  1.1  drochner 
    377  1.1  drochner #ifdef WSDISPLAY_COMPAT_PCVT
    378  1.1  drochner 	    case VGAPCVTID:
    379  1.1  drochner #define id ((struct pcvtid *)data)
    380  1.1  drochner 		strcpy(id->name, "pcvt");
    381  1.1  drochner 		id->rmajor = 3;
    382  1.1  drochner 		id->rminor = 32;
    383  1.1  drochner #undef id
    384  1.1  drochner 		return (0);
    385  1.1  drochner #endif
    386  1.1  drochner #ifdef WSDISPLAY_COMPAT_SYSCONS
    387  1.1  drochner 	    case CONS_GETVERS:
    388  1.1  drochner 		*(int *)data = 0x200;    /* version 2.0 */
    389  1.1  drochner 		return (0);
    390  1.1  drochner #endif
    391  1.1  drochner 
    392  1.1  drochner 	    default:
    393  1.1  drochner 		return (-1);
    394  1.1  drochner 
    395  1.1  drochner 	    /*
    396  1.1  drochner 	     * the following are converted to wsdisplay ioctls
    397  1.1  drochner 	     */
    398  1.1  drochner 	    case KDSETMODE:
    399  1.1  drochner 		req = WSDISPLAYIO_SMODE;
    400  1.1  drochner #define d (*(int *)data)
    401  1.1  drochner 		switch (d) {
    402  1.1  drochner 		    case KD_GRAPHICS:
    403  1.1  drochner 			intarg = WSDISPLAYIO_MODE_MAPPED;
    404  1.1  drochner 			break;
    405  1.1  drochner 		    case KD_TEXT:
    406  1.1  drochner 			intarg = WSDISPLAYIO_MODE_EMUL;
    407  1.1  drochner 			break;
    408  1.1  drochner 		    default:
    409  1.1  drochner 			return (EINVAL);
    410  1.1  drochner 		}
    411  1.1  drochner #undef d
    412  1.1  drochner 		arg = &intarg;
    413  1.1  drochner 		break;
    414  1.1  drochner 	    case KDMKTONE:
    415  1.1  drochner 		req = WSKBDIO_COMPLEXBELL;
    416  1.1  drochner #define d (*(int *)data)
    417  1.1  drochner 		if (d) {
    418  1.1  drochner 			bd.which = WSKBD_BELL_DOPITCH | WSKBD_BELL_DOPERIOD;
    419  1.1  drochner 			bd.pitch = d & 0xffff; /* Hz */
    420  1.1  drochner 			bd.period = d >> 16; /* ms */
    421  1.1  drochner 		} else
    422  1.1  drochner 			bd.which = 0; /* default */
    423  1.1  drochner #undef d
    424  1.1  drochner 		arg = &bd;
    425  1.1  drochner 		break;
    426  1.1  drochner 	    case KDSETLED:
    427  1.1  drochner 		req = WSKBDIO_SETLEDS;
    428  1.1  drochner 		intarg = 0;
    429  1.1  drochner #define d (*(int *)data)
    430  1.1  drochner 		if (d & LED_CAP)
    431  1.1  drochner 			intarg |= WSKBD_LED_CAPS;
    432  1.1  drochner 		if (d & LED_NUM)
    433  1.1  drochner 			intarg |= WSKBD_LED_NUM;
    434  1.1  drochner 		if (d & LED_SCR)
    435  1.1  drochner 			intarg |= WSKBD_LED_SCROLL;
    436  1.1  drochner #undef d
    437  1.1  drochner 		arg = &intarg;
    438  1.1  drochner 		break;
    439  1.1  drochner 	    case KDGETLED:
    440  1.1  drochner 		req = WSKBDIO_GETLEDS;
    441  1.1  drochner 		arg = &intarg;
    442  1.1  drochner 		break;
    443  1.1  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    444  1.1  drochner 	    case KDSKBMODE:
    445  1.1  drochner 		req = WSKBDIO_SETMODE;
    446  1.1  drochner 		switch (*(int *)data) {
    447  1.1  drochner 		    case K_RAW:
    448  1.1  drochner 			intarg = WSKBD_RAW;
    449  1.1  drochner 			break;
    450  1.1  drochner 		    case K_XLATE:
    451  1.1  drochner 			intarg = WSKBD_TRANSLATED;
    452  1.1  drochner 			break;
    453  1.1  drochner 		    default:
    454  1.1  drochner 			return (EINVAL);
    455  1.1  drochner 		}
    456  1.1  drochner 		arg = &intarg;
    457  1.1  drochner 		break;
    458  1.1  drochner 	    case KDGKBMODE:
    459  1.1  drochner 		req = WSKBDIO_GETMODE;
    460  1.1  drochner 		arg = &intarg;
    461  1.1  drochner 		break;
    462  1.1  drochner #endif
    463  1.1  drochner 	}
    464  1.1  drochner 
    465  1.1  drochner 	res = wsdisplay_internal_ioctl(sc, scr, req, arg, flag, p);
    466  1.1  drochner 	if (res)
    467  1.1  drochner 		return (res);
    468  1.1  drochner 
    469  1.1  drochner 	switch (cmd) {
    470  1.1  drochner 	    case KDGETLED:
    471  1.1  drochner #define d (*(int *)data)
    472  1.1  drochner 		d = 0;
    473  1.1  drochner 		if (intarg & WSKBD_LED_CAPS)
    474  1.1  drochner 			d |= LED_CAP;
    475  1.1  drochner 		if (intarg & WSKBD_LED_NUM)
    476  1.1  drochner 			d |= LED_NUM;
    477  1.1  drochner 		if (intarg & WSKBD_LED_SCROLL)
    478  1.1  drochner 			d |= LED_SCR;
    479  1.1  drochner #undef d
    480  1.1  drochner 		break;
    481  1.1  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    482  1.1  drochner 	    case KDGKBMODE:
    483  1.1  drochner 		*(int *)data = (intarg == WSKBD_RAW ? K_RAW : K_XLATE);
    484  1.1  drochner 		break;
    485  1.1  drochner #endif
    486  1.1  drochner 	}
    487  1.1  drochner 
    488  1.1  drochner 	return (0);
    489  1.1  drochner }
    490