The Avshws sample in the DDK illustrates how to build an AVStream minidriver that uses DMA.
First, set up an interrupt by calling IoConnectInterrupt. Then, set up a DMA adapter object using IoGetDmaAdapter. Then register the DMA adapter object with AVStream by calling KsDeviceRegisterAdapterObject. At this point, AVStream performs some basic services on behalf of the minidriver.
A KSPIN that is performing DMA to or from hardware must specify the flag KSPIN_FLAG_GENERATE_MAPPINGS. When the minidriver specifies this flag, AVStream automatically generates scatter/gather mappings for each frame in the queue when the minidriver locks a stream pointer referencing that frame. This means that instead of each KSSTREAM_POINTER_OFFSET structure pointing directly to the virtual addresses of the data, it points to a mappings table through the Mappings member.
The count and remaining fields of the stream pointer offset are mapping granular instead of byte granular. Each mapping in the mappings table contains the physical address of a contiguous chunk of the frame, the number of bytes in the chunk, and the alignment of the chunk.
The minidriver specifies the maximum size for a single scatter/gather mapping by providing a MaxMappingByteCount field in its call to KsDeviceRegisterAdapterObject. If any scatter/gather mapping exceeds this maximum size, AVStream automatically breaks it into multiple scatter/gather mappings, each of which is no larger than the size specified in MaxMappingByteCount.