xref: /onnv-gate/usr/src/uts/i86pc/io/pci/pci.c (revision 6313)
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
51865Sdilpreet  * Common Development and Distribution License (the "License").
61865Sdilpreet  * 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*6313Skrishnae  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  *	Host to PCI local bus driver
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/conf.h>
330Sstevel@tonic-gate #include <sys/modctl.h>
340Sstevel@tonic-gate #include <sys/pci.h>
350Sstevel@tonic-gate #include <sys/pci_impl.h>
36881Sjohnny #include <sys/sysmacros.h>
370Sstevel@tonic-gate #include <sys/sunndi.h>
381865Sdilpreet #include <sys/ddifm.h>
391865Sdilpreet #include <sys/ndifm.h>
401865Sdilpreet #include <sys/fm/protocol.h>
410Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h>
42881Sjohnny #include <io/pci/pci_common.h>
43881Sjohnny #include <io/pci/pci_tools_ext.h>
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /* Save minimal state. */
460Sstevel@tonic-gate void *pci_statep;
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * Bus Operation functions
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate static int	pci_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *,
520Sstevel@tonic-gate 		    off_t, off_t, caddr_t *);
530Sstevel@tonic-gate static int	pci_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
540Sstevel@tonic-gate 		    void *, void *);
550Sstevel@tonic-gate static int	pci_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t,
560Sstevel@tonic-gate 		    ddi_intr_handle_impl_t *, void *);
571865Sdilpreet static int	pci_fm_init(dev_info_t *, dev_info_t *, int,
581865Sdilpreet 		    ddi_iblock_cookie_t *);
591865Sdilpreet static int	pci_fm_callback(dev_info_t *, ddi_fm_error_t *, const void *);
600Sstevel@tonic-gate 
610Sstevel@tonic-gate struct bus_ops pci_bus_ops = {
620Sstevel@tonic-gate 	BUSO_REV,
630Sstevel@tonic-gate 	pci_bus_map,
640Sstevel@tonic-gate 	NULL,
650Sstevel@tonic-gate 	NULL,
660Sstevel@tonic-gate 	NULL,
670Sstevel@tonic-gate 	i_ddi_map_fault,
680Sstevel@tonic-gate 	ddi_dma_map,
690Sstevel@tonic-gate 	ddi_dma_allochdl,
700Sstevel@tonic-gate 	ddi_dma_freehdl,
710Sstevel@tonic-gate 	ddi_dma_bindhdl,
720Sstevel@tonic-gate 	ddi_dma_unbindhdl,
730Sstevel@tonic-gate 	ddi_dma_flush,
740Sstevel@tonic-gate 	ddi_dma_win,
750Sstevel@tonic-gate 	ddi_dma_mctl,
760Sstevel@tonic-gate 	pci_ctlops,
770Sstevel@tonic-gate 	ddi_bus_prop_op,
780Sstevel@tonic-gate 	0,		/* (*bus_get_eventcookie)();	*/
790Sstevel@tonic-gate 	0,		/* (*bus_add_eventcall)();	*/
800Sstevel@tonic-gate 	0,		/* (*bus_remove_eventcall)();	*/
810Sstevel@tonic-gate 	0,		/* (*bus_post_event)();		*/
820Sstevel@tonic-gate 	0,		/* (*bus_intr_ctl)(); */
830Sstevel@tonic-gate 	0,		/* (*bus_config)(); */
840Sstevel@tonic-gate 	0,		/* (*bus_unconfig)(); */
851865Sdilpreet 	pci_fm_init,	/* (*bus_fm_init)(); */
860Sstevel@tonic-gate 	NULL,		/* (*bus_fm_fini)(); */
870Sstevel@tonic-gate 	NULL,		/* (*bus_fm_access_enter)(); */
880Sstevel@tonic-gate 	NULL,		/* (*bus_fm_access_exit)(); */
890Sstevel@tonic-gate 	NULL,		/* (*bus_power)(); */
900Sstevel@tonic-gate 	pci_intr_ops	/* (*bus_intr_op)(); */
910Sstevel@tonic-gate };
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate  * One goal here is to leverage off of the pcihp.c source without making
950Sstevel@tonic-gate  * changes to it.  Call into it's cb_ops directly if needed, piggybacking
960Sstevel@tonic-gate  * anything else needed by the pci_tools.c module.  Only pci_tools and pcihp
97117Sschwartz  * will be opening PCI nexus driver file descriptors.
980Sstevel@tonic-gate  */
99881Sjohnny static int	pci_open(dev_t *, int, int, cred_t *);
100881Sjohnny static int	pci_close(dev_t, int, int, cred_t *);
101881Sjohnny static int	pci_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
102881Sjohnny static int	pci_prop_op(dev_t, dev_info_t *, ddi_prop_op_t, int, char *,
103881Sjohnny 		    caddr_t, int *);
104881Sjohnny static int	pci_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
105*6313Skrishnae static void	pci_peekpoke_cb(dev_info_t *, ddi_fm_error_t *);
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate struct cb_ops pci_cb_ops = {
1080Sstevel@tonic-gate 	pci_open,			/* open */
1090Sstevel@tonic-gate 	pci_close,			/* close */
1100Sstevel@tonic-gate 	nodev,				/* strategy */
1110Sstevel@tonic-gate 	nodev,				/* print */
1120Sstevel@tonic-gate 	nodev,				/* dump */
1130Sstevel@tonic-gate 	nodev,				/* read */
1140Sstevel@tonic-gate 	nodev,				/* write */
1150Sstevel@tonic-gate 	pci_ioctl,			/* ioctl */
1160Sstevel@tonic-gate 	nodev,				/* devmap */
1170Sstevel@tonic-gate 	nodev,				/* mmap */
1180Sstevel@tonic-gate 	nodev,				/* segmap */
1190Sstevel@tonic-gate 	nochpoll,			/* poll */
1200Sstevel@tonic-gate 	pci_prop_op,			/* cb_prop_op */
1210Sstevel@tonic-gate 	NULL,				/* streamtab */
1220Sstevel@tonic-gate 	D_NEW | D_MP | D_HOTPLUG,	/* Driver compatibility flag */
1230Sstevel@tonic-gate 	CB_REV,				/* rev */
1240Sstevel@tonic-gate 	nodev,				/* int (*cb_aread)() */
1250Sstevel@tonic-gate 	nodev				/* int (*cb_awrite)() */
1260Sstevel@tonic-gate };
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /*
1290Sstevel@tonic-gate  * Device Node Operation functions
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate static int pci_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
1320Sstevel@tonic-gate static int pci_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate struct dev_ops pci_ops = {
1350Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev */
1360Sstevel@tonic-gate 	0,			/* refcnt  */
1370Sstevel@tonic-gate 	pci_info,		/* info */
1380Sstevel@tonic-gate 	nulldev,		/* identify */
1390Sstevel@tonic-gate 	nulldev,		/* probe */
1400Sstevel@tonic-gate 	pci_attach,		/* attach */
1410Sstevel@tonic-gate 	pci_detach,		/* detach */
1420Sstevel@tonic-gate 	nulldev,		/* reset */
1430Sstevel@tonic-gate 	&pci_cb_ops,		/* driver operations */
1440Sstevel@tonic-gate 	&pci_bus_ops		/* bus operations */
1450Sstevel@tonic-gate };
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate /*
148354Smyers  * This variable controls the default setting of the command register
149354Smyers  * for pci devices.  See pci_initchild() for details.
150354Smyers  */
151354Smyers static ushort_t pci_command_default = PCI_COMM_ME |
152354Smyers 					PCI_COMM_MAE |
153354Smyers 					PCI_COMM_IO;
154354Smyers 
155354Smyers /*
1560Sstevel@tonic-gate  * Internal routines in support of particular pci_ctlops.
1570Sstevel@tonic-gate  */
1580Sstevel@tonic-gate static int pci_removechild(dev_info_t *child);
1590Sstevel@tonic-gate static int pci_initchild(dev_info_t *child);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * Module linkage information for the kernel.
1630Sstevel@tonic-gate  */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate static struct modldrv modldrv = {
1660Sstevel@tonic-gate 	&mod_driverops, /* Type of module */
1670Sstevel@tonic-gate 	"host to PCI nexus driver %I%",
1680Sstevel@tonic-gate 	&pci_ops,	/* driver ops */
1690Sstevel@tonic-gate };
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate static struct modlinkage modlinkage = {
1720Sstevel@tonic-gate 	MODREV_1,
1730Sstevel@tonic-gate 	(void *)&modldrv,
1740Sstevel@tonic-gate 	NULL
1750Sstevel@tonic-gate };
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate int
1780Sstevel@tonic-gate _init(void)
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate 	int e;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 	/*
1830Sstevel@tonic-gate 	 * Initialize per-pci bus soft state pointer.
1840Sstevel@tonic-gate 	 */
1850Sstevel@tonic-gate 	e = ddi_soft_state_init(&pci_statep, sizeof (pci_state_t), 1);
1860Sstevel@tonic-gate 	if (e != 0)
1870Sstevel@tonic-gate 		return (e);
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 	if ((e = mod_install(&modlinkage)) != 0)
1900Sstevel@tonic-gate 		ddi_soft_state_fini(&pci_statep);
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	return (e);
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate int
1960Sstevel@tonic-gate _fini(void)
1970Sstevel@tonic-gate {
1980Sstevel@tonic-gate 	int rc;
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate 	rc = mod_remove(&modlinkage);
2010Sstevel@tonic-gate 	if (rc != 0)
2020Sstevel@tonic-gate 		return (rc);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	ddi_soft_state_fini(&pci_statep);
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	return (rc);
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate int
2100Sstevel@tonic-gate _info(struct modinfo *modinfop)
2110Sstevel@tonic-gate {
2120Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2130Sstevel@tonic-gate }
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate /*ARGSUSED*/
2160Sstevel@tonic-gate static int
2170Sstevel@tonic-gate pci_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
2180Sstevel@tonic-gate {
2190Sstevel@tonic-gate 	/*
2200Sstevel@tonic-gate 	 * Use the minor number as constructed by pcihp, as the index value to
2210Sstevel@tonic-gate 	 * ddi_soft_state_zalloc.
2220Sstevel@tonic-gate 	 */
223117Sschwartz 	int instance = ddi_get_instance(devi);
2240Sstevel@tonic-gate 	pci_state_t *pcip = NULL;
2255295Srandyf 	switch (cmd) {
2265295Srandyf 	case DDI_ATTACH:
2275295Srandyf 		break;
2285295Srandyf 
2295295Srandyf 	case DDI_RESUME:
2305295Srandyf 		return (DDI_SUCCESS);
2315295Srandyf 
2325295Srandyf 	default:
2335295Srandyf 		return (DDI_FAILURE);
2345295Srandyf 	}
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 	if (ddi_prop_update_string(DDI_DEV_T_NONE, devi, "device_type", "pci")
2370Sstevel@tonic-gate 	    != DDI_PROP_SUCCESS) {
2380Sstevel@tonic-gate 		cmn_err(CE_WARN, "pci:  'device_type' prop create failed");
2390Sstevel@tonic-gate 	}
2400Sstevel@tonic-gate 
241117Sschwartz 	if (ddi_soft_state_zalloc(pci_statep, instance) == DDI_SUCCESS) {
242117Sschwartz 		pcip = ddi_get_soft_state(pci_statep, instance);
2430Sstevel@tonic-gate 	}
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	if (pcip == NULL) {
246117Sschwartz 		goto bad_soft_state;
2470Sstevel@tonic-gate 	}
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	pcip->pci_dip = devi;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * Initialize hotplug support on this bus. At minimum
2530Sstevel@tonic-gate 	 * (for non hotplug bus) this would create ":devctl" minor
2540Sstevel@tonic-gate 	 * node to support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls
2550Sstevel@tonic-gate 	 * to this bus.
2560Sstevel@tonic-gate 	 */
2570Sstevel@tonic-gate 	if (pcihp_init(devi) != DDI_SUCCESS) {
2580Sstevel@tonic-gate 		cmn_err(CE_WARN, "pci: Failed to setup hotplug framework");
259117Sschwartz 		goto bad_pcihp_init;
260117Sschwartz 	}
261117Sschwartz 
262777Sschwartz 	/* Second arg: initialize for pci, not pci_express */
263777Sschwartz 	if (pcitool_init(devi, B_FALSE) != DDI_SUCCESS) {
264117Sschwartz 		goto bad_pcitool_init;
2650Sstevel@tonic-gate 	}
2660Sstevel@tonic-gate 
2671865Sdilpreet 	pcip->pci_fmcap = DDI_FM_ERRCB_CAPABLE |
2681865Sdilpreet 	    DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE;
2691865Sdilpreet 	ddi_fm_init(devi, &pcip->pci_fmcap, &pcip->pci_fm_ibc);
2701865Sdilpreet 	mutex_init(&pcip->pci_err_mutex, NULL, MUTEX_DRIVER,
2711865Sdilpreet 	    (void *)pcip->pci_fm_ibc);
2721865Sdilpreet 	mutex_init(&pcip->pci_peek_poke_mutex, NULL, MUTEX_DRIVER,
2731865Sdilpreet 	    (void *)pcip->pci_fm_ibc);
2741865Sdilpreet 	if (pcip->pci_fmcap & DDI_FM_ERRCB_CAPABLE) {
2751865Sdilpreet 		pci_ereport_setup(devi);
2761865Sdilpreet 		ddi_fm_handler_register(devi, pci_fm_callback, NULL);
2771865Sdilpreet 	}
2781865Sdilpreet 
2790Sstevel@tonic-gate 	ddi_report_dev(devi);
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	return (DDI_SUCCESS);
282117Sschwartz 
283117Sschwartz bad_pcitool_init:
284117Sschwartz 	(void) pcihp_uninit(devi);
285117Sschwartz bad_pcihp_init:
286117Sschwartz 	ddi_soft_state_free(pci_statep, instance);
287117Sschwartz bad_soft_state:
288117Sschwartz 	return (DDI_FAILURE);
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate /*ARGSUSED*/
2920Sstevel@tonic-gate static int
2930Sstevel@tonic-gate pci_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
2940Sstevel@tonic-gate {
295916Sschwartz 	int instance = ddi_get_instance(devi);
2961865Sdilpreet 	pci_state_t *pcip;
2971865Sdilpreet 
2981865Sdilpreet 	pcip = ddi_get_soft_state(pci_statep, ddi_get_instance(devi));
2995295Srandyf 
300916Sschwartz 
3015295Srandyf 	switch (cmd) {
3025295Srandyf 	case DDI_DETACH:
3035295Srandyf 		if (pcip->pci_fmcap & DDI_FM_ERRCB_CAPABLE) {
3045295Srandyf 			ddi_fm_handler_unregister(devi);
3055295Srandyf 			pci_ereport_teardown(devi);
3065295Srandyf 		}
3075295Srandyf 		mutex_destroy(&pcip->pci_peek_poke_mutex);
3085295Srandyf 		mutex_destroy(&pcip->pci_err_mutex);
3095295Srandyf 		ddi_fm_fini(devi);	/* Uninitialize pcitool support. */
3105295Srandyf 		pcitool_uninit(devi);
311117Sschwartz 
3125295Srandyf 		/* Uninitialize hotplug support on this bus. */
3135295Srandyf 		(void) pcihp_uninit(devi);
3145295Srandyf 
3155295Srandyf 		ddi_soft_state_free(pci_statep, instance);
316117Sschwartz 
3175295Srandyf 		return (DDI_SUCCESS);
3185295Srandyf 	case DDI_SUSPEND:
3195295Srandyf 		return (DDI_SUCCESS);
3205295Srandyf 	default:
3215295Srandyf 		return (DDI_FAILURE);
3225295Srandyf 	}
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate static int
3260Sstevel@tonic-gate pci_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
3270Sstevel@tonic-gate 	off_t offset, off_t len, caddr_t *vaddrp)
3280Sstevel@tonic-gate {
3290Sstevel@tonic-gate 	struct regspec reg;
3300Sstevel@tonic-gate 	ddi_map_req_t mr;
3310Sstevel@tonic-gate 	ddi_acc_hdl_t *hp;
3320Sstevel@tonic-gate 	pci_regspec_t pci_reg;
3330Sstevel@tonic-gate 	pci_regspec_t *pci_rp;
3340Sstevel@tonic-gate 	int 	rnumber;
3350Sstevel@tonic-gate 	int	length;
3360Sstevel@tonic-gate 	pci_acc_cfblk_t *cfp;
3370Sstevel@tonic-gate 	int	space;
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	mr = *mp; /* Get private copy of request */
3410Sstevel@tonic-gate 	mp = &mr;
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	/*
3440Sstevel@tonic-gate 	 * check for register number
3450Sstevel@tonic-gate 	 */
3460Sstevel@tonic-gate 	switch (mp->map_type) {
3470Sstevel@tonic-gate 	case DDI_MT_REGSPEC:
3480Sstevel@tonic-gate 		pci_reg = *(pci_regspec_t *)(mp->map_obj.rp);
3490Sstevel@tonic-gate 		pci_rp = &pci_reg;
350881Sjohnny 		if (pci_common_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS)
3510Sstevel@tonic-gate 			return (DDI_FAILURE);
3520Sstevel@tonic-gate 		break;
3530Sstevel@tonic-gate 	case DDI_MT_RNUMBER:
3540Sstevel@tonic-gate 		rnumber = mp->map_obj.rnumber;
3550Sstevel@tonic-gate 		/*
3560Sstevel@tonic-gate 		 * get ALL "reg" properties for dip, select the one of
3570Sstevel@tonic-gate 		 * of interest. In x86, "assigned-addresses" property
3580Sstevel@tonic-gate 		 * is identical to the "reg" property, so there is no
3590Sstevel@tonic-gate 		 * need to cross check the two to determine the physical
3600Sstevel@tonic-gate 		 * address of the registers.
3610Sstevel@tonic-gate 		 * This routine still performs some validity checks to
3620Sstevel@tonic-gate 		 * make sure that everything is okay.
3630Sstevel@tonic-gate 		 */
364881Sjohnny 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip,
365881Sjohnny 		    DDI_PROP_DONTPASS, "reg", (int **)&pci_rp,
366881Sjohnny 		    (uint_t *)&length) != DDI_PROP_SUCCESS)
3670Sstevel@tonic-gate 			return (DDI_FAILURE);
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 		/*
3700Sstevel@tonic-gate 		 * validate the register number.
3710Sstevel@tonic-gate 		 */
3720Sstevel@tonic-gate 		length /= (sizeof (pci_regspec_t) / sizeof (int));
3730Sstevel@tonic-gate 		if (rnumber >= length) {
3740Sstevel@tonic-gate 			ddi_prop_free(pci_rp);
3750Sstevel@tonic-gate 			return (DDI_FAILURE);
3760Sstevel@tonic-gate 		}
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 		/*
3790Sstevel@tonic-gate 		 * copy the required entry.
3800Sstevel@tonic-gate 		 */
3810Sstevel@tonic-gate 		pci_reg = pci_rp[rnumber];
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 		/*
3840Sstevel@tonic-gate 		 * free the memory allocated by ddi_prop_lookup_int_array
3850Sstevel@tonic-gate 		 */
3860Sstevel@tonic-gate 		ddi_prop_free(pci_rp);
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 		pci_rp = &pci_reg;
389881Sjohnny 		if (pci_common_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS)
3900Sstevel@tonic-gate 			return (DDI_FAILURE);
3910Sstevel@tonic-gate 		mp->map_type = DDI_MT_REGSPEC;
3920Sstevel@tonic-gate 		break;
3930Sstevel@tonic-gate 	default:
3940Sstevel@tonic-gate 		return (DDI_ME_INVAL);
3950Sstevel@tonic-gate 	}
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 	space = pci_rp->pci_phys_hi & PCI_REG_ADDR_M;
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 	/*
4000Sstevel@tonic-gate 	 * check for unmap and unlock of address space
4010Sstevel@tonic-gate 	 */
4020Sstevel@tonic-gate 	if ((mp->map_op == DDI_MO_UNMAP) || (mp->map_op == DDI_MO_UNLOCK)) {
4030Sstevel@tonic-gate 		/*
4040Sstevel@tonic-gate 		 * Adjust offset and length
4050Sstevel@tonic-gate 		 * A non-zero length means override the one in the regspec.
4060Sstevel@tonic-gate 		 */
4070Sstevel@tonic-gate 		pci_rp->pci_phys_low += (uint_t)offset;
4080Sstevel@tonic-gate 		if (len != 0)
4090Sstevel@tonic-gate 			pci_rp->pci_size_low = len;
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 		switch (space) {
4120Sstevel@tonic-gate 		case PCI_ADDR_CONFIG:
4130Sstevel@tonic-gate 			/* No work required on unmap of Config space */
4140Sstevel@tonic-gate 			return (DDI_SUCCESS);
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 		case PCI_ADDR_IO:
4170Sstevel@tonic-gate 			reg.regspec_bustype = 1;
4180Sstevel@tonic-gate 			break;
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 		case PCI_ADDR_MEM64:
4210Sstevel@tonic-gate 			/*
4220Sstevel@tonic-gate 			 * MEM64 requires special treatment on map, to check
4230Sstevel@tonic-gate 			 * that the device is below 4G.  On unmap, however,
4240Sstevel@tonic-gate 			 * we can assume that everything is OK... the map
4250Sstevel@tonic-gate 			 * must have succeeded.
4260Sstevel@tonic-gate 			 */
4270Sstevel@tonic-gate 			/* FALLTHROUGH */
4280Sstevel@tonic-gate 		case PCI_ADDR_MEM32:
4290Sstevel@tonic-gate 			reg.regspec_bustype = 0;
4300Sstevel@tonic-gate 			break;
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 		default:
4330Sstevel@tonic-gate 			return (DDI_FAILURE);
4340Sstevel@tonic-gate 		}
4350Sstevel@tonic-gate 		reg.regspec_addr = pci_rp->pci_phys_low;
4360Sstevel@tonic-gate 		reg.regspec_size = pci_rp->pci_size_low;
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate 		mp->map_obj.rp = &reg;
4390Sstevel@tonic-gate 		return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp));
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	}
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate 	/* check for user mapping request - not legal for Config */
4440Sstevel@tonic-gate 	if (mp->map_op == DDI_MO_MAP_HANDLE && space == PCI_ADDR_CONFIG) {
4450Sstevel@tonic-gate 		return (DDI_FAILURE);
4460Sstevel@tonic-gate 	}
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	/*
4490Sstevel@tonic-gate 	 * check for config space
4500Sstevel@tonic-gate 	 * On x86, CONFIG is not mapped via MMU and there is
4510Sstevel@tonic-gate 	 * no endian-ness issues. Set the attr field in the handle to
4520Sstevel@tonic-gate 	 * indicate that the common routines to call the nexus driver.
4530Sstevel@tonic-gate 	 */
4540Sstevel@tonic-gate 	if (space == PCI_ADDR_CONFIG) {
4551865Sdilpreet 		/* Can't map config space without a handle */
4560Sstevel@tonic-gate 		hp = (ddi_acc_hdl_t *)mp->map_handlep;
457881Sjohnny 		if (hp == NULL)
4580Sstevel@tonic-gate 			return (DDI_FAILURE);
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 		/* record the device address for future reference */
4610Sstevel@tonic-gate 		cfp = (pci_acc_cfblk_t *)&hp->ah_bus_private;
4620Sstevel@tonic-gate 		cfp->c_busnum = PCI_REG_BUS_G(pci_rp->pci_phys_hi);
4630Sstevel@tonic-gate 		cfp->c_devnum = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
4640Sstevel@tonic-gate 		cfp->c_funcnum = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
4650Sstevel@tonic-gate 
4661865Sdilpreet 		*vaddrp = (caddr_t)offset;
4671865Sdilpreet 		return (pci_fm_acc_setup(hp, offset, len));
4680Sstevel@tonic-gate 	}
4690Sstevel@tonic-gate 
4700Sstevel@tonic-gate 	/*
4710Sstevel@tonic-gate 	 * range check
4720Sstevel@tonic-gate 	 */
4730Sstevel@tonic-gate 	if ((offset >= pci_rp->pci_size_low) ||
4740Sstevel@tonic-gate 	    (len > pci_rp->pci_size_low) ||
4750Sstevel@tonic-gate 	    (offset + len > pci_rp->pci_size_low)) {
4760Sstevel@tonic-gate 		return (DDI_FAILURE);
4770Sstevel@tonic-gate 	}
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	/*
4800Sstevel@tonic-gate 	 * Adjust offset and length
4810Sstevel@tonic-gate 	 * A non-zero length means override the one in the regspec.
4820Sstevel@tonic-gate 	 */
4830Sstevel@tonic-gate 	pci_rp->pci_phys_low += (uint_t)offset;
4840Sstevel@tonic-gate 	if (len != 0)
4850Sstevel@tonic-gate 		pci_rp->pci_size_low = len;
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate 	/*
4880Sstevel@tonic-gate 	 * convert the pci regsec into the generic regspec used by the
4890Sstevel@tonic-gate 	 * parent root nexus driver.
4900Sstevel@tonic-gate 	 */
4910Sstevel@tonic-gate 	switch (space) {
4920Sstevel@tonic-gate 	case PCI_ADDR_IO:
4930Sstevel@tonic-gate 		reg.regspec_bustype = 1;
4940Sstevel@tonic-gate 		break;
4950Sstevel@tonic-gate 	case PCI_ADDR_MEM64:
4960Sstevel@tonic-gate 		/*
4970Sstevel@tonic-gate 		 * We can't handle 64-bit devices that are mapped above
4980Sstevel@tonic-gate 		 * 4G or that are larger than 4G.
4990Sstevel@tonic-gate 		 */
5000Sstevel@tonic-gate 		if (pci_rp->pci_phys_mid != 0 ||
5010Sstevel@tonic-gate 		    pci_rp->pci_size_hi != 0)
5020Sstevel@tonic-gate 			return (DDI_FAILURE);
5030Sstevel@tonic-gate 		/*
5040Sstevel@tonic-gate 		 * Other than that, we can treat them as 32-bit mappings
5050Sstevel@tonic-gate 		 */
5060Sstevel@tonic-gate 		/* FALLTHROUGH */
5070Sstevel@tonic-gate 	case PCI_ADDR_MEM32:
5080Sstevel@tonic-gate 		reg.regspec_bustype = 0;
5090Sstevel@tonic-gate 		break;
5100Sstevel@tonic-gate 	default:
5110Sstevel@tonic-gate 		return (DDI_FAILURE);
5120Sstevel@tonic-gate 	}
5130Sstevel@tonic-gate 	reg.regspec_addr = pci_rp->pci_phys_low;
5140Sstevel@tonic-gate 	reg.regspec_size = pci_rp->pci_size_low;
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 	mp->map_obj.rp = &reg;
5170Sstevel@tonic-gate 	return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp));
5180Sstevel@tonic-gate }
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate /*ARGSUSED*/
5220Sstevel@tonic-gate static int
5230Sstevel@tonic-gate pci_ctlops(dev_info_t *dip, dev_info_t *rdip,
5240Sstevel@tonic-gate 	ddi_ctl_enum_t ctlop, void *arg, void *result)
5250Sstevel@tonic-gate {
5260Sstevel@tonic-gate 	pci_regspec_t *drv_regp;
5270Sstevel@tonic-gate 	uint_t	reglen;
5280Sstevel@tonic-gate 	int	rn;
5290Sstevel@tonic-gate 	int	totreg;
5301865Sdilpreet 	pci_state_t *pcip;
5315295Srandyf 	struct  attachspec *asp;
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 	switch (ctlop) {
5340Sstevel@tonic-gate 	case DDI_CTLOPS_REPORTDEV:
5350Sstevel@tonic-gate 		if (rdip == (dev_info_t *)0)
5360Sstevel@tonic-gate 			return (DDI_FAILURE);
5370Sstevel@tonic-gate 		cmn_err(CE_CONT, "?PCI-device: %s@%s, %s%d\n",
5380Sstevel@tonic-gate 		    ddi_node_name(rdip), ddi_get_name_addr(rdip),
5390Sstevel@tonic-gate 		    ddi_driver_name(rdip),
5400Sstevel@tonic-gate 		    ddi_get_instance(rdip));
5410Sstevel@tonic-gate 		return (DDI_SUCCESS);
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate 	case DDI_CTLOPS_INITCHILD:
5440Sstevel@tonic-gate 		return (pci_initchild((dev_info_t *)arg));
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate 	case DDI_CTLOPS_UNINITCHILD:
5470Sstevel@tonic-gate 		return (pci_removechild((dev_info_t *)arg));
5480Sstevel@tonic-gate 
5490Sstevel@tonic-gate 	case DDI_CTLOPS_SIDDEV:
5500Sstevel@tonic-gate 		return (DDI_SUCCESS);
5510Sstevel@tonic-gate 
5520Sstevel@tonic-gate 	case DDI_CTLOPS_REGSIZE:
5530Sstevel@tonic-gate 	case DDI_CTLOPS_NREGS:
5540Sstevel@tonic-gate 		if (rdip == (dev_info_t *)0)
5550Sstevel@tonic-gate 			return (DDI_FAILURE);
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 		*(int *)result = 0;
5580Sstevel@tonic-gate 		if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip,
5595295Srandyf 		    DDI_PROP_DONTPASS, "reg", (int **)&drv_regp,
5605295Srandyf 		    &reglen) != DDI_PROP_SUCCESS) {
5610Sstevel@tonic-gate 			return (DDI_FAILURE);
5620Sstevel@tonic-gate 		}
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 		totreg = (reglen * sizeof (int)) / sizeof (pci_regspec_t);
5650Sstevel@tonic-gate 		if (ctlop == DDI_CTLOPS_NREGS)
5660Sstevel@tonic-gate 			*(int *)result = totreg;
5670Sstevel@tonic-gate 		else if (ctlop == DDI_CTLOPS_REGSIZE) {
5680Sstevel@tonic-gate 			rn = *(int *)arg;
5690Sstevel@tonic-gate 			if (rn >= totreg) {
5700Sstevel@tonic-gate 				ddi_prop_free(drv_regp);
5710Sstevel@tonic-gate 				return (DDI_FAILURE);
5720Sstevel@tonic-gate 			}
5730Sstevel@tonic-gate 			*(off_t *)result = drv_regp[rn].pci_size_low;
5740Sstevel@tonic-gate 		}
5750Sstevel@tonic-gate 		ddi_prop_free(drv_regp);
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate 		return (DDI_SUCCESS);
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate 	case DDI_CTLOPS_POWER: {
5800Sstevel@tonic-gate 		power_req_t	*reqp = (power_req_t *)arg;
5810Sstevel@tonic-gate 		/*
5820Sstevel@tonic-gate 		 * We currently understand reporting of PCI_PM_IDLESPEED
5830Sstevel@tonic-gate 		 * capability. Everything else is passed up.
5840Sstevel@tonic-gate 		 */
5850Sstevel@tonic-gate 		if ((reqp->request_type == PMR_REPORT_PMCAP) &&
5860Sstevel@tonic-gate 		    (reqp->req.report_pmcap_req.cap ==  PCI_PM_IDLESPEED)) {
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate 			return (DDI_SUCCESS);
5890Sstevel@tonic-gate 		}
5900Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
5910Sstevel@tonic-gate 	}
5920Sstevel@tonic-gate 
5931865Sdilpreet 	case DDI_CTLOPS_PEEK:
5941865Sdilpreet 	case DDI_CTLOPS_POKE:
5951865Sdilpreet 		pcip = ddi_get_soft_state(pci_statep, ddi_get_instance(dip));
5961865Sdilpreet 		return (pci_peekpoke_check(dip, rdip, ctlop, arg, result,
5971865Sdilpreet 		    pci_common_peekpoke, &pcip->pci_err_mutex,
598*6313Skrishnae 		    &pcip->pci_peek_poke_mutex, pci_peekpoke_cb));
5991865Sdilpreet 
6005295Srandyf 	/* for now only X86 systems support PME wakeup from suspended state */
6015295Srandyf 	case DDI_CTLOPS_ATTACH:
6025295Srandyf 		asp = (struct attachspec *)arg;
6035295Srandyf 		if (asp->cmd == DDI_RESUME && asp->when == DDI_PRE)
6045295Srandyf 			if (pci_pre_resume(rdip) != DDI_SUCCESS)
6055295Srandyf 				return (DDI_FAILURE);
6065295Srandyf 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
6075295Srandyf 
6085295Srandyf 	case DDI_CTLOPS_DETACH:
6095295Srandyf 		asp = (struct attachspec *)arg;
6105295Srandyf 		if (asp->cmd == DDI_SUSPEND && asp->when == DDI_POST)
6115295Srandyf 			if (pci_post_suspend(rdip) != DDI_SUCCESS)
6125295Srandyf 				return (DDI_FAILURE);
6135295Srandyf 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
6145295Srandyf 
6150Sstevel@tonic-gate 	default:
6160Sstevel@tonic-gate 		return (ddi_ctlops(dip, rdip, ctlop, arg, result));
6170Sstevel@tonic-gate 	}
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate 	/* NOTREACHED */
6200Sstevel@tonic-gate 
6210Sstevel@tonic-gate }
6220Sstevel@tonic-gate 
6230Sstevel@tonic-gate /*
624881Sjohnny  * pci_intr_ops
6250Sstevel@tonic-gate  */
6260Sstevel@tonic-gate static int
627881Sjohnny pci_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
628881Sjohnny     ddi_intr_handle_impl_t *hdlp, void *result)
6290Sstevel@tonic-gate {
630881Sjohnny 	return (pci_common_intr_ops(pdip, rdip, intr_op, hdlp, result));
631881Sjohnny }
6320Sstevel@tonic-gate 
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate static int
6350Sstevel@tonic-gate pci_initchild(dev_info_t *child)
6360Sstevel@tonic-gate {
6370Sstevel@tonic-gate 	char name[80];
638354Smyers 	ddi_acc_handle_t config_handle;
639354Smyers 	ushort_t command_preserve, command;
6400Sstevel@tonic-gate 
641881Sjohnny 	if (pci_common_name_child(child, name, 80) != DDI_SUCCESS) {
6420Sstevel@tonic-gate 		return (DDI_FAILURE);
6430Sstevel@tonic-gate 	}
6440Sstevel@tonic-gate 	ddi_set_name_addr(child, name);
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate 	/*
6470Sstevel@tonic-gate 	 * Pseudo nodes indicate a prototype node with per-instance
6480Sstevel@tonic-gate 	 * properties to be merged into the real h/w device node.
6490Sstevel@tonic-gate 	 * The interpretation of the unit-address is DD[,F]
6500Sstevel@tonic-gate 	 * where DD is the device id and F is the function.
6510Sstevel@tonic-gate 	 */
6520Sstevel@tonic-gate 	if (ndi_dev_is_persistent_node(child) == 0) {
6530Sstevel@tonic-gate 		extern int pci_allow_pseudo_children;
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 		ddi_set_parent_data(child, NULL);
6560Sstevel@tonic-gate 
6570Sstevel@tonic-gate 		/*
6580Sstevel@tonic-gate 		 * Try to merge the properties from this prototype
6590Sstevel@tonic-gate 		 * node into real h/w nodes.
6600Sstevel@tonic-gate 		 */
661881Sjohnny 		if (ndi_merge_node(child, pci_common_name_child) ==
662881Sjohnny 		    DDI_SUCCESS) {
6630Sstevel@tonic-gate 			/*
6640Sstevel@tonic-gate 			 * Merged ok - return failure to remove the node.
6650Sstevel@tonic-gate 			 */
6660Sstevel@tonic-gate 			ddi_set_name_addr(child, NULL);
6670Sstevel@tonic-gate 			return (DDI_FAILURE);
6680Sstevel@tonic-gate 		}
6690Sstevel@tonic-gate 
6700Sstevel@tonic-gate 		/* workaround for ddivs to run under PCI */
6710Sstevel@tonic-gate 		if (pci_allow_pseudo_children) {
6720Sstevel@tonic-gate 			/*
6730Sstevel@tonic-gate 			 * If the "interrupts" property doesn't exist,
6740Sstevel@tonic-gate 			 * this must be the ddivs no-intr case, and it returns
6750Sstevel@tonic-gate 			 * DDI_SUCCESS instead of DDI_FAILURE.
6760Sstevel@tonic-gate 			 */
6770Sstevel@tonic-gate 			if (ddi_prop_get_int(DDI_DEV_T_ANY, child,
6780Sstevel@tonic-gate 			    DDI_PROP_DONTPASS, "interrupts", -1) == -1)
6790Sstevel@tonic-gate 				return (DDI_SUCCESS);
6800Sstevel@tonic-gate 			/*
6810Sstevel@tonic-gate 			 * Create the ddi_parent_private_data for a pseudo
6820Sstevel@tonic-gate 			 * child.
6830Sstevel@tonic-gate 			 */
684881Sjohnny 			pci_common_set_parent_private_data(child);
6850Sstevel@tonic-gate 			return (DDI_SUCCESS);
6860Sstevel@tonic-gate 		}
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate 		/*
6890Sstevel@tonic-gate 		 * The child was not merged into a h/w node,
6900Sstevel@tonic-gate 		 * but there's not much we can do with it other
6910Sstevel@tonic-gate 		 * than return failure to cause the node to be removed.
6920Sstevel@tonic-gate 		 */
6930Sstevel@tonic-gate 		cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged",
6940Sstevel@tonic-gate 		    ddi_get_name(child), ddi_get_name_addr(child),
6950Sstevel@tonic-gate 		    ddi_get_name(child));
6960Sstevel@tonic-gate 		ddi_set_name_addr(child, NULL);
6970Sstevel@tonic-gate 		return (DDI_NOT_WELL_FORMED);
6980Sstevel@tonic-gate 	}
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate 	if (ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
701881Sjohnny 	    "interrupts", -1) != -1)
702881Sjohnny 		pci_common_set_parent_private_data(child);
703881Sjohnny 	else
7040Sstevel@tonic-gate 		ddi_set_parent_data(child, NULL);
7050Sstevel@tonic-gate 
706354Smyers 	/*
707354Smyers 	 * initialize command register
708354Smyers 	 */
709354Smyers 	if (pci_config_setup(child, &config_handle) != DDI_SUCCESS)
710354Smyers 		return (DDI_FAILURE);
711354Smyers 
712354Smyers 	/*
713354Smyers 	 * Support for the "command-preserve" property.
714354Smyers 	 */
715354Smyers 	command_preserve = ddi_prop_get_int(DDI_DEV_T_ANY, child,
7165295Srandyf 	    DDI_PROP_DONTPASS, "command-preserve", 0);
717354Smyers 	command = pci_config_get16(config_handle, PCI_CONF_COMM);
718354Smyers 	command &= (command_preserve | PCI_COMM_BACK2BACK_ENAB);
719354Smyers 	command |= (pci_command_default & ~command_preserve);
720354Smyers 	pci_config_put16(config_handle, PCI_CONF_COMM, command);
721354Smyers 
722354Smyers 	pci_config_teardown(&config_handle);
7230Sstevel@tonic-gate 	return (DDI_SUCCESS);
7240Sstevel@tonic-gate }
7250Sstevel@tonic-gate 
7260Sstevel@tonic-gate static int
7270Sstevel@tonic-gate pci_removechild(dev_info_t *dip)
7280Sstevel@tonic-gate {
7290Sstevel@tonic-gate 	struct ddi_parent_private_data *pdptr;
7300Sstevel@tonic-gate 
7310Sstevel@tonic-gate 	if ((pdptr = ddi_get_parent_data(dip)) != NULL) {
7320Sstevel@tonic-gate 		kmem_free(pdptr, (sizeof (*pdptr) + sizeof (struct intrspec)));
7330Sstevel@tonic-gate 		ddi_set_parent_data(dip, NULL);
7340Sstevel@tonic-gate 	}
7350Sstevel@tonic-gate 	ddi_set_name_addr(dip, NULL);
7360Sstevel@tonic-gate 
7370Sstevel@tonic-gate 	/*
7380Sstevel@tonic-gate 	 * Strip the node to properly convert it back to prototype form
7390Sstevel@tonic-gate 	 */
7400Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate 	impl_rem_dev_props(dip);
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate 	return (DDI_SUCCESS);
7450Sstevel@tonic-gate }
7460Sstevel@tonic-gate 
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate /*
7490Sstevel@tonic-gate  * When retrofitting this module for pci_tools, functions such as open, close,
7500Sstevel@tonic-gate  * and ioctl are now pulled into this module.  Before this, the functions in
7510Sstevel@tonic-gate  * the pcihp module were referenced directly.  Now they are called or
7520Sstevel@tonic-gate  * referenced through the pcihp cb_ops structure from functions in this module.
7530Sstevel@tonic-gate  */
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate static int
7560Sstevel@tonic-gate pci_open(dev_t *devp, int flags, int otyp, cred_t *credp)
7570Sstevel@tonic-gate {
758881Sjohnny 	return ((pcihp_get_cb_ops())->cb_open(devp, flags, otyp, credp));
7590Sstevel@tonic-gate }
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate static int
7620Sstevel@tonic-gate pci_close(dev_t dev, int flags, int otyp, cred_t *credp)
7630Sstevel@tonic-gate {
764881Sjohnny 	return ((pcihp_get_cb_ops())->cb_close(dev, flags, otyp, credp));
7650Sstevel@tonic-gate }
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate static int
768881Sjohnny pci_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp)
7690Sstevel@tonic-gate {
770777Sschwartz 	minor_t		minor = getminor(dev);
771777Sschwartz 	int		instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
772777Sschwartz 	pci_state_t	*pci_p = ddi_get_soft_state(pci_statep, instance);
7730Sstevel@tonic-gate 
774881Sjohnny 	if (pci_p == NULL)
775881Sjohnny 		return (ENXIO);
776117Sschwartz 
777881Sjohnny 	return (pci_common_ioctl(pci_p->pci_dip,
778881Sjohnny 	    dev, cmd, arg, mode, credp, rvalp));
779881Sjohnny }
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate 
7820Sstevel@tonic-gate static int
7830Sstevel@tonic-gate pci_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
784117Sschwartz 	int flags, char *name, caddr_t valuep, int *lengthp)
7850Sstevel@tonic-gate {
786881Sjohnny 	return ((pcihp_get_cb_ops())->cb_prop_op(dev, dip, prop_op, flags,
7870Sstevel@tonic-gate 	    name, valuep, lengthp));
7880Sstevel@tonic-gate }
7890Sstevel@tonic-gate 
7900Sstevel@tonic-gate static int
7910Sstevel@tonic-gate pci_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
7920Sstevel@tonic-gate {
7930Sstevel@tonic-gate 	return (pcihp_info(dip, cmd, arg, result));
7940Sstevel@tonic-gate }
7951865Sdilpreet 
796*6313Skrishnae void pci_peekpoke_cb(dev_info_t *dip, ddi_fm_error_t *derr) {
797*6313Skrishnae 	(void) pci_ereport_post(dip, derr, NULL);
798*6313Skrishnae }
799*6313Skrishnae 
8001865Sdilpreet /*ARGSUSED*/
8011865Sdilpreet static int
8021865Sdilpreet pci_fm_init(dev_info_t *dip, dev_info_t *tdip, int cap,
8031865Sdilpreet     ddi_iblock_cookie_t *ibc)
8041865Sdilpreet {
8051865Sdilpreet 	pci_state_t  *pcip = ddi_get_soft_state(pci_statep,
8061865Sdilpreet 	    ddi_get_instance(dip));
8071865Sdilpreet 
8081865Sdilpreet 	ASSERT(ibc != NULL);
8091865Sdilpreet 	*ibc = pcip->pci_fm_ibc;
8101865Sdilpreet 
8111865Sdilpreet 	return (pcip->pci_fmcap);
8121865Sdilpreet }
8131865Sdilpreet 
8141865Sdilpreet /*ARGSUSED*/
8151865Sdilpreet static int
8161865Sdilpreet pci_fm_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *no_used)
8171865Sdilpreet {
8181865Sdilpreet 	pci_state_t  *pcip = ddi_get_soft_state(pci_statep,
8191865Sdilpreet 	    ddi_get_instance(dip));
8201865Sdilpreet 
8211865Sdilpreet 	mutex_enter(&pcip->pci_err_mutex);
8221865Sdilpreet 	pci_ereport_post(dip, derr, NULL);
8231865Sdilpreet 	mutex_exit(&pcip->pci_err_mutex);
8241865Sdilpreet 	return (derr->fme_status);
8251865Sdilpreet }
826