osd_util.h revision 87826
18348SEric.Yu@Sun.COM/*
28348SEric.Yu@Sun.COM * Copyright (c) 1996-1999 Distributed Processing Technology Corporation
38348SEric.Yu@Sun.COM * All rights reserved.
48348SEric.Yu@Sun.COM *
58348SEric.Yu@Sun.COM * Redistribution and use in source form, with or without modification, are
68348SEric.Yu@Sun.COM * permitted provided that redistributions of source code must retain the
78348SEric.Yu@Sun.COM * above copyright notice, this list of conditions and the following disclaimer.
88348SEric.Yu@Sun.COM *
98348SEric.Yu@Sun.COM * This software is provided `as is' by Distributed Processing Technology and
108348SEric.Yu@Sun.COM * any express or implied warranties, including, but not limited to, the
118348SEric.Yu@Sun.COM * implied warranties of merchantability and fitness for a particular purpose,
128348SEric.Yu@Sun.COM * are disclaimed. In no event shall Distributed Processing Technology be
138348SEric.Yu@Sun.COM * liable for any direct, indirect, incidental, special, exemplary or
148348SEric.Yu@Sun.COM * consequential damages (including, but not limited to, procurement of
158348SEric.Yu@Sun.COM * substitute goods or services; loss of use, data, or profits; or business
168348SEric.Yu@Sun.COM * interruptions) however caused and on any theory of liability, whether in
178348SEric.Yu@Sun.COM * contract, strict liability, or tort (including negligence or otherwise)
188348SEric.Yu@Sun.COM * arising in any way out of the use of this driver software, even if advised
198348SEric.Yu@Sun.COM * of the possibility of such damage.
208348SEric.Yu@Sun.COM *
218348SEric.Yu@Sun.COM * $FreeBSD: head/sys/dev/asr/osd_util.h 87826 2001-12-13 23:48:34Z obrien $
228348SEric.Yu@Sun.COM */
239059SErik.Nordmark@Sun.COM
248348SEric.Yu@Sun.COM#ifndef         __OSD_UTIL_H
258348SEric.Yu@Sun.COM#define         __OSD_UTIL_H
268348SEric.Yu@Sun.COM
278348SEric.Yu@Sun.COM/*File - OSD_UTIL.H
288348SEric.Yu@Sun.COM ****************************************************************************
298348SEric.Yu@Sun.COM *
308348SEric.Yu@Sun.COM *Description:
318348SEric.Yu@Sun.COM *
328348SEric.Yu@Sun.COM *      This file contains defines and function prototypes that are
338348SEric.Yu@Sun.COM *operating system dependent.  The resources defined in this file
348348SEric.Yu@Sun.COM *are not specific to any particular application.
358348SEric.Yu@Sun.COM *
368348SEric.Yu@Sun.COM *Copyright Distributed Processing Technology, Corp.
378348SEric.Yu@Sun.COM *        140 Candace Dr.
388348SEric.Yu@Sun.COM *        Maitland, Fl. 32751   USA
398348SEric.Yu@Sun.COM *        Phone: (407) 830-5522  Fax: (407) 260-5366
408348SEric.Yu@Sun.COM *        All Rights Reserved
418348SEric.Yu@Sun.COM *
428348SEric.Yu@Sun.COM *Author:       Doug Anderson
438348SEric.Yu@Sun.COM *Date:         1/7/94
448348SEric.Yu@Sun.COM *
458348SEric.Yu@Sun.COM *Editors:
468348SEric.Yu@Sun.COM *
478348SEric.Yu@Sun.COM *Remarks:
488348SEric.Yu@Sun.COM *
498348SEric.Yu@Sun.COM *
508348SEric.Yu@Sun.COM *****************************************************************************/
518348SEric.Yu@Sun.COM
528348SEric.Yu@Sun.COM
538348SEric.Yu@Sun.COM/*Definitions - Defines & Constants ----------------------------------------- */
548348SEric.Yu@Sun.COM
558348SEric.Yu@Sun.COM/*----------------------------- */
568348SEric.Yu@Sun.COM/* Operating system selections: */
578348SEric.Yu@Sun.COM/*----------------------------- */
588348SEric.Yu@Sun.COM
598348SEric.Yu@Sun.COM/*#define               _DPT_MSDOS      */
608348SEric.Yu@Sun.COM/*#define               _DPT_WIN_3X     */
618348SEric.Yu@Sun.COM/*#define               _DPT_WIN_4X     */
628348SEric.Yu@Sun.COM/*#define               _DPT_WIN_NT     */
638348SEric.Yu@Sun.COM/*#define               _DPT_NETWARE    */
648348SEric.Yu@Sun.COM/*#define               _DPT_OS2        */
658348SEric.Yu@Sun.COM/*#define               _DPT_SCO        */
668348SEric.Yu@Sun.COM/*#define               _DPT_UNIXWARE   */
678348SEric.Yu@Sun.COM/*#define               _DPT_SOLARIS    */
688348SEric.Yu@Sun.COM/*#define               _DPT_NEXTSTEP   */
698348SEric.Yu@Sun.COM/*#define               _DPT_BANYAN     */
708348SEric.Yu@Sun.COM
718348SEric.Yu@Sun.COM/*-------------------------------- */
728348SEric.Yu@Sun.COM/* Include the OS specific defines */
738348SEric.Yu@Sun.COM/*-------------------------------- */
748348SEric.Yu@Sun.COM
758348SEric.Yu@Sun.COM/*#define       OS_SELECTION    From Above List */
768348SEric.Yu@Sun.COM/*#define       SEMAPHORE_T     ??? */
778348SEric.Yu@Sun.COM/*#define       DLL_HANDLE_T    ??? */
788348SEric.Yu@Sun.COM
798348SEric.Yu@Sun.COM#if (defined(KERNEL) && defined(__bsdi__))
808348SEric.Yu@Sun.COM# include        "i386/isa/dpt_osd_defs.h"
818348SEric.Yu@Sun.COM#elif ((defined(KERNEL) || defined(_KERNEL)) && defined(__FreeBSD__))
828348SEric.Yu@Sun.COM# if (KERN_VERSION < 3)
838348SEric.Yu@Sun.COM#  include        "i386/isa/dpt_osd_defs.h"
848348SEric.Yu@Sun.COM# else
858348SEric.Yu@Sun.COM#  include        "dev/asr/osd_defs.h"
868348SEric.Yu@Sun.COM# endif
878348SEric.Yu@Sun.COM#else
888348SEric.Yu@Sun.COM# include        "osd_defs.h"
898348SEric.Yu@Sun.COM#endif
908348SEric.Yu@Sun.COM
918348SEric.Yu@Sun.COM#ifndef DPT_UNALIGNED
928348SEric.Yu@Sun.COM   #define      DPT_UNALIGNED
938348SEric.Yu@Sun.COM#endif
948348SEric.Yu@Sun.COM
958348SEric.Yu@Sun.COM#ifndef DPT_EXPORT
968348SEric.Yu@Sun.COM   #define      DPT_EXPORT
978348SEric.Yu@Sun.COM#endif
988348SEric.Yu@Sun.COM
998348SEric.Yu@Sun.COM#ifndef DPT_IMPORT
1008348SEric.Yu@Sun.COM   #define      DPT_IMPORT
1018348SEric.Yu@Sun.COM#endif
1028348SEric.Yu@Sun.COM
1038348SEric.Yu@Sun.COM#ifndef DPT_RUNTIME_IMPORT
1048348SEric.Yu@Sun.COM   #define      DPT_RUNTIME_IMPORT  DPT_IMPORT
1058348SEric.Yu@Sun.COM#endif
1068348SEric.Yu@Sun.COM
1078348SEric.Yu@Sun.COM/*--------------------- */
1088348SEric.Yu@Sun.COM/* OS dependent defines */
1098348SEric.Yu@Sun.COM/*--------------------- */
1108348SEric.Yu@Sun.COM
1118348SEric.Yu@Sun.COM#if defined (_DPT_MSDOS) || defined (_DPT_WIN_3X)
1128348SEric.Yu@Sun.COM   #define      _DPT_16_BIT
1138348SEric.Yu@Sun.COM#else
1148348SEric.Yu@Sun.COM   #define      _DPT_32_BIT
1158348SEric.Yu@Sun.COM#endif
1168348SEric.Yu@Sun.COM
1178348SEric.Yu@Sun.COM#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)
1188348SEric.Yu@Sun.COM   #define      _DPT_UNIX
1198348SEric.Yu@Sun.COM#endif
1208348SEric.Yu@Sun.COM
1218348SEric.Yu@Sun.COM#if defined (_DPT_WIN_3x) || defined (_DPT_WIN_4X) || defined (_DPT_WIN_NT) \
1228348SEric.Yu@Sun.COM	    || defined (_DPT_OS2)
1238348SEric.Yu@Sun.COM   #define      _DPT_DLL_SUPPORT
1248348SEric.Yu@Sun.COM#endif
1258348SEric.Yu@Sun.COM
1268348SEric.Yu@Sun.COM#if !defined (_DPT_MSDOS) && !defined (_DPT_WIN_3X) && !defined (_DPT_NETWARE)
1278348SEric.Yu@Sun.COM   #define      _DPT_PREEMPTIVE
1288348SEric.Yu@Sun.COM#endif
1298348SEric.Yu@Sun.COM
1308348SEric.Yu@Sun.COM#if !defined (_DPT_MSDOS) && !defined (_DPT_WIN_3X)
1318348SEric.Yu@Sun.COM   #define      _DPT_MULTI_THREADED
1328348SEric.Yu@Sun.COM#endif
1338348SEric.Yu@Sun.COM
1348348SEric.Yu@Sun.COM#if !defined (_DPT_MSDOS)
1358348SEric.Yu@Sun.COM   #define      _DPT_MULTI_TASKING
1368348SEric.Yu@Sun.COM#endif
1378348SEric.Yu@Sun.COM
1388348SEric.Yu@Sun.COM  /* These exist for platforms that   */
1398348SEric.Yu@Sun.COM  /* chunk when accessing mis-aligned */
1408348SEric.Yu@Sun.COM  /* data                             */
1418348SEric.Yu@Sun.COM#if defined (SNI_MIPS) || defined (_DPT_SOLARIS)
1428348SEric.Yu@Sun.COM   #if defined (_DPT_BIG_ENDIAN)
1438348SEric.Yu@Sun.COM	#if !defined (_DPT_STRICT_ALIGN)
1448348SEric.Yu@Sun.COM            #define _DPT_STRICT_ALIGN
1458348SEric.Yu@Sun.COM	#endif
1468348SEric.Yu@Sun.COM   #endif
1478348SEric.Yu@Sun.COM#endif
1488348SEric.Yu@Sun.COM
1498348SEric.Yu@Sun.COM  /* Determine if in C or C++ mode */
1508348SEric.Yu@Sun.COM#ifdef  __cplusplus
1518348SEric.Yu@Sun.COM   #define      _DPT_CPP
1528348SEric.Yu@Sun.COM#else
1538348SEric.Yu@Sun.COM   #define      _DPT_C
1548348SEric.Yu@Sun.COM#endif
1558348SEric.Yu@Sun.COM
1568348SEric.Yu@Sun.COM/*-------------------------------------------------------------------*/
1578348SEric.Yu@Sun.COM/* Under Solaris the compiler refuses to accept code like:           */
1588348SEric.Yu@Sun.COM/*   { {"DPT"}, 0, NULL .... },                                      */
1598348SEric.Yu@Sun.COM/* and complains about the {"DPT"} part by saying "cannot use { }    */
1608348SEric.Yu@Sun.COM/* to initialize char*".                                             */
1618348SEric.Yu@Sun.COM/*                                                                   */
1628348SEric.Yu@Sun.COM/* By defining these ugly macros we can get around this and also     */
1638348SEric.Yu@Sun.COM/* not have to copy and #ifdef large sections of code.  I know that  */
1648348SEric.Yu@Sun.COM/* these macros are *really* ugly, but they should help reduce       */
1658348SEric.Yu@Sun.COM/* maintenance in the long run.                                      */
1668348SEric.Yu@Sun.COM/*                                                                   */
1678348SEric.Yu@Sun.COM/* In the meantime, just pray that we can all move to Win32 as soon  */
1688348SEric.Yu@Sun.COM/* as possible...                                                    */
1698348SEric.Yu@Sun.COM/*-------------------------------------------------------------------*/
1708348SEric.Yu@Sun.COM#if !defined (DPTSQO)
1718348SEric.Yu@Sun.COM   #if defined (_DPT_SOLARIS)
1728348SEric.Yu@Sun.COM      #define DPTSQO
1739059SErik.Nordmark@Sun.COM      #define DPTSQC
1749059SErik.Nordmark@Sun.COM   #else
1759059SErik.Nordmark@Sun.COM      #define DPTSQO {
1769059SErik.Nordmark@Sun.COM      #define DPTSQC }
1779059SErik.Nordmark@Sun.COM   #endif  /* solaris */
1789059SErik.Nordmark@Sun.COM#endif  /* DPTSQO */
1799059SErik.Nordmark@Sun.COM
1809059SErik.Nordmark@Sun.COM
1819059SErik.Nordmark@Sun.COM/*---------------------- */
1828348SEric.Yu@Sun.COM/* OS dependent typedefs */
1838348SEric.Yu@Sun.COM/*---------------------- */
1848348SEric.Yu@Sun.COM
1858348SEric.Yu@Sun.COM#if defined (_DPT_MSDOS) || defined (_DPT_SCO)
1868348SEric.Yu@Sun.COM   #define BYTE unsigned char
1878348SEric.Yu@Sun.COM   #define WORD unsigned short
1888348SEric.Yu@Sun.COM#endif
1898348SEric.Yu@Sun.COM
1908348SEric.Yu@Sun.COM#ifndef _DPT_TYPEDEFS
1918348SEric.Yu@Sun.COM   #define _DPT_TYPEDEFS
1928348SEric.Yu@Sun.COM   typedef unsigned char   uCHAR;
1938348SEric.Yu@Sun.COM   typedef unsigned short  uSHORT;
1948348SEric.Yu@Sun.COM   typedef unsigned int    uINT;
1958348SEric.Yu@Sun.COM   typedef unsigned long   uLONG;
1968348SEric.Yu@Sun.COM
1978348SEric.Yu@Sun.COM   typedef union {
1988348SEric.Yu@Sun.COM	 uCHAR        u8[4];
1998348SEric.Yu@Sun.COM	 uSHORT       u16[2];
2008348SEric.Yu@Sun.COM	 uLONG        u32;
2018348SEric.Yu@Sun.COM   } access_U;
2028348SEric.Yu@Sun.COM#endif
2038348SEric.Yu@Sun.COM
2048348SEric.Yu@Sun.COM#if !defined (NULL)
2058348SEric.Yu@Sun.COM   #define      NULL    0
2068348SEric.Yu@Sun.COM#endif
2078348SEric.Yu@Sun.COM
2088348SEric.Yu@Sun.COM
2098348SEric.Yu@Sun.COM/*Prototypes - function ----------------------------------------------------- */
2108348SEric.Yu@Sun.COM
2118348SEric.Yu@Sun.COM#ifdef  __cplusplus
2128348SEric.Yu@Sun.COM   extern "C" {         /* Declare all these functions as "C" functions */
2138348SEric.Yu@Sun.COM#endif
2148348SEric.Yu@Sun.COM
2158348SEric.Yu@Sun.COM/*------------------------ */
2168348SEric.Yu@Sun.COM/* Byte reversal functions */
2178348SEric.Yu@Sun.COM/*------------------------ */
2188348SEric.Yu@Sun.COM
2198348SEric.Yu@Sun.COM  /* Reverses the byte ordering of a 2 byte variable */
2208348SEric.Yu@Sun.COM#if (!defined(osdSwap2))
2218348SEric.Yu@Sun.COM uSHORT       osdSwap2(DPT_UNALIGNED uSHORT *);
2228348SEric.Yu@Sun.COM#endif  /* !osdSwap2 */
2238348SEric.Yu@Sun.COM
2248348SEric.Yu@Sun.COM  /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */
2258348SEric.Yu@Sun.COM#if (!defined(osdSwap3))
2268348SEric.Yu@Sun.COM uLONG        osdSwap3(DPT_UNALIGNED uLONG *);
2278348SEric.Yu@Sun.COM#endif  /* !osdSwap3 */
2288348SEric.Yu@Sun.COM
2298348SEric.Yu@Sun.COM
2308348SEric.Yu@Sun.COM#ifdef  _DPT_NETWARE
231   #include "novpass.h" /* For DPT_Bswapl() prototype */
232	/* Inline the byte swap */
233   #ifdef __cplusplus
234	 inline uLONG osdSwap4(uLONG *inLong) {
235	 return *inLong = DPT_Bswapl(*inLong);
236	 }
237   #else
238	 #define osdSwap4(inLong)       DPT_Bswapl(inLong)
239   #endif  /* cplusplus */
240#else
241	/* Reverses the byte ordering of a 4 byte variable */
242# if (!defined(osdSwap4))
243   uLONG        osdSwap4(DPT_UNALIGNED uLONG *);
244# endif  /* !osdSwap4 */
245
246  /* The following functions ALWAYS swap regardless of the *
247   * presence of DPT_BIG_ENDIAN                            */
248
249   uSHORT       trueSwap2(DPT_UNALIGNED uSHORT *);
250   uLONG        trueSwap4(DPT_UNALIGNED uLONG *);
251
252#endif  /* netware */
253
254
255/*-------------------------------------*
256 * Network order swap functions        *
257 *                                     *
258 * These functions/macros will be used *
259 * by the structure insert()/extract() *
260 * functions.                          *
261 *
262 * We will enclose all structure       *
263 * portability modifications inside    *
264 * #ifdefs.  When we are ready, we     *
265 * will #define DPT_PORTABLE to begin  *
266 * using the modifications.            *
267 *-------------------------------------*/
268uLONG	netSwap4(uLONG val);
269
270#if defined (_DPT_BIG_ENDIAN)
271
272/* for big-endian we need to swap */
273
274#ifndef NET_SWAP_2
275#define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8))
276#endif  /* NET_SWAP_2 */
277
278#ifndef NET_SWAP_4
279#define NET_SWAP_4(x) netSwap4((x))
280#endif  /* NET_SWAP_4 */
281
282#else
283
284/* for little-endian we don't need to do anything */
285
286#ifndef NET_SWAP_2
287#define NET_SWAP_2(x) (x)
288#endif  /* NET_SWAP_2 */
289
290#ifndef NET_SWAP_4
291#define NET_SWAP_4(x) (x)
292#endif  /* NET_SWAP_4 */
293
294#endif  /* big endian */
295
296
297
298/*----------------------------------- */
299/* Run-time loadable module functions */
300/*----------------------------------- */
301
302  /* Loads the specified run-time loadable DLL */
303DLL_HANDLE_T    osdLoadModule(uCHAR *);
304  /* Unloads the specified run-time loadable DLL */
305uSHORT          osdUnloadModule(DLL_HANDLE_T);
306  /* Returns a pointer to a function inside a run-time loadable DLL */
307void *          osdGetFnAddr(DLL_HANDLE_T,uCHAR *);
308
309/*--------------------------------------- */
310/* Mutually exclusive semaphore functions */
311/*--------------------------------------- */
312
313  /* Create a named semaphore */
314SEMAPHORE_T     osdCreateNamedSemaphore(char *);
315  /* Create a mutually exlusive semaphore */
316SEMAPHORE_T     osdCreateSemaphore(void);
317	/* create an event semaphore */
318SEMAPHORE_T              osdCreateEventSemaphore(void);
319	/* create a named event semaphore */
320SEMAPHORE_T             osdCreateNamedEventSemaphore(char *);
321
322  /* Destroy the specified mutually exclusive semaphore object */
323uSHORT          osdDestroySemaphore(SEMAPHORE_T);
324  /* Request access to the specified mutually exclusive semaphore */
325uLONG           osdRequestSemaphore(SEMAPHORE_T,uLONG);
326  /* Release access to the specified mutually exclusive semaphore */
327uSHORT          osdReleaseSemaphore(SEMAPHORE_T);
328	/* wait for a event to happen */
329uLONG                            osdWaitForEventSemaphore(SEMAPHORE_T, uLONG);
330	/* signal an event */
331uLONG                            osdSignalEventSemaphore(SEMAPHORE_T);
332	/* reset the event */
333uLONG                            osdResetEventSemaphore(SEMAPHORE_T);
334
335/*----------------- */
336/* Thread functions */
337/*----------------- */
338
339  /* Releases control to the task switcher in non-preemptive */
340  /* multitasking operating systems. */
341void            osdSwitchThreads(void);
342
343  /* Starts a thread function */
344uLONG   osdStartThread(void *,void *);
345
346/* what is my thread id */
347uLONG osdGetThreadID(void);
348
349/* wakes up the specifed thread */
350void osdWakeThread(uLONG);
351
352/* osd sleep for x miliseconds */
353void osdSleep(uLONG);
354
355#define DPT_THREAD_PRIORITY_LOWEST 0x00
356#define DPT_THREAD_PRIORITY_NORMAL 0x01
357#define DPT_THREAD_PRIORITY_HIGHEST 0x02
358
359uCHAR osdSetThreadPriority(uLONG tid, uCHAR priority);
360
361#ifdef __cplusplus
362   }    /* end the xtern "C" declaration */
363#endif
364
365#endif  /* osd_util_h */
366