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 510Sstevel@tonic-gate static int insert_av(void *intr_id, struct av_head *vectp, avfunc f, 52*916Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, int pri_level, 53*916Sschwartz dev_info_t *dip); 540Sstevel@tonic-gate static void remove_av(void *intr_id, struct av_head *vectp, avfunc f, 550Sstevel@tonic-gate int pri_level, int vect); 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * Arrange for a driver to be called when a particular 590Sstevel@tonic-gate * auto-vectored interrupt occurs. 600Sstevel@tonic-gate * NOTE: if a device can generate interrupts on more than 610Sstevel@tonic-gate * one level, or if a driver services devices that interrupt 620Sstevel@tonic-gate * on more than one level, then the driver should install 630Sstevel@tonic-gate * itself on each of those levels. 640Sstevel@tonic-gate */ 650Sstevel@tonic-gate static char badsoft[] = 660Sstevel@tonic-gate "add_avintr: bad soft interrupt level %d for driver '%s'\n"; 670Sstevel@tonic-gate static char multilevel[] = 680Sstevel@tonic-gate "!IRQ%d is being shared by drivers with different interrupt levels.\n" 690Sstevel@tonic-gate "This may result in reduced system performance."; 700Sstevel@tonic-gate static char multilevel2[] = 710Sstevel@tonic-gate "Cannot register interrupt for '%s' device at IPL %d because it\n" 720Sstevel@tonic-gate "conflicts with another device using the same vector %d with an IPL\n" 730Sstevel@tonic-gate "of %d. Reconfigure the conflicting devices to use different vectors."; 740Sstevel@tonic-gate 750Sstevel@tonic-gate #define MAX_VECT 256 760Sstevel@tonic-gate struct autovec *nmivect = NULL; 770Sstevel@tonic-gate struct av_head autovect[MAX_VECT]; 780Sstevel@tonic-gate struct av_head softvect[LOCK_LEVEL + 1]; 790Sstevel@tonic-gate kmutex_t av_lock; 800Sstevel@tonic-gate ddi_softint_hdl_impl_t softlevel1_hdl = 810Sstevel@tonic-gate {0, NULL, NULL, 0, 0, NULL, NULL, NULL}; 820Sstevel@tonic-gate 830Sstevel@tonic-gate void 840Sstevel@tonic-gate set_pending(int pri) 850Sstevel@tonic-gate { 860Sstevel@tonic-gate atomic_or_32((uint32_t *)&CPU->cpu_softinfo.st_pending, 1 << pri); 870Sstevel@tonic-gate } 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * register nmi interrupt routine. The first arg is used only to order 910Sstevel@tonic-gate * various nmi interrupt service routines in the chain. Higher lvls will 920Sstevel@tonic-gate * be called first 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate int 950Sstevel@tonic-gate add_nmintr(int lvl, avfunc nmintr, char *name, caddr_t arg) 960Sstevel@tonic-gate { 970Sstevel@tonic-gate struct autovec *mem; 980Sstevel@tonic-gate struct autovec *p, *prev = NULL; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate if (nmintr == NULL) { 1010Sstevel@tonic-gate printf("Attempt to add null vect for %s on nmi\n", name); 1020Sstevel@tonic-gate return (0); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 1070Sstevel@tonic-gate mem->av_vector = nmintr; 1080Sstevel@tonic-gate mem->av_intarg1 = arg; 1090Sstevel@tonic-gate mem->av_intarg2 = NULL; 1100Sstevel@tonic-gate mem->av_intr_id = NULL; 1110Sstevel@tonic-gate mem->av_prilevel = lvl; 112191Sahl mem->av_dip = NULL; 1130Sstevel@tonic-gate mem->av_link = NULL; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate mutex_enter(&av_lock); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate if (!nmivect) { 1180Sstevel@tonic-gate nmivect = mem; 1190Sstevel@tonic-gate mutex_exit(&av_lock); 1200Sstevel@tonic-gate return (1); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate /* find where it goes in list */ 1230Sstevel@tonic-gate for (p = nmivect; p != NULL; p = p->av_link) { 1240Sstevel@tonic-gate if (p->av_vector == nmintr && p->av_intarg1 == arg) { 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * already in list 1270Sstevel@tonic-gate * So? Somebody added the same interrupt twice. 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate cmn_err(CE_WARN, "Driver already registered '%s'", 1300Sstevel@tonic-gate name); 1310Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 1320Sstevel@tonic-gate mutex_exit(&av_lock); 1330Sstevel@tonic-gate return (0); 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate if (p->av_prilevel < lvl) { 1360Sstevel@tonic-gate if (p == nmivect) { /* it's at head of list */ 1370Sstevel@tonic-gate mem->av_link = p; 1380Sstevel@tonic-gate nmivect = mem; 1390Sstevel@tonic-gate } else { 1400Sstevel@tonic-gate mem->av_link = p; 1410Sstevel@tonic-gate prev->av_link = mem; 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate mutex_exit(&av_lock); 1440Sstevel@tonic-gate return (1); 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate prev = p; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate /* didn't find it, add it to the end */ 1500Sstevel@tonic-gate prev->av_link = mem; 1510Sstevel@tonic-gate mutex_exit(&av_lock); 1520Sstevel@tonic-gate return (1); 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* 1570Sstevel@tonic-gate * register a hardware interrupt handler. 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate int 1600Sstevel@tonic-gate add_avintr(void *intr_id, int lvl, avfunc xxintr, char *name, int vect, 161*916Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, dev_info_t *dip) 1620Sstevel@tonic-gate { 1630Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 1640Sstevel@tonic-gate avfunc f; 1650Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 1660Sstevel@tonic-gate ushort_t hi_pri; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if ((f = xxintr) == NULL) { 1690Sstevel@tonic-gate printf("Attempt to add null vect for %s on vector %d\n", 1700Sstevel@tonic-gate name, vect); 1710Sstevel@tonic-gate return (0); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate vectindex = vect % MAX_VECT; 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate vecp = &autovect[vectindex]; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * "hi_pri == 0" implies all entries on list are "unused", 1800Sstevel@tonic-gate * which means that it's OK to just insert this one. 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate hi_pri = vecp->avh_hi_pri; 1830Sstevel@tonic-gate if (vecp->avh_link && (hi_pri != 0)) { 1840Sstevel@tonic-gate if (((hi_pri > LOCK_LEVEL) && (lvl < LOCK_LEVEL)) || 1850Sstevel@tonic-gate ((hi_pri < LOCK_LEVEL) && (lvl > LOCK_LEVEL))) { 1860Sstevel@tonic-gate cmn_err(CE_WARN, multilevel2, name, lvl, vect, 1870Sstevel@tonic-gate hi_pri); 1880Sstevel@tonic-gate return (0); 1890Sstevel@tonic-gate } 1900Sstevel@tonic-gate if ((vecp->avh_lo_pri != lvl) || (hi_pri != lvl)) 1910Sstevel@tonic-gate cmn_err(CE_NOTE, multilevel, vect); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 194*916Sschwartz if (!insert_av(intr_id, vecp, f, arg1, arg2, ticksp, lvl, dip)) 1950Sstevel@tonic-gate return (0); 1960Sstevel@tonic-gate s = splhi(); 1970Sstevel@tonic-gate /* 1980Sstevel@tonic-gate * do what ever machine specific things are necessary 1990Sstevel@tonic-gate * to set priority level (e.g. set picmasks) 2000Sstevel@tonic-gate */ 2010Sstevel@tonic-gate mutex_enter(&av_lock); 2020Sstevel@tonic-gate (*addspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 2030Sstevel@tonic-gate mutex_exit(&av_lock); 2040Sstevel@tonic-gate splx(s); 2050Sstevel@tonic-gate return (1); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate } 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate void 2100Sstevel@tonic-gate update_avsoftintr_args(void *intr_id, int lvl, caddr_t arg2) 2110Sstevel@tonic-gate { 2120Sstevel@tonic-gate struct autovec *p; 2130Sstevel@tonic-gate struct autovec *target = NULL; 2140Sstevel@tonic-gate struct av_head *vectp = (struct av_head *)&softvect[lvl]; 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate for (p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 2170Sstevel@tonic-gate if (p->av_intr_id == intr_id) { 2180Sstevel@tonic-gate target = p; 2190Sstevel@tonic-gate break; 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate if (target == NULL) 2240Sstevel@tonic-gate return; 2250Sstevel@tonic-gate target->av_intarg2 = arg2; 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * Register a software interrupt handler 2300Sstevel@tonic-gate */ 2310Sstevel@tonic-gate int 2320Sstevel@tonic-gate add_avsoftintr(void *intr_id, int lvl, avfunc xxintr, char *name, 2330Sstevel@tonic-gate caddr_t arg1, caddr_t arg2) 2340Sstevel@tonic-gate { 2350Sstevel@tonic-gate int slvl; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) 2380Sstevel@tonic-gate return (add_avintr(intr_id, lvl, xxintr, 239*916Sschwartz name, slvl, arg1, arg2, NULL, NULL)); 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate if (intr_id == NULL) { 2420Sstevel@tonic-gate printf("Attempt to add null intr_id for %s on level %d\n", 2430Sstevel@tonic-gate name, lvl); 2440Sstevel@tonic-gate return (0); 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate if (xxintr == NULL) { 2480Sstevel@tonic-gate printf("Attempt to add null handler for %s on level %d\n", 2490Sstevel@tonic-gate name, lvl); 2500Sstevel@tonic-gate return (0); 2510Sstevel@tonic-gate } 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate if (lvl <= 0 || lvl > LOCK_LEVEL) { 2540Sstevel@tonic-gate printf(badsoft, lvl, name); 2550Sstevel@tonic-gate return (0); 2560Sstevel@tonic-gate } 257*916Sschwartz if (!insert_av(intr_id, &softvect[lvl], xxintr, arg1, arg2, NULL, 2580Sstevel@tonic-gate lvl, NULL)) { 2590Sstevel@tonic-gate return (0); 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate return (1); 2620Sstevel@tonic-gate } 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate /* insert an interrupt vector into chain */ 2650Sstevel@tonic-gate static int 2660Sstevel@tonic-gate insert_av(void *intr_id, struct av_head *vectp, avfunc f, caddr_t arg1, 267*916Sschwartz caddr_t arg2, uint64_t *ticksp, int pri_level, dev_info_t *dip) 2680Sstevel@tonic-gate { 2690Sstevel@tonic-gate /* 2700Sstevel@tonic-gate * Protect rewrites of the list 2710Sstevel@tonic-gate */ 2720Sstevel@tonic-gate struct autovec *p, *mem; 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 2750Sstevel@tonic-gate mem->av_vector = f; 2760Sstevel@tonic-gate mem->av_intarg1 = arg1; 2770Sstevel@tonic-gate mem->av_intarg2 = arg2; 278*916Sschwartz mem->av_ticksp = ticksp; 2790Sstevel@tonic-gate mem->av_intr_id = intr_id; 2800Sstevel@tonic-gate mem->av_prilevel = pri_level; 2810Sstevel@tonic-gate mem->av_dip = dip; 2820Sstevel@tonic-gate mem->av_link = NULL; 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate mutex_enter(&av_lock); 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate if (vectp->avh_link == NULL) { /* Nothing on list - put it at head */ 2870Sstevel@tonic-gate vectp->avh_link = mem; 2880Sstevel@tonic-gate vectp->avh_hi_pri = vectp->avh_lo_pri = (ushort_t)pri_level; 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate mutex_exit(&av_lock); 2910Sstevel@tonic-gate return (1); 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /* find where it goes in list */ 2950Sstevel@tonic-gate for (p = vectp->avh_link; p != NULL; p = p->av_link) { 2960Sstevel@tonic-gate if (p->av_vector == NULL) { /* freed struct available */ 2970Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 2980Sstevel@tonic-gate p->av_intarg1 = arg1; 2990Sstevel@tonic-gate p->av_intarg2 = arg2; 300*916Sschwartz p->av_ticksp = ticksp; 3010Sstevel@tonic-gate p->av_intr_id = intr_id; 3020Sstevel@tonic-gate p->av_prilevel = pri_level; 303191Sahl p->av_dip = dip; 3040Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3050Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3080Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate p->av_vector = f; 3110Sstevel@tonic-gate mutex_exit(&av_lock); 3120Sstevel@tonic-gate return (1); 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate } 3150Sstevel@tonic-gate /* insert new intpt at beginning of chain */ 3160Sstevel@tonic-gate mem->av_link = vectp->avh_link; 3170Sstevel@tonic-gate vectp->avh_link = mem; 3180Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3190Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3220Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3230Sstevel@tonic-gate } 3240Sstevel@tonic-gate mutex_exit(&av_lock); 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate return (1); 3270Sstevel@tonic-gate } 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate /* 3300Sstevel@tonic-gate * Remove a driver from the autovector list. 3310Sstevel@tonic-gate */ 3320Sstevel@tonic-gate int 3330Sstevel@tonic-gate rem_avsoftintr(void *intr_id, int lvl, avfunc xxintr) 3340Sstevel@tonic-gate { 3350Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 3360Sstevel@tonic-gate int slvl; 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate if (xxintr == NULL) 3390Sstevel@tonic-gate return (0); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) { 3420Sstevel@tonic-gate rem_avintr(intr_id, lvl, xxintr, slvl); 3430Sstevel@tonic-gate return (1); 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate if (lvl <= 0 && lvl >= LOCK_LEVEL) { 3470Sstevel@tonic-gate return (0); 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate vecp = &softvect[lvl]; 3500Sstevel@tonic-gate remove_av(intr_id, vecp, xxintr, lvl, 0); 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate return (1); 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate void 3560Sstevel@tonic-gate rem_avintr(void *intr_id, int lvl, avfunc xxintr, int vect) 3570Sstevel@tonic-gate { 3580Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 3590Sstevel@tonic-gate avfunc f; 3600Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate if ((f = xxintr) == NULL) 3630Sstevel@tonic-gate return; 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate vectindex = vect % MAX_VECT; 3660Sstevel@tonic-gate vecp = &autovect[vectindex]; 3670Sstevel@tonic-gate remove_av(intr_id, vecp, f, lvl, vect); 3680Sstevel@tonic-gate s = splhi(); 3690Sstevel@tonic-gate mutex_enter(&av_lock); 3700Sstevel@tonic-gate (*delspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 3710Sstevel@tonic-gate mutex_exit(&av_lock); 3720Sstevel@tonic-gate splx(s); 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate /* 3770Sstevel@tonic-gate * After having made a change to an autovector list, wait until we have 3780Sstevel@tonic-gate * seen each cpu not executing an interrupt at that level--so we know our 3790Sstevel@tonic-gate * change has taken effect completely (no old state in registers, etc). 3800Sstevel@tonic-gate */ 3810Sstevel@tonic-gate void 3820Sstevel@tonic-gate wait_till_seen(int ipl) 3830Sstevel@tonic-gate { 3840Sstevel@tonic-gate int cpu_in_chain, cix; 3850Sstevel@tonic-gate struct cpu *cpup; 3860Sstevel@tonic-gate cpuset_t cpus_to_check; 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate CPUSET_ALL(cpus_to_check); 3890Sstevel@tonic-gate do { 3900Sstevel@tonic-gate cpu_in_chain = 0; 3910Sstevel@tonic-gate for (cix = 0; cix < NCPU; cix++) { 3920Sstevel@tonic-gate cpup = cpu[cix]; 3930Sstevel@tonic-gate if (cpup != NULL && CPU_IN_SET(cpus_to_check, cix)) { 3940Sstevel@tonic-gate if (intr_active(cpup, ipl)) { 3950Sstevel@tonic-gate cpu_in_chain = 1; 3960Sstevel@tonic-gate } else { 3970Sstevel@tonic-gate CPUSET_DEL(cpus_to_check, cix); 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate } 4010Sstevel@tonic-gate } while (cpu_in_chain); 4020Sstevel@tonic-gate } 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate /* remove an interrupt vector from the chain */ 4050Sstevel@tonic-gate static void 4060Sstevel@tonic-gate remove_av(void *intr_id, struct av_head *vectp, avfunc f, int pri_level, 4070Sstevel@tonic-gate int vect) 4080Sstevel@tonic-gate { 4090Sstevel@tonic-gate struct autovec *endp, *p, *target; 4100Sstevel@tonic-gate int lo_pri, hi_pri; 4110Sstevel@tonic-gate int ipl; 4120Sstevel@tonic-gate /* 4130Sstevel@tonic-gate * Protect rewrites of the list 4140Sstevel@tonic-gate */ 4150Sstevel@tonic-gate target = NULL; 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate mutex_enter(&av_lock); 4180Sstevel@tonic-gate ipl = pri_level; 4190Sstevel@tonic-gate lo_pri = MAXIPL; 4200Sstevel@tonic-gate hi_pri = 0; 4210Sstevel@tonic-gate for (endp = p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 4220Sstevel@tonic-gate endp = p; 4230Sstevel@tonic-gate if ((p->av_vector == f) && (p->av_intr_id == intr_id)) { 4240Sstevel@tonic-gate /* found the handler */ 4250Sstevel@tonic-gate target = p; 4260Sstevel@tonic-gate continue; 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate if (p->av_prilevel > hi_pri) 4290Sstevel@tonic-gate hi_pri = p->av_prilevel; 4300Sstevel@tonic-gate if (p->av_prilevel < lo_pri) 4310Sstevel@tonic-gate lo_pri = p->av_prilevel; 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate if (ipl < hi_pri) 4340Sstevel@tonic-gate ipl = hi_pri; 4350Sstevel@tonic-gate if (target == NULL) { /* not found */ 4360Sstevel@tonic-gate printf("Couldn't remove function %p at %d, %d\n", 4370Sstevel@tonic-gate (void *)f, vect, pri_level); 4380Sstevel@tonic-gate mutex_exit(&av_lock); 4390Sstevel@tonic-gate return; 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate target->av_vector = NULL; 443*916Sschwartz target->av_ticksp = NULL; 4440Sstevel@tonic-gate wait_till_seen(ipl); 4450Sstevel@tonic-gate if (endp != target) { /* vector to be removed is not last in chain */ 446191Sahl target->av_vector = endp->av_vector; 4470Sstevel@tonic-gate target->av_intarg1 = endp->av_intarg1; 4480Sstevel@tonic-gate target->av_intarg2 = endp->av_intarg2; 449*916Sschwartz target->av_ticksp = endp->av_ticksp; 450191Sahl target->av_intr_id = endp->av_intr_id; 4510Sstevel@tonic-gate target->av_prilevel = endp->av_prilevel; 452191Sahl target->av_dip = endp->av_dip; 4530Sstevel@tonic-gate /* 4540Sstevel@tonic-gate * We have a hole here where the routine corresponding to 4550Sstevel@tonic-gate * endp may not get called. Do a wait_till_seen to take care 4560Sstevel@tonic-gate * of this. 4570Sstevel@tonic-gate */ 4580Sstevel@tonic-gate wait_till_seen(ipl); 4590Sstevel@tonic-gate endp->av_vector = NULL; 460*916Sschwartz endp->av_ticksp = NULL; 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate if (lo_pri > hi_pri) { /* the chain is now empty */ 4640Sstevel@tonic-gate /* Leave the unused entries here for probable future use */ 4650Sstevel@tonic-gate vectp->avh_lo_pri = MAXIPL; 4660Sstevel@tonic-gate vectp->avh_hi_pri = 0; 4670Sstevel@tonic-gate } else { 4680Sstevel@tonic-gate if ((int)vectp->avh_lo_pri < lo_pri) 4690Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)lo_pri; 4700Sstevel@tonic-gate if ((int)vectp->avh_hi_pri > hi_pri) 4710Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)hi_pri; 4720Sstevel@tonic-gate } 4730Sstevel@tonic-gate mutex_exit(&av_lock); 4740Sstevel@tonic-gate wait_till_seen(ipl); 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* 4780Sstevel@tonic-gate * Trigger a soft interrupt. 4790Sstevel@tonic-gate */ 4800Sstevel@tonic-gate void 4810Sstevel@tonic-gate siron(void) 4820Sstevel@tonic-gate { 4830Sstevel@tonic-gate softlevel1_hdl.ih_pending = 1; 4840Sstevel@tonic-gate (*setsoftint)(1); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /* 4880Sstevel@tonic-gate * Walk the autovector table for this vector, invoking each 4890Sstevel@tonic-gate * interrupt handler as we go. 4900Sstevel@tonic-gate */ 491*916Sschwartz 492*916Sschwartz extern uint64_t intr_get_time(void); 493*916Sschwartz 4940Sstevel@tonic-gate void 4950Sstevel@tonic-gate av_dispatch_autovect(uint_t vec) 4960Sstevel@tonic-gate { 4970Sstevel@tonic-gate struct autovec *av; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate while ((av = autovect[vec].avh_link) != NULL) { 5020Sstevel@tonic-gate uint_t numcalled = 0; 5030Sstevel@tonic-gate uint_t claimed = 0; 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate for (; av; av = av->av_link) { 5060Sstevel@tonic-gate uint_t r; 5070Sstevel@tonic-gate uint_t (*intr)() = av->av_vector; 5080Sstevel@tonic-gate caddr_t arg1 = av->av_intarg1; 5090Sstevel@tonic-gate caddr_t arg2 = av->av_intarg2; 5100Sstevel@tonic-gate dev_info_t *dip = av->av_dip; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate numcalled++; 5130Sstevel@tonic-gate if (intr == NULL) 5140Sstevel@tonic-gate break; 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t *, dip, 5170Sstevel@tonic-gate void *, intr, caddr_t, arg1, caddr_t, arg2); 5180Sstevel@tonic-gate r = (*intr)(arg1, arg2); 5190Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t *, dip, 5200Sstevel@tonic-gate void *, intr, caddr_t, arg1, uint_t, r); 5210Sstevel@tonic-gate claimed |= r; 522*916Sschwartz if (av->av_ticksp && av->av_prilevel <= LOCK_LEVEL) 523*916Sschwartz atomic_add_64(av->av_ticksp, intr_get_time()); 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate /* 5270Sstevel@tonic-gate * If there's only one interrupt handler in the chain, 5280Sstevel@tonic-gate * or if no-one claimed the interrupt at all give up now. 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate if (numcalled == 1 || claimed == 0) 5310Sstevel@tonic-gate break; 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate } 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate /* 5360Sstevel@tonic-gate * Call every soft interrupt handler we can find at this level once. 5370Sstevel@tonic-gate */ 5380Sstevel@tonic-gate void 5390Sstevel@tonic-gate av_dispatch_softvect(uint_t pil) 5400Sstevel@tonic-gate { 5410Sstevel@tonic-gate struct autovec *av; 5420Sstevel@tonic-gate ddi_softint_hdl_impl_t *hdlp; 5430Sstevel@tonic-gate uint_t (*intr)(); 5440Sstevel@tonic-gate caddr_t arg1; 5450Sstevel@tonic-gate caddr_t arg2; 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 5480Sstevel@tonic-gate ASSERT(pil >= 0 && pil <= PIL_MAX); 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate for (av = softvect[pil].avh_link; av; av = av->av_link) { 5510Sstevel@tonic-gate if ((intr = av->av_vector) == NULL) 5520Sstevel@tonic-gate break; 5530Sstevel@tonic-gate arg1 = av->av_intarg1; 5540Sstevel@tonic-gate arg2 = av->av_intarg2; 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate hdlp = (ddi_softint_hdl_impl_t *)av->av_intr_id; 5570Sstevel@tonic-gate ASSERT(hdlp); 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate if (hdlp->ih_pending) { 5600Sstevel@tonic-gate hdlp->ih_pending = 0; 5610Sstevel@tonic-gate (void) (*intr)(arg1, arg2); 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate struct regs; 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate /* 5690Sstevel@tonic-gate * Call every NMI handler we know of once. 5700Sstevel@tonic-gate */ 5710Sstevel@tonic-gate void 5720Sstevel@tonic-gate av_dispatch_nmivect(struct regs *rp) 5730Sstevel@tonic-gate { 5740Sstevel@tonic-gate struct autovec *av; 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate for (av = nmivect; av; av = av->av_link) 5790Sstevel@tonic-gate (void) (av->av_vector)(av->av_intarg1, rp); 5800Sstevel@tonic-gate } 581