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