17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ae115bc7Smrj * Common Development and Distribution License (the "License"). 6ae115bc7Smrj * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*5cd376e8SJimmy Vetayases * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate /* 267c478bd9Sstevel@tonic-gate * Autovectored Interrupt Configuration and Deconfiguration 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/param.h> 307c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 317c478bd9Sstevel@tonic-gate #include <sys/trap.h> 327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 337c478bd9Sstevel@tonic-gate #include <sys/avintr.h> 347c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 357c478bd9Sstevel@tonic-gate #include <sys/machlock.h> 367c478bd9Sstevel@tonic-gate #include <sys/systm.h> 377c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 387c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 397c478bd9Sstevel@tonic-gate #include <sys/x_call.h> 407c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 417c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 427c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h> 437c478bd9Sstevel@tonic-gate #include <sys/sdt.h> 447c478bd9Sstevel@tonic-gate #include <sys/stack.h> 457c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 46843e1988Sjohnlev #ifdef __xpv 47843e1988Sjohnlev #include <sys/evtchn_impl.h> 48843e1988Sjohnlev #endif 497c478bd9Sstevel@tonic-gate 50e23a7e34Slq150181 typedef struct av_softinfo { 51e23a7e34Slq150181 cpuset_t av_pending; /* pending bitmasks */ 52e23a7e34Slq150181 } av_softinfo_t; 53e23a7e34Slq150181 54e23a7e34Slq150181 static void insert_av(void *intr_id, struct av_head *vectp, avfunc f, 557a364d25Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, int pri_level, 567a364d25Sschwartz dev_info_t *dip); 577c478bd9Sstevel@tonic-gate static void remove_av(void *intr_id, struct av_head *vectp, avfunc f, 587c478bd9Sstevel@tonic-gate int pri_level, int vect); 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * Arrange for a driver to be called when a particular 627c478bd9Sstevel@tonic-gate * auto-vectored interrupt occurs. 637c478bd9Sstevel@tonic-gate * NOTE: if a device can generate interrupts on more than 647c478bd9Sstevel@tonic-gate * one level, or if a driver services devices that interrupt 657c478bd9Sstevel@tonic-gate * on more than one level, then the driver should install 667c478bd9Sstevel@tonic-gate * itself on each of those levels. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate static char badsoft[] = 697c478bd9Sstevel@tonic-gate "add_avintr: bad soft interrupt level %d for driver '%s'\n"; 707c478bd9Sstevel@tonic-gate static char multilevel[] = 717c478bd9Sstevel@tonic-gate "!IRQ%d is being shared by drivers with different interrupt levels.\n" 727c478bd9Sstevel@tonic-gate "This may result in reduced system performance."; 737c478bd9Sstevel@tonic-gate static char multilevel2[] = 747c478bd9Sstevel@tonic-gate "Cannot register interrupt for '%s' device at IPL %d because it\n" 757c478bd9Sstevel@tonic-gate "conflicts with another device using the same vector %d with an IPL\n" 767c478bd9Sstevel@tonic-gate "of %d. Reconfigure the conflicting devices to use different vectors."; 777c478bd9Sstevel@tonic-gate 78843e1988Sjohnlev #ifdef __xpv 79843e1988Sjohnlev #define MAX_VECT NR_IRQS 80843e1988Sjohnlev #else 817c478bd9Sstevel@tonic-gate #define MAX_VECT 256 82843e1988Sjohnlev #endif 83843e1988Sjohnlev 847c478bd9Sstevel@tonic-gate struct autovec *nmivect = NULL; 857c478bd9Sstevel@tonic-gate struct av_head autovect[MAX_VECT]; 867c478bd9Sstevel@tonic-gate struct av_head softvect[LOCK_LEVEL + 1]; 877c478bd9Sstevel@tonic-gate kmutex_t av_lock; 88dd4eeefdSeota /* 89dd4eeefdSeota * These are software interrupt handlers dedicated to ddi timer. 90dd4eeefdSeota * The interrupt levels up to 10 are supported, but high interrupts 91dd4eeefdSeota * must not be used there. 92dd4eeefdSeota */ 93dd4eeefdSeota ddi_softint_hdl_impl_t softlevel_hdl[DDI_IPL_10] = { 94dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 1 */ 95dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 2 */ 96dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 3 */ 97dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 4 */ 98dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 5 */ 99dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 6 */ 100dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 7 */ 101dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 8 */ 102dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 9 */ 103dd4eeefdSeota {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 10 */ 104dd4eeefdSeota }; 1057c478bd9Sstevel@tonic-gate ddi_softint_hdl_impl_t softlevel1_hdl = 106e23a7e34Slq150181 {0, NULL, NULL, NULL, 0, NULL, NULL, NULL}; 1077c478bd9Sstevel@tonic-gate 108e23a7e34Slq150181 /* 109e23a7e34Slq150181 * clear/check softint pending flag corresponding for 110e23a7e34Slq150181 * the current CPU 111e23a7e34Slq150181 */ 1127c478bd9Sstevel@tonic-gate void 113e23a7e34Slq150181 av_clear_softint_pending(av_softinfo_t *infop) 1147c478bd9Sstevel@tonic-gate { 115e23a7e34Slq150181 CPUSET_ATOMIC_DEL(infop->av_pending, CPU->cpu_seqid); 116e23a7e34Slq150181 } 117e23a7e34Slq150181 118e23a7e34Slq150181 boolean_t 119e23a7e34Slq150181 av_check_softint_pending(av_softinfo_t *infop, boolean_t check_all) 120e23a7e34Slq150181 { 121e23a7e34Slq150181 if (check_all) 122e23a7e34Slq150181 return (!CPUSET_ISNULL(infop->av_pending)); 123e23a7e34Slq150181 else 124e23a7e34Slq150181 return (CPU_IN_SET(infop->av_pending, CPU->cpu_seqid) != 0); 125e23a7e34Slq150181 } 126e23a7e34Slq150181 127e23a7e34Slq150181 /* 128a1af7ba0Scwb * This is the wrapper function which is generally used to set a softint 129a1af7ba0Scwb * pending 130a1af7ba0Scwb */ 131a1af7ba0Scwb void 132a1af7ba0Scwb av_set_softint_pending(int pri, av_softinfo_t *infop) 133a1af7ba0Scwb { 134a1af7ba0Scwb kdi_av_set_softint_pending(pri, infop); 135a1af7ba0Scwb } 136a1af7ba0Scwb 137a1af7ba0Scwb /* 138a1af7ba0Scwb * This is kmdb's private entry point to setsoftint called from kdi_siron 139e23a7e34Slq150181 * It first sets our av softint pending bit for the current CPU, 140e23a7e34Slq150181 * then it sets the CPU softint pending bit for pri. 141e23a7e34Slq150181 */ 142e23a7e34Slq150181 void 143a1af7ba0Scwb kdi_av_set_softint_pending(int pri, av_softinfo_t *infop) 144e23a7e34Slq150181 { 145e23a7e34Slq150181 CPUSET_ATOMIC_ADD(infop->av_pending, CPU->cpu_seqid); 146e23a7e34Slq150181 1477c478bd9Sstevel@tonic-gate atomic_or_32((uint32_t *)&CPU->cpu_softinfo.st_pending, 1 << pri); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* 1517c478bd9Sstevel@tonic-gate * register nmi interrupt routine. The first arg is used only to order 1527c478bd9Sstevel@tonic-gate * various nmi interrupt service routines in the chain. Higher lvls will 1537c478bd9Sstevel@tonic-gate * be called first 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate int 1567c478bd9Sstevel@tonic-gate add_nmintr(int lvl, avfunc nmintr, char *name, caddr_t arg) 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate struct autovec *mem; 1597c478bd9Sstevel@tonic-gate struct autovec *p, *prev = NULL; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate if (nmintr == NULL) { 1627c478bd9Sstevel@tonic-gate printf("Attempt to add null vect for %s on nmi\n", name); 1637c478bd9Sstevel@tonic-gate return (0); 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 1687c478bd9Sstevel@tonic-gate mem->av_vector = nmintr; 1697c478bd9Sstevel@tonic-gate mem->av_intarg1 = arg; 1707c478bd9Sstevel@tonic-gate mem->av_intarg2 = NULL; 1717c478bd9Sstevel@tonic-gate mem->av_intr_id = NULL; 1727c478bd9Sstevel@tonic-gate mem->av_prilevel = lvl; 1730b38a8bdSahl mem->av_dip = NULL; 1747c478bd9Sstevel@tonic-gate mem->av_link = NULL; 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate mutex_enter(&av_lock); 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate if (!nmivect) { 1797c478bd9Sstevel@tonic-gate nmivect = mem; 1807c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 1817c478bd9Sstevel@tonic-gate return (1); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate /* find where it goes in list */ 1847c478bd9Sstevel@tonic-gate for (p = nmivect; p != NULL; p = p->av_link) { 1857c478bd9Sstevel@tonic-gate if (p->av_vector == nmintr && p->av_intarg1 == arg) { 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * already in list 1887c478bd9Sstevel@tonic-gate * So? Somebody added the same interrupt twice. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Driver already registered '%s'", 1917c478bd9Sstevel@tonic-gate name); 1927c478bd9Sstevel@tonic-gate kmem_free(mem, sizeof (struct autovec)); 1937c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 1947c478bd9Sstevel@tonic-gate return (0); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate if (p->av_prilevel < lvl) { 1977c478bd9Sstevel@tonic-gate if (p == nmivect) { /* it's at head of list */ 1987c478bd9Sstevel@tonic-gate mem->av_link = p; 1997c478bd9Sstevel@tonic-gate nmivect = mem; 2007c478bd9Sstevel@tonic-gate } else { 2017c478bd9Sstevel@tonic-gate mem->av_link = p; 2027c478bd9Sstevel@tonic-gate prev->av_link = mem; 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 2057c478bd9Sstevel@tonic-gate return (1); 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate prev = p; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate /* didn't find it, add it to the end */ 2117c478bd9Sstevel@tonic-gate prev->av_link = mem; 2127c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 2137c478bd9Sstevel@tonic-gate return (1); 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* 2187c478bd9Sstevel@tonic-gate * register a hardware interrupt handler. 2197ff178cdSJimmy Vetayases * 2207ff178cdSJimmy Vetayases * The autovect data structure only supports globally 256 interrupts. 2217ff178cdSJimmy Vetayases * In order to support 256 * #LocalAPIC interrupts, a new PSM module 2227ff178cdSJimmy Vetayases * apix is introduced. It defines PSM private data structures for the 2237ff178cdSJimmy Vetayases * interrupt handlers. The PSM module initializes addintr to a PSM 2247ff178cdSJimmy Vetayases * private function so that it could override add_avintr() to operate 2257ff178cdSJimmy Vetayases * on its private data structures. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate int 2287c478bd9Sstevel@tonic-gate add_avintr(void *intr_id, int lvl, avfunc xxintr, char *name, int vect, 2297a364d25Sschwartz caddr_t arg1, caddr_t arg2, uint64_t *ticksp, dev_info_t *dip) 2307c478bd9Sstevel@tonic-gate { 2317c478bd9Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 2327c478bd9Sstevel@tonic-gate avfunc f; 2337c478bd9Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 2347c478bd9Sstevel@tonic-gate ushort_t hi_pri; 2357c478bd9Sstevel@tonic-gate 2367ff178cdSJimmy Vetayases if (addintr) { 2377ff178cdSJimmy Vetayases return ((*addintr)(intr_id, lvl, xxintr, name, vect, 2387ff178cdSJimmy Vetayases arg1, arg2, ticksp, dip)); 2397ff178cdSJimmy Vetayases } 2407ff178cdSJimmy Vetayases 2417c478bd9Sstevel@tonic-gate if ((f = xxintr) == NULL) { 2427c478bd9Sstevel@tonic-gate printf("Attempt to add null vect for %s on vector %d\n", 2437c478bd9Sstevel@tonic-gate name, vect); 2447c478bd9Sstevel@tonic-gate return (0); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate vectindex = vect % MAX_VECT; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate vecp = &autovect[vectindex]; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * "hi_pri == 0" implies all entries on list are "unused", 2537c478bd9Sstevel@tonic-gate * which means that it's OK to just insert this one. 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate hi_pri = vecp->avh_hi_pri; 2567c478bd9Sstevel@tonic-gate if (vecp->avh_link && (hi_pri != 0)) { 2577c478bd9Sstevel@tonic-gate if (((hi_pri > LOCK_LEVEL) && (lvl < LOCK_LEVEL)) || 2587c478bd9Sstevel@tonic-gate ((hi_pri < LOCK_LEVEL) && (lvl > LOCK_LEVEL))) { 2597c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, multilevel2, name, lvl, vect, 2607c478bd9Sstevel@tonic-gate hi_pri); 2617c478bd9Sstevel@tonic-gate return (0); 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate if ((vecp->avh_lo_pri != lvl) || (hi_pri != lvl)) 2647c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, multilevel, vect); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 267e23a7e34Slq150181 insert_av(intr_id, vecp, f, arg1, arg2, ticksp, lvl, dip); 2687c478bd9Sstevel@tonic-gate s = splhi(); 2697c478bd9Sstevel@tonic-gate /* 2707c478bd9Sstevel@tonic-gate * do what ever machine specific things are necessary 2717c478bd9Sstevel@tonic-gate * to set priority level (e.g. set picmasks) 2727c478bd9Sstevel@tonic-gate */ 2737c478bd9Sstevel@tonic-gate mutex_enter(&av_lock); 2747c478bd9Sstevel@tonic-gate (*addspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 2757c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 2767c478bd9Sstevel@tonic-gate splx(s); 2777c478bd9Sstevel@tonic-gate return (1); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate void 2827c478bd9Sstevel@tonic-gate update_avsoftintr_args(void *intr_id, int lvl, caddr_t arg2) 2837c478bd9Sstevel@tonic-gate { 2847c478bd9Sstevel@tonic-gate struct autovec *p; 2857c478bd9Sstevel@tonic-gate struct autovec *target = NULL; 2867c478bd9Sstevel@tonic-gate struct av_head *vectp = (struct av_head *)&softvect[lvl]; 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate for (p = vectp->avh_link; p && p->av_vector; p = p->av_link) { 2897c478bd9Sstevel@tonic-gate if (p->av_intr_id == intr_id) { 2907c478bd9Sstevel@tonic-gate target = p; 2917c478bd9Sstevel@tonic-gate break; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (target == NULL) 2967c478bd9Sstevel@tonic-gate return; 2977c478bd9Sstevel@tonic-gate target->av_intarg2 = arg2; 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Register a software interrupt handler 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate int 3047c478bd9Sstevel@tonic-gate add_avsoftintr(void *intr_id, int lvl, avfunc xxintr, char *name, 3057c478bd9Sstevel@tonic-gate caddr_t arg1, caddr_t arg2) 3067c478bd9Sstevel@tonic-gate { 3077c478bd9Sstevel@tonic-gate int slvl; 308e23a7e34Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) 3117c478bd9Sstevel@tonic-gate return (add_avintr(intr_id, lvl, xxintr, 3127a364d25Sschwartz name, slvl, arg1, arg2, NULL, NULL)); 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate if (intr_id == NULL) { 3157c478bd9Sstevel@tonic-gate printf("Attempt to add null intr_id for %s on level %d\n", 3167c478bd9Sstevel@tonic-gate name, lvl); 3177c478bd9Sstevel@tonic-gate return (0); 3187c478bd9Sstevel@tonic-gate } 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate if (xxintr == NULL) { 3217c478bd9Sstevel@tonic-gate printf("Attempt to add null handler for %s on level %d\n", 3227c478bd9Sstevel@tonic-gate name, lvl); 3237c478bd9Sstevel@tonic-gate return (0); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate if (lvl <= 0 || lvl > LOCK_LEVEL) { 3277c478bd9Sstevel@tonic-gate printf(badsoft, lvl, name); 3287c478bd9Sstevel@tonic-gate return (0); 3297c478bd9Sstevel@tonic-gate } 330e23a7e34Slq150181 331e23a7e34Slq150181 if (hdlp->ih_pending == NULL) { 332e23a7e34Slq150181 hdlp->ih_pending = 333e23a7e34Slq150181 kmem_zalloc(sizeof (av_softinfo_t), KM_SLEEP); 3347c478bd9Sstevel@tonic-gate } 335e23a7e34Slq150181 336e23a7e34Slq150181 insert_av(intr_id, &softvect[lvl], xxintr, arg1, arg2, NULL, lvl, NULL); 337e23a7e34Slq150181 3387c478bd9Sstevel@tonic-gate return (1); 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate 3417ff178cdSJimmy Vetayases /* 3427ff178cdSJimmy Vetayases * insert an interrupt vector into chain by its priority from high 3437ff178cdSJimmy Vetayases * to low 3447ff178cdSJimmy Vetayases */ 345e23a7e34Slq150181 static void 3467c478bd9Sstevel@tonic-gate insert_av(void *intr_id, struct av_head *vectp, avfunc f, caddr_t arg1, 3477a364d25Sschwartz caddr_t arg2, uint64_t *ticksp, int pri_level, dev_info_t *dip) 3487c478bd9Sstevel@tonic-gate { 3497c478bd9Sstevel@tonic-gate /* 3507c478bd9Sstevel@tonic-gate * Protect rewrites of the list 3517c478bd9Sstevel@tonic-gate */ 3527ff178cdSJimmy Vetayases struct autovec *p, *prep, *mem; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP); 3557c478bd9Sstevel@tonic-gate mem->av_vector = f; 3567c478bd9Sstevel@tonic-gate mem->av_intarg1 = arg1; 3577c478bd9Sstevel@tonic-gate mem->av_intarg2 = arg2; 3587a364d25Sschwartz mem->av_ticksp = ticksp; 3597c478bd9Sstevel@tonic-gate mem->av_intr_id = intr_id; 3607c478bd9Sstevel@tonic-gate mem->av_prilevel = pri_level; 3617c478bd9Sstevel@tonic-gate mem->av_dip = dip; 3627c478bd9Sstevel@tonic-gate mem->av_link = NULL; 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate mutex_enter(&av_lock); 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate if (vectp->avh_link == NULL) { /* Nothing on list - put it at head */ 3677c478bd9Sstevel@tonic-gate vectp->avh_link = mem; 3687c478bd9Sstevel@tonic-gate vectp->avh_hi_pri = vectp->avh_lo_pri = (ushort_t)pri_level; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 371e23a7e34Slq150181 return; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /* find where it goes in list */ 3757ff178cdSJimmy Vetayases prep = NULL; 3767c478bd9Sstevel@tonic-gate for (p = vectp->avh_link; p != NULL; p = p->av_link) { 3777ff178cdSJimmy Vetayases if (p->av_vector && p->av_prilevel <= pri_level) 3787ff178cdSJimmy Vetayases break; 3797ff178cdSJimmy Vetayases prep = p; 3807ff178cdSJimmy Vetayases } 3817ff178cdSJimmy Vetayases if (prep != NULL) { 3827ff178cdSJimmy Vetayases if (prep->av_vector == NULL) { /* freed struct available */ 3837ff178cdSJimmy Vetayases p = prep; 3847c478bd9Sstevel@tonic-gate p->av_intarg1 = arg1; 3857c478bd9Sstevel@tonic-gate p->av_intarg2 = arg2; 3867a364d25Sschwartz p->av_ticksp = ticksp; 3877c478bd9Sstevel@tonic-gate p->av_intr_id = intr_id; 3887c478bd9Sstevel@tonic-gate p->av_prilevel = pri_level; 3890b38a8bdSahl p->av_dip = dip; 3907c478bd9Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 3917c478bd9Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 3947c478bd9Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 3957c478bd9Sstevel@tonic-gate } 396843e1988Sjohnlev /* 397843e1988Sjohnlev * To prevent calling service routine before args 398843e1988Sjohnlev * and ticksp are ready fill in vector last. 399843e1988Sjohnlev */ 4007c478bd9Sstevel@tonic-gate p->av_vector = f; 4017c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 402843e1988Sjohnlev kmem_free(mem, sizeof (struct autovec)); 403e23a7e34Slq150181 return; 4047c478bd9Sstevel@tonic-gate } 4057ff178cdSJimmy Vetayases 4067ff178cdSJimmy Vetayases mem->av_link = prep->av_link; 4077ff178cdSJimmy Vetayases prep->av_link = mem; 4087ff178cdSJimmy Vetayases } else { 4097c478bd9Sstevel@tonic-gate /* insert new intpt at beginning of chain */ 4107c478bd9Sstevel@tonic-gate mem->av_link = vectp->avh_link; 4117c478bd9Sstevel@tonic-gate vectp->avh_link = mem; 4127ff178cdSJimmy Vetayases } 4137c478bd9Sstevel@tonic-gate if (pri_level > (int)vectp->avh_hi_pri) { 4147c478bd9Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)pri_level; 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate if (pri_level < (int)vectp->avh_lo_pri) { 4177c478bd9Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)pri_level; 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 422e23a7e34Slq150181 static int 423e23a7e34Slq150181 av_rem_softintr(void *intr_id, int lvl, avfunc xxintr, boolean_t rem_softinfo) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 4267c478bd9Sstevel@tonic-gate int slvl; 427e23a7e34Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 428e23a7e34Slq150181 av_softinfo_t *infop = (av_softinfo_t *)hdlp->ih_pending; 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate if (xxintr == NULL) 4317c478bd9Sstevel@tonic-gate return (0); 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate if ((slvl = slvltovect(lvl)) != -1) { 4347c478bd9Sstevel@tonic-gate rem_avintr(intr_id, lvl, xxintr, slvl); 4357c478bd9Sstevel@tonic-gate return (1); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate if (lvl <= 0 && lvl >= LOCK_LEVEL) { 4397c478bd9Sstevel@tonic-gate return (0); 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate vecp = &softvect[lvl]; 4427c478bd9Sstevel@tonic-gate remove_av(intr_id, vecp, xxintr, lvl, 0); 4437c478bd9Sstevel@tonic-gate 444e23a7e34Slq150181 if (rem_softinfo) { 445e23a7e34Slq150181 kmem_free(infop, sizeof (av_softinfo_t)); 446e23a7e34Slq150181 hdlp->ih_pending = NULL; 447e23a7e34Slq150181 } 448e23a7e34Slq150181 4497c478bd9Sstevel@tonic-gate return (1); 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate 452e23a7e34Slq150181 int 453e23a7e34Slq150181 av_softint_movepri(void *intr_id, int old_lvl) 454e23a7e34Slq150181 { 455e23a7e34Slq150181 int ret; 456e23a7e34Slq150181 ddi_softint_hdl_impl_t *hdlp = (ddi_softint_hdl_impl_t *)intr_id; 457e23a7e34Slq150181 458e23a7e34Slq150181 ret = add_avsoftintr(intr_id, hdlp->ih_pri, hdlp->ih_cb_func, 459e23a7e34Slq150181 DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 460e23a7e34Slq150181 461e23a7e34Slq150181 if (ret) { 462e23a7e34Slq150181 (void) av_rem_softintr(intr_id, old_lvl, hdlp->ih_cb_func, 463e23a7e34Slq150181 B_FALSE); 464e23a7e34Slq150181 } 465e23a7e34Slq150181 466e23a7e34Slq150181 return (ret); 467e23a7e34Slq150181 } 468e23a7e34Slq150181 469e23a7e34Slq150181 /* 470e23a7e34Slq150181 * Remove a driver from the autovector list. 471e23a7e34Slq150181 */ 472e23a7e34Slq150181 int 473e23a7e34Slq150181 rem_avsoftintr(void *intr_id, int lvl, avfunc xxintr) 474e23a7e34Slq150181 { 475e23a7e34Slq150181 return (av_rem_softintr(intr_id, lvl, xxintr, B_TRUE)); 476e23a7e34Slq150181 } 477e23a7e34Slq150181 4787ff178cdSJimmy Vetayases /* 4797ff178cdSJimmy Vetayases * Remove specified interrupt handler. 4807ff178cdSJimmy Vetayases * 4817ff178cdSJimmy Vetayases * PSM module could initialize remintr to some PSM private function 4827ff178cdSJimmy Vetayases * so that it could override rem_avintr() to operate on its private 4837ff178cdSJimmy Vetayases * data structures. 4847ff178cdSJimmy Vetayases */ 4857c478bd9Sstevel@tonic-gate void 4867c478bd9Sstevel@tonic-gate rem_avintr(void *intr_id, int lvl, avfunc xxintr, int vect) 4877c478bd9Sstevel@tonic-gate { 4887c478bd9Sstevel@tonic-gate struct av_head *vecp = (struct av_head *)0; 4897c478bd9Sstevel@tonic-gate avfunc f; 4907c478bd9Sstevel@tonic-gate int s, vectindex; /* save old spl value */ 4917c478bd9Sstevel@tonic-gate 4927ff178cdSJimmy Vetayases if (remintr) { 4937ff178cdSJimmy Vetayases (*remintr)(intr_id, lvl, xxintr, vect); 4947ff178cdSJimmy Vetayases return; 4957ff178cdSJimmy Vetayases } 4967ff178cdSJimmy Vetayases 4977c478bd9Sstevel@tonic-gate if ((f = xxintr) == NULL) 4987c478bd9Sstevel@tonic-gate return; 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate vectindex = vect % MAX_VECT; 5017c478bd9Sstevel@tonic-gate vecp = &autovect[vectindex]; 5027c478bd9Sstevel@tonic-gate remove_av(intr_id, vecp, f, lvl, vect); 5037c478bd9Sstevel@tonic-gate s = splhi(); 5047c478bd9Sstevel@tonic-gate mutex_enter(&av_lock); 5057c478bd9Sstevel@tonic-gate (*delspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri); 5067c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 5077c478bd9Sstevel@tonic-gate splx(s); 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate /* 5127c478bd9Sstevel@tonic-gate * After having made a change to an autovector list, wait until we have 5137c478bd9Sstevel@tonic-gate * seen each cpu not executing an interrupt at that level--so we know our 5147c478bd9Sstevel@tonic-gate * change has taken effect completely (no old state in registers, etc). 5157c478bd9Sstevel@tonic-gate */ 5167ff178cdSJimmy Vetayases void 5177c478bd9Sstevel@tonic-gate wait_till_seen(int ipl) 5187c478bd9Sstevel@tonic-gate { 5197c478bd9Sstevel@tonic-gate int cpu_in_chain, cix; 5207c478bd9Sstevel@tonic-gate struct cpu *cpup; 5217c478bd9Sstevel@tonic-gate cpuset_t cpus_to_check; 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate CPUSET_ALL(cpus_to_check); 5247c478bd9Sstevel@tonic-gate do { 5257c478bd9Sstevel@tonic-gate cpu_in_chain = 0; 5267c478bd9Sstevel@tonic-gate for (cix = 0; cix < NCPU; cix++) { 5277c478bd9Sstevel@tonic-gate cpup = cpu[cix]; 5287c478bd9Sstevel@tonic-gate if (cpup != NULL && CPU_IN_SET(cpus_to_check, cix)) { 529e8bb33d8SColin Yi if (INTR_ACTIVE(cpup, ipl)) { 5307c478bd9Sstevel@tonic-gate cpu_in_chain = 1; 5317c478bd9Sstevel@tonic-gate } else { 5327c478bd9Sstevel@tonic-gate CPUSET_DEL(cpus_to_check, cix); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate } while (cpu_in_chain); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 539843e1988Sjohnlev static uint64_t dummy_tick; 540843e1988Sjohnlev 5417c478bd9Sstevel@tonic-gate /* remove an interrupt vector from the chain */ 5427c478bd9Sstevel@tonic-gate static void 5437c478bd9Sstevel@tonic-gate remove_av(void *intr_id, struct av_head *vectp, avfunc f, int pri_level, 5447c478bd9Sstevel@tonic-gate int vect) 5457c478bd9Sstevel@tonic-gate { 546843e1988Sjohnlev struct autovec *p, *target; 5477c478bd9Sstevel@tonic-gate int lo_pri, hi_pri; 5487c478bd9Sstevel@tonic-gate int ipl; 5497c478bd9Sstevel@tonic-gate /* 5507c478bd9Sstevel@tonic-gate * Protect rewrites of the list 5517c478bd9Sstevel@tonic-gate */ 5527c478bd9Sstevel@tonic-gate target = NULL; 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate mutex_enter(&av_lock); 5557c478bd9Sstevel@tonic-gate ipl = pri_level; 5567c478bd9Sstevel@tonic-gate lo_pri = MAXIPL; 5577c478bd9Sstevel@tonic-gate hi_pri = 0; 558843e1988Sjohnlev for (p = vectp->avh_link; p; p = p->av_link) { 5597c478bd9Sstevel@tonic-gate if ((p->av_vector == f) && (p->av_intr_id == intr_id)) { 5607c478bd9Sstevel@tonic-gate /* found the handler */ 5617c478bd9Sstevel@tonic-gate target = p; 5627c478bd9Sstevel@tonic-gate continue; 5637c478bd9Sstevel@tonic-gate } 564843e1988Sjohnlev if (p->av_vector != NULL) { 5657c478bd9Sstevel@tonic-gate if (p->av_prilevel > hi_pri) 5667c478bd9Sstevel@tonic-gate hi_pri = p->av_prilevel; 5677c478bd9Sstevel@tonic-gate if (p->av_prilevel < lo_pri) 5687c478bd9Sstevel@tonic-gate lo_pri = p->av_prilevel; 5697c478bd9Sstevel@tonic-gate } 570843e1988Sjohnlev } 5717c478bd9Sstevel@tonic-gate if (ipl < hi_pri) 5727c478bd9Sstevel@tonic-gate ipl = hi_pri; 5737c478bd9Sstevel@tonic-gate if (target == NULL) { /* not found */ 5747c478bd9Sstevel@tonic-gate printf("Couldn't remove function %p at %d, %d\n", 5757c478bd9Sstevel@tonic-gate (void *)f, vect, pri_level); 5767c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 5777c478bd9Sstevel@tonic-gate return; 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate /* 581843e1988Sjohnlev * This drops the handler from the chain, it can no longer be called. 582843e1988Sjohnlev * However, there is no guarantee that the handler is not currently 583843e1988Sjohnlev * still executing. 5847c478bd9Sstevel@tonic-gate */ 585843e1988Sjohnlev target->av_vector = NULL; 586843e1988Sjohnlev /* 587843e1988Sjohnlev * There is a race where we could be just about to pick up the ticksp 588843e1988Sjohnlev * pointer to increment it after returning from the service routine 589843e1988Sjohnlev * in av_dispatch_autovect. Rather than NULL it out let's just point 590843e1988Sjohnlev * it off to something safe so that any final tick update attempt 591843e1988Sjohnlev * won't fault. 592843e1988Sjohnlev */ 593843e1988Sjohnlev target->av_ticksp = &dummy_tick; 5947c478bd9Sstevel@tonic-gate wait_till_seen(ipl); 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate if (lo_pri > hi_pri) { /* the chain is now empty */ 5977c478bd9Sstevel@tonic-gate /* Leave the unused entries here for probable future use */ 5987c478bd9Sstevel@tonic-gate vectp->avh_lo_pri = MAXIPL; 5997c478bd9Sstevel@tonic-gate vectp->avh_hi_pri = 0; 6007c478bd9Sstevel@tonic-gate } else { 6017c478bd9Sstevel@tonic-gate if ((int)vectp->avh_lo_pri < lo_pri) 6027c478bd9Sstevel@tonic-gate vectp->avh_lo_pri = (ushort_t)lo_pri; 6037c478bd9Sstevel@tonic-gate if ((int)vectp->avh_hi_pri > hi_pri) 6047c478bd9Sstevel@tonic-gate vectp->avh_hi_pri = (ushort_t)hi_pri; 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate mutex_exit(&av_lock); 6077c478bd9Sstevel@tonic-gate wait_till_seen(ipl); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate /* 611a1af7ba0Scwb * kmdb uses siron (and thus setsoftint) while the world is stopped in order to 612a1af7ba0Scwb * inform its driver component that there's work to be done. We need to keep 613a1af7ba0Scwb * DTrace from instrumenting kmdb's siron and setsoftint. We duplicate siron, 614a1af7ba0Scwb * giving kmdb's version a kdi prefix to keep DTrace at bay. We also 615a1af7ba0Scwb * provide a version of the various setsoftint functions available for kmdb to 616a1af7ba0Scwb * use using a kdi_ prefix while the main *setsoftint() functionality is 617a1af7ba0Scwb * implemented as a wrapper. This allows tracing, while still providing a 618a1af7ba0Scwb * way for kmdb to sneak in unmolested. 619a1af7ba0Scwb */ 620a1af7ba0Scwb void 621a1af7ba0Scwb kdi_siron(void) 622a1af7ba0Scwb { 623a1af7ba0Scwb (*kdisetsoftint)(1, softlevel1_hdl.ih_pending); 624a1af7ba0Scwb } 625a1af7ba0Scwb 626a1af7ba0Scwb /* 6277c478bd9Sstevel@tonic-gate * Trigger a soft interrupt. 6287c478bd9Sstevel@tonic-gate */ 6297c478bd9Sstevel@tonic-gate void 6307c478bd9Sstevel@tonic-gate siron(void) 6317c478bd9Sstevel@tonic-gate { 632dd4eeefdSeota /* Level 1 software interrupt */ 633e23a7e34Slq150181 (*setsoftint)(1, softlevel1_hdl.ih_pending); 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate /* 637dd4eeefdSeota * Trigger software interrupts dedicated to ddi timer. 638dd4eeefdSeota */ 639dd4eeefdSeota void 640dd4eeefdSeota sir_on(int level) 641dd4eeefdSeota { 642dd4eeefdSeota ASSERT(level >= DDI_IPL_1 && level <= DDI_IPL_10); 643dd4eeefdSeota (*setsoftint)(level, softlevel_hdl[level-1].ih_pending); 644dd4eeefdSeota } 645dd4eeefdSeota 646dd4eeefdSeota /* 6473aedfe0bSmishra * The handler which is executed on the target CPU. 6483aedfe0bSmishra */ 6493aedfe0bSmishra /*ARGSUSED*/ 6503aedfe0bSmishra static int 6513aedfe0bSmishra siron_poke_intr(xc_arg_t a1, xc_arg_t a2, xc_arg_t a3) 6523aedfe0bSmishra { 6533aedfe0bSmishra siron(); 6543aedfe0bSmishra return (0); 6553aedfe0bSmishra } 6563aedfe0bSmishra 6573aedfe0bSmishra /* 6583aedfe0bSmishra * May get called from softcall to poke CPUs. 6593aedfe0bSmishra */ 6603aedfe0bSmishra void 6613aedfe0bSmishra siron_poke_cpu(cpuset_t poke) 6623aedfe0bSmishra { 6633aedfe0bSmishra int cpuid = CPU->cpu_id; 6643aedfe0bSmishra 6653aedfe0bSmishra /* 6663aedfe0bSmishra * If we are poking to ourself then we can simply 6673aedfe0bSmishra * generate level1 using siron() 6683aedfe0bSmishra */ 6693aedfe0bSmishra if (CPU_IN_SET(poke, cpuid)) { 6703aedfe0bSmishra siron(); 6713aedfe0bSmishra CPUSET_DEL(poke, cpuid); 6723aedfe0bSmishra if (CPUSET_ISNULL(poke)) 6733aedfe0bSmishra return; 6743aedfe0bSmishra } 6753aedfe0bSmishra 676f34a7178SJoe Bonasera xc_call(0, 0, 0, CPUSET2BV(poke), (xc_func_t)siron_poke_intr); 6773aedfe0bSmishra } 6783aedfe0bSmishra 6793aedfe0bSmishra /* 6807c478bd9Sstevel@tonic-gate * Walk the autovector table for this vector, invoking each 6817c478bd9Sstevel@tonic-gate * interrupt handler as we go. 6827c478bd9Sstevel@tonic-gate */ 6837a364d25Sschwartz 6847a364d25Sschwartz extern uint64_t intr_get_time(void); 6857a364d25Sschwartz 6867c478bd9Sstevel@tonic-gate void 6877c478bd9Sstevel@tonic-gate av_dispatch_autovect(uint_t vec) 6887c478bd9Sstevel@tonic-gate { 6897c478bd9Sstevel@tonic-gate struct autovec *av; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate while ((av = autovect[vec].avh_link) != NULL) { 6947c478bd9Sstevel@tonic-gate uint_t numcalled = 0; 6957c478bd9Sstevel@tonic-gate uint_t claimed = 0; 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate for (; av; av = av->av_link) { 6987c478bd9Sstevel@tonic-gate uint_t r; 6997c478bd9Sstevel@tonic-gate uint_t (*intr)() = av->av_vector; 7007c478bd9Sstevel@tonic-gate caddr_t arg1 = av->av_intarg1; 7017c478bd9Sstevel@tonic-gate caddr_t arg2 = av->av_intarg2; 7027c478bd9Sstevel@tonic-gate dev_info_t *dip = av->av_dip; 7037c478bd9Sstevel@tonic-gate 704843e1988Sjohnlev /* 705843e1988Sjohnlev * We must walk the entire chain. Removed handlers 706843e1988Sjohnlev * may be anywhere in the chain. 707843e1988Sjohnlev */ 7087c478bd9Sstevel@tonic-gate if (intr == NULL) 709843e1988Sjohnlev continue; 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate DTRACE_PROBE4(interrupt__start, dev_info_t *, dip, 7127c478bd9Sstevel@tonic-gate void *, intr, caddr_t, arg1, caddr_t, arg2); 7137c478bd9Sstevel@tonic-gate r = (*intr)(arg1, arg2); 7147c478bd9Sstevel@tonic-gate DTRACE_PROBE4(interrupt__complete, dev_info_t *, dip, 7157c478bd9Sstevel@tonic-gate void *, intr, caddr_t, arg1, uint_t, r); 716ae115bc7Smrj numcalled++; 7177c478bd9Sstevel@tonic-gate claimed |= r; 7187a364d25Sschwartz if (av->av_ticksp && av->av_prilevel <= LOCK_LEVEL) 7197a364d25Sschwartz atomic_add_64(av->av_ticksp, intr_get_time()); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate /* 7237c478bd9Sstevel@tonic-gate * If there's only one interrupt handler in the chain, 7247c478bd9Sstevel@tonic-gate * or if no-one claimed the interrupt at all give up now. 7257c478bd9Sstevel@tonic-gate */ 7267c478bd9Sstevel@tonic-gate if (numcalled == 1 || claimed == 0) 7277c478bd9Sstevel@tonic-gate break; 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* 7327c478bd9Sstevel@tonic-gate * Call every soft interrupt handler we can find at this level once. 7337c478bd9Sstevel@tonic-gate */ 7347c478bd9Sstevel@tonic-gate void 7357c478bd9Sstevel@tonic-gate av_dispatch_softvect(uint_t pil) 7367c478bd9Sstevel@tonic-gate { 7377c478bd9Sstevel@tonic-gate struct autovec *av; 7387c478bd9Sstevel@tonic-gate ddi_softint_hdl_impl_t *hdlp; 7397c478bd9Sstevel@tonic-gate uint_t (*intr)(); 7407c478bd9Sstevel@tonic-gate caddr_t arg1; 7417c478bd9Sstevel@tonic-gate caddr_t arg2; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 7447c478bd9Sstevel@tonic-gate ASSERT(pil >= 0 && pil <= PIL_MAX); 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate for (av = softvect[pil].avh_link; av; av = av->av_link) { 747843e1988Sjohnlev /* 748843e1988Sjohnlev * We must walk the entire chain. Removed handlers 749843e1988Sjohnlev * may be anywhere in the chain. 750843e1988Sjohnlev */ 7517c478bd9Sstevel@tonic-gate if ((intr = av->av_vector) == NULL) 752843e1988Sjohnlev continue; 7537c478bd9Sstevel@tonic-gate arg1 = av->av_intarg1; 7547c478bd9Sstevel@tonic-gate arg2 = av->av_intarg2; 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate hdlp = (ddi_softint_hdl_impl_t *)av->av_intr_id; 7577c478bd9Sstevel@tonic-gate ASSERT(hdlp); 7587c478bd9Sstevel@tonic-gate 759e23a7e34Slq150181 /* 760e23a7e34Slq150181 * Each cpu has its own pending bit in hdlp->ih_pending, 761e23a7e34Slq150181 * here av_check/clear_softint_pending is just checking 762e23a7e34Slq150181 * and clearing the pending bit for the current cpu, who 763e23a7e34Slq150181 * has just triggered a softint. 764e23a7e34Slq150181 */ 765e23a7e34Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) { 766e23a7e34Slq150181 av_clear_softint_pending(hdlp->ih_pending); 7677c478bd9Sstevel@tonic-gate (void) (*intr)(arg1, arg2); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate } 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate struct regs; 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate /* 7757c478bd9Sstevel@tonic-gate * Call every NMI handler we know of once. 7767c478bd9Sstevel@tonic-gate */ 7777c478bd9Sstevel@tonic-gate void 7787c478bd9Sstevel@tonic-gate av_dispatch_nmivect(struct regs *rp) 7797c478bd9Sstevel@tonic-gate { 7807c478bd9Sstevel@tonic-gate struct autovec *av; 7817c478bd9Sstevel@tonic-gate 7827c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate for (av = nmivect; av; av = av->av_link) 7857c478bd9Sstevel@tonic-gate (void) (av->av_vector)(av->av_intarg1, rp); 7867c478bd9Sstevel@tonic-gate } 787