ReactOS 0.4.16-dev-197-g92996da
FxDmaTransactionBase Class Referenceabstract

#include <fxdmatransaction.hpp>

Inheritance diagram for FxDmaTransactionBase:
Collaboration diagram for FxDmaTransactionBase:

Public Member Functions

 FxDmaTransactionBase (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in USHORT ExtraSize, __in FxDmaEnabler *DmaEnabler)
 
virtual BOOLEAN Dispose (VOID)
 
_Must_inspect_result_ NTSTATUS Initialize (__in PFN_WDF_PROGRAM_DMA ProgramDmaFunction, __in WDF_DMA_DIRECTION DmaDirection, __in PMDL Mdl, __in size_t Offset, __in ULONG Length)
 
virtual _Must_inspect_result_ NTSTATUS InitializeResources (VOID)=0
 
_Must_inspect_result_ NTSTATUS Execute (__in PVOID Context)
 
virtual _Must_inspect_result_ NTSTATUS StartTransfer (VOID)=0
 
virtual _Must_inspect_result_ NTSTATUS StageTransfer (VOID)=0
 
BOOLEAN DmaCompleted (__in size_t TransferredLength, __out NTSTATUS *ReturnStatus, __in FxDmaCompletionType CompletionType)
 
virtual _Must_inspect_result_ NTSTATUS TransferCompleted (VOID)=0
 
VOID ReleaseForReuse (__in BOOLEAN ForceRelease)
 
virtual VOID ReleaseResources (__in BOOLEAN ForceRelease)=0
 
VOID GetTransferInfo (__out_opt ULONG *MapRegisterCount, __out_opt ULONG *ScatterGatherElementCount)
 
__forceinline size_t GetBytesTransferred (VOID)
 
__forceinline FxDmaEnablerGetDmaEnabler (VOID)
 
__forceinline FxRequestGetRequest (VOID)
 
__forceinline BOOLEAN IsRequestReferenced (VOID)
 
__forceinline VOID SetRequest (__in FxRequest *Request)
 
__forceinline VOID ReferenceRequest (VOID)
 
__forceinline VOID ReleaseButRetainRequest (VOID)
 
__forceinline VOID ClearRequest (VOID)
 
__forceinline size_t GetMaximumFragmentLength (VOID)
 
__forceinline VOID SetMaximumFragmentLength (size_t MaximumFragmentLength)
 
__forceinline size_t GetCurrentFragmentLength (VOID)
 
__forceinline WDFDMATRANSACTION GetHandle (VOID)
 
PVOID GetTransferContext (VOID)
 
VOID SetImmediateExecution (__in BOOLEAN Value)
 
BOOLEAN CancelResourceAllocation (VOID)
 
FxDmaTransactionState GetTransactionState (VOID)
 
- Public Member Functions inherited from FxNonPagedObject
 FxNonPagedObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
 FxNonPagedObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType ObjectType)
 
virtual ~FxNonPagedObject (VOID)
 
 _Acquires_lock_ (this->m_NPLock.m_Lock) __drv_maxIRQL(DISPATCH_LEVEL) __drv_setsIRQL(DISPATCH_LEVEL) VOID Lock(__out __drv_deref(__drv_savesIRQL) PKIRQL PreviousIrql)
 
 _Releases_lock_ (this->m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) __inline VOID Unlock(__in __drv_restoresIRQL KIRQL PreviousIrql)
 
 _Acquires_lock_ (this->m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) VOID LockAtDispatch(VOID)
 
 _Requires_lock_held_ (this->m_NPLock.m_Lock) _Releases_lock_(this -> m_NPLock.m_Lock) __drv_requiresIRQL(DISPATCH_LEVEL) __inline VOID UnlockFromDispatch(VOID)
 
- Public Member Functions inherited from FxObject
PVOID GetCOMWrapper ()
 
void SetCOMWrapper (__drv_aliasesMem PVOID Wrapper)
 
 FxObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
virtual ~FxObject (VOID)
 
PVOID __inline operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType Type)
 
PVOID __inline operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in USHORT ExtraSize=0)
 
VOID operator delete (__in PVOID Memory)
 
VOID SetNoContextHeader (VOID)
 
PVOID __inline GetObjectHandle (VOID)
 
__inline FxContextHeaderGetContextHeader (VOID)
 
__inline PFX_DRIVER_GLOBALS GetDriverGlobals (VOID)
 
WDFTYPE GetType (VOID)
 
USHORT GetObjectSize (VOID)
 
LONG GetRefCnt (VOID)
 
FxTagTrackerGetTagTracker (VOID)
 
CfxDeviceGetDevice (VOID)
 
CfxDeviceBaseGetDeviceBase (VOID)
 
VOID SetDeviceBase (__in CfxDeviceBase *DeviceBase)
 
__inline VOID CallCleanup (VOID)
 
ULONG __inline AddRef (__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG Release (__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG AddRefOverride (__in WDFOBJECT_OFFSET Offset, __in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual ULONG ReleaseOverride (__in WDFOBJECT_OFFSET Offset, __in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
 
virtual _Must_inspect_result_ NTSTATUS QueryInterface (__in FxQueryInterfaceParams *Params)
 
VOID MarkTraceState (VOID)
 
BOOLEAN __inline IsTraceState (VOID)
 
VOID __inline TraceDroppedEvent (__in FxObjectDroppedEvent Event)
 
VOID MarkPassiveDispose (__in FxObjectLockState State=ObjectLock)
 
VOID MarkPassiveCallbacks (__in FxObjectLockState State=ObjectLock)
 
VOID MarkForceDisposeThread (__in FxObjectLockState State=ObjectLock)
 
BOOLEAN IsPassiveCallbacks (__in BOOLEAN AcquireLock=TRUE)
 
BOOLEAN IsPassiveDispose (__in BOOLEAN AcquireLock=TRUE)
 
BOOLEAN IsForceDisposeThread (__in BOOLEAN AcquireLock=TRUE)
 
VOID MarkCommitted (VOID)
 
BOOLEAN IsCommitted (VOID)
 
VOID MarkDisposeOverride (__in FxObjectLockState State=ObjectLock)
 
VOID MarkNoDeleteDDI (__in FxObjectLockState State=ObjectLock)
 
BOOLEAN IsNoDeleteDDI (VOID)
 
_Must_inspect_result_ NTSTATUS Commit (__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
 
VOID DeleteFromFailedCreate (VOID)
 
VOID ClearEvtCallbacks (VOID)
 
BOOLEAN EarlyDispose (VOID)
 
virtual VOID DeleteObject (VOID)
 
virtual BOOLEAN Dispose (VOID)
 
_Must_inspect_result_ NTSTATUS AssignParentObject (__in FxObject *ParentObject)
 
_Must_inspect_result_ NTSTATUS AddContext (__in FxContextHeader *Header, __in PVOID *Context, __in PWDF_OBJECT_ATTRIBUTES Attributes)
 
_Must_inspect_result_ NTSTATUS RemoveParentAssignment (VOID)
 
_Must_inspect_result_ FxObjectGetParentObjectReferenced (__in PVOID Tag)
 
BOOLEAN IsDisposed (VOID)
 

Static Public Member Functions

static VOID _ComputeNextTransferAddress (__in PMDL CurrentMdl, __in size_t CurrentOffset, __in ULONG Transferred, __deref_out PMDL *NextMdl, __out size_t *NextOffset)
 
static _Must_inspect_result_ NTSTATUS _CalculateRequiredMapRegisters (__in PMDL Mdl, __in size_t CurrentOffset, __in ULONG Length, __in ULONG AvailableMapRegisters, __out_opt PULONG PossibleTransferLength, __out PULONG MapRegistersRequired)
 
- Static Public Member Functions inherited from FxObject
static FxObject_FromDisposeEntry (__in PSINGLE_LIST_ENTRY Entry)
 
static FxObject_GetObjectFromHandle (__in WDFOBJECT Handle, __inout PWDFOBJECT_OFFSET ObjectOffset)
 
static PVOID __inline _ToHandle (__in FxObject *Object)
 
static VOID __inline _ReferenceActual (__in WDFOBJECT Object, __in_opt PVOID Tag, __in LONG Line, __in PSTR File)
 
static VOID __inline _DereferenceActual (__in WDFOBJECT Object, __in_opt PVOID Tag, __in LONG Line, __in PSTR File)
 
static PVOID _GetDebugBase (__in FxObject *Object)
 
static PFX_POOL_HEADER _CleanupPointer (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Object)
 
static _Must_inspect_result_ NTSTATUS _GetEffectiveLock (__in FxObject *Object, __in_opt IFxHasCallbacks *Callbacks, __in BOOLEAN AutomaticLocking, __in BOOLEAN PassiveCallbacks, __out FxCallbackLock **CallbackLock, __out_opt FxObject **CallbackLockObject)
 
static _Must_inspect_result_ NTSTATUS _ObjectQuery (_In_ FxObject *Object, _In_ CONST GUID *Guid, _In_ ULONG QueryBufferLength, _Out_writes_bytes_(QueryBufferLength) PVOID QueryBuffer)
 

Protected Member Functions

virtual VOID Reuse (VOID)
 
- Protected Member Functions inherited from FxObject
 FxObject (__in WDFTYPE Type, __in USHORT Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObjectType ObjectType)
 
FxObjectDebugExtensionGetDebugExtension (VOID)
 
BOOLEAN IsDebug (VOID)
 
VOID AllocateTagTracker (__in WDFTYPE Type)
 
virtual VOID SelfDestruct (VOID)
 
PVOID __inline GetObjectHandleUnchecked (VOID)
 
VOID __inline DestroyChildren (VOID)
 
VOID DeleteEarlyDisposedObject (VOID)
 

Static Protected Member Functions

static PVOID GetStartVaFromOffset (__in PMDL Mdl, __in size_t Offset)
 
- Static Protected Member Functions inherited from FxObject
static PVOID _GetBase (__in FxObject *Object)
 

Protected Attributes

FxDmaTransactionState m_State
 
WDF_DMA_DIRECTION m_DmaDirection
 
FxDmaEnablerm_DmaEnabler
 
FxDmaDescriptionm_AdapterInfo
 
FxRequestm_EncodedRequest
 
FxDmaTransactionProgramOrReserveDma m_DmaAcquiredFunction
 
PVOID m_DmaAcquiredContext
 
PVOID m_TransferContext
 
PMDL m_StartMdl
 
PMDL m_CurrentFragmentMdl
 
size_t m_StartOffset
 
size_t m_CurrentFragmentOffset
 
size_t m_MaxFragmentLength
 
size_t m_TransactionLength
 
size_t m_Remaining
 
size_t m_Transferred
 
size_t m_CurrentFragmentLength
 
ULONG m_Flags
 
- Protected Attributes inherited from FxObject
union {
   CfxDeviceBase *   m_DeviceBase
 
   CfxDevice *   m_Device
 
}; 
 

Friends

class FxDmaEnabler
 

Detailed Description

Definition at line 86 of file fxdmatransaction.hpp.

Constructor & Destructor Documentation

◆ FxDmaTransactionBase()

FxDmaTransactionBase::FxDmaTransactionBase ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in USHORT  ObjectSize,
__in USHORT  ExtraSize,
__in FxDmaEnabler DmaEnabler 
)

Definition at line 30 of file fxdmatransaction.cpp.

35 :
38 ExtraSize == 0 ? ObjectSize : COMPUTE_OBJECT_SIZE(ObjectSize, ExtraSize),
39 FxDriverGlobals)
40{
50 m_Remaining = 0;
53 m_Transferred = 0;
54 m_Flags = 0;
55
57
59
60 if (ExtraSize == 0) {
62 } else {
64 this,
65 COMPUTE_RAW_OBJECT_SIZE(ObjectSize),
66 PVOID
67 );
68 }
69
71}
FxDmaTransactionProgramOrReserveDma m_DmaAcquiredFunction
FxDmaEnabler * m_DmaEnabler
WDF_DMA_DIRECTION m_DmaDirection
FxDmaTransactionState m_State
union FxDmaTransactionProgramOrReserveDma::@4337 Method
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
#define NULL
Definition: types.h:112
@ FxDmaTransactionStateCreated
#define COMPUTE_RAW_OBJECT_SIZE(_rawObjectSize)
Definition: fxhandle.h:100
#define COMPUTE_OBJECT_SIZE(_rawObjectSize, _extraSize)
Definition: fxhandle.h:107
@ ObjectDoNotLock
Definition: fxobject.hpp:128
@ FX_TYPE_DMA_TRANSACTION
Definition: fxtypes.h:108
_Must_inspect_result_ _In_ WDFDMAENABLER DmaEnabler
#define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type)
Definition: wdfcore.h:141
@ WdfDmaDirectionReadFromDevice
Definition: wdfdmaenabler.h:65

Member Function Documentation

◆ _CalculateRequiredMapRegisters()

_Must_inspect_result_ NTSTATUS FxDmaTransactionBase::_CalculateRequiredMapRegisters ( __in PMDL  Mdl,
__in size_t  CurrentOffset,
__in ULONG  Length,
__in ULONG  AvailableMapRegisters,
__out_opt PULONG  PossibleTransferLength,
__out PULONG  MapRegistersRequired 
)
static

Definition at line 633 of file fxdmatransaction.cpp.

671{
672 PMDL tempMdl;
673 ULONG requiredMapRegisters;
674 ULONG transferLength;
675 ULONG mdlLength;
676 ULONG pageOffset;
677 ULONG possTransferLength;
678
679 //
680 // Calculate the number of required map registers.
681 //
682 tempMdl = Mdl;
683 transferLength = (ULONG) MmGetMdlByteCount(tempMdl) - (ULONG) CurrentOffset;
684 mdlLength = transferLength;
685
686 pageOffset = BYTE_OFFSET(GetStartVaFromOffset(tempMdl, CurrentOffset));
687 requiredMapRegisters = 0;
688 possTransferLength = 0;
689
690 //
691 // The virtual address should fit in the first MDL.
692 //
693
694 ASSERT(CurrentOffset <= tempMdl->ByteCount);
695
696 //
697 // Loop through chained MDLs, accumulating the required
698 // number of map registers.
699 //
700
701 while (transferLength < Length && tempMdl->Next != NULL) {
702
703 //
704 // With pageOffset and length, calculate number of pages spanned by
705 // the buffer.
706 //
707 requiredMapRegisters += (pageOffset + mdlLength + PAGE_SIZE - 1) >>
709
710 if (requiredMapRegisters <= AvailableMapRegisters) {
711 possTransferLength = transferLength;
712 }
713
714 tempMdl = tempMdl->Next;
715 pageOffset = tempMdl->ByteOffset;
716 mdlLength = tempMdl->ByteCount;
717 transferLength += mdlLength;
718 }
719
720 if ((transferLength + PAGE_SIZE) < (Length + pageOffset )) {
721 ASSERT(transferLength >= Length);
723 }
724
725 //
726 // Calculate the last number of map registers based on the requested
727 // length not the length of the last MDL.
728 //
729
730 ASSERT( transferLength <= mdlLength + Length );
731
732 requiredMapRegisters += (pageOffset + Length + mdlLength - transferLength +
733 PAGE_SIZE - 1) >> PAGE_SHIFT;
734
735 if (requiredMapRegisters <= AvailableMapRegisters) {
736 possTransferLength += (Length + mdlLength - transferLength);
737 }
738
739 if (PossibleTransferLength != NULL) {
740 *PossibleTransferLength = possTransferLength;
741 }
742
743 ASSERT(*PossibleTransferLength);
744
745 *MapRegistersRequired = requiredMapRegisters;
746
747 return STATUS_SUCCESS;
748}
static PVOID GetStartVaFromOffset(__in PMDL Mdl, __in size_t Offset)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define ASSERT(a)
Definition: mode.c:44
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099
#define MmGetMdlByteCount(_Mdl)
#define BYTE_OFFSET(Va)

Referenced by FxDmaScatterGatherTransaction::InitializeResources(), FxDmaPacketTransaction::ReserveAdapter(), and FxDmaScatterGatherTransaction::StageTransfer().

◆ _ComputeNextTransferAddress()

VOID FxDmaTransactionBase::_ComputeNextTransferAddress ( __in PMDL  CurrentMdl,
__in size_t  CurrentOffset,
__in ULONG  Transferred,
__deref_out PMDL NextMdl,
__out size_t NextOffset 
)
static

Definition at line 562 of file fxdmatransaction.cpp.

589{
590 size_t transfered, mdlSize;
591 PMDL mdl;
592
593 mdlSize = MmGetMdlByteCount(CurrentMdl) - CurrentOffset;
594
595 if (Transferred < mdlSize) {
596 //
597 // We are still in the first MDL
598 //
599 *NextMdl = CurrentMdl;
600 *NextOffset = CurrentOffset + Transferred;
601 return;
602 }
603
604 //
605 // We have transfered the content of the first MDL.
606 // Move to the next one.
607 //
608 transfered = Transferred - mdlSize;
609 mdl = CurrentMdl->Next;
610 ASSERT(mdl != NULL);
611
612 while (transfered >= MmGetMdlByteCount(mdl)) {
613 //
614 // We have transfered the content of this MDL.
615 // Move to the next one.
616 //
617 transfered -= MmGetMdlByteCount(mdl);
618 mdl = mdl->Next;
619 ASSERT(mdl != NULL);
620 }
621
622 //
623 // This is the mdl where the last transfer occured.
624 //
625 *NextMdl = mdl;
626 *NextOffset = transfered;
627
628 return;
629}
static PMDL CurrentMdl
MDL * mdl

Referenced by FxDmaScatterGatherTransaction::InitializeResources(), and FxDmaScatterGatherTransaction::StageTransfer().

◆ CancelResourceAllocation()

BOOLEAN FxDmaTransactionBase::CancelResourceAllocation ( VOID  )

Definition at line 514 of file fxdmatransaction.cpp.

517{
521
526 "WDFDMATRANSACTION %p cannot be cancelled in state "
527 "%!FxDmaTransactionState!",
528 GetHandle(),
529 m_State
530 );
531
536 // unreachable code
537 }
538
539 PDMA_OPERATIONS dmaOperations =
541
543
544 result = dmaOperations->CancelAdapterChannel(
548 );
549
550 if (result) {
552
553 if (m_EncodedRequest != NULL) {
555 }
556 }
557
558 return result;
559}
unsigned char BOOLEAN
PDEVICE_OBJECT m_FDO
__forceinline VOID ReleaseButRetainRequest(VOID)
FxDmaDescription * m_AdapterInfo
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
#define TRACINGDMA
Definition: dbgtrace.h:71
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
return pObject GetObjectHandle()
@ FxDmaTransactionStateDeleted
@ FxDmaTransactionStateReleased
@ FxDmaTransactionStateTransferFailed
return pDmaTrans GetTransferContext()
#define FxVerifierBugCheck(FxDriverGlobals, Error,...)
Definition: fxverifier.h:58
GLuint64EXT * result
Definition: glext.h:11304
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
PCANCEL_ADAPTER_CHANNEL CancelAdapterChannel
Definition: iotypes.h:2655
PDMA_ADAPTER AdapterObject
#define GetHandle(h)
Definition: treelist.c:116
uint32_t ULONG_PTR
Definition: typedefs.h:65
@ WDF_DMA_FATAL_ERROR
Definition: wdfbugcodes.h:65

◆ ClearRequest()

__forceinline VOID FxDmaTransactionBase::ClearRequest ( VOID  )
inline

Definition at line 308 of file fxdmatransaction.hpp.

311 {
312 if (IsRequestReferenced()) {
314 }
316 }
__forceinline BOOLEAN IsRequestReferenced(VOID)

Referenced by Dispose(), and ReleaseForReuse().

◆ Dispose()

BOOLEAN FxDmaTransactionBase::Dispose ( VOID  )
virtual

Reimplemented from FxObject.

Reimplemented in FxDmaScatterGatherTransaction.

Definition at line 74 of file fxdmatransaction.cpp.

77{
79
80 //
81 // Must not be in transfer state.
82 //
85 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
86 "is invalid", GetHandle(), m_State);
87
90 WDF_DMA_FATAL_ERROR, // type
91 (ULONG_PTR) GetObjectHandle(), // parm 2
92 (ULONG_PTR) m_State); // parm 3
93 }
94 }
95
97
98 //
99 // Release resources for this Dma Transaction.
100 //
102
103 if (m_EncodedRequest != NULL) {
104 ClearRequest();
105 }
106
107 return TRUE;
108}
virtual VOID ReleaseResources(__in BOOLEAN ForceRelease)=0
__forceinline VOID ClearRequest(VOID)
#define TRUE
Definition: types.h:120
PFX_DRIVER_GLOBALS pFxDriverGlobals
@ FxDmaTransactionStateTransfer
@ OkForDownLevel
Definition: fxglobals.h:80
_Must_inspect_result_ BOOLEAN IsVerificationEnabled(__in ULONG Major, __in ULONG Minor, __in FxVerifierDownlevelOption DownLevel)
Definition: fxglobals.h:286

Referenced by FxDmaScatterGatherTransaction::Dispose().

◆ DmaCompleted()

BOOLEAN FxDmaTransactionBase::DmaCompleted ( __in size_t  TransferredLength,
__out NTSTATUS ReturnStatus,
__in FxDmaCompletionType  CompletionType 
)

Definition at line 252 of file fxdmatransaction.cpp.

257{
258 BOOLEAN hasTransitioned;
261 WDFDMATRANSACTION dmaTransaction;
262
263 //
264 // In the case of partial completion, we will start a new transfer
265 // from with in this function by calling StageTransfer. After that
266 // call, we lose ownership of the object. Since we need the handle
267 // for tracing purposes, we will save the value in a local variable and
268 // use that.
269 //
270 dmaTransaction = GetHandle();
271
274 "Enter WDFDMATRANSACTION %p, length %d",
275 dmaTransaction, (ULONG)TransferredLength);
276 }
277
278 //
279 // Must be in Transfer state.
280 //
283 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
284 "is invalid", dmaTransaction, m_State);
285
287 WDF_DMA_FATAL_ERROR, // specific type
288 (ULONG_PTR) dmaTransaction, // parm 2
289 (ULONG_PTR) m_State); // parm 3
290 }
291
295 "WDFDMATRANSACTION %p Transfered Length %I64d can't be more "
296 "than the length asked to transfer %I64d "
297 "%!STATUS!", dmaTransaction, TransferredLength,
300 goto End;
301 }
302
303
304 if (CompletionType == FxDmaCompletionTypePartial ||
305 CompletionType == FxDmaCompletionTypeAbort) {
306 //
307 // Tally this DMA tranferred byte count into the accumulator.
308 //
310
311 //
312 // Adjust the remaining length to account for the partial transfer.
313 //
315
316 //
317 // Update CurrentDmaLength to reflect actual transfer because
318 // we need to FlushAdapterBuffers based on this value in
319 // TransferCompleted for packet based transfer.
320 //
322
323 } else {
324 //
325 // Tally this DMA tranferred byte count into the accumulator.
326 //
328 }
329
331
332 //
333 // Inform the derived object that transfer is completed so it
334 // can release resources specific to last transfer.
335 //
337 if (!NT_SUCCESS(status)) {
338 goto End;
339 }
340
341 //
342 // If remaining DmaTransaction length is zero or if the driver wants
343 // this to be the last transfer then free the map registers and
344 // change the state to completed.
345 //
346 if (m_Remaining == 0 || CompletionType == FxDmaCompletionTypeAbort) {
348 goto End;
349 }
350
351 //
352 // Stage the next packet for this DmaTransaction...
353 //
355
356 if (NT_SUCCESS(status)) {
357 //
358 // StageTransfer results in a call to the EvtProgramDma routine
359 // where driver could complete and delete the object. So
360 // don't touch the object beyond this point.
361 //
363 }
364 else {
365 //
366 // The error will be returned to the caller of
367 // WdfDmaTransactionDmaComplete*()
368 //
369 }
370
371End:
372
374 //
375 // Failed or succeeded. Either way free
376 // map registers and release the device.
377 //
378 if (NT_SUCCESS(status)) {
380 } else {
382 }
383
386 "WDFDMATRANSACTION %p completed with status %!STATUS! - "
387 "releasing DMA resources",
388 GetHandle(),
389 status);
390 }
391
393
394 if (m_EncodedRequest != NULL) {
396 }
397
399
400 hasTransitioned = TRUE;
401 } else {
402 hasTransitioned = FALSE;
403 }
404
405 *ReturnStatus = status;
406
409 "Exit WDFDMATRANSACTION %p "
410 "Transitioned(%!BOOLEAN!)",
411 dmaTransaction, hasTransitioned);
412 }
413
414 return hasTransitioned;
415}
LONG NTSTATUS
Definition: precomp.h:26
virtual _Must_inspect_result_ NTSTATUS TransferCompleted(VOID)=0
virtual _Must_inspect_result_ NTSTATUS StageTransfer(VOID)=0
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
FxVerifierDbgBreakPoint(pFxDriverGlobals)
@ FxDmaTransactionStateTransferCompleted
@ FxDmaCompletionTypeAbort
@ FxDmaCompletionTypePartial
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
BOOLEAN FxVerifierOn
Definition: fxglobals.h:420
Definition: ps.c:97
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ WDFDMATRANSACTION _In_ size_t TransferredLength

◆ Execute()

_Must_inspect_result_ NTSTATUS FxDmaTransactionBase::Execute ( __in PVOID  Context)

Definition at line 187 of file fxdmatransaction.cpp.

190{
193
194 //
195 // Must be in Initialized state.
196 //
198
200 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
201 "is invalid", GetHandle(), m_State);
202
204 WDF_DMA_FATAL_ERROR, // specific type
205 (ULONG_PTR) GetObjectHandle(), // parm 2
206 (ULONG_PTR) m_State); // parm 3
207 }
208
209 //
210 // If this was initialized with a request, then reference the
211 // request now.
212 //
213 if (m_EncodedRequest != NULL) {
215 }
216
217 //
218 // Set state to Transfer.
219 // This is necessary because the Execute path complete
220 // all the way to DmaCompleted before returning to this point.
221 //
223
224 //
225 // Save the caller's context
226 //
228
229 ASSERT(m_Transferred == 0);
231
233 if (!NT_SUCCESS(status)) {
236
237 if (m_EncodedRequest != NULL) {
239 }
240 }
241
242 //
243 // StartTransfer results in a call to the EvtProgramDma routine
244 // where driver could complete and delete the object. So
245 // don't touch the object beyond this point.
246 //
247
248 return status;
249}
virtual _Must_inspect_result_ NTSTATUS StartTransfer(VOID)=0
__forceinline VOID ReferenceRequest(VOID)
@ FxDmaTransactionStateInitialized

◆ GetBytesTransferred()

__forceinline size_t FxDmaTransactionBase::GetBytesTransferred ( VOID  )
inline

Definition at line 197 of file fxdmatransaction.hpp.

200 {
201 return m_Transferred;
202 }

◆ GetCurrentFragmentLength()

__forceinline size_t FxDmaTransactionBase::GetCurrentFragmentLength ( VOID  )
inline

Definition at line 340 of file fxdmatransaction.hpp.

343 {
345 }

◆ GetDmaEnabler()

__forceinline FxDmaEnabler * FxDmaTransactionBase::GetDmaEnabler ( VOID  )
inline

Definition at line 206 of file fxdmatransaction.hpp.

209 {
210 return m_DmaEnabler;
211 }

Referenced by FxDmaPacketTransaction::_AdapterControl(), and if().

◆ GetHandle()

__forceinline WDFDMATRANSACTION FxDmaTransactionBase::GetHandle ( VOID  )
inline

◆ GetMaximumFragmentLength()

__forceinline size_t FxDmaTransactionBase::GetMaximumFragmentLength ( VOID  )
inline

Definition at line 320 of file fxdmatransaction.hpp.

323 {
324 return m_MaxFragmentLength;
325 }

◆ GetRequest()

__forceinline FxRequest * FxDmaTransactionBase::GetRequest ( VOID  )
inline

Definition at line 215 of file fxdmatransaction.hpp.

218 {
219 //
220 // Strip out the strong reference tag if it's set
221 //
225 }
#define FX_DECODE_POINTER(T, p, tag)
#define FX_STRONG_REF_TAG

◆ GetStartVaFromOffset()

static PVOID FxDmaTransactionBase::GetStartVaFromOffset ( __in PMDL  Mdl,
__in size_t  Offset 
)
inlinestaticprotected

◆ GetTransactionState()

FxDmaTransactionState FxDmaTransactionBase::GetTransactionState ( VOID  )
inline

Definition at line 375 of file fxdmatransaction.hpp.

378 {
379 return m_State;
380 }

◆ GetTransferContext()

PVOID FxDmaTransactionBase::GetTransferContext ( VOID  )
inline

Definition at line 357 of file fxdmatransaction.hpp.

360 {
361 return m_TransferContext;
362 }

◆ GetTransferInfo()

VOID FxDmaTransactionBase::GetTransferInfo ( __out_opt ULONG MapRegisterCount,
__out_opt ULONG ScatterGatherElementCount 
)

Definition at line 2331 of file fxdmatransaction.cpp.

2335{
2338
2340 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
2341 "is invalid", GetHandle(), m_State);
2342
2344 WDF_DMA_FATAL_ERROR, // specific type
2345 (ULONG_PTR) GetObjectHandle(), // parm 2
2346 (ULONG_PTR) m_State); // parm 3
2347 }
2348
2349 DMA_TRANSFER_INFO info = {0};
2350
2351
2352
2353
2354
2355
2356 if (m_DmaEnabler->UsesDmaV3()) {
2357
2358 //
2359 // Ask the HAL for information about the MDL and how many resources
2360 // it will require to transfer.
2361 //
2362 m_AdapterInfo->AdapterObject->DmaOperations->GetDmaTransferInfo(
2364 m_StartMdl,
2366 (ULONG) this->m_TransactionLength,
2367 this->m_DmaDirection == WDF_DMA_DIRECTION::WdfDmaDirectionWriteToDevice,
2368 &info
2369 );
2370 } else {
2371 size_t offset = m_StartOffset;
2372 size_t length = m_TransactionLength;
2373
2374 //
2375 // Walk through the MDL chain and make a worst-case computation of
2376 // the number of scatter gather entries and map registers the
2377 // transaction would require.
2378 //
2379 for(PMDL mdl = m_StartMdl;
2380 mdl != NULL && length != 0;
2381 mdl = mdl->Next) {
2382
2384 if (byteCount <= offset) {
2385 offset -= byteCount;
2386 } else {
2388
2389 startVa += offset;
2390 byteCount -= offset;
2391
2392 info.V1.MapRegisterCount +=
2394 startVa,
2396 );
2397
2399 }
2400 }
2401
2402 info.V1.ScatterGatherElementCount = info.V1.MapRegisterCount;
2403 }
2404
2406 *MapRegisterCount = info.V1.MapRegisterCount;
2407 }
2408
2410 *ScatterGatherElementCount = info.V1.ScatterGatherElementCount;
2411 }
2412
2413 return;
2414}
BOOLEAN UsesDmaV3(VOID)
#define ULONG_PTR
Definition: config.h:101
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLintptr offset
Definition: glext.h:5920
#define min(a, b)
Definition: monoChain.cc:55
#define ARGUMENT_PRESENT(ArgumentPointer)
UCHAR byteCount
Definition: scsi.h:3709
_In_ WDFDMATRANSACTION _Out_opt_ ULONG * MapRegisterCount
_In_ WDFDMATRANSACTION _Out_opt_ ULONG _Out_opt_ ULONG * ScatterGatherElementCount
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)

◆ Initialize()

_Must_inspect_result_ NTSTATUS FxDmaTransactionBase::Initialize ( __in PFN_WDF_PROGRAM_DMA  ProgramDmaFunction,
__in WDF_DMA_DIRECTION  DmaDirection,
__in PMDL  Mdl,
__in size_t  Offset,
__in ULONG  Length 
)

Definition at line 112 of file fxdmatransaction.cpp.

119{
122
124 "Enter WDFDMATRANSACTION %p", GetHandle());
125 //
126 // Must be in Reserve, Created or Released state.
127 //
131
133 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
134 "is invalid", GetHandle(), m_State);
135
137 WDF_DMA_FATAL_ERROR, // specific type
138 (ULONG_PTR) GetObjectHandle(), // parm 2
139 (ULONG_PTR) m_State); // parm 3
140 }
141
144 } else {
146 }
147
148 //
149 // Initialize the DmaTransaction object
150 //
151
154 m_StartMdl = Mdl;
160 m_DmaAcquiredFunction.Method.ProgramDma = ProgramDmaFunction;
161
162 //
163 // If needed, initialize the transfer context.
164 //
165
166 if (m_DmaEnabler->UsesDmaV3()) {
169 }
170
172 if (NT_SUCCESS(status)) {
174 } else {
176 }
177
179 "Exit WDFDMATRANSACTION %p, %!STATUS!",
180 GetHandle(), status);
181
182 return status;
183}
VOID InitializeTransferContext(__out PVOID Context, __in WDF_DMA_DIRECTION Direction)
__inline FxDmaDescription * GetWriteDmaDescription(VOID)
__inline FxDmaDescription * GetReadDmaDescription(VOID)
VOID ReleaseForReuse(__in BOOLEAN ForceRelease)
virtual _Must_inspect_result_ NTSTATUS InitializeResources(VOID)=0
@ FxDmaTransactionStateReserved
size_t MaximumFragmentLength
_In_ WDFDMAENABLER _In_ WDF_DMA_DIRECTION DmaDirection

◆ InitializeResources()

virtual _Must_inspect_result_ NTSTATUS FxDmaTransactionBase::InitializeResources ( VOID  )
pure virtual

◆ IsRequestReferenced()

__forceinline BOOLEAN FxDmaTransactionBase::IsRequestReferenced ( VOID  )
inline

Definition at line 229 of file fxdmatransaction.hpp.

232 {
234 }
#define FX_IS_POINTER_ENCODED(p, tag)

Referenced by ClearRequest(), ReferenceRequest(), and ReleaseButRetainRequest().

◆ ReferenceRequest()

__forceinline VOID FxDmaTransactionBase::ReferenceRequest ( VOID  )
inline

Definition at line 254 of file fxdmatransaction.hpp.

257 {
259 ASSERT(IsRequestReferenced() == false);
260
261 //
262 // Take a reference on the irp to catch completion of request
263 // when there is a pending DMA transaction.
264 // While there is no need to take a reference on request itself,
265 // I'm keeping it to avoid regression as we are so close to
266 // shipping this.
267 //
269
270 //
271 // Increment reference to this Request.
272 // See complementary section in WdfDmaTransactionDelete
273 // and WdfDmaTransactionRelease.
274 //
275 m_EncodedRequest->ADDREF( this );
276
280 }
VOID AddIrpReference(VOID)
Definition: fxrequest.cpp:2470
#define FX_ENCODE_POINTER(T, p, tag)

Referenced by Execute().

◆ ReleaseButRetainRequest()

__forceinline VOID FxDmaTransactionBase::ReleaseButRetainRequest ( VOID  )
inline

Definition at line 284 of file fxdmatransaction.hpp.

287 {
290
291 //
292 // Clear the referenced bit on the encoded request.
293 //
297
298 //
299 // Release this reference to the Irp and FxRequest.
300 //
302
303 m_EncodedRequest->RELEASE( this );
304 }
VOID ReleaseIrpReference(VOID)
Definition: fxrequest.cpp:2512

Referenced by CancelResourceAllocation(), ClearRequest(), DmaCompleted(), Execute(), and FxDmaPacketTransaction::ReserveAdapter().

◆ ReleaseForReuse()

VOID FxDmaTransactionBase::ReleaseForReuse ( __in BOOLEAN  ForceRelease)

Definition at line 418 of file fxdmatransaction.cpp.

421{
423
424 if (ForceRelease == FALSE)
425 {
427
428 //
429 // Double release is probably due to cancel during early in transaction
430 // initialization. DC2 on very slow machines shows this behavior.
431 // The double release case is rare and benign.
432 //
434 "WDFDMATRANSACTION %p is already released, "
435 "%!STATUS!", GetHandle(), STATUS_SUCCESS);
436
437 return; // already released.
438 }
439
440 //
441 // Must not be in transfer state.
442 //
445 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
446 "is invalid (release transaction)", GetHandle(), m_State);
447
450 WDF_DMA_FATAL_ERROR, // type
451 (ULONG_PTR) GetObjectHandle(), // parm 2
452 (ULONG_PTR) m_State); // parm 3
453 }
454 }
455 }
456
458
459 ReleaseResources(ForceRelease);
460
461 //
462 // Except DMA enabler field and adapter info everything else should be
463 // cleared. Adapter info is cleared by ReleaseResources above.
464 //
466
467 if (m_EncodedRequest != NULL) {
468 ClearRequest();
469 }
470
473 m_StartOffset = 0;
476 m_Transferred = 0;
477 m_Remaining = 0;
480 m_Flags = 0;
481
483
484}
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28

Referenced by Initialize(), FxDmaPacketTransaction::ReleaseAdapter(), and FxDmaPacketTransaction::ReserveAdapter().

◆ ReleaseResources()

virtual VOID FxDmaTransactionBase::ReleaseResources ( __in BOOLEAN  ForceRelease)
pure virtual

◆ Reuse()

virtual VOID FxDmaTransactionBase::Reuse ( VOID  )
inlineprotectedvirtual

Reimplemented in FxDmaPacketTransaction, and FxDmaSystemTransaction.

Definition at line 491 of file fxdmatransaction.hpp.

494 {
495 return;
496 }

◆ SetImmediateExecution()

VOID FxDmaTransactionBase::SetImmediateExecution ( __in BOOLEAN  Value)

Definition at line 487 of file fxdmatransaction.cpp.

490{
496 "Must set immediate execution flag for WDFDMATRANSACTION "
497 "%p before calling AllocateResources or Execute (current "
498 "state is %!FxDmaTransactionState!)",
499 GetHandle(),
500 m_State
501 );
503 }
504
505 if (Value) {
506 m_Flags |= DMA_SYNCHRONOUS_CALLBACK;
507 }
508 else {
509 m_Flags &= ~DMA_SYNCHRONOUS_CALLBACK;
510 }
511}
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ SetMaximumFragmentLength()

__forceinline VOID FxDmaTransactionBase::SetMaximumFragmentLength ( size_t  MaximumFragmentLength)
inline

Definition at line 329 of file fxdmatransaction.hpp.

332 {
333 if (MaximumFragmentLength < m_AdapterInfo->MaximumFragmentLength) {
334 m_MaxFragmentLength = MaximumFragmentLength;
335 }
336 }

◆ SetRequest()

__forceinline VOID FxDmaTransactionBase::SetRequest ( __in FxRequest Request)
inline

Definition at line 238 of file fxdmatransaction.hpp.

241 {
243
244 //
245 // Make sure the pointer doesn't have the strong ref flag set already
246 //
248
250 }
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

◆ StageTransfer()

virtual _Must_inspect_result_ NTSTATUS FxDmaTransactionBase::StageTransfer ( VOID  )
pure virtual

◆ StartTransfer()

virtual _Must_inspect_result_ NTSTATUS FxDmaTransactionBase::StartTransfer ( VOID  )
pure virtual

Implemented in FxDmaScatterGatherTransaction, and FxDmaPacketTransaction.

Referenced by Execute().

◆ TransferCompleted()

virtual _Must_inspect_result_ NTSTATUS FxDmaTransactionBase::TransferCompleted ( VOID  )
pure virtual

Friends And Related Function Documentation

◆ FxDmaEnabler

friend class FxDmaEnabler
friend

Definition at line 88 of file fxdmatransaction.hpp.

Member Data Documentation

◆ m_AdapterInfo

◆ m_CurrentFragmentLength

◆ m_CurrentFragmentMdl

◆ m_CurrentFragmentOffset

◆ m_DmaAcquiredContext

◆ m_DmaAcquiredFunction

◆ m_DmaDirection

◆ m_DmaEnabler

◆ m_EncodedRequest

◆ m_Flags

◆ m_MaxFragmentLength

◆ m_Remaining

◆ m_StartMdl

◆ m_StartOffset

◆ m_State

◆ m_TransactionLength

◆ m_TransferContext

PVOID FxDmaTransactionBase::m_TransferContext
protected

Definition at line 419 of file fxdmatransaction.hpp.

Referenced by FxDmaTransactionBase(), and GetTransferContext().

◆ m_Transferred


The documentation for this class was generated from the following files: