xref: /openbsd-src/sys/arch/powerpc64/include/softintr.h (revision dacd911afd79bb107e64e769fd9f403208f9a3bc)
1*dacd911aSkettenis /*	$OpenBSD: softintr.h,v 1.2 2020/08/14 16:51:09 kettenis Exp $	*/
213861200Skettenis 
313861200Skettenis /*-
413861200Skettenis  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
513861200Skettenis  * All rights reserved.
613861200Skettenis  *
713861200Skettenis  * This code is derived from software contributed to The NetBSD Foundation
813861200Skettenis  * by Charles M. Hannum, and by Jason R. Thorpe.
913861200Skettenis  *
1013861200Skettenis  * Redistribution and use in source and binary forms, with or without
1113861200Skettenis  * modification, are permitted provided that the following conditions
1213861200Skettenis  * are met:
1313861200Skettenis  * 1. Redistributions of source code must retain the above copyright
1413861200Skettenis  *    notice, this list of conditions and the following disclaimer.
1513861200Skettenis  * 2. Redistributions in binary form must reproduce the above copyright
1613861200Skettenis  *    notice, this list of conditions and the following disclaimer in the
1713861200Skettenis  *    documentation and/or other materials provided with the distribution.
1813861200Skettenis  *
1913861200Skettenis  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2013861200Skettenis  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2113861200Skettenis  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2213861200Skettenis  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2313861200Skettenis  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2413861200Skettenis  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2513861200Skettenis  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2613861200Skettenis  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2713861200Skettenis  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2813861200Skettenis  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2913861200Skettenis  * POSSIBILITY OF SUCH DAMAGE.
3013861200Skettenis  */
3113861200Skettenis 
3213861200Skettenis #ifndef	_MACHINE_SOFTINTR_H_
3313861200Skettenis #define	_MACHINE_SOFTINTR_H_
3413861200Skettenis 
3513861200Skettenis #ifdef _KERNEL
3613861200Skettenis 
3713861200Skettenis #include <sys/mutex.h>
3813861200Skettenis #include <sys/queue.h>
3913861200Skettenis 
4013861200Skettenis /*
41*dacd911aSkettenis  * Generic software interrupt support.
4213861200Skettenis  *
4313861200Skettenis  * To use this code, include <machine/softintr.h> from your platform's
4413861200Skettenis  * <machine/intr.h>.
4513861200Skettenis  */
4613861200Skettenis 
4713861200Skettenis #define	SIR_SOFT	0	/* for IPL_SOFT */
4813861200Skettenis #define	SIR_CLOCK	1	/* for IPL_SOFTCLOCK */
4913861200Skettenis #define	SIR_NET		2	/* for IPL_SOFTNET */
5013861200Skettenis #define	SIR_TTY		3	/* for IPL_SOFTTTY */
5113861200Skettenis 
5213861200Skettenis #define	SI_NSOFTINTR		4
5313861200Skettenis 
5413861200Skettenis struct soft_intrhand {
5513861200Skettenis 	TAILQ_ENTRY(soft_intrhand)
5613861200Skettenis 		sih_q;
5713861200Skettenis 	struct soft_intr *sih_intrhead;
5813861200Skettenis 	void    (*sih_fn)(void *);
5913861200Skettenis 	void    (*sih_fnwrap)(void *);
6013861200Skettenis 	void    *sih_arg;
6113861200Skettenis 	void    *sih_argwrap;
6213861200Skettenis 	int     sih_pending;
6313861200Skettenis };
6413861200Skettenis 
6513861200Skettenis struct soft_intr {
6613861200Skettenis 	TAILQ_HEAD(, soft_intrhand)
6713861200Skettenis 			softintr_q;
6813861200Skettenis 	int             softintr_ssir;
6913861200Skettenis 	struct mutex    softintr_lock;
7013861200Skettenis };
7113861200Skettenis 
7213861200Skettenis #define SOFTINTR_ESTABLISH_MPSAFE       0x01
7313861200Skettenis void    *softintr_establish_flags(int, void (*)(void *), void *, int);
7413861200Skettenis #define softintr_establish(i, f, a)                                     \
7513861200Skettenis         softintr_establish_flags(i, f, a, 0)
7613861200Skettenis #define softintr_establish_mpsafe(i, f, a)                              \
7713861200Skettenis         softintr_establish_flags(i, f, a, SOFTINTR_ESTABLISH_MPSAFE)
7813861200Skettenis void    softintr_disestablish(void *);
7913861200Skettenis void    softintr_init(void);
8013861200Skettenis void    softintr_dispatch(int);
8113861200Skettenis void    softintr(int);
8213861200Skettenis 
8313861200Skettenis #define softintr_schedule(arg)						\
8413861200Skettenis do {									\
8513861200Skettenis 	struct soft_intrhand *__sih = (arg);				\
8613861200Skettenis 	struct soft_intr *__si = __sih->sih_intrhead;			\
8713861200Skettenis 									\
8813861200Skettenis 	mtx_enter(&__si->softintr_lock);				\
8913861200Skettenis 	if (__sih->sih_pending == 0) {					\
9013861200Skettenis 		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
9113861200Skettenis 		__sih->sih_pending = 1;					\
9213861200Skettenis 		softintr(__si->softintr_ssir);				\
9313861200Skettenis 	}								\
9413861200Skettenis 	mtx_leave(&__si->softintr_lock);				\
9513861200Skettenis } while (/*CONSTCOND*/ 0)
9613861200Skettenis 
9713861200Skettenis #endif /* _KERNEL */
9813861200Skettenis 
9913861200Skettenis #endif	/* _MACHINE_SOFTINTR_H_ */
100