xref: /onnv-gate/usr/src/uts/sun4/io/ebus.c (revision 7656:2621e50fdf4a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53920Srameshc  * Common Development and Distribution License (the "License").
63920Srameshc  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/conf.h>
290Sstevel@tonic-gate #include <sys/ddi.h>
300Sstevel@tonic-gate #include <sys/sunddi.h>
310Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
320Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
330Sstevel@tonic-gate #include <sys/pci.h>
340Sstevel@tonic-gate #include <sys/autoconf.h>
350Sstevel@tonic-gate #include <sys/cmn_err.h>
360Sstevel@tonic-gate #include <sys/errno.h>
370Sstevel@tonic-gate #include <sys/kmem.h>
380Sstevel@tonic-gate #include <sys/debug.h>
390Sstevel@tonic-gate #include <sys/sysmacros.h>
400Sstevel@tonic-gate #include <sys/ebus.h>
410Sstevel@tonic-gate #include <sys/open.h>
420Sstevel@tonic-gate #include <sys/stat.h>
430Sstevel@tonic-gate #include <sys/file.h>
440Sstevel@tonic-gate #include <sys/sunndi.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #ifdef DEBUG
470Sstevel@tonic-gate uint64_t ebus_debug_flags = 0;
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * The values of the following variables are used to initialize
520Sstevel@tonic-gate  * the cache line size and latency timer registers in the ebus
530Sstevel@tonic-gate  * configuration header.  Variables are used instead of constants
540Sstevel@tonic-gate  * to allow tuning from the /etc/system file.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate static uint8_t ebus_cache_line_size = 0x10;	/* 64 bytes */
570Sstevel@tonic-gate static uint8_t ebus_latency_timer = 0x40;	/* 64 PCI cycles */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * function prototypes for bus ops routines:
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate static int
630Sstevel@tonic-gate ebus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
640Sstevel@tonic-gate 	off_t offset, off_t len, caddr_t *addrp);
650Sstevel@tonic-gate static int
660Sstevel@tonic-gate ebus_ctlops(dev_info_t *dip, dev_info_t *rdip,
670Sstevel@tonic-gate 	ddi_ctl_enum_t op, void *arg, void *result);
680Sstevel@tonic-gate static int
690Sstevel@tonic-gate ebus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
700Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, void *result);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * function prototypes for dev ops routines:
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate static int ebus_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
760Sstevel@tonic-gate static int ebus_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
770Sstevel@tonic-gate static int ebus_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
780Sstevel@tonic-gate 	void *arg, void **result);
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * general function prototypes:
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate static int ebus_config(ebus_devstate_t *ebus_p);
840Sstevel@tonic-gate static int ebus_apply_range(ebus_devstate_t *ebus_p, dev_info_t *rdip,
85558Sjasonwu     ebus_regspec_t *ebus_rp, vregspec_t *rp);
86558Sjasonwu int ebus_get_ranges_prop(ebus_devstate_t *ebus_p);
87558Sjasonwu static void ebus_get_cells_prop(ebus_devstate_t *ebus_p);
88558Sjasonwu static void ebus_vreg_dump(ebus_devstate_t *ebus_p, vregspec_t *rp);
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	getprop(dip, name, addr, intp)		\
91506Scth 		ddi_getlongprop(DDI_DEV_T_ANY, (dip), DDI_PROP_DONTPASS, \
920Sstevel@tonic-gate 				(name), (caddr_t)(addr), (intp))
930Sstevel@tonic-gate 
940Sstevel@tonic-gate static int ebus_open(dev_t *devp, int flags, int otyp, cred_t *credp);
950Sstevel@tonic-gate static int ebus_close(dev_t dev, int flags, int otyp, cred_t *credp);
960Sstevel@tonic-gate static int ebus_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
970Sstevel@tonic-gate 						cred_t *credp, int *rvalp);
980Sstevel@tonic-gate struct cb_ops ebus_cb_ops = {
990Sstevel@tonic-gate 	ebus_open,			/* open */
1000Sstevel@tonic-gate 	ebus_close,			/* close */
1010Sstevel@tonic-gate 	nodev,				/* strategy */
1020Sstevel@tonic-gate 	nodev,				/* print */
1030Sstevel@tonic-gate 	nodev,				/* dump */
1040Sstevel@tonic-gate 	nodev,				/* read */
1050Sstevel@tonic-gate 	nodev,				/* write */
1060Sstevel@tonic-gate 	ebus_ioctl,			/* ioctl */
1070Sstevel@tonic-gate 	nodev,				/* devmap */
1080Sstevel@tonic-gate 	nodev,				/* mmap */
1090Sstevel@tonic-gate 	nodev,				/* segmap */
1100Sstevel@tonic-gate 	nochpoll,			/* poll */
1110Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
1120Sstevel@tonic-gate 	NULL,				/* streamtab */
1130Sstevel@tonic-gate 	D_NEW | D_MP | D_HOTPLUG,	/* Driver compatibility flag */
1140Sstevel@tonic-gate 	CB_REV,				/* rev */
1150Sstevel@tonic-gate 	nodev,				/* int (*cb_aread)() */
1160Sstevel@tonic-gate 	nodev				/* int (*cb_awrite)() */
1170Sstevel@tonic-gate };
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * bus ops and dev ops structures:
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate static struct bus_ops ebus_bus_ops = {
1230Sstevel@tonic-gate 	BUSO_REV,
1240Sstevel@tonic-gate 	ebus_map,
1250Sstevel@tonic-gate 	NULL,
1260Sstevel@tonic-gate 	NULL,
1270Sstevel@tonic-gate 	NULL,
1280Sstevel@tonic-gate 	i_ddi_map_fault,
1290Sstevel@tonic-gate 	ddi_dma_map,
1300Sstevel@tonic-gate 	ddi_dma_allochdl,
1310Sstevel@tonic-gate 	ddi_dma_freehdl,
1320Sstevel@tonic-gate 	ddi_dma_bindhdl,
1330Sstevel@tonic-gate 	ddi_dma_unbindhdl,
1340Sstevel@tonic-gate 	ddi_dma_flush,
1350Sstevel@tonic-gate 	ddi_dma_win,
1360Sstevel@tonic-gate 	ddi_dma_mctl,
1370Sstevel@tonic-gate 	ebus_ctlops,
1380Sstevel@tonic-gate 	ddi_bus_prop_op,
1390Sstevel@tonic-gate 	ndi_busop_get_eventcookie,
1400Sstevel@tonic-gate 	ndi_busop_add_eventcall,
1410Sstevel@tonic-gate 	ndi_busop_remove_eventcall,
1420Sstevel@tonic-gate 	ndi_post_event,
1430Sstevel@tonic-gate 	0,
1440Sstevel@tonic-gate 	0,
1450Sstevel@tonic-gate 	0,
1460Sstevel@tonic-gate 	0,
1470Sstevel@tonic-gate 	0,
1480Sstevel@tonic-gate 	0,
1490Sstevel@tonic-gate 	0,
1500Sstevel@tonic-gate 	0,
1510Sstevel@tonic-gate 	ebus_intr_ops
1520Sstevel@tonic-gate };
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate static struct dev_ops ebus_ops = {
1550Sstevel@tonic-gate 	DEVO_REV,
1560Sstevel@tonic-gate 	0,
1570Sstevel@tonic-gate 	ebus_info,
1580Sstevel@tonic-gate 	nulldev,
1590Sstevel@tonic-gate 	nulldev,
1600Sstevel@tonic-gate 	ebus_attach,
1610Sstevel@tonic-gate 	ebus_detach,
1620Sstevel@tonic-gate 	nodev,
1630Sstevel@tonic-gate 	&ebus_cb_ops,
164*7656SSherry.Moore@Sun.COM 	&ebus_bus_ops,
165*7656SSherry.Moore@Sun.COM 	NULL,
166*7656SSherry.Moore@Sun.COM 	ddi_quiesce_not_supported,	/* devo_quiesce */
1670Sstevel@tonic-gate };
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate /*
1700Sstevel@tonic-gate  * module definitions:
1710Sstevel@tonic-gate  */
1720Sstevel@tonic-gate #include <sys/modctl.h>
1730Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate static struct modldrv modldrv = {
1760Sstevel@tonic-gate 	&mod_driverops, 	/* Type of module.  This one is a driver */
177*7656SSherry.Moore@Sun.COM 	"ebus nexus driver", /* Name of module. */
1780Sstevel@tonic-gate 	&ebus_ops,		/* driver ops */
1790Sstevel@tonic-gate };
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate static struct modlinkage modlinkage = {
1820Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
1830Sstevel@tonic-gate };
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate  * driver global data:
1870Sstevel@tonic-gate  */
1880Sstevel@tonic-gate static void *per_ebus_state;		/* per-ebus soft state pointer */
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate int
_init(void)1920Sstevel@tonic-gate _init(void)
1930Sstevel@tonic-gate {
1940Sstevel@tonic-gate 	int e;
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 	/*
1970Sstevel@tonic-gate 	 * Initialize per-ebus soft state pointer.
1980Sstevel@tonic-gate 	 */
1990Sstevel@tonic-gate 	e = ddi_soft_state_init(&per_ebus_state, sizeof (ebus_devstate_t), 1);
2000Sstevel@tonic-gate 	if (e != 0)
2010Sstevel@tonic-gate 		return (e);
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	/*
2040Sstevel@tonic-gate 	 * Install the module.
2050Sstevel@tonic-gate 	 */
2060Sstevel@tonic-gate 	e = mod_install(&modlinkage);
2070Sstevel@tonic-gate 	if (e != 0)
2080Sstevel@tonic-gate 		ddi_soft_state_fini(&per_ebus_state);
2090Sstevel@tonic-gate 	return (e);
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate int
_fini(void)2130Sstevel@tonic-gate _fini(void)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate 	int e;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	/*
2180Sstevel@tonic-gate 	 * Remove the module.
2190Sstevel@tonic-gate 	 */
2200Sstevel@tonic-gate 	e = mod_remove(&modlinkage);
2210Sstevel@tonic-gate 	if (e != 0)
2220Sstevel@tonic-gate 		return (e);
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	/*
2250Sstevel@tonic-gate 	 * Free the soft state info.
2260Sstevel@tonic-gate 	 */
2270Sstevel@tonic-gate 	ddi_soft_state_fini(&per_ebus_state);
2280Sstevel@tonic-gate 	return (e);
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2320Sstevel@tonic-gate _info(struct modinfo *modinfop)
2330Sstevel@tonic-gate {
2340Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate /* device driver entry points */
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /*ARGSUSED*/
2400Sstevel@tonic-gate static int
ebus_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)2410Sstevel@tonic-gate ebus_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
2420Sstevel@tonic-gate {
2430Sstevel@tonic-gate 	ebus_devstate_t *ebus_p;	/* per ebus state pointer */
2440Sstevel@tonic-gate 	int instance;
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	instance = getminor((dev_t)arg);
2470Sstevel@tonic-gate 	ebus_p = get_ebus_soft_state(instance);
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	switch (infocmd) {
2500Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
251796Smathue 		*result = (void *)(uintptr_t)instance;
252558Sjasonwu 		break;
2530Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
2540Sstevel@tonic-gate 		if (ebus_p == NULL)
2550Sstevel@tonic-gate 			return (DDI_FAILURE);
2560Sstevel@tonic-gate 		*result = (void *)ebus_p->dip;
257558Sjasonwu 		break;
258558Sjasonwu 	default:
259558Sjasonwu 		return (DDI_FAILURE);
2600Sstevel@tonic-gate 	}
261558Sjasonwu 
262558Sjasonwu 	return (DDI_SUCCESS);
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate /*
2660Sstevel@tonic-gate  * attach entry point:
2670Sstevel@tonic-gate  *
2680Sstevel@tonic-gate  * normal attach:
2690Sstevel@tonic-gate  *
2700Sstevel@tonic-gate  *	create soft state structure (dip, reg, nreg and state fields)
2710Sstevel@tonic-gate  *	map in configuration header
2720Sstevel@tonic-gate  *	make sure device is properly configured
2730Sstevel@tonic-gate  *	report device
2740Sstevel@tonic-gate  */
2750Sstevel@tonic-gate static int
ebus_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)2760Sstevel@tonic-gate ebus_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2770Sstevel@tonic-gate {
2780Sstevel@tonic-gate 	ebus_devstate_t *ebus_p;	/* per ebus state pointer */
2790Sstevel@tonic-gate 	int instance;
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	DBG1(D_ATTACH, NULL, "dip=%p\n", dip);
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	switch (cmd) {
2840Sstevel@tonic-gate 	case DDI_ATTACH:
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate 		/*
2870Sstevel@tonic-gate 		 * Allocate soft state for this instance.
2880Sstevel@tonic-gate 		 */
2890Sstevel@tonic-gate 		instance = ddi_get_instance(dip);
2900Sstevel@tonic-gate 		if (ddi_soft_state_zalloc(per_ebus_state, instance)
291558Sjasonwu 		    != DDI_SUCCESS) {
2920Sstevel@tonic-gate 			DBG(D_ATTACH, NULL, "failed to alloc soft state\n");
2930Sstevel@tonic-gate 			return (DDI_FAILURE);
2940Sstevel@tonic-gate 		}
2950Sstevel@tonic-gate 		ebus_p = get_ebus_soft_state(instance);
2960Sstevel@tonic-gate 		ebus_p->dip = dip;
2970Sstevel@tonic-gate 		mutex_init(&ebus_p->ebus_mutex, NULL, MUTEX_DRIVER, NULL);
2980Sstevel@tonic-gate 		ebus_p->ebus_soft_state = EBUS_SOFT_STATE_CLOSED;
2990Sstevel@tonic-gate 
300558Sjasonwu 		ebus_get_cells_prop(ebus_p);
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 		(void) ddi_prop_create(DDI_DEV_T_NONE, dip,
303558Sjasonwu 		    DDI_PROP_CANSLEEP, "no-dma-interrupt-sync", NULL, 0);
3040Sstevel@tonic-gate 		/* Get our ranges property for mapping child registers. */
305558Sjasonwu 		if (ebus_get_ranges_prop(ebus_p) != DDI_SUCCESS) {
306558Sjasonwu 			goto attach_fail;
3070Sstevel@tonic-gate 		}
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate 		/*
3100Sstevel@tonic-gate 		 * create minor node for devctl interfaces
3110Sstevel@tonic-gate 		 */
3120Sstevel@tonic-gate 		if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance,
313*7656SSherry.Moore@Sun.COM 		    DDI_NT_NEXUS, 0) != DDI_SUCCESS) {
314558Sjasonwu 			goto attach_fail;
3150Sstevel@tonic-gate 		}
316558Sjasonwu 
317558Sjasonwu 		if (ebus_config(ebus_p) != DDI_SUCCESS) {
318558Sjasonwu 			ddi_remove_minor_node(dip, "devctl");
319558Sjasonwu 			goto attach_fail;
3200Sstevel@tonic-gate 		}
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 		/*
3230Sstevel@tonic-gate 		 * Make the pci_report_pmcap() call only for RIO
3240Sstevel@tonic-gate 		 * implementations.
3250Sstevel@tonic-gate 		 */
3260Sstevel@tonic-gate 		if (IS_RIO(dip)) {
3270Sstevel@tonic-gate 			(void) pci_report_pmcap(dip, PCI_PM_IDLESPEED,
3280Sstevel@tonic-gate 			    (void *)EBUS_4MHZ);
3290Sstevel@tonic-gate 		}
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 		/*
3320Sstevel@tonic-gate 		 * Make the state as attached and report the device.
3330Sstevel@tonic-gate 		 */
3340Sstevel@tonic-gate 		ebus_p->state = ATTACHED;
3350Sstevel@tonic-gate 		ddi_report_dev(dip);
3360Sstevel@tonic-gate 		DBG(D_ATTACH, ebus_p, "returning\n");
337558Sjasonwu 		break;
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	case DDI_RESUME:
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 		instance = ddi_get_instance(dip);
3420Sstevel@tonic-gate 		ebus_p = get_ebus_soft_state(instance);
3430Sstevel@tonic-gate 
344558Sjasonwu 		(void) ebus_config(ebus_p);
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 		ebus_p->state = RESUMED;
347558Sjasonwu 		break;
3480Sstevel@tonic-gate 	}
349558Sjasonwu 
350558Sjasonwu 	return (DDI_SUCCESS);
351558Sjasonwu 
352558Sjasonwu attach_fail:
353558Sjasonwu 	mutex_destroy(&ebus_p->ebus_mutex);
354558Sjasonwu 	free_ebus_soft_state(instance);
3550Sstevel@tonic-gate 	return (DDI_FAILURE);
3560Sstevel@tonic-gate }
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate /*
3590Sstevel@tonic-gate  * detach entry point:
3600Sstevel@tonic-gate  */
3610Sstevel@tonic-gate static int
ebus_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)3620Sstevel@tonic-gate ebus_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3630Sstevel@tonic-gate {
3640Sstevel@tonic-gate 	int instance = ddi_get_instance(dip);
3650Sstevel@tonic-gate 	ebus_devstate_t *ebus_p = get_ebus_soft_state(instance);
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate 	switch (cmd) {
3680Sstevel@tonic-gate 	case DDI_DETACH:
3690Sstevel@tonic-gate 		DBG1(D_DETACH, ebus_p, "DDI_DETACH dip=%p\n", dip);
3700Sstevel@tonic-gate 
371558Sjasonwu 		kmem_free(ebus_p->vrangep, ebus_p->vrange_len);
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 		ddi_remove_minor_node(dip, "devctl");
3740Sstevel@tonic-gate 		mutex_destroy(&ebus_p->ebus_mutex);
3750Sstevel@tonic-gate 		free_ebus_soft_state(instance);
376558Sjasonwu 		break;
3770Sstevel@tonic-gate 	case DDI_SUSPEND:
3780Sstevel@tonic-gate 		DBG1(D_DETACH, ebus_p, "DDI_SUSPEND dip=%p\n", dip);
3790Sstevel@tonic-gate 		ebus_p->state = SUSPENDED;
380558Sjasonwu 		break;
381558Sjasonwu 	default:
382558Sjasonwu 		DBG(D_ATTACH, NULL,
383558Sjasonwu 		    "failed to recognize ebus detach command\n");
384558Sjasonwu 		return (DDI_FAILURE);
3850Sstevel@tonic-gate 	}
386558Sjasonwu 	return (DDI_SUCCESS);
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate int
ebus_get_ranges_prop(ebus_devstate_t * ebus_p)391558Sjasonwu ebus_get_ranges_prop(ebus_devstate_t *ebus_p)
3920Sstevel@tonic-gate {
393558Sjasonwu 	if (ddi_getlongprop(DDI_DEV_T_ANY, ebus_p->dip, DDI_PROP_DONTPASS,
394*7656SSherry.Moore@Sun.COM 	    "ranges", (caddr_t)&ebus_p->vrangep, &ebus_p->vrange_len)
395558Sjasonwu 	    != DDI_SUCCESS) {
396558Sjasonwu 		cmn_err(CE_WARN, "Can't get %s ranges property",
397558Sjasonwu 		    ddi_get_name(ebus_p->dip));
398558Sjasonwu 		return (DDI_ME_REGSPEC_RANGE);
399558Sjasonwu 	}
4000Sstevel@tonic-gate 
401558Sjasonwu 	ebus_p->vrange_cnt = ebus_p->vrange_len /
402558Sjasonwu 	    (ebus_p->ebus_paddr_cells + ebus_p->ebus_addr_cells +
403*7656SSherry.Moore@Sun.COM 	    ebus_p->ebus_psz_cells);
4040Sstevel@tonic-gate 
405558Sjasonwu 	if (ebus_p->vrange_cnt == 0) {
406558Sjasonwu 		kmem_free(ebus_p->vrangep, ebus_p->vrange_len);
407558Sjasonwu 		DBG(D_ATTACH, NULL, "range is equal to zero\n");
4080Sstevel@tonic-gate 		return (DDI_FAILURE);
4090Sstevel@tonic-gate 	}
410558Sjasonwu 
411558Sjasonwu 	return (DDI_SUCCESS);
412558Sjasonwu }
413558Sjasonwu 
414558Sjasonwu static void
ebus_get_cells_prop(ebus_devstate_t * ebus_p)415558Sjasonwu ebus_get_cells_prop(ebus_devstate_t *ebus_p)
416558Sjasonwu {
417558Sjasonwu 	dev_info_t *dip = ebus_p->dip;
418558Sjasonwu 	dev_info_t *pdip;
419558Sjasonwu 
420558Sjasonwu 	ebus_p->ebus_addr_cells = ddi_getprop(DDI_DEV_T_ANY,
421558Sjasonwu 	    dip, DDI_PROP_DONTPASS, "#address-cells", 2);
422558Sjasonwu 
423558Sjasonwu 	pdip = ddi_get_parent(dip);
424558Sjasonwu 	ebus_p->ebus_paddr_cells = ddi_getprop(DDI_DEV_T_ANY,
425558Sjasonwu 	    pdip, DDI_PROP_DONTPASS, "#address-cells", 2);
426558Sjasonwu 
427558Sjasonwu 	ASSERT((ebus_p->ebus_paddr_cells == 3) ||
428558Sjasonwu 	    (ebus_p->ebus_paddr_cells == 2));
429558Sjasonwu 
430558Sjasonwu 	ebus_p->ebus_sz_cells = ddi_getprop(DDI_DEV_T_ANY,
431558Sjasonwu 	    dip, DDI_PROP_DONTPASS, "#size-cells", 2);
432558Sjasonwu 	ebus_p->ebus_psz_cells = ddi_getprop(DDI_DEV_T_ANY,
433558Sjasonwu 	    pdip, DDI_PROP_DONTPASS, "#size-cells", 1);
434558Sjasonwu 
435558Sjasonwu 	/* XXX rootnex assumes 1 cell and does not respect #size-cells */
436558Sjasonwu 	if (ddi_root_node() == pdip)
437558Sjasonwu 		ebus_p->ebus_psz_cells = 1;
438558Sjasonwu 
439558Sjasonwu 	ASSERT((ebus_p->ebus_psz_cells == 2) ||
440558Sjasonwu 	    (ebus_p->ebus_psz_cells == 1));
441558Sjasonwu 
4420Sstevel@tonic-gate }
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate /* bus driver entry points */
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate /*
4470Sstevel@tonic-gate  * bus map entry point:
4480Sstevel@tonic-gate  *
4490Sstevel@tonic-gate  * 	if map request is for an rnumber
4500Sstevel@tonic-gate  *		get the corresponding regspec from device node
4510Sstevel@tonic-gate  * 	build a new regspec in our parent's format
4520Sstevel@tonic-gate  *	build a new map_req with the new regspec
4530Sstevel@tonic-gate  *	call up the tree to complete the mapping
4540Sstevel@tonic-gate  */
4550Sstevel@tonic-gate static int
ebus_map(dev_info_t * dip,dev_info_t * rdip,ddi_map_req_t * mp,off_t off,off_t len,caddr_t * addrp)4560Sstevel@tonic-gate ebus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
4570Sstevel@tonic-gate 	off_t off, off_t len, caddr_t *addrp)
4580Sstevel@tonic-gate {
4590Sstevel@tonic-gate 	ebus_devstate_t *ebus_p = get_ebus_soft_state(ddi_get_instance(dip));
4600Sstevel@tonic-gate 	ebus_regspec_t *ebus_rp, *ebus_regs;
461558Sjasonwu 	vregspec_t vreg;
4620Sstevel@tonic-gate 	ddi_map_req_t p_map_request;
4630Sstevel@tonic-gate 	int rnumber, i, n;
4640Sstevel@tonic-gate 	int rval = DDI_SUCCESS;
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	/*
4670Sstevel@tonic-gate 	 * Handle the mapping according to its type.
4680Sstevel@tonic-gate 	 */
4690Sstevel@tonic-gate 	DBG4(D_MAP, ebus_p, "rdip=%s%d: off=%x len=%x\n",
4700Sstevel@tonic-gate 	    ddi_get_name(rdip), ddi_get_instance(rdip), off, len);
4710Sstevel@tonic-gate 	switch (mp->map_type) {
4720Sstevel@tonic-gate 	case DDI_MT_REGSPEC:
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate 		/*
4750Sstevel@tonic-gate 		 * We assume the register specification is in ebus format.
4760Sstevel@tonic-gate 		 * We must convert it into a PCI format regspec and pass
4770Sstevel@tonic-gate 		 * the request to our parent.
4780Sstevel@tonic-gate 		 */
4790Sstevel@tonic-gate 		DBG3(D_MAP, ebus_p, "rdip=%s%d: REGSPEC - handlep=%p\n",
480*7656SSherry.Moore@Sun.COM 		    ddi_get_name(rdip), ddi_get_instance(rdip),
481*7656SSherry.Moore@Sun.COM 		    mp->map_handlep);
4820Sstevel@tonic-gate 		ebus_rp = (ebus_regspec_t *)mp->map_obj.rp;
4830Sstevel@tonic-gate 		break;
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	case DDI_MT_RNUMBER:
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate 		/*
4880Sstevel@tonic-gate 		 * Get the "reg" property from the device node and convert
4890Sstevel@tonic-gate 		 * it to our parent's format.
4900Sstevel@tonic-gate 		 */
4910Sstevel@tonic-gate 		rnumber = mp->map_obj.rnumber;
4920Sstevel@tonic-gate 		DBG4(D_MAP, ebus_p, "rdip=%s%d: rnumber=%x handlep=%p\n",
493*7656SSherry.Moore@Sun.COM 		    ddi_get_name(rdip), ddi_get_instance(rdip),
494*7656SSherry.Moore@Sun.COM 		    rnumber, mp->map_handlep);
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate 		if (getprop(rdip, "reg", &ebus_regs, &i) != DDI_SUCCESS) {
4970Sstevel@tonic-gate 			DBG(D_MAP, ebus_p, "can't get reg property\n");
4980Sstevel@tonic-gate 			return (DDI_ME_RNUMBER_RANGE);
4990Sstevel@tonic-gate 		}
500558Sjasonwu 
5010Sstevel@tonic-gate 		n = i / sizeof (ebus_regspec_t);
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 		if (rnumber < 0 || rnumber >= n) {
5040Sstevel@tonic-gate 			DBG(D_MAP, ebus_p, "rnumber out of range\n");
5050Sstevel@tonic-gate 			return (DDI_ME_RNUMBER_RANGE);
5060Sstevel@tonic-gate 		}
5070Sstevel@tonic-gate 		ebus_rp = &ebus_regs[rnumber];
5080Sstevel@tonic-gate 		break;
5090Sstevel@tonic-gate 
5100Sstevel@tonic-gate 	default:
5110Sstevel@tonic-gate 		return (DDI_ME_INVAL);
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	}
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate 	/* Adjust our reg property with offset and length */
5160Sstevel@tonic-gate 	ebus_rp->addr_low += off;
5170Sstevel@tonic-gate 	if (len)
5180Sstevel@tonic-gate 		ebus_rp->size = len;
5190Sstevel@tonic-gate 
520558Sjasonwu 	rval = ebus_apply_range(ebus_p, rdip, ebus_rp, &vreg);
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate 	if (mp->map_type == DDI_MT_RNUMBER)
5230Sstevel@tonic-gate 		kmem_free(ebus_regs, i);
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate 	if (rval != DDI_SUCCESS)
5260Sstevel@tonic-gate 		return (rval);
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 	p_map_request = *mp;
5290Sstevel@tonic-gate 	p_map_request.map_type = DDI_MT_REGSPEC;
5300Sstevel@tonic-gate 
531558Sjasonwu 	p_map_request.map_obj.rp = (struct regspec *)&vreg;
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 	rval = ddi_map(dip, &p_map_request, 0, 0, addrp);
5340Sstevel@tonic-gate 	DBG1(D_MAP, ebus_p, "parent returned %x\n", rval);
5350Sstevel@tonic-gate 	return (rval);
5360Sstevel@tonic-gate }
5370Sstevel@tonic-gate 
538558Sjasonwu /*
539558Sjasonwu  * ebus_apply_range generically relocates child's regspec to
540558Sjasonwu  * parent's format according to ebus' range spec
541558Sjasonwu  *
542558Sjasonwu  * Assumptions:
543558Sjasonwu  * - rng_caddr_hi is the space type
544558Sjasonwu  * - rng_caddr_low is the base address
545558Sjasonwu  * - ebus address is 32 bit and ebus entirely lives between 0-4G of
546558Sjasonwu  *   parent space, so maths on preg/rng_cell_p[ebus_p->ebus_paddr_cells - 1],
547558Sjasonwu  *   preg_cell_p[i], rng_caddr_low and ebus_rp->size are sufficient.
548558Sjasonwu  */
5490Sstevel@tonic-gate static int
ebus_apply_range(ebus_devstate_t * ebus_p,dev_info_t * rdip,ebus_regspec_t * ebus_rp,vregspec_t * rp)5500Sstevel@tonic-gate ebus_apply_range(ebus_devstate_t *ebus_p, dev_info_t *rdip,
551558Sjasonwu     ebus_regspec_t *ebus_rp, vregspec_t *rp) {
552558Sjasonwu 	int b, i;
553558Sjasonwu 	int nrange = ebus_p->vrange_cnt;
554558Sjasonwu 	uint32_t addr_offset, rng_caddr_hi, rng_caddr_low, rng_sz;
555558Sjasonwu 	uint32_t req_addr = ebus_rp->addr_low;
556558Sjasonwu 
557558Sjasonwu 	uint32_t *rng_cell_p = (uint32_t *)ebus_p->vrangep;
558558Sjasonwu 	int rng_rec_sz = ebus_p->ebus_paddr_cells + ebus_p->ebus_addr_cells +
559558Sjasonwu 	    ebus_p->ebus_sz_cells;
560558Sjasonwu 	uint32_t *preg_cell_p = (uint32_t *)rp;
561558Sjasonwu 	int preg_rec_sz = ebus_p->ebus_paddr_cells + ebus_p->ebus_psz_cells;
562558Sjasonwu 
5630Sstevel@tonic-gate 	static char out_of_range[] =
5640Sstevel@tonic-gate 	    "Out of range register specification from device node <%s>";
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 	DBG3(D_MAP, ebus_p, "Range Matching Addr 0x%x.%x size 0x%x\n",
567558Sjasonwu 	    ebus_rp->addr_hi, req_addr, ebus_rp->size);
568558Sjasonwu 
569558Sjasonwu 	for (b = 0; b < nrange; b++, rng_cell_p += rng_rec_sz) {
570558Sjasonwu 
571558Sjasonwu 		rng_caddr_hi = rng_cell_p[0];
572558Sjasonwu 		rng_caddr_low = rng_cell_p[1];
573558Sjasonwu 		rng_sz = rng_cell_p[rng_rec_sz-1];
5740Sstevel@tonic-gate 
575558Sjasonwu 		/* Check for correct space */
576558Sjasonwu 		if (ebus_rp->addr_hi != rng_caddr_hi)
577558Sjasonwu 			continue;
578558Sjasonwu 
579558Sjasonwu 		/* Detect whether request entirely fits within a range */
580558Sjasonwu 		if (req_addr < rng_caddr_low)
581558Sjasonwu 			continue;
582558Sjasonwu 
583558Sjasonwu 		if ((req_addr + ebus_rp->size - 1)
584558Sjasonwu 		    > (rng_caddr_low + rng_sz - 1))
585558Sjasonwu 			continue;
5860Sstevel@tonic-gate 
587558Sjasonwu 		addr_offset = req_addr - rng_caddr_low;
588558Sjasonwu 
589558Sjasonwu 		/* parent addr = child addr + offset from ranges */
590558Sjasonwu 		for (i = 0; i < preg_rec_sz; i++)
591558Sjasonwu 			preg_cell_p[i] = 0;
592558Sjasonwu 
593558Sjasonwu 		/* Copy the physical address */
594558Sjasonwu 		for (i = 0; i < ebus_p->ebus_paddr_cells; i++)
595558Sjasonwu 			preg_cell_p[i] = rng_cell_p[ebus_p->ebus_addr_cells+i];
5960Sstevel@tonic-gate 
597558Sjasonwu 		preg_cell_p[ebus_p->ebus_paddr_cells-1] += addr_offset;
598558Sjasonwu 
599558Sjasonwu 		/* Copy the size */
600558Sjasonwu 		preg_cell_p[preg_rec_sz-1] = min(ebus_rp->size,
601558Sjasonwu 		    rng_sz - addr_offset);
6020Sstevel@tonic-gate 
603558Sjasonwu #ifdef DEBUG
604558Sjasonwu 		ebus_vreg_dump(ebus_p, (vregspec_t *)preg_cell_p);
605558Sjasonwu #endif /* DEBUG */
606558Sjasonwu 
607558Sjasonwu 		break;
6080Sstevel@tonic-gate 	}
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	if (b == nrange)  {
6110Sstevel@tonic-gate 		cmn_err(CE_WARN, out_of_range, ddi_get_name(rdip));
6120Sstevel@tonic-gate 		return (DDI_ME_REGSPEC_RANGE);
6130Sstevel@tonic-gate 	}
6140Sstevel@tonic-gate 
615558Sjasonwu 	return (DDI_SUCCESS);
6160Sstevel@tonic-gate }
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate static int
ebus_name_child(dev_info_t * child,char * name,int namelen)6190Sstevel@tonic-gate ebus_name_child(dev_info_t *child, char *name, int namelen)
6200Sstevel@tonic-gate {
6210Sstevel@tonic-gate 	ebus_regspec_t *ebus_rp;
6220Sstevel@tonic-gate 	int reglen;
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate 	/*
6250Sstevel@tonic-gate 	 * Get the address portion of the node name based on the
6260Sstevel@tonic-gate 	 * address/offset.
6270Sstevel@tonic-gate 	 */
628506Scth 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
6290Sstevel@tonic-gate 	    "reg", (caddr_t)&ebus_rp, &reglen) != DDI_SUCCESS) {
6300Sstevel@tonic-gate 		return (DDI_FAILURE);
6310Sstevel@tonic-gate 	}
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate 	(void) snprintf(name, namelen, "%x,%x", ebus_rp->addr_hi,
6340Sstevel@tonic-gate 	    ebus_rp->addr_low);
6350Sstevel@tonic-gate 	kmem_free(ebus_rp, reglen);
6360Sstevel@tonic-gate 
6370Sstevel@tonic-gate 	return (DDI_SUCCESS);
6380Sstevel@tonic-gate }
6390Sstevel@tonic-gate 
6400Sstevel@tonic-gate /*
6410Sstevel@tonic-gate  * control ops entry point:
6420Sstevel@tonic-gate  *
6430Sstevel@tonic-gate  * Requests handled completely:
6440Sstevel@tonic-gate  *	DDI_CTLOPS_INITCHILD
6450Sstevel@tonic-gate  *	DDI_CTLOPS_UNINITCHILD
6460Sstevel@tonic-gate  *	DDI_CTLOPS_REPORTDEV
6470Sstevel@tonic-gate  *	DDI_CTLOPS_REGSIZE
6480Sstevel@tonic-gate  *	DDI_CTLOPS_NREGS
6490Sstevel@tonic-gate  *
6500Sstevel@tonic-gate  * All others passed to parent.
6510Sstevel@tonic-gate  */
6520Sstevel@tonic-gate static int
ebus_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t op,void * arg,void * result)6530Sstevel@tonic-gate ebus_ctlops(dev_info_t *dip, dev_info_t *rdip,
6540Sstevel@tonic-gate 	ddi_ctl_enum_t op, void *arg, void *result)
6550Sstevel@tonic-gate {
6560Sstevel@tonic-gate #ifdef DEBUG
6570Sstevel@tonic-gate 	ebus_devstate_t *ebus_p = get_ebus_soft_state(ddi_get_instance(dip));
6580Sstevel@tonic-gate #endif
6590Sstevel@tonic-gate 	ebus_regspec_t *ebus_rp;
6600Sstevel@tonic-gate 	int i, n;
6610Sstevel@tonic-gate 	char name[10];
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate 	switch (op) {
6640Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD: {
6650Sstevel@tonic-gate 		dev_info_t *child = (dev_info_t *)arg;
6660Sstevel@tonic-gate 		/*
6670Sstevel@tonic-gate 		 * Set the address portion of the node name based on the
6680Sstevel@tonic-gate 		 * address/offset.
6690Sstevel@tonic-gate 		 */
6700Sstevel@tonic-gate 		DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_INITCHILD: rdip=%s%d\n",
6710Sstevel@tonic-gate 		    ddi_get_name(child), ddi_get_instance(child));
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 		if (ebus_name_child(child, name, 10) != DDI_SUCCESS) {
6740Sstevel@tonic-gate 			DBG(D_CTLOPS, ebus_p, "can't name child\n");
6750Sstevel@tonic-gate 			return (DDI_FAILURE);
6760Sstevel@tonic-gate 		}
6770Sstevel@tonic-gate 
6780Sstevel@tonic-gate 		ddi_set_name_addr(child, name);
6790Sstevel@tonic-gate 		ddi_set_parent_data(child, NULL);
6800Sstevel@tonic-gate 		return (DDI_SUCCESS);
6810Sstevel@tonic-gate 	}
6820Sstevel@tonic-gate 
6830Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
6840Sstevel@tonic-gate 		DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_UNINITCHILD: rdip=%s%d\n",
685*7656SSherry.Moore@Sun.COM 		    ddi_get_name((dev_info_t *)arg),
686*7656SSherry.Moore@Sun.COM 		    ddi_get_instance((dev_info_t *)arg));
6870Sstevel@tonic-gate 		ddi_set_name_addr((dev_info_t *)arg, NULL);
6880Sstevel@tonic-gate 		ddi_remove_minor_node((dev_info_t *)arg, NULL);
6890Sstevel@tonic-gate 		impl_rem_dev_props((dev_info_t *)arg);
6900Sstevel@tonic-gate 		return (DDI_SUCCESS);
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate 		DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_REPORTDEV: rdip=%s%d\n",
695*7656SSherry.Moore@Sun.COM 		    ddi_get_name(rdip), ddi_get_instance(rdip));
6960Sstevel@tonic-gate 		cmn_err(CE_CONT, "?%s%d at %s%d: offset %s\n",
697*7656SSherry.Moore@Sun.COM 		    ddi_driver_name(rdip), ddi_get_instance(rdip),
698*7656SSherry.Moore@Sun.COM 		    ddi_driver_name(dip), ddi_get_instance(dip),
699*7656SSherry.Moore@Sun.COM 		    ddi_get_name_addr(rdip));
7000Sstevel@tonic-gate 		return (DDI_SUCCESS);
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 		DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_REGSIZE: rdip=%s%d\n",
705*7656SSherry.Moore@Sun.COM 		    ddi_get_name(rdip), ddi_get_instance(rdip));
7060Sstevel@tonic-gate 		if (getprop(rdip, "reg", &ebus_rp, &i) != DDI_SUCCESS) {
7070Sstevel@tonic-gate 			DBG(D_CTLOPS, ebus_p, "can't get reg property\n");
7080Sstevel@tonic-gate 			return (DDI_FAILURE);
7090Sstevel@tonic-gate 		}
7100Sstevel@tonic-gate 		n = i / sizeof (ebus_regspec_t);
7110Sstevel@tonic-gate 		if (*(int *)arg < 0 || *(int *)arg >= n) {
7120Sstevel@tonic-gate 			DBG(D_MAP, ebus_p, "rnumber out of range\n");
7130Sstevel@tonic-gate 			kmem_free(ebus_rp, i);
7140Sstevel@tonic-gate 			return (DDI_FAILURE);
7150Sstevel@tonic-gate 		}
7160Sstevel@tonic-gate 		*((off_t *)result) = ebus_rp[*(int *)arg].size;
7170Sstevel@tonic-gate 		kmem_free(ebus_rp, i);
7180Sstevel@tonic-gate 		return (DDI_SUCCESS);
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate 		DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_NREGS: rdip=%s%d\n",
723*7656SSherry.Moore@Sun.COM 		    ddi_get_name(rdip), ddi_get_instance(rdip));
7240Sstevel@tonic-gate 		if (getprop(rdip, "reg", &ebus_rp, &i) != DDI_SUCCESS) {
7250Sstevel@tonic-gate 			DBG(D_CTLOPS, ebus_p, "can't get reg property\n");
7260Sstevel@tonic-gate 			return (DDI_FAILURE);
7270Sstevel@tonic-gate 		}
7280Sstevel@tonic-gate 		*((uint_t *)result) = i / sizeof (ebus_regspec_t);
7290Sstevel@tonic-gate 		kmem_free(ebus_rp, i);
7300Sstevel@tonic-gate 		return (DDI_SUCCESS);
7310Sstevel@tonic-gate 	}
7320Sstevel@tonic-gate 
7330Sstevel@tonic-gate 	/*
7340Sstevel@tonic-gate 	 * Now pass the request up to our parent.
7350Sstevel@tonic-gate 	 */
7360Sstevel@tonic-gate 	DBG2(D_CTLOPS, ebus_p, "passing request to parent: rdip=%s%d\n",
737*7656SSherry.Moore@Sun.COM 	    ddi_get_name(rdip), ddi_get_instance(rdip));
7380Sstevel@tonic-gate 	return (ddi_ctlops(dip, rdip, op, arg, result));
7390Sstevel@tonic-gate }
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate struct ebus_string_to_pil {
7420Sstevel@tonic-gate 	int8_t *string;
7430Sstevel@tonic-gate 	uint32_t pil;
7440Sstevel@tonic-gate };
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate static struct ebus_string_to_pil ebus_name_to_pil[] = {{"SUNW,CS4231", 9},
7470Sstevel@tonic-gate 							{"audio", 9},
7480Sstevel@tonic-gate 							{"fdthree", 8},
7490Sstevel@tonic-gate 							{"floppy", 8},
7500Sstevel@tonic-gate 							{"ecpp", 3},
7510Sstevel@tonic-gate 							{"parallel", 3},
7520Sstevel@tonic-gate 							{"su", 12},
7530Sstevel@tonic-gate 							{"se", 12},
7540Sstevel@tonic-gate 							{"serial", 12},
7550Sstevel@tonic-gate 							{"power", 14}};
7560Sstevel@tonic-gate 
7570Sstevel@tonic-gate static struct ebus_string_to_pil ebus_device_type_to_pil[] = {{"serial", 12},
7580Sstevel@tonic-gate 								{"block", 8}};
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate static int
ebus_intr_ops(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t intr_op,ddi_intr_handle_impl_t * hdlp,void * result)7610Sstevel@tonic-gate ebus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
7620Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, void *result)
7630Sstevel@tonic-gate {
7640Sstevel@tonic-gate #ifdef DEBUG
7650Sstevel@tonic-gate 	ebus_devstate_t *ebus_p = get_ebus_soft_state(ddi_get_instance(dip));
7660Sstevel@tonic-gate #endif
767693Sgovinda 	int32_t		i, max_children, max_device_types, len;
768693Sgovinda 	char		*name_p, *device_type_p;
7690Sstevel@tonic-gate 
770693Sgovinda 	DBG1(D_INTR, ebus_p, "ebus_p 0x%p\n", ebus_p);
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate 	/*
7730Sstevel@tonic-gate 	 * NOTE: These ops below will never be supported in this nexus
7740Sstevel@tonic-gate 	 * driver, hence they always return immediately.
7750Sstevel@tonic-gate 	 */
7760Sstevel@tonic-gate 	switch (intr_op) {
7770Sstevel@tonic-gate 	case DDI_INTROP_GETCAP:
778693Sgovinda 		*(int *)result = DDI_INTR_FLAG_LEVEL;
7790Sstevel@tonic-gate 		return (DDI_SUCCESS);
7803920Srameshc 	case DDI_INTROP_SUPPORTED_TYPES:
7813920Srameshc 		*(int *)result = i_ddi_get_intx_nintrs(rdip) ?
7823920Srameshc 		    DDI_INTR_TYPE_FIXED : 0;
7833920Srameshc 		return (DDI_SUCCESS);
7840Sstevel@tonic-gate 	case DDI_INTROP_SETCAP:
7850Sstevel@tonic-gate 	case DDI_INTROP_SETMASK:
7860Sstevel@tonic-gate 	case DDI_INTROP_CLRMASK:
7870Sstevel@tonic-gate 	case DDI_INTROP_GETPENDING:
7880Sstevel@tonic-gate 		return (DDI_ENOTSUP);
7890Sstevel@tonic-gate 	default:
7900Sstevel@tonic-gate 		break;
7910Sstevel@tonic-gate 	}
7920Sstevel@tonic-gate 
7933920Srameshc 	if (hdlp->ih_pri)
7940Sstevel@tonic-gate 		goto done;
7950Sstevel@tonic-gate 
7960Sstevel@tonic-gate 	/*
7970Sstevel@tonic-gate 	 * This is a hack to set the PIL for the devices under ebus.
7980Sstevel@tonic-gate 	 * We first look up a device by it's specific name, if we can't
7990Sstevel@tonic-gate 	 * match the name, we try and match it's device_type property.
8000Sstevel@tonic-gate 	 * Lastly we default a PIL level of 1.
8010Sstevel@tonic-gate 	 */
8020Sstevel@tonic-gate 	name_p = ddi_node_name(rdip);
8030Sstevel@tonic-gate 	max_children = sizeof (ebus_name_to_pil) /
8040Sstevel@tonic-gate 	    sizeof (struct ebus_string_to_pil);
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate 	for (i = 0; i < max_children; i++) {
8070Sstevel@tonic-gate 		if (strcmp(ebus_name_to_pil[i].string, name_p) == 0) {
8080Sstevel@tonic-gate 			DBG2(D_INTR, ebus_p, "child name %s; match PIL %d\n",
8090Sstevel@tonic-gate 			    ebus_name_to_pil[i].string,
8100Sstevel@tonic-gate 			    ebus_name_to_pil[i].pil);
8110Sstevel@tonic-gate 
812693Sgovinda 			hdlp->ih_pri = ebus_name_to_pil[i].pil;
8130Sstevel@tonic-gate 			goto done;
8140Sstevel@tonic-gate 		}
8150Sstevel@tonic-gate 	}
8160Sstevel@tonic-gate 
817506Scth 	if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
8180Sstevel@tonic-gate 	    "device_type", (caddr_t)&device_type_p, &len) == DDI_SUCCESS) {
8190Sstevel@tonic-gate 
8200Sstevel@tonic-gate 		max_device_types = sizeof (ebus_device_type_to_pil) /
8210Sstevel@tonic-gate 		    sizeof (struct ebus_string_to_pil);
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 		for (i = 0; i < max_device_types; i++) {
8240Sstevel@tonic-gate 			if (strcmp(ebus_device_type_to_pil[i].string,
8250Sstevel@tonic-gate 			    device_type_p) == 0) {
8260Sstevel@tonic-gate 				DBG2(D_INTR, ebus_p, "Device type %s; match "
8270Sstevel@tonic-gate 				    "PIL %d\n", ebus_device_type_to_pil[i].
8280Sstevel@tonic-gate 				    string, ebus_device_type_to_pil[i].pil);
8290Sstevel@tonic-gate 
830693Sgovinda 				hdlp->ih_pri = ebus_device_type_to_pil[i].pil;
8310Sstevel@tonic-gate 				break;
8320Sstevel@tonic-gate 			}
8330Sstevel@tonic-gate 		}
8340Sstevel@tonic-gate 
8350Sstevel@tonic-gate 		kmem_free(device_type_p, len);
8360Sstevel@tonic-gate 	}
8370Sstevel@tonic-gate 
8380Sstevel@tonic-gate 	/*
8390Sstevel@tonic-gate 	 * If we get here, we need to set a default value
8400Sstevel@tonic-gate 	 * for the PIL.
8410Sstevel@tonic-gate 	 */
842693Sgovinda 	if (hdlp->ih_pri == 0) {
843693Sgovinda 		hdlp->ih_pri = 1;
8440Sstevel@tonic-gate 
8450Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d assigning default interrupt level %d "
846693Sgovinda 		    "for device %s%d", ddi_driver_name(dip),
847693Sgovinda 		    ddi_get_instance(dip), hdlp->ih_pri, ddi_driver_name(rdip),
848693Sgovinda 		    ddi_get_instance(rdip));
8490Sstevel@tonic-gate 	}
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate done:
8520Sstevel@tonic-gate 	/* Pass up the request to our parent. */
8530Sstevel@tonic-gate 	return (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result));
8540Sstevel@tonic-gate }
8550Sstevel@tonic-gate 
856558Sjasonwu /*
857558Sjasonwu  * ebus_config: setup pci config space registers:
858558Sjasonwu  *     enable bus mastering, memory access and error reporting
859558Sjasonwu  */
8600Sstevel@tonic-gate static int
ebus_config(ebus_devstate_t * ebus_p)8610Sstevel@tonic-gate ebus_config(ebus_devstate_t *ebus_p)
8620Sstevel@tonic-gate {
8630Sstevel@tonic-gate 	ddi_acc_handle_t conf_handle;
8640Sstevel@tonic-gate 	uint16_t comm;
865558Sjasonwu 	dev_info_t *dip = ebus_p->dip;
866558Sjasonwu 	char *devtype_str;
867558Sjasonwu 	int devtype_len;
868558Sjasonwu 
869558Sjasonwu 	if (ddi_getlongprop(DDI_DEV_T_ANY, ddi_get_parent(dip),
870*7656SSherry.Moore@Sun.COM 	    DDI_PROP_DONTPASS, "device_type", (caddr_t)&devtype_str,
871*7656SSherry.Moore@Sun.COM 	    &devtype_len) != DDI_SUCCESS) {
872558Sjasonwu 		cmn_err(CE_WARN, "Can't get %s device_type property",
873558Sjasonwu 		    ddi_get_name(ddi_get_parent(dip)));
874558Sjasonwu 
875558Sjasonwu 		return (DDI_FAILURE);
876558Sjasonwu 	}
877558Sjasonwu 
878558Sjasonwu 	comm = strcmp(devtype_str, "pci");
879558Sjasonwu 	kmem_free(devtype_str, devtype_len);
880558Sjasonwu 
881558Sjasonwu 	if (comm)
882558Sjasonwu 		return (DDI_SUCCESS);
8830Sstevel@tonic-gate 
8840Sstevel@tonic-gate 	/*
8850Sstevel@tonic-gate 	 * Make sure the master enable and memory access enable
8860Sstevel@tonic-gate 	 * bits are set in the config command register.
8870Sstevel@tonic-gate 	 */
8880Sstevel@tonic-gate 	if (pci_config_setup(ebus_p->dip, &conf_handle) != DDI_SUCCESS)
889558Sjasonwu 		return (DDI_FAILURE);
8900Sstevel@tonic-gate 
8910Sstevel@tonic-gate 	comm = pci_config_get16(conf_handle, PCI_CONF_COMM),
8920Sstevel@tonic-gate #ifdef DEBUG
8930Sstevel@tonic-gate 	    DBG1(D_MAP, ebus_p, "command register was 0x%x\n", comm);
8940Sstevel@tonic-gate #endif
8950Sstevel@tonic-gate 	comm |= (PCI_COMM_ME|PCI_COMM_MAE|PCI_COMM_SERR_ENABLE|
8960Sstevel@tonic-gate 	    PCI_COMM_PARITY_DETECT);
8970Sstevel@tonic-gate 	pci_config_put16(conf_handle, PCI_CONF_COMM, comm),
8980Sstevel@tonic-gate #ifdef DEBUG
8990Sstevel@tonic-gate 	    DBG1(D_MAP, ebus_p, "command register is now 0x%x\n", comm);
9000Sstevel@tonic-gate #endif
9010Sstevel@tonic-gate 	pci_config_put8(conf_handle, PCI_CONF_CACHE_LINESZ,
9020Sstevel@tonic-gate 	    (uchar_t)ebus_cache_line_size);
9030Sstevel@tonic-gate 	pci_config_put8(conf_handle, PCI_CONF_LATENCY_TIMER,
9040Sstevel@tonic-gate 	    (uchar_t)ebus_latency_timer);
9050Sstevel@tonic-gate 	pci_config_teardown(&conf_handle);
906558Sjasonwu 	return (DDI_SUCCESS);
9070Sstevel@tonic-gate }
9080Sstevel@tonic-gate 
9090Sstevel@tonic-gate #ifdef DEBUG
9100Sstevel@tonic-gate extern void prom_printf(const char *, ...);
9110Sstevel@tonic-gate 
9120Sstevel@tonic-gate static void
ebus_debug(uint_t flag,ebus_devstate_t * ebus_p,char * fmt,uintptr_t a1,uintptr_t a2,uintptr_t a3,uintptr_t a4,uintptr_t a5)9130Sstevel@tonic-gate ebus_debug(uint_t flag, ebus_devstate_t *ebus_p, char *fmt,
9140Sstevel@tonic-gate 	uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
9150Sstevel@tonic-gate {
9160Sstevel@tonic-gate 	char *s;
9170Sstevel@tonic-gate 
9180Sstevel@tonic-gate 	if (ebus_debug_flags & flag) {
9190Sstevel@tonic-gate 		switch (flag) {
9200Sstevel@tonic-gate 		case D_ATTACH:
9210Sstevel@tonic-gate 			s = "attach"; break;
9220Sstevel@tonic-gate 		case D_DETACH:
9230Sstevel@tonic-gate 			s = "detach"; break;
9240Sstevel@tonic-gate 		case D_MAP:
9250Sstevel@tonic-gate 			s = "map"; break;
9260Sstevel@tonic-gate 		case D_CTLOPS:
9270Sstevel@tonic-gate 			s = "ctlops"; break;
9280Sstevel@tonic-gate 		case D_INTR:
9290Sstevel@tonic-gate 			s = "intr"; break;
9300Sstevel@tonic-gate 		}
9310Sstevel@tonic-gate 		if (ebus_p)
9320Sstevel@tonic-gate 			cmn_err(CE_CONT, "%s%d: %s: ",
933*7656SSherry.Moore@Sun.COM 			    ddi_get_name(ebus_p->dip),
934*7656SSherry.Moore@Sun.COM 			    ddi_get_instance(ebus_p->dip), s);
9350Sstevel@tonic-gate 		else
9360Sstevel@tonic-gate 			cmn_err(CE_CONT, "ebus: ");
9370Sstevel@tonic-gate 		cmn_err(CE_CONT, fmt, a1, a2, a3, a4, a5);
9380Sstevel@tonic-gate 	}
9390Sstevel@tonic-gate }
940558Sjasonwu 
941558Sjasonwu static void
ebus_vreg_dump(ebus_devstate_t * ebus_p,vregspec_t * rp)942558Sjasonwu ebus_vreg_dump(ebus_devstate_t *ebus_p, vregspec_t *rp)
943558Sjasonwu {
944558Sjasonwu 	if (ebus_p->ebus_paddr_cells == 3) {
945558Sjasonwu 		DBG5(D_MAP, ebus_p, "(%x,%x,%x)(%x,%x)\n",
946558Sjasonwu 		    rp->pci_regspec.pci_phys_hi,
947558Sjasonwu 		    rp->pci_regspec.pci_phys_mid,
948558Sjasonwu 		    rp->pci_regspec.pci_phys_low,
949558Sjasonwu 		    rp->pci_regspec.pci_size_hi,
950558Sjasonwu 		    rp->pci_regspec.pci_size_low);
951558Sjasonwu 	} else if (ebus_p->ebus_paddr_cells == 2) {
952558Sjasonwu 		DBG3(D_MAP, ebus_p, "%x,%x,%x\n",
953558Sjasonwu 		    rp->jbus_regspec.regspec_bustype,
954558Sjasonwu 		    rp->jbus_regspec.regspec_addr,
955558Sjasonwu 		    rp->jbus_regspec.regspec_size);
956558Sjasonwu 	}
957558Sjasonwu }
958558Sjasonwu #endif /* DEBUG */
9590Sstevel@tonic-gate 
9600Sstevel@tonic-gate /* ARGSUSED3 */
9610Sstevel@tonic-gate static int
ebus_open(dev_t * devp,int flags,int otyp,cred_t * credp)9620Sstevel@tonic-gate ebus_open(dev_t *devp, int flags, int otyp, cred_t *credp)
9630Sstevel@tonic-gate {
9640Sstevel@tonic-gate 	ebus_devstate_t *ebus_p;
9650Sstevel@tonic-gate 
9660Sstevel@tonic-gate 	/*
9670Sstevel@tonic-gate 	 * Make sure the open is for the right file type.
9680Sstevel@tonic-gate 	 */
9690Sstevel@tonic-gate 	if (otyp != OTYP_CHR)
9700Sstevel@tonic-gate 		return (EINVAL);
9710Sstevel@tonic-gate 
9720Sstevel@tonic-gate 	/*
9730Sstevel@tonic-gate 	 * Get the soft state structure for the device.
9740Sstevel@tonic-gate 	 */
9750Sstevel@tonic-gate 	ebus_p = get_ebus_soft_state(getminor(*devp));
9760Sstevel@tonic-gate 	if (ebus_p == NULL)
9770Sstevel@tonic-gate 		return (ENXIO);
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate 	/*
9800Sstevel@tonic-gate 	 * Handle the open by tracking the device state.
9810Sstevel@tonic-gate 	 */
9820Sstevel@tonic-gate 	mutex_enter(&ebus_p->ebus_mutex);
9830Sstevel@tonic-gate 	if (flags & FEXCL) {
9840Sstevel@tonic-gate 		if (ebus_p->ebus_soft_state != EBUS_SOFT_STATE_CLOSED) {
9850Sstevel@tonic-gate 			mutex_exit(&ebus_p->ebus_mutex);
9860Sstevel@tonic-gate 			return (EBUSY);
9870Sstevel@tonic-gate 		}
9880Sstevel@tonic-gate 		ebus_p->ebus_soft_state = EBUS_SOFT_STATE_OPEN_EXCL;
9890Sstevel@tonic-gate 	} else {
9900Sstevel@tonic-gate 		if (ebus_p->ebus_soft_state == EBUS_SOFT_STATE_OPEN_EXCL) {
9910Sstevel@tonic-gate 			mutex_exit(&ebus_p->ebus_mutex);
9920Sstevel@tonic-gate 			return (EBUSY);
9930Sstevel@tonic-gate 		}
9940Sstevel@tonic-gate 		ebus_p->ebus_soft_state = EBUS_SOFT_STATE_OPEN;
9950Sstevel@tonic-gate 	}
9960Sstevel@tonic-gate 	mutex_exit(&ebus_p->ebus_mutex);
9970Sstevel@tonic-gate 	return (0);
9980Sstevel@tonic-gate }
9990Sstevel@tonic-gate 
10000Sstevel@tonic-gate 
10010Sstevel@tonic-gate /* ARGSUSED */
10020Sstevel@tonic-gate static int
ebus_close(dev_t dev,int flags,int otyp,cred_t * credp)10030Sstevel@tonic-gate ebus_close(dev_t dev, int flags, int otyp, cred_t *credp)
10040Sstevel@tonic-gate {
10050Sstevel@tonic-gate 	ebus_devstate_t *ebus_p;
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate 	if (otyp != OTYP_CHR)
10080Sstevel@tonic-gate 		return (EINVAL);
10090Sstevel@tonic-gate 
10100Sstevel@tonic-gate 	ebus_p = get_ebus_soft_state(getminor(dev));
10110Sstevel@tonic-gate 	if (ebus_p == NULL)
10120Sstevel@tonic-gate 		return (ENXIO);
10130Sstevel@tonic-gate 
10140Sstevel@tonic-gate 	mutex_enter(&ebus_p->ebus_mutex);
10150Sstevel@tonic-gate 	ebus_p->ebus_soft_state = EBUS_SOFT_STATE_CLOSED;
10160Sstevel@tonic-gate 	mutex_exit(&ebus_p->ebus_mutex);
10170Sstevel@tonic-gate 	return (0);
10180Sstevel@tonic-gate }
10190Sstevel@tonic-gate 
10200Sstevel@tonic-gate 
10210Sstevel@tonic-gate /*
10220Sstevel@tonic-gate  * ebus_ioctl: devctl hotplug controls
10230Sstevel@tonic-gate  */
10240Sstevel@tonic-gate /* ARGSUSED */
10250Sstevel@tonic-gate static int
ebus_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)10260Sstevel@tonic-gate ebus_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
10270Sstevel@tonic-gate 	int *rvalp)
10280Sstevel@tonic-gate {
10290Sstevel@tonic-gate 	ebus_devstate_t *ebus_p;
10300Sstevel@tonic-gate 	dev_info_t *self;
10310Sstevel@tonic-gate 	struct devctl_iocdata *dcp;
10320Sstevel@tonic-gate 	uint_t bus_state;
10330Sstevel@tonic-gate 	int rv = 0;
10340Sstevel@tonic-gate 
10350Sstevel@tonic-gate 	ebus_p = get_ebus_soft_state(getminor(dev));
10360Sstevel@tonic-gate 	if (ebus_p == NULL)
10370Sstevel@tonic-gate 		return (ENXIO);
10380Sstevel@tonic-gate 
10390Sstevel@tonic-gate 	self = ebus_p->dip;
10400Sstevel@tonic-gate 
10410Sstevel@tonic-gate 	/*
10420Sstevel@tonic-gate 	 * We can use the generic implementation for these ioctls
10430Sstevel@tonic-gate 	 */
10440Sstevel@tonic-gate 	switch (cmd) {
10450Sstevel@tonic-gate 	case DEVCTL_DEVICE_GETSTATE:
10460Sstevel@tonic-gate 	case DEVCTL_DEVICE_ONLINE:
10470Sstevel@tonic-gate 	case DEVCTL_DEVICE_OFFLINE:
10480Sstevel@tonic-gate 	case DEVCTL_BUS_GETSTATE:
10490Sstevel@tonic-gate 		return (ndi_devctl_ioctl(self, cmd, arg, mode, 0));
10500Sstevel@tonic-gate 	}
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate 	/*
10530Sstevel@tonic-gate 	 * read devctl ioctl data
10540Sstevel@tonic-gate 	 */
10550Sstevel@tonic-gate 	if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS)
10560Sstevel@tonic-gate 		return (EFAULT);
10570Sstevel@tonic-gate 
10580Sstevel@tonic-gate 	switch (cmd) {
10590Sstevel@tonic-gate 
10600Sstevel@tonic-gate 	case DEVCTL_DEVICE_RESET:
10610Sstevel@tonic-gate 		rv = ENOTSUP;
10620Sstevel@tonic-gate 		break;
10630Sstevel@tonic-gate 
10640Sstevel@tonic-gate 	case DEVCTL_BUS_QUIESCE:
10650Sstevel@tonic-gate 		if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
10660Sstevel@tonic-gate 			if (bus_state == BUS_QUIESCED)
10670Sstevel@tonic-gate 				break;
10680Sstevel@tonic-gate 		(void) ndi_set_bus_state(self, BUS_QUIESCED);
10690Sstevel@tonic-gate 		break;
10700Sstevel@tonic-gate 
10710Sstevel@tonic-gate 	case DEVCTL_BUS_UNQUIESCE:
10720Sstevel@tonic-gate 		if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
10730Sstevel@tonic-gate 			if (bus_state == BUS_ACTIVE)
10740Sstevel@tonic-gate 				break;
10750Sstevel@tonic-gate 		(void) ndi_set_bus_state(self, BUS_ACTIVE);
10760Sstevel@tonic-gate 		break;
10770Sstevel@tonic-gate 
10780Sstevel@tonic-gate 	case DEVCTL_BUS_RESET:
10790Sstevel@tonic-gate 		rv = ENOTSUP;
10800Sstevel@tonic-gate 		break;
10810Sstevel@tonic-gate 
10820Sstevel@tonic-gate 	case DEVCTL_BUS_RESETALL:
10830Sstevel@tonic-gate 		rv = ENOTSUP;
10840Sstevel@tonic-gate 		break;
10850Sstevel@tonic-gate 
10860Sstevel@tonic-gate 	default:
10870Sstevel@tonic-gate 		rv = ENOTTY;
10880Sstevel@tonic-gate 	}
10890Sstevel@tonic-gate 
10900Sstevel@tonic-gate 	ndi_dc_freehdl(dcp);
10910Sstevel@tonic-gate 	return (rv);
10920Sstevel@tonic-gate }
1093