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