DRIVER_CONTROL callback function (wdm.h)

This routine starts a DMA data-transfer or a data transfer operation.

Syntax

DRIVER_CONTROL DriverControl;

IO_ALLOCATION_ACTION DriverControl(
  [in]      _DEVICE_OBJECT *DeviceObject,
  [in, out] _IRP *Irp,
  [in]      PVOID MapRegisterBase,
  [in]      PVOID Context
)
{...}

Parameters

[in] DeviceObject

Caller-supplied pointer to a DEVICE_OBJECT structure. This is the device object for the target device, previously created by the driver's AddDevice routine.

[in, out] Irp

Caller-supplied pointer to an IRP structure. Irp is equal to the value of the CurrentIrp member of DeviceObject when the callback routine was registered.

[in] MapRegisterBase

In the case of AdapterControl, this is a caller-supplied opaque value that represents the map registers that the system has assigned for this transfer operation. The driver passes this value to FlushAdapterBuffers, FreeMapRegisters, and MapTransfer.

In the case of ControllerControl, this is not used.

[in] Context

Caller-supplied pointer to driver-defined context information, specified in a previous call to AllocateAdapterChannel.

Return value

The routine must return one of the values defined by the IO_ALLOCATION_ACTION enumeration. Drivers of bus-master devices return either DeallocateObject or DeallocateObjectKeepRegisters; drivers that use system DMA return KeepObject.

Remarks

To register an AdapterControl routine for a specific device object, a driver must call IoGetDmaAdapter to obtain an adapter object, then call AllocateAdapterChannel to request use of the adapter and to supply the AdapterControl routine's address. When the adapter is free, the system calls the AdapterControl routine.

If AdapterControl has been registered by a StartIo routine, then the Irp parameter is guaranteed to point to the IRP currently being processed by the StartIo routine. Otherwise, drivers must set the CurrentIrp member of the device object structure before calling AllocateAdapterChannel.

For detailed information about implementing an AdapterControl routine, see Writing AdapterControl Routines.

A driver's ControllerControl routine executes in an arbitrary thread context at IRQL = DISPATCH_LEVEL.

To register a ControllerControl routine for a specific device object, a driver must call IoCreateController to obtain a controller object, then call IoAllocateController to request use of the controller and to supply the ControllerControl routine's address. When the controller is free, the system calls the ControllerControl routine.

For detailed information about implementing a ControllerControl routine, see Writing ControllerControl Routines. Also see Controller Objects.

The DRIVER_CONTROL function type is defined in the Wdm.h header file. To more accurately identify errors when you run the code analysis tools, be sure to add the _Use_decl_annotations_ annotation to your function definition. The _Use_decl_annotations_ annotation ensures that the annotations that are applied to the DRIVER_CONTROL function type in the header file are used. For more information about the requirements for function declarations, see Declaring Functions by Using Function Role Types for WDM Drivers. For information about _Use_decl_annotations_, see Annotating Function Behavior.

Examples

To define a callback routine, you must first provide a function declaration that identifies the type of callback routine you're defining. Windows provides a set of callback function types for drivers. Declaring a function using the callback function types helps Code Analysis for Drivers, Static Driver Verifier (SDV), and other verification tools find errors, and it's a requirement for writing drivers for the Windows operating system.

For example, to define an AdapterControl callback routine that is named MyAdapterControl, use the DRIVER_CONTROL type as shown in this code example:

DRIVER_CONTROL MyAdapterControl;

Then, implement your callback routine as follows:

_Use_decl_annotations_
IO_ALLOCATION_ACTION
 MyAdapterControl(
    struct _DEVICE_OBJECT  *DeviceObject,
    struct _IRP  *Irp,
    PVOID  MapRegisterBase,
    PVOID  Context
    )
  {
      // Function body
  }

Requirements

Requirement Value
Target Platform Desktop
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
IRQL Called at DISPATCH_LEVEL.

See also

AllocateAdapterChannel