85 lines
3.6 KiB
C
85 lines
3.6 KiB
C
// Public nt-lite DMA declarations.
|
|
|
|
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <ntlite/status.h>
|
|
|
|
struct DEVICE_OBJECT;
|
|
struct PROCESS;
|
|
typedef struct IO_DMA_ADAPTER IO_DMA_ADAPTER;
|
|
typedef struct IO_DMA_BUFFER IO_DMA_BUFFER;
|
|
typedef struct IO_DMA_MAPPING IO_DMA_MAPPING;
|
|
typedef struct MM_PINNED_MEMORY MM_PINNED_MEMORY;
|
|
|
|
typedef enum IO_DMA_DIRECTION {
|
|
IoDmaToDevice = 1,
|
|
IoDmaFromDevice,
|
|
IoDmaBidirectional
|
|
} IO_DMA_DIRECTION;
|
|
|
|
// Fails a streaming mapping instead of allocating a bounce buffer.
|
|
#define IO_DMA_MAP_NO_BOUNCE 0x00000001u
|
|
|
|
// Describes immutable constraints shared by one device adapter. Address,
|
|
// alignment, and boundary limits apply to common buffers. Segment limits apply
|
|
// to streaming mappings. Zero selects the unconstrained default for each field.
|
|
typedef struct IO_DMA_REQUIREMENTS {
|
|
uint64_t MaximumDeviceAddress;
|
|
size_t Alignment;
|
|
size_t Boundary;
|
|
size_t MaximumSegmentLength;
|
|
uint32_t MaximumSegments;
|
|
} IO_DMA_REQUIREMENTS;
|
|
|
|
// Describes one device-visible span in a streaming mapping.
|
|
typedef struct IO_DMA_SEGMENT {
|
|
uint64_t DeviceAddress;
|
|
size_t Length;
|
|
} IO_DMA_SEGMENT;
|
|
|
|
// Reports cumulative activity and live ownership for validation.
|
|
typedef struct IO_DMA_STATS {
|
|
uint64_t AdaptersCreated;
|
|
uint64_t AdaptersDestroyed;
|
|
uint64_t AdaptersInUse;
|
|
uint64_t CommonBuffersAllocated;
|
|
uint64_t CommonBuffersFreed;
|
|
uint64_t CommonBuffersInUse;
|
|
uint64_t CommonBufferBytesInUse;
|
|
uint64_t PinnedKernelRanges;
|
|
uint64_t PinnedUserRanges;
|
|
uint64_t PinnedRangesReleased;
|
|
uint64_t PinnedRangesInUse;
|
|
uint64_t PinnedPagesInUse;
|
|
uint64_t StreamingMappings;
|
|
uint64_t StreamingMappingsUnmapped;
|
|
uint64_t StreamingMappingsInUse;
|
|
uint64_t DirectMappings;
|
|
uint64_t BounceMappings;
|
|
uint64_t BounceBytesCopiedToDevice;
|
|
uint64_t BounceBytesCopiedToCpu;
|
|
uint64_t FailedAllocations;
|
|
uint64_t FailedMappings;
|
|
} IO_DMA_STATS;
|
|
|
|
|
|
__declspec(dllexport) KSTATUS IoDmaGetAdapter(struct DEVICE_OBJECT* device, const IO_DMA_REQUIREMENTS* requirements, IO_DMA_ADAPTER** outAdapter);
|
|
__declspec(dllexport) void IoDmaPutAdapter(IO_DMA_ADAPTER* adapter);
|
|
__declspec(dllexport) KSTATUS IoDmaAllocateCommonBuffer(IO_DMA_ADAPTER* adapter, size_t size, size_t alignment, IO_DMA_BUFFER** outBuffer);
|
|
__declspec(dllexport) void IoDmaFreeCommonBuffer(IO_DMA_BUFFER* buffer);
|
|
__declspec(dllexport) void* IoDmaGetCommonBufferAddress(const IO_DMA_BUFFER* buffer);
|
|
__declspec(dllexport) uint64_t IoDmaGetCommonBufferDeviceAddress(const IO_DMA_BUFFER* buffer);
|
|
__declspec(dllexport) size_t IoDmaGetCommonBufferSize(const IO_DMA_BUFFER* buffer);
|
|
__declspec(dllexport) KSTATUS IoDmaPinKernelMemory(void* address, size_t size, IO_DMA_DIRECTION direction, MM_PINNED_MEMORY** outMemory);
|
|
__declspec(dllexport) KSTATUS IoDmaPinUserMemory(struct PROCESS* process, void* address, size_t size, IO_DMA_DIRECTION direction, MM_PINNED_MEMORY** outMemory);
|
|
__declspec(dllexport) void IoDmaUnpinMemory(MM_PINNED_MEMORY* memory);
|
|
__declspec(dllexport) KSTATUS IoDmaMapPinnedMemory(IO_DMA_ADAPTER* adapter, MM_PINNED_MEMORY* memory, size_t offset, size_t length, IO_DMA_DIRECTION direction, uint32_t flags, IO_DMA_MAPPING** outMapping);
|
|
__declspec(dllexport) void IoDmaUnmapMemory(IO_DMA_MAPPING* mapping);
|
|
__declspec(dllexport) KSTATUS IoDmaSynchronizeForDevice(IO_DMA_MAPPING* mapping);
|
|
__declspec(dllexport) KSTATUS IoDmaSynchronizeForCpu(IO_DMA_MAPPING* mapping);
|
|
__declspec(dllexport) uint32_t IoDmaGetSegmentCount(const IO_DMA_MAPPING* mapping);
|
|
__declspec(dllexport) const IO_DMA_SEGMENT* IoDmaGetSegments(const IO_DMA_MAPPING* mapping);
|
|
__declspec(dllexport) void IoDmaQueryStats(IO_DMA_STATS* outStats);
|