xref: /onnv-gate/usr/src/uts/sun4u/io/pci/pci_intr.c (revision 10053:79ff8cfc9153)
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
51811Sesolom  * Common Development and Distribution License (the "License").
61811Sesolom  * 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 /*
228535Sevan.yan@sun.com  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * PCI nexus interrupt handling:
280Sstevel@tonic-gate  *	PCI device interrupt handler wrapper
290Sstevel@tonic-gate  *	pil lookup routine
300Sstevel@tonic-gate  *	PCI device interrupt related initchild code
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <sys/kmem.h>
350Sstevel@tonic-gate #include <sys/async.h>
360Sstevel@tonic-gate #include <sys/spl.h>
370Sstevel@tonic-gate #include <sys/sunddi.h>
380Sstevel@tonic-gate #include <sys/machsystm.h>	/* e_ddi_nodeid_to_dip() */
390Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
400Sstevel@tonic-gate #include <sys/pci/pci_obj.h>
410Sstevel@tonic-gate #include <sys/sdt.h>
4266Sesolom #include <sys/clock.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #ifdef _STARFIRE
450Sstevel@tonic-gate #include <sys/starfire.h>
460Sstevel@tonic-gate #endif /* _STARFIRE */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * interrupt jabber:
500Sstevel@tonic-gate  *
510Sstevel@tonic-gate  * When an interrupt line is jabbering, every time the state machine for the
520Sstevel@tonic-gate  * associated ino is idled, a new mondo will be sent and the ino will go into
530Sstevel@tonic-gate  * the pending state again. The mondo will cause a new call to
540Sstevel@tonic-gate  * pci_intr_wrapper() which normally idles the ino's state machine which would
550Sstevel@tonic-gate  * precipitate another trip round the loop.
560Sstevel@tonic-gate  * The loop can be broken by preventing the ino's state machine from being
570Sstevel@tonic-gate  * idled when an interrupt line is jabbering. See the comment at the
580Sstevel@tonic-gate  * beginning of pci_intr_wrapper() explaining how the 'interrupt jabber
590Sstevel@tonic-gate  * protection' code does this.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*LINTLIBRARY*/
630Sstevel@tonic-gate 
640Sstevel@tonic-gate #ifdef NOT_DEFINED
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * This array is used to determine the sparc PIL at the which the
670Sstevel@tonic-gate  * handler for a given INO will execute.  This table is for onboard
680Sstevel@tonic-gate  * devices only.  A different scheme will be used for plug-in cards.
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate 
710Sstevel@tonic-gate uint_t ino_to_pil[] = {
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	/* pil */		/* ino */
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	0, 0, 0, 0,  		/* 0x00 - 0x03: bus A slot 0 int#A, B, C, D */
760Sstevel@tonic-gate 	0, 0, 0, 0,		/* 0x04 - 0x07: bus A slot 1 int#A, B, C, D */
770Sstevel@tonic-gate 	0, 0, 0, 0,  		/* 0x08 - 0x0B: unused */
780Sstevel@tonic-gate 	0, 0, 0, 0,		/* 0x0C - 0x0F: unused */
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	0, 0, 0, 0,  		/* 0x10 - 0x13: bus B slot 0 int#A, B, C, D */
810Sstevel@tonic-gate 	0, 0, 0, 0,		/* 0x14 - 0x17: bus B slot 1 int#A, B, C, D */
820Sstevel@tonic-gate 	0, 0, 0, 0,  		/* 0x18 - 0x1B: bus B slot 2 int#A, B, C, D */
830Sstevel@tonic-gate 	4, 0, 0, 0,		/* 0x1C - 0x1F: bus B slot 3 int#A, B, C, D */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	4,			/* 0x20: SCSI */
860Sstevel@tonic-gate 	6,			/* 0x21: ethernet */
870Sstevel@tonic-gate 	3,			/* 0x22: parallel port */
880Sstevel@tonic-gate 	9,			/* 0x23: audio record */
890Sstevel@tonic-gate 	9,			/* 0x24: audio playback */
900Sstevel@tonic-gate 	14,			/* 0x25: power fail */
910Sstevel@tonic-gate 	4,			/* 0x26: 2nd SCSI */
920Sstevel@tonic-gate 	8,			/* 0x27: floppy */
930Sstevel@tonic-gate 	14,			/* 0x28: thermal warning */
940Sstevel@tonic-gate 	12,			/* 0x29: keyboard */
950Sstevel@tonic-gate 	12,			/* 0x2A: mouse */
960Sstevel@tonic-gate 	12,			/* 0x2B: serial */
970Sstevel@tonic-gate 	0,			/* 0x2C: timer/counter 0 */
980Sstevel@tonic-gate 	0,			/* 0x2D: timer/counter 1 */
990Sstevel@tonic-gate 	14,			/* 0x2E: uncorrectable ECC errors */
1000Sstevel@tonic-gate 	14,			/* 0x2F: correctable ECC errors */
1010Sstevel@tonic-gate 	14,			/* 0x30: PCI bus A error */
1020Sstevel@tonic-gate 	14,			/* 0x31: PCI bus B error */
1030Sstevel@tonic-gate 	14,			/* 0x32: power management wakeup */
1040Sstevel@tonic-gate 	14,			/* 0x33 */
1050Sstevel@tonic-gate 	14,			/* 0x34 */
1060Sstevel@tonic-gate 	14,			/* 0x35 */
1070Sstevel@tonic-gate 	14,			/* 0x36 */
1080Sstevel@tonic-gate 	14,			/* 0x37 */
1090Sstevel@tonic-gate 	14,			/* 0x38 */
1100Sstevel@tonic-gate 	14,			/* 0x39 */
1110Sstevel@tonic-gate 	14,			/* 0x3a */
1120Sstevel@tonic-gate 	14,			/* 0x3b */
1130Sstevel@tonic-gate 	14,			/* 0x3c */
1140Sstevel@tonic-gate 	14,			/* 0x3d */
1150Sstevel@tonic-gate 	14,			/* 0x3e */
1160Sstevel@tonic-gate 	14,			/* 0x3f */
1170Sstevel@tonic-gate 	14			/* 0x40 */
1180Sstevel@tonic-gate };
1190Sstevel@tonic-gate #endif /* NOT_DEFINED */
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate #define	PCI_SIMBA_VENID		0x108e	/* vendor id for simba */
1230Sstevel@tonic-gate #define	PCI_SIMBA_DEVID		0x5000	/* device id for simba */
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate /*
1260Sstevel@tonic-gate  * map_pcidev_cfg_reg - create mapping to pci device configuration registers
1270Sstevel@tonic-gate  *			if we have a simba AND a pci to pci bridge along the
1280Sstevel@tonic-gate  *			device path.
1290Sstevel@tonic-gate  *			Called with corresponding mutexes held!!
1300Sstevel@tonic-gate  *
1310Sstevel@tonic-gate  * XXX	  XXX	XXX	The purpose of this routine is to overcome a hardware
1320Sstevel@tonic-gate  *			defect in Sabre CPU and Simba bridge configuration
1330Sstevel@tonic-gate  *			which does not drain DMA write data stalled in
1340Sstevel@tonic-gate  *			PCI to PCI bridges (such as the DEC bridge) beyond
1350Sstevel@tonic-gate  *			Simba. This routine will setup the data structures
1360Sstevel@tonic-gate  *			to allow the pci_intr_wrapper to perform a manual
1370Sstevel@tonic-gate  *			drain data operation before passing the control to
1380Sstevel@tonic-gate  *			interrupt handlers of device drivers.
1390Sstevel@tonic-gate  * return value:
1400Sstevel@tonic-gate  * DDI_SUCCESS
1410Sstevel@tonic-gate  * DDI_FAILURE		if unable to create mapping
1420Sstevel@tonic-gate  */
1430Sstevel@tonic-gate static int
map_pcidev_cfg_reg(dev_info_t * dip,dev_info_t * rdip,ddi_acc_handle_t * hdl_p)1440Sstevel@tonic-gate map_pcidev_cfg_reg(dev_info_t *dip, dev_info_t *rdip, ddi_acc_handle_t *hdl_p)
1450Sstevel@tonic-gate {
1460Sstevel@tonic-gate 	dev_info_t *cdip;
1470Sstevel@tonic-gate 	dev_info_t *pci_dip = NULL;
1480Sstevel@tonic-gate 	pci_t *pci_p = get_pci_soft_state(ddi_get_instance(dip));
1490Sstevel@tonic-gate 	int simba_found = 0, pci_bridge_found = 0;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	for (cdip = rdip; cdip && cdip != dip; cdip = ddi_get_parent(cdip)) {
1520Sstevel@tonic-gate 		ddi_acc_handle_t config_handle;
1530Sstevel@tonic-gate 		uint32_t vendor_id = ddi_getprop(DDI_DEV_T_ANY, cdip,
1546790Sgd78059 		    DDI_PROP_DONTPASS, "vendor-id", 0xffff);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 		DEBUG4(DBG_A_INTX, pci_p->pci_dip,
1576790Sgd78059 		    "map dev cfg reg for %s%d: @%s%d\n",
1586790Sgd78059 		    ddi_driver_name(rdip), ddi_get_instance(rdip),
1596790Sgd78059 		    ddi_driver_name(cdip), ddi_get_instance(cdip));
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 		if (ddi_prop_exists(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS,
1626790Sgd78059 		    "no-dma-interrupt-sync"))
1630Sstevel@tonic-gate 			continue;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 		/* continue to search up-stream if not a PCI device */
1660Sstevel@tonic-gate 		if (vendor_id == 0xffff)
1670Sstevel@tonic-gate 			continue;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 		/* record the deepest pci device */
1700Sstevel@tonic-gate 		if (!pci_dip)
1710Sstevel@tonic-gate 			pci_dip = cdip;
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 		/* look for simba */
1740Sstevel@tonic-gate 		if (vendor_id == PCI_SIMBA_VENID) {
1750Sstevel@tonic-gate 			uint32_t device_id = ddi_getprop(DDI_DEV_T_ANY,
1760Sstevel@tonic-gate 			    cdip, DDI_PROP_DONTPASS, "device-id", -1);
1770Sstevel@tonic-gate 			if (device_id == PCI_SIMBA_DEVID) {
1780Sstevel@tonic-gate 				simba_found = 1;
1790Sstevel@tonic-gate 				DEBUG0(DBG_A_INTX, pci_p->pci_dip,
1806790Sgd78059 				    "\tFound simba\n");
1810Sstevel@tonic-gate 				continue; /* do not check bridge if simba */
1820Sstevel@tonic-gate 			}
1830Sstevel@tonic-gate 		}
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 		/* look for pci to pci bridge */
1860Sstevel@tonic-gate 		if (pci_config_setup(cdip, &config_handle) != DDI_SUCCESS) {
1870Sstevel@tonic-gate 			cmn_err(CE_WARN,
1880Sstevel@tonic-gate 			    "%s%d: can't get brdg cfg space for %s%d\n",
1896790Sgd78059 			    ddi_driver_name(dip), ddi_get_instance(dip),
1906790Sgd78059 			    ddi_driver_name(cdip), ddi_get_instance(cdip));
1910Sstevel@tonic-gate 			return (DDI_FAILURE);
1920Sstevel@tonic-gate 		}
1930Sstevel@tonic-gate 		if (pci_config_get8(config_handle, PCI_CONF_BASCLASS)
1940Sstevel@tonic-gate 		    == PCI_CLASS_BRIDGE) {
1950Sstevel@tonic-gate 			DEBUG0(DBG_A_INTX, pci_p->pci_dip,
1966790Sgd78059 			    "\tFound PCI to xBus bridge\n");
1970Sstevel@tonic-gate 			pci_bridge_found = 1;
1980Sstevel@tonic-gate 		}
1990Sstevel@tonic-gate 		pci_config_teardown(&config_handle);
2000Sstevel@tonic-gate 	}
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	if (!pci_bridge_found)
2030Sstevel@tonic-gate 		return (DDI_SUCCESS);
2040Sstevel@tonic-gate 	if (!simba_found && (CHIP_TYPE(pci_p) < PCI_CHIP_SCHIZO))
2050Sstevel@tonic-gate 		return (DDI_SUCCESS);
2060Sstevel@tonic-gate 	if (pci_config_setup(pci_dip, hdl_p) != DDI_SUCCESS) {
2070Sstevel@tonic-gate 		cmn_err(CE_WARN, "%s%d: can not get config space for %s%d\n",
2086790Sgd78059 		    ddi_driver_name(dip), ddi_get_instance(dip),
2096790Sgd78059 		    ddi_driver_name(cdip), ddi_get_instance(cdip));
2100Sstevel@tonic-gate 		return (DDI_FAILURE);
2110Sstevel@tonic-gate 	}
2120Sstevel@tonic-gate 	return (DDI_SUCCESS);
2130Sstevel@tonic-gate }
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate /*
2160Sstevel@tonic-gate  * If the unclaimed interrupt count has reached the limit set by
2170Sstevel@tonic-gate  * pci_unclaimed_intr_max within the time limit, then all interrupts
2180Sstevel@tonic-gate  * on this ino is blocked by not idling the interrupt state machine.
2190Sstevel@tonic-gate  */
2200Sstevel@tonic-gate static int
pci_spurintr(ib_ino_pil_t * ipil_p)2212973Sgovinda pci_spurintr(ib_ino_pil_t *ipil_p) {
2222973Sgovinda 	ib_ino_info_t	*ino_p = ipil_p->ipil_ino_p;
2232973Sgovinda 	ih_t		*ih_p = ipil_p->ipil_ih_start;
2242973Sgovinda 	pci_t		*pci_p = ino_p->ino_ib_p->ib_pci_p;
2252973Sgovinda 	char		*err_fmt_str;
2262973Sgovinda 	boolean_t	blocked = B_FALSE;
2272973Sgovinda 	int		i;
2280Sstevel@tonic-gate 
2292973Sgovinda 	if (ino_p->ino_unclaimed_intrs > pci_unclaimed_intr_max)
2300Sstevel@tonic-gate 		return (DDI_INTR_CLAIMED);
2310Sstevel@tonic-gate 
2322973Sgovinda 	if (!ino_p->ino_unclaimed_intrs)
2330Sstevel@tonic-gate 		ino_p->ino_spurintr_begin = ddi_get_lbolt();
2340Sstevel@tonic-gate 
2352973Sgovinda 	ino_p->ino_unclaimed_intrs++;
2360Sstevel@tonic-gate 
2372973Sgovinda 	if (ino_p->ino_unclaimed_intrs <= pci_unclaimed_intr_max)
2380Sstevel@tonic-gate 		goto clear;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	if (drv_hztousec(ddi_get_lbolt() - ino_p->ino_spurintr_begin)
2410Sstevel@tonic-gate 	    > pci_spurintr_duration) {
2422973Sgovinda 		ino_p->ino_unclaimed_intrs = 0;
2430Sstevel@tonic-gate 		goto clear;
2440Sstevel@tonic-gate 	}
2450Sstevel@tonic-gate 	err_fmt_str = "%s%d: ino 0x%x blocked";
2462234Sdanice 	blocked = B_TRUE;
2470Sstevel@tonic-gate 	goto warn;
2480Sstevel@tonic-gate clear:
2492234Sdanice 	if (!pci_spurintr_msgs) { /* tomatillo errata #71 spurious mondo */
2502234Sdanice 		/* clear the pending state */
2512234Sdanice 		IB_INO_INTR_CLEAR(ino_p->ino_clr_reg);
2520Sstevel@tonic-gate 		return (DDI_INTR_CLAIMED);
2532234Sdanice 	}
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	err_fmt_str = "!%s%d: spurious interrupt from ino 0x%x";
2560Sstevel@tonic-gate warn:
2570Sstevel@tonic-gate 	cmn_err(CE_WARN, err_fmt_str, NAMEINST(pci_p->pci_dip), ino_p->ino_ino);
2582973Sgovinda 	for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next)
2590Sstevel@tonic-gate 		cmn_err(CE_CONT, "!%s-%d#%x ", NAMEINST(ih_p->ih_dip),
2600Sstevel@tonic-gate 		    ih_p->ih_inum);
2610Sstevel@tonic-gate 	cmn_err(CE_CONT, "!\n");
2622234Sdanice 	if (blocked == B_FALSE)  /* clear the pending state */
2632234Sdanice 		IB_INO_INTR_CLEAR(ino_p->ino_clr_reg);
2642234Sdanice 
2650Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate /*
2690Sstevel@tonic-gate  * pci_intr_wrapper
2700Sstevel@tonic-gate  *
2710Sstevel@tonic-gate  * This routine is used as wrapper around interrupt handlers installed by child
2720Sstevel@tonic-gate  * device drivers.  This routine invokes the driver interrupt handlers and
2730Sstevel@tonic-gate  * examines the return codes.
2740Sstevel@tonic-gate  * There is a count of unclaimed interrupts kept on a per-ino basis. If at
2750Sstevel@tonic-gate  * least one handler claims the interrupt then the counter is halved and the
2760Sstevel@tonic-gate  * interrupt state machine is idled. If no handler claims the interrupt then
2770Sstevel@tonic-gate  * the counter is incremented by one and the state machine is idled.
2780Sstevel@tonic-gate  * If the count ever reaches the limit value set by pci_unclaimed_intr_max
2790Sstevel@tonic-gate  * then the interrupt state machine is not idled thus preventing any further
2800Sstevel@tonic-gate  * interrupts on that ino. The state machine will only be idled again if a
2810Sstevel@tonic-gate  * handler is subsequently added or removed.
2820Sstevel@tonic-gate  *
2830Sstevel@tonic-gate  * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt,
2840Sstevel@tonic-gate  * DDI_INTR_UNCLAIMED otherwise.
2850Sstevel@tonic-gate  */
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate extern uint64_t intr_get_time(void);
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate uint_t
pci_intr_wrapper(caddr_t arg)2900Sstevel@tonic-gate pci_intr_wrapper(caddr_t arg)
2910Sstevel@tonic-gate {
2922973Sgovinda 	ib_ino_pil_t	*ipil_p = (ib_ino_pil_t *)arg;
2932973Sgovinda 	ib_ino_info_t	*ino_p = ipil_p->ipil_ino_p;
2942973Sgovinda 	uint_t		result = 0, r = DDI_INTR_UNCLAIMED;
2952973Sgovinda 	pci_t		*pci_p = ino_p->ino_ib_p->ib_pci_p;
2962973Sgovinda 	pbm_t		*pbm_p = pci_p->pci_pbm_p;
2972973Sgovinda 	ih_t		*ih_p = ipil_p->ipil_ih_start;
2982973Sgovinda 	int		i;
2990Sstevel@tonic-gate 
3002973Sgovinda 	for (i = 0; i < ipil_p->ipil_ih_size; i++, ih_p = ih_p->ih_next) {
3010Sstevel@tonic-gate 		dev_info_t *dip = ih_p->ih_dip;
3020Sstevel@tonic-gate 		uint_t (*handler)() = ih_p->ih_handler;
3030Sstevel@tonic-gate 		caddr_t arg1 = ih_p->ih_handler_arg1;
3040Sstevel@tonic-gate 		caddr_t arg2 = ih_p->ih_handler_arg2;
3050Sstevel@tonic-gate 		ddi_acc_handle_t cfg_hdl = ih_p->ih_config_handle;
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 		if (pci_intr_dma_sync && cfg_hdl && pbm_p->pbm_sync_reg_pa) {
3080Sstevel@tonic-gate 			(void) pci_config_get16(cfg_hdl, PCI_CONF_VENID);
3090Sstevel@tonic-gate 			pci_pbm_dma_sync(pbm_p, ino_p->ino_ino);
3100Sstevel@tonic-gate 		}
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 		if (ih_p->ih_intr_state == PCI_INTR_STATE_DISABLE) {
3130Sstevel@tonic-gate 			DEBUG3(DBG_INTR, pci_p->pci_dip,
3140Sstevel@tonic-gate 			    "pci_intr_wrapper: %s%d interrupt %d is disabled\n",
3150Sstevel@tonic-gate 			    ddi_driver_name(dip), ddi_get_instance(dip),
3160Sstevel@tonic-gate 			    ino_p->ino_ino);
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 			continue;
3190Sstevel@tonic-gate 		}
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 		DTRACE_PROBE4(interrupt__start, dev_info_t, dip,
3220Sstevel@tonic-gate 		    void *, handler, caddr_t, arg1, caddr_t, arg2);
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 		r = (*handler)(arg1, arg2);
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 		/*
3270Sstevel@tonic-gate 		 * Account for time used by this interrupt. Protect against
3280Sstevel@tonic-gate 		 * conflicting writes to ih_ticks from ib_intr_dist_all() by
3290Sstevel@tonic-gate 		 * using atomic ops.
3300Sstevel@tonic-gate 		 */
3310Sstevel@tonic-gate 
3322973Sgovinda 		if (ipil_p->ipil_pil <= LOCK_LEVEL)
3330Sstevel@tonic-gate 			atomic_add_64(&ih_p->ih_ticks, intr_get_time());
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 		DTRACE_PROBE4(interrupt__complete, dev_info_t, dip,
3360Sstevel@tonic-gate 		    void *, handler, caddr_t, arg1, int, r);
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 		result += r;
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 		if (pci_check_all_handlers)
3410Sstevel@tonic-gate 			continue;
3420Sstevel@tonic-gate 		if (result)
3430Sstevel@tonic-gate 			break;
3440Sstevel@tonic-gate 	}
3450Sstevel@tonic-gate 
3462973Sgovinda 	if (result)
3472973Sgovinda 		ino_p->ino_claimed |= (1 << ipil_p->ipil_pil);
3482973Sgovinda 
3492973Sgovinda 	/* Interrupt can only be cleared after all pil levels are handled */
3502973Sgovinda 	if (ipil_p->ipil_pil != ino_p->ino_lopil)
3512973Sgovinda 		return (DDI_INTR_CLAIMED);
3520Sstevel@tonic-gate 
3532973Sgovinda 	if (!ino_p->ino_claimed)
3542973Sgovinda 		return (pci_spurintr(ipil_p));
3552973Sgovinda 
3562973Sgovinda 	ino_p->ino_unclaimed_intrs = 0;
3572973Sgovinda 	ino_p->ino_claimed = 0;
3582973Sgovinda 
3592973Sgovinda 	/* Clear the pending state */
3602973Sgovinda 	IB_INO_INTR_CLEAR(ino_p->ino_clr_reg);
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
3630Sstevel@tonic-gate }
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate dev_info_t *
get_my_childs_dip(dev_info_t * dip,dev_info_t * rdip)3660Sstevel@tonic-gate get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip)
3670Sstevel@tonic-gate {
3680Sstevel@tonic-gate 	dev_info_t *cdip = rdip;
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip))
3710Sstevel@tonic-gate 		;
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	return (cdip);
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate 
37666Sesolom static struct {
37766Sesolom 	kstat_named_t pciintr_ks_name;
37866Sesolom 	kstat_named_t pciintr_ks_type;
37966Sesolom 	kstat_named_t pciintr_ks_cpu;
38066Sesolom 	kstat_named_t pciintr_ks_pil;
38166Sesolom 	kstat_named_t pciintr_ks_time;
38266Sesolom 	kstat_named_t pciintr_ks_ino;
38366Sesolom 	kstat_named_t pciintr_ks_cookie;
38466Sesolom 	kstat_named_t pciintr_ks_devpath;
38566Sesolom 	kstat_named_t pciintr_ks_buspath;
38666Sesolom } pciintr_ks_template = {
38766Sesolom 	{ "name",	KSTAT_DATA_CHAR },
38866Sesolom 	{ "type",	KSTAT_DATA_CHAR },
38966Sesolom 	{ "cpu",	KSTAT_DATA_UINT64 },
39066Sesolom 	{ "pil",	KSTAT_DATA_UINT64 },
39166Sesolom 	{ "time",	KSTAT_DATA_UINT64 },
39266Sesolom 	{ "ino",	KSTAT_DATA_UINT64 },
39366Sesolom 	{ "cookie",	KSTAT_DATA_UINT64 },
39466Sesolom 	{ "devpath",	KSTAT_DATA_STRING },
39566Sesolom 	{ "buspath",	KSTAT_DATA_STRING },
39666Sesolom };
39766Sesolom static uint32_t pciintr_ks_instance;
3981811Sesolom static char ih_devpath[MAXPATHLEN];
3991811Sesolom static char ih_buspath[MAXPATHLEN];
40066Sesolom 
40166Sesolom kmutex_t pciintr_ks_template_lock;
40266Sesolom 
40366Sesolom int
pci_ks_update(kstat_t * ksp,int rw)40466Sesolom pci_ks_update(kstat_t *ksp, int rw)
40566Sesolom {
4062973Sgovinda 	ih_t		*ih_p = ksp->ks_private;
4072973Sgovinda 	int	maxlen = sizeof (pciintr_ks_template.pciintr_ks_name.value.c);
4082973Sgovinda 	ib_ino_pil_t	*ipil_p = ih_p->ih_ipil_p;
4092973Sgovinda 	ib_ino_info_t	*ino_p = ipil_p->ipil_ino_p;
4102973Sgovinda 	ib_t		*ib_p = ino_p->ino_ib_p;
4112973Sgovinda 	pci_t		*pci_p = ib_p->ib_pci_p;
4122973Sgovinda 	ib_ino_t	ino;
41366Sesolom 
4142973Sgovinda 	ino = ino_p->ino_ino;
41566Sesolom 
41666Sesolom 	(void) snprintf(pciintr_ks_template.pciintr_ks_name.value.c, maxlen,
41766Sesolom 	    "%s%d", ddi_driver_name(ih_p->ih_dip),
41866Sesolom 	    ddi_get_instance(ih_p->ih_dip));
41966Sesolom 
42066Sesolom 	(void) ddi_pathname(ih_p->ih_dip, ih_devpath);
42166Sesolom 	(void) ddi_pathname(pci_p->pci_dip, ih_buspath);
42266Sesolom 	kstat_named_setstr(&pciintr_ks_template.pciintr_ks_devpath, ih_devpath);
42366Sesolom 	kstat_named_setstr(&pciintr_ks_template.pciintr_ks_buspath, ih_buspath);
42466Sesolom 
4251087Sschwartz 	if (ih_p->ih_intr_state == PCI_INTR_STATE_ENABLE) {
4261087Sschwartz 		(void) strcpy(pciintr_ks_template.pciintr_ks_type.value.c,
4271087Sschwartz 		    "fixed");
4281087Sschwartz 		pciintr_ks_template.pciintr_ks_cpu.value.ui64 =
4292973Sgovinda 		    ino_p->ino_cpuid;
4301087Sschwartz 		pciintr_ks_template.pciintr_ks_pil.value.ui64 =
4312973Sgovinda 		    ipil_p->ipil_pil;
4321087Sschwartz 		pciintr_ks_template.pciintr_ks_time.value.ui64 = ih_p->ih_nsec +
4331087Sschwartz 		    (uint64_t)tick2ns((hrtime_t)ih_p->ih_ticks,
4342973Sgovinda 		    ino_p->ino_cpuid);
4351087Sschwartz 		pciintr_ks_template.pciintr_ks_ino.value.ui64 = ino;
4361087Sschwartz 		pciintr_ks_template.pciintr_ks_cookie.value.ui64 =
4376790Sgd78059 		    IB_INO_TO_MONDO(ib_p, ino);
4381087Sschwartz 	} else {
4391087Sschwartz 		(void) strcpy(pciintr_ks_template.pciintr_ks_type.value.c,
4401087Sschwartz 		    "disabled");
4411087Sschwartz 		pciintr_ks_template.pciintr_ks_cpu.value.ui64 = 0;
4421087Sschwartz 		pciintr_ks_template.pciintr_ks_pil.value.ui64 = 0;
4431087Sschwartz 		pciintr_ks_template.pciintr_ks_time.value.ui64 = 0;
4441087Sschwartz 		pciintr_ks_template.pciintr_ks_ino.value.ui64 = 0;
4451087Sschwartz 		pciintr_ks_template.pciintr_ks_cookie.value.ui64 = 0;
4461087Sschwartz 	}
4471087Sschwartz 
44866Sesolom 	return (0);
44966Sesolom }
45066Sesolom 
4510Sstevel@tonic-gate int
pci_add_intr(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)4520Sstevel@tonic-gate pci_add_intr(dev_info_t *dip, dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
4530Sstevel@tonic-gate {
4542973Sgovinda 	pci_t		*pci_p = get_pci_soft_state(ddi_get_instance(dip));
4552973Sgovinda 	ib_t		*ib_p = pci_p->pci_ib_p;
4562973Sgovinda 	cb_t		*cb_p = pci_p->pci_cb_p;
4572973Sgovinda 	ih_t		*ih_p;
4582973Sgovinda 	ib_ino_t	ino;
4592973Sgovinda 	ib_ino_info_t	*ino_p;	/* pulse interrupts have no ino */
4602973Sgovinda 	ib_ino_pil_t	*ipil_p, *ipil_list;
4612973Sgovinda 	ib_mondo_t	mondo;
4622973Sgovinda 	uint32_t	cpu_id;
4632973Sgovinda 	int		ret;
4642973Sgovinda 	int32_t		weight;
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	ino = IB_MONDO_TO_INO(hdlp->ih_vector);
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	DEBUG3(DBG_A_INTX, dip, "pci_add_intr: rdip=%s%d ino=%x\n",
4690Sstevel@tonic-gate 	    ddi_driver_name(rdip), ddi_get_instance(rdip), ino);
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 	if (ino > ib_p->ib_max_ino) {
4720Sstevel@tonic-gate 		DEBUG1(DBG_A_INTX, dip, "ino %x is invalid\n", ino);
4730Sstevel@tonic-gate 		return (DDI_INTR_NOTFOUND);
4740Sstevel@tonic-gate 	}
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate 	if (hdlp->ih_vector & PCI_PULSE_INO) {
4770Sstevel@tonic-gate 		volatile uint64_t *map_reg_addr;
4780Sstevel@tonic-gate 		map_reg_addr = ib_intr_map_reg_addr(ib_p, ino);
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate 		mondo = pci_xlate_intr(dip, rdip, ib_p, ino);
4810Sstevel@tonic-gate 		if (mondo == 0)
4820Sstevel@tonic-gate 			goto fail1;
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 		hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo);
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 		if (i_ddi_add_ivintr(hdlp) != DDI_SUCCESS)
4870Sstevel@tonic-gate 			goto fail1;
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 		/*
4900Sstevel@tonic-gate 		 * Select cpu and program.
4910Sstevel@tonic-gate 		 *
4920Sstevel@tonic-gate 		 * Since there is no good way to always derive cpuid in
4930Sstevel@tonic-gate 		 * pci_remove_intr for PCI_PULSE_INO (esp. for STARFIRE), we
4940Sstevel@tonic-gate 		 * don't add (or remove) device weight for pulsed interrupt
4950Sstevel@tonic-gate 		 * sources.
4960Sstevel@tonic-gate 		 */
4970Sstevel@tonic-gate 		mutex_enter(&ib_p->ib_intr_lock);
4980Sstevel@tonic-gate 		cpu_id = intr_dist_cpuid();
4990Sstevel@tonic-gate 		*map_reg_addr = ib_get_map_reg(mondo, cpu_id);
5000Sstevel@tonic-gate 		mutex_exit(&ib_p->ib_intr_lock);
5010Sstevel@tonic-gate 		*map_reg_addr;	/* flush previous write */
5020Sstevel@tonic-gate 		goto done;
5030Sstevel@tonic-gate 	}
5040Sstevel@tonic-gate 
5050Sstevel@tonic-gate 	if ((mondo = pci_xlate_intr(dip, rdip, pci_p->pci_ib_p, ino)) == 0)
5060Sstevel@tonic-gate 		goto fail1;
5070Sstevel@tonic-gate 
5080Sstevel@tonic-gate 	ino = IB_MONDO_TO_INO(mondo);
5090Sstevel@tonic-gate 
5100Sstevel@tonic-gate 	mutex_enter(&ib_p->ib_ino_lst_mutex);
5110Sstevel@tonic-gate 	ih_p = ib_alloc_ih(rdip, hdlp->ih_inum,
5120Sstevel@tonic-gate 	    hdlp->ih_cb_func, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2);
5130Sstevel@tonic-gate 	if (map_pcidev_cfg_reg(dip, rdip, &ih_p->ih_config_handle))
5140Sstevel@tonic-gate 		goto fail2;
5150Sstevel@tonic-gate 
5162973Sgovinda 	ino_p = ib_locate_ino(ib_p, ino);
5172973Sgovinda 	ipil_list = ino_p ? ino_p->ino_ipil_p:NULL;
5182973Sgovinda 
5192973Sgovinda 	/* Sharing ino */
5202973Sgovinda 	if (ino_p && (ipil_p = ib_ino_locate_ipil(ino_p, hdlp->ih_pri))) {
5212973Sgovinda 		if (ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum)) {
5222973Sgovinda 			DEBUG1(DBG_A_INTX, dip, "dup intr #%d\n",
5232973Sgovinda 			    hdlp->ih_inum);
5240Sstevel@tonic-gate 			goto fail3;
5250Sstevel@tonic-gate 		}
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 		/* add weight to the cpu that we are already targeting */
5280Sstevel@tonic-gate 		cpu_id = ino_p->ino_cpuid;
5290Sstevel@tonic-gate 		weight = pci_class_to_intr_weight(rdip);
5300Sstevel@tonic-gate 		intr_dist_cpuid_add_device_weight(cpu_id, rdip, weight);
5310Sstevel@tonic-gate 
5322973Sgovinda 		ib_ino_add_intr(pci_p, ipil_p, ih_p);
5330Sstevel@tonic-gate 		goto ino_done;
5340Sstevel@tonic-gate 	}
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 	if (hdlp->ih_pri == 0)
5370Sstevel@tonic-gate 		hdlp->ih_pri = pci_class_to_pil(rdip);
5380Sstevel@tonic-gate 
5392973Sgovinda 	ipil_p = ib_new_ino_pil(ib_p, ino, hdlp->ih_pri, ih_p);
5402973Sgovinda 	ino_p = ipil_p->ipil_ino_p;
5412973Sgovinda 
5420Sstevel@tonic-gate 	hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo);
5430Sstevel@tonic-gate 
544909Segillett 	/* Store this global mondo */
545909Segillett 	ino_p->ino_mondo = hdlp->ih_vector;
546909Segillett 
5470Sstevel@tonic-gate 	DEBUG2(DBG_A_INTX, dip, "pci_add_intr:  pil=0x%x mondo=0x%x\n",
5480Sstevel@tonic-gate 	    hdlp->ih_pri, hdlp->ih_vector);
5490Sstevel@tonic-gate 
5500Sstevel@tonic-gate 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp,
5512973Sgovinda 	    (ddi_intr_handler_t *)pci_intr_wrapper, (caddr_t)ipil_p, NULL);
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate 	ret = i_ddi_add_ivintr(hdlp);
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate 	/*
5560Sstevel@tonic-gate 	 * Restore original interrupt handler
5570Sstevel@tonic-gate 	 * and arguments in interrupt handle.
5580Sstevel@tonic-gate 	 */
5590Sstevel@tonic-gate 	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, ih_p->ih_handler,
5600Sstevel@tonic-gate 	    ih_p->ih_handler_arg1, ih_p->ih_handler_arg2);
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 	if (ret != DDI_SUCCESS)
5630Sstevel@tonic-gate 		goto fail4;
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate 	/* Save the pil for this ino */
5662973Sgovinda 	ipil_p->ipil_pil = hdlp->ih_pri;
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 	/* clear and enable interrupt */
5690Sstevel@tonic-gate 	IB_INO_INTR_CLEAR(ino_p->ino_clr_reg);
5700Sstevel@tonic-gate 
5712973Sgovinda 	/*
5722973Sgovinda 	 * Select cpu and compute weight, saving both for sharing and removal.
5732973Sgovinda 	 */
5742973Sgovinda 	if (ipil_list == NULL)
5752973Sgovinda 		ino_p->ino_cpuid = pci_intr_dist_cpuid(ib_p, ino_p);
5762973Sgovinda 
5772973Sgovinda 	cpu_id = ino_p->ino_cpuid;
5780Sstevel@tonic-gate 	ino_p->ino_established = 1;
5790Sstevel@tonic-gate 	weight = pci_class_to_intr_weight(rdip);
5800Sstevel@tonic-gate 	intr_dist_cpuid_add_device_weight(cpu_id, rdip, weight);
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate #ifdef _STARFIRE
5830Sstevel@tonic-gate 	cpu_id = pc_translate_tgtid(cb_p->cb_ittrans_cookie, cpu_id,
5846790Sgd78059 	    IB_GET_MAPREG_INO(ino));
5850Sstevel@tonic-gate #endif /* _STARFIRE */
5862973Sgovinda 	if (!ipil_list) {
5872973Sgovinda 		*ino_p->ino_map_reg = ib_get_map_reg(mondo, cpu_id);
5882973Sgovinda 		*ino_p->ino_map_reg;
5892973Sgovinda 	}
5900Sstevel@tonic-gate ino_done:
591*10053SEvan.Yan@Sun.COM 	hdlp->ih_target = ino_p->ino_cpuid;
5922973Sgovinda 	ih_p->ih_ipil_p = ipil_p;
59366Sesolom 	ih_p->ih_ksp = kstat_create("pci_intrs",
59466Sesolom 	    atomic_inc_32_nv(&pciintr_ks_instance), "config", "interrupts",
59566Sesolom 	    KSTAT_TYPE_NAMED,
59666Sesolom 	    sizeof (pciintr_ks_template) / sizeof (kstat_named_t),
59766Sesolom 	    KSTAT_FLAG_VIRTUAL);
59866Sesolom 	if (ih_p->ih_ksp != NULL) {
59966Sesolom 		ih_p->ih_ksp->ks_data_size += MAXPATHLEN * 2;
60066Sesolom 		ih_p->ih_ksp->ks_lock = &pciintr_ks_template_lock;
60166Sesolom 		ih_p->ih_ksp->ks_data = &pciintr_ks_template;
60266Sesolom 		ih_p->ih_ksp->ks_private = ih_p;
60366Sesolom 		ih_p->ih_ksp->ks_update = pci_ks_update;
6040Sstevel@tonic-gate 		kstat_install(ih_p->ih_ksp);
60566Sesolom 	}
6060Sstevel@tonic-gate 	ib_ino_map_reg_share(ib_p, ino, ino_p);
6070Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
6080Sstevel@tonic-gate done:
6090Sstevel@tonic-gate 	DEBUG2(DBG_A_INTX, dip, "done! Interrupt 0x%x pil=%x\n",
6106790Sgd78059 	    hdlp->ih_vector, hdlp->ih_pri);
6110Sstevel@tonic-gate 	return (DDI_SUCCESS);
6120Sstevel@tonic-gate fail4:
6132973Sgovinda 	ib_delete_ino_pil(ib_p, ipil_p);
6140Sstevel@tonic-gate fail3:
6150Sstevel@tonic-gate 	if (ih_p->ih_config_handle)
6160Sstevel@tonic-gate 		pci_config_teardown(&ih_p->ih_config_handle);
6170Sstevel@tonic-gate fail2:
6180Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
6190Sstevel@tonic-gate 	kmem_free(ih_p, sizeof (ih_t));
6200Sstevel@tonic-gate fail1:
6210Sstevel@tonic-gate 	DEBUG2(DBG_A_INTX, dip, "Failed! Interrupt 0x%x pil=%x\n",
6226790Sgd78059 	    hdlp->ih_vector, hdlp->ih_pri);
6230Sstevel@tonic-gate 	return (DDI_FAILURE);
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate int
pci_remove_intr(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)6270Sstevel@tonic-gate pci_remove_intr(dev_info_t *dip, dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp)
6280Sstevel@tonic-gate {
6292973Sgovinda 	pci_t		*pci_p = get_pci_soft_state(ddi_get_instance(dip));
6302973Sgovinda 	ib_t		*ib_p = pci_p->pci_ib_p;
6312973Sgovinda 	cb_t		*cb_p = pci_p->pci_cb_p;
6322973Sgovinda 	ib_ino_t	ino;
6332973Sgovinda 	ib_mondo_t	mondo;
6342973Sgovinda 	ib_ino_info_t	*ino_p;	/* non-pulse only */
6352973Sgovinda 	ib_ino_pil_t	*ipil_p; /* non-pulse only */
6362973Sgovinda 	ih_t		*ih_p;	/* non-pulse only */
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate 	ino = IB_MONDO_TO_INO(hdlp->ih_vector);
6390Sstevel@tonic-gate 
6400Sstevel@tonic-gate 	DEBUG3(DBG_R_INTX, dip, "pci_rem_intr: rdip=%s%d ino=%x\n",
6410Sstevel@tonic-gate 	    ddi_driver_name(rdip), ddi_get_instance(rdip), ino);
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	if (hdlp->ih_vector & PCI_PULSE_INO) { /* pulse interrupt */
6440Sstevel@tonic-gate 		volatile uint64_t *map_reg_addr;
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate 		/*
6470Sstevel@tonic-gate 		 * No weight was added by pci_add_intr for PCI_PULSE_INO
6480Sstevel@tonic-gate 		 * because it is difficult to determine cpuid here.
6490Sstevel@tonic-gate 		 */
6500Sstevel@tonic-gate 		map_reg_addr = ib_intr_map_reg_addr(ib_p, ino);
6510Sstevel@tonic-gate 		IB_INO_INTR_RESET(map_reg_addr);	/* disable intr */
6520Sstevel@tonic-gate 		*map_reg_addr;
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate 		mondo = pci_xlate_intr(dip, rdip, ib_p, ino);
6550Sstevel@tonic-gate 		if (mondo == 0) {
6560Sstevel@tonic-gate 			DEBUG1(DBG_R_INTX, dip,
6576790Sgd78059 			    "can't get mondo for ino %x\n", ino);
6580Sstevel@tonic-gate 			return (DDI_FAILURE);
6590Sstevel@tonic-gate 		}
6600Sstevel@tonic-gate 
6610Sstevel@tonic-gate 		if (hdlp->ih_pri == 0)
6620Sstevel@tonic-gate 			hdlp->ih_pri = pci_class_to_pil(rdip);
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate 		hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo);
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 		DEBUG2(DBG_R_INTX, dip, "pci_rem_intr: pil=0x%x mondo=0x%x\n",
6670Sstevel@tonic-gate 		    hdlp->ih_pri, hdlp->ih_vector);
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate 		i_ddi_rem_ivintr(hdlp);
6700Sstevel@tonic-gate 
6710Sstevel@tonic-gate 		DEBUG2(DBG_R_INTX, dip, "pulse success mondo=%x reg=%p\n",
6726790Sgd78059 		    mondo, map_reg_addr);
6730Sstevel@tonic-gate 		return (DDI_SUCCESS);
6740Sstevel@tonic-gate 	}
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 	/* Translate the interrupt property */
6770Sstevel@tonic-gate 	mondo = pci_xlate_intr(dip, rdip, pci_p->pci_ib_p, ino);
6780Sstevel@tonic-gate 	if (mondo == 0) {
6790Sstevel@tonic-gate 		DEBUG1(DBG_R_INTX, dip, "can't get mondo for ino %x\n", ino);
6800Sstevel@tonic-gate 		return (DDI_FAILURE);
6810Sstevel@tonic-gate 	}
6820Sstevel@tonic-gate 	ino = IB_MONDO_TO_INO(mondo);
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate 	mutex_enter(&ib_p->ib_ino_lst_mutex);
6850Sstevel@tonic-gate 	ino_p = ib_locate_ino(ib_p, ino);
6860Sstevel@tonic-gate 	if (!ino_p) {
6870Sstevel@tonic-gate 		int r = cb_remove_xintr(pci_p, dip, rdip, ino, mondo);
6880Sstevel@tonic-gate 		if (r != DDI_SUCCESS)
6890Sstevel@tonic-gate 			cmn_err(CE_WARN, "%s%d-xintr: ino %x is invalid",
6900Sstevel@tonic-gate 			    ddi_driver_name(dip), ddi_get_instance(dip), ino);
6910Sstevel@tonic-gate 		mutex_exit(&ib_p->ib_ino_lst_mutex);
6920Sstevel@tonic-gate 		return (r);
6930Sstevel@tonic-gate 	}
6940Sstevel@tonic-gate 
6952973Sgovinda 	ipil_p = ib_ino_locate_ipil(ino_p, hdlp->ih_pri);
6962973Sgovinda 	ih_p = ib_intr_locate_ih(ipil_p, rdip, hdlp->ih_inum);
6972973Sgovinda 	ib_ino_rem_intr(pci_p, ipil_p, ih_p);
6980Sstevel@tonic-gate 	intr_dist_cpuid_rem_device_weight(ino_p->ino_cpuid, rdip);
6992973Sgovinda 	if (ipil_p->ipil_ih_size == 0) {
7000Sstevel@tonic-gate 		IB_INO_INTR_PEND(ib_clear_intr_reg_addr(ib_p, ino));
7010Sstevel@tonic-gate 		hdlp->ih_vector = CB_MONDO_TO_XMONDO(cb_p, mondo);
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate 		i_ddi_rem_ivintr(hdlp);
7042973Sgovinda 		ib_delete_ino_pil(ib_p, ipil_p);
7050Sstevel@tonic-gate 	}
7060Sstevel@tonic-gate 
7070Sstevel@tonic-gate 	/* re-enable interrupt only if mapping register still shared */
7082973Sgovinda 	if (ib_ino_map_reg_unshare(ib_p, ino, ino_p) || ino_p->ino_ipil_size) {
7090Sstevel@tonic-gate 		IB_INO_INTR_ON(ino_p->ino_map_reg);
7100Sstevel@tonic-gate 		*ino_p->ino_map_reg;
7110Sstevel@tonic-gate 	}
7120Sstevel@tonic-gate 	mutex_exit(&ib_p->ib_ino_lst_mutex);
7130Sstevel@tonic-gate 
7142973Sgovinda 	if (ino_p->ino_ipil_size == 0)
7150Sstevel@tonic-gate 		kmem_free(ino_p, sizeof (ib_ino_info_t));
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 	DEBUG1(DBG_R_INTX, dip, "success! mondo=%x\n", mondo);
7180Sstevel@tonic-gate 	return (DDI_SUCCESS);
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate /*
7220Sstevel@tonic-gate  * free the pci_inos array allocated during pci_intr_setup. the actual
7230Sstevel@tonic-gate  * interrupts are torn down by their respective block destroy routines:
7240Sstevel@tonic-gate  * cb_destroy, pbm_destroy, and ib_destroy.
7250Sstevel@tonic-gate  */
7260Sstevel@tonic-gate void
pci_intr_teardown(pci_t * pci_p)7270Sstevel@tonic-gate pci_intr_teardown(pci_t *pci_p)
7280Sstevel@tonic-gate {
7290Sstevel@tonic-gate 	kmem_free(pci_p->pci_inos, pci_p->pci_inos_len);
7300Sstevel@tonic-gate 	pci_p->pci_inos = NULL;
7310Sstevel@tonic-gate 	pci_p->pci_inos_len = 0;
7320Sstevel@tonic-gate }
733