intr.h revision 1.8 1 1.8 is /* $NetBSD: intr.h,v 1.8 1998/07/18 21:27:27 is Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*
4 1.6 mycroft * Copyright (c) 1996, 1997 Charles M. Hannum. All rights reserved.
5 1.1 mycroft *
6 1.1 mycroft * Redistribution and use in source and binary forms, with or without
7 1.1 mycroft * modification, are permitted provided that the following conditions
8 1.1 mycroft * are met:
9 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.1 mycroft * notice, this list of conditions and the following disclaimer.
11 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.1 mycroft * documentation and/or other materials provided with the distribution.
14 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.1 mycroft * must display the following acknowledgement:
16 1.1 mycroft * This product includes software developed by Charles M. Hannum.
17 1.1 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.1 mycroft * derived from this software without specific prior written permission.
19 1.1 mycroft *
20 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 mycroft */
31 1.1 mycroft
32 1.4 mycroft #ifndef _I386_INTR_H_
33 1.4 mycroft #define _I386_INTR_H_
34 1.4 mycroft
35 1.6 mycroft /* Interrupt priority `levels'. */
36 1.7 mycroft #define IPL_NONE 9 /* nothing */
37 1.7 mycroft #define IPL_SOFTCLOCK 8 /* timeouts */
38 1.7 mycroft #define IPL_SOFTNET 7 /* protocol stacks */
39 1.7 mycroft #define IPL_BIO 6 /* block I/O */
40 1.7 mycroft #define IPL_NET 5 /* network */
41 1.7 mycroft #define IPL_SOFTSERIAL 4 /* serial */
42 1.7 mycroft #define IPL_TTY 3 /* terminal */
43 1.7 mycroft #define IPL_IMP 3 /* memory allocation */
44 1.7 mycroft #define IPL_AUDIO 2 /* audio */
45 1.6 mycroft #define IPL_CLOCK 1 /* clock */
46 1.6 mycroft #define IPL_HIGH 1 /* everything */
47 1.6 mycroft #define IPL_SERIAL 0 /* serial */
48 1.7 mycroft #define NIPL 10
49 1.1 mycroft
50 1.1 mycroft /* Interrupt sharing types. */
51 1.1 mycroft #define IST_NONE 0 /* none */
52 1.1 mycroft #define IST_PULSE 1 /* pulsed */
53 1.1 mycroft #define IST_EDGE 2 /* edge-triggered */
54 1.1 mycroft #define IST_LEVEL 3 /* level-triggered */
55 1.3 mycroft
56 1.3 mycroft /* Soft interrupt masks. */
57 1.3 mycroft #define SIR_CLOCK 31
58 1.3 mycroft #define SIR_NET 30
59 1.6 mycroft #define SIR_SERIAL 29
60 1.3 mycroft
61 1.3 mycroft #ifndef _LOCORE
62 1.3 mycroft
63 1.3 mycroft volatile int cpl, ipending, astpending;
64 1.6 mycroft int imask[NIPL];
65 1.3 mycroft
66 1.3 mycroft extern void Xspllower __P((void));
67 1.3 mycroft
68 1.3 mycroft static __inline int splraise __P((int));
69 1.3 mycroft static __inline int spllower __P((int));
70 1.3 mycroft static __inline void splx __P((int));
71 1.3 mycroft static __inline void softintr __P((int));
72 1.3 mycroft
73 1.3 mycroft /*
74 1.3 mycroft * Add a mask to cpl, and return the old value of cpl.
75 1.3 mycroft */
76 1.3 mycroft static __inline int
77 1.3 mycroft splraise(ncpl)
78 1.3 mycroft register int ncpl;
79 1.3 mycroft {
80 1.3 mycroft register int ocpl = cpl;
81 1.3 mycroft
82 1.3 mycroft cpl = ocpl | ncpl;
83 1.3 mycroft return (ocpl);
84 1.3 mycroft }
85 1.3 mycroft
86 1.3 mycroft /*
87 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
88 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
89 1.3 mycroft */
90 1.3 mycroft static __inline void
91 1.3 mycroft splx(ncpl)
92 1.3 mycroft register int ncpl;
93 1.3 mycroft {
94 1.3 mycroft
95 1.3 mycroft cpl = ncpl;
96 1.3 mycroft if (ipending & ~ncpl)
97 1.3 mycroft Xspllower();
98 1.3 mycroft }
99 1.3 mycroft
100 1.3 mycroft /*
101 1.3 mycroft * Same as splx(), but we return the old value of spl, for the
102 1.3 mycroft * benefit of some splsoftclock() callers.
103 1.3 mycroft */
104 1.3 mycroft static __inline int
105 1.3 mycroft spllower(ncpl)
106 1.3 mycroft register int ncpl;
107 1.3 mycroft {
108 1.3 mycroft register int ocpl = cpl;
109 1.3 mycroft
110 1.3 mycroft cpl = ncpl;
111 1.3 mycroft if (ipending & ~ncpl)
112 1.3 mycroft Xspllower();
113 1.3 mycroft return (ocpl);
114 1.3 mycroft }
115 1.3 mycroft
116 1.3 mycroft /*
117 1.3 mycroft * Hardware interrupt masks
118 1.3 mycroft */
119 1.3 mycroft #define splbio() splraise(imask[IPL_BIO])
120 1.3 mycroft #define splnet() splraise(imask[IPL_NET])
121 1.3 mycroft #define spltty() splraise(imask[IPL_TTY])
122 1.7 mycroft #define splaudio() splraise(imask[IPL_AUDIO])
123 1.3 mycroft #define splclock() splraise(imask[IPL_CLOCK])
124 1.7 mycroft #define splstatclock() splclock()
125 1.6 mycroft #define splserial() splraise(imask[IPL_SERIAL])
126 1.8 is
127 1.8 is #define spllpt() spltty()
128 1.3 mycroft
129 1.3 mycroft /*
130 1.3 mycroft * Software interrupt masks
131 1.3 mycroft *
132 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
133 1.3 mycroft * clock to softclock before it calls softclock().
134 1.3 mycroft */
135 1.6 mycroft #define splsoftclock() spllower(imask[IPL_SOFTCLOCK])
136 1.6 mycroft #define splsoftnet() splraise(imask[IPL_SOFTNET])
137 1.6 mycroft #define splsoftserial() splraise(imask[IPL_SOFTSERIAL])
138 1.3 mycroft
139 1.3 mycroft /*
140 1.3 mycroft * Miscellaneous
141 1.3 mycroft */
142 1.7 mycroft #define splimp() splraise(imask[IPL_IMP])
143 1.6 mycroft #define splhigh() splraise(imask[IPL_HIGH])
144 1.3 mycroft #define spl0() spllower(0)
145 1.3 mycroft
146 1.3 mycroft /*
147 1.3 mycroft * Software interrupt registration
148 1.3 mycroft *
149 1.3 mycroft * We hand-code this to ensure that it's atomic.
150 1.3 mycroft */
151 1.3 mycroft static __inline void
152 1.3 mycroft softintr(mask)
153 1.3 mycroft register int mask;
154 1.3 mycroft {
155 1.3 mycroft
156 1.6 mycroft __asm __volatile("orl %0,_ipending" : : "ir" (1 << mask));
157 1.3 mycroft }
158 1.3 mycroft
159 1.3 mycroft #define setsoftast() (astpending = 1)
160 1.6 mycroft #define setsoftclock() softintr(SIR_CLOCK)
161 1.6 mycroft #define setsoftnet() softintr(SIR_NET)
162 1.6 mycroft #define setsoftserial() softintr(SIR_SERIAL)
163 1.3 mycroft
164 1.3 mycroft #endif /* !_LOCORE */
165 1.4 mycroft
166 1.4 mycroft #endif /* !_I386_INTR_H_ */
167