xref: /onnv-gate/usr/src/uts/sun4u/io/pci/pci_pci.c (revision 1624:16ffeb79fcfc)
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
5*1624Spjha  * Common Development and Distribution License (the "License").
6*1624Spjha  * 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*1624Spjha  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  *	Sun4u PCI to PCI bus bridge nexus driver
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/conf.h>
330Sstevel@tonic-gate #include <sys/kmem.h>
340Sstevel@tonic-gate #include <sys/debug.h>
350Sstevel@tonic-gate #include <sys/modctl.h>
360Sstevel@tonic-gate #include <sys/autoconf.h>
370Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
380Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
390Sstevel@tonic-gate #include <sys/pci.h>
40*1624Spjha #include <sys/pci_cap.h>
410Sstevel@tonic-gate #include <sys/pci/pci_nexus.h>
420Sstevel@tonic-gate #include <sys/pci/pci_regs.h>
430Sstevel@tonic-gate #include <sys/ddi.h>
440Sstevel@tonic-gate #include <sys/sunndi.h>
450Sstevel@tonic-gate #include <sys/sunddi.h>
460Sstevel@tonic-gate #include <sys/fm/protocol.h>
470Sstevel@tonic-gate #include <sys/ddifm.h>
480Sstevel@tonic-gate #include <sys/pci/pci_pwr.h>
490Sstevel@tonic-gate #include <sys/pci/pci_debug.h>
500Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h>
510Sstevel@tonic-gate #include <sys/open.h>
520Sstevel@tonic-gate #include <sys/stat.h>
530Sstevel@tonic-gate #include <sys/file.h>
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	NUM_LOGICAL_SLOTS	32
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	PPB_RANGE_LEN 2
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #define	PPB_32BIT_IO 1
600Sstevel@tonic-gate #define	PPB_32bit_MEM 1
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define	PPB_MEMGRAIN 0x100000
630Sstevel@tonic-gate #define	PPB_IOGRAIN 0x1000
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #define	PPB_16bit_IOADDR(addr) ((uint16_t)(((uint8_t)(addr) & 0xF0) << 8))
660Sstevel@tonic-gate #define	PPB_LADDR(lo, hi) (((uint16_t)(hi) << 16) | (uint16_t)(lo))
670Sstevel@tonic-gate #define	PPB_32bit_MEMADDR(addr) (PPB_LADDR(0, ((uint16_t)(addr) & 0xFFF0)))
680Sstevel@tonic-gate 
690Sstevel@tonic-gate typedef struct	slot_table {
700Sstevel@tonic-gate 	uchar_t		bus_id[128];
710Sstevel@tonic-gate 	uchar_t		slot_name[32];
720Sstevel@tonic-gate 	uint8_t		device_no;
730Sstevel@tonic-gate 	uint8_t		phys_slot_num;
740Sstevel@tonic-gate } slot_table_t;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * The following typedef is used to represent an entry in the "ranges"
780Sstevel@tonic-gate  * property of a device node.
790Sstevel@tonic-gate  */
800Sstevel@tonic-gate typedef struct {
810Sstevel@tonic-gate 	uint32_t child_high;
820Sstevel@tonic-gate 	uint32_t child_mid;
830Sstevel@tonic-gate 	uint32_t child_low;
840Sstevel@tonic-gate 	uint32_t parent_high;
850Sstevel@tonic-gate 	uint32_t parent_mid;
860Sstevel@tonic-gate 	uint32_t parent_low;
870Sstevel@tonic-gate 	uint32_t size_high;
880Sstevel@tonic-gate 	uint32_t size_low;
890Sstevel@tonic-gate } ppb_ranges_t;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate  * The variable controls the default setting of the command register
930Sstevel@tonic-gate  * for pci devices.  See ppb_initchild() for details.
940Sstevel@tonic-gate  */
950Sstevel@tonic-gate static ushort_t ppb_command_default = PCI_COMM_SERR_ENABLE |
960Sstevel@tonic-gate 					PCI_COMM_WAIT_CYC_ENAB |
970Sstevel@tonic-gate 					PCI_COMM_PARITY_DETECT |
980Sstevel@tonic-gate 					PCI_COMM_ME |
990Sstevel@tonic-gate 					PCI_COMM_MAE |
1000Sstevel@tonic-gate 					PCI_COMM_IO;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate static int ppb_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *,
1030Sstevel@tonic-gate 	off_t, off_t, caddr_t *);
1040Sstevel@tonic-gate static int ppb_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
1050Sstevel@tonic-gate 	void *, void *);
1060Sstevel@tonic-gate static int ppb_intr_ops(dev_info_t *dip, dev_info_t *rdip,
1070Sstevel@tonic-gate 	ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate /*
1100Sstevel@tonic-gate  * fm_init busop to initialize our children
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate static int ppb_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap,
1130Sstevel@tonic-gate 		ddi_iblock_cookie_t *ibc);
1140Sstevel@tonic-gate static void ppb_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle);
1150Sstevel@tonic-gate static void ppb_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle);
1160Sstevel@tonic-gate static int ppb_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op,
1170Sstevel@tonic-gate     void *arg, void *result);
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate struct bus_ops ppb_bus_ops = {
1200Sstevel@tonic-gate 	BUSO_REV,
1210Sstevel@tonic-gate 	ppb_bus_map,
1220Sstevel@tonic-gate 	0,
1230Sstevel@tonic-gate 	0,
1240Sstevel@tonic-gate 	0,
1250Sstevel@tonic-gate 	i_ddi_map_fault,
1260Sstevel@tonic-gate 	ddi_dma_map,
1270Sstevel@tonic-gate 	ddi_dma_allochdl,
1280Sstevel@tonic-gate 	ddi_dma_freehdl,
1290Sstevel@tonic-gate 	ddi_dma_bindhdl,
1300Sstevel@tonic-gate 	ddi_dma_unbindhdl,
1310Sstevel@tonic-gate 	ddi_dma_flush,
1320Sstevel@tonic-gate 	ddi_dma_win,
1330Sstevel@tonic-gate 	ddi_dma_mctl,
1340Sstevel@tonic-gate 	ppb_ctlops,
1350Sstevel@tonic-gate 	ddi_bus_prop_op,
1360Sstevel@tonic-gate 	ndi_busop_get_eventcookie,	/* (*bus_get_eventcookie)();    */
1370Sstevel@tonic-gate 	ndi_busop_add_eventcall,	/* (*bus_add_eventcall)();	*/
1380Sstevel@tonic-gate 	ndi_busop_remove_eventcall,	/* (*bus_remove_eventcall)();   */
1390Sstevel@tonic-gate 	ndi_post_event,			/* (*bus_post_event)();		*/
1400Sstevel@tonic-gate 	0,				/* (*bus_intr_ctl)();		*/
1410Sstevel@tonic-gate 	0,				/* (*bus_config)(); 		*/
1420Sstevel@tonic-gate 	0,				/* (*bus_unconfig)(); 		*/
1430Sstevel@tonic-gate 	ppb_fm_init_child,		/* (*bus_fm_init)(); 		*/
1440Sstevel@tonic-gate 	NULL,				/* (*bus_fm_fini)(); 		*/
1450Sstevel@tonic-gate 	ppb_bus_enter,			/* (*bus_enter)()		*/
1460Sstevel@tonic-gate 	ppb_bus_exit,			/* (*bus_exit)()		*/
1470Sstevel@tonic-gate 	ppb_bus_power,			/* (*bus_power)()		*/
1480Sstevel@tonic-gate 	ppb_intr_ops			/* (*bus_intr_op)(); 		*/
1490Sstevel@tonic-gate };
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate static int ppb_open(dev_t *devp, int flags, int otyp, cred_t *credp);
1520Sstevel@tonic-gate static int ppb_close(dev_t dev, int flags, int otyp, cred_t *credp);
1530Sstevel@tonic-gate static int ppb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
1540Sstevel@tonic-gate 						cred_t *credp, int *rvalp);
1550Sstevel@tonic-gate static int ppb_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
1560Sstevel@tonic-gate     int flags, char *name, caddr_t valuep, int *lengthp);
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate static struct cb_ops ppb_cb_ops = {
1590Sstevel@tonic-gate 	ppb_open,			/* open */
1600Sstevel@tonic-gate 	ppb_close,			/* close */
1610Sstevel@tonic-gate 	nulldev,			/* strategy */
1620Sstevel@tonic-gate 	nulldev,			/* print */
1630Sstevel@tonic-gate 	nulldev,			/* dump */
1640Sstevel@tonic-gate 	nulldev,			/* read */
1650Sstevel@tonic-gate 	nulldev,			/* write */
1660Sstevel@tonic-gate 	ppb_ioctl,			/* ioctl */
1670Sstevel@tonic-gate 	nodev,				/* devmap */
1680Sstevel@tonic-gate 	nodev,				/* mmap */
1690Sstevel@tonic-gate 	nodev,				/* segmap */
1700Sstevel@tonic-gate 	nochpoll,			/* poll */
1710Sstevel@tonic-gate 	ppb_prop_op,			/* cb_prop_op */
1720Sstevel@tonic-gate 	NULL,				/* streamtab */
1730Sstevel@tonic-gate 	D_NEW | D_MP | D_HOTPLUG,	/* Driver compatibility flag */
1740Sstevel@tonic-gate 	CB_REV,				/* rev */
1750Sstevel@tonic-gate 	nodev,				/* int (*cb_aread)() */
1760Sstevel@tonic-gate 	nodev				/* int (*cb_awrite)() */
1770Sstevel@tonic-gate };
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate static int ppb_probe(dev_info_t *);
1800Sstevel@tonic-gate static int ppb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
1810Sstevel@tonic-gate static int ppb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
1820Sstevel@tonic-gate static int ppb_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
1830Sstevel@tonic-gate     void *arg, void **result);
1840Sstevel@tonic-gate static int ppb_pwr(dev_info_t *dip, int component, int level);
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate struct dev_ops ppb_ops = {
1870Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev */
1880Sstevel@tonic-gate 	0,			/* refcnt  */
1890Sstevel@tonic-gate 	ppb_info,		/* info */
1900Sstevel@tonic-gate 	nulldev,		/* identify */
1910Sstevel@tonic-gate 	ppb_probe,		/* probe */
1920Sstevel@tonic-gate 	ppb_attach,		/* attach */
1930Sstevel@tonic-gate 	ppb_detach,		/* detach */
1940Sstevel@tonic-gate 	nulldev,		/* reset */
1950Sstevel@tonic-gate 	&ppb_cb_ops,		/* driver operations */
1960Sstevel@tonic-gate 	&ppb_bus_ops,		/* bus operations */
1970Sstevel@tonic-gate 	ppb_pwr
1980Sstevel@tonic-gate };
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * Module linkage information for the kernel.
2020Sstevel@tonic-gate  */
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate static struct modldrv modldrv = {
2050Sstevel@tonic-gate 	&mod_driverops, /* Type of module */
206506Scth 	"Standard PCI to PCI bridge nexus driver %I%",
2070Sstevel@tonic-gate 	&ppb_ops,	/* driver ops */
2080Sstevel@tonic-gate };
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate static struct modlinkage modlinkage = {
2110Sstevel@tonic-gate 	MODREV_1,
2120Sstevel@tonic-gate 	(void *)&modldrv,
2130Sstevel@tonic-gate 	NULL
2140Sstevel@tonic-gate };
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate /*
2170Sstevel@tonic-gate  * soft state pointer and structure template:
2180Sstevel@tonic-gate  */
2190Sstevel@tonic-gate static void *ppb_state;
2200Sstevel@tonic-gate 
221946Smathue struct ppb_cfg_state {
2220Sstevel@tonic-gate 	dev_info_t *dip;
2230Sstevel@tonic-gate 	ushort_t command;
2240Sstevel@tonic-gate 	uchar_t cache_line_size;
2250Sstevel@tonic-gate 	uchar_t latency_timer;
2260Sstevel@tonic-gate 	uchar_t header_type;
2270Sstevel@tonic-gate 	uchar_t sec_latency_timer;
2280Sstevel@tonic-gate 	ushort_t bridge_control;
2290Sstevel@tonic-gate };
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate typedef struct {
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 	dev_info_t *dip;
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	/*
2360Sstevel@tonic-gate 	 * configuration register state for the bus:
2370Sstevel@tonic-gate 	 */
2380Sstevel@tonic-gate 	uchar_t ppb_cache_line_size;
2390Sstevel@tonic-gate 	uchar_t ppb_latency_timer;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	/*
2420Sstevel@tonic-gate 	 * PM support
2430Sstevel@tonic-gate 	 */
2440Sstevel@tonic-gate 	ddi_acc_handle_t	ppb_conf_hdl;
245*1624Spjha 	uint16_t		ppb_pm_cap_ptr;
2460Sstevel@tonic-gate 	pci_pwr_t		*ppb_pwr_p;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	/*
2490Sstevel@tonic-gate 	 * HP support
2500Sstevel@tonic-gate 	 */
2510Sstevel@tonic-gate 	boolean_t		hotplug_capable;
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	kmutex_t ppb_mutex;
2540Sstevel@tonic-gate 	uint_t ppb_soft_state;
2550Sstevel@tonic-gate #define	PPB_SOFT_STATE_CLOSED		0x00
2560Sstevel@tonic-gate #define	PPB_SOFT_STATE_OPEN		0x01
2570Sstevel@tonic-gate #define	PPB_SOFT_STATE_OPEN_EXCL	0x02
2580Sstevel@tonic-gate 	int fm_cap;
2590Sstevel@tonic-gate 	ddi_iblock_cookie_t fm_ibc;
2600Sstevel@tonic-gate } ppb_devstate_t;
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate /*
2630Sstevel@tonic-gate  * The following variable enables a workaround for the following obp bug:
2640Sstevel@tonic-gate  *
2650Sstevel@tonic-gate  *	1234181 - obp should set latency timer registers in pci
2660Sstevel@tonic-gate  *		configuration header
2670Sstevel@tonic-gate  *
2680Sstevel@tonic-gate  * Until this bug gets fixed in the obp, the following workaround should
2690Sstevel@tonic-gate  * be enabled.
2700Sstevel@tonic-gate  */
2710Sstevel@tonic-gate static uint_t ppb_set_latency_timer_register = 1;
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate /*
2740Sstevel@tonic-gate  * The following variable enables a workaround for an obp bug to be
2750Sstevel@tonic-gate  * submitted.  A bug requesting a workaround fof this problem has
2760Sstevel@tonic-gate  * been filed:
2770Sstevel@tonic-gate  *
2780Sstevel@tonic-gate  *	1235094 - need workarounds on positron nexus drivers to set cache
2790Sstevel@tonic-gate  *		line size registers
2800Sstevel@tonic-gate  *
2810Sstevel@tonic-gate  * Until this bug gets fixed in the obp, the following workaround should
2820Sstevel@tonic-gate  * be enabled.
2830Sstevel@tonic-gate  */
2840Sstevel@tonic-gate static uint_t ppb_set_cache_line_size_register = 1;
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate  * forward function declarations:
2880Sstevel@tonic-gate  */
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate  * FMA error callback
2920Sstevel@tonic-gate  * Register error handling callback with our parent. We will just call
2930Sstevel@tonic-gate  * our children's error callbacks and return their status.
2940Sstevel@tonic-gate  */
2950Sstevel@tonic-gate static int ppb_err_callback(dev_info_t *dip, ddi_fm_error_t *derr,
2960Sstevel@tonic-gate 		const void *impl_data);
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate /*
2990Sstevel@tonic-gate  * init/fini routines to alloc/dealloc fm structures and
3000Sstevel@tonic-gate  * register/unregister our callback.
3010Sstevel@tonic-gate  */
3020Sstevel@tonic-gate static void ppb_fm_init(ppb_devstate_t *ppb_p);
3030Sstevel@tonic-gate static void ppb_fm_fini(ppb_devstate_t *ppb_p);
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate static void ppb_removechild(dev_info_t *);
3060Sstevel@tonic-gate static int ppb_initchild(dev_info_t *child);
3070Sstevel@tonic-gate static dev_info_t *get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
3080Sstevel@tonic-gate static void ppb_pwr_setup(ppb_devstate_t *ppb, dev_info_t *dip);
3090Sstevel@tonic-gate static void ppb_pwr_teardown(ppb_devstate_t *ppb, dev_info_t *dip);
3100Sstevel@tonic-gate static void ppb_init_hotplug(ppb_devstate_t *ppb);
3110Sstevel@tonic-gate static void ppb_create_ranges_prop(dev_info_t *, ddi_acc_handle_t);
312964Smathue uint64_t pci_debug_flags = 0;
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate int
3150Sstevel@tonic-gate _init(void)
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate 	int e;
3180Sstevel@tonic-gate 	if ((e = ddi_soft_state_init(&ppb_state, sizeof (ppb_devstate_t),
3190Sstevel@tonic-gate 	    1)) == 0 && (e = mod_install(&modlinkage)) != 0)
3200Sstevel@tonic-gate 		ddi_soft_state_fini(&ppb_state);
3210Sstevel@tonic-gate 	return (e);
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate int
3250Sstevel@tonic-gate _fini(void)
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate 	int e;
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 	if ((e = mod_remove(&modlinkage)) == 0)
3300Sstevel@tonic-gate 		ddi_soft_state_fini(&ppb_state);
3310Sstevel@tonic-gate 	return (e);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate int
3350Sstevel@tonic-gate _info(struct modinfo *modinfop)
3360Sstevel@tonic-gate {
3370Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
3380Sstevel@tonic-gate }
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate /*ARGSUSED*/
3410Sstevel@tonic-gate static int
3420Sstevel@tonic-gate ppb_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
3430Sstevel@tonic-gate {
3440Sstevel@tonic-gate 	ppb_devstate_t *ppb_p;	/* per ppb state pointer */
3450Sstevel@tonic-gate 	minor_t		minor = getminor((dev_t)arg);
3460Sstevel@tonic-gate 	int		instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate 	ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
3490Sstevel@tonic-gate 	    instance);
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	switch (infocmd) {
3520Sstevel@tonic-gate 	default:
3530Sstevel@tonic-gate 		return (DDI_FAILURE);
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
356946Smathue 		*result = (void *)(uintptr_t)instance;
3570Sstevel@tonic-gate 		return (DDI_SUCCESS);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
3600Sstevel@tonic-gate 		if (ppb_p == NULL)
3610Sstevel@tonic-gate 			return (DDI_FAILURE);
3620Sstevel@tonic-gate 		*result = (void *)ppb_p->dip;
3630Sstevel@tonic-gate 		return (DDI_SUCCESS);
3640Sstevel@tonic-gate 	}
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate /*ARGSUSED*/
3680Sstevel@tonic-gate static int
3690Sstevel@tonic-gate ppb_probe(register dev_info_t *devi)
3700Sstevel@tonic-gate {
3710Sstevel@tonic-gate 	return (DDI_PROBE_SUCCESS);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate /*ARGSUSED*/
3750Sstevel@tonic-gate static int
3760Sstevel@tonic-gate ppb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
3770Sstevel@tonic-gate {
3780Sstevel@tonic-gate 	int instance;
3790Sstevel@tonic-gate 	ppb_devstate_t *ppb;
3800Sstevel@tonic-gate 	ddi_acc_handle_t config_handle;
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	switch (cmd) {
3830Sstevel@tonic-gate 	case DDI_ATTACH:
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 		/*
3860Sstevel@tonic-gate 		 * Make sure the "device_type" property exists.
3870Sstevel@tonic-gate 		 */
3880Sstevel@tonic-gate 		(void) ddi_prop_update_string(DDI_DEV_T_NONE, devi,
3890Sstevel@tonic-gate 		    "device_type", "pci");
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 		/*
3920Sstevel@tonic-gate 		 * Allocate and get soft state structure.
3930Sstevel@tonic-gate 		 */
3940Sstevel@tonic-gate 		instance = ddi_get_instance(devi);
3950Sstevel@tonic-gate 		if (ddi_soft_state_zalloc(ppb_state, instance) != DDI_SUCCESS)
3960Sstevel@tonic-gate 			return (DDI_FAILURE);
3970Sstevel@tonic-gate 		ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, instance);
3980Sstevel@tonic-gate 		ppb->dip = devi;
3990Sstevel@tonic-gate 		mutex_init(&ppb->ppb_mutex, NULL, MUTEX_DRIVER, NULL);
4000Sstevel@tonic-gate 		ppb->ppb_soft_state = PPB_SOFT_STATE_CLOSED;
4010Sstevel@tonic-gate 		if (pci_config_setup(devi, &config_handle) != DDI_SUCCESS) {
4020Sstevel@tonic-gate 			mutex_destroy(&ppb->ppb_mutex);
4030Sstevel@tonic-gate 			ddi_soft_state_free(ppb_state, instance);
4040Sstevel@tonic-gate 			return (DDI_FAILURE);
4050Sstevel@tonic-gate 		}
4060Sstevel@tonic-gate 		ppb_pwr_setup(ppb, devi);
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 		if (PM_CAPABLE(ppb->ppb_pwr_p)) {
4090Sstevel@tonic-gate 			mutex_enter(&ppb->ppb_pwr_p->pwr_mutex);
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 			/*
4120Sstevel@tonic-gate 			 * Before reading config registers, make sure power is
4130Sstevel@tonic-gate 			 * on, and remains on.
4140Sstevel@tonic-gate 			 */
4150Sstevel@tonic-gate 			ppb->ppb_pwr_p->pwr_fp++;
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 			pci_pwr_change(ppb->ppb_pwr_p,
4180Sstevel@tonic-gate 			    ppb->ppb_pwr_p->current_lvl,
4190Sstevel@tonic-gate 			    pci_pwr_new_lvl(ppb->ppb_pwr_p));
4200Sstevel@tonic-gate 		}
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 		ppb->ppb_cache_line_size =
4230Sstevel@tonic-gate 		    pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ);
4240Sstevel@tonic-gate 		ppb->ppb_latency_timer =
4250Sstevel@tonic-gate 		    pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER);
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate 		/*
4280Sstevel@tonic-gate 		 * Check whether the "ranges" property is present.
4290Sstevel@tonic-gate 		 * Otherwise create the ranges property by reading
4300Sstevel@tonic-gate 		 * the configuration registers
4310Sstevel@tonic-gate 		 */
4320Sstevel@tonic-gate 		if (ddi_prop_exists(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
4330Sstevel@tonic-gate 		    "ranges") == 0) {
4340Sstevel@tonic-gate 			ppb_create_ranges_prop(devi, config_handle);
4350Sstevel@tonic-gate 		}
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 		pci_config_teardown(&config_handle);
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 		if (PM_CAPABLE(ppb->ppb_pwr_p)) {
4400Sstevel@tonic-gate 			ppb->ppb_pwr_p->pwr_fp--;
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate 			pci_pwr_change(ppb->ppb_pwr_p,
4430Sstevel@tonic-gate 			    ppb->ppb_pwr_p->current_lvl,
4440Sstevel@tonic-gate 			    pci_pwr_new_lvl(ppb->ppb_pwr_p));
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate 			mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
4470Sstevel@tonic-gate 		}
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 		/*
4500Sstevel@tonic-gate 		 * Initialize hotplug support on this bus. At minimum
4510Sstevel@tonic-gate 		 * (for non hotplug bus) this would create ":devctl" minor
4520Sstevel@tonic-gate 		 * node to support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls
4530Sstevel@tonic-gate 		 * to this bus. This all takes place if this nexus has hot-plug
4540Sstevel@tonic-gate 		 * slots and successfully initializes Hot Plug Framework.
4550Sstevel@tonic-gate 		 */
4560Sstevel@tonic-gate 		ppb->hotplug_capable = B_FALSE;
4570Sstevel@tonic-gate 		ppb_init_hotplug(ppb);
4580Sstevel@tonic-gate 		if (ppb->hotplug_capable == B_FALSE) {
4590Sstevel@tonic-gate 			/*
4600Sstevel@tonic-gate 			 * create minor node for devctl interfaces
4610Sstevel@tonic-gate 			 */
4620Sstevel@tonic-gate 			if (ddi_create_minor_node(devi, "devctl", S_IFCHR,
4630Sstevel@tonic-gate 			    PCIHP_AP_MINOR_NUM(instance, PCIHP_DEVCTL_MINOR),
4640Sstevel@tonic-gate 			    DDI_NT_NEXUS, 0) != DDI_SUCCESS) {
4650Sstevel@tonic-gate 				if (ppb->ppb_pwr_p != NULL) {
4660Sstevel@tonic-gate 					ppb_pwr_teardown(ppb, devi);
4670Sstevel@tonic-gate 				}
4680Sstevel@tonic-gate 				mutex_destroy(&ppb->ppb_mutex);
4690Sstevel@tonic-gate 				ddi_soft_state_free(ppb_state, instance);
4700Sstevel@tonic-gate 				return (DDI_FAILURE);
4710Sstevel@tonic-gate 			}
4720Sstevel@tonic-gate 		}
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate 		DEBUG1(DBG_ATTACH, devi,
4750Sstevel@tonic-gate 			"ppb_attach(): this nexus %s hotplug slots\n",
4760Sstevel@tonic-gate 			ppb->hotplug_capable == B_TRUE ? "has":"has no");
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 		ppb_fm_init(ppb);
4790Sstevel@tonic-gate 		ddi_report_dev(devi);
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 		return (DDI_SUCCESS);
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 	case DDI_RESUME:
4840Sstevel@tonic-gate 		/*
4850Sstevel@tonic-gate 		 * Get the soft state structure for the bridge.
4860Sstevel@tonic-gate 		 */
4870Sstevel@tonic-gate 		ppb = (ppb_devstate_t *)
4880Sstevel@tonic-gate 			ddi_get_soft_state(ppb_state, ddi_get_instance(devi));
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 		pci_pwr_resume(devi, ppb->ppb_pwr_p);
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 		return (DDI_SUCCESS);
4930Sstevel@tonic-gate 	}
4940Sstevel@tonic-gate 	return (DDI_FAILURE);
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate /*ARGSUSED*/
4980Sstevel@tonic-gate static int
4990Sstevel@tonic-gate ppb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
5000Sstevel@tonic-gate {
5010Sstevel@tonic-gate 	ppb_devstate_t *ppb;
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 	switch (cmd) {
5040Sstevel@tonic-gate 	case DDI_DETACH:
5050Sstevel@tonic-gate 		/*
5060Sstevel@tonic-gate 		 * And finally free the per-pci soft state after
5070Sstevel@tonic-gate 		 * uninitializing hotplug support for this bus.
5080Sstevel@tonic-gate 		 */
5090Sstevel@tonic-gate 		ppb = (ppb_devstate_t *)
5100Sstevel@tonic-gate 		    ddi_get_soft_state(ppb_state, ddi_get_instance(devi));
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate 		ppb_fm_fini(ppb);
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 		if (ppb->hotplug_capable == B_TRUE)
5150Sstevel@tonic-gate 			if (pcihp_uninit(devi) == DDI_FAILURE)
5160Sstevel@tonic-gate 				return (DDI_FAILURE);
5170Sstevel@tonic-gate 		else
5180Sstevel@tonic-gate 			ddi_remove_minor_node(devi, "devctl");
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate 		(void) ddi_prop_remove(DDI_DEV_T_NONE, devi, "device_type");
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate 		if (ppb->ppb_pwr_p != NULL) {
5230Sstevel@tonic-gate 			ppb_pwr_teardown(ppb, devi);
5240Sstevel@tonic-gate 		}
5250Sstevel@tonic-gate 		mutex_destroy(&ppb->ppb_mutex);
5260Sstevel@tonic-gate 		ddi_soft_state_free(ppb_state, ddi_get_instance(devi));
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 		return (DDI_SUCCESS);
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate 	case DDI_SUSPEND:
5310Sstevel@tonic-gate 		ppb = (ppb_devstate_t *)
5320Sstevel@tonic-gate 			ddi_get_soft_state(ppb_state, ddi_get_instance(devi));
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 		pci_pwr_suspend(devi, ppb->ppb_pwr_p);
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 		return (DDI_SUCCESS);
5370Sstevel@tonic-gate 	}
5380Sstevel@tonic-gate 	return (DDI_FAILURE);
5390Sstevel@tonic-gate }
5400Sstevel@tonic-gate 
5410Sstevel@tonic-gate /*ARGSUSED*/
5420Sstevel@tonic-gate static int
5430Sstevel@tonic-gate ppb_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
5440Sstevel@tonic-gate 	off_t offset, off_t len, caddr_t *vaddrp)
5450Sstevel@tonic-gate {
5460Sstevel@tonic-gate 	register dev_info_t *pdip;
5470Sstevel@tonic-gate 
5480Sstevel@tonic-gate 	pdip = (dev_info_t *)DEVI(dip)->devi_parent;
5490Sstevel@tonic-gate 	return ((DEVI(pdip)->devi_ops->devo_bus_ops->bus_map)
5500Sstevel@tonic-gate 	    (pdip, rdip, mp, offset, len, vaddrp));
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate /*ARGSUSED*/
5540Sstevel@tonic-gate static int
5550Sstevel@tonic-gate ppb_ctlops(dev_info_t *dip, dev_info_t *rdip,
5560Sstevel@tonic-gate 	ddi_ctl_enum_t ctlop, void *arg, void *result)
5570Sstevel@tonic-gate {
5580Sstevel@tonic-gate 	pci_regspec_t *drv_regp;
5590Sstevel@tonic-gate 	int	reglen;
5600Sstevel@tonic-gate 	int	rn;
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 	int	totreg;
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 	switch (ctlop) {
5650Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
5660Sstevel@tonic-gate 		if (rdip == (dev_info_t *)0)
5670Sstevel@tonic-gate 			return (DDI_FAILURE);
5680Sstevel@tonic-gate 		cmn_err(CE_CONT, "?PCI-device: %s@%s, %s%d\n",
5690Sstevel@tonic-gate 		    ddi_node_name(rdip), ddi_get_name_addr(rdip),
5700Sstevel@tonic-gate 		    ddi_driver_name(rdip),
5710Sstevel@tonic-gate 		    ddi_get_instance(rdip));
5720Sstevel@tonic-gate 		return (DDI_SUCCESS);
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
5750Sstevel@tonic-gate 		return (ppb_initchild((dev_info_t *)arg));
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
5780Sstevel@tonic-gate 		ppb_removechild((dev_info_t *)arg);
5790Sstevel@tonic-gate 		return (DDI_SUCCESS);
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
5820Sstevel@tonic-gate 		return (DDI_SUCCESS);
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
5850Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
5860Sstevel@tonic-gate 		if (rdip == (dev_info_t *)0)
5870Sstevel@tonic-gate 			return (DDI_FAILURE);
5880Sstevel@tonic-gate 		break;
5890Sstevel@tonic-gate 	default:
5900Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
5910Sstevel@tonic-gate 	}
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 	*(int *)result = 0;
594506Scth 	if (ddi_getlongprop(DDI_DEV_T_ANY, rdip,
5950Sstevel@tonic-gate 		DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "reg",
5960Sstevel@tonic-gate 		(caddr_t)&drv_regp, &reglen) != DDI_SUCCESS)
5970Sstevel@tonic-gate 		return (DDI_FAILURE);
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate 	totreg = reglen / sizeof (pci_regspec_t);
6000Sstevel@tonic-gate 	if (ctlop == DDI_CTLOPS_NREGS)
6010Sstevel@tonic-gate 		*(int *)result = totreg;
6020Sstevel@tonic-gate 	else if (ctlop == DDI_CTLOPS_REGSIZE) {
6030Sstevel@tonic-gate 		rn = *(int *)arg;
6040Sstevel@tonic-gate 		if (rn >= totreg) {
6050Sstevel@tonic-gate 			kmem_free(drv_regp, reglen);
6060Sstevel@tonic-gate 			return (DDI_FAILURE);
6070Sstevel@tonic-gate 		}
6080Sstevel@tonic-gate 		*(off_t *)result = drv_regp[rn].pci_size_low |
6090Sstevel@tonic-gate 			((uint64_t)drv_regp[rn].pci_size_hi << 32);
6100Sstevel@tonic-gate 	}
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate 	kmem_free(drv_regp, reglen);
6130Sstevel@tonic-gate 	return (DDI_SUCCESS);
6140Sstevel@tonic-gate }
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate static dev_info_t *
6180Sstevel@tonic-gate get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip)
6190Sstevel@tonic-gate {
6200Sstevel@tonic-gate 	dev_info_t *cdip = rdip;
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate 	for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip))
6230Sstevel@tonic-gate 		;
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate 	return (cdip);
6260Sstevel@tonic-gate }
6270Sstevel@tonic-gate 
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate static int
6300Sstevel@tonic-gate ppb_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
6310Sstevel@tonic-gate     ddi_intr_handle_impl_t *hdlp, void *result)
6320Sstevel@tonic-gate {
633693Sgovinda 	dev_info_t	*cdip = rdip;
634693Sgovinda 	pci_regspec_t	*pci_rp;
635693Sgovinda 	int		reglen, len;
636693Sgovinda 	uint32_t	d, intr;
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate 	if (hdlp->ih_type != DDI_INTR_TYPE_FIXED)
6390Sstevel@tonic-gate 		goto done;
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate 	/*
6420Sstevel@tonic-gate 	 * If the interrupt-map property is defined at this
6430Sstevel@tonic-gate 	 * node, it will have performed the interrupt
6440Sstevel@tonic-gate 	 * translation as part of the property, so no
6450Sstevel@tonic-gate 	 * rotation needs to be done.
6460Sstevel@tonic-gate 	 */
6470Sstevel@tonic-gate 	if (ddi_getproplen(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
6480Sstevel@tonic-gate 	    "interrupt-map", &len) == DDI_PROP_SUCCESS)
6490Sstevel@tonic-gate 		goto done;
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate 	cdip = get_my_childs_dip(dip, rdip);
6520Sstevel@tonic-gate 
6530Sstevel@tonic-gate 	/*
6540Sstevel@tonic-gate 	 * Use the devices reg property to determine its
6550Sstevel@tonic-gate 	 * PCI bus number and device number.
6560Sstevel@tonic-gate 	 */
657506Scth 	if (ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS,
6580Sstevel@tonic-gate 	    "reg", (caddr_t)&pci_rp, &reglen) != DDI_SUCCESS)
6590Sstevel@tonic-gate 		return (DDI_FAILURE);
6600Sstevel@tonic-gate 
661693Sgovinda 	intr = hdlp->ih_vector;
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate 	/* Spin the interrupt */
6640Sstevel@tonic-gate 	d = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi);
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 	if ((intr >= PCI_INTA) && (intr <= PCI_INTD))
667693Sgovinda 		hdlp->ih_vector = ((intr - 1 + (d % 4)) % 4 + 1);
6680Sstevel@tonic-gate 	else
6690Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: %s: PCI intr=%x out of range",
6700Sstevel@tonic-gate 		    ddi_driver_name(rdip), ddi_get_instance(rdip),
6710Sstevel@tonic-gate 		    ddi_driver_name(dip), intr);
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 	kmem_free(pci_rp, reglen);
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate done:
6760Sstevel@tonic-gate 	/* Pass up the request to our parent. */
6770Sstevel@tonic-gate 	return (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result));
6780Sstevel@tonic-gate }
6790Sstevel@tonic-gate 
6800Sstevel@tonic-gate static int
6810Sstevel@tonic-gate ppb_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op,
6820Sstevel@tonic-gate     void *arg, void *result)
6830Sstevel@tonic-gate {
6840Sstevel@tonic-gate 	ppb_devstate_t *ppb;
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate 	ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
6870Sstevel@tonic-gate 	    ddi_get_instance(dip));
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate 	return (pci_pwr_ops(ppb->ppb_pwr_p, dip, impl_arg, op, arg, result));
6900Sstevel@tonic-gate }
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 
6930Sstevel@tonic-gate /*
6940Sstevel@tonic-gate  * name_child
6950Sstevel@tonic-gate  *
6960Sstevel@tonic-gate  * This function is called from init_child to name a node. It is
6970Sstevel@tonic-gate  * also passed as a callback for node merging functions.
6980Sstevel@tonic-gate  *
6990Sstevel@tonic-gate  * return value: DDI_SUCCESS, DDI_FAILURE
7000Sstevel@tonic-gate  */
7010Sstevel@tonic-gate static int
7020Sstevel@tonic-gate ppb_name_child(dev_info_t *child, char *name, int namelen)
7030Sstevel@tonic-gate {
7040Sstevel@tonic-gate 	pci_regspec_t *pci_rp;
7050Sstevel@tonic-gate 	uint_t slot, func;
7060Sstevel@tonic-gate 	char **unit_addr;
7070Sstevel@tonic-gate 	uint_t n;
7080Sstevel@tonic-gate 
7090Sstevel@tonic-gate 	/*
7100Sstevel@tonic-gate 	 * Pseudo nodes indicate a prototype node with per-instance
7110Sstevel@tonic-gate 	 * properties to be merged into the real h/w device node.
7120Sstevel@tonic-gate 	 * The interpretation of the unit-address is DD[,F]
7130Sstevel@tonic-gate 	 * where DD is the device id and F is the function.
7140Sstevel@tonic-gate 	 */
7150Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) == 0) {
7160Sstevel@tonic-gate 		if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
7170Sstevel@tonic-gate 		    DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) !=
7180Sstevel@tonic-gate 		    DDI_PROP_SUCCESS) {
7190Sstevel@tonic-gate 			cmn_err(CE_WARN, "cannot name node from %s.conf",
7200Sstevel@tonic-gate 			    ddi_driver_name(child));
7210Sstevel@tonic-gate 			return (DDI_FAILURE);
7220Sstevel@tonic-gate 		}
7230Sstevel@tonic-gate 		if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
7240Sstevel@tonic-gate 			cmn_err(CE_WARN, "unit-address property in %s.conf"
7250Sstevel@tonic-gate 			    " not well-formed", ddi_driver_name(child));
7260Sstevel@tonic-gate 			ddi_prop_free(unit_addr);
7270Sstevel@tonic-gate 			return (DDI_FAILURE);
7280Sstevel@tonic-gate 		}
7290Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%s", *unit_addr);
7300Sstevel@tonic-gate 		ddi_prop_free(unit_addr);
7310Sstevel@tonic-gate 		return (DDI_SUCCESS);
7320Sstevel@tonic-gate 	}
7330Sstevel@tonic-gate 
7340Sstevel@tonic-gate 	/*
7350Sstevel@tonic-gate 	 * Get the address portion of the node name based on
7360Sstevel@tonic-gate 	 * the function and device number.
7370Sstevel@tonic-gate 	 */
7380Sstevel@tonic-gate 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
7390Sstevel@tonic-gate 	    "reg", (int **)&pci_rp, &n) != DDI_SUCCESS) {
7400Sstevel@tonic-gate 		return (DDI_FAILURE);
7410Sstevel@tonic-gate 	}
7420Sstevel@tonic-gate 
7430Sstevel@tonic-gate 	slot = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi);
7440Sstevel@tonic-gate 	func = PCI_REG_FUNC_G(pci_rp[0].pci_phys_hi);
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 	if (func != 0)
7470Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%x,%x", slot, func);
7480Sstevel@tonic-gate 	else
7490Sstevel@tonic-gate 		(void) snprintf(name, namelen, "%x", slot);
7500Sstevel@tonic-gate 
7510Sstevel@tonic-gate 	ddi_prop_free(pci_rp);
7520Sstevel@tonic-gate 	return (DDI_SUCCESS);
7530Sstevel@tonic-gate }
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate static int
7560Sstevel@tonic-gate ppb_initchild(dev_info_t *child)
7570Sstevel@tonic-gate {
7580Sstevel@tonic-gate 	char name[MAXNAMELEN];
7590Sstevel@tonic-gate 	ddi_acc_handle_t config_handle;
7600Sstevel@tonic-gate 	ushort_t command_preserve, command;
7610Sstevel@tonic-gate 	uint_t n;
7620Sstevel@tonic-gate 	ushort_t bcr;
7630Sstevel@tonic-gate 	uchar_t header_type;
7640Sstevel@tonic-gate 	uchar_t min_gnt, latency_timer;
7650Sstevel@tonic-gate 	ppb_devstate_t *ppb;
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 	/*
7680Sstevel@tonic-gate 	 * Name the child
7690Sstevel@tonic-gate 	 */
7700Sstevel@tonic-gate 	if (ppb_name_child(child, name, MAXNAMELEN) != DDI_SUCCESS)
7710Sstevel@tonic-gate 		return (DDI_FAILURE);
7720Sstevel@tonic-gate 
7730Sstevel@tonic-gate 	ddi_set_name_addr(child, name);
7740Sstevel@tonic-gate 	ddi_set_parent_data(child, NULL);
7750Sstevel@tonic-gate 
7760Sstevel@tonic-gate 	/*
7770Sstevel@tonic-gate 	 * Pseudo nodes indicate a prototype node with per-instance
7780Sstevel@tonic-gate 	 * properties to be merged into the real h/w device node.
7790Sstevel@tonic-gate 	 * The interpretation of the unit-address is DD[,F]
7800Sstevel@tonic-gate 	 * where DD is the device id and F is the function.
7810Sstevel@tonic-gate 	 */
7820Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) == 0) {
7830Sstevel@tonic-gate 		extern int pci_allow_pseudo_children;
7840Sstevel@tonic-gate 
7850Sstevel@tonic-gate 		/*
7860Sstevel@tonic-gate 		 * Try to merge the properties from this prototype
7870Sstevel@tonic-gate 		 * node into real h/w nodes.
7880Sstevel@tonic-gate 		 */
7890Sstevel@tonic-gate 		if (ndi_merge_node(child, ppb_name_child) == DDI_SUCCESS) {
7900Sstevel@tonic-gate 			/*
7910Sstevel@tonic-gate 			 * Merged ok - return failure to remove the node.
7920Sstevel@tonic-gate 			 */
7930Sstevel@tonic-gate 			ppb_removechild(child);
7940Sstevel@tonic-gate 			return (DDI_FAILURE);
7950Sstevel@tonic-gate 		}
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate 		/* workaround for ddivs to run under PCI */
7980Sstevel@tonic-gate 		if (pci_allow_pseudo_children)
7990Sstevel@tonic-gate 			return (DDI_SUCCESS);
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate 		/*
8020Sstevel@tonic-gate 		 * The child was not merged into a h/w node,
8030Sstevel@tonic-gate 		 * but there's not much we can do with it other
8040Sstevel@tonic-gate 		 * than return failure to cause the node to be removed.
8050Sstevel@tonic-gate 		 */
8060Sstevel@tonic-gate 		cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged",
8070Sstevel@tonic-gate 		    ddi_driver_name(child), ddi_get_name_addr(child),
8080Sstevel@tonic-gate 		    ddi_driver_name(child));
8090Sstevel@tonic-gate 		ppb_removechild(child);
8100Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
8110Sstevel@tonic-gate 	}
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 	ddi_set_parent_data(child, NULL);
8140Sstevel@tonic-gate 
8150Sstevel@tonic-gate 	ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
8160Sstevel@tonic-gate 	    ddi_get_instance(ddi_get_parent(child)));
8170Sstevel@tonic-gate 
8180Sstevel@tonic-gate 	/*
8190Sstevel@tonic-gate 	 * If hardware is PM capable, set up the power info structure.
8200Sstevel@tonic-gate 	 * This also ensures the the bus will not be off (0MHz) otherwise
8210Sstevel@tonic-gate 	 * system panics during a bus access.
8220Sstevel@tonic-gate 	 */
8230Sstevel@tonic-gate 	if (PM_CAPABLE(ppb->ppb_pwr_p)) {
8240Sstevel@tonic-gate 		/*
8250Sstevel@tonic-gate 		 * Create a pwr_info struct for child.  Bus will be
8260Sstevel@tonic-gate 		 * at full speed after creating info.
8270Sstevel@tonic-gate 		 */
8280Sstevel@tonic-gate 		pci_pwr_create_info(ppb->ppb_pwr_p, child);
8290Sstevel@tonic-gate #ifdef DEBUG
8300Sstevel@tonic-gate 		ASSERT(ppb->ppb_pwr_p->current_lvl == PM_LEVEL_B0);
8310Sstevel@tonic-gate #endif
8320Sstevel@tonic-gate 	}
8330Sstevel@tonic-gate 
8340Sstevel@tonic-gate 	/*
8350Sstevel@tonic-gate 	 * If configuration registers were previously saved by
8360Sstevel@tonic-gate 	 * child (before it entered D3), then let the child do the
8370Sstevel@tonic-gate 	 * restore to set up the config regs as it'll first need to
8380Sstevel@tonic-gate 	 * power the device out of D3.
8390Sstevel@tonic-gate 	 */
8400Sstevel@tonic-gate 	if (ddi_prop_exists(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
8410Sstevel@tonic-gate 	    "config-regs-saved-by-child") == 1) {
8420Sstevel@tonic-gate 		DEBUG2(DBG_PWR, ddi_get_parent(child),
8430Sstevel@tonic-gate 			"INITCHILD: config regs to be restored by child"
8440Sstevel@tonic-gate 			" for %s@%s\n", ddi_node_name(child),
8450Sstevel@tonic-gate 				ddi_get_name_addr(child));
8460Sstevel@tonic-gate 
8470Sstevel@tonic-gate 		return (DDI_SUCCESS);
8480Sstevel@tonic-gate 	}
8490Sstevel@tonic-gate 
8500Sstevel@tonic-gate 	DEBUG2(DBG_PWR, ddi_get_parent(child),
8510Sstevel@tonic-gate 	    "INITCHILD: config regs setup for %s@%s\n",
8520Sstevel@tonic-gate 	    ddi_node_name(child), ddi_get_name_addr(child));
8530Sstevel@tonic-gate 
8540Sstevel@tonic-gate 	if (pci_config_setup(child, &config_handle) != DDI_SUCCESS) {
8550Sstevel@tonic-gate 		if (PM_CAPABLE(ppb->ppb_pwr_p)) {
8560Sstevel@tonic-gate 			pci_pwr_rm_info(ppb->ppb_pwr_p, child);
8570Sstevel@tonic-gate 		}
8580Sstevel@tonic-gate 
8590Sstevel@tonic-gate 		return (DDI_FAILURE);
8600Sstevel@tonic-gate 	}
8610Sstevel@tonic-gate 
8620Sstevel@tonic-gate 	/*
8630Sstevel@tonic-gate 	 * Determine the configuration header type.
8640Sstevel@tonic-gate 	 */
8650Sstevel@tonic-gate 	header_type = pci_config_get8(config_handle, PCI_CONF_HEADER);
8660Sstevel@tonic-gate 
8670Sstevel@tonic-gate 	/*
8680Sstevel@tonic-gate 	 * Support for the "command-preserve" property.
8690Sstevel@tonic-gate 	 */
8700Sstevel@tonic-gate 	command_preserve = ddi_prop_get_int(DDI_DEV_T_ANY, child,
8710Sstevel@tonic-gate 		DDI_PROP_DONTPASS, "command-preserve", 0);
8720Sstevel@tonic-gate 	command = pci_config_get16(config_handle, PCI_CONF_COMM);
8730Sstevel@tonic-gate 	command &= (command_preserve | PCI_COMM_BACK2BACK_ENAB);
8740Sstevel@tonic-gate 	command |= (ppb_command_default & ~command_preserve);
8750Sstevel@tonic-gate 	pci_config_put16(config_handle, PCI_CONF_COMM, command);
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate 	/*
8780Sstevel@tonic-gate 	 * If the device has a bus control register then program it
8790Sstevel@tonic-gate 	 * based on the settings in the command register.
8800Sstevel@tonic-gate 	 */
8810Sstevel@tonic-gate 	if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) {
8820Sstevel@tonic-gate 		bcr = pci_config_get8(config_handle, PCI_BCNF_BCNTRL);
8830Sstevel@tonic-gate 		if (ppb_command_default & PCI_COMM_PARITY_DETECT)
8840Sstevel@tonic-gate 			bcr |= PCI_BCNF_BCNTRL_PARITY_ENABLE;
8850Sstevel@tonic-gate 		if (ppb_command_default & PCI_COMM_SERR_ENABLE)
8860Sstevel@tonic-gate 			bcr |= PCI_BCNF_BCNTRL_SERR_ENABLE;
8870Sstevel@tonic-gate 		bcr |= PCI_BCNF_BCNTRL_MAST_AB_MODE;
8880Sstevel@tonic-gate 		pci_config_put8(config_handle, PCI_BCNF_BCNTRL, bcr);
8890Sstevel@tonic-gate 	}
8900Sstevel@tonic-gate 
8910Sstevel@tonic-gate 	/*
8920Sstevel@tonic-gate 	 * Initialize cache-line-size configuration register if needed.
8930Sstevel@tonic-gate 	 */
8940Sstevel@tonic-gate 	if (ppb_set_cache_line_size_register &&
8950Sstevel@tonic-gate 	    ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
8960Sstevel@tonic-gate 		"cache-line-size", 0) == 0) {
8970Sstevel@tonic-gate 		pci_config_put8(config_handle, PCI_CONF_CACHE_LINESZ,
8980Sstevel@tonic-gate 			ppb->ppb_cache_line_size);
8990Sstevel@tonic-gate 		n = pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ);
9000Sstevel@tonic-gate 		if (n != 0) {
9010Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, child,
9020Sstevel@tonic-gate 					"cache-line-size", n);
9030Sstevel@tonic-gate 		}
9040Sstevel@tonic-gate 	}
9050Sstevel@tonic-gate 
9060Sstevel@tonic-gate 	/*
9070Sstevel@tonic-gate 	 * Initialize latency timer configuration registers if needed.
9080Sstevel@tonic-gate 	 */
9090Sstevel@tonic-gate 	if (ppb_set_latency_timer_register &&
9100Sstevel@tonic-gate 	    ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
9110Sstevel@tonic-gate 		"latency-timer", 0) == 0) {
9120Sstevel@tonic-gate 
9130Sstevel@tonic-gate 		if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) {
9140Sstevel@tonic-gate 			latency_timer = ppb->ppb_latency_timer;
9150Sstevel@tonic-gate 			pci_config_put8(config_handle, PCI_BCNF_LATENCY_TIMER,
9160Sstevel@tonic-gate 				ppb->ppb_latency_timer);
9170Sstevel@tonic-gate 		} else {
9180Sstevel@tonic-gate 			min_gnt = pci_config_get8(config_handle,
9190Sstevel@tonic-gate 				PCI_CONF_MIN_G);
9200Sstevel@tonic-gate 			latency_timer = min_gnt * 8;
9210Sstevel@tonic-gate 		}
9220Sstevel@tonic-gate 		pci_config_put8(config_handle, PCI_CONF_LATENCY_TIMER,
9230Sstevel@tonic-gate 			latency_timer);
9240Sstevel@tonic-gate 		n = pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER);
9250Sstevel@tonic-gate 		if (n != 0) {
9260Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, child,
9270Sstevel@tonic-gate 					"latency-timer", n);
9280Sstevel@tonic-gate 		}
9290Sstevel@tonic-gate 	}
9300Sstevel@tonic-gate 
9310Sstevel@tonic-gate 	/*
9320Sstevel@tonic-gate 	 * Check to see if the XMITS/PCI-X workaround applies.
9330Sstevel@tonic-gate 	 */
9340Sstevel@tonic-gate 	n = ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_NOTPROM,
9350Sstevel@tonic-gate 	    "pcix-update-cmd-reg", -1);
9360Sstevel@tonic-gate 
9370Sstevel@tonic-gate 	if (n != -1) {
9380Sstevel@tonic-gate 		extern void pcix_set_cmd_reg(dev_info_t *child, uint16_t value);
9390Sstevel@tonic-gate 		DEBUG1(DBG_INIT_CLD, child, "Turning on XMITS NCPQ "
9400Sstevel@tonic-gate 		    "Workaround: value = %x\n", n);
9410Sstevel@tonic-gate 		pcix_set_cmd_reg(child, n);
9420Sstevel@tonic-gate 	}
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate 	pci_config_teardown(&config_handle);
9450Sstevel@tonic-gate 
9460Sstevel@tonic-gate 	return (DDI_SUCCESS);
9470Sstevel@tonic-gate }
9480Sstevel@tonic-gate 
9490Sstevel@tonic-gate static void
9500Sstevel@tonic-gate ppb_removechild(dev_info_t *dip)
9510Sstevel@tonic-gate {
9520Sstevel@tonic-gate 	ppb_devstate_t *ppb;
9530Sstevel@tonic-gate 
9540Sstevel@tonic-gate 	ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
9550Sstevel@tonic-gate 	    ddi_get_instance(ddi_get_parent(dip)));
9560Sstevel@tonic-gate 
9570Sstevel@tonic-gate 	if (PM_CAPABLE(ppb->ppb_pwr_p)) {
9580Sstevel@tonic-gate 
9590Sstevel@tonic-gate 		DEBUG2(DBG_PWR, ddi_get_parent(dip),
9600Sstevel@tonic-gate 		    "UNINITCHILD: removing pwr_info for %s@%s\n",
9610Sstevel@tonic-gate 		    ddi_node_name(dip), ddi_get_name_addr(dip));
9620Sstevel@tonic-gate 		pci_pwr_rm_info(ppb->ppb_pwr_p, dip);
9630Sstevel@tonic-gate 	}
9640Sstevel@tonic-gate 
9650Sstevel@tonic-gate 	ddi_set_name_addr(dip, NULL);
9660Sstevel@tonic-gate 
9670Sstevel@tonic-gate 	/*
9680Sstevel@tonic-gate 	 * Strip the node to properly convert it back to prototype form
9690Sstevel@tonic-gate 	 */
9700Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
9710Sstevel@tonic-gate 
9720Sstevel@tonic-gate 	impl_rem_dev_props(dip);
9730Sstevel@tonic-gate }
9740Sstevel@tonic-gate 
9750Sstevel@tonic-gate /*
9760Sstevel@tonic-gate  * If bridge is PM capable, set up PM state for nexus.
9770Sstevel@tonic-gate  */
9780Sstevel@tonic-gate static void
9790Sstevel@tonic-gate ppb_pwr_setup(ppb_devstate_t *ppb, dev_info_t *pdip)
9800Sstevel@tonic-gate {
9810Sstevel@tonic-gate 	char *comp_array[5];
9820Sstevel@tonic-gate 	int i;
9830Sstevel@tonic-gate 	ddi_acc_handle_t conf_hdl;
9840Sstevel@tonic-gate 	uint8_t pmcsr_bse;
9850Sstevel@tonic-gate 	uint16_t pmcap;
9860Sstevel@tonic-gate 
9870Sstevel@tonic-gate 	/*
9880Sstevel@tonic-gate 	 * Determine if bridge is PM capable.  If not, leave ppb_pwr_p NULL
9890Sstevel@tonic-gate 	 * and return.
9900Sstevel@tonic-gate 	 */
9910Sstevel@tonic-gate 	if (pci_config_setup(pdip, &ppb->ppb_conf_hdl) != DDI_SUCCESS) {
9920Sstevel@tonic-gate 
9930Sstevel@tonic-gate 		return;
9940Sstevel@tonic-gate 	}
9950Sstevel@tonic-gate 
9960Sstevel@tonic-gate 	conf_hdl = ppb->ppb_conf_hdl;
9970Sstevel@tonic-gate 
9980Sstevel@tonic-gate 	/*
999*1624Spjha 	 * Locate and store the power management cap_ptr for future references.
10000Sstevel@tonic-gate 	 */
1001*1624Spjha 	if ((PCI_CAP_LOCATE(conf_hdl, PCI_CAP_ID_PM, &ppb->ppb_pm_cap_ptr))
1002*1624Spjha 		== DDI_FAILURE) {
10030Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "bridge does not support PM. PCI"
10040Sstevel@tonic-gate 		    " PM data structure not found in config header\n");
10050Sstevel@tonic-gate 		pci_config_teardown(&conf_hdl);
10060Sstevel@tonic-gate 
10070Sstevel@tonic-gate 		return;
10080Sstevel@tonic-gate 	}
10090Sstevel@tonic-gate 
10100Sstevel@tonic-gate 	/*
10110Sstevel@tonic-gate 	 * Allocate PM state structure for ppb.
10120Sstevel@tonic-gate 	 */
10130Sstevel@tonic-gate 	ppb->ppb_pwr_p = (pci_pwr_t *)
10140Sstevel@tonic-gate 	    kmem_zalloc(sizeof (pci_pwr_t), KM_SLEEP);
10150Sstevel@tonic-gate 	ppb->ppb_pwr_p->pwr_fp = 0;
10160Sstevel@tonic-gate 
1017*1624Spjha 	pmcsr_bse = PCI_CAP_GET8(conf_hdl, NULL, ppb->ppb_pm_cap_ptr,
1018*1624Spjha 		PCI_PMCSR_BSE);
10190Sstevel@tonic-gate 
1020*1624Spjha 	pmcap = PCI_CAP_GET16(conf_hdl, NULL, ppb->ppb_pm_cap_ptr,
1021*1624Spjha 		PCI_PMCAP);
10220Sstevel@tonic-gate 
1023*1624Spjha 	if (pmcap == DDI_FAILURE || pmcsr_bse == DDI_FAILURE) {
1024*1624Spjha 		pci_config_teardown(&conf_hdl);
1025*1624Spjha 		return;
1026*1624Spjha 	}
10270Sstevel@tonic-gate 
10280Sstevel@tonic-gate 	if (pmcap & PCI_PMCAP_D1) {
10290Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "setup: B1 state supported\n");
10300Sstevel@tonic-gate 		ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B1_CAPABLE;
10310Sstevel@tonic-gate 	} else {
10320Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "setup: B1 state NOT supported\n");
10330Sstevel@tonic-gate 	}
10340Sstevel@tonic-gate 	if (pmcap & PCI_PMCAP_D2) {
10350Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "setup: B2 state supported\n");
10360Sstevel@tonic-gate 		ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B2_CAPABLE;
10370Sstevel@tonic-gate 	} else {
10380Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "setup: B2 via D2 NOT supported\n");
10390Sstevel@tonic-gate 	}
10400Sstevel@tonic-gate 
10410Sstevel@tonic-gate 	if (pmcsr_bse & PCI_PMCSR_BSE_BPCC_EN) {
10420Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip,
1043*1624Spjha 		"setup: bridge power/clock control enable\n");
10440Sstevel@tonic-gate 	} else {
10450Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip,
1046*1624Spjha 		"setup: bridge power/clock control disabled\n");
10470Sstevel@tonic-gate 
10480Sstevel@tonic-gate 		kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t));
10490Sstevel@tonic-gate 		ppb->ppb_pwr_p = NULL;
10500Sstevel@tonic-gate 		pci_config_teardown(&conf_hdl);
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate 		return;
10530Sstevel@tonic-gate 	}
10540Sstevel@tonic-gate 
10550Sstevel@tonic-gate 	/*
10560Sstevel@tonic-gate 	 * PCI states D0 and D3 always are supported for normal PCI
10570Sstevel@tonic-gate 	 * devices.  D1 and D2 are optional which are checked for above.
10580Sstevel@tonic-gate 	 * Bridge function states D0-D3 correspond to secondary bus states
10590Sstevel@tonic-gate 	 * B0-B3, EXCEPT if PCI_PMCSR_BSE_B2_B3 is set.  In this case, setting
10600Sstevel@tonic-gate 	 * the bridge function to D3 will set the bridge bus to state B2 instead
10610Sstevel@tonic-gate 	 * of B3.  D2 will not correspond to B2 (and in fact, probably
10620Sstevel@tonic-gate 	 * won't be D2 capable).  Implicitly, this means that if
10630Sstevel@tonic-gate 	 * PCI_PMCSR_BSE_B2_B3 is set, the bus will not be B3 capable.
10640Sstevel@tonic-gate 	 */
10650Sstevel@tonic-gate 	if (pmcsr_bse & PCI_PMCSR_BSE_B2_B3) {
10660Sstevel@tonic-gate 		ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B2_CAPABLE;
10670Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "B2 supported via D3\n");
10680Sstevel@tonic-gate 	} else {
10690Sstevel@tonic-gate 		ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B3_CAPABLE;
10700Sstevel@tonic-gate 		DEBUG0(DBG_PWR, pdip, "B3 supported via D3\n");
10710Sstevel@tonic-gate 	}
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate 	ppb->ppb_pwr_p->pwr_dip = pdip;
10740Sstevel@tonic-gate 	mutex_init(&ppb->ppb_pwr_p->pwr_mutex, NULL, MUTEX_DRIVER, NULL);
10750Sstevel@tonic-gate 
10760Sstevel@tonic-gate 	i = 0;
10770Sstevel@tonic-gate 	comp_array[i++] = "NAME=PCI bridge PM";
10780Sstevel@tonic-gate 	if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) {
10790Sstevel@tonic-gate 		comp_array[i++] = "0=Clock/Power Off (B3)";
10800Sstevel@tonic-gate 	}
10810Sstevel@tonic-gate 	if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B2_CAPABLE) {
10820Sstevel@tonic-gate 		comp_array[i++] = "1=Clock Off (B2)";
10830Sstevel@tonic-gate 	}
10840Sstevel@tonic-gate 	if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B1_CAPABLE) {
10850Sstevel@tonic-gate 		comp_array[i++] = "2=Bus Inactive (B1)";
10860Sstevel@tonic-gate 	}
10870Sstevel@tonic-gate 	comp_array[i++] = "3=Full Power (B0)";
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate 	/*
10900Sstevel@tonic-gate 	 * Create pm-components property. It does not already exist.
10910Sstevel@tonic-gate 	 */
10920Sstevel@tonic-gate 	if (ddi_prop_update_string_array(DDI_DEV_T_NONE, pdip,
10930Sstevel@tonic-gate 	    "pm-components", comp_array, i) != DDI_PROP_SUCCESS) {
10940Sstevel@tonic-gate 		cmn_err(CE_WARN,
10950Sstevel@tonic-gate 		    "%s%d pm-components prop update failed",
10960Sstevel@tonic-gate 		    ddi_driver_name(pdip), ddi_get_instance(pdip));
10970Sstevel@tonic-gate 		pci_config_teardown(&conf_hdl);
10980Sstevel@tonic-gate 		mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex);
10990Sstevel@tonic-gate 		kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t));
11000Sstevel@tonic-gate 		ppb->ppb_pwr_p = NULL;
11010Sstevel@tonic-gate 
11020Sstevel@tonic-gate 		return;
11030Sstevel@tonic-gate 	}
11040Sstevel@tonic-gate 
11050Sstevel@tonic-gate 	if (ddi_prop_create(DDI_DEV_T_NONE, pdip, DDI_PROP_CANSLEEP,
11060Sstevel@tonic-gate 	    "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) {
11070Sstevel@tonic-gate 		cmn_err(CE_WARN,
11080Sstevel@tonic-gate 			"%s%d fail to create pm-want-child-notification? prop",
11090Sstevel@tonic-gate 			ddi_driver_name(pdip), ddi_get_instance(pdip));
11100Sstevel@tonic-gate 
11110Sstevel@tonic-gate 		(void) ddi_prop_remove(DDI_DEV_T_NONE, pdip, "pm-components");
11120Sstevel@tonic-gate 		pci_config_teardown(&conf_hdl);
11130Sstevel@tonic-gate 		mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex);
11140Sstevel@tonic-gate 		kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t));
11150Sstevel@tonic-gate 		ppb->ppb_pwr_p = NULL;
11160Sstevel@tonic-gate 
11170Sstevel@tonic-gate 		return;
11180Sstevel@tonic-gate 	}
11190Sstevel@tonic-gate 
11200Sstevel@tonic-gate 	ppb->ppb_pwr_p->current_lvl =
1121*1624Spjha 		pci_pwr_current_lvl(ppb->ppb_pwr_p);
11220Sstevel@tonic-gate }
11230Sstevel@tonic-gate 
11240Sstevel@tonic-gate /*
11250Sstevel@tonic-gate  * Remove PM state for nexus.
11260Sstevel@tonic-gate  */
11270Sstevel@tonic-gate static void
11280Sstevel@tonic-gate ppb_pwr_teardown(ppb_devstate_t *ppb, dev_info_t *dip)
11290Sstevel@tonic-gate {
11300Sstevel@tonic-gate 	int low_lvl;
11310Sstevel@tonic-gate 
11320Sstevel@tonic-gate 	/*
11330Sstevel@tonic-gate 	 * Determine the lowest power level supported.
11340Sstevel@tonic-gate 	 */
11350Sstevel@tonic-gate 	if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) {
11360Sstevel@tonic-gate 		low_lvl = PM_LEVEL_B3;
11370Sstevel@tonic-gate 	} else {
11380Sstevel@tonic-gate 		low_lvl = PM_LEVEL_B2;
11390Sstevel@tonic-gate 	}
11400Sstevel@tonic-gate 
11410Sstevel@tonic-gate 	if (pm_lower_power(dip, PCI_PM_COMP_0, low_lvl) != DDI_SUCCESS) {
11420Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d failed to lower power",
11430Sstevel@tonic-gate 		    ddi_driver_name(dip), ddi_get_instance(dip));
11440Sstevel@tonic-gate 	}
11450Sstevel@tonic-gate 
11460Sstevel@tonic-gate 	pci_config_teardown(&ppb->ppb_conf_hdl);
11470Sstevel@tonic-gate 	mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex);
11480Sstevel@tonic-gate 	kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t));
11490Sstevel@tonic-gate 
11500Sstevel@tonic-gate 	if (ddi_prop_remove(DDI_DEV_T_NONE, dip, "pm-components") !=
11510Sstevel@tonic-gate 		DDI_PROP_SUCCESS) {
11520Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d unable to remove prop pm-components",
11530Sstevel@tonic-gate 		    ddi_driver_name(dip), ddi_get_instance(dip));
11540Sstevel@tonic-gate 	}
11550Sstevel@tonic-gate 
11560Sstevel@tonic-gate 	if (ddi_prop_remove(DDI_DEV_T_NONE, dip,
11570Sstevel@tonic-gate 	    "pm-want-child-notification?") != DDI_PROP_SUCCESS) {
11580Sstevel@tonic-gate 		cmn_err(CE_WARN,
11590Sstevel@tonic-gate 		    "%s%d unable to remove prop pm-want_child_notification?",
11600Sstevel@tonic-gate 		    ddi_driver_name(dip), ddi_get_instance(dip));
11610Sstevel@tonic-gate 	}
11620Sstevel@tonic-gate }
11630Sstevel@tonic-gate 
11640Sstevel@tonic-gate /*
11650Sstevel@tonic-gate  * Examine the pmcsr register and return the software defined
11660Sstevel@tonic-gate  * state (the difference being whether D3 means B2 or B3).
11670Sstevel@tonic-gate  */
11680Sstevel@tonic-gate int
11690Sstevel@tonic-gate pci_pwr_current_lvl(pci_pwr_t *pwr_p)
11700Sstevel@tonic-gate {
11710Sstevel@tonic-gate 	ppb_devstate_t *ppb;
11720Sstevel@tonic-gate 	uint16_t pmcsr;
11730Sstevel@tonic-gate 
11740Sstevel@tonic-gate 	/*
11750Sstevel@tonic-gate 	 * Find out current power level
11760Sstevel@tonic-gate 	 */
11770Sstevel@tonic-gate 	ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
11780Sstevel@tonic-gate 	    ddi_get_instance(pwr_p->pwr_dip));
11790Sstevel@tonic-gate 
1180*1624Spjha 	if ((pmcsr = PCI_CAP_GET16(ppb->ppb_conf_hdl, NULL,
1181*1624Spjha 		ppb->ppb_pm_cap_ptr, PCI_PMCSR)) == DDI_FAILURE)
1182*1624Spjha 		return (DDI_FAILURE);
11830Sstevel@tonic-gate 
11840Sstevel@tonic-gate 	switch (pmcsr & PCI_PMCSR_STATE_MASK) {
11850Sstevel@tonic-gate 	case PCI_PMCSR_D0:
11860Sstevel@tonic-gate 
11870Sstevel@tonic-gate 		return (PM_LEVEL_B0);
11880Sstevel@tonic-gate 	case PCI_PMCSR_D1:
11890Sstevel@tonic-gate 
11900Sstevel@tonic-gate 		return (PM_LEVEL_B1);
11910Sstevel@tonic-gate 	case PCI_PMCSR_D2:
11920Sstevel@tonic-gate 
11930Sstevel@tonic-gate 		return (PM_LEVEL_B2);
11940Sstevel@tonic-gate 	case PCI_PMCSR_D3HOT:
11950Sstevel@tonic-gate 		if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) {
11960Sstevel@tonic-gate 
11970Sstevel@tonic-gate 			return (PM_LEVEL_B2);
11980Sstevel@tonic-gate 		} else {
11990Sstevel@tonic-gate 
12000Sstevel@tonic-gate 			return (PM_LEVEL_B3);
12010Sstevel@tonic-gate 		}
12020Sstevel@tonic-gate 	}
1203946Smathue 	/*NOTREACHED*/
1204946Smathue 	return (PM_LEVEL_B3);
12050Sstevel@tonic-gate }
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate /*
12080Sstevel@tonic-gate  * Power entry point.  Called by the PM framework to change the
12090Sstevel@tonic-gate  * current power state of the bus.  This function must first verify that
12100Sstevel@tonic-gate  * the requested power change is still valid.
12110Sstevel@tonic-gate  */
12120Sstevel@tonic-gate /*ARGSUSED*/
12130Sstevel@tonic-gate static int
12140Sstevel@tonic-gate ppb_pwr(dev_info_t *dip, int component, int lvl)
12150Sstevel@tonic-gate {
12160Sstevel@tonic-gate 	ppb_devstate_t *ppb;
12170Sstevel@tonic-gate 	uint16_t pmcsr;
12180Sstevel@tonic-gate 	char *str;
12190Sstevel@tonic-gate 	int lowest_lvl;
12200Sstevel@tonic-gate 	int old_lvl;
12210Sstevel@tonic-gate 	int new_lvl;
12220Sstevel@tonic-gate 
12230Sstevel@tonic-gate 	ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
12240Sstevel@tonic-gate 	    ddi_get_instance(dip));
12250Sstevel@tonic-gate 	if (ppb == NULL) {
12260Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d ppb_pwr: can't get soft state",
12270Sstevel@tonic-gate 		    ddi_driver_name(dip), ddi_get_instance(dip));
12280Sstevel@tonic-gate 
12290Sstevel@tonic-gate 		return (DDI_FAILURE);
12300Sstevel@tonic-gate 	}
12310Sstevel@tonic-gate 
12320Sstevel@tonic-gate 	DEBUG1(DBG_PWR, dip, "ppb_pwr(): ENTER level = %d\n", lvl);
12330Sstevel@tonic-gate 
12340Sstevel@tonic-gate 	mutex_enter(&ppb->ppb_pwr_p->pwr_mutex);
12350Sstevel@tonic-gate 
12360Sstevel@tonic-gate 	/*
12370Sstevel@tonic-gate 	 * Find out if the power setting is possible.  If it is not,
12380Sstevel@tonic-gate 	 * set component busy and return failure.  If it is possible,
12390Sstevel@tonic-gate 	 * and it is the lowest pwr setting possible, set component
12400Sstevel@tonic-gate 	 * busy so that the framework does not try to lower any further.
12410Sstevel@tonic-gate 	 */
12420Sstevel@tonic-gate 	lowest_lvl = pci_pwr_new_lvl(ppb->ppb_pwr_p);
12430Sstevel@tonic-gate 	if (lowest_lvl > lvl) {
12440Sstevel@tonic-gate 		pci_pwr_component_busy(ppb->ppb_pwr_p);
12450Sstevel@tonic-gate 		DEBUG2(DBG_PWR, dip, "ppb_pwr: failing power request "
12460Sstevel@tonic-gate 			"lowest allowed is %d requested is %d\n",
12470Sstevel@tonic-gate 				lowest_lvl, lvl);
12480Sstevel@tonic-gate 		mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
12490Sstevel@tonic-gate 
12500Sstevel@tonic-gate 		return (DDI_FAILURE);
12510Sstevel@tonic-gate 	} else if (lowest_lvl == lvl) {
12520Sstevel@tonic-gate 		pci_pwr_component_busy(ppb->ppb_pwr_p);
12530Sstevel@tonic-gate 	} else {
12540Sstevel@tonic-gate 		pci_pwr_component_idle(ppb->ppb_pwr_p);
12550Sstevel@tonic-gate 	}
12560Sstevel@tonic-gate 
1257*1624Spjha 	if ((pmcsr = PCI_CAP_GET16(ppb->ppb_conf_hdl, NULL,
1258*1624Spjha 		ppb->ppb_pm_cap_ptr, PCI_PMCSR)) == DDI_FAILURE)
1259*1624Spjha 		return (DDI_FAILURE);
12600Sstevel@tonic-gate 
12610Sstevel@tonic-gate 	/*
12620Sstevel@tonic-gate 	 * Save the current power level.  This is the actual function level,
12630Sstevel@tonic-gate 	 * not the translated bridge level stored in pwr_p->current_lvl
12640Sstevel@tonic-gate 	 */
12650Sstevel@tonic-gate 	old_lvl = pmcsr & PCI_PMCSR_STATE_MASK;
12660Sstevel@tonic-gate 
12670Sstevel@tonic-gate 	pmcsr &= ~PCI_PMCSR_STATE_MASK;
12680Sstevel@tonic-gate 	switch (lvl) {
12690Sstevel@tonic-gate 	case PM_LEVEL_B0:
12700Sstevel@tonic-gate 		str = "PM_LEVEL_B0 (full speed)";
12710Sstevel@tonic-gate 		pmcsr |= PCI_PMCSR_D0;
12720Sstevel@tonic-gate 		break;
12730Sstevel@tonic-gate 	case PM_LEVEL_B1:
12740Sstevel@tonic-gate 		str = "PM_LEVEL_B1 (light sleep. No bus traffic allowed)";
12750Sstevel@tonic-gate 		if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B1_CAPABLE) == 0) {
12760Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s%d PCI PM state B1 not supported",
12770Sstevel@tonic-gate 			    ddi_driver_name(dip), ddi_get_instance(dip));
12780Sstevel@tonic-gate 
12790Sstevel@tonic-gate 			mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
12800Sstevel@tonic-gate 			return (DDI_FAILURE);
12810Sstevel@tonic-gate 		}
12820Sstevel@tonic-gate 		pmcsr |= PCI_PMCSR_D1;
12830Sstevel@tonic-gate 		break;
12840Sstevel@tonic-gate 	case PM_LEVEL_B2:
12850Sstevel@tonic-gate 		str = "PM_LEVEL_B2 (clock off)";
12860Sstevel@tonic-gate 		if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B2_CAPABLE) == 0) {
12870Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s%d PM state B2 not supported...",
12880Sstevel@tonic-gate 			    ddi_driver_name(dip),
12890Sstevel@tonic-gate 			    ddi_get_instance(dip));
12900Sstevel@tonic-gate 			mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 			return (DDI_FAILURE);
12930Sstevel@tonic-gate 		}
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 		if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) {
12960Sstevel@tonic-gate 			/*
12970Sstevel@tonic-gate 			 * If B3 isn't supported, use D3 for B2 to avoid the
12980Sstevel@tonic-gate 			 * possible case that D2 for B2 isn't supported.
12990Sstevel@tonic-gate 			 * Saves and extra check and state flag..
13000Sstevel@tonic-gate 			 */
13010Sstevel@tonic-gate 			pmcsr |= PCI_PMCSR_D3HOT;
13020Sstevel@tonic-gate 		} else {
13030Sstevel@tonic-gate 			pmcsr |= PCI_PMCSR_D2;
13040Sstevel@tonic-gate 		}
13050Sstevel@tonic-gate 		break;
13060Sstevel@tonic-gate 	case PM_LEVEL_B3:
13070Sstevel@tonic-gate 		str = "PM_LEVEL_B30 (clock and power off)";
13080Sstevel@tonic-gate 		if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) {
13090Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s%d PM state B3 not supported...",
13100Sstevel@tonic-gate 			    ddi_driver_name(dip),
13110Sstevel@tonic-gate 			    ddi_get_instance(dip));
13120Sstevel@tonic-gate 			mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate 			return (DDI_FAILURE);
13150Sstevel@tonic-gate 		}
13160Sstevel@tonic-gate 		pmcsr |= PCI_PMCSR_D3HOT;
13170Sstevel@tonic-gate 
13180Sstevel@tonic-gate 		break;
13190Sstevel@tonic-gate 
13200Sstevel@tonic-gate 	default:
13210Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d Unknown PM state %d",
13220Sstevel@tonic-gate 		    ddi_driver_name(dip), ddi_get_instance(dip), lvl);
13230Sstevel@tonic-gate 		mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
13240Sstevel@tonic-gate 
13250Sstevel@tonic-gate 		return (DDI_FAILURE);
13260Sstevel@tonic-gate 	}
13270Sstevel@tonic-gate 
13280Sstevel@tonic-gate 	new_lvl = pmcsr & PCI_PMCSR_STATE_MASK;
13290Sstevel@tonic-gate 
13300Sstevel@tonic-gate 	/*
13310Sstevel@tonic-gate 	 * Save config regs if going into HW state D3 (B2 or B3)
13320Sstevel@tonic-gate 	 */
13330Sstevel@tonic-gate 	if ((old_lvl != PCI_PMCSR_D3HOT) && (new_lvl == PCI_PMCSR_D3HOT)) {
13340Sstevel@tonic-gate 		DEBUG0(DBG_PWR, dip, "ppb_pwr(): SAVING CONFIG REGS\n");
13350Sstevel@tonic-gate 		if (pci_save_config_regs(dip) != DDI_SUCCESS) {
13360Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s%d Save config regs failed",
13370Sstevel@tonic-gate 				ddi_driver_name(dip), ddi_get_instance(dip));
13380Sstevel@tonic-gate 			mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
13390Sstevel@tonic-gate 
13400Sstevel@tonic-gate 			return (DDI_FAILURE);
13410Sstevel@tonic-gate 		}
13420Sstevel@tonic-gate 	}
13430Sstevel@tonic-gate 
1344*1624Spjha 	PCI_CAP_PUT16(ppb->ppb_conf_hdl, NULL, ppb->ppb_pm_cap_ptr, PCI_PMCSR,
1345*1624Spjha 		pmcsr);
13460Sstevel@tonic-gate 
13470Sstevel@tonic-gate 	/*
13480Sstevel@tonic-gate 	 * No bus transactions should occur without waiting for
13490Sstevel@tonic-gate 	 * settle time specified in PCI PM spec rev 2.1 sec 5.6.1
13500Sstevel@tonic-gate 	 * To make things simple, just use the max time specified for
13510Sstevel@tonic-gate 	 * all state transitions.
13520Sstevel@tonic-gate 	 */
13530Sstevel@tonic-gate 	delay(drv_usectohz(PCI_CLK_SETTLE_TIME));
13540Sstevel@tonic-gate 
13550Sstevel@tonic-gate 	/*
13560Sstevel@tonic-gate 	 * Restore configuration registers if coming out of HW state D3
13570Sstevel@tonic-gate 	 */
13580Sstevel@tonic-gate 	if ((old_lvl == PCI_PMCSR_D3HOT) && (new_lvl != PCI_PMCSR_D3HOT)) {
13590Sstevel@tonic-gate 		DEBUG0(DBG_PWR, dip, "ppb_pwr(): RESTORING CONFIG REGS\n");
13600Sstevel@tonic-gate 		if (pci_restore_config_regs(dip) != DDI_SUCCESS) {
13610Sstevel@tonic-gate 			panic("%s%d restore config regs failed",
13620Sstevel@tonic-gate 			    ddi_driver_name(dip), ddi_get_instance(dip));
13630Sstevel@tonic-gate 		}
13640Sstevel@tonic-gate 		/*NOTREACHED*/
13650Sstevel@tonic-gate 	}
13660Sstevel@tonic-gate 
13670Sstevel@tonic-gate 	ppb->ppb_pwr_p->current_lvl = lvl;
13680Sstevel@tonic-gate 
13690Sstevel@tonic-gate 	mutex_exit(&ppb->ppb_pwr_p->pwr_mutex);
13700Sstevel@tonic-gate 
13710Sstevel@tonic-gate 	DEBUG1(DBG_PWR, dip, "ppb_set_pwr: set PM state to %s\n\n", str);
13720Sstevel@tonic-gate 
13730Sstevel@tonic-gate 	return (DDI_SUCCESS);
13740Sstevel@tonic-gate }
13750Sstevel@tonic-gate 
13760Sstevel@tonic-gate /*
13770Sstevel@tonic-gate  * Initialize hotplug framework if we are hotpluggable.
13780Sstevel@tonic-gate  * Sets flag in the soft state if Hot Plug is supported and initialized
13790Sstevel@tonic-gate  * properly.
13800Sstevel@tonic-gate  */
13810Sstevel@tonic-gate /*ARGSUSED*/
13820Sstevel@tonic-gate static void
13830Sstevel@tonic-gate ppb_init_hotplug(ppb_devstate_t *ppb)
13840Sstevel@tonic-gate {
13850Sstevel@tonic-gate 	if (ddi_prop_exists(DDI_DEV_T_ANY, ppb->dip, DDI_PROP_DONTPASS,
13860Sstevel@tonic-gate 	    "hotplug-capable")) {
13870Sstevel@tonic-gate 		(void) modload("misc", "pcihp");
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate 		if (pcihp_init(ppb->dip) != DDI_SUCCESS) {
13900Sstevel@tonic-gate 			cmn_err(CE_WARN,
13910Sstevel@tonic-gate 			    "%s #%d: Failed setting hotplug framework",
13920Sstevel@tonic-gate 			    ddi_driver_name(ppb->dip),
13930Sstevel@tonic-gate 			    ddi_get_instance(ppb->dip));
13940Sstevel@tonic-gate 		} else
13950Sstevel@tonic-gate 			ppb->hotplug_capable = B_TRUE;
13960Sstevel@tonic-gate 	}
13970Sstevel@tonic-gate 
13980Sstevel@tonic-gate }
13990Sstevel@tonic-gate 
14000Sstevel@tonic-gate static void
14010Sstevel@tonic-gate ppb_create_ranges_prop(dev_info_t *dip,
14020Sstevel@tonic-gate 	ddi_acc_handle_t config_handle)
14030Sstevel@tonic-gate {
14040Sstevel@tonic-gate 	uint32_t base, limit;
14050Sstevel@tonic-gate 	ppb_ranges_t	ranges[PPB_RANGE_LEN];
14060Sstevel@tonic-gate 	uint8_t io_base_lo, io_limit_lo;
14070Sstevel@tonic-gate 	uint16_t io_base_hi, io_limit_hi, mem_base, mem_limit;
14080Sstevel@tonic-gate 	int i = 0, rangelen = sizeof (ppb_ranges_t)/sizeof (int);
14090Sstevel@tonic-gate 
14100Sstevel@tonic-gate 	io_base_lo = pci_config_get8(config_handle, PCI_BCNF_IO_BASE_LOW);
14110Sstevel@tonic-gate 	io_limit_lo = pci_config_get8(config_handle, PCI_BCNF_IO_LIMIT_LOW);
14120Sstevel@tonic-gate 	io_base_hi = pci_config_get16(config_handle, PCI_BCNF_IO_BASE_HI);
14130Sstevel@tonic-gate 	io_limit_hi = pci_config_get16(config_handle, PCI_BCNF_IO_LIMIT_HI);
14140Sstevel@tonic-gate 	mem_base = pci_config_get16(config_handle, PCI_BCNF_MEM_BASE);
14150Sstevel@tonic-gate 	mem_limit = pci_config_get16(config_handle, PCI_BCNF_MEM_LIMIT);
14160Sstevel@tonic-gate 
14170Sstevel@tonic-gate 	/*
14180Sstevel@tonic-gate 	 * Create ranges for IO space
14190Sstevel@tonic-gate 	 */
14200Sstevel@tonic-gate 	ranges[i].size_low = ranges[i].size_high = 0;
14210Sstevel@tonic-gate 	ranges[i].parent_mid = ranges[i].child_mid =
14220Sstevel@tonic-gate 		ranges[i].parent_high = 0;
14230Sstevel@tonic-gate 	ranges[i].child_high = ranges[i].parent_high |=
14240Sstevel@tonic-gate 		(PCI_REG_REL_M | PCI_ADDR_IO);
14250Sstevel@tonic-gate 	base = PPB_16bit_IOADDR(io_base_lo);
14260Sstevel@tonic-gate 	limit = PPB_16bit_IOADDR(io_limit_lo);
14270Sstevel@tonic-gate 
14280Sstevel@tonic-gate 	if ((io_base_lo & 0xf) == PPB_32BIT_IO) {
14290Sstevel@tonic-gate 		base = PPB_LADDR(base, io_base_hi);
14300Sstevel@tonic-gate 	}
14310Sstevel@tonic-gate 	if ((io_limit_lo & 0xf) == PPB_32BIT_IO) {
14320Sstevel@tonic-gate 		limit = PPB_LADDR(limit, io_limit_hi);
14330Sstevel@tonic-gate 	}
14340Sstevel@tonic-gate 
14350Sstevel@tonic-gate 	if ((io_base_lo & PPB_32BIT_IO) && (io_limit_hi > 0)) {
14360Sstevel@tonic-gate 		base = PPB_LADDR(base, io_base_hi);
14370Sstevel@tonic-gate 		limit = PPB_LADDR(limit, io_limit_hi);
14380Sstevel@tonic-gate 	}
14390Sstevel@tonic-gate 
14400Sstevel@tonic-gate 	/*
14410Sstevel@tonic-gate 	 * Create ranges for 32bit memory space
14420Sstevel@tonic-gate 	 */
14430Sstevel@tonic-gate 	base = PPB_32bit_MEMADDR(mem_base);
14440Sstevel@tonic-gate 	limit = PPB_32bit_MEMADDR(mem_limit);
14450Sstevel@tonic-gate 	ranges[i].size_low = ranges[i].size_high = 0;
14460Sstevel@tonic-gate 	ranges[i].parent_mid = ranges[i].child_mid =
14470Sstevel@tonic-gate 		ranges[i].parent_high = 0;
14480Sstevel@tonic-gate 	ranges[i].child_high = ranges[i].parent_high |=
14490Sstevel@tonic-gate 		(PCI_REG_REL_M | PCI_ADDR_MEM32);
14500Sstevel@tonic-gate 	ranges[i].child_low = ranges[i].parent_low = base;
14510Sstevel@tonic-gate 	if (limit >= base) {
14520Sstevel@tonic-gate 		ranges[i].size_low = limit - base + PPB_MEMGRAIN;
14530Sstevel@tonic-gate 		i++;
14540Sstevel@tonic-gate 	}
14550Sstevel@tonic-gate 
14560Sstevel@tonic-gate 	if (i) {
14570Sstevel@tonic-gate 		(void) ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "ranges",
14580Sstevel@tonic-gate 		    (int *)ranges, i * rangelen);
14590Sstevel@tonic-gate 	}
14600Sstevel@tonic-gate }
14610Sstevel@tonic-gate 
14620Sstevel@tonic-gate /* ARGSUSED */
14630Sstevel@tonic-gate static int
14640Sstevel@tonic-gate ppb_open(dev_t *devp, int flags, int otyp, cred_t *credp)
14650Sstevel@tonic-gate {
14660Sstevel@tonic-gate 	ppb_devstate_t *ppb_p;
14670Sstevel@tonic-gate 	minor_t		minor = getminor(*devp);
14680Sstevel@tonic-gate 	int		instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
14690Sstevel@tonic-gate 
14700Sstevel@tonic-gate 	/*
14710Sstevel@tonic-gate 	 * Make sure the open is for the right file type.
14720Sstevel@tonic-gate 	 */
14730Sstevel@tonic-gate 	if (otyp != OTYP_CHR)
14740Sstevel@tonic-gate 		return (EINVAL);
14750Sstevel@tonic-gate 
14760Sstevel@tonic-gate 	/*
14770Sstevel@tonic-gate 	 * Get the soft state structure for the device.
14780Sstevel@tonic-gate 	 */
14790Sstevel@tonic-gate 	ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
14800Sstevel@tonic-gate 	    instance);
14810Sstevel@tonic-gate 
14820Sstevel@tonic-gate 	if (ppb_p == NULL)
14830Sstevel@tonic-gate 		return (ENXIO);
14840Sstevel@tonic-gate 
14850Sstevel@tonic-gate 	if (ppb_p->hotplug_capable == B_TRUE)
14860Sstevel@tonic-gate 		return ((pcihp_get_cb_ops())->cb_open(devp, flags,
14870Sstevel@tonic-gate 		    otyp, credp));
14880Sstevel@tonic-gate 
14890Sstevel@tonic-gate 	/*
14900Sstevel@tonic-gate 	 * Handle the open by tracking the device state.
14910Sstevel@tonic-gate 	 */
14920Sstevel@tonic-gate 	mutex_enter(&ppb_p->ppb_mutex);
14930Sstevel@tonic-gate 	if (flags & FEXCL) {
14940Sstevel@tonic-gate 		if (ppb_p->ppb_soft_state != PPB_SOFT_STATE_CLOSED) {
14950Sstevel@tonic-gate 			mutex_exit(&ppb_p->ppb_mutex);
14960Sstevel@tonic-gate 			return (EBUSY);
14970Sstevel@tonic-gate 		}
14980Sstevel@tonic-gate 		ppb_p->ppb_soft_state = PPB_SOFT_STATE_OPEN_EXCL;
14990Sstevel@tonic-gate 	} else {
15000Sstevel@tonic-gate 		if (ppb_p->ppb_soft_state == PPB_SOFT_STATE_OPEN_EXCL) {
15010Sstevel@tonic-gate 			mutex_exit(&ppb_p->ppb_mutex);
15020Sstevel@tonic-gate 			return (EBUSY);
15030Sstevel@tonic-gate 		}
15040Sstevel@tonic-gate 		ppb_p->ppb_soft_state = PPB_SOFT_STATE_OPEN;
15050Sstevel@tonic-gate 	}
15060Sstevel@tonic-gate 	mutex_exit(&ppb_p->ppb_mutex);
15070Sstevel@tonic-gate 	return (0);
15080Sstevel@tonic-gate }
15090Sstevel@tonic-gate 
15100Sstevel@tonic-gate 
15110Sstevel@tonic-gate /* ARGSUSED */
15120Sstevel@tonic-gate static int
15130Sstevel@tonic-gate ppb_close(dev_t dev, int flags, int otyp, cred_t *credp)
15140Sstevel@tonic-gate {
15150Sstevel@tonic-gate 	ppb_devstate_t *ppb_p;
15160Sstevel@tonic-gate 	minor_t		minor = getminor(dev);
15170Sstevel@tonic-gate 	int		instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
15180Sstevel@tonic-gate 
15190Sstevel@tonic-gate 	if (otyp != OTYP_CHR)
15200Sstevel@tonic-gate 		return (EINVAL);
15210Sstevel@tonic-gate 
15220Sstevel@tonic-gate 	ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
15230Sstevel@tonic-gate 	    instance);
15240Sstevel@tonic-gate 
15250Sstevel@tonic-gate 	if (ppb_p == NULL)
15260Sstevel@tonic-gate 		return (ENXIO);
15270Sstevel@tonic-gate 
15280Sstevel@tonic-gate 	if (ppb_p->hotplug_capable == B_TRUE)
15290Sstevel@tonic-gate 		return ((pcihp_get_cb_ops())->cb_close(dev, flags,
15300Sstevel@tonic-gate 		    otyp, credp));
15310Sstevel@tonic-gate 
15320Sstevel@tonic-gate 	mutex_enter(&ppb_p->ppb_mutex);
15330Sstevel@tonic-gate 	ppb_p->ppb_soft_state = PPB_SOFT_STATE_CLOSED;
15340Sstevel@tonic-gate 	mutex_exit(&ppb_p->ppb_mutex);
15350Sstevel@tonic-gate 	return (0);
15360Sstevel@tonic-gate }
15370Sstevel@tonic-gate 
15380Sstevel@tonic-gate 
15390Sstevel@tonic-gate /*
15400Sstevel@tonic-gate  * ppb_ioctl: devctl hotplug controls
15410Sstevel@tonic-gate  */
15420Sstevel@tonic-gate /* ARGSUSED */
15430Sstevel@tonic-gate static int
15440Sstevel@tonic-gate ppb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
15450Sstevel@tonic-gate 	int *rvalp)
15460Sstevel@tonic-gate {
15470Sstevel@tonic-gate 	ppb_devstate_t *ppb_p;
15480Sstevel@tonic-gate 	dev_info_t *self;
15490Sstevel@tonic-gate 	struct devctl_iocdata *dcp;
15500Sstevel@tonic-gate 	uint_t bus_state;
15510Sstevel@tonic-gate 	int rv = 0;
15520Sstevel@tonic-gate 	minor_t		minor = getminor(dev);
15530Sstevel@tonic-gate 	int		instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
15540Sstevel@tonic-gate 
15550Sstevel@tonic-gate 	ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
15560Sstevel@tonic-gate 	    instance);
15570Sstevel@tonic-gate 
15580Sstevel@tonic-gate 	if (ppb_p == NULL)
15590Sstevel@tonic-gate 		return (ENXIO);
15600Sstevel@tonic-gate 
15610Sstevel@tonic-gate 	if (ppb_p->hotplug_capable == B_TRUE)
15620Sstevel@tonic-gate 		return ((pcihp_get_cb_ops())->cb_ioctl(dev, cmd,
15630Sstevel@tonic-gate 		    arg, mode, credp, rvalp));
15640Sstevel@tonic-gate 
15650Sstevel@tonic-gate 	self = ppb_p->dip;
15660Sstevel@tonic-gate 
15670Sstevel@tonic-gate 	/*
15680Sstevel@tonic-gate 	 * We can use the generic implementation for these ioctls
15690Sstevel@tonic-gate 	 */
15700Sstevel@tonic-gate 	switch (cmd) {
15710Sstevel@tonic-gate 	case DEVCTL_DEVICE_GETSTATE:
15720Sstevel@tonic-gate 	case DEVCTL_DEVICE_ONLINE:
15730Sstevel@tonic-gate 	case DEVCTL_DEVICE_OFFLINE:
15740Sstevel@tonic-gate 	case DEVCTL_BUS_GETSTATE:
15750Sstevel@tonic-gate 		return (ndi_devctl_ioctl(self, cmd, arg, mode, 0));
15760Sstevel@tonic-gate 	}
15770Sstevel@tonic-gate 
15780Sstevel@tonic-gate 	/*
15790Sstevel@tonic-gate 	 * read devctl ioctl data
15800Sstevel@tonic-gate 	 */
15810Sstevel@tonic-gate 	if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS)
15820Sstevel@tonic-gate 		return (EFAULT);
15830Sstevel@tonic-gate 
15840Sstevel@tonic-gate 	switch (cmd) {
15850Sstevel@tonic-gate 
15860Sstevel@tonic-gate 	case DEVCTL_DEVICE_RESET:
15870Sstevel@tonic-gate 		rv = ENOTSUP;
15880Sstevel@tonic-gate 		break;
15890Sstevel@tonic-gate 
15900Sstevel@tonic-gate 	case DEVCTL_BUS_QUIESCE:
15910Sstevel@tonic-gate 		if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
15920Sstevel@tonic-gate 			if (bus_state == BUS_QUIESCED)
15930Sstevel@tonic-gate 				break;
15940Sstevel@tonic-gate 		(void) ndi_set_bus_state(self, BUS_QUIESCED);
15950Sstevel@tonic-gate 		break;
15960Sstevel@tonic-gate 
15970Sstevel@tonic-gate 	case DEVCTL_BUS_UNQUIESCE:
15980Sstevel@tonic-gate 		if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
15990Sstevel@tonic-gate 			if (bus_state == BUS_ACTIVE)
16000Sstevel@tonic-gate 				break;
16010Sstevel@tonic-gate 		(void) ndi_set_bus_state(self, BUS_ACTIVE);
16020Sstevel@tonic-gate 		break;
16030Sstevel@tonic-gate 
16040Sstevel@tonic-gate 	case DEVCTL_BUS_RESET:
16050Sstevel@tonic-gate 		rv = ENOTSUP;
16060Sstevel@tonic-gate 		break;
16070Sstevel@tonic-gate 
16080Sstevel@tonic-gate 	case DEVCTL_BUS_RESETALL:
16090Sstevel@tonic-gate 		rv = ENOTSUP;
16100Sstevel@tonic-gate 		break;
16110Sstevel@tonic-gate 
16120Sstevel@tonic-gate 	default:
16130Sstevel@tonic-gate 		rv = ENOTTY;
16140Sstevel@tonic-gate 	}
16150Sstevel@tonic-gate 
16160Sstevel@tonic-gate 	ndi_dc_freehdl(dcp);
16170Sstevel@tonic-gate 	return (rv);
16180Sstevel@tonic-gate }
16190Sstevel@tonic-gate 
16200Sstevel@tonic-gate static int ppb_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
16210Sstevel@tonic-gate     int flags, char *name, caddr_t valuep, int *lengthp)
16220Sstevel@tonic-gate {
16230Sstevel@tonic-gate 	ppb_devstate_t *ppb_p;
16240Sstevel@tonic-gate 	minor_t		minor = getminor(dev);
16250Sstevel@tonic-gate 	int		instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
16260Sstevel@tonic-gate 
16270Sstevel@tonic-gate 	ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
16280Sstevel@tonic-gate 	    instance);
16290Sstevel@tonic-gate 
16300Sstevel@tonic-gate 	if (ppb_p == NULL)
16310Sstevel@tonic-gate 		return (ENXIO);
16320Sstevel@tonic-gate 
16330Sstevel@tonic-gate 	if (ppb_p->hotplug_capable == B_TRUE)
16340Sstevel@tonic-gate 		return ((pcihp_get_cb_ops())->cb_prop_op(dev, dip, prop_op,
16350Sstevel@tonic-gate 		    flags, name, valuep, lengthp));
16360Sstevel@tonic-gate 
16370Sstevel@tonic-gate 	return (ddi_prop_op(dev, dip, prop_op, flags, name, valuep, lengthp));
16380Sstevel@tonic-gate }
16390Sstevel@tonic-gate 
16400Sstevel@tonic-gate /*
16410Sstevel@tonic-gate  * Initialize our FMA resources
16420Sstevel@tonic-gate  */
16430Sstevel@tonic-gate static void
16440Sstevel@tonic-gate ppb_fm_init(ppb_devstate_t *ppb_p)
16450Sstevel@tonic-gate {
16460Sstevel@tonic-gate 	ddi_fm_error_t derr;
16470Sstevel@tonic-gate 
16480Sstevel@tonic-gate 	ppb_p->fm_cap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE |
16490Sstevel@tonic-gate 		DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE;
16500Sstevel@tonic-gate 
16510Sstevel@tonic-gate 	/*
16520Sstevel@tonic-gate 	 * Request our capability level and get our parents capability
16530Sstevel@tonic-gate 	 * and ibc.
16540Sstevel@tonic-gate 	 */
16550Sstevel@tonic-gate 	ddi_fm_init(ppb_p->dip, &ppb_p->fm_cap, &ppb_p->fm_ibc);
16560Sstevel@tonic-gate 	ASSERT((ppb_p->fm_cap & DDI_FM_EREPORT_CAPABLE) &&
16570Sstevel@tonic-gate 	    (ppb_p->fm_cap & DDI_FM_ERRCB_CAPABLE));
16580Sstevel@tonic-gate 
16590Sstevel@tonic-gate 	pci_ereport_setup(ppb_p->dip);
16600Sstevel@tonic-gate 
16610Sstevel@tonic-gate 	/*
16620Sstevel@tonic-gate 	 * clear any outstanding error bits
16630Sstevel@tonic-gate 	 */
16640Sstevel@tonic-gate 	bzero(&derr, sizeof (ddi_fm_error_t));
16650Sstevel@tonic-gate 	derr.fme_version = DDI_FME_VERSION;
16660Sstevel@tonic-gate 	derr.fme_flag = DDI_FM_ERR_EXPECTED;
16670Sstevel@tonic-gate 	pci_ereport_post(ppb_p->dip, &derr, NULL);
16680Sstevel@tonic-gate 	pci_bdg_ereport_post(ppb_p->dip, &derr, NULL);
16690Sstevel@tonic-gate 
16700Sstevel@tonic-gate 	/*
16710Sstevel@tonic-gate 	 * Register error callback with our parent.
16720Sstevel@tonic-gate 	 */
16730Sstevel@tonic-gate 	ddi_fm_handler_register(ppb_p->dip, ppb_err_callback, NULL);
16740Sstevel@tonic-gate }
16750Sstevel@tonic-gate 
16760Sstevel@tonic-gate /*
16770Sstevel@tonic-gate  * Breakdown our FMA resources
16780Sstevel@tonic-gate  */
16790Sstevel@tonic-gate static void
16800Sstevel@tonic-gate ppb_fm_fini(ppb_devstate_t *ppb_p)
16810Sstevel@tonic-gate {
16820Sstevel@tonic-gate 	/*
16830Sstevel@tonic-gate 	 * Clean up allocated fm structures
16840Sstevel@tonic-gate 	 */
16850Sstevel@tonic-gate 	ddi_fm_handler_unregister(ppb_p->dip);
16860Sstevel@tonic-gate 	pci_ereport_teardown(ppb_p->dip);
16870Sstevel@tonic-gate 	ddi_fm_fini(ppb_p->dip);
16880Sstevel@tonic-gate }
16890Sstevel@tonic-gate 
16900Sstevel@tonic-gate /*
16910Sstevel@tonic-gate  * Initialize FMA resources for children devices. Called when
16920Sstevel@tonic-gate  * child calls ddi_fm_init().
16930Sstevel@tonic-gate  */
16940Sstevel@tonic-gate /*ARGSUSED*/
16950Sstevel@tonic-gate static int
16960Sstevel@tonic-gate ppb_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap,
16970Sstevel@tonic-gate 		ddi_iblock_cookie_t *ibc)
16980Sstevel@tonic-gate {
16990Sstevel@tonic-gate 	ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state,
17000Sstevel@tonic-gate 			ddi_get_instance(dip));
17010Sstevel@tonic-gate 	*ibc = ppb_p->fm_ibc;
17020Sstevel@tonic-gate 	return (ppb_p->fm_cap);
17030Sstevel@tonic-gate }
17040Sstevel@tonic-gate 
17050Sstevel@tonic-gate /*
17060Sstevel@tonic-gate  * FMA registered error callback
17070Sstevel@tonic-gate  */
17080Sstevel@tonic-gate static int
17090Sstevel@tonic-gate ppb_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *impl_data)
17100Sstevel@tonic-gate {
17110Sstevel@tonic-gate 	uint16_t pci_cfg_stat, pci_cfg_sec_stat;
17120Sstevel@tonic-gate 
17130Sstevel@tonic-gate 	ASSERT(impl_data == NULL);
17140Sstevel@tonic-gate 	pci_ereport_post(dip, derr, &pci_cfg_stat);
17150Sstevel@tonic-gate 	pci_bdg_ereport_post(dip, derr, &pci_cfg_sec_stat);
17160Sstevel@tonic-gate 	return (pci_bdg_check_status(dip, derr, pci_cfg_stat,
17170Sstevel@tonic-gate 	    pci_cfg_sec_stat));
17180Sstevel@tonic-gate }
17190Sstevel@tonic-gate 
17200Sstevel@tonic-gate static void
17210Sstevel@tonic-gate ppb_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle)
17220Sstevel@tonic-gate {
17230Sstevel@tonic-gate 	i_ndi_busop_access_enter(dip, handle);
17240Sstevel@tonic-gate }
17250Sstevel@tonic-gate 
17260Sstevel@tonic-gate /* ARGSUSED */
17270Sstevel@tonic-gate static void
17280Sstevel@tonic-gate ppb_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle)
17290Sstevel@tonic-gate {
17300Sstevel@tonic-gate 	i_ndi_busop_access_exit(dip, handle);
17310Sstevel@tonic-gate }
1732