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