xref: /titanic_50/usr/src/uts/common/os/ddi_intr_impl.c (revision 657f87de670449e1422db4f51fb2880a7cb69d5a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d12abe7cSanish  * Common Development and Distribution License (the "License").
6d12abe7cSanish  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22a120541cSScott M. Carter  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #include <sys/note.h>
267c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/systm.h>
307c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
317c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
327c478bd9Sstevel@tonic-gate #include <sys/debug.h>
337c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
347c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
357c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
367c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h>	/* include prototypes */
377c478bd9Sstevel@tonic-gate 
3863ea9ad2SEvan Yan #if defined(__i386) || defined(__amd64)
3963ea9ad2SEvan Yan /*
4063ea9ad2SEvan Yan  * MSI-X allocation limit.
4163ea9ad2SEvan Yan  */
4263ea9ad2SEvan Yan uint_t		ddi_msix_alloc_limit = DDI_DEFAULT_MSIX_ALLOC;
4363ea9ad2SEvan Yan #endif
44ef643aefSegillett 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * New DDI interrupt framework
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate void
i_ddi_intr_devi_init(dev_info_t * dip)497c478bd9Sstevel@tonic-gate i_ddi_intr_devi_init(dev_info_t *dip)
507c478bd9Sstevel@tonic-gate {
517c478bd9Sstevel@tonic-gate 	int	supported_types;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	DDI_INTR_APIDBG((CE_CONT, "i_ddi_intr_devi_init: dip %p\n",
547c478bd9Sstevel@tonic-gate 	    (void *)dip));
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 	if (DEVI(dip)->devi_intr_p)
577c478bd9Sstevel@tonic-gate 		return;
587c478bd9Sstevel@tonic-gate 
595febcb4aSScott Carter, SD IOSW 	DEVI(dip)->devi_intr_p = kmem_zalloc(sizeof (devinfo_intr_t), KM_SLEEP);
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	supported_types = i_ddi_intr_get_supported_types(dip);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	/* Save supported interrupt types information */
647c478bd9Sstevel@tonic-gate 	i_ddi_intr_set_supported_types(dip, supported_types);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate void
i_ddi_intr_devi_fini(dev_info_t * dip)687c478bd9Sstevel@tonic-gate i_ddi_intr_devi_fini(dev_info_t *dip)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	devinfo_intr_t	*intr_p = DEVI(dip)->devi_intr_p;
717c478bd9Sstevel@tonic-gate 
72a195726fSgovinda 	DDI_INTR_APIDBG((CE_CONT, "i_ddi_intr_devi_fini: dip %p\n",
73a195726fSgovinda 	    (void *)dip));
74a195726fSgovinda 
755febcb4aSScott Carter, SD IOSW 	if ((intr_p == NULL) || i_ddi_intr_get_current_nintrs(dip))
76a195726fSgovinda 		return;
77a195726fSgovinda 
787c478bd9Sstevel@tonic-gate 	/*
797c478bd9Sstevel@tonic-gate 	 * devi_intr_handle_p will only be used for devices
807c478bd9Sstevel@tonic-gate 	 * which are using the legacy DDI Interrupt interfaces.
817c478bd9Sstevel@tonic-gate 	 */
827c478bd9Sstevel@tonic-gate 	if (intr_p->devi_intr_handle_p) {
837c478bd9Sstevel@tonic-gate 		/* nintrs could be zero; so check for it first */
847c478bd9Sstevel@tonic-gate 		if (intr_p->devi_intr_sup_nintrs) {
857c478bd9Sstevel@tonic-gate 			kmem_free(intr_p->devi_intr_handle_p,
867c478bd9Sstevel@tonic-gate 			    intr_p->devi_intr_sup_nintrs *
877c478bd9Sstevel@tonic-gate 			    sizeof (ddi_intr_handle_t));
887c478bd9Sstevel@tonic-gate 		}
897c478bd9Sstevel@tonic-gate 	}
90a195726fSgovinda 
915febcb4aSScott Carter, SD IOSW 	/*
925febcb4aSScott Carter, SD IOSW 	 * devi_irm_req_p will only be used for devices which
935febcb4aSScott Carter, SD IOSW 	 * are mapped to an Interrupt Resource Management pool.
945febcb4aSScott Carter, SD IOSW 	 */
955febcb4aSScott Carter, SD IOSW 	if (intr_p->devi_irm_req_p)
965febcb4aSScott Carter, SD IOSW 		(void) i_ddi_irm_remove(dip);
975febcb4aSScott Carter, SD IOSW 
987c478bd9Sstevel@tonic-gate 	kmem_free(DEVI(dip)->devi_intr_p, sizeof (devinfo_intr_t));
997c478bd9Sstevel@tonic-gate 	DEVI(dip)->devi_intr_p = NULL;
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate uint_t
i_ddi_intr_get_supported_types(dev_info_t * dip)1037c478bd9Sstevel@tonic-gate i_ddi_intr_get_supported_types(dev_info_t *dip)
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	devinfo_intr_t		*intr_p = DEVI(dip)->devi_intr_p;
1067c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t	hdl;
1077c478bd9Sstevel@tonic-gate 	int			ret, intr_types;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	if ((intr_p) && (intr_p->devi_intr_sup_types))
1107c478bd9Sstevel@tonic-gate 		return (intr_p->devi_intr_sup_types);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
1137c478bd9Sstevel@tonic-gate 	hdl.ih_dip = dip;
1147c478bd9Sstevel@tonic-gate 
115a195726fSgovinda 	ret = i_ddi_intr_ops(dip, dip, DDI_INTROP_SUPPORTED_TYPES, &hdl,
1167c478bd9Sstevel@tonic-gate 	    (void *)&intr_types);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	return ((ret == DDI_SUCCESS) ? intr_types : 0);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * NOTE: This function is only called by i_ddi_dev_init().
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate void
i_ddi_intr_set_supported_types(dev_info_t * dip,int intr_types)1257c478bd9Sstevel@tonic-gate i_ddi_intr_set_supported_types(dev_info_t *dip, int intr_types)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	devinfo_intr_t		*intr_p = DEVI(dip)->devi_intr_p;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	if (intr_p)
1307c478bd9Sstevel@tonic-gate 		intr_p->devi_intr_sup_types = intr_types;
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate uint_t
i_ddi_intr_get_supported_nintrs(dev_info_t * dip,int intr_type)1347c478bd9Sstevel@tonic-gate i_ddi_intr_get_supported_nintrs(dev_info_t *dip, int intr_type)
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate 	devinfo_intr_t		*intr_p = DEVI(dip)->devi_intr_p;
1377c478bd9Sstevel@tonic-gate 	ddi_intr_handle_impl_t	hdl;
1387c478bd9Sstevel@tonic-gate 	int			ret, nintrs;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	if ((intr_p) && (intr_p->devi_intr_curr_type == intr_type) &&
1417c478bd9Sstevel@tonic-gate 	    (intr_p->devi_intr_sup_nintrs))
1427c478bd9Sstevel@tonic-gate 		return (intr_p->devi_intr_sup_nintrs);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
1457c478bd9Sstevel@tonic-gate 	hdl.ih_dip = dip;
1467c478bd9Sstevel@tonic-gate 	hdl.ih_type = intr_type;
1477c478bd9Sstevel@tonic-gate 
148a195726fSgovinda 	ret = i_ddi_intr_ops(dip, dip, DDI_INTROP_NINTRS, &hdl,
1497c478bd9Sstevel@tonic-gate 	    (void *)&nintrs);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	return ((ret == DDI_SUCCESS) ? nintrs : 0);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * NOTE: This function is only called by ddi_intr_alloc().
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate void
i_ddi_intr_set_supported_nintrs(dev_info_t * dip,int nintrs)1587c478bd9Sstevel@tonic-gate i_ddi_intr_set_supported_nintrs(dev_info_t *dip, int nintrs)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (intr_p)
1637c478bd9Sstevel@tonic-gate 		intr_p->devi_intr_sup_nintrs = nintrs;
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate uint_t
i_ddi_intr_get_current_type(dev_info_t * dip)1677c478bd9Sstevel@tonic-gate i_ddi_intr_get_current_type(dev_info_t *dip)
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	return (intr_p ? intr_p->devi_intr_curr_type : 0);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate  * NOTE: This function is only called by
1767c478bd9Sstevel@tonic-gate  *       ddi_intr_alloc() and ddi_intr_free().
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate void
i_ddi_intr_set_current_type(dev_info_t * dip,int intr_type)1797c478bd9Sstevel@tonic-gate i_ddi_intr_set_current_type(dev_info_t *dip, int intr_type)
1807c478bd9Sstevel@tonic-gate {
1817c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	if (intr_p)
1847c478bd9Sstevel@tonic-gate 		intr_p->devi_intr_curr_type = intr_type;
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate uint_t
i_ddi_intr_get_current_nintrs(dev_info_t * dip)1887c478bd9Sstevel@tonic-gate i_ddi_intr_get_current_nintrs(dev_info_t *dip)
1897c478bd9Sstevel@tonic-gate {
1907c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	return (intr_p ? intr_p->devi_intr_curr_nintrs : 0);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * NOTE: This function is only called by
1977c478bd9Sstevel@tonic-gate  *       ddi_intr_alloc() and ddi_intr_free().
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate void
i_ddi_intr_set_current_nintrs(dev_info_t * dip,int nintrs)2007c478bd9Sstevel@tonic-gate i_ddi_intr_set_current_nintrs(dev_info_t *dip, int nintrs)
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	if (intr_p)
2057c478bd9Sstevel@tonic-gate 		intr_p->devi_intr_curr_nintrs = nintrs;
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2085febcb4aSScott Carter, SD IOSW uint_t
i_ddi_intr_get_current_nenables(dev_info_t * dip)2092145b8d4SGuoli Shu i_ddi_intr_get_current_nenables(dev_info_t *dip)
2102145b8d4SGuoli Shu {
2112145b8d4SGuoli Shu 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
2122145b8d4SGuoli Shu 
2132145b8d4SGuoli Shu 	return (intr_p ? intr_p->devi_intr_curr_nenables : 0);
2142145b8d4SGuoli Shu }
2152145b8d4SGuoli Shu 
2162145b8d4SGuoli Shu void
i_ddi_intr_set_current_nenables(dev_info_t * dip,int nintrs)2172145b8d4SGuoli Shu i_ddi_intr_set_current_nenables(dev_info_t *dip, int nintrs)
2182145b8d4SGuoli Shu {
2192145b8d4SGuoli Shu 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
2202145b8d4SGuoli Shu 
2212145b8d4SGuoli Shu 	if (intr_p)
2222145b8d4SGuoli Shu 		intr_p->devi_intr_curr_nenables = nintrs;
2232145b8d4SGuoli Shu }
2242145b8d4SGuoli Shu 
225a120541cSScott M. Carter /*
226a120541cSScott M. Carter  * i_ddi_intr_get_current_navail:
227a120541cSScott M. Carter  *
228a120541cSScott M. Carter  *	Return the number of interrupts currently available.
229a120541cSScott M. Carter  *	If a precise number set by IRM is not available, then
230a120541cSScott M. Carter  *	return the limit determined by i_ddi_intr_get_limit().
231a120541cSScott M. Carter  */
2322145b8d4SGuoli Shu uint_t
i_ddi_intr_get_current_navail(dev_info_t * dip,int type)2335febcb4aSScott Carter, SD IOSW i_ddi_intr_get_current_navail(dev_info_t *dip, int type)
2345febcb4aSScott Carter, SD IOSW {
235a120541cSScott M. Carter 	devinfo_intr_t		*intr_p;
2365febcb4aSScott Carter, SD IOSW 	ddi_irm_pool_t		*pool_p;
2375febcb4aSScott Carter, SD IOSW 	ddi_irm_req_t		*req_p;
238a120541cSScott M. Carter 	uint_t			navail;
2395febcb4aSScott Carter, SD IOSW 
240a120541cSScott M. Carter 	/* Check for a precise number from IRM */
241a120541cSScott M. Carter 	if (((intr_p = DEVI(dip)->devi_intr_p) != NULL) &&
242a120541cSScott M. Carter 	    ((req_p = intr_p->devi_irm_req_p) != NULL) &&
243a120541cSScott M. Carter 	    (type == req_p->ireq_type) &&
244a120541cSScott M. Carter 	    ((pool_p = req_p->ireq_pool_p) != NULL)) {
2455febcb4aSScott Carter, SD IOSW 		/*
246a120541cSScott M. Carter 		 * Lock to be sure a rebalance is not in progress.
247a120541cSScott M. Carter 		 * (Should be changed to a rwlock.)
2485febcb4aSScott Carter, SD IOSW 		 */
2495febcb4aSScott Carter, SD IOSW 		mutex_enter(&pool_p->ipool_navail_lock);
2505febcb4aSScott Carter, SD IOSW 		navail = req_p->ireq_navail;
2515febcb4aSScott Carter, SD IOSW 		mutex_exit(&pool_p->ipool_navail_lock);
2525febcb4aSScott Carter, SD IOSW 		return (navail);
2535febcb4aSScott Carter, SD IOSW 	}
254a120541cSScott M. Carter 
255a120541cSScott M. Carter 	/* Otherwise, return the limit */
256a120541cSScott M. Carter 	return (i_ddi_intr_get_limit(dip, type, NULL));
2575febcb4aSScott Carter, SD IOSW }
258a120541cSScott M. Carter 
259a120541cSScott M. Carter /*
260a120541cSScott M. Carter  * i_ddi_intr_get_limit:
261a120541cSScott M. Carter  *
262a120541cSScott M. Carter  *	Return the limit of how many interrupts a driver can allocate.
263a120541cSScott M. Carter  */
264a120541cSScott M. Carter uint_t
i_ddi_intr_get_limit(dev_info_t * dip,int type,ddi_irm_pool_t * pool_p)265a120541cSScott M. Carter i_ddi_intr_get_limit(dev_info_t *dip, int type, ddi_irm_pool_t *pool_p)
266a120541cSScott M. Carter {
267a120541cSScott M. Carter 	ddi_intr_handle_impl_t	hdl;
268a120541cSScott M. Carter 	uint_t			limit, nintrs;
269a120541cSScott M. Carter 
270a120541cSScott M. Carter 	/* Check for interrupt pool */
271a120541cSScott M. Carter 	if (pool_p == NULL)
272a120541cSScott M. Carter 		pool_p = i_ddi_intr_get_pool(dip, type);
273a120541cSScott M. Carter 
274a120541cSScott M. Carter 	/* Get default limit, from interrupt pool or by INTROP method */
275a120541cSScott M. Carter 	if (pool_p != NULL) {
276a120541cSScott M. Carter 		limit = pool_p->ipool_defsz;
2775febcb4aSScott Carter, SD IOSW 	} else {
2785febcb4aSScott Carter, SD IOSW 		bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
2795febcb4aSScott Carter, SD IOSW 		hdl.ih_dip = dip;
2805febcb4aSScott Carter, SD IOSW 		hdl.ih_type = type;
2815febcb4aSScott Carter, SD IOSW 		if (i_ddi_intr_ops(dip, dip, DDI_INTROP_NAVAIL, &hdl,
282a120541cSScott M. Carter 		    (void *)&limit) != DDI_SUCCESS)
2835febcb4aSScott Carter, SD IOSW 			return (0);
2845febcb4aSScott Carter, SD IOSW 	}
2855febcb4aSScott Carter, SD IOSW 
286a120541cSScott M. Carter 	/* Get maximum supported by the device */
287a120541cSScott M. Carter 	nintrs = i_ddi_intr_get_supported_nintrs(dip, type);
288a120541cSScott M. Carter 
289a120541cSScott M. Carter 	/* No limit if device and system both support IRM */
290a120541cSScott M. Carter 	if ((pool_p != NULL) && (i_ddi_irm_supported(dip, type) == DDI_SUCCESS))
291a120541cSScott M. Carter 		return (nintrs);
292a120541cSScott M. Carter 
293a120541cSScott M. Carter 	/* Limit cannot exceed what device supports */
294a120541cSScott M. Carter 	limit = MIN(limit, nintrs);
295a120541cSScott M. Carter 
296a120541cSScott M. Carter 	/* Impose a global MSI-X limit on x86 */
29763ea9ad2SEvan Yan #if defined(__i386) || defined(__amd64)
298a120541cSScott M. Carter 	if (type == DDI_INTR_TYPE_MSIX)
299a120541cSScott M. Carter 		limit = MIN(limit, ddi_msix_alloc_limit);
30063ea9ad2SEvan Yan #endif
3015febcb4aSScott Carter, SD IOSW 
302a120541cSScott M. Carter 	/* Impose a global MSI limit on all platforms */
3035febcb4aSScott Carter, SD IOSW 	if (type == DDI_INTR_TYPE_MSI)
304a120541cSScott M. Carter 		limit = MIN(limit, DDI_MAX_MSI_ALLOC);
3055febcb4aSScott Carter, SD IOSW 
306a120541cSScott M. Carter 	return (limit);
3075febcb4aSScott Carter, SD IOSW }
3085febcb4aSScott Carter, SD IOSW 
3097c478bd9Sstevel@tonic-gate ddi_intr_msix_t *
i_ddi_get_msix(dev_info_t * dip)3107c478bd9Sstevel@tonic-gate i_ddi_get_msix(dev_info_t *dip)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	return (intr_p ? intr_p->devi_msix_p : NULL);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate void
i_ddi_set_msix(dev_info_t * dip,ddi_intr_msix_t * msix_p)3187c478bd9Sstevel@tonic-gate i_ddi_set_msix(dev_info_t *dip, ddi_intr_msix_t *msix_p)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	if (intr_p)
3237c478bd9Sstevel@tonic-gate 		intr_p->devi_msix_p = msix_p;
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3265febcb4aSScott Carter, SD IOSW ddi_intr_handle_t
i_ddi_get_intr_handle(dev_info_t * dip,int inum)3277c478bd9Sstevel@tonic-gate i_ddi_get_intr_handle(dev_info_t *dip, int inum)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	if (intr_p == NULL)
3327c478bd9Sstevel@tonic-gate 		return (NULL);
3337c478bd9Sstevel@tonic-gate 
334e821bd34Sanish 	/*
335e821bd34Sanish 	 * Changed this to a check and return NULL if an invalid inum
336e821bd34Sanish 	 * is passed to retrieve a handle
337e821bd34Sanish 	 */
338e821bd34Sanish 	if ((inum < 0) || (inum >= intr_p->devi_intr_sup_nintrs))
339e821bd34Sanish 		return (NULL);
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	return ((intr_p->devi_intr_handle_p) ?
3427c478bd9Sstevel@tonic-gate 	    intr_p->devi_intr_handle_p[inum] : NULL);
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate void
i_ddi_set_intr_handle(dev_info_t * dip,int inum,ddi_intr_handle_t intr_hdl)3465febcb4aSScott Carter, SD IOSW i_ddi_set_intr_handle(dev_info_t *dip, int inum, ddi_intr_handle_t intr_hdl)
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate 	devinfo_intr_t	*intr_p = DEVI(dip)->devi_intr_p;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	if (intr_p == NULL)
3517c478bd9Sstevel@tonic-gate 		return;
3527c478bd9Sstevel@tonic-gate 
353e821bd34Sanish 	/*
354e821bd34Sanish 	 * Changed this to a check and return if an invalid inum
355e821bd34Sanish 	 * is passed to set a handle
356e821bd34Sanish 	 */
357e821bd34Sanish 	if ((inum < 0) || (inum >= intr_p->devi_intr_sup_nintrs))
358e821bd34Sanish 		return;
3597c478bd9Sstevel@tonic-gate 
3605febcb4aSScott Carter, SD IOSW 	if (intr_hdl && (intr_p->devi_intr_handle_p == NULL)) {
3617c478bd9Sstevel@tonic-gate 		/* nintrs could be zero; so check for it first */
3627c478bd9Sstevel@tonic-gate 		if (intr_p->devi_intr_sup_nintrs)
3637c478bd9Sstevel@tonic-gate 			intr_p->devi_intr_handle_p = kmem_zalloc(
3647c478bd9Sstevel@tonic-gate 			    sizeof (ddi_intr_handle_t) *
3657c478bd9Sstevel@tonic-gate 			    intr_p->devi_intr_sup_nintrs, KM_SLEEP);
3667c478bd9Sstevel@tonic-gate 	}
3677c478bd9Sstevel@tonic-gate 
368a195726fSgovinda 	if (intr_p->devi_intr_handle_p)
3695febcb4aSScott Carter, SD IOSW 		intr_p->devi_intr_handle_p[inum] = intr_hdl;
3707c478bd9Sstevel@tonic-gate }
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate /*
3737c478bd9Sstevel@tonic-gate  * The "ddi-intr-weight" property contains the weight of each interrupt
3747c478bd9Sstevel@tonic-gate  * associated with a dev_info node. For devices with multiple interrupts per
3757c478bd9Sstevel@tonic-gate  * dev_info node, the total load of the device is "devi_intr_weight * nintr",
3767c478bd9Sstevel@tonic-gate  * possibly spread out over multiple CPUs.
3777c478bd9Sstevel@tonic-gate  *
3787c478bd9Sstevel@tonic-gate  * Maintaining this as a property permits possible tweaking in the product
3797c478bd9Sstevel@tonic-gate  * in response to customer problems via driver.conf property definitions at
3807c478bd9Sstevel@tonic-gate  * the driver or the instance level.  This does not mean that "ddi-intr_weight"
3817c478bd9Sstevel@tonic-gate  * is a formal or committed interface.
3827c478bd9Sstevel@tonic-gate  */
3837c478bd9Sstevel@tonic-gate int32_t
i_ddi_get_intr_weight(dev_info_t * dip)3847c478bd9Sstevel@tonic-gate i_ddi_get_intr_weight(dev_info_t *dip)
3857c478bd9Sstevel@tonic-gate {
3867c478bd9Sstevel@tonic-gate 	int32_t	weight;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	weight = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
3897c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ddi-intr-weight", -1);
3907c478bd9Sstevel@tonic-gate 	if (weight < -1)
3917c478bd9Sstevel@tonic-gate 		weight = -1;			/* undefined */
3927c478bd9Sstevel@tonic-gate 	return (weight);
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate int32_t
i_ddi_set_intr_weight(dev_info_t * dip,int32_t weight)3967c478bd9Sstevel@tonic-gate i_ddi_set_intr_weight(dev_info_t *dip, int32_t weight)
3977c478bd9Sstevel@tonic-gate {
3987c478bd9Sstevel@tonic-gate 	int32_t oweight;
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	oweight = i_ddi_get_intr_weight(dip);
4017c478bd9Sstevel@tonic-gate 	if ((weight > 0) && (oweight != weight))
4027c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, dip,
4037c478bd9Sstevel@tonic-gate 		    "ddi-intr-weight", weight);
4047c478bd9Sstevel@tonic-gate 	return (oweight);
4057c478bd9Sstevel@tonic-gate }
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate  * Old DDI interrupt framework
4097c478bd9Sstevel@tonic-gate  *
4107c478bd9Sstevel@tonic-gate  * NOTE:
4117c478bd9Sstevel@tonic-gate  *	The following 4 busops entry points are obsoleted with version
4127c478bd9Sstevel@tonic-gate  *	9 or greater. Use i_ddi_intr_op interface in place of these
4137c478bd9Sstevel@tonic-gate  *	obsolete interfaces.
4147c478bd9Sstevel@tonic-gate  *
4157c478bd9Sstevel@tonic-gate  *	Remove these busops entry points and all related data structures
4167c478bd9Sstevel@tonic-gate  *	in future major/minor solaris release.
4177c478bd9Sstevel@tonic-gate  */
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate /* ARGSUSED */
4207c478bd9Sstevel@tonic-gate ddi_intrspec_t
i_ddi_get_intrspec(dev_info_t * dip,dev_info_t * rdip,uint_t inumber)4217c478bd9Sstevel@tonic-gate i_ddi_get_intrspec(dev_info_t *dip, dev_info_t *rdip, uint_t inumber)
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate 	dev_info_t	*pdip = ddi_get_parent(dip);
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "Failed to process interrupt "
4267c478bd9Sstevel@tonic-gate 	    "for %s%d due to down-rev nexus driver %s%d",
427a195726fSgovinda 	    ddi_driver_name(rdip), ddi_get_instance(rdip),
428a195726fSgovinda 	    ddi_driver_name(pdip), ddi_get_instance(pdip));
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	return (NULL);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate /* ARGSUSED */
4347c478bd9Sstevel@tonic-gate int
i_ddi_add_intrspec(dev_info_t * dip,dev_info_t * rdip,ddi_intrspec_t intrspec,ddi_iblock_cookie_t * iblock_cookiep,ddi_idevice_cookie_t * idevice_cookiep,uint_t (* int_handler)(caddr_t int_handler_arg),caddr_t int_handler_arg,int kind)4357c478bd9Sstevel@tonic-gate i_ddi_add_intrspec(dev_info_t *dip, dev_info_t *rdip, ddi_intrspec_t intrspec,
4367c478bd9Sstevel@tonic-gate     ddi_iblock_cookie_t *iblock_cookiep,
4377c478bd9Sstevel@tonic-gate     ddi_idevice_cookie_t *idevice_cookiep,
4387c478bd9Sstevel@tonic-gate     uint_t (*int_handler)(caddr_t int_handler_arg),
4397c478bd9Sstevel@tonic-gate     caddr_t int_handler_arg, int kind)
4407c478bd9Sstevel@tonic-gate {
4417c478bd9Sstevel@tonic-gate 	dev_info_t	*pdip = ddi_get_parent(dip);
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "Failed to process interrupt "
4447c478bd9Sstevel@tonic-gate 	    "for %s%d due to down-rev nexus driver %s%d",
445a195726fSgovinda 	    ddi_driver_name(rdip), ddi_get_instance(rdip),
446a195726fSgovinda 	    ddi_driver_name(pdip), ddi_get_instance(pdip));
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	return (DDI_ENOTSUP);
4497c478bd9Sstevel@tonic-gate }
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate /* ARGSUSED */
4527c478bd9Sstevel@tonic-gate void
i_ddi_remove_intrspec(dev_info_t * dip,dev_info_t * rdip,ddi_intrspec_t intrspec,ddi_iblock_cookie_t iblock_cookie)4537c478bd9Sstevel@tonic-gate i_ddi_remove_intrspec(dev_info_t *dip, dev_info_t *rdip,
4547c478bd9Sstevel@tonic-gate     ddi_intrspec_t intrspec, ddi_iblock_cookie_t iblock_cookie)
4557c478bd9Sstevel@tonic-gate {
4567c478bd9Sstevel@tonic-gate 	dev_info_t	*pdip = ddi_get_parent(dip);
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "Failed to process interrupt "
4597c478bd9Sstevel@tonic-gate 	    "for %s%d due to down-rev nexus driver %s%d",
460a195726fSgovinda 	    ddi_driver_name(rdip), ddi_get_instance(rdip),
461a195726fSgovinda 	    ddi_driver_name(pdip), ddi_get_instance(pdip));
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate /* ARGSUSED */
4657c478bd9Sstevel@tonic-gate int
i_ddi_intr_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_intr_ctlop_t op,void * arg,void * val)4667c478bd9Sstevel@tonic-gate i_ddi_intr_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_ctlop_t op,
4677c478bd9Sstevel@tonic-gate     void *arg, void *val)
4687c478bd9Sstevel@tonic-gate {
4697c478bd9Sstevel@tonic-gate 	dev_info_t	*pdip = ddi_get_parent(dip);
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "Failed to process interrupt "
4727c478bd9Sstevel@tonic-gate 	    "for %s%d due to down-rev nexus driver %s%d",
473a195726fSgovinda 	    ddi_driver_name(rdip), ddi_get_instance(rdip),
474a195726fSgovinda 	    ddi_driver_name(pdip), ddi_get_instance(pdip));
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	return (DDI_ENOTSUP);
4777c478bd9Sstevel@tonic-gate }
478d12abe7cSanish 
479*657f87deSgongtian zhao - Sun Microsystems - Beijing China /*
480*657f87deSgongtian zhao - Sun Microsystems - Beijing China  * Interrupt target get/set functions
481*657f87deSgongtian zhao - Sun Microsystems - Beijing China  */
482*657f87deSgongtian zhao - Sun Microsystems - Beijing China int
get_intr_affinity(ddi_intr_handle_t h,processorid_t * tgt_p)483*657f87deSgongtian zhao - Sun Microsystems - Beijing China get_intr_affinity(ddi_intr_handle_t h, processorid_t *tgt_p)
484*657f87deSgongtian zhao - Sun Microsystems - Beijing China {
485*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	ddi_intr_handle_impl_t	*hdlp = (ddi_intr_handle_impl_t *)h;
486*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	int			ret;
487*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
488*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	DDI_INTR_APIDBG((CE_CONT, "get_intr_affinity: hdlp = %p\n",
489*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	    (void *)hdlp));
490*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
491*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	if ((hdlp == NULL) || (tgt_p == NULL))
492*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		return (DDI_EINVAL);
493*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
494*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	rw_enter(&hdlp->ih_rwlock, RW_READER);
495*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	if (hdlp->ih_state != DDI_IHDL_STATE_ENABLE) {
496*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		rw_exit(&hdlp->ih_rwlock);
497*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		return (DDI_EINVAL);
498*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	}
499*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
500*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	ret = i_ddi_intr_ops(hdlp->ih_dip, hdlp->ih_dip,
501*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	    DDI_INTROP_GETTARGET, hdlp, (void *)tgt_p);
502*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
503*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	DDI_INTR_APIDBG((CE_CONT, "get_intr_affinity: target %x\n",
504*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	    *tgt_p));
505*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
506*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	if (ret == DDI_SUCCESS)
507*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		hdlp->ih_target = *tgt_p;
508*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
509*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	rw_exit(&hdlp->ih_rwlock);
510*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	return (ret);
511*657f87deSgongtian zhao - Sun Microsystems - Beijing China }
512*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
513*657f87deSgongtian zhao - Sun Microsystems - Beijing China int
set_intr_affinity(ddi_intr_handle_t h,processorid_t tgt)514*657f87deSgongtian zhao - Sun Microsystems - Beijing China set_intr_affinity(ddi_intr_handle_t h, processorid_t tgt)
515*657f87deSgongtian zhao - Sun Microsystems - Beijing China {
516*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	ddi_intr_handle_impl_t	*hdlp = (ddi_intr_handle_impl_t *)h;
517*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	int			ret;
518*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
519*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	DDI_INTR_APIDBG((CE_CONT, "set_intr_affinity: hdlp = %p "
520*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	    "target %x\n", (void *)hdlp, tgt));
521*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
522*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	if (hdlp == NULL)
523*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		return (DDI_EINVAL);
524*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
525*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	rw_enter(&hdlp->ih_rwlock, RW_WRITER);
526*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	if ((hdlp->ih_state != DDI_IHDL_STATE_ENABLE) ||
527*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	    (hdlp->ih_type != DDI_INTR_TYPE_MSIX)) {
528*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		rw_exit(&hdlp->ih_rwlock);
529*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		return (DDI_EINVAL);
530*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	}
531*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
532*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	ret = i_ddi_intr_ops(hdlp->ih_dip, hdlp->ih_dip,
533*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	    DDI_INTROP_SETTARGET, hdlp, &tgt);
534*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
535*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	if (ret == DDI_SUCCESS)
536*657f87deSgongtian zhao - Sun Microsystems - Beijing China 		hdlp->ih_target = tgt;
537*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
538*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	rw_exit(&hdlp->ih_rwlock);
539*657f87deSgongtian zhao - Sun Microsystems - Beijing China 	return (ret);
540*657f87deSgongtian zhao - Sun Microsystems - Beijing China }
541*657f87deSgongtian zhao - Sun Microsystems - Beijing China 
542d12abe7cSanish #if defined(__i386) || defined(__amd64)
543d12abe7cSanish ddi_acc_handle_t
i_ddi_get_pci_config_handle(dev_info_t * dip)544d12abe7cSanish i_ddi_get_pci_config_handle(dev_info_t *dip)
545d12abe7cSanish {
546d12abe7cSanish 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
547d12abe7cSanish 
548d12abe7cSanish 	return (intr_p ? intr_p->devi_cfg_handle : NULL);
549d12abe7cSanish }
550d12abe7cSanish 
551d12abe7cSanish void
i_ddi_set_pci_config_handle(dev_info_t * dip,ddi_acc_handle_t handle)552d12abe7cSanish i_ddi_set_pci_config_handle(dev_info_t *dip, ddi_acc_handle_t handle)
553d12abe7cSanish {
554d12abe7cSanish 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
555d12abe7cSanish 
556d12abe7cSanish 	if (intr_p)
557d12abe7cSanish 		intr_p->devi_cfg_handle = handle;
558d12abe7cSanish }
559d12abe7cSanish 
560d12abe7cSanish 
561d12abe7cSanish int
i_ddi_get_msi_msix_cap_ptr(dev_info_t * dip)562d12abe7cSanish i_ddi_get_msi_msix_cap_ptr(dev_info_t *dip)
563d12abe7cSanish {
564d12abe7cSanish 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
565d12abe7cSanish 
566d12abe7cSanish 	return (intr_p ? intr_p->devi_cap_ptr : 0);
567d12abe7cSanish }
568d12abe7cSanish 
569d12abe7cSanish void
i_ddi_set_msi_msix_cap_ptr(dev_info_t * dip,int cap_ptr)570d12abe7cSanish i_ddi_set_msi_msix_cap_ptr(dev_info_t *dip, int cap_ptr)
571d12abe7cSanish {
572d12abe7cSanish 	devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p;
573d12abe7cSanish 
574d12abe7cSanish 	if (intr_p)
575d12abe7cSanish 		intr_p->devi_cap_ptr = cap_ptr;
576d12abe7cSanish }
577d12abe7cSanish #endif
578