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