1.5  DMA

HalGetAdapter

Returns a pointer to the adapter object representing the DMA channel to which the driver’s device is connected or representing the driver’s busmaster adapter, together with the maximum number of map registers the driver can specify for each DMA transfer, given the input device description.

IoAllocateAdapterChannel

“Connects” a device object to an adapter object and calls a driver-supplied AdapterControl routine to carry out an I/O operation through the system DMA controller or a busmaster adapter as soon as the appropriate DMA channel is available and/or any necessary map registers are available. (This routine reserves exclusive access to a DMA channel and/or map registers for the specified device.)

MmGetMdlVirtualAddress

Returns a (possibly invalid) virtual address for a buffer described by a given MDL; the returned address, used as an index to a physical address entry in the MDL, can be input to IoMapTransfer.

ADDRESS_AND_SIZE_TO_SPAN_PAGES

Returns the number of pages required to contain a given virtual address and size in bytes. (This macro can be used to determine whether a given transfer request must be split into partial transfers.)

IoMapTransfer

Sets up map registers (up to the maximum returned by HalGetAdapter) for the given adapter object (already allocated by a call to IoAllocateAdapterChannel) to map a transfer from a locked-down buffer specified by an MDL, starting address, and length. Returns the logical address of the mapped region and, for busmaster devices that support scatter/gather, the number of bytes mapped.

IoFlushAdapterBuffers

Forces any data remaining in a busmaster adapter’s or the system DMA controller’s internal buffers to be written into memory or to the device, if the caller currently “owns” the adapter object, or terminates a transfer in progress if the driver detects a time-out or other error condition.

KeFlushIoBuffers

Flushes the memory region described by a given MDL from all processors’ caches into memory.

IoFreeAdapterChannel

Releases an adapter object, representing a system DMA channel, and optionally releases map registers, if any were allocated.

IoFreeMapRegisters

Releases a set of map registers, saved from a call to IoAllocateAdapterChannel, after the registers have been used in one or more calls to IoMapTransfer and the busmaster DMA transfer is complete.

HalReadDmaCounter

Returns how many bytes remain to be transferred during the current system DMA operation (autoinitialize mode), given a pointer to the adapter object.

HalAllocateCommonBuffer

Allocates and maps a logically contiguous region of memory that is simultaneously accessible both from the processor and from a device, given access to an adapter object, the requested length of the memory region to allocate, and access to variables where the starting logical and virtual addresses of the allocated region are returned. This routine returns TRUE if the requested length was allocated.

HalFreeCommonBuffer

Releases an allocated common buffer and unmaps it, given access to the adapter object, the length, and the starting logical and virtual addresses of the region to be freed. (Arguments must match those passed in the preceding call to HalAllocateCommonBuffer.)

KeGetDcacheFillSize

Returns the processor’s data cache-line boundary in bytes, useful for allocating buffers and sizing transfers to prevent cache tearing during DMA transfers.