intr.h revision 1.3.96.2 1 1.3.96.2 matt /* $NetBSD: intr.h,v 1.3.96.2 2010/02/15 07:36:03 matt Exp $ */
2 1.3.96.2 matt /*-
3 1.3.96.2 matt * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
4 1.3.96.2 matt * All rights reserved.
5 1.3.96.2 matt *
6 1.3.96.2 matt * This code is derived from software contributed to The NetBSD Foundation
7 1.3.96.2 matt * by Matt Thomas <matt (at) 3am-software.com>.
8 1.3.96.2 matt *
9 1.3.96.2 matt * Redistribution and use in source and binary forms, with or without
10 1.3.96.2 matt * modification, are permitted provided that the following conditions
11 1.3.96.2 matt * are met:
12 1.3.96.2 matt * 1. Redistributions of source code must retain the above copyright
13 1.3.96.2 matt * notice, this list of conditions and the following disclaimer.
14 1.3.96.2 matt * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.96.2 matt * notice, this list of conditions and the following disclaimer in the
16 1.3.96.2 matt * documentation and/or other materials provided with the distribution.
17 1.3.96.2 matt *
18 1.3.96.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.3.96.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.3.96.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.3.96.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.3.96.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.3.96.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.3.96.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.3.96.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.3.96.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.3.96.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.3.96.2 matt * POSSIBILITY OF SUCH DAMAGE.
29 1.3.96.2 matt */
30 1.3.96.2 matt
31 1.3.96.2 matt #ifndef _MIPS_INTR_H_
32 1.3.96.2 matt #define _MIPS_INTR_H_
33 1.3.96.2 matt
34 1.3.96.2 matt /*
35 1.3.96.2 matt * This is a common <machine/intr.h> for all MIPS platforms.
36 1.3.96.2 matt */
37 1.3.96.2 matt
38 1.3.96.2 matt #define IPL_NONE 0
39 1.3.96.2 matt #ifdef __HAVE_PREEMPTION
40 1.3.96.2 matt #define IPL_PREEMPT (IPL_NONE+1)
41 1.3.96.2 matt #else
42 1.3.96.2 matt #define IPL_PREEMPT IPL_NONE
43 1.3.96.2 matt #endif
44 1.3.96.2 matt #define IPL_SOFTCLOCK (IPL_PREEMPT+1)
45 1.3.96.2 matt #define IPL_SOFTBIO (IPL_SOFTCLOCK) /* shares SWINT with softclock */
46 1.3.96.2 matt #define IPL_SOFTNET (IPL_SOFTBIO+1)
47 1.3.96.2 matt #define IPL_SOFTSERIAL (IPL_SOFTNET) /* shares SWINT with softnet */
48 1.3.96.2 matt #define IPL_VM (IPL_SOFTSERIAL+1)
49 1.3.96.2 matt #define IPL_SCHED (IPL_VM+1)
50 1.3.96.2 matt #define IPL_HIGH (IPL_SCHED)
51 1.3.96.2 matt
52 1.3.96.2 matt #define _IPL_N (IPL_HIGH+1)
53 1.3.96.2 matt
54 1.3.96.2 matt #define IST_UNUSABLE -1 /* interrupt cannot be used */
55 1.3.96.2 matt #define IST_NONE 0 /* none (dummy) */
56 1.3.96.2 matt #define IST_PULSE 1 /* pulsed */
57 1.3.96.2 matt #define IST_EDGE 2 /* edge-triggered */
58 1.3.96.2 matt #define IST_LEVEL 3 /* level-triggered */
59 1.3.96.2 matt #define IST_LEVEL_HIGH 4 /* level triggered, active high */
60 1.3.96.2 matt #define IST_LEVEL_LOW 5 /* level triggered, active low */
61 1.3.96.2 matt
62 1.3.96.2 matt struct splsw {
63 1.3.96.2 matt int (*splsw_splhigh)(void);
64 1.3.96.2 matt int (*splsw_splsched)(void);
65 1.3.96.2 matt int (*splsw_splvm)(void);
66 1.3.96.2 matt int (*splsw_splsoftserial)(void);
67 1.3.96.2 matt int (*splsw_splsoftnet)(void);
68 1.3.96.2 matt int (*splsw_splsoftbio)(void);
69 1.3.96.2 matt int (*splsw_splsoftclock)(void);
70 1.3.96.2 matt int (*splsw_splraise)(int);
71 1.3.96.2 matt void (*splsw_spl0)(void);
72 1.3.96.2 matt void (*splsw_splx)(int);
73 1.3.96.2 matt int (*splsw_splhigh_noprof)(void);
74 1.3.96.2 matt void (*splsw_splx_noprof)(int);
75 1.3.96.2 matt void (*splsw_setsoftintr)(uint32_t);
76 1.3.96.2 matt void (*splsw_clrsoftintr)(uint32_t);
77 1.3.96.2 matt int (*splsw_splintr)(uint32_t *);
78 1.3.96.2 matt void (*splsw_splcheck)(void);
79 1.3.96.2 matt };
80 1.3.96.2 matt
81 1.3.96.2 matt typedef int ipl_t;
82 1.3.96.2 matt typedef struct {
83 1.3.96.2 matt ipl_t _spl;
84 1.3.96.2 matt } ipl_cookie_t;
85 1.3.96.2 matt
86 1.3.96.2 matt #ifdef _KERNEL
87 1.3.96.2 matt extern struct splsw mips_splsw;
88 1.3.96.2 matt extern const uint32_t ipl_sr_bits[_IPL_N];
89 1.3.96.2 matt
90 1.3.96.2 matt static inline int
91 1.3.96.2 matt splhigh(void)
92 1.3.96.2 matt {
93 1.3.96.2 matt return (*mips_splsw.splsw_splhigh)();
94 1.3.96.2 matt }
95 1.3.96.2 matt
96 1.3.96.2 matt static inline int
97 1.3.96.2 matt splhigh_noprof(void)
98 1.3.96.2 matt {
99 1.3.96.2 matt return (*mips_splsw.splsw_splhigh_noprof)();
100 1.3.96.2 matt }
101 1.3.96.2 matt
102 1.3.96.2 matt static inline int
103 1.3.96.2 matt splsched(void)
104 1.3.96.2 matt {
105 1.3.96.2 matt return (*mips_splsw.splsw_splsched)();
106 1.3.96.2 matt }
107 1.3.96.2 matt
108 1.3.96.2 matt static inline int
109 1.3.96.2 matt splvm(void)
110 1.3.96.2 matt {
111 1.3.96.2 matt return (*mips_splsw.splsw_splvm)();
112 1.3.96.2 matt }
113 1.3.96.2 matt
114 1.3.96.2 matt static inline int
115 1.3.96.2 matt splsoftserial(void)
116 1.3.96.2 matt {
117 1.3.96.2 matt return (*mips_splsw.splsw_splsoftserial)();
118 1.3.96.2 matt }
119 1.3.96.2 matt
120 1.3.96.2 matt static inline int
121 1.3.96.2 matt splsoftnet(void)
122 1.3.96.2 matt {
123 1.3.96.2 matt return (*mips_splsw.splsw_splsoftnet)();
124 1.3.96.2 matt }
125 1.3.96.2 matt
126 1.3.96.2 matt static inline int
127 1.3.96.2 matt splsoftbio(void)
128 1.3.96.2 matt {
129 1.3.96.2 matt return (*mips_splsw.splsw_splsoftbio)();
130 1.3.96.2 matt }
131 1.3.96.2 matt
132 1.3.96.2 matt static inline int
133 1.3.96.2 matt splsoftclock(void)
134 1.3.96.2 matt {
135 1.3.96.2 matt return (*mips_splsw.splsw_splsoftclock)();
136 1.3.96.2 matt }
137 1.3.96.2 matt
138 1.3.96.2 matt static inline void
139 1.3.96.2 matt spl0(void)
140 1.3.96.2 matt {
141 1.3.96.2 matt (*mips_splsw.splsw_spl0)();
142 1.3.96.2 matt }
143 1.3.96.2 matt
144 1.3.96.2 matt static inline void
145 1.3.96.2 matt splx(int s)
146 1.3.96.2 matt {
147 1.3.96.2 matt (*mips_splsw.splsw_splx)(s);
148 1.3.96.2 matt }
149 1.3.96.2 matt
150 1.3.96.2 matt static inline void
151 1.3.96.2 matt splx_noprof(int s)
152 1.3.96.2 matt {
153 1.3.96.2 matt (*mips_splsw.splsw_splx_noprof)(s);
154 1.3.96.2 matt }
155 1.3.96.2 matt
156 1.3.96.2 matt static inline void
157 1.3.96.2 matt _setsoftintr(uint32_t m)
158 1.3.96.2 matt {
159 1.3.96.2 matt (*mips_splsw.splsw_setsoftintr)(m);
160 1.3.96.2 matt }
161 1.3.96.2 matt
162 1.3.96.2 matt static inline void
163 1.3.96.2 matt _clrsoftintr(uint32_t m)
164 1.3.96.2 matt {
165 1.3.96.2 matt (*mips_splsw.splsw_clrsoftintr)(m);
166 1.3.96.2 matt }
167 1.3.96.2 matt
168 1.3.96.2 matt static inline ipl_cookie_t
169 1.3.96.2 matt makeiplcookie(ipl_t s)
170 1.3.96.2 matt {
171 1.3.96.2 matt return (ipl_cookie_t){._spl = s};
172 1.3.96.2 matt }
173 1.3.96.2 matt
174 1.3.96.2 matt static inline int
175 1.3.96.2 matt splraise(int s)
176 1.3.96.2 matt {
177 1.3.96.2 matt return (*mips_splsw.splsw_splraise)(s);
178 1.3.96.2 matt }
179 1.3.96.2 matt
180 1.3.96.2 matt static inline int
181 1.3.96.2 matt splraiseipl(ipl_cookie_t icookie)
182 1.3.96.2 matt {
183 1.3.96.2 matt return splraise(icookie._spl);
184 1.3.96.2 matt }
185 1.3.96.2 matt
186 1.3.96.2 matt static inline int
187 1.3.96.2 matt splintr(uint32_t *p)
188 1.3.96.2 matt {
189 1.3.96.2 matt return (*mips_splsw.splsw_splintr)(p);
190 1.3.96.2 matt }
191 1.3.96.2 matt
192 1.3.96.2 matt #endif /* _KERNEL */
193 1.3.96.2 matt #endif /* _MIPS_INTR_H_ */
194