/*++

Copyright (c) 1998-2000  Microsoft Corporation All Rights Reserved

Module Name:

  DummyDma.h

Abstract:  

    Header file for DummyDma sample.

Author:

    Abdul Ismail (Compaq Computer Corp.)   Oct 1998
		
Environment:

    Kernel mode

Revision History:

    Peter Lee (Compaq Computer Corp.)   Feb 1999

--*/

#ifndef __DummyDma_H__
#define __DummyDma_H__

#include <ntddk.h>

#ifdef  ExAllocatePool
#undef  ExAllocatePool
#endif
#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a, b, 'amdD')


#if DBG
#define DD_DebugPrint(_x_) \
               DDmaDbgPrint _x_;

VOID
DDmaDbgPrint    (
    ULONG   DebugPrintLevel,
    PCCHAR  DebugMessage,
    ...
    );
#else
#define DD_DebugPrint(_x_)
#endif  // DBG


typedef struct _GLOBALS {
   
    // 
    // Path to the driver's Services Key in the registry
    //

    UNICODE_STRING RegistryPath;

} GLOBALS;

extern GLOBALS Globals;


//
// These are the states FDO transition to upon
// receiving a specific PnP Irp. Refer to the PnP Device States
// diagram in DDK documentation for better understanding.
//

typedef enum _DEVICE_PNP_STATE {

    NotStarted = 0,         // Not started yet
    Started,                // Device has received the START_DEVICE IRP
    StopPending,            // Device has received the QUERY_STOP IRP
    Stopped,                // Device has received the STOP_DEVICE IRP
    RemovePending,          // Device has received the QUERY_REMOVE IRP
    SurpriseRemovePending,  // Device has received the SURPRISE_REMOVE IRP
    Deleted                 // Device has received the REMOVE_DEVICE IRP

} DEVICE_PNP_STATE;


//
// Device Extension
//
typedef struct _DUMMYDMA_DEVICE_EXTENSION
{
    DEVICE_PNP_STATE    DevicePnPState;   // Track the state of the device

    BOOLEAN             HoldNewRequests; // This flag is set whenever the
                                         // device needs to queue incoming
                                         // requests (when it receives a
                                         // QUERY_STOP or QUERY_REMOVE).
    CHAR                Reserved[3];  
   
    PDEVICE_OBJECT      Self; // a back pointer to the DeviceObject.

    PDEVICE_OBJECT      PDO; // The PDO to which the FDO is attached.

    PDEVICE_OBJECT      NextLowerDriver; // The top of the device stack just
                                         // beneath this device object.

    KEVENT              RemoveEvent; // an event to sync outstandIO to zero.

    KEVENT              StopEvent;   // an event to sync outstandIO to 1.
   
    ULONG               OutstandingIO; // 1-biased count of reasons why
                                       // this object should stick around.
    
    //
    // The name returned from IoRegisterDeviceInterface,
    // which is used as a handle for IoSetDev... and friends.
    //
    
    UNICODE_STRING      SymbolicLinkName;

    // 
    // DMA related variables
    //

    PSCATTER_GATHER_LIST ScatterGatherList;	// Scatter gather list for request
    ULONG               MaxMapRegisters;
    ULONG               numberOfMapRegisters;

    PDMA_ADAPTER        Adapter;

    ULONG               CurrentTransferLength;
    PUCHAR              CurrentVirtualAddress;

    PIRP                CurrentIrp;
    NTSTATUS            IrpStatus;

    KTIMER              DmaCompletedTimer;
    KDPC                DmaCompletedDpc;

    ULONG               PacketNumber;
    BOOLEAN             FinalPacket;

} DUMMYDMA_DEVICE_EXTENSION, *PDUMMYDMA_DEVICE_EXTENSION;


#define SETMASK(x, mask)     ((x) |=  (mask));

//
// Function prototypes
//

NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT  DriverObject,
    IN PUNICODE_STRING RegistryPath
    )   ;


NTSTATUS
DummyDmaAddDevice(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject
    )   ;


NTSTATUS
DummyDmaCleanup (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );


VOID
DummyDmaCancelQueued (
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp
    );


NTSTATUS
DummyDmaCreateClose (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );


NTSTATUS
DummyDmaDispatch(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp 
	);


NTSTATUS
DummyDmaDispatchPnp (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );


NTSTATUS
DummyDmaDispatchPnpComplete (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN PVOID Context
    );


NTSTATUS
DummyDmaDispatchPower (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );


LONG
DummyDmaIoDecrement    (
    IN  OUT PDUMMYDMA_DEVICE_EXTENSION   DeviceExtension
    )   ;


LONG
DummyDmaIoIncrement    (
    IN  OUT PDUMMYDMA_DEVICE_EXTENSION   DeviceExtension
    )   ;


NTSTATUS    
DummyDmaPassDownToNextPowerDriver  (
    IN  PDEVICE_OBJECT  DeviceObject,
    IN OUT  PIRP        Irp
    )   ;
                                 

VOID
DummyDmaProcessQueuedRequests(
    IN PDEVICE_OBJECT DeviceObject
    );


NTSTATUS
DummyDmaSendIrpSynchronously (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );
    

NTSTATUS
DummyDmaStartDevice (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP             Irp
    );


NTSTATUS
DummyDmaStartIo(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp 
	);


NTSTATUS
DummyDmaSystemControl(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp
    );
    

VOID
DummyDmaUnload(
    IN PDRIVER_OBJECT DriverObject
    );


#endif  // __DummyDma_H__
