xref: /titanic_50/usr/src/uts/common/io/tphci.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
5144dfaa9Scth  * Common Development and Distribution License (the "License").
6144dfaa9Scth  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*19397407SSherry Moore  * 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 /*
287c478bd9Sstevel@tonic-gate  * The tphci driver can be used to exercise the mpxio framework together
297c478bd9Sstevel@tonic-gate  * with tvhci/tclient.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/conf.h>
337c478bd9Sstevel@tonic-gate #include <sys/file.h>
347c478bd9Sstevel@tonic-gate #include <sys/open.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
377c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
387c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
397c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
407c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h>
417c478bd9Sstevel@tonic-gate #include <sys/disp.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /* cb_ops entry points */
447c478bd9Sstevel@tonic-gate static int tphci_open(dev_t *, int, int, cred_t *);
457c478bd9Sstevel@tonic-gate static int tphci_close(dev_t, int, int, cred_t *);
467c478bd9Sstevel@tonic-gate static int tphci_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
477c478bd9Sstevel@tonic-gate static int tphci_attach(dev_info_t *, ddi_attach_cmd_t);
487c478bd9Sstevel@tonic-gate static int tphci_detach(dev_info_t *, ddi_detach_cmd_t);
497c478bd9Sstevel@tonic-gate static int tphci_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* bus_ops entry points */
527c478bd9Sstevel@tonic-gate static int tphci_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *,
537c478bd9Sstevel@tonic-gate     void *);
547c478bd9Sstevel@tonic-gate static int tphci_initchild(dev_info_t *, dev_info_t *);
557c478bd9Sstevel@tonic-gate static int tphci_uninitchild(dev_info_t *, dev_info_t *);
567c478bd9Sstevel@tonic-gate static int tphci_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, void *,
577c478bd9Sstevel@tonic-gate     dev_info_t **);
587c478bd9Sstevel@tonic-gate static int tphci_bus_unconfig(dev_info_t *, uint_t, ddi_bus_config_op_t,
597c478bd9Sstevel@tonic-gate     void *);
607c478bd9Sstevel@tonic-gate static int tphci_intr_op(dev_info_t *dip, dev_info_t *rdip,
617c478bd9Sstevel@tonic-gate     ddi_intr_op_t op, ddi_intr_handle_impl_t *hdlp, void *result);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate static void *tphci_state;
657c478bd9Sstevel@tonic-gate struct tphci_state {
667c478bd9Sstevel@tonic-gate 	dev_info_t *dip;
677c478bd9Sstevel@tonic-gate };
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static struct cb_ops tphci_cb_ops = {
707c478bd9Sstevel@tonic-gate 	tphci_open,			/* open */
717c478bd9Sstevel@tonic-gate 	tphci_close,			/* close */
727c478bd9Sstevel@tonic-gate 	nodev,				/* strategy */
737c478bd9Sstevel@tonic-gate 	nodev,				/* print */
747c478bd9Sstevel@tonic-gate 	nodev,				/* dump */
757c478bd9Sstevel@tonic-gate 	nodev,				/* read */
767c478bd9Sstevel@tonic-gate 	nodev,				/* write */
777c478bd9Sstevel@tonic-gate 	tphci_ioctl,			/* ioctl */
787c478bd9Sstevel@tonic-gate 	nodev,				/* devmap */
797c478bd9Sstevel@tonic-gate 	nodev,				/* mmap */
807c478bd9Sstevel@tonic-gate 	nodev,				/* segmap */
817c478bd9Sstevel@tonic-gate 	nochpoll,			/* chpoll */
827c478bd9Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
837c478bd9Sstevel@tonic-gate 	0,				/* streamtab */
847c478bd9Sstevel@tonic-gate 	D_NEW | D_MP,			/* cb_flag */
857c478bd9Sstevel@tonic-gate 	CB_REV,				/* rev */
867c478bd9Sstevel@tonic-gate 	nodev,				/* aread */
877c478bd9Sstevel@tonic-gate 	nodev				/* awrite */
887c478bd9Sstevel@tonic-gate };
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate static struct bus_ops tphci_bus_ops = {
917c478bd9Sstevel@tonic-gate 	BUSO_REV,			/* busops_rev */
927c478bd9Sstevel@tonic-gate 	nullbusmap,			/* bus_map */
937c478bd9Sstevel@tonic-gate 	NULL,				/* bus_get_intrspec */
947c478bd9Sstevel@tonic-gate 	NULL,				/* bus_add_interspec */
957c478bd9Sstevel@tonic-gate 	NULL,				/* bus_remove_interspec */
967c478bd9Sstevel@tonic-gate 	i_ddi_map_fault,		/* bus_map_fault */
977c478bd9Sstevel@tonic-gate 	ddi_no_dma_map,			/* bus_dma_map */
987c478bd9Sstevel@tonic-gate 	ddi_no_dma_allochdl,		/* bus_dma_allochdl */
997c478bd9Sstevel@tonic-gate 	NULL,				/* bus_dma_freehdl */
1007c478bd9Sstevel@tonic-gate 	NULL,				/* bus_dma_bindhdl */
1017c478bd9Sstevel@tonic-gate 	NULL,				/* bus_dma_unbindhdl */
1027c478bd9Sstevel@tonic-gate 	NULL,				/* bus_dma_flush */
1037c478bd9Sstevel@tonic-gate 	NULL,				/* bus_dma_win */
1047c478bd9Sstevel@tonic-gate 	NULL,				/* bus_dma_ctl */
1057c478bd9Sstevel@tonic-gate 	tphci_ctl,			/* bus_ctl */
1067c478bd9Sstevel@tonic-gate 	ddi_bus_prop_op,		/* bus_prop_op */
1077c478bd9Sstevel@tonic-gate 	NULL,				/* bus_get_eventcookie */
1087c478bd9Sstevel@tonic-gate 	NULL,				/* bus_add_eventcall */
1097c478bd9Sstevel@tonic-gate 	NULL,				/* bus_remove_event */
1107c478bd9Sstevel@tonic-gate 	NULL,				/* bus_post_event */
1117c478bd9Sstevel@tonic-gate 	NULL,				/* bus_intr_ctl */
1127c478bd9Sstevel@tonic-gate 	tphci_bus_config,		/* bus_config */
1137c478bd9Sstevel@tonic-gate 	tphci_bus_unconfig,		/* bus_unconfig */
1147c478bd9Sstevel@tonic-gate 	NULL,				/* bus_fm_init */
1157c478bd9Sstevel@tonic-gate 	NULL,				/* bus_fm_fini */
1167c478bd9Sstevel@tonic-gate 	NULL,				/* bus_fm_access_enter */
1177c478bd9Sstevel@tonic-gate 	NULL,				/* bus_fm_access_exit */
1187c478bd9Sstevel@tonic-gate 	NULL,				/* bus_power */
1197c478bd9Sstevel@tonic-gate 	tphci_intr_op			/* bus_intr_op */
1207c478bd9Sstevel@tonic-gate };
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate static struct dev_ops tphci_ops = {
1237c478bd9Sstevel@tonic-gate 	DEVO_REV,
1247c478bd9Sstevel@tonic-gate 	0,
1257c478bd9Sstevel@tonic-gate 	tphci_getinfo,
1267c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
1277c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
1287c478bd9Sstevel@tonic-gate 	tphci_attach,		/* attach and detach are mandatory */
1297c478bd9Sstevel@tonic-gate 	tphci_detach,
1307c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
1317c478bd9Sstevel@tonic-gate 	&tphci_cb_ops,		/* cb_ops */
1327c478bd9Sstevel@tonic-gate 	&tphci_bus_ops,		/* bus_ops */
133*19397407SSherry Moore 	NULL,			/* power */
134*19397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
1357c478bd9Sstevel@tonic-gate };
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
1407c478bd9Sstevel@tonic-gate 	&mod_driverops,
141*19397407SSherry Moore 	"test phci driver",
1427c478bd9Sstevel@tonic-gate 	&tphci_ops
1437c478bd9Sstevel@tonic-gate };
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1467c478bd9Sstevel@tonic-gate 	MODREV_1,
1477c478bd9Sstevel@tonic-gate 	&modldrv,
1487c478bd9Sstevel@tonic-gate 	NULL
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate int
_init(void)1527c478bd9Sstevel@tonic-gate _init(void)
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate 	int rval;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	if ((rval = ddi_soft_state_init(&tphci_state,
1577c478bd9Sstevel@tonic-gate 	    sizeof (struct tphci_state), 2)) != 0) {
1587c478bd9Sstevel@tonic-gate 		return (rval);
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	if ((rval = mod_install(&modlinkage)) != 0) {
1627c478bd9Sstevel@tonic-gate 		ddi_soft_state_fini(&tphci_state);
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 	return (rval);
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate int
_fini(void)1697c478bd9Sstevel@tonic-gate _fini(void)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate 	int rval;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	/*
1747c478bd9Sstevel@tonic-gate 	 * don't start cleaning up until we know that the module remove
1757c478bd9Sstevel@tonic-gate 	 * has worked  -- if this works, then we know that each instance
1767c478bd9Sstevel@tonic-gate 	 * has successfully been detached
1777c478bd9Sstevel@tonic-gate 	 */
1787c478bd9Sstevel@tonic-gate 	if ((rval = mod_remove(&modlinkage)) != 0) {
1797c478bd9Sstevel@tonic-gate 		return (rval);
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	ddi_soft_state_fini(&tphci_state);
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	return (rval);
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1887c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1897c478bd9Sstevel@tonic-gate {
1907c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /* ARGSUSED */
1947c478bd9Sstevel@tonic-gate static int
tphci_open(dev_t * devp,int flag,int otype,cred_t * credp)1957c478bd9Sstevel@tonic-gate tphci_open(dev_t *devp, int flag, int otype, cred_t *credp)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate 	struct tphci_state *phci;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	if (otype != OTYP_CHR) {
2007c478bd9Sstevel@tonic-gate 		return (EINVAL);
2017c478bd9Sstevel@tonic-gate 	}
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	phci = ddi_get_soft_state(tphci_state, getminor(*devp));
2047c478bd9Sstevel@tonic-gate 	if (phci == NULL) {
2057c478bd9Sstevel@tonic-gate 		return (ENXIO);
2067c478bd9Sstevel@tonic-gate 	}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	return (0);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* ARGSUSED */
2137c478bd9Sstevel@tonic-gate static int
tphci_close(dev_t dev,int flag,int otype,cred_t * credp)2147c478bd9Sstevel@tonic-gate tphci_close(dev_t dev, int flag, int otype, cred_t *credp)
2157c478bd9Sstevel@tonic-gate {
2167c478bd9Sstevel@tonic-gate 	struct tphci_state *phci;
2177c478bd9Sstevel@tonic-gate 	if (otype != OTYP_CHR) {
2187c478bd9Sstevel@tonic-gate 		return (EINVAL);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	phci = ddi_get_soft_state(tphci_state, getminor(dev));
2227c478bd9Sstevel@tonic-gate 	if (phci == NULL) {
2237c478bd9Sstevel@tonic-gate 		return (ENXIO);
2247c478bd9Sstevel@tonic-gate 	}
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	return (0);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /* ARGSUSED */
2307c478bd9Sstevel@tonic-gate static int
tphci_ioctl(dev_t dev,int cmd,intptr_t data,int mode,cred_t * credp,int * rval)2317c478bd9Sstevel@tonic-gate tphci_ioctl(dev_t dev, int cmd, intptr_t data, int mode,
2327c478bd9Sstevel@tonic-gate 	cred_t *credp, int *rval)
2337c478bd9Sstevel@tonic-gate {
2347c478bd9Sstevel@tonic-gate 	return (0);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  * attach the module
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate static int
tphci_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)2417c478bd9Sstevel@tonic-gate tphci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate 	char *vclass;
2447c478bd9Sstevel@tonic-gate 	int instance, phci_regis = 0;
2457c478bd9Sstevel@tonic-gate 	struct tphci_state *phci = NULL;
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	switch (cmd) {
2507c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
2517c478bd9Sstevel@tonic-gate 		break;
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
2547c478bd9Sstevel@tonic-gate 	case DDI_PM_RESUME:
2557c478bd9Sstevel@tonic-gate 		return (0);	/* nothing to do */
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	default:
2587c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	/*
2627c478bd9Sstevel@tonic-gate 	 * Allocate phci data structure.
2637c478bd9Sstevel@tonic-gate 	 */
2647c478bd9Sstevel@tonic-gate 	if (ddi_soft_state_zalloc(tphci_state, instance) != DDI_SUCCESS) {
2657c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	phci = ddi_get_soft_state(tphci_state, instance);
2697c478bd9Sstevel@tonic-gate 	ASSERT(phci != NULL);
2707c478bd9Sstevel@tonic-gate 	phci->dip = dip;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/* bus_addr has the form #,<vhci_class> */
2737c478bd9Sstevel@tonic-gate 	vclass = strchr(ddi_get_name_addr(dip), ',');
2747c478bd9Sstevel@tonic-gate 	if (vclass == NULL || vclass[1] == '\0') {
2757c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "tphci invalid bus_addr %s",
2767c478bd9Sstevel@tonic-gate 		    ddi_get_name_addr(dip));
2777c478bd9Sstevel@tonic-gate 		goto attach_fail;
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	/*
2817c478bd9Sstevel@tonic-gate 	 * Attach this instance with the mpxio framework
2827c478bd9Sstevel@tonic-gate 	 */
2837c478bd9Sstevel@tonic-gate 	if (mdi_phci_register(vclass + 1, dip, 0) != MDI_SUCCESS) {
2847c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s mdi_phci_register failed",
2857c478bd9Sstevel@tonic-gate 		    ddi_node_name(dip));
2867c478bd9Sstevel@tonic-gate 		goto attach_fail;
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 	phci_regis++;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, "devctl", S_IFCHR,
2917c478bd9Sstevel@tonic-gate 	    instance, DDI_NT_SCSI_NEXUS, 0) != DDI_SUCCESS) {
2927c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "%s ddi_create_minor_node failed",
2937c478bd9Sstevel@tonic-gate 		    ddi_node_name(dip));
2947c478bd9Sstevel@tonic-gate 		goto attach_fail;
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1);
2987c478bd9Sstevel@tonic-gate 	ddi_report_dev(dip);
2997c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate attach_fail:
3027c478bd9Sstevel@tonic-gate 	if (phci_regis)
3037c478bd9Sstevel@tonic-gate 		(void) mdi_phci_unregister(dip, 0);
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	ddi_soft_state_free(tphci_state, instance);
3067c478bd9Sstevel@tonic-gate 	return (DDI_FAILURE);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3117c478bd9Sstevel@tonic-gate static int
tphci_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)3127c478bd9Sstevel@tonic-gate tphci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3137c478bd9Sstevel@tonic-gate {
3147c478bd9Sstevel@tonic-gate 	int instance = ddi_get_instance(dip);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	switch (cmd) {
3177c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
3187c478bd9Sstevel@tonic-gate 		break;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
3217c478bd9Sstevel@tonic-gate 	case DDI_PM_SUSPEND:
3227c478bd9Sstevel@tonic-gate 		return (0);	/* nothing to do */
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	default:
3257c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
3267c478bd9Sstevel@tonic-gate 	}
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	if (mdi_phci_unregister(dip, 0) != MDI_SUCCESS)
3297c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
3327c478bd9Sstevel@tonic-gate 	ddi_soft_state_free(tphci_state, instance);
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * tphci_getinfo()
3397c478bd9Sstevel@tonic-gate  * Given the device number, return the devinfo pointer or the
3407c478bd9Sstevel@tonic-gate  * instance number.
3417c478bd9Sstevel@tonic-gate  * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach.
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3457c478bd9Sstevel@tonic-gate static int
tphci_getinfo(dev_info_t * dip,ddi_info_cmd_t cmd,void * arg,void ** result)3467c478bd9Sstevel@tonic-gate tphci_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate 	struct tphci_state *phci;
3497c478bd9Sstevel@tonic-gate 	int instance = getminor((dev_t)arg);
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	switch (cmd) {
3527c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
3537c478bd9Sstevel@tonic-gate 		phci = ddi_get_soft_state(tphci_state, instance);
3547c478bd9Sstevel@tonic-gate 		if (phci != NULL)
3557c478bd9Sstevel@tonic-gate 			*result = phci->dip;
3567c478bd9Sstevel@tonic-gate 		else {
3577c478bd9Sstevel@tonic-gate 			*result = NULL;
3587c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3597c478bd9Sstevel@tonic-gate 		}
3607c478bd9Sstevel@tonic-gate 		break;
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
3637c478bd9Sstevel@tonic-gate 		*result = (void *)(uintptr_t)instance;
3647c478bd9Sstevel@tonic-gate 		break;
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	default:
3677c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
3687c478bd9Sstevel@tonic-gate 	}
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate /*
3747c478bd9Sstevel@tonic-gate  * Interrupt stuff. NO OP for pseudo drivers.
3757c478bd9Sstevel@tonic-gate  */
3767c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3777c478bd9Sstevel@tonic-gate static int
tphci_intr_op(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t op,ddi_intr_handle_impl_t * hdlp,void * result)3787c478bd9Sstevel@tonic-gate tphci_intr_op(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op,
3797c478bd9Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, void *result)
3807c478bd9Sstevel@tonic-gate {
3817c478bd9Sstevel@tonic-gate 	return (DDI_FAILURE);
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate static int
tphci_ctl(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t ctlop,void * arg,void * result)3857c478bd9Sstevel@tonic-gate tphci_ctl(dev_info_t *dip, dev_info_t *rdip,
3867c478bd9Sstevel@tonic-gate 	ddi_ctl_enum_t ctlop, void *arg, void *result)
3877c478bd9Sstevel@tonic-gate {
3887c478bd9Sstevel@tonic-gate 	switch (ctlop) {
3897c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
3907c478bd9Sstevel@tonic-gate 		if (rdip == (dev_info_t *)0)
3917c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
3927c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "?tphci-device: %s%d\n",
3937c478bd9Sstevel@tonic-gate 		    ddi_get_name(rdip), ddi_get_instance(rdip));
3947c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
3977c478bd9Sstevel@tonic-gate 	{
3987c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
3997c478bd9Sstevel@tonic-gate 		return (tphci_initchild(dip, child));
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
4037c478bd9Sstevel@tonic-gate 	{
4047c478bd9Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
4057c478bd9Sstevel@tonic-gate 		return (tphci_uninitchild(dip, child));
4067c478bd9Sstevel@tonic-gate 	}
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DMAPMAPC:
4097c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTINT:
4107c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
4117c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
4127c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
4137c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_SLAVEONLY:
4147c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_AFFINITY:
4157c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_POKE:
4167c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_PEEK:
4177c478bd9Sstevel@tonic-gate 		/*
4187c478bd9Sstevel@tonic-gate 		 * These ops correspond to functions that "shouldn't" be called
4197c478bd9Sstevel@tonic-gate 		 * by a pseudo driver.  So we whine when we're called.
4207c478bd9Sstevel@tonic-gate 		 */
4217c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n",
4227c478bd9Sstevel@tonic-gate 		    ddi_get_name(dip), ddi_get_instance(dip),
4237c478bd9Sstevel@tonic-gate 		    ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
4247c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_ATTACH:
4277c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_BTOP:
4287c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_BTOPR:
4297c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DETACH:
4307c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_DVMAPAGESIZE:
4317c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_IOMIN:
4327c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_POWER:
4337c478bd9Sstevel@tonic-gate 	case DDI_CTLOPS_PTOB:
4347c478bd9Sstevel@tonic-gate 	default:
4357c478bd9Sstevel@tonic-gate 		/*
4367c478bd9Sstevel@tonic-gate 		 * The ops that we pass up (default).  We pass up memory
4377c478bd9Sstevel@tonic-gate 		 * allocation oriented ops that we receive - these may be
4387c478bd9Sstevel@tonic-gate 		 * associated with pseudo HBA drivers below us with target
4397c478bd9Sstevel@tonic-gate 		 * drivers below them that use ddi memory allocation
4407c478bd9Sstevel@tonic-gate 		 * interfaces like scsi_alloc_consistent_buf.
4417c478bd9Sstevel@tonic-gate 		 */
4427c478bd9Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
4437c478bd9Sstevel@tonic-gate 	}
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate static int
tphci_initchild(dev_info_t * dip,dev_info_t * child)4477c478bd9Sstevel@tonic-gate tphci_initchild(dev_info_t *dip, dev_info_t *child)
4487c478bd9Sstevel@tonic-gate {
4497c478bd9Sstevel@tonic-gate 	_NOTE(ARGUNUSED(dip))
4507c478bd9Sstevel@tonic-gate 	ddi_set_name_addr(child, "0");
4517c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4557c478bd9Sstevel@tonic-gate static int
tphci_uninitchild(dev_info_t * dip,dev_info_t * child)4567c478bd9Sstevel@tonic-gate tphci_uninitchild(dev_info_t *dip, dev_info_t *child)
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate 	ddi_set_name_addr(child, NULL);
4597c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate static int
tp_decode_name(char * devnm,char ** cname,char ** paddr,char ** guid)4637c478bd9Sstevel@tonic-gate tp_decode_name(char *devnm, char **cname, char **paddr, char **guid)
4647c478bd9Sstevel@tonic-gate {
4657c478bd9Sstevel@tonic-gate 	char *tmp;
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	i_ddi_parse_name(devnm, cname, paddr, NULL);
4687c478bd9Sstevel@tonic-gate 	if ((strcmp(*cname, "tclient") != 0) &&
4697c478bd9Sstevel@tonic-gate 	    (strcmp(*cname, "tphci") != 0) || *paddr == NULL)
4707c478bd9Sstevel@tonic-gate 		return (-1);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	tmp = strchr(*paddr, ',');
4737c478bd9Sstevel@tonic-gate 	if (tmp == NULL || tmp[1] == '\0')
4747c478bd9Sstevel@tonic-gate 		return (-1);
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	*guid = tmp + 1;
4777c478bd9Sstevel@tonic-gate 	return (0);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate static int
tphci_bus_config(dev_info_t * parent,uint_t flags,ddi_bus_config_op_t op,void * arg,dev_info_t ** childp)4817c478bd9Sstevel@tonic-gate tphci_bus_config(dev_info_t *parent, uint_t flags,
4827c478bd9Sstevel@tonic-gate     ddi_bus_config_op_t op, void *arg, dev_info_t **childp)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	_NOTE(ARGUNUSED(flags))
4857c478bd9Sstevel@tonic-gate 	char		*cname, *paddr, *guid, *devnm;
4867c478bd9Sstevel@tonic-gate 	mdi_pathinfo_t	*pip;
4875e3986cbScth 	int		len, circ, rval;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	switch (op) {
4907c478bd9Sstevel@tonic-gate 	case BUS_CONFIG_ONE:
4917c478bd9Sstevel@tonic-gate 		break;
4927c478bd9Sstevel@tonic-gate 	case BUS_CONFIG_DRIVER:	/* no direct children to configure */
4937c478bd9Sstevel@tonic-gate 	case BUS_CONFIG_ALL:
4945e3986cbScth 		return (NDI_SUCCESS);
4957c478bd9Sstevel@tonic-gate 	default:
4965e3986cbScth 		return (NDI_FAILURE);
4977c478bd9Sstevel@tonic-gate 	}
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	/* only implement BUS_CONFIG_ONE */
5007c478bd9Sstevel@tonic-gate 	devnm = i_ddi_strdup((char *)arg, KM_SLEEP);
5017c478bd9Sstevel@tonic-gate 	len = strlen(devnm) + 1;
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	/* caddr is hardcoded in the form *,<guid> */
5047c478bd9Sstevel@tonic-gate 	if (tp_decode_name(devnm, &cname, &paddr, &guid) != 0) {
5057c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "tphci_bus_config -- invalid device %s",
5067c478bd9Sstevel@tonic-gate 		    (char *)arg);
5077c478bd9Sstevel@tonic-gate 		kmem_free(devnm, len);
5085e3986cbScth 		return (NDI_FAILURE);
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate 
5115e3986cbScth 	mdi_devi_enter(parent, &circ);
5125e3986cbScth 	rval = mdi_pi_alloc(parent, cname, guid, paddr, 0, &pip);
5135e3986cbScth 	kmem_free(devnm, len);
5145e3986cbScth 	if (rval != MDI_SUCCESS) {
5157c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "tphci_bus_config -- mdi_pi_alloc failed");
5165e3986cbScth 		mdi_devi_exit(parent, circ);
5175e3986cbScth 		return (NDI_FAILURE);
5187c478bd9Sstevel@tonic-gate 	}
5197c478bd9Sstevel@tonic-gate 
5205e3986cbScth 	/*
5215e3986cbScth 	 * Hold the path and exit the pHCI while calling mdi_pi_online
5225e3986cbScth 	 * to avoid deadlock with power management of pHCI.
5235e3986cbScth 	 */
5245e3986cbScth 	mdi_hold_path(pip);
5255e3986cbScth 	mdi_devi_exit_phci(parent, circ);
5265e3986cbScth 	rval = mdi_pi_online(pip, 0);
5275e3986cbScth 	mdi_devi_enter_phci(parent, &circ);
5285e3986cbScth 	mdi_rele_path(pip);
5295e3986cbScth 
5305e3986cbScth 	if (rval != MDI_SUCCESS) {
5317c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "tphci_bus_config -- mdi_pi_online failed");
5327c478bd9Sstevel@tonic-gate 		(void) mdi_pi_free(pip, 0);
5335e3986cbScth 		mdi_devi_exit(parent, circ);
5345e3986cbScth 		return (NDI_FAILURE);
5357c478bd9Sstevel@tonic-gate 	}
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	if (childp) {
5385e3986cbScth 		*childp = mdi_pi_get_client(pip);
5397c478bd9Sstevel@tonic-gate 		ndi_hold_devi(*childp);
5407c478bd9Sstevel@tonic-gate 	}
5415e3986cbScth 	mdi_devi_exit(parent, circ);
5425e3986cbScth 
5435e3986cbScth 	return (NDI_SUCCESS);
5447c478bd9Sstevel@tonic-gate }
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate static int
tphci_bus_unconfig(dev_info_t * parent,uint_t flags,ddi_bus_config_op_t op,void * arg)5477c478bd9Sstevel@tonic-gate tphci_bus_unconfig(dev_info_t *parent, uint_t flags,
5487c478bd9Sstevel@tonic-gate     ddi_bus_config_op_t op, void *arg)
5497c478bd9Sstevel@tonic-gate {
5505e3986cbScth 	int		rval = MDI_SUCCESS;
5515e3986cbScth 	int		circ;
5525e3986cbScth 	mdi_pathinfo_t	*pip, *next;
5537c478bd9Sstevel@tonic-gate 	char		*devnm, *cname, *caddr;
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	switch (op) {
5567c478bd9Sstevel@tonic-gate 	case BUS_UNCONFIG_ONE:
5577c478bd9Sstevel@tonic-gate 		devnm = (char *)arg;
5587c478bd9Sstevel@tonic-gate 		i_ddi_parse_name(devnm, &cname, &caddr, NULL);
5597c478bd9Sstevel@tonic-gate 		if (strcmp(cname, "tclient") != 0)
5605e3986cbScth 			return (NDI_SUCCESS);	/* no such device */
5615e3986cbScth 
5625e3986cbScth 		mdi_devi_enter(parent, &circ);
5637c478bd9Sstevel@tonic-gate 		pip = mdi_pi_find(parent, NULL, caddr);
5645e3986cbScth 		if (pip) {
5655e3986cbScth 			mdi_hold_path(pip);
5665e3986cbScth 			mdi_devi_exit_phci(parent, circ);
5677c478bd9Sstevel@tonic-gate 			rval = mdi_pi_offline(pip, NDI_DEVI_REMOVE);
5685e3986cbScth 			mdi_devi_enter_phci(parent, &circ);
5695e3986cbScth 			mdi_rele_path(pip);
5705e3986cbScth 
5715e3986cbScth 			if (rval == MDI_SUCCESS)
5725e3986cbScth 				(void) mdi_pi_free(pip, 0);
5735e3986cbScth 		}
5745e3986cbScth 		mdi_devi_exit(parent, circ);
5757c478bd9Sstevel@tonic-gate 		return (rval == MDI_SUCCESS ? NDI_SUCCESS : NDI_FAILURE);
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	case BUS_UNCONFIG_ALL:
5787c478bd9Sstevel@tonic-gate 		if (flags & NDI_AUTODETACH)
5795e3986cbScth 			return (NDI_FAILURE);
5807c478bd9Sstevel@tonic-gate 
5815e3986cbScth 		mdi_devi_enter(parent, &circ);
5825e3986cbScth 		next = mdi_get_next_client_path(parent, NULL);
5835e3986cbScth 		while ((pip = next) != NULL) {
5845e3986cbScth 			next = mdi_get_next_client_path(parent, pip);
5857c478bd9Sstevel@tonic-gate 
5865e3986cbScth 			mdi_hold_path(pip);
5875e3986cbScth 			mdi_devi_exit_phci(parent, circ);
5887c478bd9Sstevel@tonic-gate 			rval = mdi_pi_offline(pip, NDI_DEVI_REMOVE);
5895e3986cbScth 			mdi_devi_enter_phci(parent, &circ);
5905e3986cbScth 			mdi_rele_path(pip);
5915e3986cbScth 
5925e3986cbScth 			if (rval != MDI_SUCCESS)
5937c478bd9Sstevel@tonic-gate 				break;
5945e3986cbScth 			(void) mdi_pi_free(pip, 0);
5957c478bd9Sstevel@tonic-gate 		}
5965e3986cbScth 		mdi_devi_exit(parent, circ);
5977c478bd9Sstevel@tonic-gate 		return (rval == MDI_SUCCESS ? NDI_SUCCESS : NDI_FAILURE);
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 	case BUS_UNCONFIG_DRIVER:	/* nothing to do */
6005e3986cbScth 		return (NDI_SUCCESS);
6015e3986cbScth 
6027c478bd9Sstevel@tonic-gate 	default:
6035e3986cbScth 		return (NDI_FAILURE);
6047c478bd9Sstevel@tonic-gate 	}
6057c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
6067c478bd9Sstevel@tonic-gate }
607