[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / drivers / scsi / dpt / osd_util.h
blob4b56c0436ba2727970fd245289ce271174f54425
1 /* BSDI osd_util.h,v 1.8 1998/06/03 19:14:58 karels Exp */
3 /*
4 * Copyright (c) 1996-1999 Distributed Processing Technology Corporation
5 * All rights reserved.
7 * Redistribution and use in source form, with or without modification, are
8 * permitted provided that redistributions of source code must retain the
9 * above copyright notice, this list of conditions and the following disclaimer.
11 * This software is provided `as is' by Distributed Processing Technology and
12 * any express or implied warranties, including, but not limited to, the
13 * implied warranties of merchantability and fitness for a particular purpose,
14 * are disclaimed. In no event shall Distributed Processing Technology be
15 * liable for any direct, indirect, incidental, special, exemplary or
16 * consequential damages (including, but not limited to, procurement of
17 * substitute goods or services; loss of use, data, or profits; or business
18 * interruptions) however caused and on any theory of liability, whether in
19 * contract, strict liability, or tort (including negligence or otherwise)
20 * arising in any way out of the use of this driver software, even if advised
21 * of the possibility of such damage.
25 #ifndef __OSD_UTIL_H
26 #define __OSD_UTIL_H
28 /*File - OSD_UTIL.H
29 ****************************************************************************
31 *Description:
33 * This file contains defines and function prototypes that are
34 *operating system dependent. The resources defined in this file
35 *are not specific to any particular application.
37 *Copyright Distributed Processing Technology, Corp.
38 * 140 Candace Dr.
39 * Maitland, Fl. 32751 USA
40 * Phone: (407) 830-5522 Fax: (407) 260-5366
41 * All Rights Reserved
43 *Author: Doug Anderson
44 *Date: 1/7/94
46 *Editors:
48 *Remarks:
51 *****************************************************************************/
54 /*Definitions - Defines & Constants ----------------------------------------- */
56 /*----------------------------- */
57 /* Operating system selections: */
58 /*----------------------------- */
60 /*#define _DPT_MSDOS */
61 /*#define _DPT_WIN_3X */
62 /*#define _DPT_WIN_4X */
63 /*#define _DPT_WIN_NT */
64 /*#define _DPT_NETWARE */
65 /*#define _DPT_OS2 */
66 /*#define _DPT_SCO */
67 /*#define _DPT_UNIXWARE */
68 /*#define _DPT_SOLARIS */
69 /*#define _DPT_NEXTSTEP */
70 /*#define _DPT_BANYAN */
72 /*-------------------------------- */
73 /* Include the OS specific defines */
74 /*-------------------------------- */
76 /*#define OS_SELECTION From Above List */
77 /*#define SEMAPHORE_T ??? */
78 /*#define DLL_HANDLE_T ??? */
80 #if (defined(KERNEL) && (defined(__FreeBSD__) || defined(__bsdi__)))
81 # include "i386/isa/dpt_osd_defs.h"
82 #else
83 # include "osd_defs.h"
84 #endif
86 #ifndef DPT_UNALIGNED
87 #define DPT_UNALIGNED
88 #endif
90 #ifndef DPT_EXPORT
91 #define DPT_EXPORT
92 #endif
94 #ifndef DPT_IMPORT
95 #define DPT_IMPORT
96 #endif
98 #ifndef DPT_RUNTIME_IMPORT
99 #define DPT_RUNTIME_IMPORT DPT_IMPORT
100 #endif
102 /*--------------------- */
103 /* OS dependent defines */
104 /*--------------------- */
106 #if defined (_DPT_MSDOS) || defined (_DPT_WIN_3X)
107 #define _DPT_16_BIT
108 #else
109 #define _DPT_32_BIT
110 #endif
112 #if defined (_DPT_SCO) || defined (_DPT_UNIXWARE) || defined (_DPT_SOLARIS) || defined (_DPT_AIX) || defined (SNI_MIPS) || defined (_DPT_BSDI) || defined (_DPT_FREE_BSD) || defined(_DPT_LINUX)
113 #define _DPT_UNIX
114 #endif
116 #if defined (_DPT_WIN_3x) || defined (_DPT_WIN_4X) || defined (_DPT_WIN_NT) \
117 || defined (_DPT_OS2)
118 #define _DPT_DLL_SUPPORT
119 #endif
121 #if !defined (_DPT_MSDOS) && !defined (_DPT_WIN_3X) && !defined (_DPT_NETWARE)
122 #define _DPT_PREEMPTIVE
123 #endif
125 #if !defined (_DPT_MSDOS) && !defined (_DPT_WIN_3X)
126 #define _DPT_MULTI_THREADED
127 #endif
129 #if !defined (_DPT_MSDOS)
130 #define _DPT_MULTI_TASKING
131 #endif
133 /* These exist for platforms that */
134 /* chunk when accessing mis-aligned */
135 /* data */
136 #if defined (SNI_MIPS) || defined (_DPT_SOLARIS)
137 #if defined (_DPT_BIG_ENDIAN)
138 #if !defined (_DPT_STRICT_ALIGN)
139 #define _DPT_STRICT_ALIGN
140 #endif
141 #endif
142 #endif
144 /* Determine if in C or C++ mode */
145 #ifdef __cplusplus
146 #define _DPT_CPP
147 #else
148 #define _DPT_C
149 #endif
151 /*-------------------------------------------------------------------*/
152 /* Under Solaris the compiler refuses to accept code like: */
153 /* { {"DPT"}, 0, NULL .... }, */
154 /* and complains about the {"DPT"} part by saying "cannot use { } */
155 /* to initialize char*". */
156 /* */
157 /* By defining these ugly macros we can get around this and also */
158 /* not have to copy and #ifdef large sections of code. I know that */
159 /* these macros are *really* ugly, but they should help reduce */
160 /* maintenance in the long run. */
161 /* */
162 /*-------------------------------------------------------------------*/
163 #if !defined (DPTSQO)
164 #if defined (_DPT_SOLARIS)
165 #define DPTSQO
166 #define DPTSQC
167 #else
168 #define DPTSQO {
169 #define DPTSQC }
170 #endif /* solaris */
171 #endif /* DPTSQO */
174 /*---------------------- */
175 /* OS dependent typedefs */
176 /*---------------------- */
178 #if defined (_DPT_MSDOS) || defined (_DPT_SCO)
179 #define BYTE unsigned char
180 #define WORD unsigned short
181 #endif
183 #ifndef _DPT_TYPEDEFS
184 #define _DPT_TYPEDEFS
185 typedef unsigned char uCHAR;
186 typedef unsigned short uSHORT;
187 typedef unsigned int uINT;
188 typedef unsigned long uLONG;
190 typedef union {
191 uCHAR u8[4];
192 uSHORT u16[2];
193 uLONG u32;
194 } access_U;
195 #endif
197 #if !defined (NULL)
198 #define NULL 0
199 #endif
202 /*Prototypes - function ----------------------------------------------------- */
204 #ifdef __cplusplus
205 extern "C" { /* Declare all these functions as "C" functions */
206 #endif
208 /*------------------------ */
209 /* Byte reversal functions */
210 /*------------------------ */
212 /* Reverses the byte ordering of a 2 byte variable */
213 #if (!defined(osdSwap2))
214 uSHORT osdSwap2(DPT_UNALIGNED uSHORT *);
215 #endif // !osdSwap2
217 /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */
218 #if (!defined(osdSwap3))
219 uLONG osdSwap3(DPT_UNALIGNED uLONG *);
220 #endif // !osdSwap3
223 #ifdef _DPT_NETWARE
224 #include "novpass.h" /* For DPT_Bswapl() prototype */
225 /* Inline the byte swap */
226 #ifdef __cplusplus
227 inline uLONG osdSwap4(uLONG *inLong) {
228 return *inLong = DPT_Bswapl(*inLong);
230 #else
231 #define osdSwap4(inLong) DPT_Bswapl(inLong)
232 #endif // cplusplus
233 #else
234 /* Reverses the byte ordering of a 4 byte variable */
235 # if (!defined(osdSwap4))
236 uLONG osdSwap4(DPT_UNALIGNED uLONG *);
237 # endif // !osdSwap4
239 /* The following functions ALWAYS swap regardless of the *
240 * presence of DPT_BIG_ENDIAN */
242 uSHORT trueSwap2(DPT_UNALIGNED uSHORT *);
243 uLONG trueSwap4(DPT_UNALIGNED uLONG *);
245 #endif // netware
248 /*-------------------------------------*
249 * Network order swap functions *
251 * These functions/macros will be used *
252 * by the structure insert()/extract() *
253 * functions. *
255 * We will enclose all structure *
256 * portability modifications inside *
257 * #ifdefs. When we are ready, we *
258 * will #define DPT_PORTABLE to begin *
259 * using the modifications. *
260 *-------------------------------------*/
261 uLONG netSwap4(uLONG val);
263 #if defined (_DPT_BIG_ENDIAN)
265 // for big-endian we need to swap
267 #ifndef NET_SWAP_2
268 #define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8))
269 #endif // NET_SWAP_2
271 #ifndef NET_SWAP_4
272 #define NET_SWAP_4(x) netSwap4((x))
273 #endif // NET_SWAP_4
275 #else
277 // for little-endian we don't need to do anything
279 #ifndef NET_SWAP_2
280 #define NET_SWAP_2(x) (x)
281 #endif // NET_SWAP_2
283 #ifndef NET_SWAP_4
284 #define NET_SWAP_4(x) (x)
285 #endif // NET_SWAP_4
287 #endif // big endian
291 /*----------------------------------- */
292 /* Run-time loadable module functions */
293 /*----------------------------------- */
295 /* Loads the specified run-time loadable DLL */
296 DLL_HANDLE_T osdLoadModule(uCHAR *);
297 /* Unloads the specified run-time loadable DLL */
298 uSHORT osdUnloadModule(DLL_HANDLE_T);
299 /* Returns a pointer to a function inside a run-time loadable DLL */
300 void * osdGetFnAddr(DLL_HANDLE_T,uCHAR *);
302 /*--------------------------------------- */
303 /* Mutually exclusive semaphore functions */
304 /*--------------------------------------- */
306 /* Create a named semaphore */
307 SEMAPHORE_T osdCreateNamedSemaphore(char *);
308 /* Create a mutually exlusive semaphore */
309 SEMAPHORE_T osdCreateSemaphore(void);
310 /* create an event semaphore */
311 SEMAPHORE_T osdCreateEventSemaphore(void);
312 /* create a named event semaphore */
313 SEMAPHORE_T osdCreateNamedEventSemaphore(char *);
315 /* Destroy the specified mutually exclusive semaphore object */
316 uSHORT osdDestroySemaphore(SEMAPHORE_T);
317 /* Request access to the specified mutually exclusive semaphore */
318 uLONG osdRequestSemaphore(SEMAPHORE_T,uLONG);
319 /* Release access to the specified mutually exclusive semaphore */
320 uSHORT osdReleaseSemaphore(SEMAPHORE_T);
321 /* wait for a event to happen */
322 uLONG osdWaitForEventSemaphore(SEMAPHORE_T, uLONG);
323 /* signal an event */
324 uLONG osdSignalEventSemaphore(SEMAPHORE_T);
325 /* reset the event */
326 uLONG osdResetEventSemaphore(SEMAPHORE_T);
328 /*----------------- */
329 /* Thread functions */
330 /*----------------- */
332 /* Releases control to the task switcher in non-preemptive */
333 /* multitasking operating systems. */
334 void osdSwitchThreads(void);
336 /* Starts a thread function */
337 uLONG osdStartThread(void *,void *);
339 /* what is my thread id */
340 uLONG osdGetThreadID(void);
342 /* wakes up the specifed thread */
343 void osdWakeThread(uLONG);
345 /* osd sleep for x miliseconds */
346 void osdSleep(uLONG);
348 #define DPT_THREAD_PRIORITY_LOWEST 0x00
349 #define DPT_THREAD_PRIORITY_NORMAL 0x01
350 #define DPT_THREAD_PRIORITY_HIGHEST 0x02
352 uCHAR osdSetThreadPriority(uLONG tid, uCHAR priority);
354 #ifdef __cplusplus
355 } /* end the xtern "C" declaration */
356 #endif
358 #endif /* osd_util_h */