1 /* $NetBSD: softintr.h,v 1.1 2002/01/29 22:54:14 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum, and by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _MACHINE_SOFTINTR_H_ 33 #define _MACHINE_SOFTINTR_H_ 34 35 #ifdef _KERNEL 36 37 #include <sys/mutex.h> 38 #include <sys/queue.h> 39 40 /* 41 * Generic software interrupt support for all AArch64 platforms. 42 * 43 * To use this code, include <machine/softintr.h> from your platform's 44 * <machine/intr.h>. 45 */ 46 47 #define SIR_SOFT 0 /* for IPL_SOFT */ 48 #define SIR_CLOCK 1 /* for IPL_SOFTCLOCK */ 49 #define SIR_NET 2 /* for IPL_SOFTNET */ 50 #define SIR_TTY 3 /* for IPL_SOFTTTY */ 51 52 #define SI_NSOFTINTR 4 53 54 struct soft_intrhand { 55 TAILQ_ENTRY(soft_intrhand) 56 sih_q; 57 struct soft_intr *sih_intrhead; 58 void (*sih_fn)(void *); 59 void (*sih_fnwrap)(void *); 60 void *sih_arg; 61 void *sih_argwrap; 62 int sih_pending; 63 }; 64 65 struct soft_intr { 66 TAILQ_HEAD(, soft_intrhand) 67 softintr_q; 68 int softintr_ssir; 69 struct mutex softintr_lock; 70 }; 71 72 #define SOFTINTR_ESTABLISH_MPSAFE 0x01 73 void *softintr_establish_flags(int, void (*)(void *), void *, int); 74 #define softintr_establish(i, f, a) \ 75 softintr_establish_flags(i, f, a, 0) 76 #define softintr_establish_mpsafe(i, f, a) \ 77 softintr_establish_flags(i, f, a, SOFTINTR_ESTABLISH_MPSAFE) 78 void softintr_disestablish(void *); 79 void softintr_init(void); 80 void softintr_dispatch(int); 81 void softintr(int); 82 83 #define softintr_schedule(arg) \ 84 do { \ 85 struct soft_intrhand *__sih = (arg); \ 86 struct soft_intr *__si = __sih->sih_intrhead; \ 87 \ 88 mtx_enter(&__si->softintr_lock); \ 89 if (__sih->sih_pending == 0) { \ 90 TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \ 91 __sih->sih_pending = 1; \ 92 softintr(__si->softintr_ssir); \ 93 } \ 94 mtx_leave(&__si->softintr_lock); \ 95 } while (/*CONSTCOND*/ 0) 96 97 #endif /* _KERNEL */ 98 99 #endif /* _MACHINE_SOFTINTR_H_ */ 100