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 5*3446Smrj * Common Development and Distribution License (the "License"). 6*3446Smrj * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3446Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * Autovectored Interrupt Configuration and Deconfiguration 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/param.h> 330Sstevel@tonic-gate #include <sys/cmn_err.h> 340Sstevel@tonic-gate #include <sys/trap.h> 350Sstevel@tonic-gate #include <sys/t_lock.h> 360Sstevel@tonic-gate #include <sys/avintr.h> 370Sstevel@tonic-gate #include <sys/kmem.h> 380Sstevel@tonic-gate #include <sys/machlock.h> 390Sstevel@tonic-gate #include <sys/systm.h> 400Sstevel@tonic-gate #include <sys/machsystm.h> 410Sstevel@tonic-gate #include <sys/sunddi.h> 420Sstevel@tonic-gate #include <sys/x_call.h> 430Sstevel@tonic-gate #include <sys/cpuvar.h> 440Sstevel@tonic-gate #include <sys/atomic.h> 450Sstevel@tonic-gate #include <sys/smp_impldefs.h> 460Sstevel@tonic-gate #include <sys/sdt.h> 470Sstevel@tonic-gate #include <sys/stack.h> 480Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 490Sstevel@tonic-gate 50999Slq150181 typedef struct av_softinfo { 51999Slq150181 cpuset_t av_pending; /* pending bitmasks */ 52999Slq150181 } av_softinfo_t; 53999Slq150181 54999Slq150181 static void insert_av(void *intr_id, struct av_head *vectp, avfunc f, 55916Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, int pri_level, 56916Sschwartz dev_info_t *dip); 570Sstevel@tonic-gate static void remove_av(void *intr_id, struct av_head *vectp, avfunc f, 580Sstevel@tonic-gate int pri_level, int vect); 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * Arrange for a driver to be called when a particular 620Sstevel@tonic-gate * auto-vectored interrupt occurs. 630Sstevel@tonic-gate * NOTE: if a device can generate interrupts on more than 640Sstevel@tonic-gate * one level, or if a driver services devices that interrupt 650Sstevel@tonic-gate * on more than one level, then the driver should install 660Sstevel@tonic-gate * itself on each of those levels. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate static char badsoft[] = 690Sstevel@tonic-gate "add_avintr: bad soft interrupt level %d for driver '%s'\n"; 700Sstevel@tonic-gate static char multilevel[] = 710Sstevel@tonic-gate "!IRQ%d is being shared by drivers with different interrupt levels.\n" 720Sstevel@tonic-gate "This may result in reduced system performance."; 730Sstevel@tonic-gate static char multilevel2[] = 740Sstevel@tonic-gate "Cannot register interrupt for '%s' device at IPL %d because it\n" 750Sstevel@tonic-gate "conflicts with another device using the same vector %d with an IPL\n" 760Sstevel@tonic-gate "of %d. Reconfigure the conflicting devices to use different vectors."; 770Sstevel@tonic-gate 780Sstevel@tonic-gate #define MAX_VECT 256 790Sstevel@tonic-gate struct autovec *nmivect = NULL; 800Sstevel@tonic-gate struct av_head autovect[MAX_VECT]; 810Sstevel@tonic-gate struct av_head softvect[LOCK_LEVEL + 1]; 820Sstevel@tonic-gate kmutex_t av_lock; 830Sstevel@tonic-gate ddi_softint_hdl_impl_t softlevel1_hdl = 84999Slq150181 {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}; 85999Slq150181 860Sstevel@tonic-gate 87999Slq150181 /* 88999Slq150181 * clear/check softint pending flag corresponding for 89999Slq150181 * the current CPU 90999Slq150181 */ 910Sstevel@tonic-gate void 92999Slq150181 av_clear_softint_pending(av_softinfo_t *infop) 93999Slq150181 { 94999Slq150181 CPUSET_ATOMIC_DEL(infop->av_pending, CPU->cpu_seqid); 95999Slq150181 } 96999Slq150181 97999Slq150181 boolean_t 98999Slq150181 av_check_softint_pending(av_softinfo_t *infop, boolean_t check_all) 990Sstevel@tonic-gate { 100999Slq150181 if (check_all) 101999Slq150181 return (!CPUSET_ISNULL(infop->av_pending)); 102999Slq150181 else 103999Slq150181 return (CPU_IN_SET(infop->av_pending, CPU->cpu_seqid) != 0); 104999Slq150181 } 105999Slq150181 106999Slq150181 /* 107999Slq150181 * It first sets our av softint pending bit for the current CPU, 108999Slq150181 * then it sets the CPU softint pending bit for pri. 109999Slq150181 */ 110999Slq150181 void 111999Slq150181 av_set_softint_pending(int pri, av_softinfo_t *infop) 112999Slq150181 { 113999Slq150181 CPUSET_ATOMIC_ADD(infop->av_pending, CPU->cpu_seqid); 114999Slq150181 1150Sstevel@tonic-gate atomic_or_32((uint32_t *)&CPU->cpu_softinfo.st_pending, 1 << pri); 1160Sstevel@tonic-gate } 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * register nmi interrupt routine. The first arg is used only to order 1200Sstevel@tonic-gate * various nmi interrupt service routines in the chain. Higher lvls will 1210Sstevel@tonic-gate * be called first 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate int 1240Sstevel@tonic-gate add_nmintr(int lvl, avfunc nmintr, char *name, caddr_t arg) 1250Sstevel@tonic-gate { 1260Sstevel@tonic-gate struct autovec *mem; 1270Sstevel@tonic-gate struct autovec *p, *prev = NULL; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate if (nmintr == NULL) { 1300Sstevel@tonic-gate printf("Attempt to add null vect for %s on nmi\n", name); 1310Sstevel@tonic-gate return (0); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 1360Sstevel@tonic-gate mem->av_vector = nmintr; 1370Sstevel@tonic-gate mem->av_intarg1 = arg; 1380Sstevel@tonic-gate mem->av_intarg2 = NULL; 1390Sstevel@tonic-gate mem->av_intr_id = NULL; 1400Sstevel@tonic-gate mem->av_prilevel = lvl; 141191Sahl mem->av_dip = NULL; 1420Sstevel@tonic-gate mem->av_link = NULL; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate mutex_enter(&av_lock); 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate if (!nmivect) { 1470Sstevel@tonic-gate nmivect = mem; 1480Sstevel@tonic-gate mutex_exit(&av_lock); 1490Sstevel@tonic-gate return (1); 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate /* find where it goes in list */ 1520Sstevel@tonic-gate for (p = nmivect; p != NULL; p = p->av_link) { 1530Sstevel@tonic-gate if (p->av_vector == nmintr && p->av_intarg1 == arg) { 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * already in list 1560Sstevel@tonic-gate * So? Somebody added the same interrupt twice. 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate cmn_err(CE_WARN, "Driver already registered '%s'", 1590Sstevel@tonic-gate name); 1600Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 1610Sstevel@tonic-gate mutex_exit(&av_lock); 1620Sstevel@tonic-gate return (0); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate if (p->av_prilevel < lvl) { 1650Sstevel@tonic-gate if (p == nmivect) { /* it's at head of list */ 1660Sstevel@tonic-gate mem->av_link = p; 1670Sstevel@tonic-gate nmivect = mem; 1680Sstevel@tonic-gate } else { 1690Sstevel@tonic-gate mem->av_link = p; 1700Sstevel@tonic-gate prev->av_link = mem; 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate mutex_exit(&av_lock); 1730Sstevel@tonic-gate return (1); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate prev = p; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate /* didn't find it, add it to the end */ 1790Sstevel@tonic-gate prev->av_link = mem; 1800Sstevel@tonic-gate mutex_exit(&av_lock); 1810Sstevel@tonic-gate return (1); 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * register a hardware interrupt handler. 1870Sstevel@tonic-gate */ 1880Sstevel@tonic-gate int 1890Sstevel@tonic-gate add_avintr(void *intr_id, int lvl, avfunc xxintr, char *name, int vect, 190916Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, dev_info_t *dip) 1910Sstevel@tonic-gate { 1920Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 1930Sstevel@tonic-gate avfunc f; 1940Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 1950Sstevel@tonic-gate ushort_t hi_pri; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate if ((f = xxintr) == NULL) { 1980Sstevel@tonic-gate printf("Attempt to add null vect for %s on vector %d\n", 1990Sstevel@tonic-gate name, vect); 2000Sstevel@tonic-gate return (0); 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate vectindex = vect % MAX_VECT; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate vecp = &autovect[vectindex]; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * "hi_pri == 0" implies all entries on list are "unused", 2090Sstevel@tonic-gate * which means that it's OK to just insert this one. 2100Sstevel@tonic-gate */ 2110Sstevel@tonic-gate hi_pri = vecp->avh_hi_pri; 2120Sstevel@tonic-gate if (vecp->avh_link && (hi_pri != 0)) { 2130Sstevel@tonic-gate if (((hi_pri > LOCK_LEVEL) && (lvl < LOCK_LEVEL)) || 2140Sstevel@tonic-gate ((hi_pri < LOCK_LEVEL) && (lvl > LOCK_LEVEL))) { 2150Sstevel@tonic-gate cmn_err(CE_WARN, multilevel2, name, lvl, vect, 2160Sstevel@tonic-gate hi_pri); 2170Sstevel@tonic-gate return (0); 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate if ((vecp->avh_lo_pri != lvl) || (hi_pri != lvl)) 2200Sstevel@tonic-gate cmn_err(CE_NOTE, multilevel, vect); 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 223999Slq150181 insert_av(intr_id, vecp, f, arg1, arg2, ticksp, lvl, dip); 2240Sstevel@tonic-gate s = splhi(); 2250Sstevel@tonic-gate /* 2260Sstevel@tonic-gate * do what ever machine specific things are necessary 2270Sstevel@tonic-gate * to set priority level (e.g. set picmasks) 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate mutex_enter(&av_lock); 2300Sstevel@tonic-gate (*addspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 2310Sstevel@tonic-gate mutex_exit(&av_lock); 2320Sstevel@tonic-gate splx(s); 2330Sstevel@tonic-gate return (1); 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate void 2380Sstevel@tonic-gate update_avsoftintr_args(void *intr_id, int lvl, caddr_t arg2) 2390Sstevel@tonic-gate { 2400Sstevel@tonic-gate struct autovec *p; 2410Sstevel@tonic-gate struct autovec *target = NULL; 2420Sstevel@tonic-gate struct av_head *vectp = (struct av_head *)&softvect[lvl]; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate for (p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 2450Sstevel@tonic-gate if (p->av_intr_id == intr_id) { 2460Sstevel@tonic-gate target = p; 2470Sstevel@tonic-gate break; 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate } 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate if (target == NULL) 2520Sstevel@tonic-gate return; 2530Sstevel@tonic-gate target->av_intarg2 = arg2; 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate /* 2570Sstevel@tonic-gate * Register a software interrupt handler 2580Sstevel@tonic-gate */ 2590Sstevel@tonic-gate int 2600Sstevel@tonic-gate add_avsoftintr(void *intr_id, int lvl, avfunc xxintr, char *name, 2610Sstevel@tonic-gate caddr_t arg1, caddr_t arg2) 2620Sstevel@tonic-gate { 2630Sstevel@tonic-gate int slvl; 264999Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) 2670Sstevel@tonic-gate return (add_avintr(intr_id, lvl, xxintr, 268916Sschwartz name, slvl, arg1, arg2, NULL, NULL)); 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate if (intr_id == NULL) { 2710Sstevel@tonic-gate printf("Attempt to add null intr_id for %s on level %d\n", 2720Sstevel@tonic-gate name, lvl); 2730Sstevel@tonic-gate return (0); 2740Sstevel@tonic-gate } 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate if (xxintr == NULL) { 2770Sstevel@tonic-gate printf("Attempt to add null handler for %s on level %d\n", 2780Sstevel@tonic-gate name, lvl); 2790Sstevel@tonic-gate return (0); 2800Sstevel@tonic-gate } 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate if (lvl <= 0 || lvl > LOCK_LEVEL) { 2830Sstevel@tonic-gate printf(badsoft, lvl, name); 2840Sstevel@tonic-gate return (0); 2850Sstevel@tonic-gate } 286999Slq150181 287999Slq150181 if (hdlp->ih_pending == NULL) { 288999Slq150181 hdlp->ih_pending = 289999Slq150181 kmem_zalloc(sizeof (av_softinfo_t), KM_SLEEP); 2900Sstevel@tonic-gate } 291999Slq150181 292999Slq150181 insert_av(intr_id, &softvect[lvl], xxintr, arg1, arg2, NULL, lvl, NULL); 293999Slq150181 2940Sstevel@tonic-gate return (1); 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate /* insert an interrupt vector into chain */ 298999Slq150181 static void 2990Sstevel@tonic-gate insert_av(void *intr_id, struct av_head *vectp, avfunc f, caddr_t arg1, 300916Sschwartz caddr_t arg2, uint64_t *ticksp, int pri_level, dev_info_t *dip) 3010Sstevel@tonic-gate { 3020Sstevel@tonic-gate /* 3030Sstevel@tonic-gate * Protect rewrites of the list 3040Sstevel@tonic-gate */ 3050Sstevel@tonic-gate struct autovec *p, *mem; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 3080Sstevel@tonic-gate mem->av_vector = f; 3090Sstevel@tonic-gate mem->av_intarg1 = arg1; 3100Sstevel@tonic-gate mem->av_intarg2 = arg2; 311916Sschwartz mem->av_ticksp = ticksp; 3120Sstevel@tonic-gate mem->av_intr_id = intr_id; 3130Sstevel@tonic-gate mem->av_prilevel = pri_level; 3140Sstevel@tonic-gate mem->av_dip = dip; 3150Sstevel@tonic-gate mem->av_link = NULL; 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate mutex_enter(&av_lock); 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate if (vectp->avh_link == NULL) { /* Nothing on list - put it at head */ 3200Sstevel@tonic-gate vectp->avh_link = mem; 3210Sstevel@tonic-gate vectp->avh_hi_pri = vectp->avh_lo_pri = (ushort_t)pri_level; 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate mutex_exit(&av_lock); 324999Slq150181 return; 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* find where it goes in list */ 3280Sstevel@tonic-gate for (p = vectp->avh_link; p != NULL; p = p->av_link) { 3290Sstevel@tonic-gate if (p->av_vector == NULL) { /* freed struct available */ 3300Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 3310Sstevel@tonic-gate p->av_intarg1 = arg1; 3320Sstevel@tonic-gate p->av_intarg2 = arg2; 333916Sschwartz p->av_ticksp = ticksp; 3340Sstevel@tonic-gate p->av_intr_id = intr_id; 3350Sstevel@tonic-gate p->av_prilevel = pri_level; 336191Sahl p->av_dip = dip; 3370Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3380Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3410Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate p->av_vector = f; 3440Sstevel@tonic-gate mutex_exit(&av_lock); 345999Slq150181 return; 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate } 3480Sstevel@tonic-gate /* insert new intpt at beginning of chain */ 3490Sstevel@tonic-gate mem->av_link = vectp->avh_link; 3500Sstevel@tonic-gate vectp->avh_link = mem; 3510Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3520Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3550Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate mutex_exit(&av_lock); 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate 360999Slq150181 static int 361999Slq150181 av_rem_softintr(void *intr_id, int lvl, avfunc xxintr, boolean_t rem_softinfo) 3620Sstevel@tonic-gate { 3630Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 3640Sstevel@tonic-gate int slvl; 365999Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 366999Slq150181 av_softinfo_t *infop = (av_softinfo_t *)hdlp->ih_pending; 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate if (xxintr == NULL) 3690Sstevel@tonic-gate return (0); 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) { 3720Sstevel@tonic-gate rem_avintr(intr_id, lvl, xxintr, slvl); 3730Sstevel@tonic-gate return (1); 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate if (lvl <= 0 && lvl >= LOCK_LEVEL) { 3770Sstevel@tonic-gate return (0); 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate vecp = &softvect[lvl]; 3800Sstevel@tonic-gate remove_av(intr_id, vecp, xxintr, lvl, 0); 3810Sstevel@tonic-gate 382999Slq150181 if (rem_softinfo) { 383999Slq150181 kmem_free(infop, sizeof (av_softinfo_t)); 384999Slq150181 hdlp->ih_pending = NULL; 385999Slq150181 } 386999Slq150181 3870Sstevel@tonic-gate return (1); 3880Sstevel@tonic-gate } 3890Sstevel@tonic-gate 390999Slq150181 int 391999Slq150181 av_softint_movepri(void *intr_id, int old_lvl) 392999Slq150181 { 393999Slq150181 int ret; 394999Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 395999Slq150181 396999Slq150181 ret = add_avsoftintr(intr_id, hdlp->ih_pri, hdlp->ih_cb_func, 397999Slq150181 DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 398999Slq150181 399999Slq150181 if (ret) { 400999Slq150181 (void) av_rem_softintr(intr_id, old_lvl, hdlp->ih_cb_func, 401999Slq150181 B_FALSE); 402999Slq150181 } 403999Slq150181 404999Slq150181 return (ret); 405999Slq150181 } 406999Slq150181 407999Slq150181 /* 408999Slq150181 * Remove a driver from the autovector list. 409999Slq150181 */ 410999Slq150181 int 411999Slq150181 rem_avsoftintr(void *intr_id, int lvl, avfunc xxintr) 412999Slq150181 { 413999Slq150181 return (av_rem_softintr(intr_id, lvl, xxintr, B_TRUE)); 414999Slq150181 } 415999Slq150181 4160Sstevel@tonic-gate void 4170Sstevel@tonic-gate rem_avintr(void *intr_id, int lvl, avfunc xxintr, int vect) 4180Sstevel@tonic-gate { 4190Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 4200Sstevel@tonic-gate avfunc f; 4210Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate if ((f = xxintr) == NULL) 4240Sstevel@tonic-gate return; 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate vectindex = vect % MAX_VECT; 4270Sstevel@tonic-gate vecp = &autovect[vectindex]; 4280Sstevel@tonic-gate remove_av(intr_id, vecp, f, lvl, vect); 4290Sstevel@tonic-gate s = splhi(); 4300Sstevel@tonic-gate mutex_enter(&av_lock); 4310Sstevel@tonic-gate (*delspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 4320Sstevel@tonic-gate mutex_exit(&av_lock); 4330Sstevel@tonic-gate splx(s); 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * After having made a change to an autovector list, wait until we have 4390Sstevel@tonic-gate * seen each cpu not executing an interrupt at that level--so we know our 4400Sstevel@tonic-gate * change has taken effect completely (no old state in registers, etc). 4410Sstevel@tonic-gate */ 4420Sstevel@tonic-gate void 4430Sstevel@tonic-gate wait_till_seen(int ipl) 4440Sstevel@tonic-gate { 4450Sstevel@tonic-gate int cpu_in_chain, cix; 4460Sstevel@tonic-gate struct cpu *cpup; 4470Sstevel@tonic-gate cpuset_t cpus_to_check; 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate CPUSET_ALL(cpus_to_check); 4500Sstevel@tonic-gate do { 4510Sstevel@tonic-gate cpu_in_chain = 0; 4520Sstevel@tonic-gate for (cix = 0; cix < NCPU; cix++) { 4530Sstevel@tonic-gate cpup = cpu[cix]; 4540Sstevel@tonic-gate if (cpup != NULL && CPU_IN_SET(cpus_to_check, cix)) { 4550Sstevel@tonic-gate if (intr_active(cpup, ipl)) { 4560Sstevel@tonic-gate cpu_in_chain = 1; 4570Sstevel@tonic-gate } else { 4580Sstevel@tonic-gate CPUSET_DEL(cpus_to_check, cix); 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate } while (cpu_in_chain); 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* remove an interrupt vector from the chain */ 4660Sstevel@tonic-gate static void 4670Sstevel@tonic-gate remove_av(void *intr_id, struct av_head *vectp, avfunc f, int pri_level, 4680Sstevel@tonic-gate int vect) 4690Sstevel@tonic-gate { 4700Sstevel@tonic-gate struct autovec *endp, *p, *target; 4710Sstevel@tonic-gate int lo_pri, hi_pri; 4720Sstevel@tonic-gate int ipl; 4730Sstevel@tonic-gate /* 4740Sstevel@tonic-gate * Protect rewrites of the list 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate target = NULL; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate mutex_enter(&av_lock); 4790Sstevel@tonic-gate ipl = pri_level; 4800Sstevel@tonic-gate lo_pri = MAXIPL; 4810Sstevel@tonic-gate hi_pri = 0; 4820Sstevel@tonic-gate for (endp = p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 4830Sstevel@tonic-gate endp = p; 4840Sstevel@tonic-gate if ((p->av_vector == f) && (p->av_intr_id == intr_id)) { 4850Sstevel@tonic-gate /* found the handler */ 4860Sstevel@tonic-gate target = p; 4870Sstevel@tonic-gate continue; 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate if (p->av_prilevel > hi_pri) 4900Sstevel@tonic-gate hi_pri = p->av_prilevel; 4910Sstevel@tonic-gate if (p->av_prilevel < lo_pri) 4920Sstevel@tonic-gate lo_pri = p->av_prilevel; 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate if (ipl < hi_pri) 4950Sstevel@tonic-gate ipl = hi_pri; 4960Sstevel@tonic-gate if (target == NULL) { /* not found */ 4970Sstevel@tonic-gate printf("Couldn't remove function %p at %d, %d\n", 4980Sstevel@tonic-gate (void *)f, vect, pri_level); 4990Sstevel@tonic-gate mutex_exit(&av_lock); 5000Sstevel@tonic-gate return; 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate target->av_vector = NULL; 504916Sschwartz target->av_ticksp = NULL; 5050Sstevel@tonic-gate wait_till_seen(ipl); 5060Sstevel@tonic-gate if (endp != target) { /* vector to be removed is not last in chain */ 507191Sahl target->av_vector = endp->av_vector; 5080Sstevel@tonic-gate target->av_intarg1 = endp->av_intarg1; 5090Sstevel@tonic-gate target->av_intarg2 = endp->av_intarg2; 510916Sschwartz target->av_ticksp = endp->av_ticksp; 511191Sahl target->av_intr_id = endp->av_intr_id; 5120Sstevel@tonic-gate target->av_prilevel = endp->av_prilevel; 513191Sahl target->av_dip = endp->av_dip; 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * We have a hole here where the routine corresponding to 5160Sstevel@tonic-gate * endp may not get called. Do a wait_till_seen to take care 5170Sstevel@tonic-gate * of this. 5180Sstevel@tonic-gate */ 5190Sstevel@tonic-gate wait_till_seen(ipl); 5200Sstevel@tonic-gate endp->av_vector = NULL; 521916Sschwartz endp->av_ticksp = NULL; 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate if (lo_pri > hi_pri) { /* the chain is now empty */ 5250Sstevel@tonic-gate /* Leave the unused entries here for probable future use */ 5260Sstevel@tonic-gate vectp->avh_lo_pri = MAXIPL; 5270Sstevel@tonic-gate vectp->avh_hi_pri = 0; 5280Sstevel@tonic-gate } else { 5290Sstevel@tonic-gate if ((int)vectp->avh_lo_pri < lo_pri) 5300Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)lo_pri; 5310Sstevel@tonic-gate if ((int)vectp->avh_hi_pri > hi_pri) 5320Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)hi_pri; 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate mutex_exit(&av_lock); 5350Sstevel@tonic-gate wait_till_seen(ipl); 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate /* 5390Sstevel@tonic-gate * Trigger a soft interrupt. 5400Sstevel@tonic-gate */ 5410Sstevel@tonic-gate void 5420Sstevel@tonic-gate siron(void) 5430Sstevel@tonic-gate { 544999Slq150181 (*setsoftint)(1, softlevel1_hdl.ih_pending); 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate /* 5480Sstevel@tonic-gate * Walk the autovector table for this vector, invoking each 5490Sstevel@tonic-gate * interrupt handler as we go. 5500Sstevel@tonic-gate */ 551916Sschwartz 552916Sschwartz extern uint64_t intr_get_time(void); 553916Sschwartz 5540Sstevel@tonic-gate void 5550Sstevel@tonic-gate av_dispatch_autovect(uint_t vec) 5560Sstevel@tonic-gate { 5570Sstevel@tonic-gate struct autovec *av; 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate while ((av = autovect[vec].avh_link) != NULL) { 5620Sstevel@tonic-gate uint_t numcalled = 0; 5630Sstevel@tonic-gate uint_t claimed = 0; 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate for (; av; av = av->av_link) { 5660Sstevel@tonic-gate uint_t r; 5670Sstevel@tonic-gate uint_t (*intr)() = av->av_vector; 5680Sstevel@tonic-gate caddr_t arg1 = av->av_intarg1; 5690Sstevel@tonic-gate caddr_t arg2 = av->av_intarg2; 5700Sstevel@tonic-gate dev_info_t *dip = av->av_dip; 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate if (intr == NULL) 5730Sstevel@tonic-gate break; 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t *, dip, 5760Sstevel@tonic-gate void *, intr, caddr_t, arg1, caddr_t, arg2); 5770Sstevel@tonic-gate r = (*intr)(arg1, arg2); 5780Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t *, dip, 5790Sstevel@tonic-gate void *, intr, caddr_t, arg1, uint_t, r); 580*3446Smrj numcalled++; 5810Sstevel@tonic-gate claimed |= r; 582916Sschwartz if (av->av_ticksp && av->av_prilevel <= LOCK_LEVEL) 583916Sschwartz atomic_add_64(av->av_ticksp, intr_get_time()); 5840Sstevel@tonic-gate } 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate /* 5870Sstevel@tonic-gate * If there's only one interrupt handler in the chain, 5880Sstevel@tonic-gate * or if no-one claimed the interrupt at all give up now. 5890Sstevel@tonic-gate */ 5900Sstevel@tonic-gate if (numcalled == 1 || claimed == 0) 5910Sstevel@tonic-gate break; 5920Sstevel@tonic-gate } 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate /* 5960Sstevel@tonic-gate * Call every soft interrupt handler we can find at this level once. 5970Sstevel@tonic-gate */ 5980Sstevel@tonic-gate void 5990Sstevel@tonic-gate av_dispatch_softvect(uint_t pil) 6000Sstevel@tonic-gate { 6010Sstevel@tonic-gate struct autovec *av; 6020Sstevel@tonic-gate ddi_softint_hdl_impl_t *hdlp; 6030Sstevel@tonic-gate uint_t (*intr)(); 6040Sstevel@tonic-gate caddr_t arg1; 6050Sstevel@tonic-gate caddr_t arg2; 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 6080Sstevel@tonic-gate ASSERT(pil >= 0 && pil <= PIL_MAX); 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate for (av = softvect[pil].avh_link; av; av = av->av_link) { 6110Sstevel@tonic-gate if ((intr = av->av_vector) == NULL) 6120Sstevel@tonic-gate break; 6130Sstevel@tonic-gate arg1 = av->av_intarg1; 6140Sstevel@tonic-gate arg2 = av->av_intarg2; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate hdlp = (ddi_softint_hdl_impl_t *)av->av_intr_id; 6170Sstevel@tonic-gate ASSERT(hdlp); 6180Sstevel@tonic-gate 619999Slq150181 /* 620999Slq150181 * Each cpu has its own pending bit in hdlp->ih_pending, 621999Slq150181 * here av_check/clear_softint_pending is just checking 622999Slq150181 * and clearing the pending bit for the current cpu, who 623999Slq150181 * has just triggered a softint. 624999Slq150181 */ 625999Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) { 626999Slq150181 av_clear_softint_pending(hdlp->ih_pending); 6270Sstevel@tonic-gate (void) (*intr)(arg1, arg2); 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate } 6300Sstevel@tonic-gate } 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate struct regs; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* 6350Sstevel@tonic-gate * Call every NMI handler we know of once. 6360Sstevel@tonic-gate */ 6370Sstevel@tonic-gate void 6380Sstevel@tonic-gate av_dispatch_nmivect(struct regs *rp) 6390Sstevel@tonic-gate { 6400Sstevel@tonic-gate struct autovec *av; 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate for (av = nmivect; av; av = av->av_link) 6450Sstevel@tonic-gate (void) (av->av_vector)(av->av_intarg1, rp); 6460Sstevel@tonic-gate } 647