intr.h revision 1.6 1 1.6 mycroft /* $NetBSD: intr.h,v 1.6 1997/02/28 16:24:03 mycroft 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.6 mycroft #define IPL_NONE 8 /* nothing */
37 1.6 mycroft #define IPL_SOFTCLOCK 7 /* timeouts */
38 1.6 mycroft #define IPL_SOFTNET 6 /* protocol stacks */
39 1.6 mycroft #define IPL_BIO 5 /* block I/O */
40 1.6 mycroft #define IPL_NET 4 /* network */
41 1.6 mycroft #define IPL_SOFTSERIAL 3 /* serial */
42 1.1 mycroft #define IPL_TTY 2 /* terminal */
43 1.6 mycroft #define IPL_IMP 2 /* memory allocation */
44 1.6 mycroft #define IPL_CLOCK 1 /* clock */
45 1.6 mycroft #define IPL_HIGH 1 /* everything */
46 1.6 mycroft #define IPL_SERIAL 0 /* serial */
47 1.6 mycroft #define NIPL 9
48 1.1 mycroft
49 1.1 mycroft /* Interrupt sharing types. */
50 1.1 mycroft #define IST_NONE 0 /* none */
51 1.1 mycroft #define IST_PULSE 1 /* pulsed */
52 1.1 mycroft #define IST_EDGE 2 /* edge-triggered */
53 1.1 mycroft #define IST_LEVEL 3 /* level-triggered */
54 1.3 mycroft
55 1.3 mycroft /* Soft interrupt masks. */
56 1.3 mycroft #define SIR_CLOCK 31
57 1.3 mycroft #define SIR_NET 30
58 1.6 mycroft #define SIR_SERIAL 29
59 1.3 mycroft
60 1.3 mycroft #ifndef _LOCORE
61 1.3 mycroft
62 1.3 mycroft volatile int cpl, ipending, astpending;
63 1.6 mycroft int imask[NIPL];
64 1.3 mycroft
65 1.3 mycroft extern void Xspllower __P((void));
66 1.3 mycroft
67 1.3 mycroft static __inline int splraise __P((int));
68 1.3 mycroft static __inline int spllower __P((int));
69 1.3 mycroft static __inline void splx __P((int));
70 1.3 mycroft static __inline void softintr __P((int));
71 1.3 mycroft
72 1.3 mycroft /*
73 1.3 mycroft * Add a mask to cpl, and return the old value of cpl.
74 1.3 mycroft */
75 1.3 mycroft static __inline int
76 1.3 mycroft splraise(ncpl)
77 1.3 mycroft register int ncpl;
78 1.3 mycroft {
79 1.3 mycroft register int ocpl = cpl;
80 1.3 mycroft
81 1.3 mycroft cpl = ocpl | ncpl;
82 1.3 mycroft return (ocpl);
83 1.3 mycroft }
84 1.3 mycroft
85 1.3 mycroft /*
86 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
87 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
88 1.3 mycroft */
89 1.3 mycroft static __inline void
90 1.3 mycroft splx(ncpl)
91 1.3 mycroft register int ncpl;
92 1.3 mycroft {
93 1.3 mycroft
94 1.3 mycroft cpl = ncpl;
95 1.3 mycroft if (ipending & ~ncpl)
96 1.3 mycroft Xspllower();
97 1.3 mycroft }
98 1.3 mycroft
99 1.3 mycroft /*
100 1.3 mycroft * Same as splx(), but we return the old value of spl, for the
101 1.3 mycroft * benefit of some splsoftclock() callers.
102 1.3 mycroft */
103 1.3 mycroft static __inline int
104 1.3 mycroft spllower(ncpl)
105 1.3 mycroft register int ncpl;
106 1.3 mycroft {
107 1.3 mycroft register int ocpl = cpl;
108 1.3 mycroft
109 1.3 mycroft cpl = ncpl;
110 1.3 mycroft if (ipending & ~ncpl)
111 1.3 mycroft Xspllower();
112 1.3 mycroft return (ocpl);
113 1.3 mycroft }
114 1.3 mycroft
115 1.3 mycroft /*
116 1.3 mycroft * Hardware interrupt masks
117 1.3 mycroft */
118 1.3 mycroft #define splbio() splraise(imask[IPL_BIO])
119 1.3 mycroft #define splnet() splraise(imask[IPL_NET])
120 1.3 mycroft #define spltty() splraise(imask[IPL_TTY])
121 1.3 mycroft #define splclock() splraise(imask[IPL_CLOCK])
122 1.3 mycroft #define splimp() splraise(imask[IPL_IMP])
123 1.6 mycroft #define splserial() splraise(imask[IPL_SERIAL])
124 1.3 mycroft #define splstatclock() splclock()
125 1.3 mycroft
126 1.3 mycroft /*
127 1.3 mycroft * Software interrupt masks
128 1.3 mycroft *
129 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
130 1.3 mycroft * clock to softclock before it calls softclock().
131 1.3 mycroft */
132 1.6 mycroft #define splsoftclock() spllower(imask[IPL_SOFTCLOCK])
133 1.6 mycroft #define splsoftnet() splraise(imask[IPL_SOFTNET])
134 1.6 mycroft #define splsoftserial() splraise(imask[IPL_SOFTSERIAL])
135 1.3 mycroft
136 1.3 mycroft /*
137 1.3 mycroft * Miscellaneous
138 1.3 mycroft */
139 1.6 mycroft #define splhigh() splraise(imask[IPL_HIGH])
140 1.3 mycroft #define spl0() spllower(0)
141 1.3 mycroft
142 1.3 mycroft /*
143 1.3 mycroft * Software interrupt registration
144 1.3 mycroft *
145 1.3 mycroft * We hand-code this to ensure that it's atomic.
146 1.3 mycroft */
147 1.3 mycroft static __inline void
148 1.3 mycroft softintr(mask)
149 1.3 mycroft register int mask;
150 1.3 mycroft {
151 1.3 mycroft
152 1.6 mycroft __asm __volatile("orl %0,_ipending" : : "ir" (1 << mask));
153 1.3 mycroft }
154 1.3 mycroft
155 1.3 mycroft #define setsoftast() (astpending = 1)
156 1.6 mycroft #define setsoftclock() softintr(SIR_CLOCK)
157 1.6 mycroft #define setsoftnet() softintr(SIR_NET)
158 1.6 mycroft #define setsoftserial() softintr(SIR_SERIAL)
159 1.3 mycroft
160 1.3 mycroft #endif /* !_LOCORE */
161 1.4 mycroft
162 1.4 mycroft #endif /* !_I386_INTR_H_ */
163