Home | History | Annotate | Line # | Download | only in wscons
wsdisplay_compat_usl.c revision 1.46
      1  1.46  christos /* $NetBSD: wsdisplay_compat_usl.c,v 1.46 2009/10/04 22:24:15 christos 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.46  christos __KERNEL_RCSID(0, "$NetBSD: wsdisplay_compat_usl.c,v 1.46 2009/10/04 22:24:15 christos 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.41        ad 	callout_t s_attach_ch;
     65  1.41        ad 	callout_t 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.44  drochner static int usl_sync_check(void *);
     72  1.44  drochner static int usl_sync_check_sig(struct usl_syncdata *, int, int);
     73  1.16  augustss static struct usl_syncdata *usl_sync_get(struct wsscreen *);
     74  1.16  augustss 
     75  1.16  augustss static int usl_detachproc(void *, int, void (*)(void *, int, int), void *);
     76  1.16  augustss static int usl_detachack(struct usl_syncdata *, int);
     77  1.16  augustss static void usl_detachtimeout(void *);
     78  1.16  augustss static int usl_attachproc(void *, int, void (*)(void *, int, int), void *);
     79  1.16  augustss static int usl_attachack(struct usl_syncdata *, int);
     80  1.16  augustss static void usl_attachtimeout(void *);
     81   1.1  drochner 
     82   1.1  drochner static const struct wscons_syncops usl_syncops = {
     83   1.1  drochner 	usl_detachproc,
     84   1.1  drochner 	usl_attachproc,
     85  1.44  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.41        ad 	callout_init(&sd->s_attach_ch, 0);
    113  1.42     joerg 	callout_setfunc(&sd->s_attach_ch, usl_attachtimeout, sd);
    114  1.41        ad 	callout_init(&sd->s_detach_ch, 0);
    115  1.42     joerg 	callout_setfunc(&sd->s_detach_ch, usl_detachtimeout, sd);
    116   1.1  drochner 	res = wsscreen_attach_sync(scr, &usl_syncops, sd);
    117   1.1  drochner 	if (res) {
    118   1.1  drochner 		free(sd, M_DEVBUF);
    119   1.1  drochner 		return (res);
    120   1.1  drochner 	}
    121   1.1  drochner 	*sdp = sd;
    122   1.1  drochner 	return (0);
    123   1.1  drochner }
    124   1.1  drochner 
    125   1.1  drochner static void
    126  1.16  augustss usl_sync_done(struct usl_syncdata *sd)
    127   1.1  drochner {
    128   1.2  drochner 	if (sd->s_flags & SF_DETACHPENDING) {
    129  1.12   thorpej 		callout_stop(&sd->s_detach_ch);
    130   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, 0, 0);
    131   1.2  drochner 	}
    132   1.6  drochner 	if (sd->s_flags & SF_ATTACHPENDING) {
    133  1.12   thorpej 		callout_stop(&sd->s_attach_ch);
    134   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, ENXIO, 0);
    135   1.6  drochner 	}
    136   1.1  drochner 	wsscreen_detach_sync(sd->s_scr);
    137   1.1  drochner 	free(sd, M_DEVBUF);
    138   1.1  drochner }
    139   1.1  drochner 
    140   1.1  drochner static int
    141  1.44  drochner usl_sync_check_sig(struct usl_syncdata *sd, int sig, int flags)
    142   1.1  drochner {
    143  1.44  drochner 
    144  1.45        ad 	mutex_enter(proc_lock);
    145  1.44  drochner 	if (sd->s_proc == p_find(sd->s_pid, PFIND_LOCKED)) {
    146  1.44  drochner 		sd->s_flags |= flags;
    147  1.44  drochner 		if (sig)
    148  1.44  drochner 			psignal(sd->s_proc, sig);
    149  1.45        ad 		mutex_exit(proc_lock);
    150   1.1  drochner 		return (1);
    151  1.44  drochner 	}
    152  1.45        ad 	mutex_exit(proc_lock);
    153  1.44  drochner 
    154   1.1  drochner 	printf("usl_sync_check: process %d died\n", sd->s_pid);
    155   1.1  drochner 	usl_sync_done(sd);
    156   1.1  drochner 	return (0);
    157   1.1  drochner }
    158   1.1  drochner 
    159  1.44  drochner static int
    160  1.44  drochner usl_sync_check(void *vsd)
    161  1.44  drochner {
    162  1.44  drochner 
    163  1.44  drochner 	struct usl_syncdata *sd = vsd;
    164  1.44  drochner 	return usl_sync_check_sig(sd, 0, 0);
    165  1.44  drochner }
    166  1.44  drochner 
    167   1.1  drochner static struct usl_syncdata *
    168  1.16  augustss usl_sync_get(struct wsscreen *scr)
    169   1.1  drochner {
    170  1.20      fvdl 	void *sd;
    171   1.1  drochner 
    172  1.20      fvdl 	if (wsscreen_lookup_sync(scr, &usl_syncops, &sd))
    173   1.1  drochner 		return (0);
    174  1.20      fvdl 	return (struct usl_syncdata *)sd;
    175   1.1  drochner }
    176   1.1  drochner 
    177   1.1  drochner static int
    178  1.37  christos usl_detachproc(void *cookie, int waitok,
    179  1.35  christos     void (*callback)(void *, int, int), void *cbarg)
    180   1.1  drochner {
    181   1.1  drochner 	struct usl_syncdata *sd = cookie;
    182   1.1  drochner 
    183  1.11  drochner 	/* we really need a callback */
    184  1.11  drochner 	if (!callback)
    185  1.11  drochner 		return (EINVAL);
    186  1.11  drochner 
    187   1.1  drochner 	/*
    188   1.1  drochner 	 * Normally, this is called from the controlling process.
    189   1.1  drochner 	 * Is is supposed to reply with a VT_RELDISP ioctl(), so
    190   1.1  drochner 	 * it is not useful to tsleep() here.
    191   1.1  drochner 	 */
    192   1.1  drochner 	sd->s_callback = callback;
    193   1.1  drochner 	sd->s_cbarg = cbarg;
    194  1.46  christos 	if (waitok) {
    195  1.46  christos 		if (!usl_sync_check_sig(sd, sd->s_relsig, SF_DETACHPENDING))
    196  1.46  christos 			return (0);
    197  1.46  christos 	}
    198  1.44  drochner 
    199  1.42     joerg 	callout_schedule(&sd->s_detach_ch, wscompat_usl_synctimeout * hz);
    200   1.1  drochner 	return (EAGAIN);
    201   1.1  drochner }
    202   1.1  drochner 
    203   1.1  drochner static int
    204  1.16  augustss usl_detachack(struct usl_syncdata *sd, int ack)
    205   1.1  drochner {
    206   1.1  drochner 	if (!(sd->s_flags & SF_DETACHPENDING)) {
    207   1.1  drochner 		printf("usl_detachack: not detaching\n");
    208   1.1  drochner 		return (EINVAL);
    209   1.1  drochner 	}
    210   1.1  drochner 
    211  1.12   thorpej 	callout_stop(&sd->s_detach_ch);
    212   1.1  drochner 	sd->s_flags &= ~SF_DETACHPENDING;
    213   1.1  drochner 
    214   1.6  drochner 	if (sd->s_callback)
    215   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, (ack ? 0 : EIO), 1);
    216   1.1  drochner 
    217   1.1  drochner 	return (0);
    218   1.1  drochner }
    219   1.1  drochner 
    220   1.1  drochner static void
    221  1.16  augustss usl_detachtimeout(void *arg)
    222   1.1  drochner {
    223   1.1  drochner 	struct usl_syncdata *sd = arg;
    224   1.1  drochner 
    225   1.1  drochner 	printf("usl_detachtimeout\n");
    226   1.1  drochner 
    227   1.1  drochner 	if (!(sd->s_flags & SF_DETACHPENDING)) {
    228   1.1  drochner 		printf("usl_detachtimeout: not detaching\n");
    229   1.1  drochner 		return;
    230   1.1  drochner 	}
    231   1.1  drochner 
    232   1.1  drochner 	sd->s_flags &= ~SF_DETACHPENDING;
    233   1.6  drochner 
    234   1.6  drochner 	if (sd->s_callback)
    235   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, EIO, 0);
    236   1.6  drochner 
    237   1.1  drochner 	(void) usl_sync_check(sd);
    238   1.1  drochner }
    239   1.1  drochner 
    240   1.1  drochner static int
    241  1.37  christos usl_attachproc(void *cookie, int waitok,
    242  1.35  christos     void (*callback)(void *, int, int), void *cbarg)
    243   1.1  drochner {
    244   1.1  drochner 	struct usl_syncdata *sd = cookie;
    245   1.1  drochner 
    246  1.11  drochner 	/* we really need a callback */
    247  1.11  drochner 	if (!callback)
    248  1.11  drochner 		return (EINVAL);
    249   1.1  drochner 
    250   1.6  drochner 	sd->s_callback = callback;
    251   1.6  drochner 	sd->s_cbarg = cbarg;
    252  1.44  drochner 	if (!usl_sync_check_sig(sd, sd->s_acqsig, SF_ATTACHPENDING))
    253  1.44  drochner 		return (0);
    254  1.44  drochner 
    255  1.42     joerg 	callout_schedule(&sd->s_attach_ch, wscompat_usl_synctimeout * hz);
    256   1.1  drochner 	return (EAGAIN);
    257   1.1  drochner }
    258   1.1  drochner 
    259   1.1  drochner static int
    260  1.16  augustss usl_attachack(struct usl_syncdata *sd, int ack)
    261   1.1  drochner {
    262   1.1  drochner 	if (!(sd->s_flags & SF_ATTACHPENDING)) {
    263   1.1  drochner 		printf("usl_attachack: not attaching\n");
    264   1.1  drochner 		return (EINVAL);
    265   1.1  drochner 	}
    266   1.1  drochner 
    267  1.12   thorpej 	callout_stop(&sd->s_attach_ch);
    268   1.1  drochner 	sd->s_flags &= ~SF_ATTACHPENDING;
    269   1.6  drochner 
    270   1.6  drochner 	if (sd->s_callback)
    271   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, (ack ? 0 : EIO), 1);
    272   1.6  drochner 
    273   1.1  drochner 	return (0);
    274   1.1  drochner }
    275   1.1  drochner 
    276   1.1  drochner static void
    277  1.16  augustss usl_attachtimeout(void *arg)
    278   1.1  drochner {
    279   1.1  drochner 	struct usl_syncdata *sd = arg;
    280   1.1  drochner 
    281   1.1  drochner 	printf("usl_attachtimeout\n");
    282   1.1  drochner 
    283   1.1  drochner 	if (!(sd->s_flags & SF_ATTACHPENDING)) {
    284   1.1  drochner 		printf("usl_attachtimeout: not attaching\n");
    285   1.1  drochner 		return;
    286   1.1  drochner 	}
    287   1.1  drochner 
    288   1.1  drochner 	sd->s_flags &= ~SF_ATTACHPENDING;
    289   1.6  drochner 
    290   1.6  drochner 	if (sd->s_callback)
    291   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, EIO, 0);
    292   1.6  drochner 
    293   1.1  drochner 	(void) usl_sync_check(sd);
    294   1.1  drochner }
    295   1.1  drochner 
    296   1.1  drochner int
    297  1.43     joerg wsdisplay_usl_ioctl1(device_t dv, u_long cmd, void *data,
    298  1.37  christos     int flag, struct lwp *l)
    299  1.10   mycroft {
    300  1.43     joerg 	struct wsdisplay_softc *sc = device_private(dv);
    301  1.10   mycroft 	int idx, maxidx;
    302  1.10   mycroft 
    303  1.10   mycroft 	switch (cmd) {
    304  1.10   mycroft 	    case VT_OPENQRY:
    305  1.10   mycroft 		maxidx = wsdisplay_maxscreenidx(sc);
    306  1.10   mycroft 		for (idx = 0; idx <= maxidx; idx++) {
    307  1.10   mycroft 			if (wsdisplay_screenstate(sc, idx) == 0) {
    308  1.10   mycroft 				*(int *)data = idx + 1;
    309  1.10   mycroft 				return (0);
    310  1.10   mycroft 			}
    311  1.10   mycroft 		}
    312  1.10   mycroft 		return (ENXIO);
    313  1.10   mycroft 	    case VT_GETACTIVE:
    314  1.10   mycroft 		idx = wsdisplay_getactivescreen(sc);
    315  1.10   mycroft 		*(int *)data = idx + 1;
    316  1.10   mycroft 		return (0);
    317  1.10   mycroft 	    case VT_ACTIVATE:
    318  1.27  macallan 	    	/*
    319  1.27  macallan 	    	 * a gross and disgusting hack to make this abused up ioctl,
    320  1.27  macallan 		 * which is a gross and disgusting hack on its own, work on
    321  1.27  macallan 		 * LP64/BE - we want the lower 32bit so we simply dereference
    322  1.27  macallan 		 * the argument pointer as long. May cause problems with 32bit
    323  1.27  macallan 		 * kernels on sparc64?
    324  1.27  macallan 		 */
    325  1.27  macallan 
    326  1.27  macallan 		idx = *(long *)data - 1;
    327  1.14  takemura 		if (idx < 0)
    328  1.14  takemura 			return (EINVAL);
    329  1.43     joerg 		return (wsdisplay_switch(dv, idx, 1));
    330  1.10   mycroft 	    case VT_WAITACTIVE:
    331  1.27  macallan 		idx = *(long *)data - 1;
    332  1.14  takemura 		if (idx < 0)
    333  1.14  takemura 			return (EINVAL);
    334  1.10   mycroft 		return (wsscreen_switchwait(sc, idx));
    335  1.10   mycroft 	    case VT_GETSTATE:
    336  1.10   mycroft #define ss ((struct vt_stat *)data)
    337  1.10   mycroft 		idx = wsdisplay_getactivescreen(sc);
    338  1.10   mycroft 		ss->v_active = idx + 1;
    339  1.10   mycroft 		ss->v_state = 0;
    340  1.10   mycroft 		maxidx = wsdisplay_maxscreenidx(sc);
    341  1.10   mycroft 		for (idx = 0; idx <= maxidx; idx++)
    342  1.10   mycroft 			if (wsdisplay_screenstate(sc, idx) == EBUSY)
    343  1.10   mycroft 				ss->v_state |= (1 << (idx + 1));
    344  1.26    martin #undef ss
    345  1.10   mycroft 		return (0);
    346  1.10   mycroft 
    347  1.10   mycroft #ifdef WSDISPLAY_COMPAT_PCVT
    348  1.10   mycroft 	    case VGAPCVTID:
    349  1.10   mycroft #define id ((struct pcvtid *)data)
    350  1.25    itojun 		strlcpy(id->name, "pcvt", sizeof(id->name));
    351  1.10   mycroft 		id->rmajor = 3;
    352  1.10   mycroft 		id->rminor = 32;
    353  1.10   mycroft #undef id
    354  1.10   mycroft 		return (0);
    355  1.10   mycroft #endif
    356  1.10   mycroft #ifdef WSDISPLAY_COMPAT_SYSCONS
    357  1.10   mycroft 	    case CONS_GETVERS:
    358  1.10   mycroft 		*(int *)data = 0x200;    /* version 2.0 */
    359  1.10   mycroft 		return (0);
    360  1.10   mycroft #endif
    361  1.10   mycroft 
    362  1.10   mycroft 	    default:
    363  1.18    atatat 		return (EPASSTHROUGH);
    364  1.10   mycroft 	}
    365  1.10   mycroft }
    366  1.10   mycroft 
    367  1.10   mycroft int
    368  1.16  augustss wsdisplay_usl_ioctl2(struct wsdisplay_softc *sc, struct wsscreen *scr,
    369  1.40  christos 		     u_long cmd, void *data, int flag, struct lwp *l)
    370   1.1  drochner {
    371  1.30  christos 	struct proc *p = l->l_proc;
    372  1.31  jmcneill 	int intarg = 0, res;
    373  1.13    simonb 	u_long req;
    374  1.15    simonb 	void *arg;
    375   1.1  drochner 	struct usl_syncdata *sd;
    376   1.1  drochner 	struct wskbd_bell_data bd;
    377   1.1  drochner 
    378   1.1  drochner 	switch (cmd) {
    379   1.1  drochner 	    case VT_SETMODE:
    380   1.1  drochner #define newmode ((struct vt_mode *)data)
    381   1.1  drochner 		if (newmode->mode == VT_PROCESS) {
    382   1.3  drochner 			res = usl_sync_init(scr, &sd, p, newmode->acqsig,
    383   1.3  drochner 					    newmode->relsig, newmode->frsig);
    384   1.1  drochner 			if (res)
    385   1.1  drochner 				return (res);
    386   1.1  drochner 		} else {
    387   1.1  drochner 			sd = usl_sync_get(scr);
    388   1.1  drochner 			if (sd)
    389   1.1  drochner 				usl_sync_done(sd);
    390   1.1  drochner 		}
    391   1.1  drochner #undef newmode
    392   1.1  drochner 		return (0);
    393   1.1  drochner 	    case VT_GETMODE:
    394   1.1  drochner #define cmode ((struct vt_mode *)data)
    395   1.1  drochner 		sd = usl_sync_get(scr);
    396   1.1  drochner 		if (sd) {
    397   1.1  drochner 			cmode->mode = VT_PROCESS;
    398   1.1  drochner 			cmode->relsig = sd->s_relsig;
    399   1.1  drochner 			cmode->acqsig = sd->s_acqsig;
    400   1.1  drochner 			cmode->frsig = sd->s_frsig;
    401   1.1  drochner 		} else
    402   1.1  drochner 			cmode->mode = VT_AUTO;
    403   1.1  drochner #undef cmode
    404   1.1  drochner 		return (0);
    405   1.1  drochner 	    case VT_RELDISP:
    406  1.27  macallan #define d (*(long *)data)
    407   1.1  drochner 		sd = usl_sync_get(scr);
    408   1.1  drochner 		if (!sd)
    409   1.1  drochner 			return (EINVAL);
    410   1.1  drochner 		switch (d) {
    411   1.1  drochner 		    case VT_FALSE:
    412   1.1  drochner 		    case VT_TRUE:
    413   1.1  drochner 			return (usl_detachack(sd, (d == VT_TRUE)));
    414   1.1  drochner 		    case VT_ACKACQ:
    415   1.1  drochner 			return (usl_attachack(sd, 1));
    416   1.1  drochner 		    default:
    417   1.1  drochner 			return (EINVAL);
    418   1.1  drochner 		}
    419   1.1  drochner #undef d
    420  1.10   mycroft 
    421   1.1  drochner 	    case KDENABIO:
    422  1.36     bjh21 #if defined(__i386__) && (defined(COMPAT_11) || defined(COMPAT_FREEBSD))
    423  1.38      elad 		if (kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_IOPL,
    424  1.38      elad 		    NULL, NULL, NULL, NULL) != 0)
    425   1.1  drochner 			return (EPERM);
    426  1.34      elad #endif
    427   1.1  drochner 		/* FALLTHRU */
    428   1.1  drochner 	    case KDDISABIO:
    429  1.36     bjh21 #if defined(__i386__) && (defined(COMPAT_11) || defined(COMPAT_FREEBSD))
    430   1.1  drochner 		{
    431  1.21   thorpej 			/* XXX NJWLWP */
    432  1.21   thorpej 		struct trapframe *fp = (struct trapframe *)curlwp->l_md.md_regs;
    433   1.1  drochner 		if (cmd == KDENABIO)
    434   1.1  drochner 			fp->tf_eflags |= PSL_IOPL;
    435   1.1  drochner 		else
    436   1.1  drochner 			fp->tf_eflags &= ~PSL_IOPL;
    437   1.1  drochner 		}
    438   1.1  drochner #endif
    439   1.1  drochner 		return (0);
    440   1.1  drochner 	    case KDSETRAD:
    441   1.1  drochner 		/* XXX ignore for now */
    442   1.1  drochner 		return (0);
    443   1.1  drochner 
    444   1.1  drochner 	    default:
    445  1.18    atatat 		return (EPASSTHROUGH);
    446   1.1  drochner 
    447   1.1  drochner 	    /*
    448   1.1  drochner 	     * the following are converted to wsdisplay ioctls
    449   1.1  drochner 	     */
    450   1.1  drochner 	    case KDSETMODE:
    451   1.1  drochner 		req = WSDISPLAYIO_SMODE;
    452  1.29  macallan #define d (*(int *)data)
    453   1.1  drochner 		switch (d) {
    454   1.1  drochner 		    case KD_GRAPHICS:
    455   1.1  drochner 			intarg = WSDISPLAYIO_MODE_MAPPED;
    456   1.1  drochner 			break;
    457   1.1  drochner 		    case KD_TEXT:
    458   1.1  drochner 			intarg = WSDISPLAYIO_MODE_EMUL;
    459   1.1  drochner 			break;
    460   1.1  drochner 		    default:
    461   1.1  drochner 			return (EINVAL);
    462   1.1  drochner 		}
    463   1.1  drochner #undef d
    464   1.1  drochner 		arg = &intarg;
    465   1.1  drochner 		break;
    466   1.1  drochner 	    case KDMKTONE:
    467   1.1  drochner 		req = WSKBDIO_COMPLEXBELL;
    468   1.1  drochner #define d (*(int *)data)
    469   1.1  drochner 		if (d) {
    470   1.8  christos #define PCVT_SYSBEEPF	1193182
    471   1.8  christos 			if (d >> 16) {
    472   1.8  christos 				bd.which = WSKBD_BELL_DOPERIOD;
    473   1.8  christos 				bd.period = d >> 16; /* ms */
    474   1.8  christos 			}
    475   1.9  christos 			else
    476   1.9  christos 				bd.which = 0;
    477   1.8  christos 			if (d & 0xffff) {
    478   1.8  christos 				bd.which |= WSKBD_BELL_DOPITCH;
    479   1.8  christos 				bd.pitch = PCVT_SYSBEEPF/(d & 0xffff); /* Hz */
    480   1.8  christos 			}
    481   1.1  drochner 		} else
    482   1.1  drochner 			bd.which = 0; /* default */
    483   1.1  drochner #undef d
    484   1.1  drochner 		arg = &bd;
    485   1.1  drochner 		break;
    486   1.1  drochner 	    case KDSETLED:
    487   1.1  drochner 		req = WSKBDIO_SETLEDS;
    488   1.1  drochner 		intarg = 0;
    489  1.29  macallan #define d (*(int *)data)
    490   1.1  drochner 		if (d & LED_CAP)
    491   1.1  drochner 			intarg |= WSKBD_LED_CAPS;
    492   1.1  drochner 		if (d & LED_NUM)
    493   1.1  drochner 			intarg |= WSKBD_LED_NUM;
    494   1.1  drochner 		if (d & LED_SCR)
    495   1.1  drochner 			intarg |= WSKBD_LED_SCROLL;
    496   1.1  drochner #undef d
    497   1.1  drochner 		arg = &intarg;
    498   1.1  drochner 		break;
    499   1.1  drochner 	    case KDGETLED:
    500   1.1  drochner 		req = WSKBDIO_GETLEDS;
    501   1.1  drochner 		arg = &intarg;
    502   1.1  drochner 		break;
    503   1.1  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    504   1.1  drochner 	    case KDSKBMODE:
    505   1.1  drochner 		req = WSKBDIO_SETMODE;
    506  1.29  macallan 		switch (*(int *)data) {
    507   1.1  drochner 		    case K_RAW:
    508   1.1  drochner 			intarg = WSKBD_RAW;
    509   1.1  drochner 			break;
    510   1.1  drochner 		    case K_XLATE:
    511   1.1  drochner 			intarg = WSKBD_TRANSLATED;
    512   1.1  drochner 			break;
    513   1.1  drochner 		    default:
    514   1.1  drochner 			return (EINVAL);
    515   1.1  drochner 		}
    516   1.1  drochner 		arg = &intarg;
    517   1.1  drochner 		break;
    518   1.1  drochner 	    case KDGKBMODE:
    519   1.1  drochner 		req = WSKBDIO_GETMODE;
    520   1.1  drochner 		arg = &intarg;
    521   1.1  drochner 		break;
    522   1.1  drochner #endif
    523   1.1  drochner 	}
    524   1.1  drochner 
    525  1.30  christos 	res = wsdisplay_internal_ioctl(sc, scr, req, arg, flag, l);
    526  1.18    atatat 	if (res != EPASSTHROUGH)
    527   1.1  drochner 		return (res);
    528   1.1  drochner 
    529   1.1  drochner 	switch (cmd) {
    530   1.1  drochner 	    case KDGETLED:
    531   1.1  drochner #define d (*(int *)data)
    532   1.1  drochner 		d = 0;
    533   1.1  drochner 		if (intarg & WSKBD_LED_CAPS)
    534   1.1  drochner 			d |= LED_CAP;
    535   1.1  drochner 		if (intarg & WSKBD_LED_NUM)
    536   1.1  drochner 			d |= LED_NUM;
    537   1.1  drochner 		if (intarg & WSKBD_LED_SCROLL)
    538   1.1  drochner 			d |= LED_SCR;
    539   1.1  drochner #undef d
    540   1.1  drochner 		break;
    541   1.1  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    542   1.1  drochner 	    case KDGKBMODE:
    543   1.1  drochner 		*(int *)data = (intarg == WSKBD_RAW ? K_RAW : K_XLATE);
    544   1.1  drochner 		break;
    545   1.1  drochner #endif
    546   1.1  drochner 	}
    547   1.1  drochner 
    548   1.1  drochner 	return (0);
    549   1.1  drochner }
    550