freebsd-skq/sys/dev/asr/osd_util.h

366 lines
10 KiB
C
Raw Normal View History

/*-
* Copyright (c) 1996-1999 Distributed Processing Technology Corporation
* All rights reserved.
*
* Redistribution and use in source form, with or without modification, are
* permitted provided that redistributions of source code must retain the
* above copyright notice, this list of conditions and the following disclaimer.
*
* This software is provided `as is' by Distributed Processing Technology and
* any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose,
* are disclaimed. In no event shall Distributed Processing Technology be
* liable for any direct, indirect, incidental, special, exemplary or
* consequential damages (including, but not limited to, procurement of
* substitute goods or services; loss of use, data, or profits; or business
* interruptions) however caused and on any theory of liability, whether in
* contract, strict liability, or tort (including negligence or otherwise)
* arising in any way out of the use of this driver software, even if advised
* of the possibility of such damage.
*
* $FreeBSD$
*/
2002-05-14 01:09:03 +00:00
#ifndef __OSD_UTIL_H
#define __OSD_UTIL_H
/*File - OSD_UTIL.H
****************************************************************************
*
*Description:
*
2002-05-14 01:09:03 +00:00
* This file contains defines and function prototypes that are
*operating system dependent. The resources defined in this file
*are not specific to any particular application.
*
*Copyright Distributed Processing Technology, Corp.
2002-05-14 01:09:03 +00:00
* 140 Candace Dr.
* Maitland, Fl. 32751 USA
* Phone: (407) 830-5522 Fax: (407) 260-5366
* All Rights Reserved
*
2002-05-14 01:09:03 +00:00
*Author: Doug Anderson
*Date: 1/7/94
*
*Editors:
*
*Remarks:
*
*
*****************************************************************************/
/*Definitions - Defines & Constants ----------------------------------------- */
/*----------------------------- */
/* Operating system selections: */
/*----------------------------- */
2002-05-14 01:09:03 +00:00
/*#define _DPT_MSDOS */
/*#define _DPT_WIN_3X */
/*#define _DPT_WIN_4X */
/*#define _DPT_WIN_NT */
/*#define _DPT_NETWARE */
/*#define _DPT_OS2 */
/*#define _DPT_SCO */
/*#define _DPT_UNIXWARE */
/*#define _DPT_SOLARIS */
/*#define _DPT_NEXTSTEP */
/*#define _DPT_BANYAN */
/*-------------------------------- */
/* Include the OS specific defines */
/*-------------------------------- */
2002-05-14 00:53:08 +00:00
/*#define OS_SELECTION From Above List */
/*#define SEMAPHORE_T ??? */
/*#define DLL_HANDLE_T ??? */
#if (defined(KERNEL) && defined(__bsdi__))
2002-05-14 01:09:03 +00:00
# include "i386/isa/dpt_osd_defs.h"
#elif ((defined(KERNEL) || defined(_KERNEL)) && defined(__FreeBSD__))
# if (KERN_VERSION < 3)
2002-05-14 01:09:03 +00:00
# include "i386/isa/dpt_osd_defs.h"
# else
2002-05-14 01:09:03 +00:00
# include "dev/asr/osd_defs.h"
# endif
#else
2002-05-14 01:09:03 +00:00
# include "osd_defs.h"
#endif
#ifndef DPT_UNALIGNED
2002-05-14 00:53:08 +00:00
#define DPT_UNALIGNED
#endif
#ifndef DPT_EXPORT
2002-05-14 00:53:08 +00:00
#define DPT_EXPORT
#endif
#ifndef DPT_IMPORT
2002-05-14 00:53:08 +00:00
#define DPT_IMPORT
#endif
#ifndef DPT_RUNTIME_IMPORT
2002-05-14 01:09:03 +00:00
#define DPT_RUNTIME_IMPORT DPT_IMPORT
#endif
/*--------------------- */
/* OS dependent defines */
/*--------------------- */
2002-05-14 21:54:56 +00:00
#if defined(_DPT_MSDOS) || defined(_DPT_WIN_3X)
2002-05-14 00:53:08 +00:00
#define _DPT_16_BIT
#else
2002-05-14 00:53:08 +00:00
#define _DPT_32_BIT
#endif
2002-05-14 21:54:56 +00:00
#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)
2002-05-14 00:53:08 +00:00
#define _DPT_UNIX
#endif
2002-05-14 21:54:56 +00:00
#if defined(_DPT_WIN_3x) || defined(_DPT_WIN_4X) || defined(_DPT_WIN_NT) \
|| defined(_DPT_OS2)
2002-05-14 00:53:08 +00:00
#define _DPT_DLL_SUPPORT
#endif
2002-05-14 21:54:56 +00:00
#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) && !defined(_DPT_NETWARE)
2002-05-14 00:53:08 +00:00
#define _DPT_PREEMPTIVE
#endif
2002-05-14 21:54:56 +00:00
#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X)
2002-05-14 00:53:08 +00:00
#define _DPT_MULTI_THREADED
#endif
2002-05-14 21:54:56 +00:00
#if !defined(_DPT_MSDOS)
2002-05-14 00:53:08 +00:00
#define _DPT_MULTI_TASKING
#endif
/* These exist for platforms that */
/* chunk when accessing mis-aligned */
2002-05-14 01:09:03 +00:00
/* data */
2002-05-14 21:54:56 +00:00
#if defined(SNI_MIPS) || defined(_DPT_SOLARIS)
#if defined(_DPT_BIG_ENDIAN)
#if !defined(_DPT_STRICT_ALIGN)
2002-05-14 01:09:03 +00:00
#define _DPT_STRICT_ALIGN
#endif
#endif
#endif
/* Determine if in C or C++ mode */
2002-05-14 01:09:03 +00:00
#ifdef __cplusplus
2002-05-14 00:53:08 +00:00
#define _DPT_CPP
#else
2002-05-14 00:53:08 +00:00
#define _DPT_C
#endif
/*-------------------------------------------------------------------*/
2002-05-14 01:09:03 +00:00
/* Under Solaris the compiler refuses to accept code like: */
/* { {"DPT"}, 0, NULL .... }, */
/* and complains about the {"DPT"} part by saying "cannot use { } */
2002-05-14 01:09:03 +00:00
/* to initialize char*". */
/* */
/* By defining these ugly macros we can get around this and also */
2002-05-14 01:09:03 +00:00
/* not have to copy and #ifdef large sections of code. I know that */
/* these macros are *really* ugly, but they should help reduce */
/* maintenance in the long run. */
/* */
/* In the meantime, just pray that we can all move to Win32 as soon */
2002-05-14 01:09:03 +00:00
/* as possible... */
/*-------------------------------------------------------------------*/
2002-05-14 21:54:56 +00:00
#if !defined(DPTSQO)
#if defined(_DPT_SOLARIS)
2002-05-14 00:53:08 +00:00
#define DPTSQO
#define DPTSQC
#else
2002-05-14 00:53:08 +00:00
#define DPTSQO {
#define DPTSQC }
#endif /* solaris */
2002-05-14 01:09:03 +00:00
#endif /* DPTSQO */
/*---------------------- */
/* OS dependent typedefs */
/*---------------------- */
2002-05-14 21:54:56 +00:00
#if defined(_DPT_MSDOS) || defined(_DPT_SCO)
2002-05-14 00:53:08 +00:00
#define BYTE unsigned char
#define WORD unsigned short
#endif
#ifndef _DPT_TYPEDEFS
2002-05-14 00:53:08 +00:00
#define _DPT_TYPEDEFS
typedef unsigned char uCHAR;
typedef unsigned short uSHORT;
2002-05-14 01:09:03 +00:00
typedef unsigned int uINT;
typedef unsigned long uLONG;
typedef union {
2002-05-14 01:09:03 +00:00
uCHAR u8[4];
uSHORT u16[2];
uLONG u32;
} access_U;
#endif
2002-05-14 21:54:56 +00:00
#if !defined(NULL)
2002-05-14 00:53:08 +00:00
#define NULL 0
#endif
/*Prototypes - function ----------------------------------------------------- */
2002-05-14 01:09:03 +00:00
#ifdef __cplusplus
extern "C" { /* Declare all these functions as "C" functions */
#endif
/*------------------------ */
/* Byte reversal functions */
/*------------------------ */
/* Reverses the byte ordering of a 2 byte variable */
#if (!defined(osdSwap2))
2002-05-14 01:09:03 +00:00
uSHORT osdSwap2(DPT_UNALIGNED uSHORT *);
#endif /* !osdSwap2 */
/* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */
#if (!defined(osdSwap3))
2002-05-14 01:09:03 +00:00
uLONG osdSwap3(DPT_UNALIGNED uLONG *);
#endif /* !osdSwap3 */
2002-05-14 01:09:03 +00:00
#ifdef _DPT_NETWARE
#include "novpass.h" /* For DPT_Bswapl() prototype */
/* Inline the byte swap */
#ifdef __cplusplus
inline uLONG osdSwap4(uLONG *inLong) {
return *inLong = DPT_Bswapl(*inLong);
}
#else
2002-05-14 00:53:08 +00:00
#define osdSwap4(inLong) DPT_Bswapl(inLong)
#endif /* cplusplus */
#else
/* Reverses the byte ordering of a 4 byte variable */
# if (!defined(osdSwap4))
2002-05-14 01:09:03 +00:00
uLONG osdSwap4(DPT_UNALIGNED uLONG *);
# endif /* !osdSwap4 */
/* The following functions ALWAYS swap regardless of the *
2002-05-14 01:09:03 +00:00
* presence of DPT_BIG_ENDIAN */
2002-05-14 01:09:03 +00:00
uSHORT trueSwap2(DPT_UNALIGNED uSHORT *);
uLONG trueSwap4(DPT_UNALIGNED uLONG *);
2002-05-14 01:09:03 +00:00
#endif /* netware */
/*-------------------------------------*
2002-05-14 01:09:03 +00:00
* Network order swap functions *
* *
* These functions/macros will be used *
* by the structure insert()/extract() *
2002-05-14 01:09:03 +00:00
* functions. *
*
* We will enclose all structure *
* portability modifications inside *
* #ifdefs. When we are ready, we *
* will #define DPT_PORTABLE to begin *
2002-05-14 01:09:03 +00:00
* using the modifications. *
*-------------------------------------*/
uLONG netSwap4(uLONG val);
2002-05-14 21:54:56 +00:00
#if defined(_DPT_BIG_ENDIAN)
/* for big-endian we need to swap */
#ifndef NET_SWAP_2
#define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8))
2002-05-14 01:09:03 +00:00
#endif /* NET_SWAP_2 */
#ifndef NET_SWAP_4
#define NET_SWAP_4(x) netSwap4((x))
2002-05-14 01:09:03 +00:00
#endif /* NET_SWAP_4 */
#else
/* for little-endian we don't need to do anything */
#ifndef NET_SWAP_2
#define NET_SWAP_2(x) (x)
2002-05-14 01:09:03 +00:00
#endif /* NET_SWAP_2 */
#ifndef NET_SWAP_4
#define NET_SWAP_4(x) (x)
2002-05-14 01:09:03 +00:00
#endif /* NET_SWAP_4 */
2002-05-14 01:09:03 +00:00
#endif /* big endian */
/*----------------------------------- */
/* Run-time loadable module functions */
/*----------------------------------- */
/* Loads the specified run-time loadable DLL */
2002-05-14 01:09:03 +00:00
DLL_HANDLE_T osdLoadModule(uCHAR *);
/* Unloads the specified run-time loadable DLL */
2002-05-14 01:09:03 +00:00
uSHORT osdUnloadModule(DLL_HANDLE_T);
/* Returns a pointer to a function inside a run-time loadable DLL */
2002-05-14 01:09:03 +00:00
void * osdGetFnAddr(DLL_HANDLE_T,uCHAR *);
/*--------------------------------------- */
/* Mutually exclusive semaphore functions */
/*--------------------------------------- */
/* Create a named semaphore */
2002-05-14 01:09:03 +00:00
SEMAPHORE_T osdCreateNamedSemaphore(char *);
/* Create a mutually exlusive semaphore */
2002-05-14 01:09:03 +00:00
SEMAPHORE_T osdCreateSemaphore(void);
/* create an event semaphore */
2002-05-14 01:09:03 +00:00
SEMAPHORE_T osdCreateEventSemaphore(void);
/* create a named event semaphore */
2002-05-14 01:09:03 +00:00
SEMAPHORE_T osdCreateNamedEventSemaphore(char *);
/* Destroy the specified mutually exclusive semaphore object */
2002-05-14 01:09:03 +00:00
uSHORT osdDestroySemaphore(SEMAPHORE_T);
/* Request access to the specified mutually exclusive semaphore */
2002-05-14 01:09:03 +00:00
uLONG osdRequestSemaphore(SEMAPHORE_T,uLONG);
/* Release access to the specified mutually exclusive semaphore */
2002-05-14 01:09:03 +00:00
uSHORT osdReleaseSemaphore(SEMAPHORE_T);
/* wait for an event to happen */
2002-05-14 01:09:03 +00:00
uLONG osdWaitForEventSemaphore(SEMAPHORE_T, uLONG);
/* signal an event */
2002-05-14 01:09:03 +00:00
uLONG osdSignalEventSemaphore(SEMAPHORE_T);
/* reset the event */
2002-05-14 01:09:03 +00:00
uLONG osdResetEventSemaphore(SEMAPHORE_T);
/*----------------- */
/* Thread functions */
/*----------------- */
/* Releases control to the task switcher in non-preemptive */
/* multitasking operating systems. */
2002-05-14 01:09:03 +00:00
void osdSwitchThreads(void);
/* Starts a thread function */
2002-05-14 01:09:03 +00:00
uLONG osdStartThread(void *,void *);
/* what is my thread id */
uLONG osdGetThreadID(void);
/* wakes up the specifed thread */
void osdWakeThread(uLONG);
/* osd sleep for x miliseconds */
void osdSleep(uLONG);
#define DPT_THREAD_PRIORITY_LOWEST 0x00
#define DPT_THREAD_PRIORITY_NORMAL 0x01
#define DPT_THREAD_PRIORITY_HIGHEST 0x02
uCHAR osdSetThreadPriority(uLONG tid, uCHAR priority);
#ifdef __cplusplus
2002-05-14 01:09:03 +00:00
} /* end the xtern "C" declaration */
#endif
2002-05-14 01:09:03 +00:00
#endif /* osd_util_h */