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