17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5a9463f18Smeem * Common Development and Distribution License (the "License").
6a9463f18Smeem * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*57f4a14aSGarrett D'Amore * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * VUIDMICE module: put mouse events into vuid format
297c478bd9Sstevel@tonic-gate */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/stream.h>
337c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
347c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
357c478bd9Sstevel@tonic-gate #include <sys/errno.h>
367c478bd9Sstevel@tonic-gate #include <sys/debug.h>
377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <sys/sad.h>
397c478bd9Sstevel@tonic-gate #include <sys/vuid_event.h>
40*57f4a14aSGarrett D'Amore #include "vuidmice.h"
417c478bd9Sstevel@tonic-gate #include <sys/vuid_wheel.h>
427c478bd9Sstevel@tonic-gate #include <sys/msio.h>
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include <sys/conf.h>
457c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
487c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
497c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static int vuidmice_open(queue_t *const, const dev_t *const,
527c478bd9Sstevel@tonic-gate const int, const int, const cred_t *const);
537c478bd9Sstevel@tonic-gate static int vuidmice_close(queue_t *const, const int, const cred_t *const);
547c478bd9Sstevel@tonic-gate static int vuidmice_rput(queue_t *const, mblk_t *);
557c478bd9Sstevel@tonic-gate static int vuidmice_rsrv(queue_t *const);
567c478bd9Sstevel@tonic-gate static int vuidmice_wput(queue_t *const, mblk_t *);
577c478bd9Sstevel@tonic-gate static void vuidmice_miocdata(queue_t *const, mblk_t *);
587c478bd9Sstevel@tonic-gate static int vuidmice_handle_wheel_resolution_ioctl(queue_t *const,
597c478bd9Sstevel@tonic-gate mblk_t *, int);
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate static int vuidmice_service_wheel_info(mblk_t *);
627c478bd9Sstevel@tonic-gate static int vuidmice_service_wheel_state(queue_t *, mblk_t *, uint_t);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate void VUID_QUEUE(queue_t *const, mblk_t *);
657c478bd9Sstevel@tonic-gate int VUID_OPEN(queue_t *const);
667c478bd9Sstevel@tonic-gate void VUID_CLOSE(queue_t *const);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate static kmutex_t vuidmice_lock;
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate static struct module_info vuidmice_iinfo = {
717c478bd9Sstevel@tonic-gate 0,
727c478bd9Sstevel@tonic-gate VUID_NAME,
737c478bd9Sstevel@tonic-gate 0,
747c478bd9Sstevel@tonic-gate INFPSZ,
757c478bd9Sstevel@tonic-gate 1000,
767c478bd9Sstevel@tonic-gate 100
777c478bd9Sstevel@tonic-gate };
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate static struct qinit vuidmice_rinit = {
807c478bd9Sstevel@tonic-gate vuidmice_rput,
817c478bd9Sstevel@tonic-gate vuidmice_rsrv,
827c478bd9Sstevel@tonic-gate vuidmice_open,
837c478bd9Sstevel@tonic-gate vuidmice_close,
847c478bd9Sstevel@tonic-gate NULL,
857c478bd9Sstevel@tonic-gate &vuidmice_iinfo,
867c478bd9Sstevel@tonic-gate NULL
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate static struct module_info vuidmice_oinfo = {
907c478bd9Sstevel@tonic-gate 0,
917c478bd9Sstevel@tonic-gate VUID_NAME,
927c478bd9Sstevel@tonic-gate 0,
937c478bd9Sstevel@tonic-gate INFPSZ,
947c478bd9Sstevel@tonic-gate 1000,
957c478bd9Sstevel@tonic-gate 100
967c478bd9Sstevel@tonic-gate };
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate static struct qinit vuidmice_winit = {
997c478bd9Sstevel@tonic-gate vuidmice_wput,
1007c478bd9Sstevel@tonic-gate NULL,
1017c478bd9Sstevel@tonic-gate NULL,
1027c478bd9Sstevel@tonic-gate NULL,
1037c478bd9Sstevel@tonic-gate NULL,
1047c478bd9Sstevel@tonic-gate &vuidmice_oinfo,
1057c478bd9Sstevel@tonic-gate NULL
1067c478bd9Sstevel@tonic-gate };
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate struct streamtab vuidmice_info = {
1097c478bd9Sstevel@tonic-gate &vuidmice_rinit,
1107c478bd9Sstevel@tonic-gate &vuidmice_winit,
1117c478bd9Sstevel@tonic-gate NULL,
1127c478bd9Sstevel@tonic-gate NULL
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate * This is the loadable module wrapper.
1177c478bd9Sstevel@tonic-gate */
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate * D_MTQPAIR effectively makes the module single threaded.
1217c478bd9Sstevel@tonic-gate * There can be only one thread active in the module at any time.
1227c478bd9Sstevel@tonic-gate * It may be a read or write thread.
1237c478bd9Sstevel@tonic-gate */
1247c478bd9Sstevel@tonic-gate #define VUIDMICE_CONF_FLAG (D_MP | D_MTQPAIR)
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
1277c478bd9Sstevel@tonic-gate VUID_NAME,
1287c478bd9Sstevel@tonic-gate &vuidmice_info,
1297c478bd9Sstevel@tonic-gate VUIDMICE_CONF_FLAG
1307c478bd9Sstevel@tonic-gate };
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1337c478bd9Sstevel@tonic-gate &mod_strmodops,
1347c478bd9Sstevel@tonic-gate "mouse events to vuid events",
1357c478bd9Sstevel@tonic-gate &fsw
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate * Module linkage information for the kernel.
1407c478bd9Sstevel@tonic-gate */
1417c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1427c478bd9Sstevel@tonic-gate MODREV_1,
1437c478bd9Sstevel@tonic-gate &modlstrmod,
1447c478bd9Sstevel@tonic-gate NULL
1457c478bd9Sstevel@tonic-gate };
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate static int module_open = 0; /* allow only one open of this module */
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate int
_init(void)1507c478bd9Sstevel@tonic-gate _init(void)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate register int rc;
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate mutex_init(&vuidmice_lock, NULL, MUTEX_DEFAULT, NULL);
1557c478bd9Sstevel@tonic-gate if ((rc = mod_install(&modlinkage)) != 0) {
1567c478bd9Sstevel@tonic-gate mutex_destroy(&vuidmice_lock);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate return (rc);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate int
_fini(void)1627c478bd9Sstevel@tonic-gate _fini(void)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate register int rc;
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate if ((rc = mod_remove(&modlinkage)) == 0)
1677c478bd9Sstevel@tonic-gate mutex_destroy(&vuidmice_lock);
1687c478bd9Sstevel@tonic-gate return (rc);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1727c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
1797c478bd9Sstevel@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)1807c478bd9Sstevel@tonic-gate vuidmice_open(queue_t *const qp, const dev_t *const devp,
1817c478bd9Sstevel@tonic-gate const int oflag, const int sflag, const cred_t *const crp)
1827c478bd9Sstevel@tonic-gate {
183a9463f18Smeem if (qp->q_ptr != NULL)
184a9463f18Smeem return (0); /* reopen */
185a9463f18Smeem
1867c478bd9Sstevel@tonic-gate mutex_enter(&vuidmice_lock);
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate /* Allow only 1 open of this module */
1897c478bd9Sstevel@tonic-gate if (module_open) {
1907c478bd9Sstevel@tonic-gate mutex_exit(&vuidmice_lock);
1917c478bd9Sstevel@tonic-gate return (EBUSY);
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate module_open++;
1957c478bd9Sstevel@tonic-gate mutex_exit(&vuidmice_lock);
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate * Both the read and write queues share the same state structures.
1997c478bd9Sstevel@tonic-gate */
2007c478bd9Sstevel@tonic-gate qp->q_ptr = kmem_zalloc(sizeof (struct MouseStateInfo), KM_SLEEP);
2017c478bd9Sstevel@tonic-gate WR(qp)->q_ptr = qp->q_ptr;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate /* initialize state */
2047c478bd9Sstevel@tonic-gate STATEP->format = VUID_NATIVE;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate qprocson(qp);
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate #ifdef VUID_OPEN
2097c478bd9Sstevel@tonic-gate if (VUID_OPEN(qp) != 0) {
2107c478bd9Sstevel@tonic-gate qprocsoff(qp);
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate mutex_enter(&vuidmice_lock);
2137c478bd9Sstevel@tonic-gate module_open--;
214a9463f18Smeem mutex_exit(&vuidmice_lock);
2157c478bd9Sstevel@tonic-gate kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
2167c478bd9Sstevel@tonic-gate qp->q_ptr = NULL;
2177c478bd9Sstevel@tonic-gate return (ENXIO);
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate #endif
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate return (0);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
2257c478bd9Sstevel@tonic-gate static int
vuidmice_close(queue_t * const qp,const int flag,const cred_t * const crp)2267c478bd9Sstevel@tonic-gate vuidmice_close(queue_t *const qp, const int flag, const cred_t *const crp)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate qprocsoff(qp);
2317c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL);
2327c478bd9Sstevel@tonic-gate flushq(OTHERQ(qp), FLUSHALL);
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate #ifdef VUID_CLOSE
2357c478bd9Sstevel@tonic-gate VUID_CLOSE(qp);
2367c478bd9Sstevel@tonic-gate #endif
237a9463f18Smeem mutex_enter(&vuidmice_lock);
2387c478bd9Sstevel@tonic-gate module_open--;
2397c478bd9Sstevel@tonic-gate mutex_exit(&vuidmice_lock);
240a9463f18Smeem kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
241a9463f18Smeem qp->q_ptr = NULL;
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate return (0);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate * Put procedure for input from driver end of stream (read queue).
2487c478bd9Sstevel@tonic-gate */
2497c478bd9Sstevel@tonic-gate static int
vuidmice_rput(queue_t * const qp,mblk_t * mp)2507c478bd9Sstevel@tonic-gate vuidmice_rput(queue_t *const qp, mblk_t *mp)
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
2537c478bd9Sstevel@tonic-gate ASSERT(mp != NULL);
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate /*
2567c478bd9Sstevel@tonic-gate * Handle all the related high priority messages here, hence
2577c478bd9Sstevel@tonic-gate * should spend the least amount of time here.
2587c478bd9Sstevel@tonic-gate */
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate if (DB_TYPE(mp) == M_DATA) {
2617c478bd9Sstevel@tonic-gate if ((int)STATEP->format == VUID_FIRM_EVENT)
2627c478bd9Sstevel@tonic-gate return (putq(qp, mp)); /* queue message & return */
2637c478bd9Sstevel@tonic-gate } else if (DB_TYPE(mp) == M_FLUSH) {
2647c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR)
2657c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate putnext(qp, mp); /* pass it on */
2697c478bd9Sstevel@tonic-gate return (0);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate static int
vuidmice_rsrv(queue_t * const qp)2737c478bd9Sstevel@tonic-gate vuidmice_rsrv(queue_t *const qp)
2747c478bd9Sstevel@tonic-gate {
2757c478bd9Sstevel@tonic-gate register mblk_t *mp;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate while ((mp = getq(qp)) != NULL) {
2807c478bd9Sstevel@tonic-gate ASSERT(DB_TYPE(mp) == M_DATA);
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate if (!canputnext(qp))
2837c478bd9Sstevel@tonic-gate return (putbq(qp, mp)); /* read side is blocked */
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) {
286a9463f18Smeem case M_DATA:
2877c478bd9Sstevel@tonic-gate if ((int)STATEP->format == VUID_FIRM_EVENT)
2887c478bd9Sstevel@tonic-gate (void) VUID_QUEUE(qp, mp);
2897c478bd9Sstevel@tonic-gate else
2907c478bd9Sstevel@tonic-gate (void) putnext(qp, mp);
2917c478bd9Sstevel@tonic-gate break;
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate default:
2947c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
2957c478bd9Sstevel@tonic-gate "vuidmice_rsrv: bad message type (0x%x)\n",
2967c478bd9Sstevel@tonic-gate DB_TYPE(mp));
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate (void) putnext(qp, mp);
2997c478bd9Sstevel@tonic-gate break;
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate return (0);
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate * Put procedure for write from user end of stream (write queue).
3077c478bd9Sstevel@tonic-gate */
3087c478bd9Sstevel@tonic-gate static int
vuidmice_wput(queue_t * const qp,mblk_t * mp)3097c478bd9Sstevel@tonic-gate vuidmice_wput(queue_t *const qp, mblk_t *mp)
3107c478bd9Sstevel@tonic-gate {
3117c478bd9Sstevel@tonic-gate int error = 0;
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
3147c478bd9Sstevel@tonic-gate ASSERT(mp != NULL);
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate /*
3177c478bd9Sstevel@tonic-gate * Handle all the related high priority messages here, hence
3187c478bd9Sstevel@tonic-gate * should spend the least amount of time here.
3197c478bd9Sstevel@tonic-gate */
3207c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) { /* handle hi pri messages here */
3217c478bd9Sstevel@tonic-gate case M_FLUSH:
3227c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW)
3237c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL);
3247c478bd9Sstevel@tonic-gate putnext(qp, mp); /* pass it on */
3257c478bd9Sstevel@tonic-gate return (0);
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate case M_IOCTL: {
32822eb7cb5Sgd78059 struct iocblk *iocbp = (void *)mp->b_rptr;
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
3317c478bd9Sstevel@tonic-gate case VUIDSFORMAT:
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate * VUIDSFORMAT is known to the stream head and thus
3357c478bd9Sstevel@tonic-gate * is guaranteed to be an I_STR ioctl.
3367c478bd9Sstevel@tonic-gate */
3377c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
3387c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
3397c478bd9Sstevel@tonic-gate return (0);
3407c478bd9Sstevel@tonic-gate } else {
3417c478bd9Sstevel@tonic-gate int format_type;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (int));
3447c478bd9Sstevel@tonic-gate if (error != 0) {
3457c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, error);
3467c478bd9Sstevel@tonic-gate return (0);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
34922eb7cb5Sgd78059 format_type =
35022eb7cb5Sgd78059 *(int *)(void *)mp->b_cont->b_rptr;
3517c478bd9Sstevel@tonic-gate STATEP->format = (uchar_t)format_type;
3527c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
3537c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
3547c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
3557c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate /* return buffer to pool ASAP */
3597c478bd9Sstevel@tonic-gate if (mp->b_cont) {
3607c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
3617c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate qreply(qp, mp);
3657c478bd9Sstevel@tonic-gate return (0);
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate case VUIDGFORMAT:
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /* return buffer to pool ASAP */
3707c478bd9Sstevel@tonic-gate if (mp->b_cont) {
3717c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); /* over written below */
3727c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate * VUIDGFORMAT is known to the stream head and thus
3777c478bd9Sstevel@tonic-gate * is guaranteed to be an I_STR ioctl.
3787c478bd9Sstevel@tonic-gate */
3797c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
3807c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
3817c478bd9Sstevel@tonic-gate return (0);
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (int), BPRI_MED);
3857c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
3867c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EAGAIN);
3877c478bd9Sstevel@tonic-gate return (0);
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate
39022eb7cb5Sgd78059 *(int *)(void *)mp->b_cont->b_rptr =
39122eb7cb5Sgd78059 (int)STATEP->format;
3927c478bd9Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (int);
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate iocbp->ioc_count = sizeof (int);
3957c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
3967c478bd9Sstevel@tonic-gate qreply(qp, mp);
3977c478bd9Sstevel@tonic-gate return (0);
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate case VUID_NATIVE:
4007c478bd9Sstevel@tonic-gate case VUIDSADDR:
4017c478bd9Sstevel@tonic-gate case VUIDGADDR:
4027c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, ENOTTY);
4037c478bd9Sstevel@tonic-gate return (0);
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate case MSIOBUTTONS:
4067c478bd9Sstevel@tonic-gate /* return buffer to pool ASAP */
4077c478bd9Sstevel@tonic-gate if (mp->b_cont) {
4087c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); /* over written below */
4097c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate /*
4137c478bd9Sstevel@tonic-gate * MSIOBUTTONS is known to streamio.c and this
4147c478bd9Sstevel@tonic-gate * is assume to be non-I_STR & non-TRANSPARENT ioctl
4157c478bd9Sstevel@tonic-gate */
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
4187c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
4197c478bd9Sstevel@tonic-gate return (0);
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate if (STATEP->nbuttons == 0) {
4237c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
4247c478bd9Sstevel@tonic-gate return (0);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (int), BPRI_MED);
4287c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
4297c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EAGAIN);
4307c478bd9Sstevel@tonic-gate return (0);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate
43322eb7cb5Sgd78059 *(int *)(void *)mp->b_cont->b_rptr =
43422eb7cb5Sgd78059 (int)STATEP->nbuttons;
4357c478bd9Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (int);
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate iocbp->ioc_count = sizeof (int);
4387c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
4397c478bd9Sstevel@tonic-gate qreply(qp, mp);
4407c478bd9Sstevel@tonic-gate return (0);
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate /*
4437c478bd9Sstevel@tonic-gate * New IOCTL support. Since it's explicitly mentioned
4447c478bd9Sstevel@tonic-gate * that you can't add more ioctls to stream head's
4457c478bd9Sstevel@tonic-gate * hard coded list, we have to do the transparent
4467c478bd9Sstevel@tonic-gate * ioctl processing which is not very exciting.
4477c478bd9Sstevel@tonic-gate */
4487c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
4497c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
4507c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
4517c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
4527c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
4537c478bd9Sstevel@tonic-gate error = vuidmice_handle_wheel_resolution_ioctl(qp,
4547c478bd9Sstevel@tonic-gate mp, iocbp->ioc_cmd);
4557c478bd9Sstevel@tonic-gate if (!error) {
4567c478bd9Sstevel@tonic-gate return (0);
4577c478bd9Sstevel@tonic-gate } else {
4587c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, error);
4597c478bd9Sstevel@tonic-gate return (0);
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate default:
4627c478bd9Sstevel@tonic-gate putnext(qp, mp); /* nothing to process here */
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate return (0);
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate } /* End of case M_IOCTL */
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate case M_IOCDATA:
4707c478bd9Sstevel@tonic-gate vuidmice_miocdata(qp, mp);
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate return (0);
4737c478bd9Sstevel@tonic-gate default:
4747c478bd9Sstevel@tonic-gate putnext(qp, mp); /* pass it on */
4757c478bd9Sstevel@tonic-gate return (0);
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate /*NOTREACHED*/
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate
4807c478bd9Sstevel@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)4817c478bd9Sstevel@tonic-gate VUID_PUTNEXT(queue_t *const qp, uchar_t event_id, uchar_t event_pair_type,
4827c478bd9Sstevel@tonic-gate uchar_t event_pair, int event_value)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate int strikes = 1;
4857c478bd9Sstevel@tonic-gate mblk_t *bp;
4867c478bd9Sstevel@tonic-gate Firm_event *fep;
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate /*
4897c478bd9Sstevel@tonic-gate * Give this event 3 chances to allocate blocks,
4907c478bd9Sstevel@tonic-gate * otherwise discard this mouse event. 3 Strikes and you're out.
4917c478bd9Sstevel@tonic-gate */
4927c478bd9Sstevel@tonic-gate while ((bp = allocb((int)sizeof (Firm_event), BPRI_HI)) == NULL) {
4937c478bd9Sstevel@tonic-gate if (++strikes > 3)
4947c478bd9Sstevel@tonic-gate return;
4957c478bd9Sstevel@tonic-gate drv_usecwait(10);
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate
49822eb7cb5Sgd78059 fep = (void *)bp->b_wptr;
4997c478bd9Sstevel@tonic-gate fep->id = vuid_id_addr(VKEY_FIRST) | vuid_id_offset(event_id);
5007c478bd9Sstevel@tonic-gate
5017c478bd9Sstevel@tonic-gate fep->pair_type = event_pair_type;
5027c478bd9Sstevel@tonic-gate fep->pair = event_pair;
5037c478bd9Sstevel@tonic-gate fep->value = event_value;
5047c478bd9Sstevel@tonic-gate uniqtime32(&fep->time);
5057c478bd9Sstevel@tonic-gate bp->b_wptr += sizeof (Firm_event);
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate if (canput(qp->q_next))
5087c478bd9Sstevel@tonic-gate putnext(qp, bp);
5097c478bd9Sstevel@tonic-gate else
5107c478bd9Sstevel@tonic-gate (void) putbq(qp, bp); /* read side is blocked */
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate * vuidmice_miocdata
5167c478bd9Sstevel@tonic-gate * M_IOCDATA processing for IOCTL's: VUIDGWHEELCOUNT, VUIDGWHEELINFO,
5177c478bd9Sstevel@tonic-gate * VUIDGWHEELSTATE, VUIDSWHEELSTATE & MSIOSRESOLUTION.
5187c478bd9Sstevel@tonic-gate */
5197c478bd9Sstevel@tonic-gate static void
vuidmice_miocdata(queue_t * qp,mblk_t * mp)5207c478bd9Sstevel@tonic-gate vuidmice_miocdata(queue_t *qp, mblk_t *mp)
5217c478bd9Sstevel@tonic-gate {
5227c478bd9Sstevel@tonic-gate struct copyresp *copyresp;
5237c478bd9Sstevel@tonic-gate struct iocblk *iocbp;
5247c478bd9Sstevel@tonic-gate mblk_t *ioctmp;
5257c478bd9Sstevel@tonic-gate mblk_t *datap;
5267c478bd9Sstevel@tonic-gate Mouse_iocstate_t *Mouseioc;
527664d603cSyz224750 size_t size;
5287c478bd9Sstevel@tonic-gate int err = 0;
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate
53122eb7cb5Sgd78059 copyresp = (void *)mp->b_rptr;
53222eb7cb5Sgd78059 iocbp = (void *)mp->b_rptr;
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate if (copyresp->cp_rval) {
5357c478bd9Sstevel@tonic-gate err = EAGAIN;
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate goto err;
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate switch (copyresp->cp_cmd) {
5407c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
5417c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
5427c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
5437c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
5447c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
5457c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
5467c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) {
5477c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5487c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
5497c478bd9Sstevel@tonic-gate }
5507c478bd9Sstevel@tonic-gate
5517c478bd9Sstevel@tonic-gate break;
5527c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
5537c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
55422eb7cb5Sgd78059 ioctmp = copyresp->cp_private;
55522eb7cb5Sgd78059 Mouseioc = (void *)ioctmp->b_rptr;
5567c478bd9Sstevel@tonic-gate if (Mouseioc->ioc_state == GETSTRUCT) {
5577c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
5587c478bd9Sstevel@tonic-gate err = EINVAL;
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate break;
5617c478bd9Sstevel@tonic-gate }
5627c478bd9Sstevel@tonic-gate datap = mp->b_cont;
5637c478bd9Sstevel@tonic-gate if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
5647c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_state(qp, datap,
5657c478bd9Sstevel@tonic-gate VUIDGWHEELSTATE);
5667c478bd9Sstevel@tonic-gate } else {
5677c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_info(datap);
5687c478bd9Sstevel@tonic-gate }
5697c478bd9Sstevel@tonic-gate if (err) {
5707c478bd9Sstevel@tonic-gate break;
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate
5737c478bd9Sstevel@tonic-gate if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
574664d603cSyz224750 size = sizeof (wheel_state);
5757c478bd9Sstevel@tonic-gate } else {
576664d603cSyz224750 size = sizeof (wheel_info);
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate Mouseioc->ioc_state = GETRESULT;
580664d603cSyz224750 ASSERT(Mouseioc->u_addr != NULL);
581664d603cSyz224750 mcopyout(mp, ioctmp, size, Mouseioc->u_addr, NULL);
5827c478bd9Sstevel@tonic-gate } else if (Mouseioc->ioc_state == GETRESULT) {
5837c478bd9Sstevel@tonic-gate freemsg(ioctmp);
5847c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
5857c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
5867c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
5877c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
5887c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
5897c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) {
5907c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5917c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
5927c478bd9Sstevel@tonic-gate }
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate break;
5967c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
5977c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
59822eb7cb5Sgd78059 ioctmp = copyresp->cp_private;
59922eb7cb5Sgd78059 Mouseioc = (void *)ioctmp->b_rptr;
6007c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
6017c478bd9Sstevel@tonic-gate err = EINVAL;
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate break;
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate datap = mp->b_cont;
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate if (copyresp->cp_cmd == VUIDSWHEELSTATE) {
6087c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_state(qp,
6097c478bd9Sstevel@tonic-gate datap, VUIDSWHEELSTATE);
6107c478bd9Sstevel@tonic-gate }
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate if (err) {
6137c478bd9Sstevel@tonic-gate break;
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate if (mp->b_cont) {
6177c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
61822eb7cb5Sgd78059 mp->b_cont = NULL;
6197c478bd9Sstevel@tonic-gate }
6207c478bd9Sstevel@tonic-gate freemsg(ioctmp);
6217c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
6227c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
6237c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
6247c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate break;
6277c478bd9Sstevel@tonic-gate default:
6287c478bd9Sstevel@tonic-gate err = EINVAL;
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate break;
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate err:
6347c478bd9Sstevel@tonic-gate if (err) {
6357c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
6367c478bd9Sstevel@tonic-gate if (mp->b_cont) {
6377c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
63822eb7cb5Sgd78059 mp->b_cont = NULL;
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate if (copyresp->cp_private) {
64122eb7cb5Sgd78059 freemsg(copyresp->cp_private);
64222eb7cb5Sgd78059 copyresp->cp_private = NULL;
6437c478bd9Sstevel@tonic-gate }
6447c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
6457c478bd9Sstevel@tonic-gate iocbp->ioc_error = err;
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate qreply(qp, mp);
6487c478bd9Sstevel@tonic-gate }
6497c478bd9Sstevel@tonic-gate
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate /*
6527c478bd9Sstevel@tonic-gate * vuidmice_handle_wheel_resolution_ioctl
6537c478bd9Sstevel@tonic-gate * Handle wheel mouse and MSIOSRESOLUTION ioctls.
6547c478bd9Sstevel@tonic-gate *
6557c478bd9Sstevel@tonic-gate * Here we also support non-transparent way of these ioctls
6567c478bd9Sstevel@tonic-gate * just like usb mouse driver does, so the consms module is
6577c478bd9Sstevel@tonic-gate * very simple to deal with these ioctls.
6587c478bd9Sstevel@tonic-gate */
6597c478bd9Sstevel@tonic-gate static int
vuidmice_handle_wheel_resolution_ioctl(queue_t * qp,mblk_t * mp,int cmd)6607c478bd9Sstevel@tonic-gate vuidmice_handle_wheel_resolution_ioctl(queue_t *qp, mblk_t *mp, int cmd)
6617c478bd9Sstevel@tonic-gate {
6627c478bd9Sstevel@tonic-gate int err = 0;
6637c478bd9Sstevel@tonic-gate Mouse_iocstate_t *Mouseioc;
664664d603cSyz224750 caddr_t useraddr;
665664d603cSyz224750 size_t size;
6667c478bd9Sstevel@tonic-gate mblk_t *ioctmp;
6677c478bd9Sstevel@tonic-gate mblk_t *datap;
6687c478bd9Sstevel@tonic-gate
66922eb7cb5Sgd78059 struct iocblk *iocbp = (void *)mp->b_rptr;
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
672664d603cSyz224750 if (mp->b_cont == NULL)
673664d603cSyz224750 return (EINVAL);
67422eb7cb5Sgd78059 useraddr = *((caddr_t *)(void *)mp->b_cont->b_rptr);
6757c478bd9Sstevel@tonic-gate switch (cmd) {
6767c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
677664d603cSyz224750 size = sizeof (int);
678664d603cSyz224750 if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
679664d603cSyz224750 return (EAGAIN);
68022eb7cb5Sgd78059 *((int *)(void *)datap->b_wptr) =
68122eb7cb5Sgd78059 STATEP->vuid_mouse_mode;
682664d603cSyz224750 mcopyout(mp, NULL, size, NULL, datap);
6837c478bd9Sstevel@tonic-gate qreply(qp, mp);
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate return (err);
6867c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
687664d603cSyz224750 size = sizeof (wheel_info);
6887c478bd9Sstevel@tonic-gate break;
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
6917c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
692664d603cSyz224750 size = sizeof (wheel_state);
6937c478bd9Sstevel@tonic-gate break;
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
696664d603cSyz224750 size = sizeof (Ms_screen_resolution);
6977c478bd9Sstevel@tonic-gate break;
6987c478bd9Sstevel@tonic-gate }
6997c478bd9Sstevel@tonic-gate
70022eb7cb5Sgd78059 if ((ioctmp = allocb(sizeof (Mouse_iocstate_t),
701664d603cSyz224750 BPRI_MED)) == NULL)
702664d603cSyz224750 return (EAGAIN);
70322eb7cb5Sgd78059 Mouseioc = (void *)ioctmp->b_rptr;
7047c478bd9Sstevel@tonic-gate Mouseioc->ioc_state = GETSTRUCT;
705664d603cSyz224750 Mouseioc->u_addr = useraddr;
7067c478bd9Sstevel@tonic-gate ioctmp->b_wptr = ioctmp->b_rptr + sizeof (Mouse_iocstate_t);
707664d603cSyz224750 mcopyin(mp, ioctmp, size, NULL);
7087c478bd9Sstevel@tonic-gate qreply(qp, mp);
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate return (err);
7117c478bd9Sstevel@tonic-gate } else {
7127c478bd9Sstevel@tonic-gate switch (cmd) {
7137c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
7147c478bd9Sstevel@tonic-gate if (mp->b_cont) {
7157c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
7167c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
7177c478bd9Sstevel@tonic-gate }
718664d603cSyz224750 if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) {
719664d603cSyz224750 err = EAGAIN;
720664d603cSyz224750 break;
721664d603cSyz224750 }
72222eb7cb5Sgd78059 *((int *)(void *)datap->b_wptr) =
72322eb7cb5Sgd78059 STATEP->vuid_mouse_mode;
7247c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
7257c478bd9Sstevel@tonic-gate mp->b_cont = datap;
7267c478bd9Sstevel@tonic-gate break;
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
7297c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL ||
7307c478bd9Sstevel@tonic-gate iocbp->ioc_count != sizeof (wheel_info)) {
7317c478bd9Sstevel@tonic-gate err = EINVAL;
7327c478bd9Sstevel@tonic-gate break;
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate datap = mp->b_cont;
7357c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_info(datap);
7367c478bd9Sstevel@tonic-gate break;
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
7397c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
7407c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL ||
7417c478bd9Sstevel@tonic-gate iocbp->ioc_count != sizeof (wheel_state)) {
7427c478bd9Sstevel@tonic-gate err = EINVAL;
7437c478bd9Sstevel@tonic-gate break;
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate datap = mp->b_cont;
7467c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_state(qp, datap, cmd);
7477c478bd9Sstevel@tonic-gate break;
7487c478bd9Sstevel@tonic-gate
7497c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
7507c478bd9Sstevel@tonic-gate /*
7517c478bd9Sstevel@tonic-gate * Now we just make Xserver and
7527c478bd9Sstevel@tonic-gate * the virtual mouse happy. Of course,
7537c478bd9Sstevel@tonic-gate * the screen resolution value may
7547c478bd9Sstevel@tonic-gate * be used later for absolute PS/2 mouse.
7557c478bd9Sstevel@tonic-gate */
7567c478bd9Sstevel@tonic-gate err = 0;
7577c478bd9Sstevel@tonic-gate break;
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gate if (!err) {
7617c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7627c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
7637c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
7647c478bd9Sstevel@tonic-gate qreply(qp, mp);
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate return (err);
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate static int
vuidmice_service_wheel_info(register mblk_t * datap)7727c478bd9Sstevel@tonic-gate vuidmice_service_wheel_info(register mblk_t *datap)
7737c478bd9Sstevel@tonic-gate {
7747c478bd9Sstevel@tonic-gate wheel_info *wi;
7757c478bd9Sstevel@tonic-gate int err = 0;
7767c478bd9Sstevel@tonic-gate
77722eb7cb5Sgd78059 wi = (void *)datap->b_rptr;
7787c478bd9Sstevel@tonic-gate if (wi->vers != VUID_WHEEL_INFO_VERS) {
7797c478bd9Sstevel@tonic-gate err = EINVAL;
7807c478bd9Sstevel@tonic-gate return (err);
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate if (wi->id > (VUIDMICE_NUM_WHEELS - 1)) {
7847c478bd9Sstevel@tonic-gate err = EINVAL;
7857c478bd9Sstevel@tonic-gate return (err);
7867c478bd9Sstevel@tonic-gate }
787a9463f18Smeem wi->format = (wi->id == VUIDMICE_VERTICAL_WHEEL_ID) ?
788a9463f18Smeem VUID_WHEEL_FORMAT_VERTICAL : VUID_WHEEL_FORMAT_HORIZONTAL;
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate return (err);
7917c478bd9Sstevel@tonic-gate }
7927c478bd9Sstevel@tonic-gate
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate static int
vuidmice_service_wheel_state(register queue_t * qp,register mblk_t * datap,register uint_t cmd)7957c478bd9Sstevel@tonic-gate vuidmice_service_wheel_state(register queue_t *qp,
7967c478bd9Sstevel@tonic-gate register mblk_t *datap,
7977c478bd9Sstevel@tonic-gate register uint_t cmd)
7987c478bd9Sstevel@tonic-gate {
7997c478bd9Sstevel@tonic-gate wheel_state *ws;
8007c478bd9Sstevel@tonic-gate uint_t err = 0;
8017c478bd9Sstevel@tonic-gate
80222eb7cb5Sgd78059 ws = (void *)datap->b_rptr;
8037c478bd9Sstevel@tonic-gate if (ws->vers != VUID_WHEEL_STATE_VERS) {
8047c478bd9Sstevel@tonic-gate err = EINVAL;
8057c478bd9Sstevel@tonic-gate return (err);
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate if (ws->id > (VUIDMICE_NUM_WHEELS - 1)) {
8097c478bd9Sstevel@tonic-gate err = EINVAL;
8107c478bd9Sstevel@tonic-gate return (err);
8117c478bd9Sstevel@tonic-gate }
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate switch (cmd) {
8147c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
8157c478bd9Sstevel@tonic-gate ws->stateflags =
8167c478bd9Sstevel@tonic-gate (STATEP->wheel_state_bf >> ws->id) & 1;
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate break;
8197c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
8207c478bd9Sstevel@tonic-gate STATEP->wheel_state_bf = (ws->stateflags << ws->id) |
8217c478bd9Sstevel@tonic-gate (STATEP->wheel_state_bf & ~(1 << ws->id));
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate break;
8247c478bd9Sstevel@tonic-gate default:
8257c478bd9Sstevel@tonic-gate err = EINVAL;
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate return (err);
8287c478bd9Sstevel@tonic-gate }
8297c478bd9Sstevel@tonic-gate
8307c478bd9Sstevel@tonic-gate return (err);
8317c478bd9Sstevel@tonic-gate }
832