Table of contents
Collapse the table of content
Expand the table of content

Supporting DMA in 64-Bit AVStream Drivers

Last Updated: 11/17/2016

AVStream supports DMA on 32-bit and 64-bit addressable devices.

All drivers compiled for Win64 platforms should use IKsDeviceFunctions::RegisterAdapterObjectEx instead of KsDeviceRegisterAdapterObject.

IKsDeviceFunctions::RegisterAdapterObjectEx is only available in Microsoft Windows Server 2003 SP1 and later.

The following code example illustrates how to support DMA on both the x64-based client release and 32-bit platforms:

NTSTATUS MyDeviceStart (...) {
// Get the DMA adapter object and store it in the Context member of the I/O stack location.
Context -> AdapterObject = IoGetDmaAdapter (
Device -> PhysicalDeviceObject,
&Context -> NumberOfMapRegisters

PUNKNOWN DeviceUnk =
KsDeviceGetOuterUnknown (

// Register the DMA adapter with AVStream
IKsDeviceFunctions *DeviceFunctions;
NTSTATUS Status = DeviceUnk -> QueryInterface (
__uuidof (IKsDeviceFunctions),
(PVOID *)&DeviceFunctions

// Conditionally, call IksDeviceFunctions::RegisterAdapterObjectEx, 
// which will not break downlevel load compatibility.

if (NT_SUCCESS (Status)) {
DeviceFunctions -> RegisterAdapterObjectEx (
Context -> AdapterObject,
Context -> NumMapRegisters,
sizeof (KSMAPPING)
DeviceFunctions -> Release ();

// If this call fails, call KsDeviceRegisterAdapterObject to
// preserve downlevel load compatibility.
else {
KsDeviceRegisterAdapterObject (
Context -> AdapterObject,
sizeof (KSMAPPING)

This code example works on 64-bit as well as 32-bit platforms. If the driver does not find IKsDeviceFunctions::RegisterAdapterObjectEx, it still calls KsDeviceRegisterAdapter.

In addition, when authoring a 64-bit AVStream driver, minimize the number of concurrent frame locks held. Since AVStream generates scatter/gather mappings when the minidriver first locks frames, your driver might run out of resources if it does not follow this guideline. In particular, if you are writing a driver to run on a Win64 platform with a 32-bit card, increasing the number of simultaneous locks increases the chance that a lock will fail because low memory buffers are a limited resource.

Send comments about this topic to Microsoft

© 2016 Microsoft