xref: /netbsd-src/sys/arch/mac68k/include/intr.h (revision 3ced769fe7a334399fec58501b354c1d245c9a4f)
1 /*	$NetBSD: intr.h,v 1.33 2024/02/28 13:05:40 thorpej Exp $	*/
2 
3 /*
4  * Copyright (C) 1997 Scott Reynolds
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _MAC68K_INTR_H_
31 #define _MAC68K_INTR_H_
32 
33 #include <machine/psl.h>
34 
35 #if defined(_KERNEL) || defined(_KMEMUSER)
36 typedef struct {
37 	uint16_t _ipl;
38 } ipl_cookie_t;
39 #endif
40 
41 #ifdef _KERNEL
42 
43 /* spl0 requires checking for software interrupts */
44 
45 #define	IPL_NONE	0
46 #define	IPL_SOFTCLOCK	1
47 #define	IPL_SOFTBIO	2
48 #define	IPL_SOFTNET	3
49 #define	IPL_SOFTSERIAL	4
50 #define	IPL_VM		5
51 #define	IPL_SCHED	6
52 #define	IPL_HIGH	7
53 #define	NIPL		8
54 
55 /*
56  * This array contains the appropriate PSL_S|PSL_IPL? values
57  * to raise interrupt priority to the requested level.
58  */
59 extern uint16_t ipl2psl_table[NIPL];
60 
61 /* These spl calls are _not_ to be used by machine-independent code. */
62 #define	splzs()		splserial()
63 
64 /*
65  * These should be used for:
66  * 1) ensuring mutual exclusion (why use processor level?)
67  * 2) allowing faster devices to take priority
68  */
69 
70 /* watch out for side effects */
71 #define splx(s)         ((s) & PSL_IPL ? _spl(s) : spl0())
72 
73 
74 typedef int ipl_t;
75 
76 static inline ipl_cookie_t
makeiplcookie(ipl_t ipl)77 makeiplcookie(ipl_t ipl)
78 {
79 
80 	return (ipl_cookie_t){._ipl = ipl};
81 }
82 
83 static inline int
splraiseipl(ipl_cookie_t icookie)84 splraiseipl(ipl_cookie_t icookie)
85 {
86 
87 	return _splraise(ipl2psl_table[icookie._ipl]);
88 }
89 
90 #include <sys/spl.h>
91 
92 /* intr.c */
93 struct clockframe;
94 void	intr_init(void);
95 void	intr_establish(int (*)(void *), void *, int);
96 void	intr_disestablish(int);
97 void	intr_dispatch(struct clockframe);
98 
99 /* locore.s */
100 int	spl0(void);
101 #endif /* _KERNEL */
102 
103 #endif /* _MAC68K_INTR_H_ */
104