- Get oskittcp to compile on msvc.
[reactos.git] / reactos / drivers / lib / oskittcp / include / freebsd / src / sys / machine / spl.h
1 /*
2 * Copyright (c) 1996-1999 University of Utah and the Flux Group.
3 * All rights reserved.
4 *
5 * This file is part of the Flux OSKit. The OSKit is free software, also known
6 * as "open source;" you can redistribute it and/or modify it under the terms
7 * of the GNU General Public License (GPL), version 2, as published by the Free
8 * Software Foundation (FSF). To explore alternate licensing terms, contact
9 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
10 *
11 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
14 * received a copy of the GPL along with the OSKit; see the file COPYING. If
15 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
16 */
17 /*-
18 * Copyright (c) 1993 The Regents of the University of California.
19 * All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. All advertising materials mentioning features or use of this software
30 * must display the following acknowledgement:
31 * This product includes software developed by the University of
32 * California, Berkeley and its contributors.
33 * 4. Neither the name of the University nor the names of its contributors
34 * may be used to endorse or promote products derived from this software
35 * without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 *
49 */
50
51 #ifndef _MACHINE_IPL_H_
52 #define _MACHINE_IPL_H_
53
54 #include <machine/ipl.h> /* XXX "machine" means cpu for i386 */
55
56 /*
57 * Software interrupt bit numbers in priority order. The priority only
58 * determines which swi will be dispatched next; a higher priority swi
59 * may be dispatched when a nested h/w interrupt handler returns.
60 */
61 #define SWI_TTY (NHWI + 0)
62 #define SWI_NET (NHWI + 1)
63 #define SWI_CLOCK 30
64 #define SWI_AST 31
65
66 /*
67 * Corresponding interrupt-pending bits for ipending.
68 */
69 #define SWI_TTY_PENDING (1 << SWI_TTY)
70 #define SWI_NET_PENDING (1 << SWI_NET)
71 #define SWI_CLOCK_PENDING (1 << SWI_CLOCK)
72 #define SWI_AST_PENDING (1 << SWI_AST)
73
74 /*
75 * Corresponding interrupt-disable masks for cpl. The ordering is now by
76 * inclusion (where each mask is considered as a set of bits). Everything
77 * except SWI_AST_MASK includes SWI_CLOCK_MASK so that softclock() doesn't
78 * run while other swi handlers are running and timeout routines can call
79 * swi handlers. Everything includes SWI_AST_MASK so that AST's are masked
80 * until just before return to user mode. SWI_TTY_MASK includes SWI_NET_MASK
81 * in case tty interrupts are processed at splsofttty() for a tty that is in
82 * SLIP or PPP line discipline (this is weaker than merging net_imask with
83 * tty_imask in isa.c - splimp() must mask hard and soft tty interrupts, but
84 * spltty() apparently only needs to mask soft net interrupts).
85 */
86 #define SWI_TTY_MASK (SWI_TTY_PENDING | SWI_CLOCK_MASK | SWI_NET_MASK)
87 #define SWI_NET_MASK (SWI_NET_PENDING | SWI_CLOCK_MASK)
88 #define SWI_CLOCK_MASK (SWI_CLOCK_PENDING | SWI_AST_MASK)
89 #define SWI_AST_MASK SWI_AST_PENDING
90 #define SWI_MASK (~HWI_MASK)
91
92 #ifdef OSKIT
93 #include "osenv.h"
94
95 extern unsigned oskit_freebsd_cpl;
96 extern unsigned oskit_freebsd_ipending;
97
98 #define GENERIC_SPL(you_name_it) \
99 static __inline int spl##you_name_it(void) \
100 { \
101 int t; \
102 osenv_intr_disable(); \
103 t = oskit_freebsd_cpl; \
104 oskit_freebsd_cpl = 1; \
105 return t; \
106 }
107
108 GENERIC_SPL(imp)
109 GENERIC_SPL(net)
110 GENERIC_SPL(bio)
111 GENERIC_SPL(high)
112 GENERIC_SPL(clock)
113 GENERIC_SPL(tty)
114 GENERIC_SPL(softtty)
115 /*
116 * this is used to reduce the clock spl to a softclock spl before
117 * calling the softclock handler directly. It will never call splx!
118 */
119 #define splsoftclock() 0
120
121 static __inline void splx(int x)
122 {
123 if (x == 0) {
124 oskit_freebsd_cpl = 0;
125 osenv_intr_enable();
126 }
127 }
128
129 /* for code from NetBSD */
130 #define spl0() splx(0)
131
132 #define setsoftclock() (oskit_freebsd_ipending |= SWI_CLOCK_PENDING)
133 #define setsofttty() (oskit_freebsd_ipending |= SWI_TTY_PENDING)
134
135 #define schedsofttty() (oskit_freebsd_ipending |= SWI_TTY_PENDING)
136
137 /*
138 * functions to save and restore the current cpl
139 */
140 static __inline void save_cpl(unsigned *x)
141 {
142 *x = oskit_freebsd_cpl;
143 }
144
145 static __inline void restore_cpl(unsigned x)
146 {
147 oskit_freebsd_cpl = x;
148 }
149
150 #else /* !OSKIT */
151 #ifndef LOCORE
152
153 extern unsigned bio_imask; /* group of interrupts masked with splbio() */
154 extern unsigned cpl; /* current priority level mask */
155 extern volatile unsigned idelayed; /* interrupts to become pending */
156 extern volatile unsigned ipending; /* active interrupts masked by cpl */
157 extern unsigned net_imask; /* group of interrupts masked with splimp() */
158 extern unsigned stat_imask; /* interrupts masked with splstatclock() */
159 extern unsigned tty_imask; /* group of interrupts masked with spltty() */
160
161 /*
162 * ipending has to be volatile so that it is read every time it is accessed
163 * in splx() and spl0(), but we don't want it to be read nonatomically when
164 * it is changed. Pretending that ipending is a plain int happens to give
165 * suitable atomic code for "ipending |= constant;".
166 */
167 #define setdelayed() (*(unsigned *)&ipending |= loadandclear(&idelayed))
168 #define setsoftast() (*(unsigned *)&ipending |= SWI_AST_PENDING)
169 #define setsoftclock() (*(unsigned *)&ipending |= SWI_CLOCK_PENDING)
170 #define setsoftnet() (*(unsigned *)&ipending |= SWI_NET_PENDING)
171 #define setsofttty() (*(unsigned *)&ipending |= SWI_TTY_PENDING)
172
173 #define schedsofttty() (*(unsigned *)&idelayed |= SWI_TTY_PENDING)
174
175 #ifdef _MSC_VER
176
177 static int splhigh() { return 0; }
178 static int splimp() { return 0; }
179 static int splnet() { return 0; }
180 static int splx(x) { return 0; }
181 static int splclock() { return 0; }
182
183 #elif defined(__GNUC__)
184
185 void splz __P((void));
186
187 #define GENSPL(name, set_cpl) \
188 static __inline int name(void) \
189 { \
190 unsigned x; \
191 \
192 __asm __volatile("" : : : "memory"); \
193 x = cpl; \
194 set_cpl; \
195 return (x); \
196 }
197
198 GENSPL(splbio, cpl |= bio_imask)
199 GENSPL(splclock, cpl = HWI_MASK | SWI_MASK)
200 GENSPL(splhigh, cpl = HWI_MASK | SWI_MASK)
201 GENSPL(splimp, cpl |= net_imask)
202 GENSPL(splnet, cpl |= SWI_NET_MASK)
203 GENSPL(splsoftclock, cpl = SWI_CLOCK_MASK)
204 GENSPL(splsofttty, cpl |= SWI_TTY_MASK)
205 GENSPL(splstatclock, cpl |= stat_imask)
206 GENSPL(spltty, cpl |= tty_imask)
207
208 static __inline void
209 spl0(void)
210 {
211 cpl = SWI_AST_MASK;
212 if (ipending & ~SWI_AST_MASK)
213 splz();
214 }
215
216 static __inline void
217 splx(int ipl)
218 {
219 cpl = ipl;
220 if (ipending & ~ipl)
221 splz();
222 }
223
224 #endif /* __GNUC__ */
225
226 #endif /* !LOCORE */
227 #endif /* !OSKIT */
228
229 #endif /* !_MACHINE_IPL_H_ */