xref: /titanic_51/usr/src/uts/common/io/avintr.c (revision dd4eeefdb8e4583c47e28a7f315db6087931ef06)
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 /*
22ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Autovectored Interrupt Configuration and Deconfiguration
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
347c478bd9Sstevel@tonic-gate #include <sys/trap.h>
357c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
367c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
377c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/machlock.h>
397c478bd9Sstevel@tonic-gate #include <sys/systm.h>
407c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
417c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
427c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
437c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
447c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
457c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h>
467c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
477c478bd9Sstevel@tonic-gate #include <sys/stack.h>
487c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
49843e1988Sjohnlev #ifdef __xpv
50843e1988Sjohnlev #include <sys/evtchn_impl.h>
51843e1988Sjohnlev #endif
527c478bd9Sstevel@tonic-gate 
53e23a7e34Slq150181 typedef struct av_softinfo {
54e23a7e34Slq150181 	cpuset_t	av_pending;	/* pending bitmasks */
55e23a7e34Slq150181 } av_softinfo_t;
56e23a7e34Slq150181 
57e23a7e34Slq150181 static void insert_av(void *intr_id, struct av_head *vectp, avfunc f,
587a364d25Sschwartz 	caddr_t arg1, caddr_t arg2, uint64_t *ticksp, int pri_level,
597a364d25Sschwartz 	dev_info_t *dip);
607c478bd9Sstevel@tonic-gate static void remove_av(void *intr_id, struct av_head *vectp, avfunc f,
617c478bd9Sstevel@tonic-gate 	int pri_level, int vect);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * Arrange for a driver to be called when a particular
657c478bd9Sstevel@tonic-gate  * auto-vectored interrupt occurs.
667c478bd9Sstevel@tonic-gate  * NOTE: if a device can generate interrupts on more than
677c478bd9Sstevel@tonic-gate  * one level, or if a driver services devices that interrupt
687c478bd9Sstevel@tonic-gate  * on more than one level, then the driver should install
697c478bd9Sstevel@tonic-gate  * itself on each of those levels.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate static char badsoft[] =
727c478bd9Sstevel@tonic-gate 	"add_avintr: bad soft interrupt level %d for driver '%s'\n";
737c478bd9Sstevel@tonic-gate static char multilevel[] =
747c478bd9Sstevel@tonic-gate 	"!IRQ%d is being shared by drivers with different interrupt levels.\n"
757c478bd9Sstevel@tonic-gate 	"This may result in reduced system performance.";
767c478bd9Sstevel@tonic-gate static char multilevel2[] =
777c478bd9Sstevel@tonic-gate 	"Cannot register interrupt for '%s' device at IPL %d because it\n"
787c478bd9Sstevel@tonic-gate 	"conflicts with another device using the same vector %d with an IPL\n"
797c478bd9Sstevel@tonic-gate 	"of %d. Reconfigure the conflicting devices to use different vectors.";
807c478bd9Sstevel@tonic-gate 
81843e1988Sjohnlev #ifdef __xpv
82843e1988Sjohnlev #define	MAX_VECT	NR_IRQS
83843e1988Sjohnlev #else
847c478bd9Sstevel@tonic-gate #define	MAX_VECT	256
85843e1988Sjohnlev #endif
86843e1988Sjohnlev 
877c478bd9Sstevel@tonic-gate struct autovec *nmivect = NULL;
887c478bd9Sstevel@tonic-gate struct av_head autovect[MAX_VECT];
897c478bd9Sstevel@tonic-gate struct av_head softvect[LOCK_LEVEL + 1];
907c478bd9Sstevel@tonic-gate kmutex_t av_lock;
91*dd4eeefdSeota /*
92*dd4eeefdSeota  * These are software interrupt handlers dedicated to ddi timer.
93*dd4eeefdSeota  * The interrupt levels up to 10 are supported, but high interrupts
94*dd4eeefdSeota  * must not be used there.
95*dd4eeefdSeota  */
96*dd4eeefdSeota ddi_softint_hdl_impl_t softlevel_hdl[DDI_IPL_10] = {
97*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 1 */
98*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 2 */
99*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 3 */
100*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 4 */
101*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 5 */
102*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 6 */
103*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 7 */
104*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 8 */
105*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 9 */
106*dd4eeefdSeota 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL}, /* level 10 */
107*dd4eeefdSeota };
1087c478bd9Sstevel@tonic-gate ddi_softint_hdl_impl_t softlevel1_hdl =
109e23a7e34Slq150181 	{0, NULL, NULL, NULL, 0, NULL, NULL, NULL};
1107c478bd9Sstevel@tonic-gate 
111e23a7e34Slq150181 /*
112e23a7e34Slq150181  * clear/check softint pending flag corresponding for
113e23a7e34Slq150181  * the current CPU
114e23a7e34Slq150181  */
1157c478bd9Sstevel@tonic-gate void
116e23a7e34Slq150181 av_clear_softint_pending(av_softinfo_t *infop)
1177c478bd9Sstevel@tonic-gate {
118e23a7e34Slq150181 	CPUSET_ATOMIC_DEL(infop->av_pending, CPU->cpu_seqid);
119e23a7e34Slq150181 }
120e23a7e34Slq150181 
121e23a7e34Slq150181 boolean_t
122e23a7e34Slq150181 av_check_softint_pending(av_softinfo_t *infop, boolean_t check_all)
123e23a7e34Slq150181 {
124e23a7e34Slq150181 	if (check_all)
125e23a7e34Slq150181 		return (!CPUSET_ISNULL(infop->av_pending));
126e23a7e34Slq150181 	else
127e23a7e34Slq150181 		return (CPU_IN_SET(infop->av_pending, CPU->cpu_seqid) != 0);
128e23a7e34Slq150181 }
129e23a7e34Slq150181 
130e23a7e34Slq150181 /*
131a1af7ba0Scwb  * This is the wrapper function which is generally used to set a softint
132a1af7ba0Scwb  * pending
133a1af7ba0Scwb  */
134a1af7ba0Scwb void
135a1af7ba0Scwb av_set_softint_pending(int pri, av_softinfo_t *infop)
136a1af7ba0Scwb {
137a1af7ba0Scwb 	kdi_av_set_softint_pending(pri, infop);
138a1af7ba0Scwb }
139a1af7ba0Scwb 
140a1af7ba0Scwb /*
141a1af7ba0Scwb  * This is kmdb's private entry point to setsoftint called from kdi_siron
142e23a7e34Slq150181  * It first sets our av softint pending bit for the current CPU,
143e23a7e34Slq150181  * then it sets the CPU softint pending bit for pri.
144e23a7e34Slq150181  */
145e23a7e34Slq150181 void
146a1af7ba0Scwb kdi_av_set_softint_pending(int pri, av_softinfo_t *infop)
147e23a7e34Slq150181 {
148e23a7e34Slq150181 	CPUSET_ATOMIC_ADD(infop->av_pending, CPU->cpu_seqid);
149e23a7e34Slq150181 
1507c478bd9Sstevel@tonic-gate 	atomic_or_32((uint32_t *)&CPU->cpu_softinfo.st_pending, 1 << pri);
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * register nmi interrupt routine. The first arg is used only to order
1557c478bd9Sstevel@tonic-gate  * various nmi interrupt service routines in the chain. Higher lvls will
1567c478bd9Sstevel@tonic-gate  * be called first
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate int
1597c478bd9Sstevel@tonic-gate add_nmintr(int lvl, avfunc nmintr, char *name, caddr_t arg)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate 	struct autovec  *mem;
1627c478bd9Sstevel@tonic-gate 	struct autovec *p, *prev = NULL;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if (nmintr == NULL) {
1657c478bd9Sstevel@tonic-gate 		printf("Attempt to add null vect for %s on nmi\n", name);
1667c478bd9Sstevel@tonic-gate 		return (0);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP);
1717c478bd9Sstevel@tonic-gate 	mem->av_vector = nmintr;
1727c478bd9Sstevel@tonic-gate 	mem->av_intarg1 = arg;
1737c478bd9Sstevel@tonic-gate 	mem->av_intarg2 = NULL;
1747c478bd9Sstevel@tonic-gate 	mem->av_intr_id = NULL;
1757c478bd9Sstevel@tonic-gate 	mem->av_prilevel = lvl;
1760b38a8bdSahl 	mem->av_dip = NULL;
1777c478bd9Sstevel@tonic-gate 	mem->av_link = NULL;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	mutex_enter(&av_lock);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	if (!nmivect) {
1827c478bd9Sstevel@tonic-gate 		nmivect = mem;
1837c478bd9Sstevel@tonic-gate 		mutex_exit(&av_lock);
1847c478bd9Sstevel@tonic-gate 		return (1);
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 	/* find where it goes in list */
1877c478bd9Sstevel@tonic-gate 	for (p = nmivect; p != NULL; p = p->av_link) {
1887c478bd9Sstevel@tonic-gate 		if (p->av_vector == nmintr && p->av_intarg1 == arg) {
1897c478bd9Sstevel@tonic-gate 			/*
1907c478bd9Sstevel@tonic-gate 			 * already in list
1917c478bd9Sstevel@tonic-gate 			 * So? Somebody added the same interrupt twice.
1927c478bd9Sstevel@tonic-gate 			 */
1937c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, "Driver already registered '%s'",
1947c478bd9Sstevel@tonic-gate 			    name);
1957c478bd9Sstevel@tonic-gate 			kmem_free(mem, sizeof (struct autovec));
1967c478bd9Sstevel@tonic-gate 			mutex_exit(&av_lock);
1977c478bd9Sstevel@tonic-gate 			return (0);
1987c478bd9Sstevel@tonic-gate 		}
1997c478bd9Sstevel@tonic-gate 		if (p->av_prilevel < lvl) {
2007c478bd9Sstevel@tonic-gate 			if (p == nmivect) {   /* it's at head of list */
2017c478bd9Sstevel@tonic-gate 				mem->av_link = p;
2027c478bd9Sstevel@tonic-gate 				nmivect = mem;
2037c478bd9Sstevel@tonic-gate 			} else {
2047c478bd9Sstevel@tonic-gate 				mem->av_link = p;
2057c478bd9Sstevel@tonic-gate 				prev->av_link = mem;
2067c478bd9Sstevel@tonic-gate 			}
2077c478bd9Sstevel@tonic-gate 			mutex_exit(&av_lock);
2087c478bd9Sstevel@tonic-gate 			return (1);
2097c478bd9Sstevel@tonic-gate 		}
2107c478bd9Sstevel@tonic-gate 		prev = p;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate 	/* didn't find it, add it to the end */
2147c478bd9Sstevel@tonic-gate 	prev->av_link = mem;
2157c478bd9Sstevel@tonic-gate 	mutex_exit(&av_lock);
2167c478bd9Sstevel@tonic-gate 	return (1);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate  * register a hardware interrupt handler.
2227c478bd9Sstevel@tonic-gate  */
2237c478bd9Sstevel@tonic-gate int
2247c478bd9Sstevel@tonic-gate add_avintr(void *intr_id, int lvl, avfunc xxintr, char *name, int vect,
2257a364d25Sschwartz     caddr_t arg1, caddr_t arg2, uint64_t *ticksp, dev_info_t *dip)
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	struct av_head *vecp = (struct av_head *)0;
2287c478bd9Sstevel@tonic-gate 	avfunc f;
2297c478bd9Sstevel@tonic-gate 	int s, vectindex;			/* save old spl value */
2307c478bd9Sstevel@tonic-gate 	ushort_t hi_pri;
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	if ((f = xxintr) == NULL) {
2337c478bd9Sstevel@tonic-gate 		printf("Attempt to add null vect for %s on vector %d\n",
2347c478bd9Sstevel@tonic-gate 		    name, vect);
2357c478bd9Sstevel@tonic-gate 		return (0);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	}
2387c478bd9Sstevel@tonic-gate 	vectindex = vect % MAX_VECT;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	vecp = &autovect[vectindex];
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	/*
2437c478bd9Sstevel@tonic-gate 	 * "hi_pri == 0" implies all entries on list are "unused",
2447c478bd9Sstevel@tonic-gate 	 * which means that it's OK to just insert this one.
2457c478bd9Sstevel@tonic-gate 	 */
2467c478bd9Sstevel@tonic-gate 	hi_pri = vecp->avh_hi_pri;
2477c478bd9Sstevel@tonic-gate 	if (vecp->avh_link && (hi_pri != 0)) {
2487c478bd9Sstevel@tonic-gate 		if (((hi_pri > LOCK_LEVEL) && (lvl < LOCK_LEVEL)) ||
2497c478bd9Sstevel@tonic-gate 		    ((hi_pri < LOCK_LEVEL) && (lvl > LOCK_LEVEL))) {
2507c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, multilevel2, name, lvl, vect,
2517c478bd9Sstevel@tonic-gate 			    hi_pri);
2527c478bd9Sstevel@tonic-gate 			return (0);
2537c478bd9Sstevel@tonic-gate 		}
2547c478bd9Sstevel@tonic-gate 		if ((vecp->avh_lo_pri != lvl) || (hi_pri != lvl))
2557c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, multilevel, vect);
2567c478bd9Sstevel@tonic-gate 	}
2577c478bd9Sstevel@tonic-gate 
258e23a7e34Slq150181 	insert_av(intr_id, vecp, f, arg1, arg2, ticksp, lvl, dip);
2597c478bd9Sstevel@tonic-gate 	s = splhi();
2607c478bd9Sstevel@tonic-gate 	/*
2617c478bd9Sstevel@tonic-gate 	 * do what ever machine specific things are necessary
2627c478bd9Sstevel@tonic-gate 	 * to set priority level (e.g. set picmasks)
2637c478bd9Sstevel@tonic-gate 	 */
2647c478bd9Sstevel@tonic-gate 	mutex_enter(&av_lock);
2657c478bd9Sstevel@tonic-gate 	(*addspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri);
2667c478bd9Sstevel@tonic-gate 	mutex_exit(&av_lock);
2677c478bd9Sstevel@tonic-gate 	splx(s);
2687c478bd9Sstevel@tonic-gate 	return (1);
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate void
2737c478bd9Sstevel@tonic-gate update_avsoftintr_args(void *intr_id, int lvl, caddr_t arg2)
2747c478bd9Sstevel@tonic-gate {
2757c478bd9Sstevel@tonic-gate 	struct autovec *p;
2767c478bd9Sstevel@tonic-gate 	struct autovec *target = NULL;
2777c478bd9Sstevel@tonic-gate 	struct av_head *vectp = (struct av_head *)&softvect[lvl];
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	for (p = vectp->avh_link; p && p->av_vector; p = p->av_link) {
2807c478bd9Sstevel@tonic-gate 		if (p->av_intr_id == intr_id) {
2817c478bd9Sstevel@tonic-gate 			target = p;
2827c478bd9Sstevel@tonic-gate 			break;
2837c478bd9Sstevel@tonic-gate 		}
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	if (target == NULL)
2877c478bd9Sstevel@tonic-gate 		return;
2887c478bd9Sstevel@tonic-gate 	target->av_intarg2 = arg2;
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate  * Register a software interrupt handler
2937c478bd9Sstevel@tonic-gate  */
2947c478bd9Sstevel@tonic-gate int
2957c478bd9Sstevel@tonic-gate add_avsoftintr(void *intr_id, int lvl, avfunc xxintr, char *name,
2967c478bd9Sstevel@tonic-gate     caddr_t arg1, caddr_t arg2)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	int slvl;
299e23a7e34Slq150181 	ddi_softint_hdl_impl_t	*hdlp = (ddi_softint_hdl_impl_t *)intr_id;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	if ((slvl = slvltovect(lvl)) != -1)
3027c478bd9Sstevel@tonic-gate 		return (add_avintr(intr_id, lvl, xxintr,
3037a364d25Sschwartz 		    name, slvl, arg1, arg2, NULL, NULL));
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	if (intr_id == NULL) {
3067c478bd9Sstevel@tonic-gate 		printf("Attempt to add null intr_id for %s on level %d\n",
3077c478bd9Sstevel@tonic-gate 		    name, lvl);
3087c478bd9Sstevel@tonic-gate 		return (0);
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	if (xxintr == NULL) {
3127c478bd9Sstevel@tonic-gate 		printf("Attempt to add null handler for %s on level %d\n",
3137c478bd9Sstevel@tonic-gate 		    name, lvl);
3147c478bd9Sstevel@tonic-gate 		return (0);
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	if (lvl <= 0 || lvl > LOCK_LEVEL) {
3187c478bd9Sstevel@tonic-gate 		printf(badsoft, lvl, name);
3197c478bd9Sstevel@tonic-gate 		return (0);
3207c478bd9Sstevel@tonic-gate 	}
321e23a7e34Slq150181 
322e23a7e34Slq150181 	if (hdlp->ih_pending == NULL) {
323e23a7e34Slq150181 		hdlp->ih_pending =
324e23a7e34Slq150181 		    kmem_zalloc(sizeof (av_softinfo_t), KM_SLEEP);
3257c478bd9Sstevel@tonic-gate 	}
326e23a7e34Slq150181 
327e23a7e34Slq150181 	insert_av(intr_id, &softvect[lvl], xxintr, arg1, arg2, NULL, lvl, NULL);
328e23a7e34Slq150181 
3297c478bd9Sstevel@tonic-gate 	return (1);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate /* insert an interrupt vector into chain */
333e23a7e34Slq150181 static void
3347c478bd9Sstevel@tonic-gate insert_av(void *intr_id, struct av_head *vectp, avfunc f, caddr_t arg1,
3357a364d25Sschwartz     caddr_t arg2, uint64_t *ticksp, int pri_level, dev_info_t *dip)
3367c478bd9Sstevel@tonic-gate {
3377c478bd9Sstevel@tonic-gate 	/*
3387c478bd9Sstevel@tonic-gate 	 * Protect rewrites of the list
3397c478bd9Sstevel@tonic-gate 	 */
3407c478bd9Sstevel@tonic-gate 	struct autovec *p, *mem;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	mem = kmem_zalloc(sizeof (struct autovec), KM_SLEEP);
3437c478bd9Sstevel@tonic-gate 	mem->av_vector = f;
3447c478bd9Sstevel@tonic-gate 	mem->av_intarg1 = arg1;
3457c478bd9Sstevel@tonic-gate 	mem->av_intarg2 = arg2;
3467a364d25Sschwartz 	mem->av_ticksp = ticksp;
3477c478bd9Sstevel@tonic-gate 	mem->av_intr_id = intr_id;
3487c478bd9Sstevel@tonic-gate 	mem->av_prilevel = pri_level;
3497c478bd9Sstevel@tonic-gate 	mem->av_dip = dip;
3507c478bd9Sstevel@tonic-gate 	mem->av_link = NULL;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	mutex_enter(&av_lock);
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	if (vectp->avh_link == NULL) {	/* Nothing on list - put it at head */
3557c478bd9Sstevel@tonic-gate 		vectp->avh_link = mem;
3567c478bd9Sstevel@tonic-gate 		vectp->avh_hi_pri = vectp->avh_lo_pri = (ushort_t)pri_level;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 		mutex_exit(&av_lock);
359e23a7e34Slq150181 		return;
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	/* find where it goes in list */
3637c478bd9Sstevel@tonic-gate 	for (p = vectp->avh_link; p != NULL; p = p->av_link) {
3647c478bd9Sstevel@tonic-gate 		if (p->av_vector == NULL) {	/* freed struct available */
3657c478bd9Sstevel@tonic-gate 			p->av_intarg1 = arg1;
3667c478bd9Sstevel@tonic-gate 			p->av_intarg2 = arg2;
3677a364d25Sschwartz 			p->av_ticksp = ticksp;
3687c478bd9Sstevel@tonic-gate 			p->av_intr_id = intr_id;
3697c478bd9Sstevel@tonic-gate 			p->av_prilevel = pri_level;
3700b38a8bdSahl 			p->av_dip = dip;
3717c478bd9Sstevel@tonic-gate 			if (pri_level > (int)vectp->avh_hi_pri) {
3727c478bd9Sstevel@tonic-gate 				vectp->avh_hi_pri = (ushort_t)pri_level;
3737c478bd9Sstevel@tonic-gate 			}
3747c478bd9Sstevel@tonic-gate 			if (pri_level < (int)vectp->avh_lo_pri) {
3757c478bd9Sstevel@tonic-gate 				vectp->avh_lo_pri = (ushort_t)pri_level;
3767c478bd9Sstevel@tonic-gate 			}
377843e1988Sjohnlev 			/*
378843e1988Sjohnlev 			 * To prevent calling service routine before args
379843e1988Sjohnlev 			 * and ticksp are ready fill in vector last.
380843e1988Sjohnlev 			 */
3817c478bd9Sstevel@tonic-gate 			p->av_vector = f;
3827c478bd9Sstevel@tonic-gate 			mutex_exit(&av_lock);
383843e1988Sjohnlev 			kmem_free(mem, sizeof (struct autovec));
384e23a7e34Slq150181 			return;
3857c478bd9Sstevel@tonic-gate 		}
3867c478bd9Sstevel@tonic-gate 	}
3877c478bd9Sstevel@tonic-gate 	/* insert new intpt at beginning of chain */
3887c478bd9Sstevel@tonic-gate 	mem->av_link = vectp->avh_link;
3897c478bd9Sstevel@tonic-gate 	vectp->avh_link = mem;
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 	}
3967c478bd9Sstevel@tonic-gate 	mutex_exit(&av_lock);
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate 
399e23a7e34Slq150181 static int
400e23a7e34Slq150181 av_rem_softintr(void *intr_id, int lvl, avfunc xxintr, boolean_t rem_softinfo)
4017c478bd9Sstevel@tonic-gate {
4027c478bd9Sstevel@tonic-gate 	struct av_head *vecp = (struct av_head *)0;
4037c478bd9Sstevel@tonic-gate 	int slvl;
404e23a7e34Slq150181 	ddi_softint_hdl_impl_t	*hdlp = (ddi_softint_hdl_impl_t *)intr_id;
405e23a7e34Slq150181 	av_softinfo_t *infop = (av_softinfo_t *)hdlp->ih_pending;
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	if (xxintr == NULL)
4087c478bd9Sstevel@tonic-gate 		return (0);
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	if ((slvl = slvltovect(lvl)) != -1) {
4117c478bd9Sstevel@tonic-gate 		rem_avintr(intr_id, lvl, xxintr, slvl);
4127c478bd9Sstevel@tonic-gate 		return (1);
4137c478bd9Sstevel@tonic-gate 	}
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 	if (lvl <= 0 && lvl >= LOCK_LEVEL) {
4167c478bd9Sstevel@tonic-gate 		return (0);
4177c478bd9Sstevel@tonic-gate 	}
4187c478bd9Sstevel@tonic-gate 	vecp = &softvect[lvl];
4197c478bd9Sstevel@tonic-gate 	remove_av(intr_id, vecp, xxintr, lvl, 0);
4207c478bd9Sstevel@tonic-gate 
421e23a7e34Slq150181 	if (rem_softinfo) {
422e23a7e34Slq150181 		kmem_free(infop, sizeof (av_softinfo_t));
423e23a7e34Slq150181 		hdlp->ih_pending = NULL;
424e23a7e34Slq150181 	}
425e23a7e34Slq150181 
4267c478bd9Sstevel@tonic-gate 	return (1);
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate 
429e23a7e34Slq150181 int
430e23a7e34Slq150181 av_softint_movepri(void *intr_id, int old_lvl)
431e23a7e34Slq150181 {
432e23a7e34Slq150181 	int ret;
433e23a7e34Slq150181 	ddi_softint_hdl_impl_t	*hdlp = (ddi_softint_hdl_impl_t *)intr_id;
434e23a7e34Slq150181 
435e23a7e34Slq150181 	ret = add_avsoftintr(intr_id, hdlp->ih_pri, hdlp->ih_cb_func,
436e23a7e34Slq150181 	    DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2);
437e23a7e34Slq150181 
438e23a7e34Slq150181 	if (ret) {
439e23a7e34Slq150181 		(void) av_rem_softintr(intr_id, old_lvl, hdlp->ih_cb_func,
440e23a7e34Slq150181 		    B_FALSE);
441e23a7e34Slq150181 	}
442e23a7e34Slq150181 
443e23a7e34Slq150181 	return (ret);
444e23a7e34Slq150181 }
445e23a7e34Slq150181 
446e23a7e34Slq150181 /*
447e23a7e34Slq150181  * Remove a driver from the autovector list.
448e23a7e34Slq150181  */
449e23a7e34Slq150181 int
450e23a7e34Slq150181 rem_avsoftintr(void *intr_id, int lvl, avfunc xxintr)
451e23a7e34Slq150181 {
452e23a7e34Slq150181 	return (av_rem_softintr(intr_id, lvl, xxintr, B_TRUE));
453e23a7e34Slq150181 }
454e23a7e34Slq150181 
4557c478bd9Sstevel@tonic-gate void
4567c478bd9Sstevel@tonic-gate rem_avintr(void *intr_id, int lvl, avfunc xxintr, int vect)
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate 	struct av_head *vecp = (struct av_head *)0;
4597c478bd9Sstevel@tonic-gate 	avfunc f;
4607c478bd9Sstevel@tonic-gate 	int s, vectindex;			/* save old spl value */
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	if ((f = xxintr) == NULL)
4637c478bd9Sstevel@tonic-gate 		return;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	vectindex = vect % MAX_VECT;
4667c478bd9Sstevel@tonic-gate 	vecp = &autovect[vectindex];
4677c478bd9Sstevel@tonic-gate 	remove_av(intr_id, vecp, f, lvl, vect);
4687c478bd9Sstevel@tonic-gate 	s = splhi();
4697c478bd9Sstevel@tonic-gate 	mutex_enter(&av_lock);
4707c478bd9Sstevel@tonic-gate 	(*delspl)(vect, lvl, vecp->avh_lo_pri, vecp->avh_hi_pri);
4717c478bd9Sstevel@tonic-gate 	mutex_exit(&av_lock);
4727c478bd9Sstevel@tonic-gate 	splx(s);
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate /*
4777c478bd9Sstevel@tonic-gate  * After having made a change to an autovector list, wait until we have
4787c478bd9Sstevel@tonic-gate  * seen each cpu not executing an interrupt at that level--so we know our
4797c478bd9Sstevel@tonic-gate  * change has taken effect completely (no old state in registers, etc).
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate void
4827c478bd9Sstevel@tonic-gate wait_till_seen(int ipl)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	int cpu_in_chain, cix;
4857c478bd9Sstevel@tonic-gate 	struct cpu *cpup;
4867c478bd9Sstevel@tonic-gate 	cpuset_t cpus_to_check;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	CPUSET_ALL(cpus_to_check);
4897c478bd9Sstevel@tonic-gate 	do {
4907c478bd9Sstevel@tonic-gate 		cpu_in_chain = 0;
4917c478bd9Sstevel@tonic-gate 		for (cix = 0; cix < NCPU; cix++) {
4927c478bd9Sstevel@tonic-gate 			cpup = cpu[cix];
4937c478bd9Sstevel@tonic-gate 			if (cpup != NULL && CPU_IN_SET(cpus_to_check, cix)) {
4947c478bd9Sstevel@tonic-gate 				if (intr_active(cpup, ipl)) {
4957c478bd9Sstevel@tonic-gate 					cpu_in_chain = 1;
4967c478bd9Sstevel@tonic-gate 				} else {
4977c478bd9Sstevel@tonic-gate 					CPUSET_DEL(cpus_to_check, cix);
4987c478bd9Sstevel@tonic-gate 				}
4997c478bd9Sstevel@tonic-gate 			}
5007c478bd9Sstevel@tonic-gate 		}
5017c478bd9Sstevel@tonic-gate 	} while (cpu_in_chain);
5027c478bd9Sstevel@tonic-gate }
5037c478bd9Sstevel@tonic-gate 
504843e1988Sjohnlev static uint64_t dummy_tick;
505843e1988Sjohnlev 
5067c478bd9Sstevel@tonic-gate /* remove an interrupt vector from the chain */
5077c478bd9Sstevel@tonic-gate static void
5087c478bd9Sstevel@tonic-gate remove_av(void *intr_id, struct av_head *vectp, avfunc f, int pri_level,
5097c478bd9Sstevel@tonic-gate 	int vect)
5107c478bd9Sstevel@tonic-gate {
511843e1988Sjohnlev 	struct autovec *p, *target;
5127c478bd9Sstevel@tonic-gate 	int	lo_pri, hi_pri;
5137c478bd9Sstevel@tonic-gate 	int	ipl;
5147c478bd9Sstevel@tonic-gate 	/*
5157c478bd9Sstevel@tonic-gate 	 * Protect rewrites of the list
5167c478bd9Sstevel@tonic-gate 	 */
5177c478bd9Sstevel@tonic-gate 	target = NULL;
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	mutex_enter(&av_lock);
5207c478bd9Sstevel@tonic-gate 	ipl = pri_level;
5217c478bd9Sstevel@tonic-gate 	lo_pri = MAXIPL;
5227c478bd9Sstevel@tonic-gate 	hi_pri = 0;
523843e1988Sjohnlev 	for (p = vectp->avh_link; p; p = p->av_link) {
5247c478bd9Sstevel@tonic-gate 		if ((p->av_vector == f) && (p->av_intr_id == intr_id)) {
5257c478bd9Sstevel@tonic-gate 			/* found the handler */
5267c478bd9Sstevel@tonic-gate 			target = p;
5277c478bd9Sstevel@tonic-gate 			continue;
5287c478bd9Sstevel@tonic-gate 		}
529843e1988Sjohnlev 		if (p->av_vector != NULL) {
5307c478bd9Sstevel@tonic-gate 			if (p->av_prilevel > hi_pri)
5317c478bd9Sstevel@tonic-gate 				hi_pri = p->av_prilevel;
5327c478bd9Sstevel@tonic-gate 			if (p->av_prilevel < lo_pri)
5337c478bd9Sstevel@tonic-gate 				lo_pri = p->av_prilevel;
5347c478bd9Sstevel@tonic-gate 		}
535843e1988Sjohnlev 	}
5367c478bd9Sstevel@tonic-gate 	if (ipl < hi_pri)
5377c478bd9Sstevel@tonic-gate 		ipl = hi_pri;
5387c478bd9Sstevel@tonic-gate 	if (target == NULL) {	/* not found */
5397c478bd9Sstevel@tonic-gate 		printf("Couldn't remove function %p at %d, %d\n",
5407c478bd9Sstevel@tonic-gate 		    (void *)f, vect, pri_level);
5417c478bd9Sstevel@tonic-gate 		mutex_exit(&av_lock);
5427c478bd9Sstevel@tonic-gate 		return;
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 	/*
546843e1988Sjohnlev 	 * This drops the handler from the chain, it can no longer be called.
547843e1988Sjohnlev 	 * However, there is no guarantee that the handler is not currently
548843e1988Sjohnlev 	 * still executing.
5497c478bd9Sstevel@tonic-gate 	 */
550843e1988Sjohnlev 	target->av_vector = NULL;
551843e1988Sjohnlev 	/*
552843e1988Sjohnlev 	 * There is a race where we could be just about to pick up the ticksp
553843e1988Sjohnlev 	 * pointer to increment it after returning from the service routine
554843e1988Sjohnlev 	 * in av_dispatch_autovect.  Rather than NULL it out let's just point
555843e1988Sjohnlev 	 * it off to something safe so that any final tick update attempt
556843e1988Sjohnlev 	 * won't fault.
557843e1988Sjohnlev 	 */
558843e1988Sjohnlev 	target->av_ticksp = &dummy_tick;
5597c478bd9Sstevel@tonic-gate 	wait_till_seen(ipl);
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	if (lo_pri > hi_pri) {	/* the chain is now empty */
5627c478bd9Sstevel@tonic-gate 		/* Leave the unused entries here for probable future use */
5637c478bd9Sstevel@tonic-gate 		vectp->avh_lo_pri = MAXIPL;
5647c478bd9Sstevel@tonic-gate 		vectp->avh_hi_pri = 0;
5657c478bd9Sstevel@tonic-gate 	} else {
5667c478bd9Sstevel@tonic-gate 		if ((int)vectp->avh_lo_pri < lo_pri)
5677c478bd9Sstevel@tonic-gate 			vectp->avh_lo_pri = (ushort_t)lo_pri;
5687c478bd9Sstevel@tonic-gate 		if ((int)vectp->avh_hi_pri > hi_pri)
5697c478bd9Sstevel@tonic-gate 			vectp->avh_hi_pri = (ushort_t)hi_pri;
5707c478bd9Sstevel@tonic-gate 	}
5717c478bd9Sstevel@tonic-gate 	mutex_exit(&av_lock);
5727c478bd9Sstevel@tonic-gate 	wait_till_seen(ipl);
5737c478bd9Sstevel@tonic-gate }
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate /*
576a1af7ba0Scwb  * kmdb uses siron (and thus setsoftint) while the world is stopped in order to
577a1af7ba0Scwb  * inform its driver component that there's work to be done.  We need to keep
578a1af7ba0Scwb  * DTrace from instrumenting kmdb's siron and setsoftint.  We duplicate siron,
579a1af7ba0Scwb  * giving kmdb's version a kdi prefix to keep DTrace at bay.   We also
580a1af7ba0Scwb  * provide a version of the various setsoftint functions available for kmdb to
581a1af7ba0Scwb  * use using a kdi_ prefix while the main *setsoftint() functionality is
582a1af7ba0Scwb  * implemented as a wrapper.  This allows tracing, while still providing a
583a1af7ba0Scwb  * way for kmdb to sneak in unmolested.
584a1af7ba0Scwb  */
585a1af7ba0Scwb void
586a1af7ba0Scwb kdi_siron(void)
587a1af7ba0Scwb {
588a1af7ba0Scwb 	(*kdisetsoftint)(1, softlevel1_hdl.ih_pending);
589a1af7ba0Scwb }
590a1af7ba0Scwb 
591a1af7ba0Scwb /*
5927c478bd9Sstevel@tonic-gate  * Trigger a soft interrupt.
5937c478bd9Sstevel@tonic-gate  */
5947c478bd9Sstevel@tonic-gate void
5957c478bd9Sstevel@tonic-gate siron(void)
5967c478bd9Sstevel@tonic-gate {
597*dd4eeefdSeota 	/* Level 1 software interrupt */
598e23a7e34Slq150181 	(*setsoftint)(1, softlevel1_hdl.ih_pending);
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate /*
602*dd4eeefdSeota  * Trigger software interrupts dedicated to ddi timer.
603*dd4eeefdSeota  */
604*dd4eeefdSeota void
605*dd4eeefdSeota sir_on(int level)
606*dd4eeefdSeota {
607*dd4eeefdSeota 	ASSERT(level >= DDI_IPL_1 && level <= DDI_IPL_10);
608*dd4eeefdSeota 	(*setsoftint)(level, softlevel_hdl[level-1].ih_pending);
609*dd4eeefdSeota }
610*dd4eeefdSeota 
611*dd4eeefdSeota /*
6123aedfe0bSmishra  * The handler which is executed on the target CPU.
6133aedfe0bSmishra  */
6143aedfe0bSmishra /*ARGSUSED*/
6153aedfe0bSmishra static int
6163aedfe0bSmishra siron_poke_intr(xc_arg_t a1, xc_arg_t a2, xc_arg_t a3)
6173aedfe0bSmishra {
6183aedfe0bSmishra 	siron();
6193aedfe0bSmishra 	return (0);
6203aedfe0bSmishra }
6213aedfe0bSmishra 
6223aedfe0bSmishra /*
6233aedfe0bSmishra  * May get called from softcall to poke CPUs.
6243aedfe0bSmishra  */
6253aedfe0bSmishra void
6263aedfe0bSmishra siron_poke_cpu(cpuset_t poke)
6273aedfe0bSmishra {
6283aedfe0bSmishra 	int cpuid = CPU->cpu_id;
6293aedfe0bSmishra 
6303aedfe0bSmishra 	/*
6313aedfe0bSmishra 	 * If we are poking to ourself then we can simply
6323aedfe0bSmishra 	 * generate level1 using siron()
6333aedfe0bSmishra 	 */
6343aedfe0bSmishra 	if (CPU_IN_SET(poke, cpuid)) {
6353aedfe0bSmishra 		siron();
6363aedfe0bSmishra 		CPUSET_DEL(poke, cpuid);
6373aedfe0bSmishra 		if (CPUSET_ISNULL(poke))
6383aedfe0bSmishra 			return;
6393aedfe0bSmishra 	}
6403aedfe0bSmishra 
6413aedfe0bSmishra 	xc_call(0, 0, 0, X_CALL_MEDPRI, poke, (xc_func_t)siron_poke_intr);
6423aedfe0bSmishra }
6433aedfe0bSmishra 
6443aedfe0bSmishra /*
6457c478bd9Sstevel@tonic-gate  * Walk the autovector table for this vector, invoking each
6467c478bd9Sstevel@tonic-gate  * interrupt handler as we go.
6477c478bd9Sstevel@tonic-gate  */
6487a364d25Sschwartz 
6497a364d25Sschwartz extern uint64_t intr_get_time(void);
6507a364d25Sschwartz 
6517c478bd9Sstevel@tonic-gate void
6527c478bd9Sstevel@tonic-gate av_dispatch_autovect(uint_t vec)
6537c478bd9Sstevel@tonic-gate {
6547c478bd9Sstevel@tonic-gate 	struct autovec *av;
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	while ((av = autovect[vec].avh_link) != NULL) {
6597c478bd9Sstevel@tonic-gate 		uint_t numcalled = 0;
6607c478bd9Sstevel@tonic-gate 		uint_t claimed = 0;
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 		for (; av; av = av->av_link) {
6637c478bd9Sstevel@tonic-gate 			uint_t r;
6647c478bd9Sstevel@tonic-gate 			uint_t (*intr)() = av->av_vector;
6657c478bd9Sstevel@tonic-gate 			caddr_t arg1 = av->av_intarg1;
6667c478bd9Sstevel@tonic-gate 			caddr_t arg2 = av->av_intarg2;
6677c478bd9Sstevel@tonic-gate 			dev_info_t *dip = av->av_dip;
6687c478bd9Sstevel@tonic-gate 
669843e1988Sjohnlev 			/*
670843e1988Sjohnlev 			 * We must walk the entire chain.  Removed handlers
671843e1988Sjohnlev 			 * may be anywhere in the chain.
672843e1988Sjohnlev 			 */
6737c478bd9Sstevel@tonic-gate 			if (intr == NULL)
674843e1988Sjohnlev 				continue;
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 			DTRACE_PROBE4(interrupt__start, dev_info_t *, dip,
6777c478bd9Sstevel@tonic-gate 			    void *, intr, caddr_t, arg1, caddr_t, arg2);
6787c478bd9Sstevel@tonic-gate 			r = (*intr)(arg1, arg2);
6797c478bd9Sstevel@tonic-gate 			DTRACE_PROBE4(interrupt__complete, dev_info_t *, dip,
6807c478bd9Sstevel@tonic-gate 			    void *, intr, caddr_t, arg1, uint_t, r);
681ae115bc7Smrj 			numcalled++;
6827c478bd9Sstevel@tonic-gate 			claimed |= r;
6837a364d25Sschwartz 			if (av->av_ticksp && av->av_prilevel <= LOCK_LEVEL)
6847a364d25Sschwartz 				atomic_add_64(av->av_ticksp, intr_get_time());
6857c478bd9Sstevel@tonic-gate 		}
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 		/*
6887c478bd9Sstevel@tonic-gate 		 * If there's only one interrupt handler in the chain,
6897c478bd9Sstevel@tonic-gate 		 * or if no-one claimed the interrupt at all give up now.
6907c478bd9Sstevel@tonic-gate 		 */
6917c478bd9Sstevel@tonic-gate 		if (numcalled == 1 || claimed == 0)
6927c478bd9Sstevel@tonic-gate 			break;
6937c478bd9Sstevel@tonic-gate 	}
6947c478bd9Sstevel@tonic-gate }
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate /*
6977c478bd9Sstevel@tonic-gate  * Call every soft interrupt handler we can find at this level once.
6987c478bd9Sstevel@tonic-gate  */
6997c478bd9Sstevel@tonic-gate void
7007c478bd9Sstevel@tonic-gate av_dispatch_softvect(uint_t pil)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate 	struct autovec *av;
7037c478bd9Sstevel@tonic-gate 	ddi_softint_hdl_impl_t	*hdlp;
7047c478bd9Sstevel@tonic-gate 	uint_t (*intr)();
7057c478bd9Sstevel@tonic-gate 	caddr_t arg1;
7067c478bd9Sstevel@tonic-gate 	caddr_t arg2;
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
7097c478bd9Sstevel@tonic-gate 	ASSERT(pil >= 0 && pil <= PIL_MAX);
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	for (av = softvect[pil].avh_link; av; av = av->av_link) {
712843e1988Sjohnlev 		/*
713843e1988Sjohnlev 		 * We must walk the entire chain.  Removed handlers
714843e1988Sjohnlev 		 * may be anywhere in the chain.
715843e1988Sjohnlev 		 */
7167c478bd9Sstevel@tonic-gate 		if ((intr = av->av_vector) == NULL)
717843e1988Sjohnlev 			continue;
7187c478bd9Sstevel@tonic-gate 		arg1 = av->av_intarg1;
7197c478bd9Sstevel@tonic-gate 		arg2 = av->av_intarg2;
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 		hdlp = (ddi_softint_hdl_impl_t *)av->av_intr_id;
7227c478bd9Sstevel@tonic-gate 		ASSERT(hdlp);
7237c478bd9Sstevel@tonic-gate 
724e23a7e34Slq150181 		/*
725e23a7e34Slq150181 		 * Each cpu has its own pending bit in hdlp->ih_pending,
726e23a7e34Slq150181 		 * here av_check/clear_softint_pending is just checking
727e23a7e34Slq150181 		 * and clearing the pending bit for the current cpu, who
728e23a7e34Slq150181 		 * has just triggered a softint.
729e23a7e34Slq150181 		 */
730e23a7e34Slq150181 		if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) {
731e23a7e34Slq150181 			av_clear_softint_pending(hdlp->ih_pending);
7327c478bd9Sstevel@tonic-gate 			(void) (*intr)(arg1, arg2);
7337c478bd9Sstevel@tonic-gate 		}
7347c478bd9Sstevel@tonic-gate 	}
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate struct regs;
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate /*
7407c478bd9Sstevel@tonic-gate  * Call every NMI handler we know of once.
7417c478bd9Sstevel@tonic-gate  */
7427c478bd9Sstevel@tonic-gate void
7437c478bd9Sstevel@tonic-gate av_dispatch_nmivect(struct regs *rp)
7447c478bd9Sstevel@tonic-gate {
7457c478bd9Sstevel@tonic-gate 	struct autovec *av;
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate 	for (av = nmivect; av; av = av->av_link)
7507c478bd9Sstevel@tonic-gate 		(void) (av->av_vector)(av->av_intarg1, rp);
7517c478bd9Sstevel@tonic-gate }
752