xref: /onnv-gate/usr/src/uts/common/io/vuidmice/vuidmice.c (revision 9840:bff764ffad2c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55202Smeem  * Common Development and Distribution License (the "License").
65202Smeem  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*9840Sgdamore@opensolaris.org  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * VUIDMICE module:  put mouse events into vuid format
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/param.h>
320Sstevel@tonic-gate #include <sys/stream.h>
330Sstevel@tonic-gate #include <sys/stropts.h>
340Sstevel@tonic-gate #include <sys/strsun.h>
350Sstevel@tonic-gate #include <sys/errno.h>
360Sstevel@tonic-gate #include <sys/debug.h>
370Sstevel@tonic-gate #include <sys/cmn_err.h>
380Sstevel@tonic-gate #include <sys/sad.h>
390Sstevel@tonic-gate #include <sys/vuid_event.h>
40*9840Sgdamore@opensolaris.org #include "vuidmice.h"
410Sstevel@tonic-gate #include <sys/vuid_wheel.h>
420Sstevel@tonic-gate #include <sys/msio.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #include <sys/conf.h>
450Sstevel@tonic-gate #include <sys/modctl.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #include <sys/kmem.h>
480Sstevel@tonic-gate #include <sys/ddi.h>
490Sstevel@tonic-gate #include <sys/sunddi.h>
500Sstevel@tonic-gate 
510Sstevel@tonic-gate static int vuidmice_open(queue_t *const, const dev_t *const,
520Sstevel@tonic-gate 	const int, const int, const cred_t *const);
530Sstevel@tonic-gate static int vuidmice_close(queue_t *const, const int, const cred_t *const);
540Sstevel@tonic-gate static int vuidmice_rput(queue_t *const, mblk_t *);
550Sstevel@tonic-gate static int vuidmice_rsrv(queue_t *const);
560Sstevel@tonic-gate static int vuidmice_wput(queue_t *const, mblk_t *);
570Sstevel@tonic-gate static void vuidmice_miocdata(queue_t *const, mblk_t *);
580Sstevel@tonic-gate static int vuidmice_handle_wheel_resolution_ioctl(queue_t *const,
590Sstevel@tonic-gate 	mblk_t *, int);
600Sstevel@tonic-gate 
610Sstevel@tonic-gate static int vuidmice_service_wheel_info(mblk_t *);
620Sstevel@tonic-gate static int vuidmice_service_wheel_state(queue_t *, mblk_t *, uint_t);
630Sstevel@tonic-gate 
640Sstevel@tonic-gate void VUID_QUEUE(queue_t *const, mblk_t *);
650Sstevel@tonic-gate int VUID_OPEN(queue_t *const);
660Sstevel@tonic-gate void VUID_CLOSE(queue_t *const);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate static kmutex_t vuidmice_lock;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate static struct module_info vuidmice_iinfo = {
710Sstevel@tonic-gate 	0,
720Sstevel@tonic-gate 	VUID_NAME,
730Sstevel@tonic-gate 	0,
740Sstevel@tonic-gate 	INFPSZ,
750Sstevel@tonic-gate 	1000,
760Sstevel@tonic-gate 	100
770Sstevel@tonic-gate };
780Sstevel@tonic-gate 
790Sstevel@tonic-gate static struct qinit vuidmice_rinit = {
800Sstevel@tonic-gate 	vuidmice_rput,
810Sstevel@tonic-gate 	vuidmice_rsrv,
820Sstevel@tonic-gate 	vuidmice_open,
830Sstevel@tonic-gate 	vuidmice_close,
840Sstevel@tonic-gate 	NULL,
850Sstevel@tonic-gate 	&vuidmice_iinfo,
860Sstevel@tonic-gate 	NULL
870Sstevel@tonic-gate };
880Sstevel@tonic-gate 
890Sstevel@tonic-gate static struct module_info vuidmice_oinfo = {
900Sstevel@tonic-gate 	0,
910Sstevel@tonic-gate 	VUID_NAME,
920Sstevel@tonic-gate 	0,
930Sstevel@tonic-gate 	INFPSZ,
940Sstevel@tonic-gate 	1000,
950Sstevel@tonic-gate 	100
960Sstevel@tonic-gate };
970Sstevel@tonic-gate 
980Sstevel@tonic-gate static struct qinit vuidmice_winit = {
990Sstevel@tonic-gate 	vuidmice_wput,
1000Sstevel@tonic-gate 	NULL,
1010Sstevel@tonic-gate 	NULL,
1020Sstevel@tonic-gate 	NULL,
1030Sstevel@tonic-gate 	NULL,
1040Sstevel@tonic-gate 	&vuidmice_oinfo,
1050Sstevel@tonic-gate 	NULL
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate struct streamtab vuidmice_info = {
1090Sstevel@tonic-gate 	&vuidmice_rinit,
1100Sstevel@tonic-gate 	&vuidmice_winit,
1110Sstevel@tonic-gate 	NULL,
1120Sstevel@tonic-gate 	NULL
1130Sstevel@tonic-gate };
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate  * This is the loadable module wrapper.
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * D_MTQPAIR effectively makes the module single threaded.
1210Sstevel@tonic-gate  * There can be only one thread active in the module at any time.
1220Sstevel@tonic-gate  * It may be a read or write thread.
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate #define	VUIDMICE_CONF_FLAG	(D_MP | D_MTQPAIR)
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate static struct fmodsw fsw = {
1270Sstevel@tonic-gate 	VUID_NAME,
1280Sstevel@tonic-gate 	&vuidmice_info,
1290Sstevel@tonic-gate 	VUIDMICE_CONF_FLAG
1300Sstevel@tonic-gate };
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1330Sstevel@tonic-gate 	&mod_strmodops,
1340Sstevel@tonic-gate 	"mouse events to vuid events",
1350Sstevel@tonic-gate 	&fsw
1360Sstevel@tonic-gate };
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate  * Module linkage information for the kernel.
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate static struct modlinkage modlinkage = {
1420Sstevel@tonic-gate 	MODREV_1,
1430Sstevel@tonic-gate 	&modlstrmod,
1440Sstevel@tonic-gate 	NULL
1450Sstevel@tonic-gate };
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate static int module_open = 0;	/* allow only one open of this module */
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate int
_init(void)1500Sstevel@tonic-gate _init(void)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	register int rc;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	mutex_init(&vuidmice_lock, NULL, MUTEX_DEFAULT, NULL);
1550Sstevel@tonic-gate 	if ((rc = mod_install(&modlinkage)) != 0) {
1560Sstevel@tonic-gate 		mutex_destroy(&vuidmice_lock);
1570Sstevel@tonic-gate 	}
1580Sstevel@tonic-gate 	return (rc);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate int
_fini(void)1620Sstevel@tonic-gate _fini(void)
1630Sstevel@tonic-gate {
1640Sstevel@tonic-gate 	register int rc;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	if ((rc = mod_remove(&modlinkage)) == 0)
1670Sstevel@tonic-gate 		mutex_destroy(&vuidmice_lock);
1680Sstevel@tonic-gate 	return (rc);
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1720Sstevel@tonic-gate _info(struct modinfo *modinfop)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate /* ARGSUSED1 */
1790Sstevel@tonic-gate static int
vuidmice_open(queue_t * const qp,const dev_t * const devp,const int oflag,const int sflag,const cred_t * const crp)1800Sstevel@tonic-gate vuidmice_open(queue_t *const qp, const dev_t *const devp,
1810Sstevel@tonic-gate 	const int oflag, const int sflag, const cred_t *const crp)
1820Sstevel@tonic-gate {
1835202Smeem 	if (qp->q_ptr != NULL)
1845202Smeem 		return (0);	 /* reopen */
1855202Smeem 
1860Sstevel@tonic-gate 	mutex_enter(&vuidmice_lock);
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	/* Allow only 1 open of this module */
1890Sstevel@tonic-gate 	if (module_open) {
1900Sstevel@tonic-gate 		mutex_exit(&vuidmice_lock);
1910Sstevel@tonic-gate 		return (EBUSY);
1920Sstevel@tonic-gate 	}
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	module_open++;
1955202Smeem 	mutex_exit(&vuidmice_lock);
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 	/*
1980Sstevel@tonic-gate 	 * Both the read and write queues share the same state structures.
1990Sstevel@tonic-gate 	 */
2000Sstevel@tonic-gate 	qp->q_ptr = kmem_zalloc(sizeof (struct MouseStateInfo), KM_SLEEP);
2010Sstevel@tonic-gate 	WR(qp)->q_ptr = qp->q_ptr;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	/* initialize state */
2040Sstevel@tonic-gate 	STATEP->format = VUID_NATIVE;
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	qprocson(qp);
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate #ifdef	VUID_OPEN
2090Sstevel@tonic-gate 	if (VUID_OPEN(qp) != 0) {
2100Sstevel@tonic-gate 		qprocsoff(qp);
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 		mutex_enter(&vuidmice_lock);
2130Sstevel@tonic-gate 		module_open--;
2145202Smeem 		mutex_exit(&vuidmice_lock);
2150Sstevel@tonic-gate 		kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
2160Sstevel@tonic-gate 		qp->q_ptr = NULL;
2170Sstevel@tonic-gate 		return (ENXIO);
2180Sstevel@tonic-gate 	}
2190Sstevel@tonic-gate #endif
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 	return (0);
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate /* ARGSUSED1 */
2250Sstevel@tonic-gate static int
vuidmice_close(queue_t * const qp,const int flag,const cred_t * const crp)2260Sstevel@tonic-gate vuidmice_close(queue_t *const qp, const int flag, const cred_t *const crp)
2270Sstevel@tonic-gate {
2280Sstevel@tonic-gate 	ASSERT(qp != NULL);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 	qprocsoff(qp);
2310Sstevel@tonic-gate 	flushq(qp, FLUSHALL);
2320Sstevel@tonic-gate 	flushq(OTHERQ(qp), FLUSHALL);
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate #ifdef	VUID_CLOSE
2350Sstevel@tonic-gate 	VUID_CLOSE(qp);
2360Sstevel@tonic-gate #endif
2375202Smeem 	mutex_enter(&vuidmice_lock);
2380Sstevel@tonic-gate 	module_open--;
2395202Smeem 	mutex_exit(&vuidmice_lock);
2400Sstevel@tonic-gate 	kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
2415202Smeem 	qp->q_ptr = NULL;
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	return (0);
2440Sstevel@tonic-gate }
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate /*
2470Sstevel@tonic-gate  * Put procedure for input from driver end of stream (read queue).
2480Sstevel@tonic-gate  */
2490Sstevel@tonic-gate static int
vuidmice_rput(queue_t * const qp,mblk_t * mp)2500Sstevel@tonic-gate vuidmice_rput(queue_t *const qp, mblk_t *mp)
2510Sstevel@tonic-gate {
2520Sstevel@tonic-gate 	ASSERT(qp != NULL);
2530Sstevel@tonic-gate 	ASSERT(mp != NULL);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	/*
2560Sstevel@tonic-gate 	 * Handle all the related high priority messages here, hence
2570Sstevel@tonic-gate 	 * should spend the least amount of time here.
2580Sstevel@tonic-gate 	 */
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 	if (DB_TYPE(mp) == M_DATA) {
2610Sstevel@tonic-gate 		if ((int)STATEP->format ==  VUID_FIRM_EVENT)
2620Sstevel@tonic-gate 			return (putq(qp, mp));   /* queue message & return */
2630Sstevel@tonic-gate 	} else if (DB_TYPE(mp) == M_FLUSH) {
2640Sstevel@tonic-gate 			if (*mp->b_rptr & FLUSHR)
2650Sstevel@tonic-gate 				flushq(qp, FLUSHALL);
2660Sstevel@tonic-gate 	}
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	putnext(qp, mp);	/* pass it on */
2690Sstevel@tonic-gate 	return (0);
2700Sstevel@tonic-gate }
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate static int
vuidmice_rsrv(queue_t * const qp)2730Sstevel@tonic-gate vuidmice_rsrv(queue_t *const qp)
2740Sstevel@tonic-gate {
2750Sstevel@tonic-gate 	register mblk_t *mp;
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	ASSERT(qp != NULL);
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 	while ((mp = getq(qp)) != NULL) {
2800Sstevel@tonic-gate 		ASSERT(DB_TYPE(mp) == M_DATA);
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate 		if (!canputnext(qp))
2830Sstevel@tonic-gate 			return (putbq(qp, mp)); /* read side is blocked */
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 		switch (DB_TYPE(mp)) {
2865202Smeem 		case M_DATA:
2875202Smeem 			if ((int)STATEP->format == VUID_FIRM_EVENT)
2885202Smeem 				(void) VUID_QUEUE(qp, mp);
2895202Smeem 			else
2905202Smeem 				(void) putnext(qp, mp);
2915202Smeem 			break;
2920Sstevel@tonic-gate 
2935202Smeem 		default:
2945202Smeem 			cmn_err(CE_WARN,
2955202Smeem 			    "vuidmice_rsrv: bad message type (0x%x)\n",
2965202Smeem 			    DB_TYPE(mp));
2970Sstevel@tonic-gate 
2985202Smeem 			(void) putnext(qp, mp);
2995202Smeem 			break;
3000Sstevel@tonic-gate 		}
3010Sstevel@tonic-gate 	}
3020Sstevel@tonic-gate 	return (0);
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate  * Put procedure for write from user end of stream (write queue).
3070Sstevel@tonic-gate  */
3080Sstevel@tonic-gate static int
vuidmice_wput(queue_t * const qp,mblk_t * mp)3090Sstevel@tonic-gate vuidmice_wput(queue_t *const qp, mblk_t *mp)
3100Sstevel@tonic-gate {
3110Sstevel@tonic-gate 	int	error = 0;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate 	ASSERT(qp != NULL);
3140Sstevel@tonic-gate 	ASSERT(mp != NULL);
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	/*
3170Sstevel@tonic-gate 	 * Handle all the related high priority messages here, hence
3180Sstevel@tonic-gate 	 * should spend the least amount of time here.
3190Sstevel@tonic-gate 	 */
3200Sstevel@tonic-gate 	switch (DB_TYPE(mp)) {	/* handle hi pri messages here */
3210Sstevel@tonic-gate 	case M_FLUSH:
3220Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW)
3230Sstevel@tonic-gate 			flushq(qp, FLUSHALL);
3240Sstevel@tonic-gate 		putnext(qp, mp);			/* pass it on */
3250Sstevel@tonic-gate 		return (0);
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 	case M_IOCTL: {
3286990Sgd78059 		struct iocblk *iocbp = (void *)mp->b_rptr;
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 		switch (iocbp->ioc_cmd) {
3310Sstevel@tonic-gate 		case VUIDSFORMAT:
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 			/*
3340Sstevel@tonic-gate 			 * VUIDSFORMAT is known to the stream head and thus
3350Sstevel@tonic-gate 			 * is guaranteed to be an I_STR ioctl.
3360Sstevel@tonic-gate 			 */
3370Sstevel@tonic-gate 			if (iocbp->ioc_count == TRANSPARENT) {
3380Sstevel@tonic-gate 				miocnak(qp, mp, 0, EINVAL);
3390Sstevel@tonic-gate 				return (0);
3400Sstevel@tonic-gate 			} else {
3410Sstevel@tonic-gate 				int format_type;
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 				error = miocpullup(mp, sizeof (int));
3440Sstevel@tonic-gate 				if (error != 0) {
3450Sstevel@tonic-gate 					miocnak(qp, mp, 0, error);
3460Sstevel@tonic-gate 					return (0);
3470Sstevel@tonic-gate 				}
3480Sstevel@tonic-gate 
3496990Sgd78059 				format_type =
3506990Sgd78059 				    *(int *)(void *)mp->b_cont->b_rptr;
3510Sstevel@tonic-gate 				STATEP->format = (uchar_t)format_type;
3520Sstevel@tonic-gate 				iocbp->ioc_rval = 0;
3530Sstevel@tonic-gate 				iocbp->ioc_count = 0;
3540Sstevel@tonic-gate 				iocbp->ioc_error = 0;
3550Sstevel@tonic-gate 				mp->b_datap->db_type = M_IOCACK;
3560Sstevel@tonic-gate 			}
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 			/* return buffer to pool ASAP */
3590Sstevel@tonic-gate 			if (mp->b_cont) {
3600Sstevel@tonic-gate 				freemsg(mp->b_cont);
3610Sstevel@tonic-gate 				mp->b_cont = NULL;
3620Sstevel@tonic-gate 			}
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 			qreply(qp, mp);
3650Sstevel@tonic-gate 			return (0);
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate 		case VUIDGFORMAT:
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 			/* return buffer to pool ASAP */
3700Sstevel@tonic-gate 			if (mp->b_cont) {
3710Sstevel@tonic-gate 				freemsg(mp->b_cont); /* over written below */
3720Sstevel@tonic-gate 				mp->b_cont = NULL;
3730Sstevel@tonic-gate 			}
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 			/*
3760Sstevel@tonic-gate 			 * VUIDGFORMAT is known to the stream head and thus
3770Sstevel@tonic-gate 			 * is guaranteed to be an I_STR ioctl.
3780Sstevel@tonic-gate 			 */
3790Sstevel@tonic-gate 			if (iocbp->ioc_count == TRANSPARENT) {
3800Sstevel@tonic-gate 				miocnak(qp, mp, 0, EINVAL);
3810Sstevel@tonic-gate 				return (0);
3820Sstevel@tonic-gate 			}
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 			mp->b_cont = allocb(sizeof (int), BPRI_MED);
3850Sstevel@tonic-gate 			if (mp->b_cont == NULL) {
3860Sstevel@tonic-gate 				miocnak(qp, mp, 0, EAGAIN);
3870Sstevel@tonic-gate 				return (0);
3880Sstevel@tonic-gate 			}
3890Sstevel@tonic-gate 
3906990Sgd78059 			*(int *)(void *)mp->b_cont->b_rptr =
3916990Sgd78059 			    (int)STATEP->format;
3920Sstevel@tonic-gate 			mp->b_cont->b_wptr += sizeof (int);
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 			iocbp->ioc_count = sizeof (int);
3950Sstevel@tonic-gate 			mp->b_datap->db_type = M_IOCACK;
3960Sstevel@tonic-gate 			qreply(qp, mp);
3970Sstevel@tonic-gate 			return (0);
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 		case VUID_NATIVE:
4000Sstevel@tonic-gate 		case VUIDSADDR:
4010Sstevel@tonic-gate 		case VUIDGADDR:
4020Sstevel@tonic-gate 			miocnak(qp, mp, 0, ENOTTY);
4030Sstevel@tonic-gate 			return (0);
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 		case MSIOBUTTONS:
4060Sstevel@tonic-gate 			/* return buffer to pool ASAP */
4070Sstevel@tonic-gate 			if (mp->b_cont) {
4080Sstevel@tonic-gate 				freemsg(mp->b_cont); /* over written below */
4090Sstevel@tonic-gate 				mp->b_cont = NULL;
4100Sstevel@tonic-gate 			}
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate 			/*
4130Sstevel@tonic-gate 			 * MSIOBUTTONS is known to streamio.c and this
4140Sstevel@tonic-gate 			 * is assume to be non-I_STR & non-TRANSPARENT ioctl
4150Sstevel@tonic-gate 			 */
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 			if (iocbp->ioc_count == TRANSPARENT) {
4180Sstevel@tonic-gate 				miocnak(qp, mp, 0, EINVAL);
4190Sstevel@tonic-gate 				return (0);
4200Sstevel@tonic-gate 			}
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 			if (STATEP->nbuttons == 0) {
4230Sstevel@tonic-gate 				miocnak(qp, mp, 0, EINVAL);
4240Sstevel@tonic-gate 				return (0);
4250Sstevel@tonic-gate 			}
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate 			mp->b_cont = allocb(sizeof (int), BPRI_MED);
4280Sstevel@tonic-gate 			if (mp->b_cont == NULL) {
4290Sstevel@tonic-gate 				miocnak(qp, mp, 0, EAGAIN);
4300Sstevel@tonic-gate 				return (0);
4310Sstevel@tonic-gate 			}
4320Sstevel@tonic-gate 
4336990Sgd78059 			*(int *)(void *)mp->b_cont->b_rptr =
4346990Sgd78059 			    (int)STATEP->nbuttons;
4350Sstevel@tonic-gate 			mp->b_cont->b_wptr += sizeof (int);
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 			iocbp->ioc_count = sizeof (int);
4380Sstevel@tonic-gate 			mp->b_datap->db_type = M_IOCACK;
4390Sstevel@tonic-gate 			qreply(qp, mp);
4400Sstevel@tonic-gate 			return (0);
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate 		/*
4430Sstevel@tonic-gate 		 * New IOCTL support. Since it's explicitly mentioned
4440Sstevel@tonic-gate 		 * that you can't add more ioctls to stream head's
4450Sstevel@tonic-gate 		 * hard coded list, we have to do the transparent
4460Sstevel@tonic-gate 		 * ioctl processing which is not very exciting.
4470Sstevel@tonic-gate 		 */
4480Sstevel@tonic-gate 		case VUIDGWHEELCOUNT:
4490Sstevel@tonic-gate 		case VUIDGWHEELINFO:
4500Sstevel@tonic-gate 		case VUIDGWHEELSTATE:
4510Sstevel@tonic-gate 		case VUIDSWHEELSTATE:
4520Sstevel@tonic-gate 		case MSIOSRESOLUTION:
4530Sstevel@tonic-gate 			error = vuidmice_handle_wheel_resolution_ioctl(qp,
4545202Smeem 			    mp, iocbp->ioc_cmd);
4550Sstevel@tonic-gate 			if (!error) {
4560Sstevel@tonic-gate 				return (0);
4570Sstevel@tonic-gate 			} else {
4580Sstevel@tonic-gate 				miocnak(qp, mp, 0, error);
4590Sstevel@tonic-gate 				return (0);
4600Sstevel@tonic-gate 			}
4610Sstevel@tonic-gate 		default:
4620Sstevel@tonic-gate 			putnext(qp, mp);	/* nothing to process here */
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 			return (0);
4650Sstevel@tonic-gate 		}
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	} /* End of case M_IOCTL */
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate 	case M_IOCDATA:
4700Sstevel@tonic-gate 		vuidmice_miocdata(qp, mp);
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 		return (0);
4730Sstevel@tonic-gate 	default:
4740Sstevel@tonic-gate 		putnext(qp, mp);		/* pass it on */
4750Sstevel@tonic-gate 		return (0);
4760Sstevel@tonic-gate 	}
4770Sstevel@tonic-gate 	/*NOTREACHED*/
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate void
VUID_PUTNEXT(queue_t * const qp,uchar_t event_id,uchar_t event_pair_type,uchar_t event_pair,int event_value)4810Sstevel@tonic-gate VUID_PUTNEXT(queue_t *const qp, uchar_t event_id, uchar_t event_pair_type,
4820Sstevel@tonic-gate 	uchar_t event_pair, int event_value)
4830Sstevel@tonic-gate {
4840Sstevel@tonic-gate 	int strikes = 1;
4850Sstevel@tonic-gate 	mblk_t *bp;
4860Sstevel@tonic-gate 	Firm_event *fep;
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate 	/*
4890Sstevel@tonic-gate 	 * Give this event 3 chances to allocate blocks,
4900Sstevel@tonic-gate 	 * otherwise discard this mouse event.  3 Strikes and you're out.
4910Sstevel@tonic-gate 	 */
4920Sstevel@tonic-gate 	while ((bp = allocb((int)sizeof (Firm_event), BPRI_HI)) == NULL) {
4930Sstevel@tonic-gate 		if (++strikes > 3)
4940Sstevel@tonic-gate 			return;
4950Sstevel@tonic-gate 		drv_usecwait(10);
4960Sstevel@tonic-gate 	}
4970Sstevel@tonic-gate 
4986990Sgd78059 	fep = (void *)bp->b_wptr;
4990Sstevel@tonic-gate 	fep->id = vuid_id_addr(VKEY_FIRST) | vuid_id_offset(event_id);
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate 	fep->pair_type	= event_pair_type;
5020Sstevel@tonic-gate 	fep->pair	= event_pair;
5030Sstevel@tonic-gate 	fep->value	= event_value;
5040Sstevel@tonic-gate 	uniqtime32(&fep->time);
5050Sstevel@tonic-gate 	bp->b_wptr += sizeof (Firm_event);
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate 	if (canput(qp->q_next))
5080Sstevel@tonic-gate 		putnext(qp, bp);
5090Sstevel@tonic-gate 	else
5100Sstevel@tonic-gate 		(void) putbq(qp, bp); /* read side is blocked */
5110Sstevel@tonic-gate }
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate /*
5150Sstevel@tonic-gate  * vuidmice_miocdata
5160Sstevel@tonic-gate  *	M_IOCDATA processing for IOCTL's: VUIDGWHEELCOUNT, VUIDGWHEELINFO,
5170Sstevel@tonic-gate  *	VUIDGWHEELSTATE, VUIDSWHEELSTATE & MSIOSRESOLUTION.
5180Sstevel@tonic-gate  */
5190Sstevel@tonic-gate static void
vuidmice_miocdata(queue_t * qp,mblk_t * mp)5200Sstevel@tonic-gate vuidmice_miocdata(queue_t *qp, mblk_t  *mp)
5210Sstevel@tonic-gate {
5220Sstevel@tonic-gate 	struct copyresp		*copyresp;
5230Sstevel@tonic-gate 	struct iocblk		*iocbp;
5240Sstevel@tonic-gate 	mblk_t			*ioctmp;
5250Sstevel@tonic-gate 	mblk_t			*datap;
5260Sstevel@tonic-gate 	Mouse_iocstate_t	*Mouseioc;
5276710Syz224750 	size_t			size;
5280Sstevel@tonic-gate 	int			err = 0;
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate 
5316990Sgd78059 	copyresp = (void *)mp->b_rptr;
5326990Sgd78059 	iocbp = (void *)mp->b_rptr;
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 	if (copyresp->cp_rval) {
5350Sstevel@tonic-gate 		err = EAGAIN;
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 		goto err;
5380Sstevel@tonic-gate 	}
5390Sstevel@tonic-gate 	switch (copyresp->cp_cmd) {
5400Sstevel@tonic-gate 	case VUIDGWHEELCOUNT:
5410Sstevel@tonic-gate 		mp->b_datap->db_type = M_IOCACK;
5420Sstevel@tonic-gate 		mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
5430Sstevel@tonic-gate 		iocbp->ioc_error = 0;
5440Sstevel@tonic-gate 		iocbp->ioc_count = 0;
5450Sstevel@tonic-gate 		iocbp->ioc_rval = 0;
5460Sstevel@tonic-gate 		if (mp->b_cont != NULL) {
5470Sstevel@tonic-gate 			freemsg(mp->b_cont);
5480Sstevel@tonic-gate 			mp->b_cont = NULL;
5490Sstevel@tonic-gate 		}
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate 		break;
5520Sstevel@tonic-gate 	case VUIDGWHEELINFO:
5530Sstevel@tonic-gate 	case VUIDGWHEELSTATE:
5546990Sgd78059 		ioctmp = copyresp->cp_private;
5556990Sgd78059 		Mouseioc = (void *)ioctmp->b_rptr;
5560Sstevel@tonic-gate 		if (Mouseioc->ioc_state == GETSTRUCT) {
5570Sstevel@tonic-gate 			if (mp->b_cont == NULL) {
5580Sstevel@tonic-gate 				err = EINVAL;
5590Sstevel@tonic-gate 
5600Sstevel@tonic-gate 				break;
5610Sstevel@tonic-gate 			}
5620Sstevel@tonic-gate 			datap = mp->b_cont;
5630Sstevel@tonic-gate 			if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
5640Sstevel@tonic-gate 				err = vuidmice_service_wheel_state(qp, datap,
5655202Smeem 				    VUIDGWHEELSTATE);
5660Sstevel@tonic-gate 			} else {
5670Sstevel@tonic-gate 				err = vuidmice_service_wheel_info(datap);
5680Sstevel@tonic-gate 			}
5690Sstevel@tonic-gate 			if (err) {
5700Sstevel@tonic-gate 				break;
5710Sstevel@tonic-gate 			}
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate 			if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
5746710Syz224750 				size = sizeof (wheel_state);
5750Sstevel@tonic-gate 			} else {
5766710Syz224750 				size = sizeof (wheel_info);
5770Sstevel@tonic-gate 			}
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate 			Mouseioc->ioc_state = GETRESULT;
5806710Syz224750 			ASSERT(Mouseioc->u_addr != NULL);
5816710Syz224750 			mcopyout(mp, ioctmp, size, Mouseioc->u_addr, NULL);
5820Sstevel@tonic-gate 		} else if (Mouseioc->ioc_state == GETRESULT) {
5830Sstevel@tonic-gate 			freemsg(ioctmp);
5840Sstevel@tonic-gate 			mp->b_datap->db_type = M_IOCACK;
5850Sstevel@tonic-gate 			mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
5860Sstevel@tonic-gate 			iocbp->ioc_error = 0;
5870Sstevel@tonic-gate 			iocbp->ioc_count = 0;
5880Sstevel@tonic-gate 			iocbp->ioc_rval = 0;
5890Sstevel@tonic-gate 			if (mp->b_cont != NULL) {
5900Sstevel@tonic-gate 				freemsg(mp->b_cont);
5910Sstevel@tonic-gate 				mp->b_cont = NULL;
5920Sstevel@tonic-gate 			}
5930Sstevel@tonic-gate 		}
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate 		break;
5960Sstevel@tonic-gate 	case VUIDSWHEELSTATE:
5970Sstevel@tonic-gate 	case MSIOSRESOLUTION:
5986990Sgd78059 		ioctmp = copyresp->cp_private;
5996990Sgd78059 		Mouseioc = (void *)ioctmp->b_rptr;
6000Sstevel@tonic-gate 		if (mp->b_cont == NULL) {
6010Sstevel@tonic-gate 			err = EINVAL;
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate 			break;
6040Sstevel@tonic-gate 		}
6050Sstevel@tonic-gate 		datap = mp->b_cont;
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate 		if (copyresp->cp_cmd == VUIDSWHEELSTATE) {
6080Sstevel@tonic-gate 			err = vuidmice_service_wheel_state(qp,
6090Sstevel@tonic-gate 			    datap, VUIDSWHEELSTATE);
6100Sstevel@tonic-gate 		}
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate 		if (err) {
6130Sstevel@tonic-gate 			break;
6140Sstevel@tonic-gate 		}
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate 		if (mp->b_cont) {
6170Sstevel@tonic-gate 			freemsg(mp->b_cont);
6186990Sgd78059 			mp->b_cont = NULL;
6190Sstevel@tonic-gate 		}
6200Sstevel@tonic-gate 		freemsg(ioctmp);
6210Sstevel@tonic-gate 		iocbp->ioc_count = 0;
6220Sstevel@tonic-gate 		iocbp->ioc_error = 0;
6230Sstevel@tonic-gate 		iocbp->ioc_rval = 0;
6240Sstevel@tonic-gate 		mp->b_datap->db_type = M_IOCACK;
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 		break;
6270Sstevel@tonic-gate 	default:
6280Sstevel@tonic-gate 		err = EINVAL;
6290Sstevel@tonic-gate 
6300Sstevel@tonic-gate 		break;
6310Sstevel@tonic-gate 	}
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate err:
6340Sstevel@tonic-gate 	if (err) {
6350Sstevel@tonic-gate 		mp->b_datap->db_type = M_IOCNAK;
6360Sstevel@tonic-gate 		if (mp->b_cont) {
6370Sstevel@tonic-gate 			freemsg(mp->b_cont);
6386990Sgd78059 			mp->b_cont = NULL;
6390Sstevel@tonic-gate 		}
6400Sstevel@tonic-gate 		if (copyresp->cp_private) {
6416990Sgd78059 			freemsg(copyresp->cp_private);
6426990Sgd78059 			copyresp->cp_private = NULL;
6430Sstevel@tonic-gate 		}
6440Sstevel@tonic-gate 		iocbp->ioc_count = 0;
6450Sstevel@tonic-gate 		iocbp->ioc_error = err;
6460Sstevel@tonic-gate 	}
6470Sstevel@tonic-gate 	qreply(qp, mp);
6480Sstevel@tonic-gate }
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate /*
6520Sstevel@tonic-gate  * vuidmice_handle_wheel_resolution_ioctl
6530Sstevel@tonic-gate  *	Handle wheel mouse and MSIOSRESOLUTION ioctls.
6540Sstevel@tonic-gate  *
6550Sstevel@tonic-gate  * Here we also support non-transparent way of these ioctls
6560Sstevel@tonic-gate  * just like usb mouse driver does, so the consms module is
6570Sstevel@tonic-gate  * very simple to deal with these ioctls.
6580Sstevel@tonic-gate  */
6590Sstevel@tonic-gate static int
vuidmice_handle_wheel_resolution_ioctl(queue_t * qp,mblk_t * mp,int cmd)6600Sstevel@tonic-gate vuidmice_handle_wheel_resolution_ioctl(queue_t *qp, mblk_t *mp, int cmd)
6610Sstevel@tonic-gate {
6620Sstevel@tonic-gate 	int			err = 0;
6630Sstevel@tonic-gate 	Mouse_iocstate_t	*Mouseioc;
6646710Syz224750 	caddr_t			useraddr;
6656710Syz224750 	size_t			size;
6660Sstevel@tonic-gate 	mblk_t			*ioctmp;
6670Sstevel@tonic-gate 	mblk_t			*datap;
6680Sstevel@tonic-gate 
6696990Sgd78059 	struct iocblk *iocbp = (void *)mp->b_rptr;
6700Sstevel@tonic-gate 
6710Sstevel@tonic-gate 	if (iocbp->ioc_count == TRANSPARENT) {
6726710Syz224750 		if (mp->b_cont == NULL)
6736710Syz224750 			return (EINVAL);
6746990Sgd78059 		useraddr = *((caddr_t *)(void *)mp->b_cont->b_rptr);
6750Sstevel@tonic-gate 		switch (cmd) {
6760Sstevel@tonic-gate 		case VUIDGWHEELCOUNT:
6776710Syz224750 			size = sizeof (int);
6786710Syz224750 			if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
6796710Syz224750 				return (EAGAIN);
6806990Sgd78059 			*((int *)(void *)datap->b_wptr) =
6816990Sgd78059 			    STATEP->vuid_mouse_mode;
6826710Syz224750 			mcopyout(mp, NULL, size, NULL, datap);
6830Sstevel@tonic-gate 			qreply(qp, mp);
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate 			return (err);
6860Sstevel@tonic-gate 		case VUIDGWHEELINFO:
6876710Syz224750 			size = sizeof (wheel_info);
6880Sstevel@tonic-gate 			break;
6890Sstevel@tonic-gate 
6900Sstevel@tonic-gate 		case VUIDSWHEELSTATE:
6910Sstevel@tonic-gate 		case VUIDGWHEELSTATE:
6926710Syz224750 			size = sizeof (wheel_state);
6930Sstevel@tonic-gate 			break;
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 		case MSIOSRESOLUTION:
6966710Syz224750 			size = sizeof (Ms_screen_resolution);
6970Sstevel@tonic-gate 			break;
6980Sstevel@tonic-gate 		}
6990Sstevel@tonic-gate 
7006990Sgd78059 		if ((ioctmp = allocb(sizeof (Mouse_iocstate_t),
7016710Syz224750 		    BPRI_MED)) == NULL)
7026710Syz224750 			return (EAGAIN);
7036990Sgd78059 		Mouseioc = (void *)ioctmp->b_rptr;
7040Sstevel@tonic-gate 		Mouseioc->ioc_state = GETSTRUCT;
7056710Syz224750 		Mouseioc->u_addr = useraddr;
7060Sstevel@tonic-gate 		ioctmp->b_wptr = ioctmp->b_rptr + sizeof (Mouse_iocstate_t);
7076710Syz224750 		mcopyin(mp, ioctmp, size, NULL);
7080Sstevel@tonic-gate 		qreply(qp, mp);
7090Sstevel@tonic-gate 
7100Sstevel@tonic-gate 		return (err);
7110Sstevel@tonic-gate 	} else {
7120Sstevel@tonic-gate 		switch (cmd) {
7130Sstevel@tonic-gate 		case VUIDGWHEELCOUNT:
7140Sstevel@tonic-gate 			if (mp->b_cont) {
7150Sstevel@tonic-gate 				freemsg(mp->b_cont);
7160Sstevel@tonic-gate 				mp->b_cont = NULL;
7170Sstevel@tonic-gate 			}
7186710Syz224750 			if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) {
7196710Syz224750 				err = EAGAIN;
7206710Syz224750 				break;
7216710Syz224750 			}
7226990Sgd78059 			*((int *)(void *)datap->b_wptr) =
7236990Sgd78059 			    STATEP->vuid_mouse_mode;
7240Sstevel@tonic-gate 			datap->b_wptr +=  sizeof (int);
7250Sstevel@tonic-gate 			mp->b_cont = datap;
7260Sstevel@tonic-gate 			break;
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate 		case VUIDGWHEELINFO:
7290Sstevel@tonic-gate 			if (mp->b_cont == NULL ||
7300Sstevel@tonic-gate 			    iocbp->ioc_count != sizeof (wheel_info)) {
7310Sstevel@tonic-gate 				err = EINVAL;
7320Sstevel@tonic-gate 				break;
7330Sstevel@tonic-gate 			}
7340Sstevel@tonic-gate 			datap = mp->b_cont;
7350Sstevel@tonic-gate 			err = vuidmice_service_wheel_info(datap);
7360Sstevel@tonic-gate 			break;
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate 		case VUIDSWHEELSTATE:
7390Sstevel@tonic-gate 		case VUIDGWHEELSTATE:
7400Sstevel@tonic-gate 			if (mp->b_cont == NULL ||
7410Sstevel@tonic-gate 			    iocbp->ioc_count != sizeof (wheel_state)) {
7420Sstevel@tonic-gate 				err = EINVAL;
7430Sstevel@tonic-gate 				break;
7440Sstevel@tonic-gate 			}
7450Sstevel@tonic-gate 			datap = mp->b_cont;
7460Sstevel@tonic-gate 			err = vuidmice_service_wheel_state(qp, datap, cmd);
7470Sstevel@tonic-gate 			break;
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate 		case MSIOSRESOLUTION:
7500Sstevel@tonic-gate 			/*
7510Sstevel@tonic-gate 			 * Now we just make Xserver and
7520Sstevel@tonic-gate 			 * the virtual mouse happy. Of course,
7530Sstevel@tonic-gate 			 * the screen resolution value may
7540Sstevel@tonic-gate 			 * be used later for absolute PS/2 mouse.
7550Sstevel@tonic-gate 			 */
7560Sstevel@tonic-gate 			err = 0;
7570Sstevel@tonic-gate 			break;
7580Sstevel@tonic-gate 		}
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate 		if (!err) {
7610Sstevel@tonic-gate 			mp->b_datap->db_type = M_IOCACK;
7620Sstevel@tonic-gate 			iocbp->ioc_rval = 0;
7630Sstevel@tonic-gate 			iocbp->ioc_error = 0;
7640Sstevel@tonic-gate 			qreply(qp, mp);
7650Sstevel@tonic-gate 		}
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 		return (err);
7680Sstevel@tonic-gate 	}
7690Sstevel@tonic-gate }
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate static int
vuidmice_service_wheel_info(register mblk_t * datap)7720Sstevel@tonic-gate vuidmice_service_wheel_info(register mblk_t *datap)
7730Sstevel@tonic-gate {
7740Sstevel@tonic-gate 	wheel_info		*wi;
7750Sstevel@tonic-gate 	int			err = 0;
7760Sstevel@tonic-gate 
7776990Sgd78059 	wi = (void *)datap->b_rptr;
7780Sstevel@tonic-gate 	if (wi->vers != VUID_WHEEL_INFO_VERS) {
7790Sstevel@tonic-gate 		err = EINVAL;
7800Sstevel@tonic-gate 		return (err);
7810Sstevel@tonic-gate 	}
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate 	if (wi->id > (VUIDMICE_NUM_WHEELS - 1)) {
7840Sstevel@tonic-gate 		err = EINVAL;
7850Sstevel@tonic-gate 		return (err);
7860Sstevel@tonic-gate 	}
7875202Smeem 	wi->format = (wi->id == VUIDMICE_VERTICAL_WHEEL_ID) ?
7885202Smeem 	    VUID_WHEEL_FORMAT_VERTICAL : VUID_WHEEL_FORMAT_HORIZONTAL;
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate 	return (err);
7910Sstevel@tonic-gate }
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate static int
vuidmice_service_wheel_state(register queue_t * qp,register mblk_t * datap,register uint_t cmd)7950Sstevel@tonic-gate vuidmice_service_wheel_state(register queue_t	*qp,
7960Sstevel@tonic-gate 			    register mblk_t	*datap,
7970Sstevel@tonic-gate 			    register uint_t	cmd)
7980Sstevel@tonic-gate {
7990Sstevel@tonic-gate 	wheel_state	*ws;
8000Sstevel@tonic-gate 	uint_t		err = 0;
8010Sstevel@tonic-gate 
8026990Sgd78059 	ws = (void *)datap->b_rptr;
8030Sstevel@tonic-gate 	if (ws->vers != VUID_WHEEL_STATE_VERS) {
8040Sstevel@tonic-gate 		err = EINVAL;
8050Sstevel@tonic-gate 		return (err);
8060Sstevel@tonic-gate 	}
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate 	if (ws->id > (VUIDMICE_NUM_WHEELS - 1)) {
8090Sstevel@tonic-gate 		err = EINVAL;
8100Sstevel@tonic-gate 		return (err);
8110Sstevel@tonic-gate 	}
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 	switch (cmd) {
8140Sstevel@tonic-gate 	case	VUIDGWHEELSTATE:
8150Sstevel@tonic-gate 		ws->stateflags =
8160Sstevel@tonic-gate 		    (STATEP->wheel_state_bf >> ws->id) & 1;
8170Sstevel@tonic-gate 
8180Sstevel@tonic-gate 		break;
8190Sstevel@tonic-gate 	case	VUIDSWHEELSTATE:
8200Sstevel@tonic-gate 		STATEP->wheel_state_bf = (ws->stateflags << ws->id) |
8210Sstevel@tonic-gate 		    (STATEP->wheel_state_bf & ~(1 << ws->id));
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 		break;
8240Sstevel@tonic-gate 	default:
8250Sstevel@tonic-gate 		err = EINVAL;
8260Sstevel@tonic-gate 
8270Sstevel@tonic-gate 		return (err);
8280Sstevel@tonic-gate 	}
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate 	return (err);
8310Sstevel@tonic-gate }
832