


/****************************************************************************
;
; NAME: hwtypes.h
;
;
; DESCRIPTION:
;
;       Hardware-dependent data type definitions - FreeBSD & Linux
;
;
; REVISION HISTORY:
;
;       $Log: /ESASHBA/Linux/kmp/hwtypes.h $
; 
; 8     9/02/08 3:39p Pcullen
; Only undef VOID if defined; define it in either case.
; 
; 7     9/02/08 3:23p Pcullen
; Remove definition of VOID if defined before defining it. This allows
; sas hba driver to compile for SuSE/xen kernel.
; 
; 6     5/30/07 2:38p Jseba
; Picked up wchar definitions and other misc. cleanups
; 
; 5     2/20/07 2:49p Jseba
; Define DW
; 
; 4     8/28/06 11:14a Jseba
; Complete overhaul of this file
; 
; 3     7/24/06 4:09p Jseba
; Merge Linux and FreeBSD versions of this file
; 
; 2     5/30/06 2:42p Jseba
; Added bit64 and PBASEADDR
; 
; 1     2/14/05 2:01p Rcrispo
; Initial Entry.
; 
;
;
; THIS PROGRAM AND THE INFORMATION CONTAINED HEREIN IS THE PROPERTY OF
; ATTO TECHNOLOGY, INC. AND SHALL NOT BE REPRODUCED, COPIED, OR USED IN
; WHOLE OR IN PART OTHER THAN AS PROVIDED FOR IN THE LICENSE AGREEMENT
; PURSUANT TO WHICH IT WAS FURNISHED.
;
; COPYRIGHT (c) ATTO TECHNOLOGY, INC. 1996-2003
; ALL RIGHTS RESERVED.
;
;***************************************************************************/



#ifndef HWTYPES_H
#define HWTYPES_H

/* Make sure the OS types are defined first to override */
/* anything in here.                                    */
 
#include <ostypes.h>

/* Definitions that can be overridden by the OS layer   */

#ifndef FAR
#define FAR
#endif

#ifndef NEAR
#define NEAR
#endif

#ifndef HUGE
#define HUGE
#endif

#ifndef VOL
#define VOL     volatile
#endif

#ifndef FAST
#define FAST
#endif

#ifndef INLINE
#define INLINE  static inline
#endif

#ifndef UNALIGNED
#define UNALIGNED
#endif

#ifndef BASED
#define BASED
#endif

#ifndef CODEBASED
#define CODEBASED
#endif

#ifdef VOID
#undef VOID
#endif
#define VOID        void

#ifndef OS_CHAR
#define OS_CHAR     char
#endif

#ifndef OS_WCHAR
#define OS_WCHAR    unsigned short
#endif

#ifndef OS_SINT8
#define OS_SINT8    signed char
#endif

#ifndef OS_SINT16
#define OS_SINT16   signed short
#endif

#ifndef OS_SINT32
#define OS_SINT32   signed int
#endif

#ifndef OS_SINT64
#define OS_SINT64   signed long long
#endif

#ifndef OS_UINT8
#define OS_UINT8    unsigned char
#endif

#ifndef OS_UINT16
#define OS_UINT16   unsigned short
#endif

#ifndef OS_UINT32
#define OS_UINT32   unsigned int
#endif

#ifndef OS_UINT64
#define OS_UINT64   unsigned long long
#endif

#ifndef OS_BOOL
#define OS_BOOL     int
#endif

#ifndef TRUE
#define TRUE        (1)
#endif

#ifndef FALSE
#define FALSE       (0)
#endif

#ifndef OS_LOCK_STATE
#define OS_LOCK_STATE   int
#endif

#ifndef OS_DPC_STATE
#define OS_DPC_STATE    int
#endif

#ifndef OS_PBASEADDR
#define OS_PBASEADDR    OS_UINT8 *
#endif

/* Define the HW types based on the OS types */

typedef OS_CHAR             CHAR;
typedef OS_WCHAR            WCHAR;
typedef OS_UINT8            BYTE;
typedef OS_UINT16           WORD;
typedef OS_UINT32           DWORD;
typedef OS_UINT64           QWORD;

typedef OS_SINT8            SBYTE;
typedef OS_SINT16           SWORD;
typedef OS_SINT32           SDWORD;
typedef OS_SINT64           SQWORD;

typedef OS_BOOL             BOOL;

typedef OS_LOCK_STATE       LOCK_STATE, *PLOCK_STATE;
typedef OS_DPC_STATE        DPC_STATE,  *PDPC_STATE;

typedef OS_PBASEADDR        PBASEADDR;

/* Pointers */

typedef VOID            *   PVOID;
typedef CHAR            *   PSTR;
typedef WCHAR           *   PWSTR;
typedef BYTE            *   PBYTE;
typedef WORD            *   PWORD;
typedef DWORD           *   PDWORD;
typedef QWORD           *   PQWORD;

typedef VOID  FAR       *   LPVOID;
typedef CHAR  FAR       *   LPSTR;
typedef WCHAR FAR       *   LPWSTR;
typedef BYTE  FAR       *   LPBYTE;
typedef WORD  FAR       *   LPWORD;
typedef DWORD FAR       *   LPDWORD;
typedef QWORD FAR       *   LPQWORD;

typedef VOID  HUGE      *   HPVOID;
typedef CHAR  HUGE      *   HPSTR;
typedef WCHAR HUGE      *   HPWSTR;
typedef BYTE  HUGE      *   HPBYTE;
typedef WORD  HUGE      *   HPWORD;
typedef DWORD HUGE      *   HPDWORD;
typedef QWORD HUGE      *   HPQWORD;

typedef VOID  VOL       *   PVVOID;
typedef CHAR  VOL       *   PVSTR;
typedef WCHAR VOL       *   PVSTRW;
typedef BYTE  VOL       *   PVBYTE;
typedef WORD  VOL       *   PVWORD;
typedef DWORD VOL       *   PVDWORD;
typedef QWORD VOL       *   PVQWORD;

typedef VOID  BASED     *   BPVOID;
typedef CHAR  BASED     *   BPSTR;
typedef WCHAR BASED     *   BPWSTR;
typedef BYTE  BASED     *   BPBYTE;
typedef WORD  BASED     *   BPWORD;
typedef DWORD BASED     *   BPDWORD;
typedef QWORD BASED     *   BPQWORD;

typedef VOID  VOL BASED *   BPVVOID;
typedef CHAR  VOL BASED *   BPVSTR;
typedef WCHAR VOL BASED *   BPVSTRW;
typedef BYTE  VOL BASED *   BPVBYTE;
typedef WORD  VOL BASED *   BPVWORD;
typedef DWORD VOL BASED *   BPVDWORD;
typedef QWORD VOL BASED *   BPVQWORD;

/* Pointers to Pointers */

typedef PVOID           *   PPVOID;
typedef PSTR            *   PPSTR;
typedef PWSTR           *   PPWSTR;
typedef PBYTE           *   PPBYTE;
typedef PWORD           *   PPWORD;
typedef PDWORD          *   PPDWORD;
typedef PQWORD          *   PPQWORD;

typedef PVOID   VOL     *   PVPVOID;
typedef PSTR    VOL     *   PVPSTR;
typedef PWSTR   VOL     *   PVPWSTR;
typedef PBYTE   VOL     *   PVPBYTE;
typedef PWORD   VOL     *   PVPWORD;
typedef PDWORD  VOL     *   PVPDWORD;
typedef PQWORD  VOL     *   PVPQWORD;

typedef BPVOID          *   PBPVOID;
typedef BPSTR           *   PBPSTR;
typedef BPWSTR          *   PBPWSTR;
typedef BPBYTE          *   PBPBYTE;
typedef BPWORD          *   PBPWORD;
typedef BPDWORD         *   PBPDWORD;
typedef BPQWORD         *   PBPQWORD;

typedef PVOID   BASED   *   BPPVOID;
typedef PSTR    BASED   *   BPPSTR;
typedef PWSTR   BASED   *   BPPWSTR;
typedef PBYTE   BASED   *   BPPBYTE;
typedef PWORD   BASED   *   BPPWORD;
typedef PDWORD  BASED   *   BPPDWORD;
typedef PQWORD  BASED   *   BPPQWORD;

typedef BPVOID  FAR     *   LPBPVOID;
typedef BPSTR   FAR     *   LPBPSTR;
typedef BPWSTR  FAR     *   LPBPWSTR;
typedef BPBYTE  FAR     *   LPBPBYTE;
typedef BPWORD  FAR     *   LPBPWORD;
typedef BPDWORD FAR     *   LPBPDWORD;
typedef BPQWORD FAR     *   LPBPQWORD;

typedef BPVOID  VOL     *   PVBPVOID;
typedef BPSTR   VOL     *   PVBPSTR;
typedef BPWSTR  VOL     *   PVBPWSTR;
typedef BPBYTE  VOL     *   PVBPBYTE;
typedef BPWORD  VOL     *   PVBPWORD;
typedef BPDWORD VOL     *   PVBPDWORD;
typedef BPQWORD VOL     *   PVBPQWORD;

typedef BPVOID  BASED   *   BPBPVOID;
typedef BPSTR   BASED   *   BPBPSTR;
typedef BPWSTR  BASED   *   BPBPWSTR;
typedef BPBYTE  BASED   *   BPBPBYTE;
typedef BPWORD  BASED   *   BPBPWORD;
typedef BPDWORD BASED   *   BPBPDWORD;
typedef BPQWORD BASED   *   BPBPQWORD;

typedef BPVOID  VOL BASED * BPVBPVOID;
typedef BPSTR   VOL BASED * BPVBPSTR;
typedef BPWSTR  VOL BASED * BPVBPWSTR;
typedef BPBYTE  VOL BASED * BPVBPBYTE;
typedef BPWORD  VOL BASED * BPVBPWORD;
typedef BPDWORD VOL BASED * BPVBPDWORD;
typedef BPQWORD VOL BASED * BPVBPQWORD;

/* The following are so we can use hwpnp.h and have the sizes and offsets   */
/* in structures correct.                                                   */

#ifdef OS_16BIT
typedef VOID (FAR  *FARPROC)  (VOID);
typedef VOID (NEAR *NEARPROC) (VOID);
typedef BYTE NEAR  *NPBYTE;
#else
#define FARPROC     DWORD
#define NEARPROC    WORD
#define NPBYTE      WORD
#endif

/* Fibre Channel Worldwide Name */

typedef union WorldWideName
{
    BYTE    c [8];
    WORD    w [4];
    DWORD   d [2];

    /* We would like to add the following field, but there are several      */
    /* structures that include this type that will be realigned.  These     */
    /* include target mode IOCTLs that must maintain their format for       */
    /* compatibility.  Instead of finding and packing all such structures,  */
    /* don't define the QWORD member.                                       */

    /* QWORD   q; */

} WWN, *PWWN, BASED *BPWWN, FAR *LPWWN;

/* SAS Address */

typedef union SasAddress
{
    BYTE    c [8];
    WORD    w [4];
    DWORD   d [2];
    QWORD   q;

} SASADDR, *PSASADDR, BASED *BPSASADDR, FAR *LPSASADDR;

/* Define NULL for kicks */

#ifndef NULL
#define NULL ((VOID *) 0)
#endif

/* WORD component macros */

#ifndef LOBYTE
#define LOBYTE(w)   ((BYTE) (WORD) (w))
#endif

#ifndef HIBYTE
#define HIBYTE(w)   ((BYTE) (((WORD) (w)) >> 8))
#endif

#ifndef MAKEWORD
#define MAKEWORD(lo, hi) ((WORD) ((BYTE) (lo) | ((WORD) (BYTE) (hi) << 8)))
#endif

/* DWORD component macros */

#ifndef LOWORD
#define LOWORD(d)   ((WORD) (DWORD) (d))
#endif

#ifndef HIWORD
#define HIWORD(d)   ((WORD) (((DWORD) (d)) >> 16))
#endif

#ifndef MAKELONG
#define MAKELONG(lo, hi) ((DWORD) ((WORD) (lo) | ((DWORD) (WORD) (hi) << 16)))
#endif

#ifndef MAKEDWORD
#define MAKEDWORD(lo, hi) ((DWORD) ((WORD) (lo) | ((DWORD) (WORD) (hi) << 16)))
#endif

/* QWORD component macros. Don't use right-shift due to the inefficient     */
/* code produced.                                                           */

#ifndef LODWORD
#ifdef HOST_BIG_ENDIAN
#define LODWORD(pq)     (*((DWORD *) (&(pq)) + 1))
#else
#define LODWORD(pq)     (*((DWORD *) (&(pq)) + 0))
#endif
#endif

#ifndef HIDWORD
#ifdef HOST_BIG_ENDIAN
#define HIDWORD(pq)     (*((DWORD *) (&(pq)) + 0))
#else
#define HIDWORD(pq)     (*((DWORD *) (&(pq)) + 1))
#endif
#endif

#ifndef MAKEQWORD
#define MAKEQWORD(lo, hi) \
    ((QWORD) ((DWORD) (lo) | ((QWORD) (DWORD) (hi) << 32)))
#endif

#ifndef MAKEQUAD
#define MAKEQUAD(lo, hi) \
    ((QWORD) ((DWORD) (lo) | ((QWORD) (DWORD) (hi) << 32)))
#endif

/* Types and macros for physical addresses */

#ifndef _DOS_

  typedef QWORD     PHYSADDR;

  #ifndef MAKEPHYSADDR
    #define MAKEPHYSADDR(lo, hi)    ((PHYSADDR) MAKEQWORD (lo, hi))
  #endif
  #ifndef LOPHYSADDR
    #define LOPHYSADDR(pa)          LODWORD (pa)
  #endif
  #ifndef HIPHYSADDR
    #define HIPHYSADDR(pa)          HIDWORD (pa)
  #endif

#else   /* _DOS_ */

  typedef DWORD     PHYSADDR;

  #ifndef MAKEPHYSADDR
    #define MAKEPHYSADDR(lo, hi)    ((PHYSADDR) ((DWORD) (lo))
  #endif
  #ifndef LOPHYSADDR
    #define LOPHYSADDR(pa)          ((DWORD) (pa))
  #endif
  #ifndef HIPHYSADDR
    #define HIPHYSADDR(pa)          (0)
  #endif

#endif  /* !_DOS_ */

typedef PHYSADDR                *PPHYSADDR;
typedef PHYSADDR    BASED       *BPPHYSADDR;
typedef PHYSADDR    FAR         *LPPHYSADDR;
typedef PHYSADDR    HUGE        *HPPHYSADDR;


/* Macro to get the lowest nonzero bit of a value */

#ifndef LOBIT
#define LOBIT(x)        ((x) & (0 - (x)))
#endif

/* Used on unreferenced function parameters */

#ifndef UNUSED_ARG
#define UNUSED_ARG(x)
#endif

/* Gets the number of elements in an array */

#ifndef numof
#define numof(x)        (sizeof (x) / sizeof (*x))
#endif

/* Unsigned integer of pointer size */

#if defined(OS_64BIT)
typedef QWORD UINTPTR;
#elif defined(OS_32BIT)
typedef DWORD UINTPTR;
#elif defined(OS_16BIT)
typedef WORD  UINTPTR;
#else
#error You must specify an OS_xxBIT compilation switch
#endif

/* Gets the offset of a structure field */

#ifndef offsetof
#define offsetof(type, field) ((DWORD)(UINTPTR)&((type *)0)->field)
#endif

/* For macros of DWORD size */

#define DW(dw)  ((DWORD)(dw))

/* Pointer conversion macros */

#define POINTER_TO_DWORD(x)    ((DWORD) (UINTPTR) (x))


/****************************************************************************
                            Types for TSDK
*****************************************************************************/

typedef BYTE    bit8;
typedef WORD    bit16;
typedef DWORD   bit32;
typedef QWORD   bit64;

typedef SBYTE   sbit8;
typedef SWORD   sbit16;
typedef SDWORD  sbit32;
typedef SQWORD  sbit64;

typedef UINTPTR bitptr;

#ifndef WINDOWS
typedef BOOL    BOOLEAN;
#endif

#ifndef GLOBAL
#define GLOBAL  extern
#endif

#ifndef LOCAL
#define LOCAL
#endif


#endif
