softintr_schedule() is defined either as a function or as a macro. The patch below turns the macros into proper functions, to reduce the differences between the soft interrupt implementations.
The patch additionally moves the soft interrupt handle definitions from the headers to the C modules that implement soft interrupts. The callers of the softintr interface generally do not need to see the definitions as softintr_establish() returns opaque handles. This moving eases changing the structs because of reduced scope of visibility. Certain arm*-land drivers have taken the liberty to treat the return type of softintr_establish() as ``struct soft_intrhand *''. Because of this, the diff forward-declares struct soft_intrhand in the headers that previously defined a struct with this name. OK? Index: arch/alpha/alpha/interrupt.c =================================================================== RCS file: src/sys/arch/alpha/alpha/interrupt.c,v retrieving revision 1.40 diff -u -p -r1.40 interrupt.c --- arch/alpha/alpha/interrupt.c 21 Jan 2017 05:42:03 -0000 1.40 +++ arch/alpha/alpha/interrupt.c 4 Jun 2021 15:28:38 -0000 @@ -70,6 +70,8 @@ #include <sys/kernel.h> #include <sys/device.h> #include <sys/mbuf.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <sys/socket.h> #include <sys/evcount.h> @@ -88,6 +90,22 @@ #include "lca.h" #include "tcasic.h" +struct alpha_soft_intrhand { + TAILQ_ENTRY(alpha_soft_intrhand) + sih_q; + struct alpha_soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void *sih_arg; + int sih_pending; +}; + +struct alpha_soft_intr { + TAILQ_HEAD(, alpha_soft_intrhand) + softintr_q; + struct mutex softintr_mtx; + unsigned long softintr_siq; +}; + extern struct evcount clk_count; struct scbvec scb_iovectab[SCB_VECTOIDX(SCB_SIZE - SCB_IOVECBASE)]; Index: arch/alpha/include/intr.h =================================================================== RCS file: src/sys/arch/alpha/include/intr.h,v retrieving revision 1.49 diff -u -p -r1.49 intr.h --- arch/alpha/include/intr.h 24 Mar 2019 06:19:26 -0000 1.49 +++ arch/alpha/include/intr.h 4 Jun 2021 15:28:38 -0000 @@ -62,7 +62,6 @@ #define _MACHINE_INTR_H_ #include <sys/evcount.h> -#include <sys/mutex.h> #include <sys/queue.h> #include <machine/atomic.h> @@ -254,22 +253,6 @@ extern unsigned long ssir; #define setsoft(x) atomic_setbits_ulong(&ssir, 1 << (x)) -struct alpha_soft_intrhand { - TAILQ_ENTRY(alpha_soft_intrhand) - sih_q; - struct alpha_soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void *sih_arg; - int sih_pending; -}; - -struct alpha_soft_intr { - TAILQ_HEAD(, alpha_soft_intrhand) - softintr_q; - struct mutex softintr_mtx; - unsigned long softintr_siq; -}; - void softintr_disestablish(void *); void softintr_dispatch(void); void *softintr_establish(int, void (*)(void *), void *); Index: arch/amd64/amd64/softintr.c =================================================================== RCS file: src/sys/arch/amd64/amd64/softintr.c,v retrieving revision 1.10 diff -u -p -r1.10 softintr.c --- arch/amd64/amd64/softintr.c 11 Sep 2020 09:27:09 -0000 1.10 +++ arch/amd64/amd64/softintr.c 4 Jun 2021 15:28:38 -0000 @@ -37,11 +37,29 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <machine/intr.h> #include <uvm/uvm_extern.h> +struct x86_soft_intrhand { + TAILQ_ENTRY(x86_soft_intrhand) + sih_q; + struct x86_soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void *sih_arg; + int sih_pending; +}; + +struct x86_soft_intr { + TAILQ_HEAD(, x86_soft_intrhand) + softintr_q; + int softintr_ssir; + struct mutex softintr_lock; +}; + struct x86_soft_intr x86_soft_intrs[X86_NSOFTINTR]; const int x86_soft_intr_to_ssir[X86_NSOFTINTR] = { @@ -169,3 +187,18 @@ softintr_disestablish(void *arg) free(sih, M_DEVBUF, sizeof(*sih)); } + +void +softintr_schedule(void *arg) +{ + struct x86_soft_intrhand *sih = arg; + struct x86_soft_intr *si = sih->sih_intrhead; + + mtx_enter(&si->softintr_lock); + if (sih->sih_pending == 0) { + TAILQ_INSERT_TAIL(&si->softintr_q, sih, sih_q); + sih->sih_pending = 1; + softintr(si->softintr_ssir); + } + mtx_leave(&si->softintr_lock); +} Index: arch/amd64/include/intr.h =================================================================== RCS file: src/sys/arch/amd64/include/intr.h,v retrieving revision 1.32 diff -u -p -r1.32 intr.h --- arch/amd64/include/intr.h 17 Jun 2020 06:14:52 -0000 1.32 +++ arch/amd64/include/intr.h 4 Jun 2021 15:28:38 -0000 @@ -231,42 +231,13 @@ extern void (*ipifunc[X86_NIPI])(struct #define X86_NSOFTINTR 3 #ifndef _LOCORE -#include <sys/queue.h> - -struct x86_soft_intrhand { - TAILQ_ENTRY(x86_soft_intrhand) - sih_q; - struct x86_soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void *sih_arg; - int sih_pending; -}; - -struct x86_soft_intr { - TAILQ_HEAD(, x86_soft_intrhand) - softintr_q; - int softintr_ssir; - struct mutex softintr_lock; -}; void *softintr_establish(int, void (*)(void *), void *); void softintr_disestablish(void *); void softintr_init(void); void softintr_dispatch(int); +void softintr_schedule(void *); -#define softintr_schedule(arg) \ -do { \ - struct x86_soft_intrhand *__sih = (arg); \ - struct x86_soft_intr *__si = __sih->sih_intrhead; \ - \ - mtx_enter(&__si->softintr_lock); \ - if (__sih->sih_pending == 0) { \ - TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ - __sih->sih_pending = 1; \ - softintr(__si->softintr_ssir); \ - } \ - mtx_leave(&__si->softintr_lock); \ -} while (/*CONSTCOND*/ 0) #endif /* _LOCORE */ #endif /* !_MACHINE_INTR_H_ */ Index: arch/arm/arm/softintr.c =================================================================== RCS file: src/sys/arch/arm/arm/softintr.c,v retrieving revision 1.11 diff -u -p -r1.11 softintr.c --- arch/arm/arm/softintr.c 25 Mar 2021 04:12:00 -0000 1.11 +++ arch/arm/arm/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -39,10 +39,27 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> + +#include <machine/intr.h> #include <uvm/uvm_extern.h> -#include <machine/intr.h> +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) sih_list; + void (*sih_func)(void *); + void *sih_arg; + struct soft_intrq *sih_siq; + int sih_pending; +}; + +struct soft_intrq { + TAILQ_HEAD(, soft_intrhand) + siq_list; + int siq_si; + struct mutex siq_mtx; +}; struct soft_intrq soft_intrq[SI_NQUEUES]; @@ -161,3 +178,18 @@ softintr_disestablish(void *arg) free(sih, M_DEVBUF, 0); } + +void +softintr_schedule(void *arg) +{ + struct soft_intrhand *sih = arg; + struct soft_intrq *siq = sih->sih_siq; + + mtx_enter(&siq->siq_mtx); + if (sih->sih_pending == 0) { + TAILQ_INSERT_TAIL(&siq->siq_list, sih, sih_list); + sih->sih_pending = 1; + _setsoftintr(siq->siq_si); + } + mtx_leave(&siq->siq_mtx); +} Index: arch/arm/include/softintr.h =================================================================== RCS file: src/sys/arch/arm/include/softintr.h,v retrieving revision 1.6 diff -u -p -r1.6 softintr.h --- arch/arm/include/softintr.h 14 Aug 2020 16:51:09 -0000 1.6 +++ arch/arm/include/softintr.h 4 Jun 2021 15:28:39 -0000 @@ -41,8 +41,6 @@ #ifdef _KERNEL -#include <sys/mutex.h> - /* * Generic software interrupt support. * @@ -57,39 +55,13 @@ #define SI_NQUEUES 4 -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) sih_list; - void (*sih_func)(void *); - void *sih_arg; - struct soft_intrq *sih_siq; - int sih_pending; -}; - -struct soft_intrq { - TAILQ_HEAD(, soft_intrhand) - siq_list; - int siq_si; - struct mutex siq_mtx; -}; +struct soft_intrhand; void *softintr_establish(int, void (*)(void *), void *); void softintr_disestablish(void *); void softintr_init(void); void softintr_dispatch(int); - -#define softintr_schedule(arg) \ -do { \ - struct soft_intrhand *__sih = (arg); \ - struct soft_intrq *__siq = __sih->sih_siq; \ - \ - mtx_enter(&__siq->siq_mtx); \ - if (__sih->sih_pending == 0) { \ - TAILQ_INSERT_TAIL(&__siq->siq_list, __sih, sih_list); \ - __sih->sih_pending = 1; \ - _setsoftintr(__siq->siq_si); \ - } \ - mtx_leave(&__siq->siq_mtx); \ -} while (/*CONSTCOND*/0) +void softintr_schedule(void *); #endif /* _KERNEL */ Index: arch/arm64/arm64/softintr.c =================================================================== RCS file: src/sys/arch/arm64/arm64/softintr.c,v retrieving revision 1.2 diff -u -p -r1.2 softintr.c --- arch/arm64/arm64/softintr.c 11 Sep 2020 09:27:10 -0000 1.2 +++ arch/arm64/arm64/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -37,11 +37,31 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <machine/intr.h> #include <uvm/uvm_extern.h> +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) + sih_q; + struct soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void (*sih_fnwrap)(void *); + void *sih_arg; + void *sih_argwrap; + int sih_pending; +}; + +struct soft_intr { + TAILQ_HEAD(, soft_intrhand) + softintr_q; + int softintr_ssir; + struct mutex softintr_lock; +}; + struct soft_intr soft_intrs[SI_NSOFTINTR]; const int soft_intr_to_ssir[SI_NSOFTINTR] = { @@ -190,6 +210,21 @@ softintr_disestablish(void *arg) } void +softintr_schedule(void *arg) +{ + struct soft_intrhand *sih = arg; + struct soft_intr *si = sih->sih_intrhead; + + mtx_enter(&si->softintr_lock); + if (sih->sih_pending == 0) { + TAILQ_INSERT_TAIL(&si->softintr_q, sih, sih_q); + sih->sih_pending = 1; + softintr(si->softintr_ssir); + } + mtx_leave(&si->softintr_lock); +} + +void softintr(int intrq) { // protected by mutex in caller Index: arch/arm64/include/softintr.h =================================================================== RCS file: src/sys/arch/arm64/include/softintr.h,v retrieving revision 1.2 diff -u -p -r1.2 softintr.h --- arch/arm64/include/softintr.h 14 Aug 2020 16:51:09 -0000 1.2 +++ arch/arm64/include/softintr.h 4 Jun 2021 15:28:39 -0000 @@ -35,9 +35,6 @@ #ifdef _KERNEL -#include <sys/mutex.h> -#include <sys/queue.h> - /* * Generic software interrupt support. * @@ -52,23 +49,7 @@ #define SI_NSOFTINTR 4 -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) - sih_q; - struct soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void (*sih_fnwrap)(void *); - void *sih_arg; - void *sih_argwrap; - int sih_pending; -}; - -struct soft_intr { - TAILQ_HEAD(, soft_intrhand) - softintr_q; - int softintr_ssir; - struct mutex softintr_lock; -}; +struct soft_intrhand; #define SOFTINTR_ESTABLISH_MPSAFE 0x01 void *softintr_establish_flags(int, void (*)(void *), void *, int); @@ -79,22 +60,9 @@ void *softintr_establish_flags(int, v void softintr_disestablish(void *); void softintr_init(void); void softintr_dispatch(int); +void softintr_schedule(void *); void softintr(int); -#define softintr_schedule(arg) \ -do { \ - struct soft_intrhand *__sih = (arg); \ - struct soft_intr *__si = __sih->sih_intrhead; \ - \ - mtx_enter(&__si->softintr_lock); \ - if (__sih->sih_pending == 0) { \ - TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ - __sih->sih_pending = 1; \ - softintr(__si->softintr_ssir); \ - } \ - mtx_leave(&__si->softintr_lock); \ -} while (/*CONSTCOND*/ 0) - #endif /* _KERNEL */ #endif /* _MACHINE_SOFTINTR_H_ */ Index: arch/i386/i386/softintr.c =================================================================== RCS file: src/sys/arch/i386/i386/softintr.c,v retrieving revision 1.8 diff -u -p -r1.8 softintr.c --- arch/i386/i386/softintr.c 11 Sep 2020 09:27:10 -0000 1.8 +++ arch/i386/i386/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -37,11 +37,29 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <machine/intr.h> #include <uvm/uvm_extern.h> +struct i386_soft_intrhand { + TAILQ_ENTRY(i386_soft_intrhand) + sih_q; + struct i386_soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void *sih_arg; + int sih_pending; +}; + +struct i386_soft_intr { + TAILQ_HEAD(, i386_soft_intrhand) + softintr_q; + int softintr_ssir; + struct mutex softintr_lock; +}; + struct i386_soft_intr i386_soft_intrs[I386_NSOFTINTR]; const int i386_soft_intr_to_ssir[I386_NSOFTINTR] = { @@ -162,3 +180,18 @@ softintr_disestablish(void *arg) free(sih, M_DEVBUF, sizeof(*sih)); } + +void +softintr_schedule(void *arg) +{ + struct i386_soft_intrhand *sih = arg; + struct i386_soft_intr *si = sih->sih_intrhead; + + mtx_enter(&si->softintr_lock); + if (sih->sih_pending == 0) { + TAILQ_INSERT_TAIL(&si->softintr_q, sih, sih_q); + sih->sih_pending = 1; + softintr(si->softintr_ssir); + } + mtx_leave(&si->softintr_lock); +} Index: arch/i386/include/intr.h =================================================================== RCS file: src/sys/arch/i386/include/intr.h,v retrieving revision 1.48 diff -u -p -r1.48 intr.h --- arch/i386/include/intr.h 20 Aug 2018 15:02:07 -0000 1.48 +++ arch/i386/include/intr.h 4 Jun 2021 15:28:39 -0000 @@ -153,42 +153,13 @@ extern void (*ipifunc[I386_NIPI])(struct #define I386_NSOFTINTR 3 #ifndef _LOCORE -#include <sys/queue.h> - -struct i386_soft_intrhand { - TAILQ_ENTRY(i386_soft_intrhand) - sih_q; - struct i386_soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void *sih_arg; - int sih_pending; -}; - -struct i386_soft_intr { - TAILQ_HEAD(, i386_soft_intrhand) - softintr_q; - int softintr_ssir; - struct mutex softintr_lock; -}; void *softintr_establish(int, void (*)(void *), void *); void softintr_disestablish(void *); void softintr_init(void); void softintr_dispatch(int); +void softintr_schedule(void *); -#define softintr_schedule(arg) \ -do { \ - struct i386_soft_intrhand *__sih = (arg); \ - struct i386_soft_intr *__si = __sih->sih_intrhead; \ - \ - mtx_enter(&__si->softintr_lock); \ - if (__sih->sih_pending == 0) { \ - TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ - __sih->sih_pending = 1; \ - softintr(__si->softintr_ssir); \ - } \ - mtx_leave(&__si->softintr_lock); \ -} while (/*CONSTCOND*/ 0) #endif /* _LOCORE */ #endif /* !_MACHINE_INTR_H_ */ Index: arch/loongson/include/intr.h =================================================================== RCS file: src/sys/arch/loongson/include/intr.h,v retrieving revision 1.18 diff -u -p -r1.18 intr.h --- arch/loongson/include/intr.h 5 Sep 2019 05:31:38 -0000 1.18 +++ arch/loongson/include/intr.h 4 Jun 2021 15:28:39 -0000 @@ -88,22 +88,7 @@ #ifndef _LOCORE -#include <sys/mutex.h> -#include <sys/queue.h> - -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) sih_list; - void (*sih_func)(void *); - void *sih_arg; - struct soft_intrq *sih_siq; - int sih_pending; -}; - -struct soft_intrq { - TAILQ_HEAD(, soft_intrhand) siq_list; - int siq_si; - struct mutex siq_mtx; -}; +struct soft_intrhand; void softintr_disestablish(void *); void softintr_dispatch(int); Index: arch/m88k/include/intr.h =================================================================== RCS file: src/sys/arch/m88k/include/intr.h,v retrieving revision 1.14 diff -u -p -r1.14 intr.h --- arch/m88k/include/intr.h 20 Aug 2018 15:02:07 -0000 1.14 +++ arch/m88k/include/intr.h 4 Jun 2021 15:28:39 -0000 @@ -123,22 +123,7 @@ void splassert_check(int, const char *); #define SI_NQUEUES 4 -#include <machine/mutex.h> -#include <sys/queue.h> - -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) sih_list; - void (*sih_func)(void *); - void *sih_arg; - struct soft_intrq *sih_siq; - int sih_pending; -}; - -struct soft_intrq { - TAILQ_HEAD(, soft_intrhand) siq_list; - int siq_si; - struct mutex siq_mtx; -}; +struct soft_intrhand; void softintr_disestablish(void *); void softintr_dispatch(int); Index: arch/m88k/m88k/softintr.c =================================================================== RCS file: src/sys/arch/m88k/m88k/softintr.c,v retrieving revision 1.8 diff -u -p -r1.8 softintr.c --- arch/m88k/m88k/softintr.c 7 Oct 2020 12:13:23 -0000 1.8 +++ arch/m88k/m88k/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -40,12 +40,27 @@ #include <sys/systm.h> #include <sys/malloc.h> #include <sys/mutex.h> +#include <sys/queue.h> #include <uvm/uvm_extern.h> #include <machine/atomic.h> #include <machine/intr.h> +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) sih_list; + void (*sih_func)(void *); + void *sih_arg; + struct soft_intrq *sih_siq; + int sih_pending; +}; + +struct soft_intrq { + TAILQ_HEAD(, soft_intrhand) siq_list; + int siq_si; + struct mutex siq_mtx; +}; + struct soft_intrq soft_intrq[SI_NQUEUES]; /* Index: arch/mips64/mips64/softintr.c =================================================================== RCS file: src/sys/arch/mips64/mips64/softintr.c,v retrieving revision 1.22 diff -u -p -r1.22 softintr.c --- arch/mips64/mips64/softintr.c 7 Oct 2020 12:13:23 -0000 1.22 +++ arch/mips64/mips64/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -38,9 +38,10 @@ #include <sys/param.h> #include <sys/systm.h> -#include <sys/mutex.h> -#include <sys/malloc.h> #include <sys/atomic.h> +#include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <uvm/uvm_extern.h> @@ -49,6 +50,20 @@ #include <mips64/mips_cpu.h> #endif +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) sih_list; + void (*sih_func)(void *); + void *sih_arg; + struct soft_intrq *sih_siq; + int sih_pending; +}; + +struct soft_intrq { + TAILQ_HEAD(, soft_intrhand) siq_list; + int siq_si; + struct mutex siq_mtx; +}; + struct soft_intrq soft_intrq[SI_NQUEUES]; /* Index: arch/octeon/include/intr.h =================================================================== RCS file: src/sys/arch/octeon/include/intr.h,v retrieving revision 1.22 diff -u -p -r1.22 intr.h --- arch/octeon/include/intr.h 5 Sep 2019 05:31:38 -0000 1.22 +++ arch/octeon/include/intr.h 4 Jun 2021 15:28:39 -0000 @@ -87,22 +87,7 @@ #ifndef _LOCORE -#include <sys/mutex.h> -#include <sys/queue.h> - -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) sih_list; - void (*sih_func)(void *); - void *sih_arg; - struct soft_intrq *sih_siq; - int sih_pending; -}; - -struct soft_intrq { - TAILQ_HEAD(, soft_intrhand) siq_list; - int siq_si; - struct mutex siq_mtx; -}; +struct soft_intrhand; void softintr_disestablish(void *); void softintr_dispatch(int); Index: arch/powerpc/include/intr.h =================================================================== RCS file: src/sys/arch/powerpc/include/intr.h,v retrieving revision 1.56 diff -u -p -r1.56 intr.h --- arch/powerpc/include/intr.h 20 Aug 2018 15:02:07 -0000 1.56 +++ arch/powerpc/include/intr.h 4 Jun 2021 15:28:39 -0000 @@ -61,6 +61,7 @@ #if defined(_KERNEL) && !defined(_LOCORE) #include <sys/evcount.h> +#include <sys/queue.h> #include <machine/atomic.h> #define PPC_NIRQ 66 @@ -130,22 +131,7 @@ void splassert_check(int, const char *); #define SI_NQUEUES 3 -#include <sys/mutex.h> -#include <sys/queue.h> - -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) sih_list; - void (*sih_func)(void *); - void *sih_arg; - struct soft_intrq *sih_siq; - int sih_pending; -}; - -struct soft_intrq { - TAILQ_HEAD(, soft_intrhand) siq_list; - int siq_si; - struct mutex siq_mtx; -}; +struct soft_intrhand; void softintr_disestablish(void *); void softintr_dispatch(int); Index: arch/powerpc/powerpc/softintr.c =================================================================== RCS file: src/sys/arch/powerpc/powerpc/softintr.c,v retrieving revision 1.10 diff -u -p -r1.10 softintr.c --- arch/powerpc/powerpc/softintr.c 11 Sep 2020 09:27:10 -0000 1.10 +++ arch/powerpc/powerpc/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -40,12 +40,27 @@ #include <sys/systm.h> #include <sys/malloc.h> #include <sys/mutex.h> +#include <sys/queue.h> #include <uvm/uvm_extern.h> #include <machine/atomic.h> #include <machine/intr.h> +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) sih_list; + void (*sih_func)(void *); + void *sih_arg; + struct soft_intrq *sih_siq; + int sih_pending; +}; + +struct soft_intrq { + TAILQ_HEAD(, soft_intrhand) siq_list; + int siq_si; + struct mutex siq_mtx; +}; + struct soft_intrq soft_intrq[SI_NQUEUES]; /* Index: arch/powerpc64/include/softintr.h =================================================================== RCS file: src/sys/arch/powerpc64/include/softintr.h,v retrieving revision 1.2 diff -u -p -r1.2 softintr.h --- arch/powerpc64/include/softintr.h 14 Aug 2020 16:51:09 -0000 1.2 +++ arch/powerpc64/include/softintr.h 4 Jun 2021 15:28:39 -0000 @@ -34,9 +34,6 @@ #ifdef _KERNEL -#include <sys/mutex.h> -#include <sys/queue.h> - /* * Generic software interrupt support. * @@ -51,23 +48,7 @@ #define SI_NSOFTINTR 4 -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) - sih_q; - struct soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void (*sih_fnwrap)(void *); - void *sih_arg; - void *sih_argwrap; - int sih_pending; -}; - -struct soft_intr { - TAILQ_HEAD(, soft_intrhand) - softintr_q; - int softintr_ssir; - struct mutex softintr_lock; -}; +struct soft_intrhand; #define SOFTINTR_ESTABLISH_MPSAFE 0x01 void *softintr_establish_flags(int, void (*)(void *), void *, int); @@ -78,22 +59,9 @@ void *softintr_establish_flags(int, v void softintr_disestablish(void *); void softintr_init(void); void softintr_dispatch(int); +void softintr_schedule(void *); void softintr(int); -#define softintr_schedule(arg) \ -do { \ - struct soft_intrhand *__sih = (arg); \ - struct soft_intr *__si = __sih->sih_intrhead; \ - \ - mtx_enter(&__si->softintr_lock); \ - if (__sih->sih_pending == 0) { \ - TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ - __sih->sih_pending = 1; \ - softintr(__si->softintr_ssir); \ - } \ - mtx_leave(&__si->softintr_lock); \ -} while (/*CONSTCOND*/ 0) - #endif /* _KERNEL */ #endif /* _MACHINE_SOFTINTR_H_ */ Index: arch/powerpc64/powerpc64/softintr.c =================================================================== RCS file: src/sys/arch/powerpc64/powerpc64/softintr.c,v retrieving revision 1.2 diff -u -p -r1.2 softintr.c --- arch/powerpc64/powerpc64/softintr.c 7 Oct 2020 12:13:23 -0000 1.2 +++ arch/powerpc64/powerpc64/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -37,11 +37,31 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <machine/intr.h> #include <uvm/uvm_extern.h> +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) + sih_q; + struct soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void (*sih_fnwrap)(void *); + void *sih_arg; + void *sih_argwrap; + int sih_pending; +}; + +struct soft_intr { + TAILQ_HEAD(, soft_intrhand) + softintr_q; + int softintr_ssir; + struct mutex softintr_lock; +}; + struct soft_intr soft_intrs[SI_NSOFTINTR]; const int soft_intr_to_ssir[SI_NSOFTINTR] = { @@ -190,6 +210,21 @@ softintr_disestablish(void *arg) } void +softintr_schedule(void *arg) +{ + struct soft_intrhand *sih = arg; + struct soft_intr *si = sih->sih_intrhead; + + mtx_enter(&si->softintr_lock); + if (sih->sih_pending == 0) { + TAILQ_INSERT_TAIL(&si->softintr_q, sih, sih_q); + sih->sih_pending = 1; + softintr(si->softintr_ssir); + } + mtx_leave(&si->softintr_lock); +} + +void softintr(int intrq) { curcpu()->ci_ipending |= (1 << intrq); Index: arch/riscv64/include/softintr.h =================================================================== RCS file: src/sys/arch/riscv64/include/softintr.h,v retrieving revision 1.2 diff -u -p -r1.2 softintr.h --- arch/riscv64/include/softintr.h 11 May 2021 14:58:08 -0000 1.2 +++ arch/riscv64/include/softintr.h 4 Jun 2021 15:28:39 -0000 @@ -34,9 +34,6 @@ #ifdef _KERNEL -#include <sys/mutex.h> -#include <sys/queue.h> - /* * Generic software interrupt support for all AArch64 platforms. * @@ -51,23 +48,7 @@ #define SI_NSOFTINTR 4 -struct soft_intrhand { - TAILQ_ENTRY(soft_intrhand) - sih_q; - struct soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void (*sih_fnwrap)(void *); - void *sih_arg; - void *sih_argwrap; - int sih_pending; -}; - -struct soft_intr { - TAILQ_HEAD(, soft_intrhand) - softintr_q; - int softintr_ssir; - struct mutex softintr_lock; -}; +struct soft_intrhand; #define SOFTINTR_ESTABLISH_MPSAFE 0x01 void *softintr_establish_flags(int, void (*)(void *), void *, int); @@ -78,22 +59,9 @@ void *softintr_establish_flags(int, v void softintr_disestablish(void *); void softintr_init(void); void softintr_dispatch(int); +void softintr_schedule(void *); void softintr(int); -#define softintr_schedule(arg) \ -do { \ - struct soft_intrhand *__sih = (arg); \ - struct soft_intr *__si = __sih->sih_intrhead; \ - \ - mtx_enter(&__si->softintr_lock); \ - if (__sih->sih_pending == 0) { \ - TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ - __sih->sih_pending = 1; \ - softintr(__si->softintr_ssir); \ - } \ - mtx_leave(&__si->softintr_lock); \ -} while (/*CONSTCOND*/ 0) - #endif /* _KERNEL */ #endif /* _MACHINE_SOFTINTR_H_ */ Index: arch/riscv64/riscv64/softintr.c =================================================================== RCS file: src/sys/arch/riscv64/riscv64/softintr.c,v retrieving revision 1.3 diff -u -p -r1.3 softintr.c --- arch/riscv64/riscv64/softintr.c 12 May 2021 01:20:52 -0000 1.3 +++ arch/riscv64/riscv64/softintr.c 4 Jun 2021 15:28:39 -0000 @@ -36,11 +36,31 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <machine/intr.h> #include <uvm/uvm_extern.h> +struct soft_intrhand { + TAILQ_ENTRY(soft_intrhand) + sih_q; + struct soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void (*sih_fnwrap)(void *); + void *sih_arg; + void *sih_argwrap; + int sih_pending; +}; + +struct soft_intr { + TAILQ_HEAD(, soft_intrhand) + softintr_q; + int softintr_ssir; + struct mutex softintr_lock; +}; + struct soft_intr soft_intrs[SI_NSOFTINTR]; const int soft_intr_to_ssir[SI_NSOFTINTR] = { @@ -189,6 +209,21 @@ softintr_disestablish(void *arg) } void +softintr_schedule(void *arg) +{ + struct soft_intrhand *sih = arg; + struct soft_intr *si = sih->sih_intrhead; + + mtx_enter(&si->softintr_lock); + if (sih->sih_pending == 0) { + TAILQ_INSERT_TAIL(&si->softintr_q, sih, sih_q); + sih->sih_pending = 1; + softintr(si->softintr_ssir); + } + mtx_leave(&si->softintr_lock); +} + +void softintr(int intrq) { // protected by mutex in caller Index: arch/sh/include/intr.h =================================================================== RCS file: src/sys/arch/sh/include/intr.h,v retrieving revision 1.10 diff -u -p -r1.10 intr.h --- arch/sh/include/intr.h 15 Jan 2016 18:53:26 -0000 1.10 +++ arch/sh/include/intr.h 4 Jun 2021 15:28:39 -0000 @@ -34,8 +34,6 @@ #include <sys/device.h> #include <sys/evcount.h> -#include <sys/mutex.h> -#include <sys/queue.h> #include <sh/psl.h> /* Interrupt sharing types. */ @@ -91,24 +89,6 @@ void intc_intr(int, int, int); void intpri_intr_priority(int evtcode, int level); -/* - * software simulated interrupt - */ -struct sh_soft_intrhand { - TAILQ_ENTRY(sh_soft_intrhand) sih_q; - struct sh_soft_intr *sih_intrhead; - void (*sih_fn)(void *); - void *sih_arg; - int sih_pending; -}; - -struct sh_soft_intr { - TAILQ_HEAD(, sh_soft_intrhand) - softintr_q; - unsigned long softintr_ipl; - struct mutex softintr_lock; -}; - void softintr_disestablish(void *); void softintr_dispatch(int); void *softintr_establish(int, void (*)(void *), void *); Index: arch/sh/sh/interrupt.c =================================================================== RCS file: src/sys/arch/sh/sh/interrupt.c,v retrieving revision 1.17 diff -u -p -r1.17 interrupt.c --- arch/sh/sh/interrupt.c 7 Oct 2020 12:13:23 -0000 1.17 +++ arch/sh/sh/interrupt.c 4 Jun 2021 15:28:39 -0000 @@ -33,6 +33,8 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/queue.h> #include <uvm/uvm_extern.h> /* uvmexp.intrs */ @@ -43,6 +45,21 @@ #include <machine/atomic.h> #include <machine/intr.h> +struct sh_soft_intrhand { + TAILQ_ENTRY(sh_soft_intrhand) sih_q; + struct sh_soft_intr *sih_intrhead; + void (*sih_fn)(void *); + void *sih_arg; + int sih_pending; +}; + +struct sh_soft_intr { + TAILQ_HEAD(, sh_soft_intrhand) + softintr_q; + unsigned long softintr_ipl; + struct mutex softintr_lock; +}; + void intc_intr_priority(int, int); struct intc_intrhand *intc_alloc_ih(void); void intc_free_ih(struct intc_intrhand *);