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 /*
2257f4a14aSGarrett 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>
4057f4a14aSGarrett 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
51*5e1743f0SToomas Soome static int vuidmice_open(queue_t *, dev_t *, int, int, cred_t *);
52*5e1743f0SToomas Soome static int vuidmice_close(queue_t *, int, cred_t *);
53*5e1743f0SToomas Soome static int vuidmice_rput(queue_t *, mblk_t *);
54*5e1743f0SToomas Soome static int vuidmice_rsrv(queue_t *);
55*5e1743f0SToomas Soome static int vuidmice_wput(queue_t *, mblk_t *);
56*5e1743f0SToomas Soome static void vuidmice_miocdata(queue_t *, mblk_t *);
57*5e1743f0SToomas Soome static int vuidmice_handle_wheel_resolution_ioctl(queue_t *, mblk_t *, int);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate static int vuidmice_service_wheel_info(mblk_t *);
607c478bd9Sstevel@tonic-gate static int vuidmice_service_wheel_state(queue_t *, mblk_t *, uint_t);
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate void VUID_QUEUE(queue_t *const, mblk_t *);
637c478bd9Sstevel@tonic-gate int VUID_OPEN(queue_t *const);
647c478bd9Sstevel@tonic-gate void VUID_CLOSE(queue_t *const);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate static kmutex_t vuidmice_lock;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate static struct module_info vuidmice_iinfo = {
697c478bd9Sstevel@tonic-gate 0,
707c478bd9Sstevel@tonic-gate VUID_NAME,
717c478bd9Sstevel@tonic-gate 0,
727c478bd9Sstevel@tonic-gate INFPSZ,
737c478bd9Sstevel@tonic-gate 1000,
747c478bd9Sstevel@tonic-gate 100
757c478bd9Sstevel@tonic-gate };
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate static struct qinit vuidmice_rinit = {
787c478bd9Sstevel@tonic-gate vuidmice_rput,
797c478bd9Sstevel@tonic-gate vuidmice_rsrv,
807c478bd9Sstevel@tonic-gate vuidmice_open,
817c478bd9Sstevel@tonic-gate vuidmice_close,
827c478bd9Sstevel@tonic-gate NULL,
837c478bd9Sstevel@tonic-gate &vuidmice_iinfo,
847c478bd9Sstevel@tonic-gate NULL
857c478bd9Sstevel@tonic-gate };
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate static struct module_info vuidmice_oinfo = {
887c478bd9Sstevel@tonic-gate 0,
897c478bd9Sstevel@tonic-gate VUID_NAME,
907c478bd9Sstevel@tonic-gate 0,
917c478bd9Sstevel@tonic-gate INFPSZ,
927c478bd9Sstevel@tonic-gate 1000,
937c478bd9Sstevel@tonic-gate 100
947c478bd9Sstevel@tonic-gate };
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate static struct qinit vuidmice_winit = {
977c478bd9Sstevel@tonic-gate vuidmice_wput,
987c478bd9Sstevel@tonic-gate NULL,
997c478bd9Sstevel@tonic-gate NULL,
1007c478bd9Sstevel@tonic-gate NULL,
1017c478bd9Sstevel@tonic-gate NULL,
1027c478bd9Sstevel@tonic-gate &vuidmice_oinfo,
1037c478bd9Sstevel@tonic-gate NULL
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate struct streamtab vuidmice_info = {
1077c478bd9Sstevel@tonic-gate &vuidmice_rinit,
1087c478bd9Sstevel@tonic-gate &vuidmice_winit,
1097c478bd9Sstevel@tonic-gate NULL,
1107c478bd9Sstevel@tonic-gate NULL
1117c478bd9Sstevel@tonic-gate };
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate * This is the loadable module wrapper.
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * D_MTQPAIR effectively makes the module single threaded.
1197c478bd9Sstevel@tonic-gate * There can be only one thread active in the module at any time.
1207c478bd9Sstevel@tonic-gate * It may be a read or write thread.
1217c478bd9Sstevel@tonic-gate */
1227c478bd9Sstevel@tonic-gate #define VUIDMICE_CONF_FLAG (D_MP | D_MTQPAIR)
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate static struct fmodsw fsw = {
1257c478bd9Sstevel@tonic-gate VUID_NAME,
1267c478bd9Sstevel@tonic-gate &vuidmice_info,
1277c478bd9Sstevel@tonic-gate VUIDMICE_CONF_FLAG
1287c478bd9Sstevel@tonic-gate };
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate static struct modlstrmod modlstrmod = {
1317c478bd9Sstevel@tonic-gate &mod_strmodops,
1327c478bd9Sstevel@tonic-gate "mouse events to vuid events",
1337c478bd9Sstevel@tonic-gate &fsw
1347c478bd9Sstevel@tonic-gate };
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate * Module linkage information for the kernel.
1387c478bd9Sstevel@tonic-gate */
1397c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1407c478bd9Sstevel@tonic-gate MODREV_1,
1417c478bd9Sstevel@tonic-gate &modlstrmod,
1427c478bd9Sstevel@tonic-gate NULL
1437c478bd9Sstevel@tonic-gate };
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate static int module_open = 0; /* allow only one open of this module */
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate int
_init(void)1487c478bd9Sstevel@tonic-gate _init(void)
1497c478bd9Sstevel@tonic-gate {
1507c478bd9Sstevel@tonic-gate register int rc;
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate mutex_init(&vuidmice_lock, NULL, MUTEX_DEFAULT, NULL);
1537c478bd9Sstevel@tonic-gate if ((rc = mod_install(&modlinkage)) != 0) {
1547c478bd9Sstevel@tonic-gate mutex_destroy(&vuidmice_lock);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate return (rc);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate int
_fini(void)1607c478bd9Sstevel@tonic-gate _fini(void)
1617c478bd9Sstevel@tonic-gate {
1627c478bd9Sstevel@tonic-gate register int rc;
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate if ((rc = mod_remove(&modlinkage)) == 0)
1657c478bd9Sstevel@tonic-gate mutex_destroy(&vuidmice_lock);
1667c478bd9Sstevel@tonic-gate return (rc);
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1707c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
1777c478bd9Sstevel@tonic-gate static int
vuidmice_open(queue_t * qp,dev_t * devp,int oflag,int sflag,cred_t * crp)178*5e1743f0SToomas Soome vuidmice_open(queue_t *qp, dev_t *devp, int oflag, int sflag, cred_t *crp)
1797c478bd9Sstevel@tonic-gate {
180a9463f18Smeem if (qp->q_ptr != NULL)
181a9463f18Smeem return (0); /* reopen */
182a9463f18Smeem
1837c478bd9Sstevel@tonic-gate mutex_enter(&vuidmice_lock);
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate /* Allow only 1 open of this module */
1867c478bd9Sstevel@tonic-gate if (module_open) {
1877c478bd9Sstevel@tonic-gate mutex_exit(&vuidmice_lock);
1887c478bd9Sstevel@tonic-gate return (EBUSY);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate module_open++;
192a9463f18Smeem mutex_exit(&vuidmice_lock);
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate * Both the read and write queues share the same state structures.
1967c478bd9Sstevel@tonic-gate */
1977c478bd9Sstevel@tonic-gate qp->q_ptr = kmem_zalloc(sizeof (struct MouseStateInfo), KM_SLEEP);
1987c478bd9Sstevel@tonic-gate WR(qp)->q_ptr = qp->q_ptr;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate /* initialize state */
2017c478bd9Sstevel@tonic-gate STATEP->format = VUID_NATIVE;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate qprocson(qp);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate #ifdef VUID_OPEN
2067c478bd9Sstevel@tonic-gate if (VUID_OPEN(qp) != 0) {
2077c478bd9Sstevel@tonic-gate qprocsoff(qp);
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate mutex_enter(&vuidmice_lock);
2107c478bd9Sstevel@tonic-gate module_open--;
211a9463f18Smeem mutex_exit(&vuidmice_lock);
2127c478bd9Sstevel@tonic-gate kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
2137c478bd9Sstevel@tonic-gate qp->q_ptr = NULL;
2147c478bd9Sstevel@tonic-gate return (ENXIO);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate #endif
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate return (0);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
2227c478bd9Sstevel@tonic-gate static int
vuidmice_close(queue_t * qp,int flag,cred_t * crp)223*5e1743f0SToomas Soome vuidmice_close(queue_t *qp, int flag, cred_t *crp)
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate qprocsoff(qp);
2287c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL);
2297c478bd9Sstevel@tonic-gate flushq(OTHERQ(qp), FLUSHALL);
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate #ifdef VUID_CLOSE
2327c478bd9Sstevel@tonic-gate VUID_CLOSE(qp);
2337c478bd9Sstevel@tonic-gate #endif
234a9463f18Smeem mutex_enter(&vuidmice_lock);
2357c478bd9Sstevel@tonic-gate module_open--;
2367c478bd9Sstevel@tonic-gate mutex_exit(&vuidmice_lock);
237a9463f18Smeem kmem_free(qp->q_ptr, sizeof (struct MouseStateInfo));
238a9463f18Smeem qp->q_ptr = NULL;
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate return (0);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate * Put procedure for input from driver end of stream (read queue).
2457c478bd9Sstevel@tonic-gate */
2467c478bd9Sstevel@tonic-gate static int
vuidmice_rput(queue_t * const qp,mblk_t * mp)2477c478bd9Sstevel@tonic-gate vuidmice_rput(queue_t *const qp, mblk_t *mp)
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
2507c478bd9Sstevel@tonic-gate ASSERT(mp != NULL);
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate * Handle all the related high priority messages here, hence
2547c478bd9Sstevel@tonic-gate * should spend the least amount of time here.
2557c478bd9Sstevel@tonic-gate */
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate if (DB_TYPE(mp) == M_DATA) {
2587c478bd9Sstevel@tonic-gate if ((int)STATEP->format == VUID_FIRM_EVENT)
2597c478bd9Sstevel@tonic-gate return (putq(qp, mp)); /* queue message & return */
2607c478bd9Sstevel@tonic-gate } else if (DB_TYPE(mp) == M_FLUSH) {
2617c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR)
2627c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate putnext(qp, mp); /* pass it on */
2667c478bd9Sstevel@tonic-gate return (0);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate static int
vuidmice_rsrv(queue_t * const qp)2707c478bd9Sstevel@tonic-gate vuidmice_rsrv(queue_t *const qp)
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate register mblk_t *mp;
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate while ((mp = getq(qp)) != NULL) {
2777c478bd9Sstevel@tonic-gate ASSERT(DB_TYPE(mp) == M_DATA);
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate if (!canputnext(qp))
2807c478bd9Sstevel@tonic-gate return (putbq(qp, mp)); /* read side is blocked */
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) {
283a9463f18Smeem case M_DATA:
284a9463f18Smeem if ((int)STATEP->format == VUID_FIRM_EVENT)
285a9463f18Smeem (void) VUID_QUEUE(qp, mp);
286a9463f18Smeem else
287a9463f18Smeem (void) putnext(qp, mp);
288a9463f18Smeem break;
2897c478bd9Sstevel@tonic-gate
290a9463f18Smeem default:
291a9463f18Smeem cmn_err(CE_WARN,
292a9463f18Smeem "vuidmice_rsrv: bad message type (0x%x)\n",
293a9463f18Smeem DB_TYPE(mp));
2947c478bd9Sstevel@tonic-gate
295a9463f18Smeem (void) putnext(qp, mp);
296a9463f18Smeem break;
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate return (0);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate * Put procedure for write from user end of stream (write queue).
3047c478bd9Sstevel@tonic-gate */
3057c478bd9Sstevel@tonic-gate static int
vuidmice_wput(queue_t * const qp,mblk_t * mp)3067c478bd9Sstevel@tonic-gate vuidmice_wput(queue_t *const qp, mblk_t *mp)
3077c478bd9Sstevel@tonic-gate {
3087c478bd9Sstevel@tonic-gate int error = 0;
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate ASSERT(qp != NULL);
3117c478bd9Sstevel@tonic-gate ASSERT(mp != NULL);
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate * Handle all the related high priority messages here, hence
3157c478bd9Sstevel@tonic-gate * should spend the least amount of time here.
3167c478bd9Sstevel@tonic-gate */
3177c478bd9Sstevel@tonic-gate switch (DB_TYPE(mp)) { /* handle hi pri messages here */
3187c478bd9Sstevel@tonic-gate case M_FLUSH:
3197c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW)
3207c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL);
3217c478bd9Sstevel@tonic-gate putnext(qp, mp); /* pass it on */
3227c478bd9Sstevel@tonic-gate return (0);
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate case M_IOCTL: {
32522eb7cb5Sgd struct iocblk *iocbp = (void *)mp->b_rptr;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate switch (iocbp->ioc_cmd) {
3287c478bd9Sstevel@tonic-gate case VUIDSFORMAT:
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate * VUIDSFORMAT is known to the stream head and thus
3327c478bd9Sstevel@tonic-gate * is guaranteed to be an I_STR ioctl.
3337c478bd9Sstevel@tonic-gate */
3347c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
3357c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
3367c478bd9Sstevel@tonic-gate return (0);
3377c478bd9Sstevel@tonic-gate } else {
3387c478bd9Sstevel@tonic-gate int format_type;
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (int));
3417c478bd9Sstevel@tonic-gate if (error != 0) {
3427c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, error);
3437c478bd9Sstevel@tonic-gate return (0);
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
34622eb7cb5Sgd format_type =
34722eb7cb5Sgd *(int *)(void *)mp->b_cont->b_rptr;
3487c478bd9Sstevel@tonic-gate STATEP->format = (uchar_t)format_type;
3497c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
3507c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
3517c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
3527c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /* return buffer to pool ASAP */
3567c478bd9Sstevel@tonic-gate if (mp->b_cont) {
3577c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
3587c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
3597c478bd9Sstevel@tonic-gate }
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate qreply(qp, mp);
3627c478bd9Sstevel@tonic-gate return (0);
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate case VUIDGFORMAT:
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate /* return buffer to pool ASAP */
3677c478bd9Sstevel@tonic-gate if (mp->b_cont) {
3687c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); /* over written below */
3697c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate /*
3737c478bd9Sstevel@tonic-gate * VUIDGFORMAT is known to the stream head and thus
3747c478bd9Sstevel@tonic-gate * is guaranteed to be an I_STR ioctl.
3757c478bd9Sstevel@tonic-gate */
3767c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
3777c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
3787c478bd9Sstevel@tonic-gate return (0);
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (int), BPRI_MED);
3827c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
3837c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EAGAIN);
3847c478bd9Sstevel@tonic-gate return (0);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate
38722eb7cb5Sgd *(int *)(void *)mp->b_cont->b_rptr =
38822eb7cb5Sgd (int)STATEP->format;
3897c478bd9Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (int);
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate iocbp->ioc_count = sizeof (int);
3927c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
3937c478bd9Sstevel@tonic-gate qreply(qp, mp);
3947c478bd9Sstevel@tonic-gate return (0);
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate case VUID_NATIVE:
3977c478bd9Sstevel@tonic-gate case VUIDSADDR:
3987c478bd9Sstevel@tonic-gate case VUIDGADDR:
3997c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, ENOTTY);
4007c478bd9Sstevel@tonic-gate return (0);
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate case MSIOBUTTONS:
4037c478bd9Sstevel@tonic-gate /* return buffer to pool ASAP */
4047c478bd9Sstevel@tonic-gate if (mp->b_cont) {
4057c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); /* over written below */
4067c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate * MSIOBUTTONS is known to streamio.c and this
4117c478bd9Sstevel@tonic-gate * is assume to be non-I_STR & non-TRANSPARENT ioctl
4127c478bd9Sstevel@tonic-gate */
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
4157c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
4167c478bd9Sstevel@tonic-gate return (0);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate if (STATEP->nbuttons == 0) {
4207c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EINVAL);
4217c478bd9Sstevel@tonic-gate return (0);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (int), BPRI_MED);
4257c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
4267c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, EAGAIN);
4277c478bd9Sstevel@tonic-gate return (0);
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate
43022eb7cb5Sgd *(int *)(void *)mp->b_cont->b_rptr =
43122eb7cb5Sgd (int)STATEP->nbuttons;
4327c478bd9Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (int);
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate iocbp->ioc_count = sizeof (int);
4357c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
4367c478bd9Sstevel@tonic-gate qreply(qp, mp);
4377c478bd9Sstevel@tonic-gate return (0);
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate /*
4407c478bd9Sstevel@tonic-gate * New IOCTL support. Since it's explicitly mentioned
4417c478bd9Sstevel@tonic-gate * that you can't add more ioctls to stream head's
4427c478bd9Sstevel@tonic-gate * hard coded list, we have to do the transparent
4437c478bd9Sstevel@tonic-gate * ioctl processing which is not very exciting.
4447c478bd9Sstevel@tonic-gate */
4457c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
4467c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
4477c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
4487c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
4497c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
4507c478bd9Sstevel@tonic-gate error = vuidmice_handle_wheel_resolution_ioctl(qp,
451a9463f18Smeem mp, iocbp->ioc_cmd);
4527c478bd9Sstevel@tonic-gate if (!error) {
4537c478bd9Sstevel@tonic-gate return (0);
4547c478bd9Sstevel@tonic-gate } else {
4557c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, error);
4567c478bd9Sstevel@tonic-gate return (0);
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate default:
4597c478bd9Sstevel@tonic-gate putnext(qp, mp); /* nothing to process here */
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate return (0);
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate } /* End of case M_IOCTL */
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate case M_IOCDATA:
4677c478bd9Sstevel@tonic-gate vuidmice_miocdata(qp, mp);
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate return (0);
4707c478bd9Sstevel@tonic-gate default:
4717c478bd9Sstevel@tonic-gate putnext(qp, mp); /* pass it on */
4727c478bd9Sstevel@tonic-gate return (0);
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate /*NOTREACHED*/
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@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)4787c478bd9Sstevel@tonic-gate VUID_PUTNEXT(queue_t *const qp, uchar_t event_id, uchar_t event_pair_type,
4797c478bd9Sstevel@tonic-gate uchar_t event_pair, int event_value)
4807c478bd9Sstevel@tonic-gate {
4817c478bd9Sstevel@tonic-gate int strikes = 1;
4827c478bd9Sstevel@tonic-gate mblk_t *bp;
4837c478bd9Sstevel@tonic-gate Firm_event *fep;
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate /*
4867c478bd9Sstevel@tonic-gate * Give this event 3 chances to allocate blocks,
4877c478bd9Sstevel@tonic-gate * otherwise discard this mouse event. 3 Strikes and you're out.
4887c478bd9Sstevel@tonic-gate */
4897c478bd9Sstevel@tonic-gate while ((bp = allocb((int)sizeof (Firm_event), BPRI_HI)) == NULL) {
4907c478bd9Sstevel@tonic-gate if (++strikes > 3)
4917c478bd9Sstevel@tonic-gate return;
4927c478bd9Sstevel@tonic-gate drv_usecwait(10);
4937c478bd9Sstevel@tonic-gate }
4947c478bd9Sstevel@tonic-gate
49522eb7cb5Sgd fep = (void *)bp->b_wptr;
4967c478bd9Sstevel@tonic-gate fep->id = vuid_id_addr(VKEY_FIRST) | vuid_id_offset(event_id);
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate fep->pair_type = event_pair_type;
4997c478bd9Sstevel@tonic-gate fep->pair = event_pair;
5007c478bd9Sstevel@tonic-gate fep->value = event_value;
5017c478bd9Sstevel@tonic-gate uniqtime32(&fep->time);
5027c478bd9Sstevel@tonic-gate bp->b_wptr += sizeof (Firm_event);
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate if (canput(qp->q_next))
5057c478bd9Sstevel@tonic-gate putnext(qp, bp);
5067c478bd9Sstevel@tonic-gate else
5077c478bd9Sstevel@tonic-gate (void) putbq(qp, bp); /* read side is blocked */
5087c478bd9Sstevel@tonic-gate }
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate
5117c478bd9Sstevel@tonic-gate /*
5127c478bd9Sstevel@tonic-gate * vuidmice_miocdata
5137c478bd9Sstevel@tonic-gate * M_IOCDATA processing for IOCTL's: VUIDGWHEELCOUNT, VUIDGWHEELINFO,
5147c478bd9Sstevel@tonic-gate * VUIDGWHEELSTATE, VUIDSWHEELSTATE & MSIOSRESOLUTION.
5157c478bd9Sstevel@tonic-gate */
5167c478bd9Sstevel@tonic-gate static void
vuidmice_miocdata(queue_t * qp,mblk_t * mp)5177c478bd9Sstevel@tonic-gate vuidmice_miocdata(queue_t *qp, mblk_t *mp)
5187c478bd9Sstevel@tonic-gate {
5197c478bd9Sstevel@tonic-gate struct copyresp *copyresp;
5207c478bd9Sstevel@tonic-gate struct iocblk *iocbp;
5217c478bd9Sstevel@tonic-gate mblk_t *ioctmp;
5227c478bd9Sstevel@tonic-gate mblk_t *datap;
5237c478bd9Sstevel@tonic-gate Mouse_iocstate_t *Mouseioc;
524664d603cSyz size_t size;
5257c478bd9Sstevel@tonic-gate int err = 0;
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate
52822eb7cb5Sgd copyresp = (void *)mp->b_rptr;
52922eb7cb5Sgd iocbp = (void *)mp->b_rptr;
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate if (copyresp->cp_rval) {
5327c478bd9Sstevel@tonic-gate err = EAGAIN;
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate goto err;
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate switch (copyresp->cp_cmd) {
5377c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
5387c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
5397c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
5407c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
5417c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
5427c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
5437c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) {
5447c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5457c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate break;
5497c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
5507c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
55122eb7cb5Sgd ioctmp = copyresp->cp_private;
55222eb7cb5Sgd Mouseioc = (void *)ioctmp->b_rptr;
5537c478bd9Sstevel@tonic-gate if (Mouseioc->ioc_state == GETSTRUCT) {
5547c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
5557c478bd9Sstevel@tonic-gate err = EINVAL;
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate break;
5587c478bd9Sstevel@tonic-gate }
5597c478bd9Sstevel@tonic-gate datap = mp->b_cont;
5607c478bd9Sstevel@tonic-gate if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
5617c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_state(qp, datap,
562a9463f18Smeem VUIDGWHEELSTATE);
5637c478bd9Sstevel@tonic-gate } else {
5647c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_info(datap);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate if (err) {
5677c478bd9Sstevel@tonic-gate break;
5687c478bd9Sstevel@tonic-gate }
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate if (copyresp->cp_cmd == VUIDGWHEELSTATE) {
571664d603cSyz size = sizeof (wheel_state);
5727c478bd9Sstevel@tonic-gate } else {
573664d603cSyz size = sizeof (wheel_info);
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate Mouseioc->ioc_state = GETRESULT;
577664d603cSyz ASSERT(Mouseioc->u_addr != NULL);
578664d603cSyz mcopyout(mp, ioctmp, size, Mouseioc->u_addr, NULL);
5797c478bd9Sstevel@tonic-gate } else if (Mouseioc->ioc_state == GETRESULT) {
5807c478bd9Sstevel@tonic-gate freemsg(ioctmp);
5817c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
5827c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + sizeof (struct iocblk);
5837c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
5847c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
5857c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
5867c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) {
5877c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
5887c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate }
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate break;
5937c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
5947c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
59522eb7cb5Sgd ioctmp = copyresp->cp_private;
59622eb7cb5Sgd Mouseioc = (void *)ioctmp->b_rptr;
5977c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) {
5987c478bd9Sstevel@tonic-gate err = EINVAL;
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate break;
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate datap = mp->b_cont;
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate if (copyresp->cp_cmd == VUIDSWHEELSTATE) {
6057c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_state(qp,
6067c478bd9Sstevel@tonic-gate datap, VUIDSWHEELSTATE);
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate if (err) {
6107c478bd9Sstevel@tonic-gate break;
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate if (mp->b_cont) {
6147c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
61522eb7cb5Sgd mp->b_cont = NULL;
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate freemsg(ioctmp);
6187c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
6197c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
6207c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
6217c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate break;
6247c478bd9Sstevel@tonic-gate default:
6257c478bd9Sstevel@tonic-gate err = EINVAL;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate break;
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate err:
6317c478bd9Sstevel@tonic-gate if (err) {
6327c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
6337c478bd9Sstevel@tonic-gate if (mp->b_cont) {
6347c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
63522eb7cb5Sgd mp->b_cont = NULL;
6367c478bd9Sstevel@tonic-gate }
6377c478bd9Sstevel@tonic-gate if (copyresp->cp_private) {
63822eb7cb5Sgd freemsg(copyresp->cp_private);
63922eb7cb5Sgd copyresp->cp_private = NULL;
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate iocbp->ioc_count = 0;
6427c478bd9Sstevel@tonic-gate iocbp->ioc_error = err;
6437c478bd9Sstevel@tonic-gate }
6447c478bd9Sstevel@tonic-gate qreply(qp, mp);
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate * vuidmice_handle_wheel_resolution_ioctl
6507c478bd9Sstevel@tonic-gate * Handle wheel mouse and MSIOSRESOLUTION ioctls.
6517c478bd9Sstevel@tonic-gate *
6527c478bd9Sstevel@tonic-gate * Here we also support non-transparent way of these ioctls
6537c478bd9Sstevel@tonic-gate * just like usb mouse driver does, so the consms module is
6547c478bd9Sstevel@tonic-gate * very simple to deal with these ioctls.
6557c478bd9Sstevel@tonic-gate */
6567c478bd9Sstevel@tonic-gate static int
vuidmice_handle_wheel_resolution_ioctl(queue_t * qp,mblk_t * mp,int cmd)6577c478bd9Sstevel@tonic-gate vuidmice_handle_wheel_resolution_ioctl(queue_t *qp, mblk_t *mp, int cmd)
6587c478bd9Sstevel@tonic-gate {
6597c478bd9Sstevel@tonic-gate int err = 0;
6607c478bd9Sstevel@tonic-gate Mouse_iocstate_t *Mouseioc;
661664d603cSyz caddr_t useraddr;
662664d603cSyz size_t size;
6637c478bd9Sstevel@tonic-gate mblk_t *ioctmp;
6647c478bd9Sstevel@tonic-gate mblk_t *datap;
6657c478bd9Sstevel@tonic-gate
66622eb7cb5Sgd struct iocblk *iocbp = (void *)mp->b_rptr;
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate if (iocbp->ioc_count == TRANSPARENT) {
669664d603cSyz if (mp->b_cont == NULL)
670664d603cSyz return (EINVAL);
67122eb7cb5Sgd useraddr = *((caddr_t *)(void *)mp->b_cont->b_rptr);
6727c478bd9Sstevel@tonic-gate switch (cmd) {
6737c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
674664d603cSyz size = sizeof (int);
675664d603cSyz if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL)
676664d603cSyz return (EAGAIN);
67722eb7cb5Sgd *((int *)(void *)datap->b_wptr) =
67822eb7cb5Sgd STATEP->vuid_mouse_mode;
679664d603cSyz mcopyout(mp, NULL, size, NULL, datap);
6807c478bd9Sstevel@tonic-gate qreply(qp, mp);
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate return (err);
6837c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
684664d603cSyz size = sizeof (wheel_info);
6857c478bd9Sstevel@tonic-gate break;
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
6887c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
689664d603cSyz size = sizeof (wheel_state);
6907c478bd9Sstevel@tonic-gate break;
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
693664d603cSyz size = sizeof (Ms_screen_resolution);
6947c478bd9Sstevel@tonic-gate break;
6957c478bd9Sstevel@tonic-gate }
6967c478bd9Sstevel@tonic-gate
69722eb7cb5Sgd if ((ioctmp = allocb(sizeof (Mouse_iocstate_t),
698664d603cSyz BPRI_MED)) == NULL)
699664d603cSyz return (EAGAIN);
70022eb7cb5Sgd Mouseioc = (void *)ioctmp->b_rptr;
7017c478bd9Sstevel@tonic-gate Mouseioc->ioc_state = GETSTRUCT;
702664d603cSyz Mouseioc->u_addr = useraddr;
7037c478bd9Sstevel@tonic-gate ioctmp->b_wptr = ioctmp->b_rptr + sizeof (Mouse_iocstate_t);
704664d603cSyz mcopyin(mp, ioctmp, size, NULL);
7057c478bd9Sstevel@tonic-gate qreply(qp, mp);
7067c478bd9Sstevel@tonic-gate
7077c478bd9Sstevel@tonic-gate return (err);
7087c478bd9Sstevel@tonic-gate } else {
7097c478bd9Sstevel@tonic-gate switch (cmd) {
7107c478bd9Sstevel@tonic-gate case VUIDGWHEELCOUNT:
7117c478bd9Sstevel@tonic-gate if (mp->b_cont) {
7127c478bd9Sstevel@tonic-gate freemsg(mp->b_cont);
7137c478bd9Sstevel@tonic-gate mp->b_cont = NULL;
7147c478bd9Sstevel@tonic-gate }
715664d603cSyz if ((datap = allocb(sizeof (int), BPRI_HI)) == NULL) {
716664d603cSyz err = EAGAIN;
717664d603cSyz break;
718664d603cSyz }
71922eb7cb5Sgd *((int *)(void *)datap->b_wptr) =
72022eb7cb5Sgd STATEP->vuid_mouse_mode;
7217c478bd9Sstevel@tonic-gate datap->b_wptr += sizeof (int);
7227c478bd9Sstevel@tonic-gate mp->b_cont = datap;
7237c478bd9Sstevel@tonic-gate break;
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate case VUIDGWHEELINFO:
7267c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL ||
7277c478bd9Sstevel@tonic-gate iocbp->ioc_count != sizeof (wheel_info)) {
7287c478bd9Sstevel@tonic-gate err = EINVAL;
7297c478bd9Sstevel@tonic-gate break;
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate datap = mp->b_cont;
7327c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_info(datap);
7337c478bd9Sstevel@tonic-gate break;
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
7367c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
7377c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL ||
7387c478bd9Sstevel@tonic-gate iocbp->ioc_count != sizeof (wheel_state)) {
7397c478bd9Sstevel@tonic-gate err = EINVAL;
7407c478bd9Sstevel@tonic-gate break;
7417c478bd9Sstevel@tonic-gate }
7427c478bd9Sstevel@tonic-gate datap = mp->b_cont;
7437c478bd9Sstevel@tonic-gate err = vuidmice_service_wheel_state(qp, datap, cmd);
7447c478bd9Sstevel@tonic-gate break;
7457c478bd9Sstevel@tonic-gate
7467c478bd9Sstevel@tonic-gate case MSIOSRESOLUTION:
7477c478bd9Sstevel@tonic-gate /*
7487c478bd9Sstevel@tonic-gate * Now we just make Xserver and
7497c478bd9Sstevel@tonic-gate * the virtual mouse happy. Of course,
7507c478bd9Sstevel@tonic-gate * the screen resolution value may
7517c478bd9Sstevel@tonic-gate * be used later for absolute PS/2 mouse.
7527c478bd9Sstevel@tonic-gate */
7537c478bd9Sstevel@tonic-gate err = 0;
7547c478bd9Sstevel@tonic-gate break;
7557c478bd9Sstevel@tonic-gate }
7567c478bd9Sstevel@tonic-gate
7577c478bd9Sstevel@tonic-gate if (!err) {
7587c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7597c478bd9Sstevel@tonic-gate iocbp->ioc_rval = 0;
7607c478bd9Sstevel@tonic-gate iocbp->ioc_error = 0;
7617c478bd9Sstevel@tonic-gate qreply(qp, mp);
7627c478bd9Sstevel@tonic-gate }
7637c478bd9Sstevel@tonic-gate
7647c478bd9Sstevel@tonic-gate return (err);
7657c478bd9Sstevel@tonic-gate }
7667c478bd9Sstevel@tonic-gate }
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate static int
vuidmice_service_wheel_info(register mblk_t * datap)7697c478bd9Sstevel@tonic-gate vuidmice_service_wheel_info(register mblk_t *datap)
7707c478bd9Sstevel@tonic-gate {
7717c478bd9Sstevel@tonic-gate wheel_info *wi;
7727c478bd9Sstevel@tonic-gate int err = 0;
7737c478bd9Sstevel@tonic-gate
77422eb7cb5Sgd wi = (void *)datap->b_rptr;
7757c478bd9Sstevel@tonic-gate if (wi->vers != VUID_WHEEL_INFO_VERS) {
7767c478bd9Sstevel@tonic-gate err = EINVAL;
7777c478bd9Sstevel@tonic-gate return (err);
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate if (wi->id > (VUIDMICE_NUM_WHEELS - 1)) {
7817c478bd9Sstevel@tonic-gate err = EINVAL;
7827c478bd9Sstevel@tonic-gate return (err);
7837c478bd9Sstevel@tonic-gate }
784a9463f18Smeem wi->format = (wi->id == VUIDMICE_VERTICAL_WHEEL_ID) ?
785a9463f18Smeem VUID_WHEEL_FORMAT_VERTICAL : VUID_WHEEL_FORMAT_HORIZONTAL;
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate return (err);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate static int
vuidmice_service_wheel_state(register queue_t * qp,register mblk_t * datap,register uint_t cmd)7927c478bd9Sstevel@tonic-gate vuidmice_service_wheel_state(register queue_t *qp,
7937c478bd9Sstevel@tonic-gate register mblk_t *datap,
7947c478bd9Sstevel@tonic-gate register uint_t cmd)
7957c478bd9Sstevel@tonic-gate {
7967c478bd9Sstevel@tonic-gate wheel_state *ws;
7977c478bd9Sstevel@tonic-gate uint_t err = 0;
7987c478bd9Sstevel@tonic-gate
79922eb7cb5Sgd ws = (void *)datap->b_rptr;
8007c478bd9Sstevel@tonic-gate if (ws->vers != VUID_WHEEL_STATE_VERS) {
8017c478bd9Sstevel@tonic-gate err = EINVAL;
8027c478bd9Sstevel@tonic-gate return (err);
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate if (ws->id > (VUIDMICE_NUM_WHEELS - 1)) {
8067c478bd9Sstevel@tonic-gate err = EINVAL;
8077c478bd9Sstevel@tonic-gate return (err);
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate
8107c478bd9Sstevel@tonic-gate switch (cmd) {
8117c478bd9Sstevel@tonic-gate case VUIDGWHEELSTATE:
8127c478bd9Sstevel@tonic-gate ws->stateflags =
8137c478bd9Sstevel@tonic-gate (STATEP->wheel_state_bf >> ws->id) & 1;
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate break;
8167c478bd9Sstevel@tonic-gate case VUIDSWHEELSTATE:
8177c478bd9Sstevel@tonic-gate STATEP->wheel_state_bf = (ws->stateflags << ws->id) |
8187c478bd9Sstevel@tonic-gate (STATEP->wheel_state_bf & ~(1 << ws->id));
8197c478bd9Sstevel@tonic-gate
8207c478bd9Sstevel@tonic-gate break;
8217c478bd9Sstevel@tonic-gate default:
8227c478bd9Sstevel@tonic-gate err = EINVAL;
8237c478bd9Sstevel@tonic-gate
8247c478bd9Sstevel@tonic-gate return (err);
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate return (err);
8287c478bd9Sstevel@tonic-gate }
829