xref: /titanic_52/usr/src/uts/sun4v/io/vnex.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
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * 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 /*
22d9e939ddSkc28005  * Copyright 2008 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 #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
297c478bd9Sstevel@tonic-gate #include <sys/conf.h>
307c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
317c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
347c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
357c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
367c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
377c478bd9Sstevel@tonic-gate #include <sys/promif.h>
387c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
397c478bd9Sstevel@tonic-gate #include <sys/ddi_intr_impl.h>
407c478bd9Sstevel@tonic-gate #include <sys/hypervisor_api.h>
417c478bd9Sstevel@tonic-gate #include <sys/intr.h>
42d66f8315Sjb145095 #include <sys/hsvc.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #define	SUN4V_REG_SPEC2CFG_HDL(x)	((x >> 32) & ~(0xfull << 28))
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate static kmutex_t vnex_id_lock;
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Vnex name  to pil map
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate typedef struct vnex_regspec {
517c478bd9Sstevel@tonic-gate 	uint64_t physaddr;
527c478bd9Sstevel@tonic-gate 	uint64_t size;
537c478bd9Sstevel@tonic-gate } vnex_regspec_t;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate struct vnex_pil_map {
567c478bd9Sstevel@tonic-gate 	caddr_t	name;
577c478bd9Sstevel@tonic-gate 	uint32_t pil;
587c478bd9Sstevel@tonic-gate };
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* vnex interrupt descriptor */
617c478bd9Sstevel@tonic-gate typedef struct vnex_id {
627c478bd9Sstevel@tonic-gate 	dev_info_t *vid_dip;
637c478bd9Sstevel@tonic-gate 	uint32_t vid_ino;
647c478bd9Sstevel@tonic-gate 	uint64_t vid_ihdl;
657c478bd9Sstevel@tonic-gate 	uint_t	(*vid_handler)();
667c478bd9Sstevel@tonic-gate 	caddr_t	vid_arg1;
677c478bd9Sstevel@tonic-gate 	caddr_t	vid_arg2;
687c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t *vid_ddi_hdlp;
697c478bd9Sstevel@tonic-gate 	uint64_t vid_cfg_hdl;
707c478bd9Sstevel@tonic-gate 	struct vnex_id *vid_next;
717c478bd9Sstevel@tonic-gate } vnex_id_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /* vnex interrupt descriptor list */
747c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_id_list;
757c478bd9Sstevel@tonic-gate 
76f3307d20Sarao hrtime_t vnex_pending_timeout = 2ull * NANOSEC; /* 2 seconds in nanoseconds */
77f3307d20Sarao 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * vnex interrupt descriptor list manipulation functions
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_locate_id(dev_info_t *dip, uint32_t ino);
837c478bd9Sstevel@tonic-gate static vnex_id_t *vnex_alloc_id(dev_info_t *dip, uint32_t ino,
847c478bd9Sstevel@tonic-gate 	uint64_t dhdl);
857c478bd9Sstevel@tonic-gate static void vnex_add_id(vnex_id_t *vid_p);
867c478bd9Sstevel@tonic-gate static void vnex_rem_id(vnex_id_t *vid_p);
877c478bd9Sstevel@tonic-gate static void vnex_free_id(vnex_id_t *vid_p);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate uint_t vnex_intr_wrapper(caddr_t arg);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate static struct vnex_pil_map vnex_name_to_pil[] = {
927c478bd9Sstevel@tonic-gate 	{"console", 	PIL_12},
937c478bd9Sstevel@tonic-gate 	{"fma",		PIL_5},
947c478bd9Sstevel@tonic-gate 	{"echo", 	PIL_3},
957c478bd9Sstevel@tonic-gate 	{"loop", 	PIL_3},
967c478bd9Sstevel@tonic-gate 	{"sunmc", 	PIL_3},
977c478bd9Sstevel@tonic-gate 	{"sunvts", 	PIL_3},
981ae08745Sheppo 	{"explorer", 	PIL_3},
9944961713Sgirish 	{"ncp", 	PIL_8},
10044961713Sgirish 	{"crypto", 	PIL_8}
1017c478bd9Sstevel@tonic-gate };
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	VNEX_MAX_DEVS	(sizeof (vnex_name_to_pil) /	\
1047c478bd9Sstevel@tonic-gate 			    sizeof (struct vnex_pil_map))
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Config information
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate static int vnex_intr_ops(dev_info_t *dip, dev_info_t *rdip,
1107c478bd9Sstevel@tonic-gate     ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static int
1137c478bd9Sstevel@tonic-gate vnex_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate static struct bus_ops vnex_bus_ops = {
1167c478bd9Sstevel@tonic-gate 	BUSO_REV,
1177c478bd9Sstevel@tonic-gate 	nullbusmap,
1187c478bd9Sstevel@tonic-gate 	NULL,	/* NO OP */
1197c478bd9Sstevel@tonic-gate 	NULL,	/* NO OP */
1207c478bd9Sstevel@tonic-gate 	NULL,	/* NO OP */
1217c478bd9Sstevel@tonic-gate 	i_ddi_map_fault,
1227c478bd9Sstevel@tonic-gate 	ddi_no_dma_map,
1237c478bd9Sstevel@tonic-gate 	ddi_no_dma_allochdl,
1247c478bd9Sstevel@tonic-gate 	NULL,
1257c478bd9Sstevel@tonic-gate 	NULL,
1267c478bd9Sstevel@tonic-gate 	NULL,
1277c478bd9Sstevel@tonic-gate 	NULL,
1287c478bd9Sstevel@tonic-gate 	NULL,
1297c478bd9Sstevel@tonic-gate 	NULL,
1307c478bd9Sstevel@tonic-gate 	vnex_ctl,
1317c478bd9Sstevel@tonic-gate 	ddi_bus_prop_op,
1327c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_get_eventcookie)();    */
1337c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_add_eventcall)();	*/
1347c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_remove_eventcall)();   */
1357c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_post_event)();		*/
1367c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_intr_ctl)();		*/
1377c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_config)();		*/
1387c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_unconfig)();		*/
1397c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_init)();		*/
1407c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_fini)();		*/
1417c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_access_enter)();	*/
1427c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_fm_access_fini)();	*/
1437c478bd9Sstevel@tonic-gate 	NULL,	/* (*bus_power)();		*/
1447c478bd9Sstevel@tonic-gate 	vnex_intr_ops	/* (*bus_intr_op)();	*/
1457c478bd9Sstevel@tonic-gate };
1467c478bd9Sstevel@tonic-gate 
147f3307d20Sarao static int vnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
148f3307d20Sarao static int vnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate static struct dev_ops pseudo_ops = {
1517c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
1527c478bd9Sstevel@tonic-gate 	0,			/* refcnt  */
1537c478bd9Sstevel@tonic-gate 	ddi_no_info,		/* info */
1547c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
1557c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
1567c478bd9Sstevel@tonic-gate 	vnex_attach,		/* attach */
1577c478bd9Sstevel@tonic-gate 	vnex_detach,		/* detach */
1587c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
1597c478bd9Sstevel@tonic-gate 	(struct cb_ops *)0,	/* driver operations */
1607c478bd9Sstevel@tonic-gate 	&vnex_bus_ops,		/* bus operations */
161*19397407SSherry Moore 	nulldev,		/* power */
162*19397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
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 */
171*19397407SSherry Moore 	"sun4v virtual-devices nexus driver",
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 {
182d66f8315Sjb145095 	uint64_t mjrnum;
183d66f8315Sjb145095 	uint64_t mnrnum;
184d66f8315Sjb145095 
185d66f8315Sjb145095 	/*
186d66f8315Sjb145095 	 * Check HV intr group api versioning.
187d66f8315Sjb145095 	 * This driver uses the old interrupt routines which are supported
188d66f8315Sjb145095 	 * in old firmware in the CORE API group and in newer firmware in
189d66f8315Sjb145095 	 * the INTR API group.  Support for these calls will be dropped
190d66f8315Sjb145095 	 * once the INTR API group major goes to 2.
191d66f8315Sjb145095 	 */
192d66f8315Sjb145095 
193d66f8315Sjb145095 	if ((hsvc_version(HSVC_GROUP_INTR, &mjrnum, &mnrnum) == 0) &&
194d66f8315Sjb145095 	    (mjrnum > 1)) {
195d66f8315Sjb145095 		cmn_err(CE_WARN, "niumx: unsupported intr api group: "
196d66f8315Sjb145095 		    "maj:0x%lx, min:0x%lx", mjrnum, mnrnum);
197d66f8315Sjb145095 		return (ENOTSUP);
198d66f8315Sjb145095 	}
199d66f8315Sjb145095 
2007c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate int
2047c478bd9Sstevel@tonic-gate _fini(void)
2057c478bd9Sstevel@tonic-gate {
2067c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate int
2107c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2117c478bd9Sstevel@tonic-gate {
2127c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*ARGSUSED*/
216f3307d20Sarao void
217f3307d20Sarao vnex_intr_dist(void *arg)
218f3307d20Sarao {
219f3307d20Sarao 	vnex_id_t *vid_p;
220f3307d20Sarao 	uint32_t cpuid;
221f3307d20Sarao 	int	intr_state;
222f3307d20Sarao 	hrtime_t start;
223f3307d20Sarao 
224f3307d20Sarao 	mutex_enter(&vnex_id_lock);
225f3307d20Sarao 
226f3307d20Sarao 	for (vid_p = vnex_id_list; vid_p != NULL;
227f3307d20Sarao 	    vid_p = vid_p->vid_next) {
228f3307d20Sarao 		/*
229f3307d20Sarao 		 * Don't do anything for disabled interrupts.
230f3307d20Sarao 		 * vnex_enable_intr takes care of redistributing interrupts.
231f3307d20Sarao 		 */
232f3307d20Sarao 		if ((hvio_intr_getvalid(vid_p->vid_ihdl,
233f3307d20Sarao 		    &intr_state) == H_EOK) && (intr_state == HV_INTR_NOTVALID))
234f3307d20Sarao 				continue;
235f3307d20Sarao 
236f3307d20Sarao 		cpuid = intr_dist_cpuid();
237f3307d20Sarao 
238f3307d20Sarao 		(void) hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_NOTVALID);
239f3307d20Sarao 		/*
240f3307d20Sarao 		 * Make a best effort to wait for pending interrupts to finish.
241f3307d20Sarao 		 * There is not much we can do if we timeout.
242f3307d20Sarao 		 */
243f3307d20Sarao 		start = gethrtime();
244f3307d20Sarao 		while (!panicstr &&
245f3307d20Sarao 		    (hvio_intr_getstate(vid_p->vid_ihdl, &intr_state) ==
246f3307d20Sarao 		    H_EOK) && (intr_state == HV_INTR_DELIVERED_STATE)) {
247f3307d20Sarao 			if (gethrtime() - start > vnex_pending_timeout) {
248f3307d20Sarao 				cmn_err(CE_WARN, "vnex_intr_dist: %s%d "
249f3307d20Sarao 				    "ino 0x%x pending: timedout\n",
250f3307d20Sarao 				    ddi_driver_name(vid_p->vid_dip),
251f3307d20Sarao 				    ddi_get_instance(vid_p->vid_dip),
252f3307d20Sarao 				    vid_p->vid_ino);
253f3307d20Sarao 				break;
254f3307d20Sarao 			}
255f3307d20Sarao 		}
256f3307d20Sarao 		(void) hvio_intr_settarget(vid_p->vid_ihdl, cpuid);
257f3307d20Sarao 		(void) hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_VALID);
258f3307d20Sarao 	}
259f3307d20Sarao 	mutex_exit(&vnex_id_lock);
260f3307d20Sarao }
261f3307d20Sarao 
2627c478bd9Sstevel@tonic-gate static int
263f3307d20Sarao vnex_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2647c478bd9Sstevel@tonic-gate {
2657c478bd9Sstevel@tonic-gate 	switch (cmd) {
2667c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
2677c478bd9Sstevel@tonic-gate 		/*
2687c478bd9Sstevel@tonic-gate 		 * Intitialize interrupt descriptor list
2697c478bd9Sstevel@tonic-gate 		 * and mutex.
2707c478bd9Sstevel@tonic-gate 		 */
2717c478bd9Sstevel@tonic-gate 		vnex_id_list = NULL;
2727c478bd9Sstevel@tonic-gate 		mutex_init(&vnex_id_lock, NULL, MUTEX_DRIVER, NULL);
273f3307d20Sarao 		/*
274f3307d20Sarao 		 * Add interrupt redistribution callback.
275f3307d20Sarao 		 */
276f3307d20Sarao 		intr_dist_add(vnex_intr_dist, dip);
2777c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
2807c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	default:
2837c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2887c478bd9Sstevel@tonic-gate static int
289f3307d20Sarao vnex_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
2907c478bd9Sstevel@tonic-gate {
2917c478bd9Sstevel@tonic-gate 	switch (cmd) {
2927c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
2937c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
2967c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	default:
2997c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
3007c478bd9Sstevel@tonic-gate 	}
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate static int
3047c478bd9Sstevel@tonic-gate vnex_ctl(dev_info_t *dip, dev_info_t *rdip,
3057c478bd9Sstevel@tonic-gate 	ddi_ctl_enum_t ctlop, void *arg, void *result)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate 	char	name[12];	/* enough for a decimal integer */
3087c478bd9Sstevel@tonic-gate 	int		reglen;
3097c478bd9Sstevel@tonic-gate 	uint32_t	*vnex_regspec;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	switch (ctlop) {
3127c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
3137c478bd9Sstevel@tonic-gate 		if (rdip == NULL)
3147c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3157c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "?virtual-device: %s%d\n",
3167c478bd9Sstevel@tonic-gate 		    ddi_driver_name(rdip), ddi_get_instance(rdip));
3177c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
3207c478bd9Sstevel@tonic-gate 	{
3217c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
3227c478bd9Sstevel@tonic-gate 
323a3282898Scth 		if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
3247c478bd9Sstevel@tonic-gate 		    "reg", (caddr_t)&vnex_regspec, &reglen) != DDI_SUCCESS)
3257c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 		(void) sprintf(name, "%x", *vnex_regspec);
3287c478bd9Sstevel@tonic-gate 		ddi_set_name_addr(child, name);
3297c478bd9Sstevel@tonic-gate 		ddi_set_parent_data(child, NULL);
3307c478bd9Sstevel@tonic-gate 		kmem_free((caddr_t)vnex_regspec, reglen);
3317c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
3367c478bd9Sstevel@tonic-gate 	{
3377c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 		ddi_set_name_addr(child, NULL);
3407c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(arg, NULL);
3417c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3427c478bd9Sstevel@tonic-gate 	}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	/*
3457c478bd9Sstevel@tonic-gate 	 * These ops correspond to functions that "shouldn't" be called
3467c478bd9Sstevel@tonic-gate 	 * by a pseudo driver.  So we whinge when we're called.
3477c478bd9Sstevel@tonic-gate 	 */
3487c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DMAPMAPC:
3497c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTINT:
3507c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
3517c478bd9Sstevel@tonic-gate 	{
3527c478bd9Sstevel@tonic-gate 		*((off_t *)result) = 0;
3537c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3547c478bd9Sstevel@tonic-gate 	}
3557c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
3567c478bd9Sstevel@tonic-gate 	{
357d9e939ddSkc28005 		dev_info_t *child = rdip;
358a3282898Scth 		if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
3597c478bd9Sstevel@tonic-gate 		    "reg", (caddr_t)&vnex_regspec, &reglen) != DDI_SUCCESS)
3607c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3617c478bd9Sstevel@tonic-gate 		*((uint_t *)result) = reglen / sizeof (uint32_t);
3627c478bd9Sstevel@tonic-gate 		kmem_free((caddr_t)vnex_regspec, reglen);
3637c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
3667c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SLAVEONLY:
3677c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_AFFINITY:
3687c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_IOMIN:
3697c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_POKE:
3707c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_PEEK:
3717c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n",
3727c478bd9Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip),
3737c478bd9Sstevel@tonic-gate 		    ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
3747c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	/*
3777c478bd9Sstevel@tonic-gate 	 * Everything else (e.g. PTOB/BTOP/BTOPR requests) we pass up
3787c478bd9Sstevel@tonic-gate 	 */
3797c478bd9Sstevel@tonic-gate 	default:
3807c478bd9Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
3817c478bd9Sstevel@tonic-gate 	}
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate static int
3857c478bd9Sstevel@tonic-gate vnex_get_pil(dev_info_t *rdip)
3867c478bd9Sstevel@tonic-gate {
3877c478bd9Sstevel@tonic-gate 	int i;
3887c478bd9Sstevel@tonic-gate 	caddr_t	name;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 	name = ddi_node_name(rdip);
3917c478bd9Sstevel@tonic-gate 	for (i = 0; i < VNEX_MAX_DEVS; i++) {
3927c478bd9Sstevel@tonic-gate 		if (strcmp(vnex_name_to_pil[i].name,
3937c478bd9Sstevel@tonic-gate 		    name) == 0) {
3947c478bd9Sstevel@tonic-gate 			return (vnex_name_to_pil[i].pil);
3957c478bd9Sstevel@tonic-gate 		}
3967c478bd9Sstevel@tonic-gate 	}
3977c478bd9Sstevel@tonic-gate 	/*
3987c478bd9Sstevel@tonic-gate 	 * if not found pil is 0
3997c478bd9Sstevel@tonic-gate 	 */
4007c478bd9Sstevel@tonic-gate 	return (0);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate static int
4047c478bd9Sstevel@tonic-gate vnex_enable_intr(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
4057c478bd9Sstevel@tonic-gate {
4067c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
4077c478bd9Sstevel@tonic-gate 	uint32_t cpuid;
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	vid_p = vnex_locate_id(rdip, hdlp->ih_vector);
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 	ASSERT(vid_p != NULL);
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 	cpuid = intr_dist_cpuid();
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	if ((hvio_intr_settarget(vid_p->vid_ihdl, cpuid)) != H_EOK) {
4167c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4177c478bd9Sstevel@tonic-gate 	}
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	if (hvio_intr_setstate(vid_p->vid_ihdl, HV_INTR_IDLE_STATE) != H_EOK) {
4207c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4217c478bd9Sstevel@tonic-gate 	}
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	if ((hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_VALID)) != H_EOK) {
4247c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4257c478bd9Sstevel@tonic-gate 	}
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate static int
4317c478bd9Sstevel@tonic-gate vnex_disable_intr(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
4327c478bd9Sstevel@tonic-gate {
4337c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	vid_p = vnex_locate_id(rdip, hdlp->ih_vector);
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	ASSERT(vid_p != NULL);
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	if (hvio_intr_setvalid(vid_p->vid_ihdl, HV_INTR_NOTVALID) != H_EOK) {
4407c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4461ae08745Sheppo int
4471ae08745Sheppo vnex_ino_to_inum(dev_info_t *dip, uint32_t ino)
4481ae08745Sheppo {
4491ae08745Sheppo 	vnex_id_t		*vid_p;
4501ae08745Sheppo 	ddi_intr_handle_impl_t	*hdlp;
4511ae08745Sheppo 
4521ae08745Sheppo 	if ((vid_p = vnex_locate_id(dip, ino)) == NULL)
4531ae08745Sheppo 		return (-1);
4541ae08745Sheppo 	else if ((hdlp = vid_p->vid_ddi_hdlp) == NULL)
4551ae08745Sheppo 		return (-1);
4561ae08745Sheppo 	else
4571ae08745Sheppo 		return (hdlp->ih_inum);
4581ae08745Sheppo }
4591ae08745Sheppo 
4607c478bd9Sstevel@tonic-gate static int
4617c478bd9Sstevel@tonic-gate vnex_add_intr(dev_info_t *dip, dev_info_t *rdip,
4627c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp)
4637c478bd9Sstevel@tonic-gate {
4647c478bd9Sstevel@tonic-gate 	int reglen, ret = DDI_SUCCESS;
4657c478bd9Sstevel@tonic-gate 	vnex_id_t	*vid_p;
4667c478bd9Sstevel@tonic-gate 	uint64_t cfg;
4677c478bd9Sstevel@tonic-gate 	uint32_t ino;
4687c478bd9Sstevel@tonic-gate 	uint64_t ihdl;
4697c478bd9Sstevel@tonic-gate 	vnex_regspec_t *reg_p;
4707c478bd9Sstevel@tonic-gate 
471a3282898Scth 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip,
4727c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, "reg", (caddr_t)&reg_p,
4737c478bd9Sstevel@tonic-gate 	    &reglen) != DDI_SUCCESS) {
4747c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4757c478bd9Sstevel@tonic-gate 	}
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	/*
4787c478bd9Sstevel@tonic-gate 	 * get the sun4v config handle for this device
4797c478bd9Sstevel@tonic-gate 	 */
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	cfg = SUN4V_REG_SPEC2CFG_HDL(reg_p->physaddr);
482ea841a36Sarao 	kmem_free(reg_p, reglen);
4837c478bd9Sstevel@tonic-gate 	ino = hdlp->ih_vector;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	/*
4867c478bd9Sstevel@tonic-gate 	 * call hv to get vihdl
4877c478bd9Sstevel@tonic-gate 	 */
4887c478bd9Sstevel@tonic-gate 	if (hvio_intr_devino_to_sysino(cfg, ino, &ihdl) != H_EOK)
4897c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	hdlp->ih_vector = ihdl;
4927c478bd9Sstevel@tonic-gate 	/*
4937c478bd9Sstevel@tonic-gate 	 * Allocate a interrupt descriptor (id) with the
4947c478bd9Sstevel@tonic-gate 	 * the interrupt handler and append it to
4957c478bd9Sstevel@tonic-gate 	 * the id list.
4967c478bd9Sstevel@tonic-gate 	 */
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 	vid_p = vnex_alloc_id(rdip, ino, cfg);
4997c478bd9Sstevel@tonic-gate 	vid_p->vid_ihdl = ihdl;
5007c478bd9Sstevel@tonic-gate 	vid_p->vid_handler =  hdlp->ih_cb_func;
5017c478bd9Sstevel@tonic-gate 	vid_p->vid_arg1 =  hdlp->ih_cb_arg1;
5027c478bd9Sstevel@tonic-gate 	vid_p->vid_arg2 =  hdlp->ih_cb_arg2;
5037c478bd9Sstevel@tonic-gate 	vid_p->vid_ddi_hdlp =  hdlp;
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp,
5067c478bd9Sstevel@tonic-gate 	    (ddi_intr_handler_t *)vnex_intr_wrapper, (caddr_t)vid_p, NULL);
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	if (hdlp->ih_pri == 0) {
5097c478bd9Sstevel@tonic-gate 		hdlp->ih_pri = vnex_get_pil(rdip);
5107c478bd9Sstevel@tonic-gate 	}
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	ret = i_ddi_add_ivintr(hdlp);
5137c478bd9Sstevel@tonic-gate 	if (ret != DDI_SUCCESS) {
5147c478bd9Sstevel@tonic-gate 		return (ret);
5157c478bd9Sstevel@tonic-gate 	}
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, vid_p->vid_handler,
5187c478bd9Sstevel@tonic-gate 	    vid_p->vid_arg1, vid_p->vid_arg2);
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	return (ret);
5217c478bd9Sstevel@tonic-gate }
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate static int
5247c478bd9Sstevel@tonic-gate vnex_remove_intr(dev_info_t *rdip,
5257c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t *hdlp)
5267c478bd9Sstevel@tonic-gate {
5277c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
5287c478bd9Sstevel@tonic-gate 	uint32_t ino;
5297c478bd9Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	ino = hdlp->ih_vector;
5327c478bd9Sstevel@tonic-gate 	vid_p = vnex_locate_id(rdip, ino);
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	hdlp->ih_vector = vid_p->vid_ihdl;
5357c478bd9Sstevel@tonic-gate 	i_ddi_rem_ivintr(hdlp);
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	vnex_free_id(vid_p);
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	return (ret);
5407c478bd9Sstevel@tonic-gate }
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate static int
5437c478bd9Sstevel@tonic-gate vnex_intr_ops(dev_info_t *dip, dev_info_t *rdip,
5447c478bd9Sstevel@tonic-gate     ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result)
5457c478bd9Sstevel@tonic-gate {
5467c478bd9Sstevel@tonic-gate 	int	ret = DDI_SUCCESS;
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate 	switch (intr_op) {
5497c478bd9Sstevel@tonic-gate 		case DDI_INTROP_GETCAP:
550a195726fSgovinda 			*(int *)result = DDI_INTR_FLAG_LEVEL;
5517c478bd9Sstevel@tonic-gate 			break;
5527c478bd9Sstevel@tonic-gate 		case DDI_INTROP_ALLOC:
5537c478bd9Sstevel@tonic-gate 			*(int *)result = hdlp->ih_scratch1;
5547c478bd9Sstevel@tonic-gate 			break;
5557c478bd9Sstevel@tonic-gate 		case DDI_INTROP_GETPRI:
556a195726fSgovinda 			*(int *)result = hdlp->ih_pri ?
557a195726fSgovinda 			    hdlp->ih_pri : vnex_get_pil(rdip);
5587c478bd9Sstevel@tonic-gate 			break;
5597c478bd9Sstevel@tonic-gate 		case DDI_INTROP_FREE:
5607c478bd9Sstevel@tonic-gate 			break;
5617c478bd9Sstevel@tonic-gate 		case DDI_INTROP_SETPRI:
5627c478bd9Sstevel@tonic-gate 			break;
5637c478bd9Sstevel@tonic-gate 		case DDI_INTROP_ADDISR:
5647c478bd9Sstevel@tonic-gate 			ret = vnex_add_intr(dip, rdip, hdlp);
5657c478bd9Sstevel@tonic-gate 			break;
5667c478bd9Sstevel@tonic-gate 		case DDI_INTROP_REMISR:
5677c478bd9Sstevel@tonic-gate 			ret = vnex_remove_intr(rdip, hdlp);
5687c478bd9Sstevel@tonic-gate 			break;
5697c478bd9Sstevel@tonic-gate 		case DDI_INTROP_ENABLE:
5707c478bd9Sstevel@tonic-gate 			ret = vnex_enable_intr(rdip, hdlp);
5717c478bd9Sstevel@tonic-gate 			break;
5727c478bd9Sstevel@tonic-gate 		case DDI_INTROP_DISABLE:
5737c478bd9Sstevel@tonic-gate 			ret = vnex_disable_intr(rdip, hdlp);
5747c478bd9Sstevel@tonic-gate 			break;
5757c478bd9Sstevel@tonic-gate 		case DDI_INTROP_NINTRS:
5767c478bd9Sstevel@tonic-gate 		case DDI_INTROP_NAVAIL:
577a54f81fbSanish 			*(int *)result = i_ddi_get_intx_nintrs(rdip);
5787c478bd9Sstevel@tonic-gate 			break;
5797c478bd9Sstevel@tonic-gate 		case DDI_INTROP_SUPPORTED_TYPES:
580a54f81fbSanish 			*(int *)result = i_ddi_get_intx_nintrs(rdip) ?
5817c478bd9Sstevel@tonic-gate 			    DDI_INTR_TYPE_FIXED : 0;
5827c478bd9Sstevel@tonic-gate 			break;
5837c478bd9Sstevel@tonic-gate 		default:
5847c478bd9Sstevel@tonic-gate 			ret = DDI_ENOTSUP;
5857c478bd9Sstevel@tonic-gate 			break;
5867c478bd9Sstevel@tonic-gate 	}
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate 	return (ret);
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate vnex_id_t *
5927c478bd9Sstevel@tonic-gate vnex_alloc_id(dev_info_t *dip, uint32_t ino, uint64_t dhdl)
5937c478bd9Sstevel@tonic-gate {
5947c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p = kmem_alloc(sizeof (vnex_id_t), KM_SLEEP);
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	vid_p->vid_dip = dip;
5977c478bd9Sstevel@tonic-gate 	vid_p->vid_ino = ino;
5987c478bd9Sstevel@tonic-gate 	vid_p->vid_cfg_hdl = dhdl;
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	mutex_enter(&vnex_id_lock);
6017c478bd9Sstevel@tonic-gate 	vnex_add_id(vid_p);
6027c478bd9Sstevel@tonic-gate 	mutex_exit(&vnex_id_lock);
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 	return (vid_p);
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate vnex_id_t *
6087c478bd9Sstevel@tonic-gate vnex_locate_id(dev_info_t *dip, uint32_t ino)
6097c478bd9Sstevel@tonic-gate {
6107c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p;
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate 	mutex_enter(&vnex_id_lock);
6137c478bd9Sstevel@tonic-gate 	vid_p = vnex_id_list;
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	while (vid_p != NULL) {
6167c478bd9Sstevel@tonic-gate 		if (vid_p->vid_dip == dip && vid_p->vid_ino == ino) {
6177c478bd9Sstevel@tonic-gate 			mutex_exit(&vnex_id_lock);
6187c478bd9Sstevel@tonic-gate 			return (vid_p);
6197c478bd9Sstevel@tonic-gate 		}
6207c478bd9Sstevel@tonic-gate 		vid_p = vid_p->vid_next;
6217c478bd9Sstevel@tonic-gate 	}
6227c478bd9Sstevel@tonic-gate 	mutex_exit(&vnex_id_lock);
6237c478bd9Sstevel@tonic-gate 	return (NULL);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate static void
6277c478bd9Sstevel@tonic-gate vnex_free_id(vnex_id_t *vid_p)
6287c478bd9Sstevel@tonic-gate {
6297c478bd9Sstevel@tonic-gate 	mutex_enter(&vnex_id_lock);
6307c478bd9Sstevel@tonic-gate 	vnex_rem_id(vid_p);
6317c478bd9Sstevel@tonic-gate 	mutex_exit(&vnex_id_lock);
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 	kmem_free(vid_p, sizeof (*vid_p));
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate static void
6377c478bd9Sstevel@tonic-gate vnex_rem_id(vnex_id_t *vid_p)
6387c478bd9Sstevel@tonic-gate {
6397b5ce6bcSmf13430 	vnex_id_t *prev_p = vnex_id_list;
6407b5ce6bcSmf13430 
6417b5ce6bcSmf13430 	if (vnex_id_list == NULL)
6427b5ce6bcSmf13430 		cmn_err(CE_PANIC, "vnex: interrupt list empty");
6437b5ce6bcSmf13430 
6447b5ce6bcSmf13430 	if (vid_p == NULL)
6457b5ce6bcSmf13430 		cmn_err(CE_PANIC, "vnex: no element to remove");
6467b5ce6bcSmf13430 
6477b5ce6bcSmf13430 	if (vnex_id_list == vid_p) {
6487c478bd9Sstevel@tonic-gate 		vnex_id_list = vid_p->vid_next;
6497c478bd9Sstevel@tonic-gate 	} else {
6507b5ce6bcSmf13430 		while (prev_p != NULL && prev_p->vid_next != vid_p)
6517b5ce6bcSmf13430 			prev_p = prev_p->vid_next;
6527b5ce6bcSmf13430 
6537b5ce6bcSmf13430 		if (prev_p == NULL)
6547b5ce6bcSmf13430 			cmn_err(CE_PANIC, "vnex: element %p not in list",
6557b5ce6bcSmf13430 			    (void *) vid_p);
6567b5ce6bcSmf13430 
6577b5ce6bcSmf13430 		prev_p->vid_next = vid_p->vid_next;
6587c478bd9Sstevel@tonic-gate 	}
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate static void
6627c478bd9Sstevel@tonic-gate vnex_add_id(vnex_id_t *vid_p)
6637c478bd9Sstevel@tonic-gate {
6647c478bd9Sstevel@tonic-gate 	vid_p->vid_next = vnex_id_list;
6657c478bd9Sstevel@tonic-gate 	vnex_id_list = vid_p;
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate uint_t
6697c478bd9Sstevel@tonic-gate vnex_intr_wrapper(caddr_t arg)
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate 	vnex_id_t *vid_p = (vnex_id_t *)arg;
6727c478bd9Sstevel@tonic-gate 	int res;
6737c478bd9Sstevel@tonic-gate 	uint_t (*handler)();
6747c478bd9Sstevel@tonic-gate 	caddr_t handler_arg1;
6757c478bd9Sstevel@tonic-gate 	caddr_t handler_arg2;
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 	handler = vid_p->vid_handler;
6787c478bd9Sstevel@tonic-gate 	handler_arg1 = vid_p->vid_arg1;
6797c478bd9Sstevel@tonic-gate 	handler_arg2 = vid_p->vid_arg2;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	res = (*handler)(handler_arg1, handler_arg2);
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	(void) hvio_intr_setstate(vid_p->vid_ihdl, HV_INTR_IDLE_STATE);
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	return (res);
6867c478bd9Sstevel@tonic-gate }
687