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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * Autovectored Interrupt Configuration and Deconfiguration 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/cmn_err.h> 350Sstevel@tonic-gate #include <sys/trap.h> 360Sstevel@tonic-gate #include <sys/t_lock.h> 370Sstevel@tonic-gate #include <sys/avintr.h> 380Sstevel@tonic-gate #include <sys/kmem.h> 390Sstevel@tonic-gate #include <sys/machlock.h> 400Sstevel@tonic-gate #include <sys/systm.h> 410Sstevel@tonic-gate #include <sys/machsystm.h> 420Sstevel@tonic-gate #include <sys/sunddi.h> 430Sstevel@tonic-gate #include <sys/x_call.h> 440Sstevel@tonic-gate #include <sys/cpuvar.h> 450Sstevel@tonic-gate #include <sys/atomic.h> 460Sstevel@tonic-gate #include <sys/smp_impldefs.h> 470Sstevel@tonic-gate #include <sys/sdt.h> 480Sstevel@tonic-gate #include <sys/stack.h> 490Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 500Sstevel@tonic-gate 51*999Slq150181 typedef struct av_softinfo { 52*999Slq150181 cpuset_t av_pending; /* pending bitmasks */ 53*999Slq150181 } av_softinfo_t; 54*999Slq150181 55*999Slq150181 static void insert_av(void *intr_id, struct av_head *vectp, avfunc f, 56916Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, int pri_level, 57916Sschwartz dev_info_t *dip); 580Sstevel@tonic-gate static void remove_av(void *intr_id, struct av_head *vectp, avfunc f, 590Sstevel@tonic-gate int pri_level, int vect); 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * Arrange for a driver to be called when a particular 630Sstevel@tonic-gate * auto-vectored interrupt occurs. 640Sstevel@tonic-gate * NOTE: if a device can generate interrupts on more than 650Sstevel@tonic-gate * one level, or if a driver services devices that interrupt 660Sstevel@tonic-gate * on more than one level, then the driver should install 670Sstevel@tonic-gate * itself on each of those levels. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate static char badsoft[] = 700Sstevel@tonic-gate "add_avintr: bad soft interrupt level %d for driver '%s'\n"; 710Sstevel@tonic-gate static char multilevel[] = 720Sstevel@tonic-gate "!IRQ%d is being shared by drivers with different interrupt levels.\n" 730Sstevel@tonic-gate "This may result in reduced system performance."; 740Sstevel@tonic-gate static char multilevel2[] = 750Sstevel@tonic-gate "Cannot register interrupt for '%s' device at IPL %d because it\n" 760Sstevel@tonic-gate "conflicts with another device using the same vector %d with an IPL\n" 770Sstevel@tonic-gate "of %d. Reconfigure the conflicting devices to use different vectors."; 780Sstevel@tonic-gate 790Sstevel@tonic-gate #define MAX_VECT 256 800Sstevel@tonic-gate struct autovec *nmivect = NULL; 810Sstevel@tonic-gate struct av_head autovect[MAX_VECT]; 820Sstevel@tonic-gate struct av_head softvect[LOCK_LEVEL + 1]; 830Sstevel@tonic-gate kmutex_t av_lock; 840Sstevel@tonic-gate ddi_softint_hdl_impl_t softlevel1_hdl = 85*999Slq150181 {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}; 86*999Slq150181 870Sstevel@tonic-gate 88*999Slq150181 /* 89*999Slq150181 * clear/check softint pending flag corresponding for 90*999Slq150181 * the current CPU 91*999Slq150181 */ 920Sstevel@tonic-gate void 93*999Slq150181 av_clear_softint_pending(av_softinfo_t *infop) 94*999Slq150181 { 95*999Slq150181 CPUSET_ATOMIC_DEL(infop->av_pending, CPU->cpu_seqid); 96*999Slq150181 } 97*999Slq150181 98*999Slq150181 boolean_t 99*999Slq150181 av_check_softint_pending(av_softinfo_t *infop, boolean_t check_all) 1000Sstevel@tonic-gate { 101*999Slq150181 if (check_all) 102*999Slq150181 return (!CPUSET_ISNULL(infop->av_pending)); 103*999Slq150181 else 104*999Slq150181 return (CPU_IN_SET(infop->av_pending, CPU->cpu_seqid) != 0); 105*999Slq150181 } 106*999Slq150181 107*999Slq150181 /* 108*999Slq150181 * It first sets our av softint pending bit for the current CPU, 109*999Slq150181 * then it sets the CPU softint pending bit for pri. 110*999Slq150181 */ 111*999Slq150181 void 112*999Slq150181 av_set_softint_pending(int pri, av_softinfo_t *infop) 113*999Slq150181 { 114*999Slq150181 CPUSET_ATOMIC_ADD(infop->av_pending, CPU->cpu_seqid); 115*999Slq150181 1160Sstevel@tonic-gate atomic_or_32((uint32_t *)&CPU->cpu_softinfo.st_pending, 1 << pri); 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /* 1200Sstevel@tonic-gate * register nmi interrupt routine. The first arg is used only to order 1210Sstevel@tonic-gate * various nmi interrupt service routines in the chain. Higher lvls will 1220Sstevel@tonic-gate * be called first 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate int 1250Sstevel@tonic-gate add_nmintr(int lvl, avfunc nmintr, char *name, caddr_t arg) 1260Sstevel@tonic-gate { 1270Sstevel@tonic-gate struct autovec *mem; 1280Sstevel@tonic-gate struct autovec *p, *prev = NULL; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate if (nmintr == NULL) { 1310Sstevel@tonic-gate printf("Attempt to add null vect for %s on nmi\n", name); 1320Sstevel@tonic-gate return (0); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 1370Sstevel@tonic-gate mem->av_vector = nmintr; 1380Sstevel@tonic-gate mem->av_intarg1 = arg; 1390Sstevel@tonic-gate mem->av_intarg2 = NULL; 1400Sstevel@tonic-gate mem->av_intr_id = NULL; 1410Sstevel@tonic-gate mem->av_prilevel = lvl; 142191Sahl mem->av_dip = NULL; 1430Sstevel@tonic-gate mem->av_link = NULL; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate mutex_enter(&av_lock); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate if (!nmivect) { 1480Sstevel@tonic-gate nmivect = mem; 1490Sstevel@tonic-gate mutex_exit(&av_lock); 1500Sstevel@tonic-gate return (1); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate /* find where it goes in list */ 1530Sstevel@tonic-gate for (p = nmivect; p != NULL; p = p->av_link) { 1540Sstevel@tonic-gate if (p->av_vector == nmintr && p->av_intarg1 == arg) { 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * already in list 1570Sstevel@tonic-gate * So? Somebody added the same interrupt twice. 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate cmn_err(CE_WARN, "Driver already registered '%s'", 1600Sstevel@tonic-gate name); 1610Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 1620Sstevel@tonic-gate mutex_exit(&av_lock); 1630Sstevel@tonic-gate return (0); 1640Sstevel@tonic-gate } 1650Sstevel@tonic-gate if (p->av_prilevel < lvl) { 1660Sstevel@tonic-gate if (p == nmivect) { /* it's at head of list */ 1670Sstevel@tonic-gate mem->av_link = p; 1680Sstevel@tonic-gate nmivect = mem; 1690Sstevel@tonic-gate } else { 1700Sstevel@tonic-gate mem->av_link = p; 1710Sstevel@tonic-gate prev->av_link = mem; 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate mutex_exit(&av_lock); 1740Sstevel@tonic-gate return (1); 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate prev = p; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate /* didn't find it, add it to the end */ 1800Sstevel@tonic-gate prev->av_link = mem; 1810Sstevel@tonic-gate mutex_exit(&av_lock); 1820Sstevel@tonic-gate return (1); 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate } 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate /* 1870Sstevel@tonic-gate * register a hardware interrupt handler. 1880Sstevel@tonic-gate */ 1890Sstevel@tonic-gate int 1900Sstevel@tonic-gate add_avintr(void *intr_id, int lvl, avfunc xxintr, char *name, int vect, 191916Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, dev_info_t *dip) 1920Sstevel@tonic-gate { 1930Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 1940Sstevel@tonic-gate avfunc f; 1950Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 1960Sstevel@tonic-gate ushort_t hi_pri; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate if ((f = xxintr) == NULL) { 1990Sstevel@tonic-gate printf("Attempt to add null vect for %s on vector %d\n", 2000Sstevel@tonic-gate name, vect); 2010Sstevel@tonic-gate return (0); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate vectindex = vect % MAX_VECT; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate vecp = &autovect[vectindex]; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * "hi_pri == 0" implies all entries on list are "unused", 2100Sstevel@tonic-gate * which means that it's OK to just insert this one. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate hi_pri = vecp->avh_hi_pri; 2130Sstevel@tonic-gate if (vecp->avh_link && (hi_pri != 0)) { 2140Sstevel@tonic-gate if (((hi_pri > LOCK_LEVEL) && (lvl < LOCK_LEVEL)) || 2150Sstevel@tonic-gate ((hi_pri < LOCK_LEVEL) && (lvl > LOCK_LEVEL))) { 2160Sstevel@tonic-gate cmn_err(CE_WARN, multilevel2, name, lvl, vect, 2170Sstevel@tonic-gate hi_pri); 2180Sstevel@tonic-gate return (0); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate if ((vecp->avh_lo_pri != lvl) || (hi_pri != lvl)) 2210Sstevel@tonic-gate cmn_err(CE_NOTE, multilevel, vect); 2220Sstevel@tonic-gate } 2230Sstevel@tonic-gate 224*999Slq150181 insert_av(intr_id, vecp, f, arg1, arg2, ticksp, lvl, dip); 2250Sstevel@tonic-gate s = splhi(); 2260Sstevel@tonic-gate /* 2270Sstevel@tonic-gate * do what ever machine specific things are necessary 2280Sstevel@tonic-gate * to set priority level (e.g. set picmasks) 2290Sstevel@tonic-gate */ 2300Sstevel@tonic-gate mutex_enter(&av_lock); 2310Sstevel@tonic-gate (*addspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 2320Sstevel@tonic-gate mutex_exit(&av_lock); 2330Sstevel@tonic-gate splx(s); 2340Sstevel@tonic-gate return (1); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate } 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate void 2390Sstevel@tonic-gate update_avsoftintr_args(void *intr_id, int lvl, caddr_t arg2) 2400Sstevel@tonic-gate { 2410Sstevel@tonic-gate struct autovec *p; 2420Sstevel@tonic-gate struct autovec *target = NULL; 2430Sstevel@tonic-gate struct av_head *vectp = (struct av_head *)&softvect[lvl]; 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate for (p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 2460Sstevel@tonic-gate if (p->av_intr_id == intr_id) { 2470Sstevel@tonic-gate target = p; 2480Sstevel@tonic-gate break; 2490Sstevel@tonic-gate } 2500Sstevel@tonic-gate } 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate if (target == NULL) 2530Sstevel@tonic-gate return; 2540Sstevel@tonic-gate target->av_intarg2 = arg2; 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* 2580Sstevel@tonic-gate * Register a software interrupt handler 2590Sstevel@tonic-gate */ 2600Sstevel@tonic-gate int 2610Sstevel@tonic-gate add_avsoftintr(void *intr_id, int lvl, avfunc xxintr, char *name, 2620Sstevel@tonic-gate caddr_t arg1, caddr_t arg2) 2630Sstevel@tonic-gate { 2640Sstevel@tonic-gate int slvl; 265*999Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) 2680Sstevel@tonic-gate return (add_avintr(intr_id, lvl, xxintr, 269916Sschwartz name, slvl, arg1, arg2, NULL, NULL)); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate if (intr_id == NULL) { 2720Sstevel@tonic-gate printf("Attempt to add null intr_id for %s on level %d\n", 2730Sstevel@tonic-gate name, lvl); 2740Sstevel@tonic-gate return (0); 2750Sstevel@tonic-gate } 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate if (xxintr == NULL) { 2780Sstevel@tonic-gate printf("Attempt to add null handler for %s on level %d\n", 2790Sstevel@tonic-gate name, lvl); 2800Sstevel@tonic-gate return (0); 2810Sstevel@tonic-gate } 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate if (lvl <= 0 || lvl > LOCK_LEVEL) { 2840Sstevel@tonic-gate printf(badsoft, lvl, name); 2850Sstevel@tonic-gate return (0); 2860Sstevel@tonic-gate } 287*999Slq150181 288*999Slq150181 if (hdlp->ih_pending == NULL) { 289*999Slq150181 hdlp->ih_pending = 290*999Slq150181 kmem_zalloc(sizeof (av_softinfo_t), KM_SLEEP); 2910Sstevel@tonic-gate } 292*999Slq150181 293*999Slq150181 insert_av(intr_id, &softvect[lvl], xxintr, arg1, arg2, NULL, lvl, NULL); 294*999Slq150181 2950Sstevel@tonic-gate return (1); 2960Sstevel@tonic-gate } 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate /* insert an interrupt vector into chain */ 299*999Slq150181 static void 3000Sstevel@tonic-gate insert_av(void *intr_id, struct av_head *vectp, avfunc f, caddr_t arg1, 301916Sschwartz caddr_t arg2, uint64_t *ticksp, int pri_level, dev_info_t *dip) 3020Sstevel@tonic-gate { 3030Sstevel@tonic-gate /* 3040Sstevel@tonic-gate * Protect rewrites of the list 3050Sstevel@tonic-gate */ 3060Sstevel@tonic-gate struct autovec *p, *mem; 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 3090Sstevel@tonic-gate mem->av_vector = f; 3100Sstevel@tonic-gate mem->av_intarg1 = arg1; 3110Sstevel@tonic-gate mem->av_intarg2 = arg2; 312916Sschwartz mem->av_ticksp = ticksp; 3130Sstevel@tonic-gate mem->av_intr_id = intr_id; 3140Sstevel@tonic-gate mem->av_prilevel = pri_level; 3150Sstevel@tonic-gate mem->av_dip = dip; 3160Sstevel@tonic-gate mem->av_link = NULL; 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate mutex_enter(&av_lock); 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate if (vectp->avh_link == NULL) { /* Nothing on list - put it at head */ 3210Sstevel@tonic-gate vectp->avh_link = mem; 3220Sstevel@tonic-gate vectp->avh_hi_pri = vectp->avh_lo_pri = (ushort_t)pri_level; 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate mutex_exit(&av_lock); 325*999Slq150181 return; 3260Sstevel@tonic-gate } 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate /* find where it goes in list */ 3290Sstevel@tonic-gate for (p = vectp->avh_link; p != NULL; p = p->av_link) { 3300Sstevel@tonic-gate if (p->av_vector == NULL) { /* freed struct available */ 3310Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 3320Sstevel@tonic-gate p->av_intarg1 = arg1; 3330Sstevel@tonic-gate p->av_intarg2 = arg2; 334916Sschwartz p->av_ticksp = ticksp; 3350Sstevel@tonic-gate p->av_intr_id = intr_id; 3360Sstevel@tonic-gate p->av_prilevel = pri_level; 337191Sahl p->av_dip = dip; 3380Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3390Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3420Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate p->av_vector = f; 3450Sstevel@tonic-gate mutex_exit(&av_lock); 346*999Slq150181 return; 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate /* insert new intpt at beginning of chain */ 3500Sstevel@tonic-gate mem->av_link = vectp->avh_link; 3510Sstevel@tonic-gate vectp->avh_link = mem; 3520Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3530Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3560Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3570Sstevel@tonic-gate } 3580Sstevel@tonic-gate mutex_exit(&av_lock); 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 361*999Slq150181 static int 362*999Slq150181 av_rem_softintr(void *intr_id, int lvl, avfunc xxintr, boolean_t rem_softinfo) 3630Sstevel@tonic-gate { 3640Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 3650Sstevel@tonic-gate int slvl; 366*999Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 367*999Slq150181 av_softinfo_t *infop = (av_softinfo_t *)hdlp->ih_pending; 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate if (xxintr == NULL) 3700Sstevel@tonic-gate return (0); 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) { 3730Sstevel@tonic-gate rem_avintr(intr_id, lvl, xxintr, slvl); 3740Sstevel@tonic-gate return (1); 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate if (lvl <= 0 && lvl >= LOCK_LEVEL) { 3780Sstevel@tonic-gate return (0); 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate vecp = &softvect[lvl]; 3810Sstevel@tonic-gate remove_av(intr_id, vecp, xxintr, lvl, 0); 3820Sstevel@tonic-gate 383*999Slq150181 if (rem_softinfo) { 384*999Slq150181 kmem_free(infop, sizeof (av_softinfo_t)); 385*999Slq150181 hdlp->ih_pending = NULL; 386*999Slq150181 } 387*999Slq150181 3880Sstevel@tonic-gate return (1); 3890Sstevel@tonic-gate } 3900Sstevel@tonic-gate 391*999Slq150181 int 392*999Slq150181 av_softint_movepri(void *intr_id, int old_lvl) 393*999Slq150181 { 394*999Slq150181 int ret; 395*999Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 396*999Slq150181 397*999Slq150181 ret = add_avsoftintr(intr_id, hdlp->ih_pri, hdlp->ih_cb_func, 398*999Slq150181 DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 399*999Slq150181 400*999Slq150181 if (ret) { 401*999Slq150181 (void) av_rem_softintr(intr_id, old_lvl, hdlp->ih_cb_func, 402*999Slq150181 B_FALSE); 403*999Slq150181 } 404*999Slq150181 405*999Slq150181 return (ret); 406*999Slq150181 } 407*999Slq150181 408*999Slq150181 /* 409*999Slq150181 * Remove a driver from the autovector list. 410*999Slq150181 */ 411*999Slq150181 int 412*999Slq150181 rem_avsoftintr(void *intr_id, int lvl, avfunc xxintr) 413*999Slq150181 { 414*999Slq150181 return (av_rem_softintr(intr_id, lvl, xxintr, B_TRUE)); 415*999Slq150181 } 416*999Slq150181 4170Sstevel@tonic-gate void 4180Sstevel@tonic-gate rem_avintr(void *intr_id, int lvl, avfunc xxintr, int vect) 4190Sstevel@tonic-gate { 4200Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 4210Sstevel@tonic-gate avfunc f; 4220Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate if ((f = xxintr) == NULL) 4250Sstevel@tonic-gate return; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate vectindex = vect % MAX_VECT; 4280Sstevel@tonic-gate vecp = &autovect[vectindex]; 4290Sstevel@tonic-gate remove_av(intr_id, vecp, f, lvl, vect); 4300Sstevel@tonic-gate s = splhi(); 4310Sstevel@tonic-gate mutex_enter(&av_lock); 4320Sstevel@tonic-gate (*delspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 4330Sstevel@tonic-gate mutex_exit(&av_lock); 4340Sstevel@tonic-gate splx(s); 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /* 4390Sstevel@tonic-gate * After having made a change to an autovector list, wait until we have 4400Sstevel@tonic-gate * seen each cpu not executing an interrupt at that level--so we know our 4410Sstevel@tonic-gate * change has taken effect completely (no old state in registers, etc). 4420Sstevel@tonic-gate */ 4430Sstevel@tonic-gate void 4440Sstevel@tonic-gate wait_till_seen(int ipl) 4450Sstevel@tonic-gate { 4460Sstevel@tonic-gate int cpu_in_chain, cix; 4470Sstevel@tonic-gate struct cpu *cpup; 4480Sstevel@tonic-gate cpuset_t cpus_to_check; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate CPUSET_ALL(cpus_to_check); 4510Sstevel@tonic-gate do { 4520Sstevel@tonic-gate cpu_in_chain = 0; 4530Sstevel@tonic-gate for (cix = 0; cix < NCPU; cix++) { 4540Sstevel@tonic-gate cpup = cpu[cix]; 4550Sstevel@tonic-gate if (cpup != NULL && CPU_IN_SET(cpus_to_check, cix)) { 4560Sstevel@tonic-gate if (intr_active(cpup, ipl)) { 4570Sstevel@tonic-gate cpu_in_chain = 1; 4580Sstevel@tonic-gate } else { 4590Sstevel@tonic-gate CPUSET_DEL(cpus_to_check, cix); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate } while (cpu_in_chain); 4640Sstevel@tonic-gate } 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* remove an interrupt vector from the chain */ 4670Sstevel@tonic-gate static void 4680Sstevel@tonic-gate remove_av(void *intr_id, struct av_head *vectp, avfunc f, int pri_level, 4690Sstevel@tonic-gate int vect) 4700Sstevel@tonic-gate { 4710Sstevel@tonic-gate struct autovec *endp, *p, *target; 4720Sstevel@tonic-gate int lo_pri, hi_pri; 4730Sstevel@tonic-gate int ipl; 4740Sstevel@tonic-gate /* 4750Sstevel@tonic-gate * Protect rewrites of the list 4760Sstevel@tonic-gate */ 4770Sstevel@tonic-gate target = NULL; 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate mutex_enter(&av_lock); 4800Sstevel@tonic-gate ipl = pri_level; 4810Sstevel@tonic-gate lo_pri = MAXIPL; 4820Sstevel@tonic-gate hi_pri = 0; 4830Sstevel@tonic-gate for (endp = p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 4840Sstevel@tonic-gate endp = p; 4850Sstevel@tonic-gate if ((p->av_vector == f) && (p->av_intr_id == intr_id)) { 4860Sstevel@tonic-gate /* found the handler */ 4870Sstevel@tonic-gate target = p; 4880Sstevel@tonic-gate continue; 4890Sstevel@tonic-gate } 4900Sstevel@tonic-gate if (p->av_prilevel > hi_pri) 4910Sstevel@tonic-gate hi_pri = p->av_prilevel; 4920Sstevel@tonic-gate if (p->av_prilevel < lo_pri) 4930Sstevel@tonic-gate lo_pri = p->av_prilevel; 4940Sstevel@tonic-gate } 4950Sstevel@tonic-gate if (ipl < hi_pri) 4960Sstevel@tonic-gate ipl = hi_pri; 4970Sstevel@tonic-gate if (target == NULL) { /* not found */ 4980Sstevel@tonic-gate printf("Couldn't remove function %p at %d, %d\n", 4990Sstevel@tonic-gate (void *)f, vect, pri_level); 5000Sstevel@tonic-gate mutex_exit(&av_lock); 5010Sstevel@tonic-gate return; 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate target->av_vector = NULL; 505916Sschwartz target->av_ticksp = NULL; 5060Sstevel@tonic-gate wait_till_seen(ipl); 5070Sstevel@tonic-gate if (endp != target) { /* vector to be removed is not last in chain */ 508191Sahl target->av_vector = endp->av_vector; 5090Sstevel@tonic-gate target->av_intarg1 = endp->av_intarg1; 5100Sstevel@tonic-gate target->av_intarg2 = endp->av_intarg2; 511916Sschwartz target->av_ticksp = endp->av_ticksp; 512191Sahl target->av_intr_id = endp->av_intr_id; 5130Sstevel@tonic-gate target->av_prilevel = endp->av_prilevel; 514191Sahl target->av_dip = endp->av_dip; 5150Sstevel@tonic-gate /* 5160Sstevel@tonic-gate * We have a hole here where the routine corresponding to 5170Sstevel@tonic-gate * endp may not get called. Do a wait_till_seen to take care 5180Sstevel@tonic-gate * of this. 5190Sstevel@tonic-gate */ 5200Sstevel@tonic-gate wait_till_seen(ipl); 5210Sstevel@tonic-gate endp->av_vector = NULL; 522916Sschwartz endp->av_ticksp = NULL; 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate if (lo_pri > hi_pri) { /* the chain is now empty */ 5260Sstevel@tonic-gate /* Leave the unused entries here for probable future use */ 5270Sstevel@tonic-gate vectp->avh_lo_pri = MAXIPL; 5280Sstevel@tonic-gate vectp->avh_hi_pri = 0; 5290Sstevel@tonic-gate } else { 5300Sstevel@tonic-gate if ((int)vectp->avh_lo_pri < lo_pri) 5310Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)lo_pri; 5320Sstevel@tonic-gate if ((int)vectp->avh_hi_pri > hi_pri) 5330Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)hi_pri; 5340Sstevel@tonic-gate } 5350Sstevel@tonic-gate mutex_exit(&av_lock); 5360Sstevel@tonic-gate wait_till_seen(ipl); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate /* 5400Sstevel@tonic-gate * Trigger a soft interrupt. 5410Sstevel@tonic-gate */ 5420Sstevel@tonic-gate void 5430Sstevel@tonic-gate siron(void) 5440Sstevel@tonic-gate { 545*999Slq150181 (*setsoftint)(1, softlevel1_hdl.ih_pending); 5460Sstevel@tonic-gate } 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate /* 5490Sstevel@tonic-gate * Walk the autovector table for this vector, invoking each 5500Sstevel@tonic-gate * interrupt handler as we go. 5510Sstevel@tonic-gate */ 552916Sschwartz 553916Sschwartz extern uint64_t intr_get_time(void); 554916Sschwartz 5550Sstevel@tonic-gate void 5560Sstevel@tonic-gate av_dispatch_autovect(uint_t vec) 5570Sstevel@tonic-gate { 5580Sstevel@tonic-gate struct autovec *av; 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate while ((av = autovect[vec].avh_link) != NULL) { 5630Sstevel@tonic-gate uint_t numcalled = 0; 5640Sstevel@tonic-gate uint_t claimed = 0; 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate for (; av; av = av->av_link) { 5670Sstevel@tonic-gate uint_t r; 5680Sstevel@tonic-gate uint_t (*intr)() = av->av_vector; 5690Sstevel@tonic-gate caddr_t arg1 = av->av_intarg1; 5700Sstevel@tonic-gate caddr_t arg2 = av->av_intarg2; 5710Sstevel@tonic-gate dev_info_t *dip = av->av_dip; 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate numcalled++; 5740Sstevel@tonic-gate if (intr == NULL) 5750Sstevel@tonic-gate break; 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t *, dip, 5780Sstevel@tonic-gate void *, intr, caddr_t, arg1, caddr_t, arg2); 5790Sstevel@tonic-gate r = (*intr)(arg1, arg2); 5800Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t *, dip, 5810Sstevel@tonic-gate void *, intr, caddr_t, arg1, uint_t, r); 5820Sstevel@tonic-gate claimed |= r; 583916Sschwartz if (av->av_ticksp && av->av_prilevel <= LOCK_LEVEL) 584916Sschwartz atomic_add_64(av->av_ticksp, intr_get_time()); 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate /* 5880Sstevel@tonic-gate * If there's only one interrupt handler in the chain, 5890Sstevel@tonic-gate * or if no-one claimed the interrupt at all give up now. 5900Sstevel@tonic-gate */ 5910Sstevel@tonic-gate if (numcalled == 1 || claimed == 0) 5920Sstevel@tonic-gate break; 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate } 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate /* 5970Sstevel@tonic-gate * Call every soft interrupt handler we can find at this level once. 5980Sstevel@tonic-gate */ 5990Sstevel@tonic-gate void 6000Sstevel@tonic-gate av_dispatch_softvect(uint_t pil) 6010Sstevel@tonic-gate { 6020Sstevel@tonic-gate struct autovec *av; 6030Sstevel@tonic-gate ddi_softint_hdl_impl_t *hdlp; 6040Sstevel@tonic-gate uint_t (*intr)(); 6050Sstevel@tonic-gate caddr_t arg1; 6060Sstevel@tonic-gate caddr_t arg2; 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 6090Sstevel@tonic-gate ASSERT(pil >= 0 && pil <= PIL_MAX); 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate for (av = softvect[pil].avh_link; av; av = av->av_link) { 6120Sstevel@tonic-gate if ((intr = av->av_vector) == NULL) 6130Sstevel@tonic-gate break; 6140Sstevel@tonic-gate arg1 = av->av_intarg1; 6150Sstevel@tonic-gate arg2 = av->av_intarg2; 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate hdlp = (ddi_softint_hdl_impl_t *)av->av_intr_id; 6180Sstevel@tonic-gate ASSERT(hdlp); 6190Sstevel@tonic-gate 620*999Slq150181 /* 621*999Slq150181 * Each cpu has its own pending bit in hdlp->ih_pending, 622*999Slq150181 * here av_check/clear_softint_pending is just checking 623*999Slq150181 * and clearing the pending bit for the current cpu, who 624*999Slq150181 * has just triggered a softint. 625*999Slq150181 */ 626*999Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) { 627*999Slq150181 av_clear_softint_pending(hdlp->ih_pending); 6280Sstevel@tonic-gate (void) (*intr)(arg1, arg2); 6290Sstevel@tonic-gate } 6300Sstevel@tonic-gate } 6310Sstevel@tonic-gate } 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate struct regs; 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate /* 6360Sstevel@tonic-gate * Call every NMI handler we know of once. 6370Sstevel@tonic-gate */ 6380Sstevel@tonic-gate void 6390Sstevel@tonic-gate av_dispatch_nmivect(struct regs *rp) 6400Sstevel@tonic-gate { 6410Sstevel@tonic-gate struct autovec *av; 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate for (av = nmivect; av; av = av->av_link) 6460Sstevel@tonic-gate (void) (av->av_vector)(av->av_intarg1, rp); 6470Sstevel@tonic-gate } 648