xref: /illumos-gate/usr/src/uts/sun4v/io/vnex.c (revision a3282898e99eb4fd1912bf791254452bfd913d4b)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4 5.0 */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
317c478bd9Sstevel@tonic-gate #include <sys/conf.h>
327c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
337c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
387c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
397c478bd9Sstevel@tonic-gate #include <sys/nexusintr_impl.h>
407c478bd9Sstevel@tonic-gate #include <sys/promif.h>
417c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
427c478bd9Sstevel@tonic-gate #include <sys/ddi_intr_impl.h>
437c478bd9Sstevel@tonic-gate #include <sys/hypervisor_api.h>
447c478bd9Sstevel@tonic-gate #include <sys/intr.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	SUN4V_REG_SPEC2CFG_HDL(x)	((x >> 32) & ~(0xfull << 28))
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate static kmutex_t vnex_id_lock;
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Vnex name  to pil map
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate typedef struct vnex_regspec {
537c478bd9Sstevel@tonic-gate 	uint64_t physaddr;
547c478bd9Sstevel@tonic-gate 	uint64_t size;
557c478bd9Sstevel@tonic-gate } vnex_regspec_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate struct vnex_pil_map {
587c478bd9Sstevel@tonic-gate 	caddr_t	name;
597c478bd9Sstevel@tonic-gate 	uint32_t pil;
607c478bd9Sstevel@tonic-gate };
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /* vnex interrupt descriptor */
637c478bd9Sstevel@tonic-gate typedef struct vnex_id {
647c478bd9Sstevel@tonic-gate 	dev_info_t *vid_dip;
657c478bd9Sstevel@tonic-gate 	uint32_t vid_ino;
667c478bd9Sstevel@tonic-gate 	uint64_t vid_ihdl;
677c478bd9Sstevel@tonic-gate 	uint_t	(*vid_handler)();
687c478bd9Sstevel@tonic-gate 	caddr_t	vid_arg1;
697c478bd9Sstevel@tonic-gate 	caddr_t	vid_arg2;
707c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t *vid_ddi_hdlp;
717c478bd9Sstevel@tonic-gate 	uint64_t vid_cfg_hdl;
727c478bd9Sstevel@tonic-gate 	struct vnex_id *vid_next;
737c478bd9Sstevel@tonic-gate 	struct vnex_id *vid_prev;
747c478bd9Sstevel@tonic-gate } vnex_id_t;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /* vnex interrupt descriptor list */
777c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_id_list;
787c478bd9Sstevel@tonic-gate 
79f3307d20Sarao hrtime_t vnex_pending_timeout = 2ull * NANOSEC; /* 2 seconds in nanoseconds */
80f3307d20Sarao 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * vnex interrupt descriptor list manipulation functions
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_locate_id(dev_info_t *dip, uint32_t ino);
867c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_alloc_id(dev_info_t *dip, uint32_t ino,
877c478bd9Sstevel@tonic-gate 	uint64_t dhdl);
887c478bd9Sstevel@tonic-gate static void vnex_add_id(vnex_id_t *vid_p);
897c478bd9Sstevel@tonic-gate static void vnex_rem_id(vnex_id_t *vid_p);
907c478bd9Sstevel@tonic-gate static void vnex_free_id(vnex_id_t *vid_p);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate uint_t vnex_intr_wrapper(caddr_t arg);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate static struct vnex_pil_map vnex_name_to_pil[] = {
957c478bd9Sstevel@tonic-gate 	{"console", 	PIL_12},
967c478bd9Sstevel@tonic-gate 	{"fma",		PIL_5},
977c478bd9Sstevel@tonic-gate 	{"echo", 	PIL_3},
987c478bd9Sstevel@tonic-gate 	{"loop", 	PIL_3},
997c478bd9Sstevel@tonic-gate 	{"sunmc", 	PIL_3},
1007c478bd9Sstevel@tonic-gate 	{"sunvts", 	PIL_3},
1017c478bd9Sstevel@tonic-gate 	{"explorer", 	PIL_3}
1027c478bd9Sstevel@tonic-gate };
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	VNEX_MAX_DEVS	(sizeof (vnex_name_to_pil) /	\
1057c478bd9Sstevel@tonic-gate 			    sizeof (struct vnex_pil_map))
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Config information
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate static int vnex_intr_ops(dev_info_t *dip, dev_info_t *rdip,
1117c478bd9Sstevel@tonic-gate     ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate static int
1147c478bd9Sstevel@tonic-gate vnex_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate static struct bus_ops vnex_bus_ops = {
1177c478bd9Sstevel@tonic-gate 	BUSO_REV,
1187c478bd9Sstevel@tonic-gate 	nullbusmap,
1197c478bd9Sstevel@tonic-gate 	NULL,	/* NO OP */
1207c478bd9Sstevel@tonic-gate 	NULL,	/* NO OP */
1217c478bd9Sstevel@tonic-gate 	NULL,	/* NO OP */
1227c478bd9Sstevel@tonic-gate 	i_ddi_map_fault,
1237c478bd9Sstevel@tonic-gate 	ddi_no_dma_map,
1247c478bd9Sstevel@tonic-gate 	ddi_no_dma_allochdl,
1257c478bd9Sstevel@tonic-gate 	NULL,
1267c478bd9Sstevel@tonic-gate 	NULL,
1277c478bd9Sstevel@tonic-gate 	NULL,
1287c478bd9Sstevel@tonic-gate 	NULL,
1297c478bd9Sstevel@tonic-gate 	NULL,
1307c478bd9Sstevel@tonic-gate 	NULL,
1317c478bd9Sstevel@tonic-gate 	vnex_ctl,
1327c478bd9Sstevel@tonic-gate 	ddi_bus_prop_op,
1337c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_get_eventcookie)();    */
1347c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_add_eventcall)();	*/
1357c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_remove_eventcall)();   */
1367c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_post_event)();		*/
1377c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_intr_ctl)();		*/
1387c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_config)();		*/
1397c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_unconfig)();		*/
1407c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_init)();		*/
1417c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_fini)();		*/
1427c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_access_enter)();	*/
1437c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_access_fini)();	*/
1447c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_power)();		*/
1457c478bd9Sstevel@tonic-gate 	vnex_intr_ops	/* (*bus_intr_op)();	*/
1467c478bd9Sstevel@tonic-gate };
1477c478bd9Sstevel@tonic-gate 
148f3307d20Sarao static int vnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
149f3307d20Sarao static int vnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate static struct dev_ops pseudo_ops = {
1527c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
1537c478bd9Sstevel@tonic-gate 	0,			/* refcnt  */
1547c478bd9Sstevel@tonic-gate 	ddi_no_info,		/* info */
1557c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
1567c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
1577c478bd9Sstevel@tonic-gate 	vnex_attach,		/* attach */
1587c478bd9Sstevel@tonic-gate 	vnex_detach,		/* detach */
1597c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
1607c478bd9Sstevel@tonic-gate 	(struct cb_ops *)0,	/* driver operations */
1617c478bd9Sstevel@tonic-gate 	&vnex_bus_ops,	/* bus operations */
1627c478bd9Sstevel@tonic-gate 	nulldev			/* power */
1637c478bd9Sstevel@tonic-gate };
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
1707c478bd9Sstevel@tonic-gate 	&mod_driverops, /* Type of module.  This one is a pseudo driver */
1717c478bd9Sstevel@tonic-gate 	"sun4v virtual-devices nexus driver v%I%",
1727c478bd9Sstevel@tonic-gate 	&pseudo_ops,	/* driver ops */
1737c478bd9Sstevel@tonic-gate };
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1767c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
1777c478bd9Sstevel@tonic-gate };
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate int
1807c478bd9Sstevel@tonic-gate _init(void)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate int
1867c478bd9Sstevel@tonic-gate _fini(void)
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate int
1927c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*ARGSUSED*/
198f3307d20Sarao void
199f3307d20Sarao vnex_intr_dist(void *arg)
200f3307d20Sarao {
201f3307d20Sarao 	vnex_id_t *vid_p;
202f3307d20Sarao 	uint32_t cpuid;
203f3307d20Sarao 	int	intr_state;
204f3307d20Sarao 	hrtime_t start;
205f3307d20Sarao 
206f3307d20Sarao 	mutex_enter(&vnex_id_lock);
207f3307d20Sarao 
208f3307d20Sarao 	for (vid_p = vnex_id_list; vid_p != NULL;
209f3307d20Sarao 	    vid_p = vid_p->vid_next) {
210f3307d20Sarao 		/*
211f3307d20Sarao 		 * Don't do anything for disabled interrupts.
212f3307d20Sarao 		 * vnex_enable_intr takes care of redistributing interrupts.
213f3307d20Sarao 		 */
214f3307d20Sarao 		if ((hvio_intr_getvalid(vid_p->vid_ihdl,
215f3307d20Sarao 		    &intr_state) == H_EOK) && (intr_state == HV_INTR_NOTVALID))
216f3307d20Sarao 				continue;
217f3307d20Sarao 
218f3307d20Sarao 		cpuid = intr_dist_cpuid();
219f3307d20Sarao 
220f3307d20Sarao 		(void) hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_NOTVALID);
221f3307d20Sarao 		/*
222f3307d20Sarao 		 * Make a best effort to wait for pending interrupts to finish.
223f3307d20Sarao 		 * There is not much we can do if we timeout.
224f3307d20Sarao 		 */
225f3307d20Sarao 		start = gethrtime();
226f3307d20Sarao 		while (!panicstr &&
227f3307d20Sarao 		    (hvio_intr_getstate(vid_p->vid_ihdl, &intr_state) ==
228f3307d20Sarao 		    H_EOK) && (intr_state == HV_INTR_DELIVERED_STATE)) {
229f3307d20Sarao 			if (gethrtime() - start > vnex_pending_timeout) {
230f3307d20Sarao 				cmn_err(CE_WARN, "vnex_intr_dist: %s%d "
231f3307d20Sarao 				    "ino 0x%x pending: timedout\n",
232f3307d20Sarao 				    ddi_driver_name(vid_p->vid_dip),
233f3307d20Sarao 				    ddi_get_instance(vid_p->vid_dip),
234f3307d20Sarao 				    vid_p->vid_ino);
235f3307d20Sarao 				break;
236f3307d20Sarao 			}
237f3307d20Sarao 		}
238f3307d20Sarao 		(void) hvio_intr_settarget(vid_p->vid_ihdl, cpuid);
239f3307d20Sarao 		(void) hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_VALID);
240f3307d20Sarao 	}
241f3307d20Sarao 	mutex_exit(&vnex_id_lock);
242f3307d20Sarao }
243f3307d20Sarao 
2447c478bd9Sstevel@tonic-gate static int
245f3307d20Sarao vnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate 	switch (cmd) {
2487c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
2497c478bd9Sstevel@tonic-gate 		/*
2507c478bd9Sstevel@tonic-gate 		 * Intitialize interrupt descriptor list
2517c478bd9Sstevel@tonic-gate 		 * and mutex.
2527c478bd9Sstevel@tonic-gate 		 */
2537c478bd9Sstevel@tonic-gate 		vnex_id_list = NULL;
2547c478bd9Sstevel@tonic-gate 		mutex_init(&vnex_id_lock, NULL, MUTEX_DRIVER, NULL);
255f3307d20Sarao 		/*
256f3307d20Sarao 		 * Add interrupt redistribution callback.
257f3307d20Sarao 		 */
258f3307d20Sarao 		intr_dist_add(vnex_intr_dist, dip);
2597c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
2627c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	default:
2657c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2707c478bd9Sstevel@tonic-gate static int
271f3307d20Sarao vnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate 	switch (cmd) {
2747c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
2757c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
2787c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	default:
2817c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2827c478bd9Sstevel@tonic-gate 	}
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate static int
2867c478bd9Sstevel@tonic-gate vnex_ctl(dev_info_t *dip, dev_info_t *rdip,
2877c478bd9Sstevel@tonic-gate 	ddi_ctl_enum_t ctlop, void *arg, void *result)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate 	char	name[12];	/* enough for a decimal integer */
2907c478bd9Sstevel@tonic-gate 	int		reglen;
2917c478bd9Sstevel@tonic-gate 	uint32_t	*vnex_regspec;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	switch (ctlop) {
2947c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
2957c478bd9Sstevel@tonic-gate 		if (rdip == NULL)
2967c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
2977c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "?virtual-device: %s%d\n",
2987c478bd9Sstevel@tonic-gate 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
2997c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
3027c478bd9Sstevel@tonic-gate 	{
3037c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
3047c478bd9Sstevel@tonic-gate 
305*a3282898Scth 		if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
3067c478bd9Sstevel@tonic-gate 		    "reg", (caddr_t)&vnex_regspec, &reglen) != DDI_SUCCESS)
3077c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 		(void) sprintf(name, "%x", *vnex_regspec);
3107c478bd9Sstevel@tonic-gate 		ddi_set_name_addr(child, name);
3117c478bd9Sstevel@tonic-gate 		ddi_set_parent_data(child, NULL);
3127c478bd9Sstevel@tonic-gate 		kmem_free((caddr_t)vnex_regspec, reglen);
3137c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
3187c478bd9Sstevel@tonic-gate 	{
3197c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 		ddi_set_name_addr(child, NULL);
3227c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(arg, NULL);
3237c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	/*
3277c478bd9Sstevel@tonic-gate 	 * These ops correspond to functions that "shouldn't" be called
3287c478bd9Sstevel@tonic-gate 	 * by a pseudo driver.  So we whinge when we're called.
3297c478bd9Sstevel@tonic-gate 	 */
3307c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DMAPMAPC:
3317c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTINT:
3327c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
3337c478bd9Sstevel@tonic-gate 	{
3347c478bd9Sstevel@tonic-gate 		*((off_t *)result) = 0;
3357c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
3387c478bd9Sstevel@tonic-gate 	{
3397c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
340*a3282898Scth 		if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
3417c478bd9Sstevel@tonic-gate 		    "reg", (caddr_t)&vnex_regspec, &reglen) != DDI_SUCCESS)
3427c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3437c478bd9Sstevel@tonic-gate 		*((uint_t *)result) = reglen / sizeof (uint32_t);
3447c478bd9Sstevel@tonic-gate 		kmem_free((caddr_t)vnex_regspec, reglen);
3457c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3467c478bd9Sstevel@tonic-gate 	}
3477c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_NINTRS:
3487c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
3497c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SLAVEONLY:
3507c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_AFFINITY:
3517c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_IOMIN:
3527c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_POKE:
3537c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_PEEK:
3547c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_INTR_HILEVEL:
3557c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_XLATE_INTRS:
3567c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n",
3577c478bd9Sstevel@tonic-gate 			ddi_get_name(dip), ddi_get_instance(dip),
3587c478bd9Sstevel@tonic-gate 			ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
3597c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	/*
3627c478bd9Sstevel@tonic-gate 	 * Everything else (e.g. PTOB/BTOP/BTOPR requests) we pass up
3637c478bd9Sstevel@tonic-gate 	 */
3647c478bd9Sstevel@tonic-gate 	default:
3657c478bd9Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
3667c478bd9Sstevel@tonic-gate 	}
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate static int
3707c478bd9Sstevel@tonic-gate vnex_get_pil(dev_info_t *rdip)
3717c478bd9Sstevel@tonic-gate {
3727c478bd9Sstevel@tonic-gate 	int i;
3737c478bd9Sstevel@tonic-gate 	caddr_t	name;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	name = ddi_node_name(rdip);
3767c478bd9Sstevel@tonic-gate 	for (i = 0; i < VNEX_MAX_DEVS; i++) {
3777c478bd9Sstevel@tonic-gate 		if (strcmp(vnex_name_to_pil[i].name,
3787c478bd9Sstevel@tonic-gate 		    name) == 0) {
3797c478bd9Sstevel@tonic-gate 			return (vnex_name_to_pil[i].pil);
3807c478bd9Sstevel@tonic-gate 		}
3817c478bd9Sstevel@tonic-gate 	}
3827c478bd9Sstevel@tonic-gate 	/*
3837c478bd9Sstevel@tonic-gate 	 * if not found pil is 0
3847c478bd9Sstevel@tonic-gate 	 */
3857c478bd9Sstevel@tonic-gate 	return (0);
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate static int
3897c478bd9Sstevel@tonic-gate vnex_enable_intr(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
3927c478bd9Sstevel@tonic-gate 	uint32_t cpuid;
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	vid_p = vnex_locate_id(rdip, hdlp->ih_vector);
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	ASSERT(vid_p != NULL);
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	cpuid = intr_dist_cpuid();
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	if ((hvio_intr_settarget(vid_p->vid_ihdl, cpuid)) != H_EOK) {
4017c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4027c478bd9Sstevel@tonic-gate 	}
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	if (hvio_intr_setstate(vid_p->vid_ihdl, HV_INTR_IDLE_STATE) != H_EOK) {
4057c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4067c478bd9Sstevel@tonic-gate 	}
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	if ((hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_VALID)) != H_EOK) {
4097c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4107c478bd9Sstevel@tonic-gate 	}
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate static int
4167c478bd9Sstevel@tonic-gate vnex_disable_intr(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
4177c478bd9Sstevel@tonic-gate {
4187c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	vid_p = vnex_locate_id(rdip, hdlp->ih_vector);
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	ASSERT(vid_p != NULL);
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	if (hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_NOTVALID) != H_EOK) {
4257c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4267c478bd9Sstevel@tonic-gate 	}
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate static int
4327c478bd9Sstevel@tonic-gate vnex_add_intr(dev_info_t *dip, dev_info_t *rdip,
4337c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
4347c478bd9Sstevel@tonic-gate {
4357c478bd9Sstevel@tonic-gate 	int reglen, ret = DDI_SUCCESS;
4367c478bd9Sstevel@tonic-gate 	vnex_id_t	*vid_p;
4377c478bd9Sstevel@tonic-gate 	uint64_t cfg;
4387c478bd9Sstevel@tonic-gate 	uint32_t ino;
4397c478bd9Sstevel@tonic-gate 	uint64_t ihdl;
4407c478bd9Sstevel@tonic-gate 	vnex_regspec_t *reg_p;
4417c478bd9Sstevel@tonic-gate 
442*a3282898Scth 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip,
4437c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "reg", (caddr_t)&reg_p,
4447c478bd9Sstevel@tonic-gate 	    &reglen) != DDI_SUCCESS) {
4457c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4467c478bd9Sstevel@tonic-gate 	}
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	/*
4497c478bd9Sstevel@tonic-gate 	 * get the sun4v config handle for this device
4507c478bd9Sstevel@tonic-gate 	 */
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	cfg = SUN4V_REG_SPEC2CFG_HDL(reg_p->physaddr);
453ea841a36Sarao 	kmem_free(reg_p, reglen);
4547c478bd9Sstevel@tonic-gate 	ino = hdlp->ih_vector;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	/*
4577c478bd9Sstevel@tonic-gate 	 * call hv to get vihdl
4587c478bd9Sstevel@tonic-gate 	 */
4597c478bd9Sstevel@tonic-gate 	if (hvio_intr_devino_to_sysino(cfg, ino, &ihdl) != H_EOK)
4607c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	hdlp->ih_vector = ihdl;
4637c478bd9Sstevel@tonic-gate 	/*
4647c478bd9Sstevel@tonic-gate 	 * Allocate a interrupt descriptor (id) with the
4657c478bd9Sstevel@tonic-gate 	 * the interrupt handler and append it to
4667c478bd9Sstevel@tonic-gate 	 * the id list.
4677c478bd9Sstevel@tonic-gate 	 */
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	vid_p = vnex_alloc_id(rdip, ino, cfg);
4707c478bd9Sstevel@tonic-gate 	vid_p->vid_ihdl = ihdl;
4717c478bd9Sstevel@tonic-gate 	vid_p->vid_handler =  hdlp->ih_cb_func;
4727c478bd9Sstevel@tonic-gate 	vid_p->vid_arg1 =  hdlp->ih_cb_arg1;
4737c478bd9Sstevel@tonic-gate 	vid_p->vid_arg2 =  hdlp->ih_cb_arg2;
4747c478bd9Sstevel@tonic-gate 	vid_p->vid_ddi_hdlp =  hdlp;
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp,
4777c478bd9Sstevel@tonic-gate 	    (ddi_intr_handler_t *)vnex_intr_wrapper, (caddr_t)vid_p, NULL);
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	if (hdlp->ih_pri == 0) {
4807c478bd9Sstevel@tonic-gate 		hdlp->ih_pri = vnex_get_pil(rdip);
4817c478bd9Sstevel@tonic-gate 	}
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 	ret = i_ddi_add_ivintr(hdlp);
4847c478bd9Sstevel@tonic-gate 	if (ret != DDI_SUCCESS) {
4857c478bd9Sstevel@tonic-gate 		return (ret);
4867c478bd9Sstevel@tonic-gate 	}
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, vid_p->vid_handler,
4897c478bd9Sstevel@tonic-gate 	    vid_p->vid_arg1, vid_p->vid_arg2);
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	return (ret);
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate static int
4957c478bd9Sstevel@tonic-gate vnex_remove_intr(dev_info_t *rdip,
4967c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t *hdlp)
4977c478bd9Sstevel@tonic-gate {
4987c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
4997c478bd9Sstevel@tonic-gate 	uint32_t ino;
5007c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	ino = hdlp->ih_vector;
5037c478bd9Sstevel@tonic-gate 	vid_p = vnex_locate_id(rdip, ino);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	hdlp->ih_vector = vid_p->vid_ihdl;
5067c478bd9Sstevel@tonic-gate 	i_ddi_rem_ivintr(hdlp);
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	vnex_free_id(vid_p);
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	return (ret);
5117c478bd9Sstevel@tonic-gate }
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate static int
5147c478bd9Sstevel@tonic-gate vnex_intr_ops(dev_info_t *dip, dev_info_t *rdip,
5157c478bd9Sstevel@tonic-gate     ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result)
5167c478bd9Sstevel@tonic-gate {
5177c478bd9Sstevel@tonic-gate 	ddi_ispec_t *ispecp = (ddi_ispec_t *)hdlp->ih_private;
5187c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	switch (intr_op) {
5217c478bd9Sstevel@tonic-gate 		case DDI_INTROP_GETCAP:
5227c478bd9Sstevel@tonic-gate 			*(int *)result = 0;
5237c478bd9Sstevel@tonic-gate 			break;
5247c478bd9Sstevel@tonic-gate 		case DDI_INTROP_ALLOC:
5257c478bd9Sstevel@tonic-gate 			*(int *)result = hdlp->ih_scratch1;
5267c478bd9Sstevel@tonic-gate 			break;
5277c478bd9Sstevel@tonic-gate 		case DDI_INTROP_GETPRI:
5287c478bd9Sstevel@tonic-gate 			*(int *)result = ispecp->is_pil ?
5297c478bd9Sstevel@tonic-gate 			    ispecp->is_pil : vnex_get_pil(rdip);
5307c478bd9Sstevel@tonic-gate 			break;
5317c478bd9Sstevel@tonic-gate 		case DDI_INTROP_FREE:
5327c478bd9Sstevel@tonic-gate 			break;
5337c478bd9Sstevel@tonic-gate 		case DDI_INTROP_SETPRI:
5347c478bd9Sstevel@tonic-gate 			ispecp->is_pil = (*(int *)result);
5357c478bd9Sstevel@tonic-gate 			break;
5367c478bd9Sstevel@tonic-gate 		case DDI_INTROP_ADDISR:
5377c478bd9Sstevel@tonic-gate 			hdlp->ih_vector = *ispecp->is_intr;
5387c478bd9Sstevel@tonic-gate 			ret = vnex_add_intr(dip, rdip, hdlp);
5397c478bd9Sstevel@tonic-gate 			break;
5407c478bd9Sstevel@tonic-gate 		case DDI_INTROP_REMISR:
5417c478bd9Sstevel@tonic-gate 			hdlp->ih_vector = *ispecp->is_intr;
5427c478bd9Sstevel@tonic-gate 			ret = vnex_remove_intr(rdip, hdlp);
5437c478bd9Sstevel@tonic-gate 			break;
5447c478bd9Sstevel@tonic-gate 		case DDI_INTROP_ENABLE:
5457c478bd9Sstevel@tonic-gate 			hdlp->ih_vector = *ispecp->is_intr;
5467c478bd9Sstevel@tonic-gate 			ret = vnex_enable_intr(rdip, hdlp);
5477c478bd9Sstevel@tonic-gate 			break;
5487c478bd9Sstevel@tonic-gate 		case DDI_INTROP_DISABLE:
5497c478bd9Sstevel@tonic-gate 			hdlp->ih_vector = *ispecp->is_intr;
5507c478bd9Sstevel@tonic-gate 			ret = vnex_disable_intr(rdip, hdlp);
5517c478bd9Sstevel@tonic-gate 			break;
5527c478bd9Sstevel@tonic-gate 		case DDI_INTROP_NINTRS:
5537c478bd9Sstevel@tonic-gate 		case DDI_INTROP_NAVAIL:
5547c478bd9Sstevel@tonic-gate 			*(int *)result = i_ddi_get_nintrs(rdip);
5557c478bd9Sstevel@tonic-gate 			break;
5567c478bd9Sstevel@tonic-gate 		case DDI_INTROP_SUPPORTED_TYPES:
5577c478bd9Sstevel@tonic-gate 			*(int *)result = i_ddi_get_nintrs(rdip) ?
5587c478bd9Sstevel@tonic-gate 			    DDI_INTR_TYPE_FIXED : 0;
5597c478bd9Sstevel@tonic-gate 			break;
5607c478bd9Sstevel@tonic-gate 		default:
5617c478bd9Sstevel@tonic-gate 			ret = DDI_ENOTSUP;
5627c478bd9Sstevel@tonic-gate 			break;
5637c478bd9Sstevel@tonic-gate 	}
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	return (ret);
5667c478bd9Sstevel@tonic-gate }
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate vnex_id_t *
5697c478bd9Sstevel@tonic-gate vnex_alloc_id(dev_info_t *dip, uint32_t ino, uint64_t dhdl)
5707c478bd9Sstevel@tonic-gate {
5717c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p = kmem_alloc(sizeof (vnex_id_t), KM_SLEEP);
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	vid_p->vid_dip = dip;
5747c478bd9Sstevel@tonic-gate 	vid_p->vid_ino = ino;
5757c478bd9Sstevel@tonic-gate 	vid_p->vid_cfg_hdl = dhdl;
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	mutex_enter(&vnex_id_lock);
5787c478bd9Sstevel@tonic-gate 	vnex_add_id(vid_p);
5797c478bd9Sstevel@tonic-gate 	mutex_exit(&vnex_id_lock);
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	return (vid_p);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate vnex_id_t *
5857c478bd9Sstevel@tonic-gate vnex_locate_id(dev_info_t *dip, uint32_t ino)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 	mutex_enter(&vnex_id_lock);
5907c478bd9Sstevel@tonic-gate 	vid_p = vnex_id_list;
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	while (vid_p != NULL) {
5937c478bd9Sstevel@tonic-gate 		if (vid_p->vid_dip == dip && vid_p->vid_ino == ino) {
5947c478bd9Sstevel@tonic-gate 			mutex_exit(&vnex_id_lock);
5957c478bd9Sstevel@tonic-gate 			return (vid_p);
5967c478bd9Sstevel@tonic-gate 		}
5977c478bd9Sstevel@tonic-gate 		vid_p = vid_p->vid_next;
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate 	mutex_exit(&vnex_id_lock);
6007c478bd9Sstevel@tonic-gate 	return (NULL);
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate static void
6047c478bd9Sstevel@tonic-gate vnex_free_id(vnex_id_t *vid_p)
6057c478bd9Sstevel@tonic-gate {
6067c478bd9Sstevel@tonic-gate 	mutex_enter(&vnex_id_lock);
6077c478bd9Sstevel@tonic-gate 	vnex_rem_id(vid_p);
6087c478bd9Sstevel@tonic-gate 	mutex_exit(&vnex_id_lock);
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 	kmem_free(vid_p, sizeof (*vid_p));
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate static void
6147c478bd9Sstevel@tonic-gate vnex_rem_id(vnex_id_t *vid_p)
6157c478bd9Sstevel@tonic-gate {
6167c478bd9Sstevel@tonic-gate 	if (vid_p->vid_prev == NULL) {
6177c478bd9Sstevel@tonic-gate 		vnex_id_list = vid_p->vid_next;
6187c478bd9Sstevel@tonic-gate 		vid_p->vid_prev = NULL;
6197c478bd9Sstevel@tonic-gate 	} else if (vid_p->vid_next == NULL) {
6207c478bd9Sstevel@tonic-gate 		vid_p->vid_prev->vid_next = NULL;
6217c478bd9Sstevel@tonic-gate 	} else {
6227c478bd9Sstevel@tonic-gate 		vid_p->vid_prev->vid_next = vid_p->vid_next;
6237c478bd9Sstevel@tonic-gate 		vid_p->vid_next->vid_prev = vid_p->vid_prev;
6247c478bd9Sstevel@tonic-gate 	}
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate static void
6287c478bd9Sstevel@tonic-gate vnex_add_id(vnex_id_t *vid_p)
6297c478bd9Sstevel@tonic-gate {
6307c478bd9Sstevel@tonic-gate 	if (vnex_id_list == NULL) {
6317c478bd9Sstevel@tonic-gate 		vnex_id_list = vid_p;
6327c478bd9Sstevel@tonic-gate 		vid_p->vid_next = NULL;
6337c478bd9Sstevel@tonic-gate 		vid_p->vid_prev = NULL;
6347c478bd9Sstevel@tonic-gate 		return;
6357c478bd9Sstevel@tonic-gate 	}
6367c478bd9Sstevel@tonic-gate 	/*
6377c478bd9Sstevel@tonic-gate 	 * We always just add to the front of the list
6387c478bd9Sstevel@tonic-gate 	 */
6397c478bd9Sstevel@tonic-gate 	vnex_id_list->vid_prev = vid_p;
6407c478bd9Sstevel@tonic-gate 	vid_p->vid_next = vnex_id_list;
6417c478bd9Sstevel@tonic-gate 	vid_p->vid_prev = NULL;
6427c478bd9Sstevel@tonic-gate 	vnex_id_list = vid_p;
6437c478bd9Sstevel@tonic-gate }
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate uint_t
6467c478bd9Sstevel@tonic-gate vnex_intr_wrapper(caddr_t arg)
6477c478bd9Sstevel@tonic-gate {
6487c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p = (vnex_id_t *)arg;
6497c478bd9Sstevel@tonic-gate 	int res;
6507c478bd9Sstevel@tonic-gate 	uint_t (*handler)();
6517c478bd9Sstevel@tonic-gate 	caddr_t handler_arg1;
6527c478bd9Sstevel@tonic-gate 	caddr_t handler_arg2;
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	handler = vid_p->vid_handler;
6557c478bd9Sstevel@tonic-gate 	handler_arg1 = vid_p->vid_arg1;
6567c478bd9Sstevel@tonic-gate 	handler_arg2 = vid_p->vid_arg2;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	res = (*handler)(handler_arg1, handler_arg2);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	(void) hvio_intr_setstate(vid_p->vid_ihdl, HV_INTR_IDLE_STATE);
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 	return (res);
6637c478bd9Sstevel@tonic-gate }
664