/*static char *SCCSID = "@(#)mddvhlp.h  6.2 91/08/19";*/

/*
 *      IBM Confidential
 *
 *      Copyright (c) IBM Corporation 1987, 1989
 *
 *      All Rights Reserved
 */

/*=============================================================================
 *
 * Source File: mddvhlp.h
 *
 * Description:
 *      This file contains macros, structures, and defines for monitor
 *      dispatcher
 *
 * Entry Points:
 *      none
 *
 * External References:
 *      none
 *
 *=============================================================================
 */

#include <mdinc.h>

typedef struct BUFFINFO {
 char       *Buff;        // 0:32 pointer to actual buffer
 ULONG       Buff_Flags;  // BUFFINFO flags    FullArray
 USHORT      EntrySize;   // Size for each array item (based on dd_buff_length)
 USHORT      ArrayEntries;// Number of entries in this array
 USHORT      InIndex;     // Index into array to write to
 USHORT      OutIndex;    // Index into array to read from
} BUFFINFO;

typedef BUFFINFO *pBUFFINFO;


typedef struct PERMONINFO {
 ULONG       BufferI;       // 16:16 Registered input buffer
 ULONG       BufferO;       // 16:16 Registered output buffer
 pBUFFINFO   R0Buff;        // 0:32 ptr to info for intermediate buffer
 struct PERMONINFO *NextMon;       // 0:32 ptr to next monitor
 struct PERMONINFO *PrevMon;       // 0:32 ptr to previous monitor
 HKSEM       WriteSemHandle;// "I want to write, but next buffer's full" sema4
 HKSEM       ReadSemHandle; // "I want to read, but my buffer's empty" sema4
 USHORT      MonPID;        // Process ID of this Monitor
} PERMONINFO;

typedef PERMONINFO *pPERMONINFO;

typedef struct PERCHAININFO {
 struct PERCHAININFO *NextChain;  // 0:32 ptr to next monitor chain
 pPERMONINFO   First_Monitor;     // 0:32 First monitor in this chain
 pPERMONINFO   Last_Monitor;      // 0:32 Last monitor in this chain
 pPERMONINFO   Last_FIRST_Monitor;// 0:32 Last monitor registered as "first"
 pPERMONINFO   Last_LAST_Monitor; // 0:32 Last monitor registered as "last"
 pBUFFINFO     FFBuff;            // 0:32 ptr to info for First Fixed Buff
 CHAR         *FinalBuff;         // 0:32 ptr to info for DD Final Buff
 HKSEM         ChainSemHandle;    // Semaphore for re-linking chain
 HKSEM         FFWriteSemHandle;  //"dh_write called, but FFBUFF is full" sema4
 ULONG         dev_notify;        // 16:16 ptr to device driver's notify rtn
 struct FarPtr dev_buff;          // 16:16 ptr to info for DD Final Buff
 USHORT        handle;            // Chain handle
 USHORT         dd_buff_length;   // length of device driver's Final Buffer
 UCHAR         Chain_Flags;       // perchain flags    dereg_in_progress
                                  //                   flush_in_progress
} PERCHAININFO;

typedef PERCHAININFO *pPERCHAININFO;
typedef pPERCHAININFO *ppPERCHAININFO;

typedef struct HEADSTRUC {
   pPERCHAININFO FirstChain; // Head of chain for perchaininfo's
   HKSEM         HeadSemHandle; // Sema4 for modifying chain of perchaininfo's
} HEADSTRUC;

//============================================================================
//============================================================================
//============================================================================

//Perchain flags
#define DEREG_IN_PROGRESS 0x01
#define FLUSH_IN_PROGRESS (DEREG_IN_PROGRESS << 1)

//buffinfo flags
#define FULL_ARRAY        0x01

#define INFINITE_TIMEOUT -1
#define MINFFBUFF        128
#define MAXFFBUFF        8*1024
#define FFBUFFMULTIPLIER  32

// Error path for dhw_MonCreate and dhw_Register
#define ERROR_FROM_VMLOCK                7
#define ERROR_FROM_1ST_CREATESEM         6
#define ERROR_FROM_2ND_CREATESEM         5
#define ERROR_FROM_3RD_CREATESEM         4
#define ERROR_FROM_1ST_ALLOC             3
#define ERROR_FROM_2ND_ALLOC             2
#define ERROR_FROM_3RD_ALLOC             1
//                              DON'T USE 0!!  0 is for NO_ERROR

// Placement flags
#define PF_SPECIAL_ADDER   3
#define PF_DEFAULT         0
#define PF_FIRST           1
#define PF_LAST            2
#define PF_DEFAULT_SPECIAL (PF_SPECIAL_ADDER+PF_DEFAULT)
#define PF_FIRST_SPECIAL   (PF_SPECIAL_ADDER+PF_FIRST  )
#define PF_LAST_SPECIAL    (PF_SPECIAL_ADDER+PF_LAST   )

//Flags used by dhw_MonWrite, DosIMonWrite, and DosIMonRead as RWFlags
#define FIRST_TIME      0x01


//Wait_Flag
#define WF_WAIT_INFINITE           0   // wait, infinite timeout
#define WF_NOWAIT                  1   // nowait
#define WF_WAIT_TIMED              2   // wait, timeout in dd_timeout_req
#define WF_CALLED_FROM_DHFLUSH  0x80   // dhw_MonWrite called from dh_Flush

// Need to define a couple of internal returncodes
// We never use these errorcode, and they are appropriate
#define TRY_AGAIN              ERROR_CANNOT_COPY
#define  MYERROR_FORCE_A_FAULT ERROR_PROTECTION_VIOLATION

//Flags for verify_buff
#define  VB_LENGTH          0x01
#define  VB_WRITE_ACCESS    (VB_LENGTH << 1)

