xref: /titanic_51/usr/src/uts/common/io/mouse8042.c (revision 193974072f41a843678abf5f61979c748687e66b)
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
5*19397407SSherry Moore  * Common Development and Distribution License (the "License").
6*19397407SSherry Moore  * 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 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*19397407SSherry Moore  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * PS/2 type Mouse Module - Streams
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/signal.h>
397c478bd9Sstevel@tonic-gate #include <sys/errno.h>
407c478bd9Sstevel@tonic-gate #include <sys/file.h>
417c478bd9Sstevel@tonic-gate #include <sys/termio.h>
427c478bd9Sstevel@tonic-gate #include <sys/stream.h>
437c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
447c478bd9Sstevel@tonic-gate #include <sys/strtty.h>
457c478bd9Sstevel@tonic-gate #include <sys/debug.h>
467c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
477c478bd9Sstevel@tonic-gate #include <sys/stat.h>
487c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
497c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #include <sys/promif.h>
527c478bd9Sstevel@tonic-gate #include <sys/cred.h>
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #include <sys/i8042.h>
557c478bd9Sstevel@tonic-gate #include <sys/note.h>
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #define	DRIVER_NAME(dip)	ddi_driver_name(dip)
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #ifdef	DEBUG
607c478bd9Sstevel@tonic-gate #define	MOUSE8042_DEBUG
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #define	MOUSE8042_INTERNAL_OPEN(minor)	(((minor) & 0x1) == 1)
647c478bd9Sstevel@tonic-gate #define	MOUSE8042_MINOR_TO_INSTANCE(minor)	((minor) / 2)
657c478bd9Sstevel@tonic-gate #define	MOUSE8042_INTERNAL_MINOR(minor)		((minor) + 1)
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate extern int ddi_create_internal_pathname(dev_info_t *, char *, int, minor_t);
687c478bd9Sstevel@tonic-gate extern void consconfig_link(major_t major, minor_t minor);
697c478bd9Sstevel@tonic-gate extern int consconfig_unlink(major_t major, minor_t minor);
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * Local Static Data
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * We only support one instance.  Yes, it's theoretically possible to
807c478bd9Sstevel@tonic-gate  * plug in more than one, but it's not worth the implementation cost.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  * The introduction of USB keyboards might make it worth reassessing
837c478bd9Sstevel@tonic-gate  * this decision, as they might free up the keyboard port for a second
847c478bd9Sstevel@tonic-gate  * PS/2 style mouse.
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate static dev_info_t *mouse8042_dip;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate struct mouse_state {
897c478bd9Sstevel@tonic-gate 	queue_t	*ms_rqp;
907c478bd9Sstevel@tonic-gate 	queue_t	*ms_wqp;
917c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t	ms_iblock_cookie;
927c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	ms_handle;
937c478bd9Sstevel@tonic-gate 	uint8_t			*ms_addr;
947c478bd9Sstevel@tonic-gate 	kmutex_t		ms_mutex;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	minor_t			ms_minor;
977c478bd9Sstevel@tonic-gate 	boolean_t		ms_opened;
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
1017c478bd9Sstevel@tonic-gate int mouse8042_debug = 0;
1027c478bd9Sstevel@tonic-gate int mouse8042_debug_minimal = 0;
1037c478bd9Sstevel@tonic-gate #endif
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate static uint_t mouse8042_intr(caddr_t arg);
1067c478bd9Sstevel@tonic-gate static int mouse8042_open(queue_t *q, dev_t *devp, int flag, int sflag,
1077c478bd9Sstevel@tonic-gate 		cred_t *cred_p);
1087c478bd9Sstevel@tonic-gate static int mouse8042_close(queue_t *q, int flag, cred_t *cred_p);
1097c478bd9Sstevel@tonic-gate static int mouse8042_wput(queue_t *q, mblk_t *mp);
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate static int mouse8042_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd,
1127c478bd9Sstevel@tonic-gate 		void *arg, void **result);
1137c478bd9Sstevel@tonic-gate static int mouse8042_attach(dev_info_t *dev, ddi_attach_cmd_t cmd);
1147c478bd9Sstevel@tonic-gate static int mouse8042_detach(dev_info_t *dev, ddi_detach_cmd_t cmd);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Streams module info.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate #define	MODULE_NAME	"mouse8042"
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate static struct module_info	mouse8042_minfo = {
1237c478bd9Sstevel@tonic-gate 	23,		/* Module ID number */
1247c478bd9Sstevel@tonic-gate 	MODULE_NAME,
1257c478bd9Sstevel@tonic-gate 	0, INFPSZ,	/* minimum & maximum packet sizes */
1267c478bd9Sstevel@tonic-gate 	256, 128	/* hi and low water marks */
1277c478bd9Sstevel@tonic-gate };
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate static struct qinit mouse8042_rinit = {
1307c478bd9Sstevel@tonic-gate 	NULL,		/* put */
1317c478bd9Sstevel@tonic-gate 	NULL,		/* service */
1327c478bd9Sstevel@tonic-gate 	mouse8042_open,
1337c478bd9Sstevel@tonic-gate 	mouse8042_close,
1347c478bd9Sstevel@tonic-gate 	NULL,		/* admin */
1357c478bd9Sstevel@tonic-gate 	&mouse8042_minfo,
1367c478bd9Sstevel@tonic-gate 	NULL		/* statistics */
1377c478bd9Sstevel@tonic-gate };
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate static struct qinit mouse8042_winit = {
1407c478bd9Sstevel@tonic-gate 	mouse8042_wput,	/* put */
1417c478bd9Sstevel@tonic-gate 	NULL,		/* service */
1427c478bd9Sstevel@tonic-gate 	NULL,		/* open */
1437c478bd9Sstevel@tonic-gate 	NULL,		/* close */
1447c478bd9Sstevel@tonic-gate 	NULL,		/* admin */
1457c478bd9Sstevel@tonic-gate 	&mouse8042_minfo,
1467c478bd9Sstevel@tonic-gate 	NULL		/* statistics */
1477c478bd9Sstevel@tonic-gate };
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate static struct streamtab mouse8042_strinfo = {
1507c478bd9Sstevel@tonic-gate 	&mouse8042_rinit,
1517c478bd9Sstevel@tonic-gate 	&mouse8042_winit,
1527c478bd9Sstevel@tonic-gate 	NULL,		/* muxrinit */
1537c478bd9Sstevel@tonic-gate 	NULL,		/* muxwinit */
1547c478bd9Sstevel@tonic-gate };
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * Local Function Declarations
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate static struct cb_ops	mouse8042_cb_ops = {
1617c478bd9Sstevel@tonic-gate 	nodev,			/* open */
1627c478bd9Sstevel@tonic-gate 	nodev,			/* close */
1637c478bd9Sstevel@tonic-gate 	nodev,			/* strategy */
1647c478bd9Sstevel@tonic-gate 	nodev,			/* print */
1657c478bd9Sstevel@tonic-gate 	nodev,			/* dump */
1667c478bd9Sstevel@tonic-gate 	nodev,			/* read */
1677c478bd9Sstevel@tonic-gate 	nodev,			/* write */
1687c478bd9Sstevel@tonic-gate 	nodev,			/* ioctl */
1697c478bd9Sstevel@tonic-gate 	nodev,			/* devmap */
1707c478bd9Sstevel@tonic-gate 	nodev,			/* mmap */
1717c478bd9Sstevel@tonic-gate 	nodev,			/* segmap */
1727c478bd9Sstevel@tonic-gate 	nochpoll,		/* poll */
1737c478bd9Sstevel@tonic-gate 	ddi_prop_op,		/* cb_prop_op */
1747c478bd9Sstevel@tonic-gate 	&mouse8042_strinfo,	/* streamtab  */
1757c478bd9Sstevel@tonic-gate 	D_MP | D_NEW
1767c478bd9Sstevel@tonic-gate };
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate static struct dev_ops	mouse8042_ops = {
1807c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
1817c478bd9Sstevel@tonic-gate 	0,			/* refcnt  */
1827c478bd9Sstevel@tonic-gate 	mouse8042_getinfo,	/* getinfo */
1837c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
1847c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
1857c478bd9Sstevel@tonic-gate 	mouse8042_attach,	/* attach */
1867c478bd9Sstevel@tonic-gate 	mouse8042_detach,	/* detach */
1877c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
1887c478bd9Sstevel@tonic-gate 	&mouse8042_cb_ops,	/* driver operations */
189*19397407SSherry Moore 	(struct bus_ops *)0,	/* bus operations */
190*19397407SSherry Moore 	NULL,			/* power */
191*19397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
1927c478bd9Sstevel@tonic-gate };
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate  * This is the loadable module wrapper.
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
2067c478bd9Sstevel@tonic-gate 	&mod_driverops, /* Type of module.  This one is a driver */
207*19397407SSherry Moore 	"PS/2 Mouse",
2087c478bd9Sstevel@tonic-gate 	&mouse8042_ops,	/* driver ops */
2097c478bd9Sstevel@tonic-gate };
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
2127c478bd9Sstevel@tonic-gate 	MODREV_1,
2137c478bd9Sstevel@tonic-gate 	(void *)&modldrv,
2147c478bd9Sstevel@tonic-gate 	NULL
2157c478bd9Sstevel@tonic-gate };
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * This is the driver initialization routine.
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate int
2217c478bd9Sstevel@tonic-gate _init()
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate 	int	rv;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	rv = mod_install(&modlinkage);
2267c478bd9Sstevel@tonic-gate 	return (rv);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate int
2317c478bd9Sstevel@tonic-gate _fini(void)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate int
2387c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate static int
2447c478bd9Sstevel@tonic-gate mouse8042_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate 	struct mouse_state *state;
247fd9cb95cSsethg 	mblk_t *mp;
2487c478bd9Sstevel@tonic-gate 	int instance = ddi_get_instance(dip);
2497c478bd9Sstevel@tonic-gate 	static ddi_device_acc_attr_t attr = {
2507c478bd9Sstevel@tonic-gate 		DDI_DEVICE_ATTR_V0,
2517c478bd9Sstevel@tonic-gate 		DDI_NEVERSWAP_ACC,
2527c478bd9Sstevel@tonic-gate 		DDI_STRICTORDER_ACC,
2537c478bd9Sstevel@tonic-gate 	};
2547c478bd9Sstevel@tonic-gate 	int rc;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
2587c478bd9Sstevel@tonic-gate 	if (mouse8042_debug) {
2597c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, MODULE_NAME "_attach entry\n");
2607c478bd9Sstevel@tonic-gate 	}
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate 
263fd9cb95cSsethg 	if (cmd == DDI_RESUME) {
264fd9cb95cSsethg 		state = (struct mouse_state *)ddi_get_driver_private(dip);
265fd9cb95cSsethg 
266fd9cb95cSsethg 		/*
267fd9cb95cSsethg 		 * Send a 0xaa 0x00 upstream.
268fd9cb95cSsethg 		 * This causes the vuid module to reset the mouse.
269fd9cb95cSsethg 		 */
270fd9cb95cSsethg 		if (state->ms_rqp != NULL) {
271fd9cb95cSsethg 			if (mp = allocb(1, BPRI_MED)) {
272fd9cb95cSsethg 				*mp->b_wptr++ = 0xaa;
273fd9cb95cSsethg 				putnext(state->ms_rqp, mp);
274fd9cb95cSsethg 			}
275fd9cb95cSsethg 			if (mp = allocb(1, BPRI_MED)) {
276fd9cb95cSsethg 				*mp->b_wptr++ = 0x0;
277fd9cb95cSsethg 				putnext(state->ms_rqp, mp);
278fd9cb95cSsethg 			}
279fd9cb95cSsethg 		}
280fd9cb95cSsethg 		return (DDI_SUCCESS);
281fd9cb95cSsethg 	}
282fd9cb95cSsethg 
2837c478bd9Sstevel@tonic-gate 	if (cmd != DDI_ATTACH)
2847c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	if (mouse8042_dip != NULL)
2877c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	/* allocate and initialize state structure */
2907c478bd9Sstevel@tonic-gate 	state = kmem_zalloc(sizeof (struct mouse_state), KM_SLEEP);
2917c478bd9Sstevel@tonic-gate 	state->ms_opened = B_FALSE;
2927c478bd9Sstevel@tonic-gate 	ddi_set_driver_private(dip, state);
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	/*
2957c478bd9Sstevel@tonic-gate 	 * In order to support virtual keyboard/mouse, we should distinguish
2967c478bd9Sstevel@tonic-gate 	 * between internal virtual open and external physical open.
2977c478bd9Sstevel@tonic-gate 	 *
2987c478bd9Sstevel@tonic-gate 	 * When the physical devices are opened by application, they will
2997c478bd9Sstevel@tonic-gate 	 * be unlinked from the virtual device and their data stream will
3007c478bd9Sstevel@tonic-gate 	 * not be sent to the virtual device. When the opened physical
3017c478bd9Sstevel@tonic-gate 	 * devices are closed, they will be relinked to the virtual devices.
3027c478bd9Sstevel@tonic-gate 	 *
3037c478bd9Sstevel@tonic-gate 	 * All these automatic switch between virtual and physical are
3047c478bd9Sstevel@tonic-gate 	 * transparent.
3057c478bd9Sstevel@tonic-gate 	 *
3067c478bd9Sstevel@tonic-gate 	 * So we change minor node numbering scheme to be:
3077c478bd9Sstevel@tonic-gate 	 * 	external node minor num == instance * 2
3087c478bd9Sstevel@tonic-gate 	 *	internal node minor num == instance * 2 + 1
3097c478bd9Sstevel@tonic-gate 	 */
310fd9cb95cSsethg 	rc = ddi_create_minor_node(dip, "mouse", S_IFCHR, instance * 2,
3117c478bd9Sstevel@tonic-gate 	    DDI_NT_MOUSE, NULL);
3127c478bd9Sstevel@tonic-gate 	if (rc != DDI_SUCCESS) {
3137c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
3147c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT,
3157c478bd9Sstevel@tonic-gate 		    MODULE_NAME "_attach: ddi_create_minor_node failed\n");
3167c478bd9Sstevel@tonic-gate #endif
3177c478bd9Sstevel@tonic-gate 		goto fail_1;
3187c478bd9Sstevel@tonic-gate 	}
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	if (ddi_create_internal_pathname(dip, "internal_mouse", S_IFCHR,
3217c478bd9Sstevel@tonic-gate 	    instance * 2 + 1) != DDI_SUCCESS) {
3227c478bd9Sstevel@tonic-gate 		goto fail_2;
3237c478bd9Sstevel@tonic-gate 	}
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	rc = ddi_regs_map_setup(dip, 0, (caddr_t *)&state->ms_addr,
3267c478bd9Sstevel@tonic-gate 	    (offset_t)0, (offset_t)0, &attr, &state->ms_handle);
3277c478bd9Sstevel@tonic-gate 	if (rc != DDI_SUCCESS) {
3287c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
3297c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, MODULE_NAME "_attach:  can't map registers");
3307c478bd9Sstevel@tonic-gate #endif
3317c478bd9Sstevel@tonic-gate 		goto fail_2;
3327c478bd9Sstevel@tonic-gate 	}
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	rc = ddi_get_iblock_cookie(dip, 0, &state->ms_iblock_cookie);
3357c478bd9Sstevel@tonic-gate 	if (rc != DDI_SUCCESS) {
3367c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
3377c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
3387c478bd9Sstevel@tonic-gate 		    MODULE_NAME "_attach:  Can't get iblock cookie");
3397c478bd9Sstevel@tonic-gate #endif
3407c478bd9Sstevel@tonic-gate 		goto fail_3;
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	mutex_init(&state->ms_mutex, NULL, MUTEX_DRIVER,
3447c478bd9Sstevel@tonic-gate 	    state->ms_iblock_cookie);
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	rc = ddi_add_intr(dip, 0,
3477c478bd9Sstevel@tonic-gate 	    (ddi_iblock_cookie_t *)NULL, (ddi_idevice_cookie_t *)NULL,
3487c478bd9Sstevel@tonic-gate 	    mouse8042_intr, (caddr_t)state);
3497c478bd9Sstevel@tonic-gate 	if (rc != DDI_SUCCESS) {
3507c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
3517c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, MODULE_NAME "_attach: cannot add interrupt");
3527c478bd9Sstevel@tonic-gate #endif
3537c478bd9Sstevel@tonic-gate 		goto fail_3;
3547c478bd9Sstevel@tonic-gate 	}
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	mouse8042_dip = dip;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	/* Now that we're attached, announce our presence to the world. */
3597c478bd9Sstevel@tonic-gate 	ddi_report_dev(dip);
3607c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
361*19397407SSherry Moore 	cmn_err(CE_CONT, "?%s #%d\n", DRIVER_NAME(dip), ddi_get_instance(dip));
3627c478bd9Sstevel@tonic-gate #endif
3637c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate fail_3:
3667c478bd9Sstevel@tonic-gate 	ddi_regs_map_free(&state->ms_handle);
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate fail_2:
3697c478bd9Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate fail_1:
3727c478bd9Sstevel@tonic-gate 	kmem_free(state, sizeof (struct mouse_state));
3737c478bd9Sstevel@tonic-gate 	return (rc);
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3777c478bd9Sstevel@tonic-gate static int
3787c478bd9Sstevel@tonic-gate mouse8042_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate 	struct mouse_state *state;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	state = ddi_get_driver_private(dip);
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	switch (cmd) {
385fd9cb95cSsethg 	case DDI_SUSPEND:
386fd9cb95cSsethg 		return (DDI_SUCCESS);
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
3897c478bd9Sstevel@tonic-gate 		ddi_remove_intr(dip, 0, state->ms_iblock_cookie);
3907c478bd9Sstevel@tonic-gate 		mouse8042_dip = NULL;
3917c478bd9Sstevel@tonic-gate 		mutex_destroy(&state->ms_mutex);
3927c478bd9Sstevel@tonic-gate 		ddi_prop_remove_all(dip);
3937c478bd9Sstevel@tonic-gate 		ddi_regs_map_free(&state->ms_handle);
3947c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(dip, NULL);
3957c478bd9Sstevel@tonic-gate 		kmem_free(state, sizeof (struct mouse_state));
3967c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	default:
3997c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
4007c478bd9Sstevel@tonic-gate 		if (mouse8042_debug) {
4017c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT,
4027c478bd9Sstevel@tonic-gate 			    "mouse8042_detach: cmd = %d unknown\n", cmd);
4037c478bd9Sstevel@tonic-gate 		}
4047c478bd9Sstevel@tonic-gate #endif
4057c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4067c478bd9Sstevel@tonic-gate 	}
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /* ARGSUSED */
4117c478bd9Sstevel@tonic-gate static int
4127c478bd9Sstevel@tonic-gate mouse8042_getinfo(
4137c478bd9Sstevel@tonic-gate     dev_info_t *dip,
4147c478bd9Sstevel@tonic-gate     ddi_info_cmd_t infocmd,
4157c478bd9Sstevel@tonic-gate     void *arg,
4167c478bd9Sstevel@tonic-gate     void **result)
4177c478bd9Sstevel@tonic-gate {
4187c478bd9Sstevel@tonic-gate 	dev_t dev = (dev_t)arg;
4197c478bd9Sstevel@tonic-gate 	minor_t	minor = getminor(dev);
4207c478bd9Sstevel@tonic-gate 	int	instance = MOUSE8042_MINOR_TO_INSTANCE(minor);
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
4237c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
4247c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_getinfo: call\n");
4257c478bd9Sstevel@tonic-gate #endif
4267c478bd9Sstevel@tonic-gate 	switch (infocmd) {
4277c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
4287c478bd9Sstevel@tonic-gate 		if (mouse8042_dip == NULL)
4297c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 		*result = (void *)mouse8042_dip;
4327c478bd9Sstevel@tonic-gate 		break;
4337c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
4347c478bd9Sstevel@tonic-gate 		*result = (void *)(uintptr_t)instance;
4357c478bd9Sstevel@tonic-gate 		break;
4367c478bd9Sstevel@tonic-gate 	default:
4377c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4387c478bd9Sstevel@tonic-gate 	}
4397c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4437c478bd9Sstevel@tonic-gate static int
4447c478bd9Sstevel@tonic-gate mouse8042_open(
4457c478bd9Sstevel@tonic-gate 	queue_t	*q,
4467c478bd9Sstevel@tonic-gate 	dev_t	*devp,
4477c478bd9Sstevel@tonic-gate 	int	flag,
4487c478bd9Sstevel@tonic-gate 	int	sflag,
4497c478bd9Sstevel@tonic-gate 	cred_t	*cred_p)
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate 	struct mouse_state *state;
4527c478bd9Sstevel@tonic-gate 	minor_t	minor = getminor(*devp);
4537c478bd9Sstevel@tonic-gate 	int rval;
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate 	if (mouse8042_dip == NULL)
4567c478bd9Sstevel@tonic-gate 		return (ENXIO);
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	state = ddi_get_driver_private(mouse8042_dip);
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
4617c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
4627c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_open:entered\n");
4637c478bd9Sstevel@tonic-gate #endif
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	mutex_enter(&state->ms_mutex);
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	if (state->ms_opened) {
4687c478bd9Sstevel@tonic-gate 		/*
4697c478bd9Sstevel@tonic-gate 		 * Exit if the same minor node is already open
4707c478bd9Sstevel@tonic-gate 		 */
4717c478bd9Sstevel@tonic-gate 		if (state->ms_minor == minor) {
4727c478bd9Sstevel@tonic-gate 			mutex_exit(&state->ms_mutex);
4737c478bd9Sstevel@tonic-gate 			return (0);
4747c478bd9Sstevel@tonic-gate 		}
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 		/*
4777c478bd9Sstevel@tonic-gate 		 * Check whether it is switch between physical and virtual
4787c478bd9Sstevel@tonic-gate 		 *
4797c478bd9Sstevel@tonic-gate 		 * Opening from virtual while the device is being physically
4807c478bd9Sstevel@tonic-gate 		 * opened by an application should not happen. So we ASSERT
4817c478bd9Sstevel@tonic-gate 		 * this in DEBUG version, and return error in the non-DEBUG
4827c478bd9Sstevel@tonic-gate 		 * case.
4837c478bd9Sstevel@tonic-gate 		 */
4847c478bd9Sstevel@tonic-gate 		ASSERT(!MOUSE8042_INTERNAL_OPEN(minor));
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 		if (MOUSE8042_INTERNAL_OPEN(minor)) {
4877c478bd9Sstevel@tonic-gate 			mutex_exit(&state->ms_mutex);
4887c478bd9Sstevel@tonic-gate 			return (EINVAL);
4897c478bd9Sstevel@tonic-gate 		}
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 		/*
4927c478bd9Sstevel@tonic-gate 		 * Opening the physical one while it is being underneath
4937c478bd9Sstevel@tonic-gate 		 * the virtual one.
4947c478bd9Sstevel@tonic-gate 		 *
4957c478bd9Sstevel@tonic-gate 		 * consconfig_unlink is called to unlink this device from
4967c478bd9Sstevel@tonic-gate 		 * the virtual one, thus the old stream serving for this
4977c478bd9Sstevel@tonic-gate 		 * device under the virtual one is closed, and then the
4987c478bd9Sstevel@tonic-gate 		 * lower driver's close routine (here is mouse8042_close)
4997c478bd9Sstevel@tonic-gate 		 * is also called to accomplish the whole stream close.
5007c478bd9Sstevel@tonic-gate 		 * Here we have to drop the lock because mouse8042_close
5017c478bd9Sstevel@tonic-gate 		 * also needs the lock.
5027c478bd9Sstevel@tonic-gate 		 *
5037c478bd9Sstevel@tonic-gate 		 * For mouse, the old stream is:
5047c478bd9Sstevel@tonic-gate 		 *	consms->["pushmod"->]"mouse_vp driver"
5057c478bd9Sstevel@tonic-gate 		 *
5067c478bd9Sstevel@tonic-gate 		 * After the consconfig_unlink returns, the old stream is closed
5077c478bd9Sstevel@tonic-gate 		 * and we grab the lock again to reopen this device as normal.
5087c478bd9Sstevel@tonic-gate 		 */
5097c478bd9Sstevel@tonic-gate 		mutex_exit(&state->ms_mutex);
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 		/*
5127c478bd9Sstevel@tonic-gate 		 * If unlink fails, fail the physical open.
5137c478bd9Sstevel@tonic-gate 		 */
5147c478bd9Sstevel@tonic-gate 		if ((rval = consconfig_unlink(ddi_driver_major(mouse8042_dip),
5157c478bd9Sstevel@tonic-gate 		    MOUSE8042_INTERNAL_MINOR(minor))) != 0) {
5167c478bd9Sstevel@tonic-gate 			return (rval);
5177c478bd9Sstevel@tonic-gate 		}
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 		mutex_enter(&state->ms_mutex);
5207c478bd9Sstevel@tonic-gate 	}
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	q->q_ptr = (caddr_t)state;
5247c478bd9Sstevel@tonic-gate 	WR(q)->q_ptr = (caddr_t)state;
5257c478bd9Sstevel@tonic-gate 	state->ms_rqp = q;
5267c478bd9Sstevel@tonic-gate 	state->ms_wqp = WR(q);
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	qprocson(q);
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 	state->ms_minor = minor;
5317c478bd9Sstevel@tonic-gate 	state->ms_opened = B_TRUE;
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	mutex_exit(&state->ms_mutex);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	return (0);
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5407c478bd9Sstevel@tonic-gate static int
5417c478bd9Sstevel@tonic-gate mouse8042_close(queue_t *q, int flag, cred_t *cred_p)
5427c478bd9Sstevel@tonic-gate {
5437c478bd9Sstevel@tonic-gate 	struct mouse_state *state;
5447c478bd9Sstevel@tonic-gate 	minor_t	minor;
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	state = (struct mouse_state *)q->q_ptr;
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
5497c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
5507c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_close:entered\n");
5517c478bd9Sstevel@tonic-gate #endif
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	mutex_enter(&state->ms_mutex);
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	qprocsoff(q);
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 	q->q_ptr = NULL;
5587c478bd9Sstevel@tonic-gate 	WR(q)->q_ptr = NULL;
5597c478bd9Sstevel@tonic-gate 	state->ms_rqp = NULL;
5607c478bd9Sstevel@tonic-gate 	state->ms_wqp = NULL;
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	state->ms_opened = B_FALSE;
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	minor = state->ms_minor;
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	mutex_exit(&state->ms_mutex);
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	if (!MOUSE8042_INTERNAL_OPEN(minor)) {
5697c478bd9Sstevel@tonic-gate 		/*
5707c478bd9Sstevel@tonic-gate 		 * Closing physical PS/2 mouse
5717c478bd9Sstevel@tonic-gate 		 *
5727c478bd9Sstevel@tonic-gate 		 * Link it back to virtual mouse, and
5737c478bd9Sstevel@tonic-gate 		 * mouse8042_open will be called as a result
574fd9cb95cSsethg 		 * of the consconfig_link call.  Do NOT try
575fd9cb95cSsethg 		 * this if the mouse is about to be detached!
5767c478bd9Sstevel@tonic-gate 		 *
5777c478bd9Sstevel@tonic-gate 		 * If linking back fails, this specific mouse
5787c478bd9Sstevel@tonic-gate 		 * will not be available underneath the virtual
5797c478bd9Sstevel@tonic-gate 		 * mouse, and can only be accessed via physical
5807c478bd9Sstevel@tonic-gate 		 * open.
5817c478bd9Sstevel@tonic-gate 		 */
5827c478bd9Sstevel@tonic-gate 		consconfig_link(ddi_driver_major(mouse8042_dip),
5837c478bd9Sstevel@tonic-gate 		    MOUSE8042_INTERNAL_MINOR(minor));
5847c478bd9Sstevel@tonic-gate 	}
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	return (0);
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate static void
5907c478bd9Sstevel@tonic-gate mouse8042_iocnack(
5917c478bd9Sstevel@tonic-gate     queue_t *qp,
5927c478bd9Sstevel@tonic-gate     mblk_t *mp,
5937c478bd9Sstevel@tonic-gate     struct iocblk *iocp,
5947c478bd9Sstevel@tonic-gate     int error,
5957c478bd9Sstevel@tonic-gate     int rval)
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate 	mp->b_datap->db_type = M_IOCNAK;
5987c478bd9Sstevel@tonic-gate 	iocp->ioc_rval = rval;
5997c478bd9Sstevel@tonic-gate 	iocp->ioc_error = error;
6007c478bd9Sstevel@tonic-gate 	qreply(qp, mp);
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate static int
6047c478bd9Sstevel@tonic-gate mouse8042_wput(queue_t *q, mblk_t *mp)
6057c478bd9Sstevel@tonic-gate {
6067c478bd9Sstevel@tonic-gate 	struct iocblk *iocbp;
6077c478bd9Sstevel@tonic-gate 	mblk_t *bp;
6087c478bd9Sstevel@tonic-gate 	mblk_t *next;
6097c478bd9Sstevel@tonic-gate 	struct mouse_state *state;
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	state = (struct mouse_state *)q->q_ptr;
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
6147c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
6157c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_wput:entered\n");
6167c478bd9Sstevel@tonic-gate #endif
6177c478bd9Sstevel@tonic-gate 	iocbp = (struct iocblk *)mp->b_rptr;
6187c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
6197c478bd9Sstevel@tonic-gate 	case M_FLUSH:
6207c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
6217c478bd9Sstevel@tonic-gate 		if (mouse8042_debug)
6227c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT, "mouse8042_wput:M_FLUSH\n");
6237c478bd9Sstevel@tonic-gate #endif
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW)
6267c478bd9Sstevel@tonic-gate 			flushq(q, FLUSHDATA);
6277c478bd9Sstevel@tonic-gate 		qreply(q, mp);
6287c478bd9Sstevel@tonic-gate 		break;
6297c478bd9Sstevel@tonic-gate 	case M_IOCTL:
6307c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
6317c478bd9Sstevel@tonic-gate 		if (mouse8042_debug)
6327c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT, "mouse8042_wput:M_IOCTL\n");
6337c478bd9Sstevel@tonic-gate #endif
6347c478bd9Sstevel@tonic-gate 		mouse8042_iocnack(q, mp, iocbp, EINVAL, 0);
6357c478bd9Sstevel@tonic-gate 		break;
6367c478bd9Sstevel@tonic-gate 	case M_IOCDATA:
6377c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
6387c478bd9Sstevel@tonic-gate 		if (mouse8042_debug)
6397c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT, "mouse8042_wput:M_IOCDATA\n");
6407c478bd9Sstevel@tonic-gate #endif
6417c478bd9Sstevel@tonic-gate 		mouse8042_iocnack(q, mp, iocbp, EINVAL, 0);
6427c478bd9Sstevel@tonic-gate 		break;
6437c478bd9Sstevel@tonic-gate 	case M_DATA:
6447c478bd9Sstevel@tonic-gate 		bp = mp;
6457c478bd9Sstevel@tonic-gate 		do {
6467c478bd9Sstevel@tonic-gate 			while (bp->b_rptr < bp->b_wptr) {
6477c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
6487c478bd9Sstevel@tonic-gate 				if (mouse8042_debug) {
6497c478bd9Sstevel@tonic-gate 					cmn_err(CE_CONT,
6507c478bd9Sstevel@tonic-gate 					    "mouse8042:  send %2x\n",
6517c478bd9Sstevel@tonic-gate 					    *bp->b_rptr);
6527c478bd9Sstevel@tonic-gate 				}
6537c478bd9Sstevel@tonic-gate 				if (mouse8042_debug_minimal) {
6547c478bd9Sstevel@tonic-gate 					cmn_err(CE_CONT, ">a:%2x ",
6557c478bd9Sstevel@tonic-gate 					    *bp->b_rptr);
6567c478bd9Sstevel@tonic-gate 				}
6577c478bd9Sstevel@tonic-gate #endif
6587c478bd9Sstevel@tonic-gate 				ddi_put8(state->ms_handle,
6597c478bd9Sstevel@tonic-gate 				    state->ms_addr + I8042_INT_OUTPUT_DATA,
6607c478bd9Sstevel@tonic-gate 				    *bp->b_rptr++);
6617c478bd9Sstevel@tonic-gate 			}
6627c478bd9Sstevel@tonic-gate 			next = bp->b_cont;
6637c478bd9Sstevel@tonic-gate 			freeb(bp);
6647c478bd9Sstevel@tonic-gate 		} while ((bp = next) != NULL);
6657c478bd9Sstevel@tonic-gate 		break;
6667c478bd9Sstevel@tonic-gate 	default:
6677c478bd9Sstevel@tonic-gate 		freemsg(mp);
6687c478bd9Sstevel@tonic-gate 		break;
6697c478bd9Sstevel@tonic-gate 	}
6707c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
6717c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
6727c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_wput:leaving\n");
6737c478bd9Sstevel@tonic-gate #endif
6747c478bd9Sstevel@tonic-gate 	return (0);	/* ignored */
6757c478bd9Sstevel@tonic-gate }
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate static uint_t
6787c478bd9Sstevel@tonic-gate mouse8042_intr(caddr_t arg)
6797c478bd9Sstevel@tonic-gate {
6807c478bd9Sstevel@tonic-gate 	unsigned char    mdata;
6817c478bd9Sstevel@tonic-gate 	mblk_t *mp;
6827c478bd9Sstevel@tonic-gate 	struct mouse_state *state = (struct mouse_state *)arg;
6837c478bd9Sstevel@tonic-gate 	int rc;
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	mutex_enter(&state->ms_mutex);
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
6887c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
6897c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_intr()\n");
6907c478bd9Sstevel@tonic-gate #endif
6917c478bd9Sstevel@tonic-gate 	rc = DDI_INTR_UNCLAIMED;
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 	for (;;) {
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 		if (ddi_get8(state->ms_handle,
6967c478bd9Sstevel@tonic-gate 		    state->ms_addr + I8042_INT_INPUT_AVAIL) == 0) {
6977c478bd9Sstevel@tonic-gate 			break;
6987c478bd9Sstevel@tonic-gate 		}
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 		mdata = ddi_get8(state->ms_handle,
7017c478bd9Sstevel@tonic-gate 		    state->ms_addr + I8042_INT_INPUT_DATA);
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate #if	defined(MOUSE8042_DEBUG)
7047c478bd9Sstevel@tonic-gate 		if (mouse8042_debug)
7057c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT, "mouse8042_intr:  got %2x\n", mdata);
7067c478bd9Sstevel@tonic-gate 		if (mouse8042_debug_minimal)
7077c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT, "<A:%2x ", mdata);
7087c478bd9Sstevel@tonic-gate #endif
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate 		rc = DDI_INTR_CLAIMED;
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 		if (state->ms_rqp != NULL && (mp = allocb(1, BPRI_MED))) {
7137c478bd9Sstevel@tonic-gate 			*mp->b_wptr++ = mdata;
7147c478bd9Sstevel@tonic-gate 			putnext(state->ms_rqp, mp);
7157c478bd9Sstevel@tonic-gate 		}
7167c478bd9Sstevel@tonic-gate 	}
7177c478bd9Sstevel@tonic-gate #ifdef MOUSE8042_DEBUG
7187c478bd9Sstevel@tonic-gate 	if (mouse8042_debug)
7197c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "mouse8042_intr() ok\n");
7207c478bd9Sstevel@tonic-gate #endif
7217c478bd9Sstevel@tonic-gate 	mutex_exit(&state->ms_mutex);
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	return (rc);
7247c478bd9Sstevel@tonic-gate }
725