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 /* 22*5febcb4aSScott Carter, SD IOSW * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/note.h> 277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/param.h> 307c478bd9Sstevel@tonic-gate #include <sys/systm.h> 317c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 327c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 337c478bd9Sstevel@tonic-gate #include <sys/debug.h> 347c478bd9Sstevel@tonic-gate #include <sys/avintr.h> 357c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 367c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 377c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h> /* include prototypes */ 387c478bd9Sstevel@tonic-gate 39ef643aefSegillett extern uint_t ddi_msix_alloc_limit; 40ef643aefSegillett 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * New DDI interrupt framework 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate void 457c478bd9Sstevel@tonic-gate i_ddi_intr_devi_init(dev_info_t *dip) 467c478bd9Sstevel@tonic-gate { 477c478bd9Sstevel@tonic-gate int supported_types; 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate DDI_INTR_APIDBG((CE_CONT, "i_ddi_intr_devi_init: dip %p\n", 507c478bd9Sstevel@tonic-gate (void *)dip)); 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate if (DEVI(dip)->devi_intr_p) 537c478bd9Sstevel@tonic-gate return; 547c478bd9Sstevel@tonic-gate 55*5febcb4aSScott Carter, SD IOSW DEVI(dip)->devi_intr_p = kmem_zalloc(sizeof (devinfo_intr_t), KM_SLEEP); 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate supported_types = i_ddi_intr_get_supported_types(dip); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* Save supported interrupt types information */ 607c478bd9Sstevel@tonic-gate i_ddi_intr_set_supported_types(dip, supported_types); 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate void 647c478bd9Sstevel@tonic-gate i_ddi_intr_devi_fini(dev_info_t *dip) 657c478bd9Sstevel@tonic-gate { 667c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 677c478bd9Sstevel@tonic-gate 68a195726fSgovinda DDI_INTR_APIDBG((CE_CONT, "i_ddi_intr_devi_fini: dip %p\n", 69a195726fSgovinda (void *)dip)); 70a195726fSgovinda 71*5febcb4aSScott Carter, SD IOSW if ((intr_p == NULL) || i_ddi_intr_get_current_nintrs(dip)) 72a195726fSgovinda return; 73a195726fSgovinda 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * devi_intr_handle_p will only be used for devices 767c478bd9Sstevel@tonic-gate * which are using the legacy DDI Interrupt interfaces. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate if (intr_p->devi_intr_handle_p) { 797c478bd9Sstevel@tonic-gate /* nintrs could be zero; so check for it first */ 807c478bd9Sstevel@tonic-gate if (intr_p->devi_intr_sup_nintrs) { 817c478bd9Sstevel@tonic-gate kmem_free(intr_p->devi_intr_handle_p, 827c478bd9Sstevel@tonic-gate intr_p->devi_intr_sup_nintrs * 837c478bd9Sstevel@tonic-gate sizeof (ddi_intr_handle_t)); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate } 86a195726fSgovinda 87*5febcb4aSScott Carter, SD IOSW /* 88*5febcb4aSScott Carter, SD IOSW * devi_irm_req_p will only be used for devices which 89*5febcb4aSScott Carter, SD IOSW * are mapped to an Interrupt Resource Management pool. 90*5febcb4aSScott Carter, SD IOSW */ 91*5febcb4aSScott Carter, SD IOSW if (intr_p->devi_irm_req_p) 92*5febcb4aSScott Carter, SD IOSW (void) i_ddi_irm_remove(dip); 93*5febcb4aSScott Carter, SD IOSW 947c478bd9Sstevel@tonic-gate kmem_free(DEVI(dip)->devi_intr_p, sizeof (devinfo_intr_t)); 957c478bd9Sstevel@tonic-gate DEVI(dip)->devi_intr_p = NULL; 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate uint_t 997c478bd9Sstevel@tonic-gate i_ddi_intr_get_supported_types(dev_info_t *dip) 1007c478bd9Sstevel@tonic-gate { 1017c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1027c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 1037c478bd9Sstevel@tonic-gate int ret, intr_types; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate if ((intr_p) && (intr_p->devi_intr_sup_types)) 1067c478bd9Sstevel@tonic-gate return (intr_p->devi_intr_sup_types); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate bzero(&hdl, sizeof (ddi_intr_handle_impl_t)); 1097c478bd9Sstevel@tonic-gate hdl.ih_dip = dip; 1107c478bd9Sstevel@tonic-gate 111a195726fSgovinda ret = i_ddi_intr_ops(dip, dip, DDI_INTROP_SUPPORTED_TYPES, &hdl, 1127c478bd9Sstevel@tonic-gate (void *)&intr_types); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate return ((ret == DDI_SUCCESS) ? intr_types : 0); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * NOTE: This function is only called by i_ddi_dev_init(). 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate void 1217c478bd9Sstevel@tonic-gate i_ddi_intr_set_supported_types(dev_info_t *dip, int intr_types) 1227c478bd9Sstevel@tonic-gate { 1237c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate if (intr_p) 1267c478bd9Sstevel@tonic-gate intr_p->devi_intr_sup_types = intr_types; 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate uint_t 1307c478bd9Sstevel@tonic-gate i_ddi_intr_get_supported_nintrs(dev_info_t *dip, int intr_type) 1317c478bd9Sstevel@tonic-gate { 1327c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1337c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 1347c478bd9Sstevel@tonic-gate int ret, nintrs; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate if ((intr_p) && (intr_p->devi_intr_curr_type == intr_type) && 1377c478bd9Sstevel@tonic-gate (intr_p->devi_intr_sup_nintrs)) 1387c478bd9Sstevel@tonic-gate return (intr_p->devi_intr_sup_nintrs); 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate bzero(&hdl, sizeof (ddi_intr_handle_impl_t)); 1417c478bd9Sstevel@tonic-gate hdl.ih_dip = dip; 1427c478bd9Sstevel@tonic-gate hdl.ih_type = intr_type; 1437c478bd9Sstevel@tonic-gate 144a195726fSgovinda ret = i_ddi_intr_ops(dip, dip, DDI_INTROP_NINTRS, &hdl, 1457c478bd9Sstevel@tonic-gate (void *)&nintrs); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate return ((ret == DDI_SUCCESS) ? nintrs : 0); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* 1517c478bd9Sstevel@tonic-gate * NOTE: This function is only called by ddi_intr_alloc(). 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate void 1547c478bd9Sstevel@tonic-gate i_ddi_intr_set_supported_nintrs(dev_info_t *dip, int nintrs) 1557c478bd9Sstevel@tonic-gate { 1567c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate if (intr_p) 1597c478bd9Sstevel@tonic-gate intr_p->devi_intr_sup_nintrs = nintrs; 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate uint_t 1637c478bd9Sstevel@tonic-gate i_ddi_intr_get_current_type(dev_info_t *dip) 1647c478bd9Sstevel@tonic-gate { 1657c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate return (intr_p ? intr_p->devi_intr_curr_type : 0); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * NOTE: This function is only called by 1727c478bd9Sstevel@tonic-gate * ddi_intr_alloc() and ddi_intr_free(). 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate void 1757c478bd9Sstevel@tonic-gate i_ddi_intr_set_current_type(dev_info_t *dip, int intr_type) 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate if (intr_p) 1807c478bd9Sstevel@tonic-gate intr_p->devi_intr_curr_type = intr_type; 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate uint_t 1847c478bd9Sstevel@tonic-gate i_ddi_intr_get_current_nintrs(dev_info_t *dip) 1857c478bd9Sstevel@tonic-gate { 1867c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate return (intr_p ? intr_p->devi_intr_curr_nintrs : 0); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * NOTE: This function is only called by 1937c478bd9Sstevel@tonic-gate * ddi_intr_alloc() and ddi_intr_free(). 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate void 1967c478bd9Sstevel@tonic-gate i_ddi_intr_set_current_nintrs(dev_info_t *dip, int nintrs) 1977c478bd9Sstevel@tonic-gate { 1987c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate if (intr_p) 2017c478bd9Sstevel@tonic-gate intr_p->devi_intr_curr_nintrs = nintrs; 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate 204*5febcb4aSScott Carter, SD IOSW uint_t 205*5febcb4aSScott Carter, SD IOSW i_ddi_intr_get_current_navail(dev_info_t *dip, int type) 206*5febcb4aSScott Carter, SD IOSW { 207*5febcb4aSScott Carter, SD IOSW ddi_intr_handle_impl_t hdl; 208*5febcb4aSScott Carter, SD IOSW devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 209*5febcb4aSScott Carter, SD IOSW ddi_cb_t *cb_p; 210*5febcb4aSScott Carter, SD IOSW ddi_irm_pool_t *pool_p; 211*5febcb4aSScott Carter, SD IOSW ddi_irm_req_t *req_p; 212*5febcb4aSScott Carter, SD IOSW uint_t navail = 0, nintrs, nreq; 213*5febcb4aSScott Carter, SD IOSW 214*5febcb4aSScott Carter, SD IOSW /* Get maximum number of supported interrupts */ 215*5febcb4aSScott Carter, SD IOSW nintrs = i_ddi_intr_get_supported_nintrs(dip, type); 216*5febcb4aSScott Carter, SD IOSW 217*5febcb4aSScott Carter, SD IOSW /* Check for an interrupt pool */ 218*5febcb4aSScott Carter, SD IOSW pool_p = i_ddi_intr_get_pool(dip, type); 219*5febcb4aSScott Carter, SD IOSW 220*5febcb4aSScott Carter, SD IOSW /* 221*5febcb4aSScott Carter, SD IOSW * If a pool exists, then IRM determines the availability. 222*5febcb4aSScott Carter, SD IOSW * Otherwise, use the older INTROP method. 223*5febcb4aSScott Carter, SD IOSW */ 224*5febcb4aSScott Carter, SD IOSW if (pool_p) { 225*5febcb4aSScott Carter, SD IOSW if (intr_p && (req_p = intr_p->devi_irm_req_p) && 226*5febcb4aSScott Carter, SD IOSW (type == req_p->ireq_type)) { 227*5febcb4aSScott Carter, SD IOSW mutex_enter(&pool_p->ipool_navail_lock); 228*5febcb4aSScott Carter, SD IOSW navail = req_p->ireq_navail; 229*5febcb4aSScott Carter, SD IOSW mutex_exit(&pool_p->ipool_navail_lock); 230*5febcb4aSScott Carter, SD IOSW return (navail); 231*5febcb4aSScott Carter, SD IOSW } 232*5febcb4aSScott Carter, SD IOSW if ((type == DDI_INTR_TYPE_MSIX) && 233*5febcb4aSScott Carter, SD IOSW (cb_p = DEVI(dip)->devi_cb_p) && 234*5febcb4aSScott Carter, SD IOSW (cb_p->cb_flags & DDI_CB_FLAG_INTR)) { 235*5febcb4aSScott Carter, SD IOSW return (nintrs); 236*5febcb4aSScott Carter, SD IOSW } 237*5febcb4aSScott Carter, SD IOSW navail = pool_p->ipool_defsz; 238*5febcb4aSScott Carter, SD IOSW } else { 239*5febcb4aSScott Carter, SD IOSW bzero(&hdl, sizeof (ddi_intr_handle_impl_t)); 240*5febcb4aSScott Carter, SD IOSW hdl.ih_dip = dip; 241*5febcb4aSScott Carter, SD IOSW hdl.ih_type = type; 242*5febcb4aSScott Carter, SD IOSW 243*5febcb4aSScott Carter, SD IOSW if (i_ddi_intr_ops(dip, dip, DDI_INTROP_NAVAIL, &hdl, 244*5febcb4aSScott Carter, SD IOSW (void *)&navail) != DDI_SUCCESS) { 245*5febcb4aSScott Carter, SD IOSW return (0); 246*5febcb4aSScott Carter, SD IOSW } 247*5febcb4aSScott Carter, SD IOSW } 248*5febcb4aSScott Carter, SD IOSW 249*5febcb4aSScott Carter, SD IOSW /* Apply MSI-X workarounds */ 250*5febcb4aSScott Carter, SD IOSW if (type == DDI_INTR_TYPE_MSIX) { 251*5febcb4aSScott Carter, SD IOSW /* Global tunable workaround */ 252*5febcb4aSScott Carter, SD IOSW if (navail < nintrs) 253*5febcb4aSScott Carter, SD IOSW navail = MIN(nintrs, ddi_msix_alloc_limit); 254*5febcb4aSScott Carter, SD IOSW /* Device property workaround */ 255*5febcb4aSScott Carter, SD IOSW if ((nreq = i_ddi_get_msix_alloc_limit(dip)) > 0) 256*5febcb4aSScott Carter, SD IOSW navail = MAX(navail, nreq); 257*5febcb4aSScott Carter, SD IOSW } 258*5febcb4aSScott Carter, SD IOSW 259*5febcb4aSScott Carter, SD IOSW /* Always restrict MSI to a precise limit */ 260*5febcb4aSScott Carter, SD IOSW if (type == DDI_INTR_TYPE_MSI) 261*5febcb4aSScott Carter, SD IOSW navail = MIN(navail, DDI_MAX_MSI_ALLOC); 262*5febcb4aSScott Carter, SD IOSW 263*5febcb4aSScott Carter, SD IOSW /* Ensure availability doesn't exceed what's supported */ 264*5febcb4aSScott Carter, SD IOSW navail = MIN(navail, nintrs); 265*5febcb4aSScott Carter, SD IOSW 266*5febcb4aSScott Carter, SD IOSW return (navail); 267*5febcb4aSScott Carter, SD IOSW } 268*5febcb4aSScott Carter, SD IOSW 2697c478bd9Sstevel@tonic-gate ddi_intr_msix_t * 2707c478bd9Sstevel@tonic-gate i_ddi_get_msix(dev_info_t *dip) 2717c478bd9Sstevel@tonic-gate { 2727c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate return (intr_p ? intr_p->devi_msix_p : NULL); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate void 2787c478bd9Sstevel@tonic-gate i_ddi_set_msix(dev_info_t *dip, ddi_intr_msix_t *msix_p) 2797c478bd9Sstevel@tonic-gate { 2807c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate if (intr_p) 2837c478bd9Sstevel@tonic-gate intr_p->devi_msix_p = msix_p; 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate 286*5febcb4aSScott Carter, SD IOSW ddi_intr_handle_t 2877c478bd9Sstevel@tonic-gate i_ddi_get_intr_handle(dev_info_t *dip, int inum) 2887c478bd9Sstevel@tonic-gate { 2897c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate if (intr_p == NULL) 2927c478bd9Sstevel@tonic-gate return (NULL); 2937c478bd9Sstevel@tonic-gate 294e821bd34Sanish /* 295e821bd34Sanish * Changed this to a check and return NULL if an invalid inum 296e821bd34Sanish * is passed to retrieve a handle 297e821bd34Sanish */ 298e821bd34Sanish if ((inum < 0) || (inum >= intr_p->devi_intr_sup_nintrs)) 299e821bd34Sanish return (NULL); 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate return ((intr_p->devi_intr_handle_p) ? 3027c478bd9Sstevel@tonic-gate intr_p->devi_intr_handle_p[inum] : NULL); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate void 306*5febcb4aSScott Carter, SD IOSW i_ddi_set_intr_handle(dev_info_t *dip, int inum, ddi_intr_handle_t intr_hdl) 3077c478bd9Sstevel@tonic-gate { 3087c478bd9Sstevel@tonic-gate devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate if (intr_p == NULL) 3117c478bd9Sstevel@tonic-gate return; 3127c478bd9Sstevel@tonic-gate 313e821bd34Sanish /* 314e821bd34Sanish * Changed this to a check and return if an invalid inum 315e821bd34Sanish * is passed to set a handle 316e821bd34Sanish */ 317e821bd34Sanish if ((inum < 0) || (inum >= intr_p->devi_intr_sup_nintrs)) 318e821bd34Sanish return; 3197c478bd9Sstevel@tonic-gate 320*5febcb4aSScott Carter, SD IOSW if (intr_hdl && (intr_p->devi_intr_handle_p == NULL)) { 3217c478bd9Sstevel@tonic-gate /* nintrs could be zero; so check for it first */ 3227c478bd9Sstevel@tonic-gate if (intr_p->devi_intr_sup_nintrs) 3237c478bd9Sstevel@tonic-gate intr_p->devi_intr_handle_p = kmem_zalloc( 3247c478bd9Sstevel@tonic-gate sizeof (ddi_intr_handle_t) * 3257c478bd9Sstevel@tonic-gate intr_p->devi_intr_sup_nintrs, KM_SLEEP); 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate 328a195726fSgovinda if (intr_p->devi_intr_handle_p) 329*5febcb4aSScott Carter, SD IOSW intr_p->devi_intr_handle_p[inum] = intr_hdl; 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate /* 3337c478bd9Sstevel@tonic-gate * The "ddi-intr-weight" property contains the weight of each interrupt 3347c478bd9Sstevel@tonic-gate * associated with a dev_info node. For devices with multiple interrupts per 3357c478bd9Sstevel@tonic-gate * dev_info node, the total load of the device is "devi_intr_weight * nintr", 3367c478bd9Sstevel@tonic-gate * possibly spread out over multiple CPUs. 3377c478bd9Sstevel@tonic-gate * 3387c478bd9Sstevel@tonic-gate * Maintaining this as a property permits possible tweaking in the product 3397c478bd9Sstevel@tonic-gate * in response to customer problems via driver.conf property definitions at 3407c478bd9Sstevel@tonic-gate * the driver or the instance level. This does not mean that "ddi-intr_weight" 3417c478bd9Sstevel@tonic-gate * is a formal or committed interface. 3427c478bd9Sstevel@tonic-gate */ 3437c478bd9Sstevel@tonic-gate int32_t 3447c478bd9Sstevel@tonic-gate i_ddi_get_intr_weight(dev_info_t *dip) 3457c478bd9Sstevel@tonic-gate { 3467c478bd9Sstevel@tonic-gate int32_t weight; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate weight = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 3497c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, "ddi-intr-weight", -1); 3507c478bd9Sstevel@tonic-gate if (weight < -1) 3517c478bd9Sstevel@tonic-gate weight = -1; /* undefined */ 3527c478bd9Sstevel@tonic-gate return (weight); 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate int32_t 3567c478bd9Sstevel@tonic-gate i_ddi_set_intr_weight(dev_info_t *dip, int32_t weight) 3577c478bd9Sstevel@tonic-gate { 3587c478bd9Sstevel@tonic-gate int32_t oweight; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate oweight = i_ddi_get_intr_weight(dip); 3617c478bd9Sstevel@tonic-gate if ((weight > 0) && (oweight != weight)) 3627c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, dip, 3637c478bd9Sstevel@tonic-gate "ddi-intr-weight", weight); 3647c478bd9Sstevel@tonic-gate return (oweight); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate /* 3687c478bd9Sstevel@tonic-gate * Old DDI interrupt framework 3697c478bd9Sstevel@tonic-gate * 3707c478bd9Sstevel@tonic-gate * NOTE: 3717c478bd9Sstevel@tonic-gate * The following 4 busops entry points are obsoleted with version 3727c478bd9Sstevel@tonic-gate * 9 or greater. Use i_ddi_intr_op interface in place of these 3737c478bd9Sstevel@tonic-gate * obsolete interfaces. 3747c478bd9Sstevel@tonic-gate * 3757c478bd9Sstevel@tonic-gate * Remove these busops entry points and all related data structures 3767c478bd9Sstevel@tonic-gate * in future major/minor solaris release. 3777c478bd9Sstevel@tonic-gate */ 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3807c478bd9Sstevel@tonic-gate ddi_intrspec_t 3817c478bd9Sstevel@tonic-gate i_ddi_get_intrspec(dev_info_t *dip, dev_info_t *rdip, uint_t inumber) 3827c478bd9Sstevel@tonic-gate { 3837c478bd9Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(dip); 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 3867c478bd9Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 387a195726fSgovinda ddi_driver_name(rdip), ddi_get_instance(rdip), 388a195726fSgovinda ddi_driver_name(pdip), ddi_get_instance(pdip)); 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate return (NULL); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3947c478bd9Sstevel@tonic-gate int 3957c478bd9Sstevel@tonic-gate i_ddi_add_intrspec(dev_info_t *dip, dev_info_t *rdip, ddi_intrspec_t intrspec, 3967c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t *iblock_cookiep, 3977c478bd9Sstevel@tonic-gate ddi_idevice_cookie_t *idevice_cookiep, 3987c478bd9Sstevel@tonic-gate uint_t (*int_handler)(caddr_t int_handler_arg), 3997c478bd9Sstevel@tonic-gate caddr_t int_handler_arg, int kind) 4007c478bd9Sstevel@tonic-gate { 4017c478bd9Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(dip); 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 4047c478bd9Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 405a195726fSgovinda ddi_driver_name(rdip), ddi_get_instance(rdip), 406a195726fSgovinda ddi_driver_name(pdip), ddi_get_instance(pdip)); 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate return (DDI_ENOTSUP); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4127c478bd9Sstevel@tonic-gate void 4137c478bd9Sstevel@tonic-gate i_ddi_remove_intrspec(dev_info_t *dip, dev_info_t *rdip, 4147c478bd9Sstevel@tonic-gate ddi_intrspec_t intrspec, ddi_iblock_cookie_t iblock_cookie) 4157c478bd9Sstevel@tonic-gate { 4167c478bd9Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(dip); 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 4197c478bd9Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 420a195726fSgovinda ddi_driver_name(rdip), ddi_get_instance(rdip), 421a195726fSgovinda ddi_driver_name(pdip), ddi_get_instance(pdip)); 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4257c478bd9Sstevel@tonic-gate int 4267c478bd9Sstevel@tonic-gate i_ddi_intr_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_ctlop_t op, 4277c478bd9Sstevel@tonic-gate void *arg, void *val) 4287c478bd9Sstevel@tonic-gate { 4297c478bd9Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(dip); 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 4327c478bd9Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 433a195726fSgovinda ddi_driver_name(rdip), ddi_get_instance(rdip), 434a195726fSgovinda ddi_driver_name(pdip), ddi_get_instance(pdip)); 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate return (DDI_ENOTSUP); 4377c478bd9Sstevel@tonic-gate } 438d12abe7cSanish 439d12abe7cSanish #if defined(__i386) || defined(__amd64) 440d12abe7cSanish ddi_acc_handle_t 441d12abe7cSanish i_ddi_get_pci_config_handle(dev_info_t *dip) 442d12abe7cSanish { 443d12abe7cSanish devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 444d12abe7cSanish 445d12abe7cSanish return (intr_p ? intr_p->devi_cfg_handle : NULL); 446d12abe7cSanish } 447d12abe7cSanish 448d12abe7cSanish void 449d12abe7cSanish i_ddi_set_pci_config_handle(dev_info_t *dip, ddi_acc_handle_t handle) 450d12abe7cSanish { 451d12abe7cSanish devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 452d12abe7cSanish 453d12abe7cSanish if (intr_p) 454d12abe7cSanish intr_p->devi_cfg_handle = handle; 455d12abe7cSanish } 456d12abe7cSanish 457d12abe7cSanish 458d12abe7cSanish int 459d12abe7cSanish i_ddi_get_msi_msix_cap_ptr(dev_info_t *dip) 460d12abe7cSanish { 461d12abe7cSanish devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 462d12abe7cSanish 463d12abe7cSanish return (intr_p ? intr_p->devi_cap_ptr : 0); 464d12abe7cSanish } 465d12abe7cSanish 466d12abe7cSanish void 467d12abe7cSanish i_ddi_set_msi_msix_cap_ptr(dev_info_t *dip, int cap_ptr) 468d12abe7cSanish { 469d12abe7cSanish devinfo_intr_t *intr_p = DEVI(dip)->devi_intr_p; 470d12abe7cSanish 471d12abe7cSanish if (intr_p) 472d12abe7cSanish intr_p->devi_cap_ptr = cap_ptr; 473d12abe7cSanish } 474d12abe7cSanish #endif 475ef643aefSegillett 476ef643aefSegillett /* ARGSUSED */ 477ef643aefSegillett uint_t 478ef643aefSegillett i_ddi_get_msix_alloc_limit(dev_info_t *dip) 479ef643aefSegillett { 480ef643aefSegillett uint_t msix_alloc_limit = ddi_msix_alloc_limit; 481ef643aefSegillett 482ef643aefSegillett #if defined(__sparc) 483ef643aefSegillett if (ddi_prop_exists(DDI_DEV_T_ANY, dip, DDI_PROP_NOTPROM | 484ef643aefSegillett DDI_PROP_DONTPASS, "#msix-request")) { 485ef643aefSegillett msix_alloc_limit = MAX(DDI_MAX_MSIX_ALLOC, 486ef643aefSegillett ddi_msix_alloc_limit); 487ef643aefSegillett } 488ef643aefSegillett #endif 489ef643aefSegillett 490ef643aefSegillett return (msix_alloc_limit); 491ef643aefSegillett } 492