Home | History | Annotate | Line # | Download | only in wscons
wsdisplay_compat_usl.c revision 1.13
      1  1.13    simonb /* $NetBSD: wsdisplay_compat_usl.c,v 1.13 2000/09/08 15:32:57 simonb 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.4   thorpej 
     35   1.4   thorpej #include "opt_compat_freebsd.h"
     36   1.5  jonathan #include "opt_compat_netbsd.h"
     37   1.1  drochner 
     38   1.1  drochner #include <sys/param.h>
     39   1.1  drochner #include <sys/systm.h>
     40  1.12   thorpej #include <sys/callout.h>
     41   1.1  drochner #include <sys/ioctl.h>
     42   1.1  drochner #include <sys/kernel.h>
     43   1.1  drochner #include <sys/proc.h>
     44   1.1  drochner #include <sys/signalvar.h>
     45   1.1  drochner #include <sys/malloc.h>
     46   1.1  drochner #include <sys/errno.h>
     47   1.1  drochner 
     48   1.1  drochner #include <dev/wscons/wsconsio.h>
     49   1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     50   1.1  drochner #include <dev/wscons/wscons_callbacks.h>
     51   1.1  drochner #include <dev/wscons/wsdisplay_usl_io.h>
     52   1.1  drochner 
     53   1.1  drochner #include "opt_wsdisplay_compat.h"
     54   1.1  drochner 
     55   1.1  drochner struct usl_syncdata {
     56   1.1  drochner 	struct wsscreen *s_scr;
     57   1.1  drochner 	struct proc *s_proc;
     58   1.1  drochner 	pid_t s_pid;
     59   1.1  drochner 	int s_flags;
     60   1.1  drochner #define SF_DETACHPENDING 1
     61   1.1  drochner #define SF_ATTACHPENDING 2
     62   1.1  drochner 	int s_acqsig, s_relsig;
     63   1.1  drochner 	int s_frsig; /* unused */
     64   1.6  drochner 	void (*s_callback) __P((void *, int, int));
     65   1.1  drochner 	void *s_cbarg;
     66  1.12   thorpej 	struct callout s_attach_ch;
     67  1.12   thorpej 	struct callout s_detach_ch;
     68   1.1  drochner };
     69   1.1  drochner 
     70   1.3  drochner static int usl_sync_init __P((struct wsscreen *, struct usl_syncdata **,
     71   1.3  drochner 			      struct proc *, int, int, int));
     72   1.1  drochner static void usl_sync_done __P((struct usl_syncdata *));
     73   1.1  drochner static int usl_sync_check __P((struct usl_syncdata *));
     74   1.1  drochner static struct usl_syncdata *usl_sync_get __P((struct wsscreen *));
     75   1.1  drochner 
     76   1.6  drochner static int usl_detachproc __P((void *, int,
     77   1.6  drochner 			       void (*)(void *, int, int), void *));
     78   1.1  drochner static int usl_detachack __P((struct usl_syncdata *, int));
     79   1.1  drochner static void usl_detachtimeout __P((void *));
     80   1.6  drochner static int usl_attachproc __P((void *, int,
     81   1.6  drochner 			       void (*)(void *, int, int), void *));
     82   1.1  drochner static int usl_attachack __P((struct usl_syncdata *, int));
     83   1.1  drochner static void usl_attachtimeout __P((void *));
     84   1.1  drochner 
     85   1.1  drochner static const struct wscons_syncops usl_syncops = {
     86   1.1  drochner 	usl_detachproc,
     87   1.1  drochner 	usl_attachproc,
     88   1.1  drochner #define _usl_sync_check ((int (*) __P((void *)))usl_sync_check)
     89   1.1  drochner 	_usl_sync_check,
     90   1.1  drochner #define _usl_sync_destroy ((void (*) __P((void *)))usl_sync_done)
     91   1.1  drochner 	_usl_sync_destroy
     92   1.1  drochner };
     93   1.1  drochner 
     94   1.7  drochner #ifndef WSCOMPAT_USL_SYNCTIMEOUT
     95   1.7  drochner #define WSCOMPAT_USL_SYNCTIMEOUT 5 /* seconds */
     96   1.7  drochner #endif
     97   1.7  drochner static int wscompat_usl_synctimeout = WSCOMPAT_USL_SYNCTIMEOUT;
     98   1.7  drochner 
     99   1.1  drochner static int
    100   1.3  drochner usl_sync_init(scr, sdp, p, acqsig, relsig, frsig)
    101   1.1  drochner 	struct wsscreen *scr;
    102   1.1  drochner 	struct usl_syncdata **sdp;
    103   1.3  drochner 	struct proc *p;
    104   1.3  drochner 	int acqsig, relsig, frsig;
    105   1.1  drochner {
    106   1.1  drochner 	struct usl_syncdata *sd;
    107   1.1  drochner 	int res;
    108   1.1  drochner 
    109   1.1  drochner 	sd = malloc(sizeof(struct usl_syncdata), M_DEVBUF, M_WAITOK);
    110   1.1  drochner 	if (!sd)
    111   1.1  drochner 		return (ENOMEM);
    112   1.1  drochner 	sd->s_scr = scr;
    113   1.3  drochner 	sd->s_proc = p;
    114   1.3  drochner 	sd->s_pid = p->p_pid;
    115   1.2  drochner 	sd->s_flags = 0;
    116   1.3  drochner 	sd->s_acqsig = acqsig;
    117   1.3  drochner 	sd->s_relsig = relsig;
    118   1.3  drochner 	sd->s_frsig = frsig;
    119  1.12   thorpej 	callout_init(&sd->s_attach_ch);
    120  1.12   thorpej 	callout_init(&sd->s_detach_ch);
    121   1.1  drochner 	res = wsscreen_attach_sync(scr, &usl_syncops, sd);
    122   1.1  drochner 	if (res) {
    123   1.1  drochner 		free(sd, M_DEVBUF);
    124   1.1  drochner 		return (res);
    125   1.1  drochner 	}
    126   1.1  drochner 	*sdp = sd;
    127   1.1  drochner 	return (0);
    128   1.1  drochner }
    129   1.1  drochner 
    130   1.1  drochner static void
    131   1.1  drochner usl_sync_done(sd)
    132   1.1  drochner 	struct usl_syncdata *sd;
    133   1.1  drochner {
    134   1.2  drochner 	if (sd->s_flags & SF_DETACHPENDING) {
    135  1.12   thorpej 		callout_stop(&sd->s_detach_ch);
    136   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, 0, 0);
    137   1.2  drochner 	}
    138   1.6  drochner 	if (sd->s_flags & SF_ATTACHPENDING) {
    139  1.12   thorpej 		callout_stop(&sd->s_attach_ch);
    140   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, ENXIO, 0);
    141   1.6  drochner 	}
    142   1.1  drochner 	wsscreen_detach_sync(sd->s_scr);
    143   1.1  drochner 	free(sd, M_DEVBUF);
    144   1.1  drochner }
    145   1.1  drochner 
    146   1.1  drochner static int
    147   1.1  drochner usl_sync_check(sd)
    148   1.1  drochner 	struct usl_syncdata *sd;
    149   1.1  drochner {
    150   1.1  drochner 	if (sd->s_proc == pfind(sd->s_pid))
    151   1.1  drochner 		return (1);
    152   1.1  drochner 	printf("usl_sync_check: process %d died\n", sd->s_pid);
    153   1.1  drochner 	usl_sync_done(sd);
    154   1.1  drochner 	return (0);
    155   1.1  drochner }
    156   1.1  drochner 
    157   1.1  drochner static struct usl_syncdata *
    158   1.1  drochner usl_sync_get(scr)
    159   1.1  drochner 	struct wsscreen *scr;
    160   1.1  drochner {
    161   1.1  drochner 	struct usl_syncdata *sd;
    162   1.1  drochner 
    163   1.1  drochner 	if (wsscreen_lookup_sync(scr, &usl_syncops, (void **)&sd))
    164   1.1  drochner 		return (0);
    165   1.1  drochner 	return (sd);
    166   1.1  drochner }
    167   1.1  drochner 
    168   1.1  drochner static int
    169   1.1  drochner usl_detachproc(cookie, waitok, callback, cbarg)
    170   1.1  drochner 	void *cookie;
    171   1.1  drochner 	int waitok;
    172   1.6  drochner 	void (*callback) __P((void *, int, int));
    173   1.1  drochner 	void *cbarg;
    174   1.1  drochner {
    175   1.1  drochner 	struct usl_syncdata *sd = cookie;
    176   1.1  drochner 
    177   1.1  drochner 	if (!usl_sync_check(sd))
    178   1.1  drochner 		return (0);
    179   1.1  drochner 
    180  1.11  drochner 	/* we really need a callback */
    181  1.11  drochner 	if (!callback)
    182  1.11  drochner 		return (EINVAL);
    183  1.11  drochner 
    184   1.1  drochner 	/*
    185   1.1  drochner 	 * Normally, this is called from the controlling process.
    186   1.1  drochner 	 * Is is supposed to reply with a VT_RELDISP ioctl(), so
    187   1.1  drochner 	 * it is not useful to tsleep() here.
    188   1.1  drochner 	 */
    189   1.1  drochner 	sd->s_callback = callback;
    190   1.1  drochner 	sd->s_cbarg = cbarg;
    191   1.1  drochner 	sd->s_flags |= SF_DETACHPENDING;
    192   1.1  drochner 	psignal(sd->s_proc, sd->s_relsig);
    193  1.12   thorpej 	callout_reset(&sd->s_detach_ch, wscompat_usl_synctimeout * hz,
    194  1.12   thorpej 	    usl_detachtimeout, sd);
    195   1.1  drochner 
    196   1.1  drochner 	return (EAGAIN);
    197   1.1  drochner }
    198   1.1  drochner 
    199   1.1  drochner static int
    200   1.1  drochner usl_detachack(sd, ack)
    201   1.1  drochner 	struct usl_syncdata *sd;
    202   1.1  drochner 	int ack;
    203   1.1  drochner {
    204   1.1  drochner 	if (!(sd->s_flags & SF_DETACHPENDING)) {
    205   1.1  drochner 		printf("usl_detachack: not detaching\n");
    206   1.1  drochner 		return (EINVAL);
    207   1.1  drochner 	}
    208   1.1  drochner 
    209  1.12   thorpej 	callout_stop(&sd->s_detach_ch);
    210   1.1  drochner 	sd->s_flags &= ~SF_DETACHPENDING;
    211   1.1  drochner 
    212   1.6  drochner 	if (sd->s_callback)
    213   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, (ack ? 0 : EIO), 1);
    214   1.1  drochner 
    215   1.1  drochner 	return (0);
    216   1.1  drochner }
    217   1.1  drochner 
    218   1.1  drochner static void
    219   1.1  drochner usl_detachtimeout(arg)
    220   1.1  drochner 	void *arg;
    221   1.1  drochner {
    222   1.1  drochner 	struct usl_syncdata *sd = arg;
    223   1.1  drochner 
    224   1.1  drochner 	printf("usl_detachtimeout\n");
    225   1.1  drochner 
    226   1.1  drochner 	if (!(sd->s_flags & SF_DETACHPENDING)) {
    227   1.1  drochner 		printf("usl_detachtimeout: not detaching\n");
    228   1.1  drochner 		return;
    229   1.1  drochner 	}
    230   1.1  drochner 
    231   1.1  drochner 	sd->s_flags &= ~SF_DETACHPENDING;
    232   1.6  drochner 
    233   1.6  drochner 	if (sd->s_callback)
    234   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, EIO, 0);
    235   1.6  drochner 
    236   1.1  drochner 	(void) usl_sync_check(sd);
    237   1.1  drochner }
    238   1.1  drochner 
    239   1.1  drochner static int
    240   1.6  drochner usl_attachproc(cookie, waitok, callback, cbarg)
    241   1.1  drochner 	void *cookie;
    242   1.1  drochner 	int waitok;
    243   1.6  drochner 	void (*callback) __P((void *, int, int));
    244   1.6  drochner 	void *cbarg;
    245   1.1  drochner {
    246   1.1  drochner 	struct usl_syncdata *sd = cookie;
    247   1.1  drochner 
    248   1.1  drochner 	if (!usl_sync_check(sd))
    249   1.1  drochner 		return (0);
    250  1.11  drochner 
    251  1.11  drochner 	/* we really need a callback */
    252  1.11  drochner 	if (!callback)
    253  1.11  drochner 		return (EINVAL);
    254   1.1  drochner 
    255   1.6  drochner 	sd->s_callback = callback;
    256   1.6  drochner 	sd->s_cbarg = cbarg;
    257   1.1  drochner 	sd->s_flags |= SF_ATTACHPENDING;
    258   1.1  drochner 	psignal(sd->s_proc, sd->s_acqsig);
    259  1.12   thorpej 	callout_reset(&sd->s_attach_ch, wscompat_usl_synctimeout * hz,
    260  1.12   thorpej 	    usl_attachtimeout, sd);
    261   1.1  drochner 
    262   1.1  drochner 	return (EAGAIN);
    263   1.1  drochner }
    264   1.1  drochner 
    265   1.1  drochner static int
    266   1.1  drochner usl_attachack(sd, ack)
    267   1.1  drochner 	struct usl_syncdata *sd;
    268   1.1  drochner 	int ack;
    269   1.1  drochner {
    270   1.1  drochner 	if (!(sd->s_flags & SF_ATTACHPENDING)) {
    271   1.1  drochner 		printf("usl_attachack: not attaching\n");
    272   1.1  drochner 		return (EINVAL);
    273   1.1  drochner 	}
    274   1.1  drochner 
    275  1.12   thorpej 	callout_stop(&sd->s_attach_ch);
    276   1.1  drochner 	sd->s_flags &= ~SF_ATTACHPENDING;
    277   1.6  drochner 
    278   1.6  drochner 	if (sd->s_callback)
    279   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, (ack ? 0 : EIO), 1);
    280   1.6  drochner 
    281   1.1  drochner 	return (0);
    282   1.1  drochner }
    283   1.1  drochner 
    284   1.1  drochner static void
    285   1.1  drochner usl_attachtimeout(arg)
    286   1.1  drochner 	void *arg;
    287   1.1  drochner {
    288   1.1  drochner 	struct usl_syncdata *sd = arg;
    289   1.1  drochner 
    290   1.1  drochner 	printf("usl_attachtimeout\n");
    291   1.1  drochner 
    292   1.1  drochner 	if (!(sd->s_flags & SF_ATTACHPENDING)) {
    293   1.1  drochner 		printf("usl_attachtimeout: not attaching\n");
    294   1.1  drochner 		return;
    295   1.1  drochner 	}
    296   1.1  drochner 
    297   1.1  drochner 	sd->s_flags &= ~SF_ATTACHPENDING;
    298   1.6  drochner 
    299   1.6  drochner 	if (sd->s_callback)
    300   1.6  drochner 		(*sd->s_callback)(sd->s_cbarg, EIO, 0);
    301   1.6  drochner 
    302   1.1  drochner 	(void) usl_sync_check(sd);
    303   1.1  drochner }
    304   1.1  drochner 
    305   1.1  drochner int
    306  1.10   mycroft wsdisplay_usl_ioctl1(sc, cmd, data, flag, p)
    307  1.10   mycroft 	struct wsdisplay_softc *sc;
    308  1.10   mycroft 	u_long cmd;
    309  1.10   mycroft 	caddr_t data;
    310  1.10   mycroft 	int flag;
    311  1.10   mycroft 	struct proc *p;
    312  1.10   mycroft {
    313  1.10   mycroft 	int idx, maxidx;
    314  1.10   mycroft 
    315  1.10   mycroft 	switch (cmd) {
    316  1.10   mycroft 	    case VT_OPENQRY:
    317  1.10   mycroft 		maxidx = wsdisplay_maxscreenidx(sc);
    318  1.10   mycroft 		for (idx = 0; idx <= maxidx; idx++) {
    319  1.10   mycroft 			if (wsdisplay_screenstate(sc, idx) == 0) {
    320  1.10   mycroft 				*(int *)data = idx + 1;
    321  1.10   mycroft 				return (0);
    322  1.10   mycroft 			}
    323  1.10   mycroft 		}
    324  1.10   mycroft 		return (ENXIO);
    325  1.10   mycroft 	    case VT_GETACTIVE:
    326  1.10   mycroft 		idx = wsdisplay_getactivescreen(sc);
    327  1.10   mycroft 		*(int *)data = idx + 1;
    328  1.10   mycroft 		return (0);
    329  1.10   mycroft 	    case VT_ACTIVATE:
    330  1.10   mycroft 		idx = *(int *)data - 1;
    331  1.10   mycroft 		return (wsdisplay_switch((struct device *)sc, idx, 1));
    332  1.10   mycroft 	    case VT_WAITACTIVE:
    333  1.10   mycroft 		idx = *(int *)data - 1;
    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.10   mycroft #undef s
    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.10   mycroft 		strcpy(id->name, "pcvt");
    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.10   mycroft 		return (-1);
    364  1.10   mycroft 	}
    365  1.10   mycroft 
    366  1.10   mycroft 	return (0);
    367  1.10   mycroft }
    368  1.10   mycroft 
    369  1.10   mycroft int
    370  1.10   mycroft wsdisplay_usl_ioctl2(sc, scr, cmd, data, flag, p)
    371   1.1  drochner 	struct wsdisplay_softc *sc;
    372   1.1  drochner 	struct wsscreen *scr;
    373   1.1  drochner 	u_long cmd;
    374   1.1  drochner 	caddr_t data;
    375   1.1  drochner 	int flag;
    376   1.1  drochner 	struct proc *p;
    377   1.1  drochner {
    378  1.13    simonb 	int res, intarg;
    379  1.13    simonb 	u_long req;
    380   1.1  drochner 	struct usl_syncdata *sd;
    381   1.1  drochner 	struct wskbd_bell_data bd;
    382   1.1  drochner 	void *arg;
    383   1.1  drochner 
    384   1.1  drochner 	switch (cmd) {
    385   1.1  drochner 	    case VT_SETMODE:
    386   1.1  drochner #define newmode ((struct vt_mode *)data)
    387   1.1  drochner 		if (newmode->mode == VT_PROCESS) {
    388   1.3  drochner 			res = usl_sync_init(scr, &sd, p, newmode->acqsig,
    389   1.3  drochner 					    newmode->relsig, newmode->frsig);
    390   1.1  drochner 			if (res)
    391   1.1  drochner 				return (res);
    392   1.1  drochner 		} else {
    393   1.1  drochner 			sd = usl_sync_get(scr);
    394   1.1  drochner 			if (sd)
    395   1.1  drochner 				usl_sync_done(sd);
    396   1.1  drochner 		}
    397   1.1  drochner #undef newmode
    398   1.1  drochner 		return (0);
    399   1.1  drochner 	    case VT_GETMODE:
    400   1.1  drochner #define cmode ((struct vt_mode *)data)
    401   1.1  drochner 		sd = usl_sync_get(scr);
    402   1.1  drochner 		if (sd) {
    403   1.1  drochner 			cmode->mode = VT_PROCESS;
    404   1.1  drochner 			cmode->relsig = sd->s_relsig;
    405   1.1  drochner 			cmode->acqsig = sd->s_acqsig;
    406   1.1  drochner 			cmode->frsig = sd->s_frsig;
    407   1.1  drochner 		} else
    408   1.1  drochner 			cmode->mode = VT_AUTO;
    409   1.1  drochner #undef cmode
    410   1.1  drochner 		return (0);
    411   1.1  drochner 	    case VT_RELDISP:
    412   1.1  drochner #define d (*(int *)data)
    413   1.1  drochner 		sd = usl_sync_get(scr);
    414   1.1  drochner 		if (!sd)
    415   1.1  drochner 			return (EINVAL);
    416   1.1  drochner 		switch (d) {
    417   1.1  drochner 		    case VT_FALSE:
    418   1.1  drochner 		    case VT_TRUE:
    419   1.1  drochner 			return (usl_detachack(sd, (d == VT_TRUE)));
    420   1.1  drochner 		    case VT_ACKACQ:
    421   1.1  drochner 			return (usl_attachack(sd, 1));
    422   1.1  drochner 		    default:
    423   1.1  drochner 			return (EINVAL);
    424   1.1  drochner 		}
    425   1.1  drochner #undef d
    426   1.1  drochner 		return (0);
    427  1.10   mycroft 
    428   1.1  drochner 	    case KDENABIO:
    429   1.1  drochner 		if (suser(p->p_ucred, &p->p_acflag) || securelevel > 1)
    430   1.1  drochner 			return (EPERM);
    431   1.1  drochner 		/* FALLTHRU */
    432   1.1  drochner 	    case KDDISABIO:
    433   1.1  drochner #if defined(__i386__)
    434   1.1  drochner #if defined(COMPAT_10) || defined(COMPAT_11) || defined(COMPAT_FREEBSD)
    435   1.1  drochner 		{
    436   1.1  drochner 		struct trapframe *fp = (struct trapframe *)p->p_md.md_regs;
    437   1.1  drochner 		if (cmd == KDENABIO)
    438   1.1  drochner 			fp->tf_eflags |= PSL_IOPL;
    439   1.1  drochner 		else
    440   1.1  drochner 			fp->tf_eflags &= ~PSL_IOPL;
    441   1.1  drochner 		}
    442   1.1  drochner #endif
    443   1.1  drochner #endif
    444   1.1  drochner 		return (0);
    445   1.1  drochner 	    case KDSETRAD:
    446   1.1  drochner 		/* XXX ignore for now */
    447   1.1  drochner 		return (0);
    448   1.1  drochner 
    449   1.1  drochner 	    default:
    450   1.1  drochner 		return (-1);
    451   1.1  drochner 
    452   1.1  drochner 	    /*
    453   1.1  drochner 	     * the following are converted to wsdisplay ioctls
    454   1.1  drochner 	     */
    455   1.1  drochner 	    case KDSETMODE:
    456   1.1  drochner 		req = WSDISPLAYIO_SMODE;
    457   1.1  drochner #define d (*(int *)data)
    458   1.1  drochner 		switch (d) {
    459   1.1  drochner 		    case KD_GRAPHICS:
    460   1.1  drochner 			intarg = WSDISPLAYIO_MODE_MAPPED;
    461   1.1  drochner 			break;
    462   1.1  drochner 		    case KD_TEXT:
    463   1.1  drochner 			intarg = WSDISPLAYIO_MODE_EMUL;
    464   1.1  drochner 			break;
    465   1.1  drochner 		    default:
    466   1.1  drochner 			return (EINVAL);
    467   1.1  drochner 		}
    468   1.1  drochner #undef d
    469   1.1  drochner 		arg = &intarg;
    470   1.1  drochner 		break;
    471   1.1  drochner 	    case KDMKTONE:
    472   1.1  drochner 		req = WSKBDIO_COMPLEXBELL;
    473   1.1  drochner #define d (*(int *)data)
    474   1.1  drochner 		if (d) {
    475   1.8  christos #define PCVT_SYSBEEPF	1193182
    476   1.8  christos 			if (d >> 16) {
    477   1.8  christos 				bd.which = WSKBD_BELL_DOPERIOD;
    478   1.8  christos 				bd.period = d >> 16; /* ms */
    479   1.8  christos 			}
    480   1.9  christos 			else
    481   1.9  christos 				bd.which = 0;
    482   1.8  christos 			if (d & 0xffff) {
    483   1.8  christos 				bd.which |= WSKBD_BELL_DOPITCH;
    484   1.8  christos 				bd.pitch = PCVT_SYSBEEPF/(d & 0xffff); /* Hz */
    485   1.8  christos 			}
    486   1.1  drochner 		} else
    487   1.1  drochner 			bd.which = 0; /* default */
    488   1.1  drochner #undef d
    489   1.1  drochner 		arg = &bd;
    490   1.1  drochner 		break;
    491   1.1  drochner 	    case KDSETLED:
    492   1.1  drochner 		req = WSKBDIO_SETLEDS;
    493   1.1  drochner 		intarg = 0;
    494   1.1  drochner #define d (*(int *)data)
    495   1.1  drochner 		if (d & LED_CAP)
    496   1.1  drochner 			intarg |= WSKBD_LED_CAPS;
    497   1.1  drochner 		if (d & LED_NUM)
    498   1.1  drochner 			intarg |= WSKBD_LED_NUM;
    499   1.1  drochner 		if (d & LED_SCR)
    500   1.1  drochner 			intarg |= WSKBD_LED_SCROLL;
    501   1.1  drochner #undef d
    502   1.1  drochner 		arg = &intarg;
    503   1.1  drochner 		break;
    504   1.1  drochner 	    case KDGETLED:
    505   1.1  drochner 		req = WSKBDIO_GETLEDS;
    506   1.1  drochner 		arg = &intarg;
    507   1.1  drochner 		break;
    508   1.1  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    509   1.1  drochner 	    case KDSKBMODE:
    510   1.1  drochner 		req = WSKBDIO_SETMODE;
    511   1.1  drochner 		switch (*(int *)data) {
    512   1.1  drochner 		    case K_RAW:
    513   1.1  drochner 			intarg = WSKBD_RAW;
    514   1.1  drochner 			break;
    515   1.1  drochner 		    case K_XLATE:
    516   1.1  drochner 			intarg = WSKBD_TRANSLATED;
    517   1.1  drochner 			break;
    518   1.1  drochner 		    default:
    519   1.1  drochner 			return (EINVAL);
    520   1.1  drochner 		}
    521   1.1  drochner 		arg = &intarg;
    522   1.1  drochner 		break;
    523   1.1  drochner 	    case KDGKBMODE:
    524   1.1  drochner 		req = WSKBDIO_GETMODE;
    525   1.1  drochner 		arg = &intarg;
    526   1.1  drochner 		break;
    527   1.1  drochner #endif
    528   1.1  drochner 	}
    529   1.1  drochner 
    530   1.1  drochner 	res = wsdisplay_internal_ioctl(sc, scr, req, arg, flag, p);
    531   1.1  drochner 	if (res)
    532   1.1  drochner 		return (res);
    533   1.1  drochner 
    534   1.1  drochner 	switch (cmd) {
    535   1.1  drochner 	    case KDGETLED:
    536   1.1  drochner #define d (*(int *)data)
    537   1.1  drochner 		d = 0;
    538   1.1  drochner 		if (intarg & WSKBD_LED_CAPS)
    539   1.1  drochner 			d |= LED_CAP;
    540   1.1  drochner 		if (intarg & WSKBD_LED_NUM)
    541   1.1  drochner 			d |= LED_NUM;
    542   1.1  drochner 		if (intarg & WSKBD_LED_SCROLL)
    543   1.1  drochner 			d |= LED_SCR;
    544   1.1  drochner #undef d
    545   1.1  drochner 		break;
    546   1.1  drochner #ifdef WSDISPLAY_COMPAT_RAWKBD
    547   1.1  drochner 	    case KDGKBMODE:
    548   1.1  drochner 		*(int *)data = (intarg == WSKBD_RAW ? K_RAW : K_XLATE);
    549   1.1  drochner 		break;
    550   1.1  drochner #endif
    551   1.1  drochner 	}
    552   1.1  drochner 
    553   1.1  drochner 	return (0);
    554   1.1  drochner }
    555