1/*	$OpenBSD: intr.h,v 1.14 2018/08/20 15:02:07 visa Exp $	*/
2/*
3 * Copyright (c) 2001 Wasabi Systems, Inc.
4 * All rights reserved.
5 *
6 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed for the NetBSD Project by
19 *	Wasabi Systems, Inc.
20 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
21 *    or promote products derived from this software without specific prior
22 *    written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36/*
37 * Copyright (C) 2000 Steve Murphree, Jr.
38 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 *    notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 *    notice, this list of conditions and the following disclaimer in the
47 *    documentation and/or other materials provided with the distribution.
48 * 3. The name of the author may not be used to endorse or promote products
49 *    derived from this software without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62
63#ifndef _M88K_INTR_H_
64#define _M88K_INTR_H_
65
66#ifdef _KERNEL
67#ifndef _LOCORE
68int	getipl(void);
69int	setipl(int level);
70int	splraise(int);
71int	spl0(void);
72
73/* SPL asserts */
74#ifdef DIAGNOSTIC
75/*
76 * Although this function is implemented in MI code, it must be in this MD
77 * header because we don't want this header to include MI includes.
78 */
79void splassert_fail(int, int, const char *);
80extern int splassert_ctl;
81void splassert_check(int, const char *);
82#define splassert(__wantipl) do {			\
83	if (splassert_ctl > 0) {			\
84		splassert_check(__wantipl, __func__);	\
85	}						\
86} while (0)
87#define	splsoftassert(wantipl)	splassert(IPL_SOFTINT)
88#else
89#define	splassert(wantipl)	do { /* nothing */ } while (0)
90#define	splsoftassert(wantipl)	do { /* nothing */ } while (0)
91#endif
92
93#endif /* _LOCORE */
94
95#define splsoftclock()		splraise(IPL_SOFTINT)
96#define splsoftnet()		splraise(IPL_SOFTINT)
97#define splbio()		splraise(IPL_BIO)
98#define splnet()		splraise(IPL_NET)
99#define spltty()		splraise(IPL_TTY)
100#define splclock()		splraise(IPL_CLOCK)
101#define splstatclock()		splraise(IPL_STATCLOCK)
102#define	splsched()		splraise(IPL_SCHED)
103#define splvm()			splraise(IPL_VM)
104#define splhigh()		setipl(IPL_HIGH)
105
106#define splx(x)			((x) ? setipl((x)) : spl0())
107
108/*
109 * Generic software interrupt support for all m88k platforms.
110 */
111
112#ifndef _LOCORE
113
114#define	IPL_SOFT		0
115#define	IPL_SOFTCLOCK		1
116#define	IPL_SOFTNET		2
117#define	IPL_SOFTTTY		3
118
119#define	SI_SOFT			0	/* for IPL_SOFT */
120#define	SI_SOFTCLOCK		1	/* for IPL_SOFTCLOCK */
121#define	SI_SOFTNET		2	/* for IPL_SOFTNET */
122#define	SI_SOFTTTY		3	/* for IPL_SOFTTTY */
123
124#define	SI_NQUEUES		4
125
126#include <machine/mutex.h>
127#include <sys/queue.h>
128
129struct soft_intrhand {
130	TAILQ_ENTRY(soft_intrhand) sih_list;
131	void (*sih_func)(void *);
132	void *sih_arg;
133	struct soft_intrq *sih_siq;
134	int sih_pending;
135};
136
137struct soft_intrq {
138	TAILQ_HEAD(, soft_intrhand) siq_list;
139	int siq_si;
140	struct mutex siq_mtx;
141};
142
143void	 softintr_disestablish(void *);
144void	 softintr_dispatch(int);
145void	*softintr_establish(int, void (*)(void *), void *);
146void	 softintr_init(void);
147void	 softintr_schedule(void *);
148
149extern int softpending;
150
151#endif	/* _LOCORE */
152
153#endif /* _KERNEL */
154#endif /* _M88K_INTR_H_ */
155