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