
/*M*                     
//                    INTEL CORPORATION PROPRIETARY INFORMATION
//      This software is supplied under the terms of a license agreement or
//      nondisclosure agreement with Intel Corporation and may not be copied
//      or disclosed except in accordance with the terms of that agreement.
//            Copyright (c) 1995-2000 Intel Corporation.  All Rights Reserved.
//
*M*/
/*
 * $Log:   //cospublic004/shareddata/isc/isc2x/NTWORK/Src/imb/imb_os.h.v  $
 * 
 *    Rev 1.7   21 Dec 1999 11:31:36   rfogel
 * Problem with UW build requiring "DiagMsg.h", so speced dummy definitions in place "DiagMsg.h".
 * 
 *    Rev 1.6   14 Dec 1999 13:40:48   rfogel
 * Latest Win 2000 Driver Version (inc. WMI support)
 * 
 *    Rev 1.5   12 Oct 1999 11:39:18   rfogel
 * Resolved conflicts between UnixWare and Win NT/2000 builds.
 * 
 *    Rev 1.4   09 Oct 1999 13:46:38   rfogel
 * Conversion to Win 2000 WDM (PnP and PM only, no WMI)
 * 
 *    Rev 1.3   May 07 1999 11:56:02   sganeshx
 * 1. added a new #define for response length
 *     to the IPMI 1.0 Get Device ID command
 * 2. modified the check in the GetDevice ID
 *    function to check for
 * (IPMI10_GET_DEVICE_ID_RESP_LENGTH-1)
 * 
 *    Rev 1.2   18 Mar 1999 13:43:58   sganeshx
 * added 'bmcVer' field to DEVICE_EXTENSION
 * 
 *    Rev 1.1   08 Dec 1998 10:55:48   jpaiasno
 * Added code to support async.
 * DPC events from the EMP console.
 * 
 *    Rev 1.8   24 Mar 1998 14:24:42   fkhanx
 * Added Copyright Header
*/
//
// This is the NT/UnixWare version of the OS specific header file
//

// Define mappings from IMB_STATUS values to NTSTATUS
//

//-----------------------------------------------------------------------------
// (*) Not UnixWare?
//-----------------------------------------------------------------------------

#ifndef UWSVR4

   #include "CompDiag.h"

#endif

#ifdef D_SupportWin2000

   #define INITGUID                   // Initialize GUIDs in this module
   #include "w2k_drv.h"

   //-----------------------------------------------------------------------
   // Registered GUID interface
   //-----------------------------------------------------------------------

   // {52971333-ACD9-11d3-8163-0004ACDD0018}
   DEFINE_GUID(   gtIMBDrvIF_GUID,0x52971333, 0xacd9, 0x11d3, 0x81, 0x63, 0x0,   \
                  0x4, 0xac, 0xdd, 0x0, 0x18                                     \
                  );

   #include "IMBDrvWMI.h"

#endif

//-----------------------------------------------------------------------------
// (*)
//-----------------------------------------------------------------------------

#ifdef D_CompilerDiagnostics
   #pragma D_CompDiagMsg("Include")
#endif

#ifdef D_CompilerDiagnostics
   #pragma D_CompDiagMsg("Include \"ntddk.h\"")
#endif

#include "ntddk.h"

#ifdef D_CompilerDiagnostics
   #pragma D_CompDiagMsg("Include \"imb_log.h\"")
#endif

//
// Added dummy defines for diag messaging.  These were taken from "DiagMsg.h"
// and put here to temporarily resolve the problem of not being able to
// include "DiagMsg.h" for UnixWare build.
//

#ifdef UWSVR4

   #define D_DiagMsg(MsgType,DiagCode)

   #define D_DiagMsg0(MsgType,DiagCode,ArgFmt)

   #define D_DiagMsg1(MsgType,DiagCode,ArgFmt,Arg1)

   #define D_DiagMsg2(MsgType,DiagCode,ArgFmt,Arg1,Arg2)

   #define D_DiagMsg3(MsgType,DiagCode,ArgFmt,Arg1,Arg2,Arg3)

   #define D_DiagMsgClose

#else

   #include "DiagMsg.h"

#endif

#ifndef D_SupportWin2000

   extern NTSTATUS gtInitializeDriver( IN PDRIVER_OBJECT    DriverObject,
                                       OUT PDEVICE_OBJECT  *atppDeviceObject
                                       );

#endif

#include "imb_log.h"

#ifdef UWSVR4
#include <sys/types.h>
#include <sys/kmem.h>
#include <sys/ksynch.h>
#include <sys/ddi.h>
#include <sys/cmn_err.h>
#include <sys/mman.h>
#include <sys/param_p.h>
//#include <sys/xdebug.h>

#endif // UWSVR4

typedef unsigned long   DWORD;
typedef unsigned short  WORD;
typedef unsigned char   BYTE;

#ifndef UWSVR4

typedef enum {
    False,
    True,
} BOOL;

#else // UWSVR4

#define False   0
#define True    1

#endif // UWSVR4
//
// Defines for IMB_STATUS values
//
typedef NTSTATUS IMB_STATUS;

#define IMB_SUCCESS                                     STATUS_SUCCESS
//
// Unicode strings for the device names
//
#define UNICODE_FULL_DEVICE_NAME        L"\\Device\\Imb0"
#define UNICODE_SYMBOLIC_LINK_NAME      L"\\DosDevices\\Imb"
#define DUMP_COUNT                                      4
//
// Timer conversion constant 100 nanoseconds to seconds
//
#define TIMER_DELAY_USEC                (ULONG)(-10)
#define TIMER_DELAY_MSEC                (-10 * 1000)
#define TIMER_DELAY_SECOND              (ULONG)(-10 * 1000 * 1000)

//
// SMS buffer polling period - 100 mSec
//
#define SMS_CHECK_PERIOD                (100 * TIMER_DELAY_MSEC)
//
// error logging related definitions
//
#define IMB_ERROR_VALUE_BASE    0x00008060

// value for IPMI 1.0 Get Device ID response length
#define IPMI10_GET_DEVICE_ID_RESP_LENGTH 12
//
// Macros for I/O port access
//
#define ReadPortUchar( addr, valp ) (*(valp) = READ_PORT_UCHAR( (UCHAR *) (addr) ) )
#define WritePortUchar( addr, val ) ( WRITE_PORT_UCHAR( (UCHAR *)(addr), (val) ) )

#define CopyMemory( dst, src, count )   RtlCopyMemory( (dst), (src), (count) )
#define ZeroMemory( dst, count )                RtlZeroMemory( (dst), (count) )

//
// Async message related types
//
#ifndef UWSVR4

typedef KSEMAPHORE ImbAsyncOsSem;       // resource type used to control AsyncQueue access
typedef KEVENT     ImbAsyncOsEvent;     // resource type used to control AsyncQueue access

#endif // UWSVR4

/***********definitions for Semaphores and Events in UNix *************/

#ifdef UWSVR4

typedef sleep_t *ImbAsyncOsSem;

typedef struct event_t
{
	int             state;
	lock_t *plock;
	sv_t *  psyncVar;
} ImbAsyncOsEvent;


#endif  // UWSVR4

/*****************end of definitions *******************************/

#include "imb_if.h"

#include "imb_asyn.h"

//maximum number of client applications that can register for async
//event notification

#define MAX_EVENT_OBJ_NUMBER  5

/////////////////////////////////////////////////////////////////////////////////////////
// DEVICE_EXTENSION
/////////////////////////////////////////////////////////////////////////////////////////

/*D*
//  Name:       DEVICE_EXTENSION
//  Purpose:    structure to hold the Imb driver's device extension
//  Context:    Used by the I/O Manager to call the driver routines
//
*D*/

typedef struct  _DEVICE_EXTENSION {

    PDEVICE_OBJECT DeviceObject;        // pointer to the device object

#ifndef UWSVR4

	KSEMAPHORE      dispatchSemaphor;       // sync. semaphore between dispatch fn and bmc 
									// request processing thread
	KSEMAPHORE      requestSemaphor;        // sync. semaphore between different threads wanting 
									// to send requests

	KSPIN_LOCK      queueSpinLock;          // spinlock object for IMB IRP queue

#else   // UWSVR4

	sleep_t *       requestSemaphor;        // unix version of request sync
	sleep_t *       asyncQSema;				// lock for async messages sync.

#endif  // UWSVR4

	HANDLE      threadHandle;               // Imb request processing thread handle

	PVOID           threadObject;           // processing thread info ptr

#ifndef UWSVR4
	
	LIST_ENTRY  queueListEntry;             // Linked list queue pointer for  IMB related IRPs

#endif  // ! UWSVR4
		
	UCHAR       unloadingDriver;    // set to 1 only during driver unload 

	KTIMER      mesgTimer;                  // Imb request timeout generating timer object pointer

	KDPC        mesgTimerDpc;               // pointer to the IMB request related timeout processing DPC
	
	UCHAR       timeOutFlag;                // IMB request related timeout indicating flag. This is
									// set in DPC. cleared otherwise
	
    UCHAR               shutdownCode;           // code for shut down action, defined in imb_if.h

	int                     delayTime;                      // delay time before shutdown, in 100ms units

	UCHAR           imbSeqNo;                       // next sequence number to use when sending an IMB request

	struct ImbIfStruct *imbIf;              // pointer to vector of routines to access IMB interface

	
	ImbAsyncQueueInfo       asyncQ;         // this structure holds async queue related state

#ifndef UWSVR4



	
	KSEMAPHORE  asyncQSemaphor;                             //protects data related to async event signalling 
											//objects.                              



   HANDLE       asyncNEventHandle ;
   PKEVENT      asyncNEventObj ;

#endif

   unsigned char bmcVer;						// IPMI Version

   //-----------------------------------------------------------------------
   // (*) Win 2000 device object directly below the FDO that is attached to
   // PDO.
   //-----------------------------------------------------------------------

#ifndef UWSVR4

   #ifdef D_SupportWin2000

      struct S_Win2000_DevExt s_Win2000_DevExt;

   #endif

#endif

   //-----------------------------------------------------------------------
   // (*)
   //-----------------------------------------------------------------------

} DEVICE_EXTENSION,  *PDEVICE_EXTENSION;


