ReactOS 0.4.15-dev-8116-gf69e256
FxDmaEnabler Class Reference

#include <fxdmaenabler.hpp>

Inheritance diagram for FxDmaEnabler:
Collaboration diagram for FxDmaEnabler:

Public Member Functions

 FxDmaEnabler (__in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
 ~FxDmaEnabler ()
 
virtual BOOLEAN Dispose (VOID)
 
_Must_inspect_result_ NTSTATUS Initialize (__in PWDF_DMA_ENABLER_CONFIG Config, __inout FxDeviceBase *Device)
 
_Must_inspect_result_ NTSTATUS ConfigureSystemAdapter (__in PWDF_DMA_SYSTEM_PROFILE_CONFIG Config, __in WDF_DMA_DIRECTION ConfigDirection)
 
VOID AllocateCommonBuffer (__in size_t Length, __deref_out_opt PVOID *BufferVA, __out PHYSICAL_ADDRESS *BufferPA)
 
VOID FreeCommonBuffer (__in size_t Length, __in PVOID BufferVA, __in PHYSICAL_ADDRESS BufferPA)
 
_Must_inspect_result_ NTSTATUS PowerUp (VOID)
 
_Must_inspect_result_ NTSTATUS PowerDown (VOID)
 
VOID RevokeResources (VOID)
 
VOID InitializeTransferContext (__out PVOID Context, __in WDF_DMA_DIRECTION Direction)
 
__inline size_t GetMaximumLength (VOID)
 
__inline size_t GetAlignment (VOID)
 
__inline WDFDMAENABLER GetHandle (VOID)
 
__inline WDFDEVICE GetDeviceHandle (VOID)
 
__inline size_t GetMaxSGElements (VOID)
 
__inline VOID SetMaxSGElements (__in size_t MaximumSGElements)
 
__inline WDF_DMA_PROFILE GetProfile (VOID)
 
__inline BOOLEAN SupportsChainedMdls (VOID)
 
__inline BOOLEAN IsBusMaster (VOID)
 
__inline BOOLEAN IsPacketBased ()
 
__inline FxDmaDescriptionGetDmaDescription (__in WDF_DMA_DIRECTION Direction)
 
__inline FxDmaDescriptionGetWriteDmaDescription (VOID)
 
__inline FxDmaDescriptionGetReadDmaDescription (VOID)
 
BOOLEAN UsesDmaV3 (VOID)
 
USHORT GetTransferContextSize (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)
 

Public Attributes

FxTransactionedEntry m_TransactionLink
 
FxDmaDescription m_SimplexAdapterInfo
 
FxDmaDescription m_DuplexAdapterInfo [FxDuplexDmaDescriptionTypeMax]
 
NPAGED_LOOKASIDE_LIST Lookaside
 
struct {
   NPAGED_LOOKASIDE_LIST   Lookaside
 
ScatterGatherProfile
 
PSCATTER_GATHER_LIST List
 
struct {
   PSCATTER_GATHER_LIST   List
 
SystemProfile
 

Protected Attributes

PDEVICE_OBJECT m_FDO
 
PDEVICE_OBJECT m_PDO
 
union {
   FxDmaDescription   m_SimplexAdapterInfo
 
   FxDmaDescription   m_DuplexAdapterInfo [FxDuplexDmaDescriptionTypeMax]
 
}; 
 
WDF_DMA_PROFILE m_Profile
 
BOOLEAN m_IsAdded: 1
 
BOOLEAN m_IsConfigured: 1
 
BOOLEAN m_IsBusMaster: 1
 
BOOLEAN m_IsScatterGather: 1
 
BOOLEAN m_IsDuplexTransfer: 1
 
BOOLEAN m_IsSGListAllocated: 1
 
ULONG m_CommonBufferAlignment
 
ULONG m_MaximumLength
 
ULONG m_MaxSGElements
 
size_t m_SGListSize
 
union {
   struct {
      NPAGED_LOOKASIDE_LIST   Lookaside
 
   }   ScatterGatherProfile
 
   struct {
      PSCATTER_GATHER_LIST   List
 
   }   SystemProfile
 
m_SGList
 
- Protected Attributes inherited from FxObject
union {
   CfxDeviceBase *   m_DeviceBase
 
   CfxDevice *   m_Device
 
}; 
 

Private Member Functions

_Must_inspect_result_ NTSTATUS ConfigureBusMasterAdapters (__in PDEVICE_DESCRIPTION DeviceDescription, __in PWDF_DMA_ENABLER_CONFIG Config)
 
_Must_inspect_result_ NTSTATUS ConfigureDmaAdapter (__in PDEVICE_DESCRIPTION DeviceDescription, __in WDF_DMA_DIRECTION ConfigDirection)
 
_Must_inspect_result_ NTSTATUS InitializeResources (__inout FxDmaDescription *AdapterInfo)
 
VOID ReleaseResources (VOID)
 
VOID FreeResources (__inout FxDmaDescription *AdapterInfo)
 

Private Attributes

FxEvtDmaEnablerFillCallback m_EvtDmaEnablerFill
 
FxEvtDmaEnablerFlushCallback m_EvtDmaEnablerFlush
 
FxEvtDmaEnablerEnableCallback m_EvtDmaEnablerEnable
 
FxEvtDmaEnablerDisableCallback m_EvtDmaEnablerDisable
 
FxEvtDmaEnablerSelfManagedIoStartCallback m_EvtDmaEnablerSelfManagedIoStart
 
FxEvtDmaEnablerSelfManagedIoStopCallback m_EvtDmaEnablerSelfManagedIoStop
 
BOOLEAN m_DmaEnablerFillFailed
 
BOOLEAN m_DmaEnablerEnableFailed
 
BOOLEAN m_DmaEnablerSelfManagedIoStartFailed
 

Friends

class FxDmaTransactionBase
 
class FxDmaPacketTransaction
 
class FxDmaScatterGatherTransaction
 
class FxDmaSystemTransaction
 

Additional Inherited Members

- 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 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 inherited from FxObject
static PVOID _GetBase (__in FxObject *Object)
 

Detailed Description

Definition at line 66 of file fxdmaenabler.hpp.

Constructor & Destructor Documentation

◆ FxDmaEnabler()

FxDmaEnabler::FxDmaEnabler ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals)

Definition at line 30 of file fxdmaenabler.cpp.

32 :
33 FxNonPagedObject(FX_TYPE_DMA_ENABLER, sizeof(FxDmaEnabler), FxDriverGlobals)
34{
37
38 //
39 // Transaction link into list of FxDmaEnabler pointers maintained by
40 // FxDevice's pnp package.
41 //
43
44 m_FDO = NULL;
45 m_PDO = NULL;
51 m_SGListSize = 0;
52
54
61
65
67
69}
BOOLEAN m_IsSGListAllocated
FxDmaDescription m_SimplexAdapterInfo
BOOLEAN m_DmaEnablerFillFailed
BOOLEAN m_IsDuplexTransfer
BOOLEAN m_IsAdded
size_t m_SGListSize
FxDmaDescription m_DuplexAdapterInfo[FxDuplexDmaDescriptionTypeMax]
FxTransactionedEntry m_TransactionLink
PDEVICE_OBJECT m_PDO
FxEvtDmaEnablerSelfManagedIoStopCallback m_EvtDmaEnablerSelfManagedIoStop
FxEvtDmaEnablerEnableCallback m_EvtDmaEnablerEnable
FxEvtDmaEnablerDisableCallback m_EvtDmaEnablerDisable
FxEvtDmaEnablerSelfManagedIoStartCallback m_EvtDmaEnablerSelfManagedIoStart
FxEvtDmaEnablerFillCallback m_EvtDmaEnablerFill
BOOLEAN m_IsScatterGather
FxEvtDmaEnablerFlushCallback m_EvtDmaEnablerFlush
BOOLEAN m_DmaEnablerEnableFailed
BOOLEAN m_DmaEnablerSelfManagedIoStartFailed
PDEVICE_OBJECT m_FDO
ULONG m_MaxSGElements
ULONG m_CommonBufferAlignment
union FxDmaEnabler::@4832 m_SGList
PFN_WDF_DMA_ENABLER_DISABLE m_Method
PFN_WDF_DMA_ENABLER_ENABLE m_Method
PFN_WDF_DMA_ENABLER_FILL m_Method
PFN_WDF_DMA_ENABLER_FLUSH m_Method
PFN_WDF_DMA_ENABLER_SELFMANAGED_IO_START m_Method
PFN_WDF_DMA_ENABLER_SELFMANAGED_IO_STOP m_Method
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
@ ObjectDoNotLock
Definition: fxobject.hpp:128
@ FX_TYPE_DMA_ENABLER
Definition: fxtypes.h:107
VOID SetTransactionedObject(__in FxObject *Object)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define WDF_DMA_ENABLER_UNLIMITED_FRAGMENTS

◆ ~FxDmaEnabler()

FxDmaEnabler::~FxDmaEnabler ( )

Definition at line 71 of file fxdmaenabler.cpp.

72{
75 //
76 // Scatter Gather profile - cleanup the lookaside list
77 //
78 ExDeleteNPagedLookasideList(&m_SGList.ScatterGatherProfile.Lookaside);
79
80 } else if (!m_IsBusMaster) {
81 //
82 // System profile (not busmastering) - cleanup the preallocated
83 // SG list
84 //
85 ExFreePool(m_SGList.SystemProfile.List);
86
87 } else {
88 //
89 // Packet profile. No special cleanup to do.
90 //
91
92 }
93
94#if DBG
96#endif
98 }
99}
BOOLEAN m_IsBusMaster
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:170

Member Function Documentation

◆ AllocateCommonBuffer()

VOID FxDmaEnabler::AllocateCommonBuffer ( __in size_t  Length,
__deref_out_opt PVOID BufferVA,
__out PHYSICAL_ADDRESS BufferPA 
)

Definition at line 1053 of file fxdmaenabler.cpp.

1058{
1059 ULONG result;
1060 PDMA_ADAPTER adapterObject;
1062
1063 *BufferVA = NULL;
1064 BufferPA->QuadPart = 0;
1065
1068 "WDFDMAENABLER %p AllocateCommonBuffer: could cast value %I64d to a "
1069 "ULONG", GetHandle(), Length);
1071 return;
1072 }
1073
1074 //
1075 // It doesn't matter which channel we use for allocating common buffers
1076 // because the addressing capability of all the channels of this DMA enablers
1077 // are same.
1078 //
1079 adapterObject = GetReadDmaDescription()->AdapterObject;
1080
1081 *BufferVA = adapterObject->DmaOperations->
1082 AllocateCommonBuffer( adapterObject,
1083 result,
1084 BufferPA,
1085 TRUE /* CacheEnabled */ );
1086}
__inline FxDmaDescription * GetReadDmaDescription(VOID)
VOID AllocateCommonBuffer(__in size_t Length, __deref_out_opt PVOID *BufferVA, __out PHYSICAL_ADDRESS *BufferPA)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
#define TRACINGDMA
Definition: dbgtrace.h:71
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
FxVerifierDbgBreakPoint(pFxDriverGlobals)
#define RtlSizeTToULong
GLuint64EXT * result
Definition: glext.h:11304
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
PDMA_ADAPTER AdapterObject
#define GetHandle(h)
Definition: treelist.c:116
uint32_t ULONG
Definition: typedefs.h:59

Referenced by FxCommonBuffer::AllocateCommonBuffer(), and AllocateCommonBuffer().

◆ ConfigureBusMasterAdapters()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::ConfigureBusMasterAdapters ( __in PDEVICE_DESCRIPTION  DeviceDescription,
__in PWDF_DMA_ENABLER_CONFIG  Config 
)
private

Definition at line 606 of file fxdmaenabler.cpp.

610{
611 ULONG alignment;
613
614 //
615 // Initialize map register management
616 //
617 DeviceDescription->MaximumLength = m_MaximumLength;
618
619 if (m_IsDuplexTransfer) {
622
623 if (!NT_SUCCESS(status)) {
624 goto End;
625 }
626
629 } else {
630 //
631 // Direction is ignored in this case.
632 //
633
636 }
637
638 if (!NT_SUCCESS(status)) {
639 goto End;
640 }
641
642 //
643 // Allocate a scatter gather lookaside list if we need one.
644 //
645
646 if (m_IsScatterGather) {
647 size_t sgLookasideListSize;
648
649 sgLookasideListSize = 0;
650
651 if (m_IsDuplexTransfer) {
654
655 alignment = readDmaDesc->AdapterObject->DmaOperations->
656 GetDmaAlignment(readDmaDesc->AdapterObject);
657
658 //
659 // GetDmaAlignment returns alignment in terms of bytes
660 // while we treat alignment as a mask (which is how it is set
661 // in _DEVICE_OBJECT as well.
662 // For example, for byte alignment GetDmaAlignment returns 1 while
663 // the alignment mask is 0x00000000
664 //
665 // For < 1.11 drivers we keep the same behaviour as before for
666 // compatibility.
667 //
668 if (GetDriverGlobals()->IsVersionGreaterThanOrEqualTo(1, 11) &&
669 alignment > 0) {
670 alignment -= 1;
671 }
672
674 alignment);
675
676 //
677 // We will create a lookaside list based on the larger of the read &
678 // write SGListSize. It's done this way so that we can allocate
679 // sglist buffer when the dma-transaction object is created, where
680 // we don't know the direction of DMA transfer, and make the
681 // transaction initialize call fail-proof.
682 //
683 sgLookasideListSize = FxSizeTMax(
684 readDmaDesc->PreallocatedSGListSize,
685 writeDmaDesc->PreallocatedSGListSize
686 );
687 } else {
688
689 FxDmaDescription *simplexDmaDesc = &m_SimplexAdapterInfo;
690
691 alignment = simplexDmaDesc->AdapterObject->DmaOperations->
692 GetDmaAlignment(simplexDmaDesc->AdapterObject);
693
694 //
695 // GetDmaAlignment returns alignment in terms of bytes
696 // while we treat alignment as a mask (which is how it is set
697 // in _DEVICE_OBJECT as well.
698 // For example, for byte alignment GetDmaAlignment returns 1 while
699 // the alignment mask is 0x00000000
700 //
701 // For < 1.11 drivers we keep the same behaviour as before for
702 // compatibility.
703 //
704 if (GetDriverGlobals()->IsVersionGreaterThanOrEqualTo(1, 11) &&
705 alignment > 0) {
706 alignment -= 1;
707 }
708
710 alignment);
711
712 sgLookasideListSize = simplexDmaDesc->PreallocatedSGListSize;
713 }
714
715 //
716 // Initialize a LookasideList for ScatterGather list
717 //
720
721 m_SGListSize = sgLookasideListSize;
722
723 ExInitializeNPagedLookasideList( &m_SGList.ScatterGatherProfile.Lookaside,
724 NULL, // Allocate OPTIONAL
725 NULL, // Free OPTIONAL
726 0, // Flag - Reserved. Must be zero.
729 0 ); // Depth - Reserved. Must be zero.
730
732 }
733 }
734
735 //
736 // The DMA enabler is configured now.
737 //
738
740
741End:
742
743 return status;
744}
LONG NTSTATUS
Definition: precomp.h:26
ULONG m_MaximumLength
__inline FxDmaDescription * GetWriteDmaDescription(VOID)
_Must_inspect_result_ NTSTATUS ConfigureDmaAdapter(__in PDEVICE_DESCRIPTION DeviceDescription, __in WDF_DMA_DIRECTION ConfigDirection)
BOOLEAN m_IsConfigured
__inline size_t FxSizeTMax(__in size_t A, __in size_t B)
Definition: fxglobals.h:987
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
#define ASSERT(a)
Definition: mode.c:44
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
size_t PreallocatedSGListSize
Definition: ps.c:97
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:476
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
@ WDF_DMA_ENABLER_CONFIG_NO_SGLIST_PREALLOCATION
@ WdfDmaDirectionReadFromDevice
Definition: wdfdmaenabler.h:65
@ WdfDmaDirectionWriteToDevice
Definition: wdfdmaenabler.h:66
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:432

Referenced by Initialize().

◆ ConfigureDmaAdapter()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::ConfigureDmaAdapter ( __in PDEVICE_DESCRIPTION  DeviceDescription,
__in WDF_DMA_DIRECTION  ConfigDirection 
)
private

Definition at line 748 of file fxdmaenabler.cpp.

752{
753 FxDmaDescription *dmaDesc;
755
756 //
757 // Select the adapter to configure.
758 //
759
761
762 //
763 // Copy the device-description we have built up so far
764 // into the read and write dma description field. These
765 // settings are common to both channels.
766 //
769 sizeof(DEVICE_DESCRIPTION));
770
771 //
772 // Then initialize resources that are private to read and write.
773 //
774
775 status = InitializeResources(dmaDesc);
776 return status;
777}
_Must_inspect_result_ NTSTATUS InitializeResources(__inout FxDmaDescription *AdapterInfo)
__inline FxDmaDescription * GetDmaDescription(__in WDF_DMA_DIRECTION Direction)
DEVICE_DESCRIPTION DeviceDescription
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ PWDF_DMA_SYSTEM_PROFILE_CONFIG _In_ WDF_DMA_DIRECTION ConfigDirection

Referenced by ConfigureBusMasterAdapters(), and ConfigureSystemAdapter().

◆ ConfigureSystemAdapter()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::ConfigureSystemAdapter ( __in PWDF_DMA_SYSTEM_PROFILE_CONFIG  Config,
__in WDF_DMA_DIRECTION  ConfigDirection 
)

Definition at line 481 of file fxdmaenabler.cpp.

485{
486 DEVICE_DESCRIPTION deviceDescription;
487
489
490 //
491 // Check to make sure this direction isn't currently configured.
492 //
493 if (GetDmaDescription(ConfigDirection)->AdapterObject != NULL) {
495
497 "WDFDMAENABLER %p, profile %!WDF_DMA_PROFILE! "
498 "Enabler has already been configured for %!WDF_DMA_DIRECTION!, %!STATUS!",
501 status
502 );
503
505
506 return status;
507 }
508
509 //
510 // Initialize the adapter info from scratch given the Config structure
511 // then copy it to the appropriate channel and do the allocation.
512 //
513 RtlZeroMemory(&deviceDescription, sizeof(DEVICE_DESCRIPTION));
514
515 deviceDescription.Version = DEVICE_DESCRIPTION_VERSION3;
516 deviceDescription.MaximumLength = m_MaximumLength;
517
518 deviceDescription.DemandMode = Config->DemandMode;
519 deviceDescription.AutoInitialize = Config->LoopedTransfer;
520
521 deviceDescription.DmaWidth = Config->DmaWidth;
522
523 deviceDescription.DeviceAddress = Config->DeviceAddress;
524
525 //
526 // Pull the remainder of the description from the provided resource.
527 //
528 deviceDescription.InterfaceType = Internal;
529 deviceDescription.DmaChannel = Config->DmaDescriptor->u.Dma.Channel;
530 deviceDescription.DmaRequestLine = Config->DmaDescriptor->u.Dma.Port;
531
532
533 //
534 // Run the common adapter configuration.
535 //
537 &deviceDescription,
539 );
540
541 if (!NT_SUCCESS(status)) {
542 goto End;
543 }
544
545 //
546 // Allocate a single SGList to pass to MapTransferEx. Since we
547 // only run a single system transfer at a time we can use the same
548 // list for each transfer
549 //
550
551 {
552 size_t systemSGListSize = 0;
553
554 if (m_IsDuplexTransfer) {
555
556 systemSGListSize = max(GetReadDmaDescription()->PreallocatedSGListSize,
557 GetWriteDmaDescription()->PreallocatedSGListSize);
558 } else {
559
561 }
562
563 //
564 // Allocate the SG list.
565 //
566 m_SGList.SystemProfile.List =
568 systemSGListSize,
570
571 if (m_SGList.SystemProfile.List == NULL) {
575 "Unable to allocate scatter gather list for system DMA "
576 "enabler %p, %!STATUS!",
578 );
579 goto End;
580 }
581
583 m_SGListSize = systemSGListSize;
584 }
585
586 //
587 // For a simple enabler, both of these calls will return the same
588 // DMA description entry.
589 //
592 )->AdapterObject != NULL) &&
595 )->AdapterObject != NULL)) {
597 }
598
599End:
600
601 return status;
602}
WDF_DMA_PROFILE m_Profile
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
@ Internal
Definition: hwresource.cpp:137
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
PHYSICAL_ADDRESS DeviceAddress
Definition: iotypes.h:2089
BOOLEAN AutoInitialize
Definition: iotypes.h:2073
DMA_WIDTH DmaWidth
Definition: iotypes.h:2081
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2080
BOOLEAN DemandMode
Definition: iotypes.h:2072
#define max(a, b)
Definition: svc.c:63
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2204
#define DEVICE_DESCRIPTION_VERSION3
Definition: iotypes.h:2066

◆ Dispose()

BOOLEAN FxDmaEnabler::Dispose ( VOID  )
virtual

Reimplemented from FxObject.

Definition at line 103 of file fxdmaenabler.cpp.

104{
106
107 if (m_IsAdded) {
110 }
111
112 return TRUE;
113}
virtual VOID RemoveDmaEnabler(__inout FxDmaEnabler *Enabler)
Definition: fxdevice.hpp:329
VOID ReleaseResources(VOID)
CfxDeviceBase * m_DeviceBase
Definition: fxobject.hpp:328

◆ FreeCommonBuffer()

VOID FxDmaEnabler::FreeCommonBuffer ( __in size_t  Length,
__in PVOID  BufferVA,
__in PHYSICAL_ADDRESS  BufferPA 
)

Definition at line 1090 of file fxdmaenabler.cpp.

1095{
1096 PDMA_ADAPTER adapterObject;
1097
1098 adapterObject = GetReadDmaDescription()->AdapterObject;
1099
1100 adapterObject->DmaOperations->
1101 FreeCommonBuffer( adapterObject,
1102 (ULONG) Length,
1103 BufferPA,
1104 BufferVA,
1105 TRUE /* CacheEnabled */ );
1106}
VOID FreeCommonBuffer(__in size_t Length, __in PVOID BufferVA, __in PHYSICAL_ADDRESS BufferPA)

Referenced by FreeCommonBuffer(), and FxCommonBuffer::FreeCommonBuffer().

◆ FreeResources()

VOID FxDmaEnabler::FreeResources ( __inout FxDmaDescription AdapterInfo)
private

Definition at line 882 of file fxdmaenabler.cpp.

885{
886 if (AdapterInfo->AdapterObject != NULL) {
887 AdapterInfo->AdapterObject->DmaOperations->PutDmaAdapter(AdapterInfo->AdapterObject);
888 AdapterInfo->AdapterObject = NULL;
889 }
890}

Referenced by ReleaseResources().

◆ GetAlignment()

__inline size_t FxDmaEnabler::GetAlignment ( VOID  )
inline

Definition at line 153 of file fxdmaenabler.hpp.

156 {
158 }

Referenced by FxCommonBuffer::FxCommonBuffer().

◆ GetDeviceHandle()

__inline WDFDEVICE FxDmaEnabler::GetDeviceHandle ( VOID  )
inline

Definition at line 171 of file fxdmaenabler.hpp.

174 {
175
176 return m_DeviceBase->GetHandle();
177 }
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237

◆ GetDmaDescription()

__inline FxDmaDescription * FxDmaEnabler::GetDmaDescription ( __in WDF_DMA_DIRECTION  Direction)
inline

Definition at line 245 of file fxdmaenabler.hpp.

248 {
249 if (m_IsDuplexTransfer) {
251 }
252 else {
253 return &m_SimplexAdapterInfo;
254 }
255 }
WDF_EXTERN_C_START typedef _In_ WDFDEVICE _In_ WDFCONTEXT _In_ WDF_DMA_DIRECTION Direction

Referenced by ConfigureDmaAdapter(), ConfigureSystemAdapter(), InitializeTransferContext(), and UsesDmaV3().

◆ GetHandle()

__inline WDFDMAENABLER FxDmaEnabler::GetHandle ( VOID  )
inline

Definition at line 162 of file fxdmaenabler.hpp.

165 {
166 return (WDFDMAENABLER) GetObjectHandle();
167 }
return pObject GetObjectHandle()

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

◆ GetMaximumLength()

__inline size_t FxDmaEnabler::GetMaximumLength ( VOID  )
inline

Definition at line 140 of file fxdmaenabler.hpp.

143 {
144 //
145 // This value is same for all the channels and equal to the value
146 // provided in the DMA_ENABLER_CONFIG.
147 //
149 }

◆ GetMaxSGElements()

__inline size_t FxDmaEnabler::GetMaxSGElements ( VOID  )
inline

Definition at line 181 of file fxdmaenabler.hpp.

184 {
185 return m_MaxSGElements;
186 }

Referenced by FxDmaScatterGatherTransaction::_AdapterListControl().

◆ GetProfile()

__inline WDF_DMA_PROFILE FxDmaEnabler::GetProfile ( VOID  )
inline

Definition at line 199 of file fxdmaenabler.hpp.

202 {
203 return m_Profile;
204 }

◆ GetReadDmaDescription()

◆ GetTransferContextSize()

USHORT FxDmaEnabler::GetTransferContextSize ( VOID  )
inline

Definition at line 303 of file fxdmaenabler.hpp.

306 {
308 }
BOOLEAN UsesDmaV3(VOID)
#define DMA_TRANSFER_CONTEXT_SIZE_V1
Definition: iotypes.h:2148

◆ GetWriteDmaDescription()

__inline FxDmaDescription * FxDmaEnabler::GetWriteDmaDescription ( VOID  )
inline

◆ Initialize()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::Initialize ( __in PWDF_DMA_ENABLER_CONFIG  Config,
__inout FxDeviceBase Device 
)

Definition at line 117 of file fxdmaenabler.cpp.

121{
123 DEVICE_DESCRIPTION deviceDescription;
125 ULONG mapRegistersAllocated;
126
127 RtlZeroMemory(&deviceDescription, sizeof(DEVICE_DESCRIPTION));
128
129 //
130 // Default to version 2 description (except on ARM platforms)
131 //
132
133#ifdef _ARM_
134 deviceDescription.Version = DEVICE_DESCRIPTION_VERSION3;
135#else
136 deviceDescription.Version = DEVICE_DESCRIPTION_VERSION2;
137#endif
138
139 //
140 // Make sure the device's list of enablers has been created.
141 //
142
143 status = Device->AllocateDmaEnablerList();
144 if (!NT_SUCCESS(status)) {
146 "Unable to allocate DmaEnablerList for "
147 "WDFDEVICE %p, %!STATUS!",
148 Device->GetHandle(), status);
149 return status;
150 }
151
152 //
153 // Retain parent FxDeviceBase object
154 //
156
157 //
158 // Save the profile.
159 //
160 m_Profile = Config->Profile;
161
162 //
163 // Invariant parameters vis-a-vis kernel-mode bus-mastering DMA APIs
164 // (overrided below if using system-DMA
165 //
166 deviceDescription.Master = TRUE;
167 deviceDescription.Dma32BitAddresses = TRUE;
168 deviceDescription.InterfaceType = PCIBus;
169
170 //
171 // Assume enabler is a bus-master
172 //
174
175 //
176 // Expand the profile into settings.
177 //
178 switch (m_Profile) {
179 //
180 // Packet based profiles.
181 //
182
184 deviceDescription.ScatterGather = FALSE;
185 deviceDescription.Dma64BitAddresses = FALSE;
186 break;
188 deviceDescription.ScatterGather = FALSE;
189 deviceDescription.Dma64BitAddresses = TRUE;
190 break;
191
192 //
193 // Scatter-gather profiles
194 //
195
197 deviceDescription.ScatterGather = TRUE;
198 deviceDescription.Dma64BitAddresses = FALSE;
200 break;
202 deviceDescription.ScatterGather = TRUE;
203 deviceDescription.Dma64BitAddresses = FALSE;
206 break;
208 deviceDescription.ScatterGather = TRUE;
209 deviceDescription.Dma64BitAddresses = TRUE;
211 break;
213 deviceDescription.ScatterGather = TRUE;
214 deviceDescription.Dma64BitAddresses = TRUE;
217 break;
218
219 //
220 // Non-PC System-mode (non-bus-mastering) profiles. These
221 // require DMA v3.
222 //
223
225 deviceDescription.ScatterGather = FALSE;
226 deviceDescription.Master = FALSE;
227 deviceDescription.Dma32BitAddresses = FALSE;
228 deviceDescription.Dma64BitAddresses = FALSE;
229 deviceDescription.Version = DEVICE_DESCRIPTION_VERSION3;
232 break;
234 deviceDescription.ScatterGather = FALSE;
235 deviceDescription.Master = FALSE;
236 deviceDescription.Dma32BitAddresses = FALSE;
237 deviceDescription.Dma64BitAddresses = FALSE;
238 deviceDescription.Version = DEVICE_DESCRIPTION_VERSION3;
242 break;
243
244 //
245 // Unknown profile.
246 //
247
248 default:
249 //
250 // Just do quick exit as no resource have been allocated.
251 //
253 }
254
255 //
256 // Save the maximum length.
257 //
258 m_MaximumLength = (ULONG) Config->MaximumLength;
259
260 //
261 // An override of address width requires the DMA v3 engine. it also requires
262 // that we explicitly specify the DMA width the controller can support, but
263 // we do that down below.
264 //
265 if (Config->AddressWidthOverride != 0) {
266
267 //
268 // Address width override is not supported for system mode DMA, since
269 // the HAL runs the DMA controller in that case and it knows the
270 // controller's address limitations better than the driver does.
271 //
272 if (m_IsBusMaster == FALSE) {
276 "AddressWidthOverride set to %d. AddressWidthOverride "
277 "must be zero when using a system DMA profile "
278 "(%!WDF_DMA_PROFILE!) - %!STATUS!",
279 Config->AddressWidthOverride,
280 Config->Profile,
281 status
282 );
284 return status;
285 }
286
287 if ((deviceDescription.Dma64BitAddresses == FALSE) &&
288 (Config->AddressWidthOverride > 32)) {
292 "AddressWidthOverride set to %d. AddressWidthOverride "
293 "must be <= 32 when using a 32-bit DMA profile "
294 "(%!WDF_DMA_PROFILE!) - %!STATUS!",
295 Config->AddressWidthOverride,
296 Config->Profile,
297 status
298 );
300 return status;
301 }
302
303 //
304 // Handle the AddressWidthOverride. For Win8 use DMA v3 and pass the
305 // value through to the HAL. For Win7 downgrade to the next lower
306 // address width.
307 //
309 deviceDescription.Version = DEVICE_DESCRIPTION_VERSION3;
310 deviceDescription.DmaAddressWidth = Config->AddressWidthOverride;
311 }
312 else {
313
314 NT_ASSERTMSGW(L"Ensure driver is not doing something earlier that "
315 L"would require DMA v3 before we downgrade them to "
316 L"DMA v2",
317 (deviceDescription.Version == DEVICE_DESCRIPTION_VERSION2));
318
319 if (Config->AddressWidthOverride < 64) {
320 deviceDescription.Dma64BitAddresses = FALSE;
321 }
322
323 if (Config->AddressWidthOverride < 32) {
324 deviceDescription.Dma32BitAddresses = FALSE;
325 }
326
327 //
328 // DMA V2 can't handle an address width restriction smaller than
329 // 24 bits (ISA DMA). DMA V3 will fail that also - return the same
330 // error here that DMA V3 would have.
331 //
332 if (Config->AddressWidthOverride < 24) {
335 "AddressWidthOverride of less than 24 bits is not supported"
336 );
337 return STATUS_UNSUCCESSFUL;
338 }
339 else if ((Config->AddressWidthOverride != 64) &&
340 (Config->AddressWidthOverride != 32)) {
341
342 //
343 // Log a warning about downgrading DMA if we are actually
344 // downgrading. if the caller uses a 64-bit DMA
345 // profile with an override of 64, or 32-bit with an override
346 // of 32 then silently let it go through.
347 //
348
351 "DMA AddressWidthOverride requires Windows version 6.2 or "
352 "higher. Windows cannot support %d bit DMA is falling back to "
353 "the next lower supported width (%d-bit)",
354 Config->AddressWidthOverride,
355 (deviceDescription.Dma32BitAddresses ? 32 : 24)
356 );
357 }
358 }
359 }
360
361 //
362 // Allow for a specific version override (and fail if
363 // that override is inconsistent with the settings). On Win7 this will
364 // fail when we get the DMA adapter.
365 //
366 if (Config->WdmDmaVersionOverride != 0) {
367
368 if (Config->WdmDmaVersionOverride < deviceDescription.Version) {
370
371 //
372 // Driver is asking for a lower version of the DMA engine than the
373 // config settings imply it needs. Fail with invalid parameter.
374 //
375
377 "WdmDmaVersionOverride set to %d, conflicts with required version of %d, "
378 "%!STATUS!",
379 Config->WdmDmaVersionOverride,
380 deviceDescription.Version,
381 status
382 );
383
385 return status;
386 }
387
388 deviceDescription.Version = Config->WdmDmaVersionOverride;
389 }
390
391 //
392 // Propagate some settings from the old engine's location to the new ones.
393 //
394 if (deviceDescription.Version >= DEVICE_DESCRIPTION_VERSION3) {
395
396 if (deviceDescription.DmaAddressWidth == 0) {
397
398 if (deviceDescription.Dma64BitAddresses) {
399 deviceDescription.DmaAddressWidth = 64;
400 } else if (deviceDescription.Dma32BitAddresses) {
401 deviceDescription.DmaAddressWidth = 32;
402 } else {
403 //
404 // Assume ISA access width.
405 //
406
407 deviceDescription.DmaAddressWidth = 24;
408 }
409 }
410 }
411
412 //
413 // Get the FDO
414 //
416 ASSERT(m_FDO != NULL);
417
418 //
419 // Get the PDO. PDO may be NULL in the miniport case, but on
420 // x86 that will still allow for DMA (IoGetDmaAdapter special
421 // cases that on x86). On amd64 the attempt to get the DMA
422 // adapter later will fail cleanly.
423 //
425
426 mapRegistersAllocated = 0;
427
428 //
429 // If this device is a bus-master then configure the profile
430 // right now, since we don't need to wait for PrepareHardware
431 // to find out the DMA resource.
432 //
433 if (m_IsBusMaster) {
434 status = ConfigureBusMasterAdapters(&deviceDescription, Config);
435 if (!NT_SUCCESS(status)) {
436 goto End;
437 }
438 }
439
440 //
441 // Retain the Power event callbacks.
442 //
443 m_EvtDmaEnablerFill.m_Method = Config->EvtDmaEnablerFill;
444 m_EvtDmaEnablerFlush.m_Method = Config->EvtDmaEnablerFlush;
445 m_EvtDmaEnablerEnable.m_Method = Config->EvtDmaEnablerEnable;
446 m_EvtDmaEnablerDisable.m_Method = Config->EvtDmaEnablerDisable;
447 m_EvtDmaEnablerSelfManagedIoStart.m_Method = Config->EvtDmaEnablerSelfManagedIoStart;
448 m_EvtDmaEnablerSelfManagedIoStop.m_Method = Config->EvtDmaEnablerSelfManagedIoStop;
449
450 //
451 // Add this DmaEnabler to the parent device's list of dma enablers.
452 //
454 m_IsAdded = TRUE;
455
456 //
457 // update hardware info for Telemetry
458 //
459 if (m_IsBusMaster) {
461 }
462
463 //
464 // Success:
465 //
467
468End:
469 //
470 // If errors then clean-up resources accumulated.
471 //
472 if (!NT_SUCCESS(status)) {
474 }
475
476 return status;
477}
virtual VOID SetDeviceTelemetryInfoFlags(_In_ FxDeviceInfoFlags Flag)
Definition: fxdevice.hpp:341
MdDeviceObject __inline GetPhysicalDevice(VOID)
Definition: fxdevice.hpp:228
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
virtual VOID AddDmaEnabler(__inout FxDmaEnabler *Enabler)
Definition: fxdevice.hpp:317
_Must_inspect_result_ NTSTATUS ConfigureBusMasterAdapters(__in PDEVICE_DESCRIPTION DeviceDescription, __in PWDF_DMA_ENABLER_CONFIG Config)
__inline _Must_inspect_result_ BOOLEAN IsOsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: fxglobals.h:1094
@ DeviceInfoDmaBusMaster
@ DeviceInfoDmaSystem
@ DeviceInfoDmaSystemDuplex
@ PCIBus
Definition: hwresource.cpp:142
if(dx< 0)
Definition: linetemp.h:194
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
BOOLEAN Dma64BitAddresses
Definition: iotypes.h:2077
BOOLEAN ScatterGather
Definition: iotypes.h:2071
BOOLEAN Dma32BitAddresses
Definition: iotypes.h:2074
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
@ WdfDmaProfileScatterGather
Definition: wdfdmaenabler.h:55
@ WdfDmaProfilePacket
Definition: wdfdmaenabler.h:54
@ WdfDmaProfileScatterGatherDuplex
Definition: wdfdmaenabler.h:58
@ WdfDmaProfileSystem
Definition: wdfdmaenabler.h:60
@ WdfDmaProfileSystemDuplex
Definition: wdfdmaenabler.h:61
@ WdfDmaProfilePacket64
Definition: wdfdmaenabler.h:56
@ WdfDmaProfileScatterGather64Duplex
Definition: wdfdmaenabler.h:59
@ WdfDmaProfileScatterGather64
Definition: wdfdmaenabler.h:57
#define DEVICE_DESCRIPTION_VERSION2
Definition: iotypes.h:2065
#define NT_ASSERTMSGW
Definition: rtlfuncs.h:3312

◆ InitializeResources()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::InitializeResources ( __inout FxDmaDescription AdapterInfo)
private

Definition at line 781 of file fxdmaenabler.cpp.

784{
787
788 NT_ASSERTMSG("expected caller to set DMA version",
789 AdapterInfo->DeviceDescription.Version != 0);
790
791 //
792 // Submit IoGetDmaAdapter and retain the DmaAdapter pointer.
793 //
794 AdapterInfo->AdapterObject =
796 &AdapterInfo->DeviceDescription,
797 (PULONG)&AdapterInfo->NumberOfMapRegisters);
798
799 if (AdapterInfo->AdapterObject == NULL) {
802 "Unable to allocate DmaAdapter object for "
803 "WDFDMAENABLER %p, %!STATUS!",
804 GetHandle(), status);
805 return status;
806 }
807
808 //
809 // Calculate the size of the SGList.
810 //
811 if (m_IsScatterGather) {
812
813 //
814 // For scatter gather DMA we ask the HAL how many bytes it needs for
815 // each SGList. The HAL allocates some scratch space of its own in
816 // each SGList, which BuildScatterGatherList depends on.
817 //
818 ULONG mapRegistersCount;
819
820 status = AdapterInfo->AdapterObject->DmaOperations->
821 CalculateScatterGatherList( AdapterInfo->AdapterObject,
822 NULL, // Optional MDL
823 NULL, // CurrentVa
824 AdapterInfo->NumberOfMapRegisters * PAGE_SIZE,
825 (PULONG) &AdapterInfo->PreallocatedSGListSize,
826 &mapRegistersCount);
827
828 if (!NT_SUCCESS(status)) {
831 "CalculateScatterGatherList failed for "
832 "WDFDMAENABLER %p, %!STATUS!", GetHandle(), status);
833 return status;
834 }
835
836 ASSERT(AdapterInfo->NumberOfMapRegisters == mapRegistersCount);
837
838 } else if (m_IsBusMaster) {
839
840 //
841 // For packet based DMA we only need a single SGList entry because
842 // the HAL moves all of the data into a single continguous buffer
843 //
844 AdapterInfo->PreallocatedSGListSize = sizeof(SCATTER_GATHER_LIST) +
846
847 } else {
848
849 //
850 // For system DMA we need a single SGList entry per map-register
851 //
852 AdapterInfo->PreallocatedSGListSize = sizeof(SCATTER_GATHER_LIST) +
853 (sizeof(SCATTER_GATHER_ELEMENT) *
854 AdapterInfo->NumberOfMapRegisters);
855 }
856
857 ASSERT(AdapterInfo->NumberOfMapRegisters > 1);
858
859 AdapterInfo->MaximumFragmentLength = FxSizeTMin(m_MaximumLength,
860 ((size_t) (AdapterInfo->NumberOfMapRegisters - 1)) << PAGE_SHIFT);
861
863 "WDFDMAENABLER %p, profile %!WDF_DMA_PROFILE! "
864 "DmaAdapterObject %p, MapRegisters %d, "
865 "MaximumFragmentLength %I64d ", GetHandle(), m_Profile,
866 AdapterInfo->AdapterObject,
867 AdapterInfo->NumberOfMapRegisters,
868 AdapterInfo->MaximumFragmentLength);
869
870 if (AdapterInfo->MaximumFragmentLength < m_MaximumLength) {
872 "The maximum transfer length for WDFDMAENABLER %p "
873 "is reduced to %I64d from %I64d due to mapregisters limit",
875 AdapterInfo->MaximumFragmentLength);
876 }
877
878 return STATUS_SUCCESS;
879}
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
__inline size_t FxSizeTMin(__in size_t A, __in size_t B)
Definition: fxglobals.h:997
PDMA_ADAPTER NTAPI IoGetDmaAdapter(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_DESCRIPTION DeviceDescription, IN OUT PULONG NumberOfMapRegisters)
Definition: pnpdma.c:23
uint32_t * PULONG
Definition: typedefs.h:59
struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST
Definition: iotypes.h:2204
#define NT_ASSERTMSG
Definition: rtlfuncs.h:3311

Referenced by ConfigureDmaAdapter().

◆ InitializeTransferContext()

VOID FxDmaEnabler::InitializeTransferContext ( __out PVOID  Context,
__in WDF_DMA_DIRECTION  Direction 
)

Definition at line 1109 of file fxdmaenabler.cpp.

1113{
1115
1117 "should not call this routine if enabler is not using DMAv3",
1118 UsesDmaV3()
1119 );
1120
1121 PDMA_OPERATIONS dmaOperations =
1122 adapter->DmaOperations;
1123
1125}
return adapter
PINITIALIZE_DMA_TRANSFER_CONTEXT InitializeDmaTransferContext
Definition: iotypes.h:2651

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

◆ IsBusMaster()

◆ IsPacketBased()

__inline BOOLEAN FxDmaEnabler::IsPacketBased ( )
inline

Definition at line 237 of file fxdmaenabler.hpp.

239 {
240 return m_IsScatterGather ? FALSE : TRUE ;
241 }

◆ PowerDown()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::PowerDown ( VOID  )

Definition at line 988 of file fxdmaenabler.cpp.

991{
993 NTSTATUS localStatus;
995 WDFDMAENABLER handle = GetHandle();
997
999 "WDFDMAENABLER %p: PowerDown notification", GetHandle());
1000
1001 do {
1002
1004
1006
1007 if (!NT_SUCCESS(localStatus)) {
1009 status = (NT_SUCCESS(status)) ? localStatus : status;
1010 }
1011 }
1012
1015 {
1016 localStatus = m_EvtDmaEnablerDisable.Invoke( handle );
1017
1018 if (!NT_SUCCESS(localStatus)) {
1020 status = (NT_SUCCESS(status)) ? localStatus : status;
1021 }
1022 }
1023
1027 {
1028 localStatus = m_EvtDmaEnablerFlush.Invoke( handle );
1029
1030 if (!NT_SUCCESS(localStatus)) {
1032 status = (NT_SUCCESS(status)) ? localStatus : status;
1033 }
1034 }
1035
1036 } WHILE (0);
1037
1038 if (!NT_SUCCESS(status)) {
1040 "WDFDMAENABLER %p: PowerDown: "
1041 "%!WdfDmaEnablerCallback! failed %!STATUS!",
1042 GetHandle(), tag, status);
1043 }
1044
1045 return status;
1046}
NTSTATUS Invoke(__in WDFDMAENABLER Handle)
NTSTATUS Invoke(__in WDFDMAENABLER Handle)
NTSTATUS Invoke(__in WDFDMAENABLER Handle)
FxDmaEnablerCallbacks
@ FxEvtDmaEnablerDisable
@ FxEvtDmaEnablerFlush
@ FxEvtDmaEnablerSelfManagedIoStop
@ FxEvtDmaEnablerInvalid
#define WHILE(constant)
Definition: fxmacros.hpp:226
Definition: ecma_167.h:138

◆ PowerUp()

_Must_inspect_result_ NTSTATUS FxDmaEnabler::PowerUp ( VOID  )

Definition at line 929 of file fxdmaenabler.cpp.

932{
935 WDFDMAENABLER handle = GetHandle();
937
939 "WDFDMAENABLER %p: PowerUp notification", GetHandle());
940
941 do {
943
945
946 if (!NT_SUCCESS(status)) {
949 break;
950 }
951 }
952
954
956
957 if (!NT_SUCCESS(status)) {
960 break;
961 }
962 }
963
965
967
968 if (!NT_SUCCESS(status)) {
971 break;
972 }
973 }
974
975 } WHILE (0);
976
977 if (!NT_SUCCESS(status)) {
979 "WDFDMAENABLER %p: PowerUp: "
980 "%!WdfDmaEnablerCallback! failed %!STATUS!",
981 GetHandle(), tag, status);
982 }
983 return status;
984}
NTSTATUS Invoke(__in WDFDMAENABLER Handle)
NTSTATUS Invoke(__in WDFDMAENABLER Handle)
NTSTATUS Invoke(__in WDFDMAENABLER Handle)
@ FxEvtDmaEnablerSelfManagedIoStart
@ FxEvtDmaEnablerEnable
@ FxEvtDmaEnablerFill

◆ ReleaseResources()

VOID FxDmaEnabler::ReleaseResources ( VOID  )
private

Definition at line 893 of file fxdmaenabler.cpp.

896{
899
901
902}
VOID FreeResources(__inout FxDmaDescription *AdapterInfo)

Referenced by Dispose(), and Initialize().

◆ RevokeResources()

VOID FxDmaEnabler::RevokeResources ( VOID  )

Definition at line 905 of file fxdmaenabler.cpp.

908{
909 //
910 // Give back any system DMA resources allocated for this device
911 //
912
913 if (m_IsBusMaster == FALSE)
914 {
915
916
917
918
919
920 }
921}

◆ SetMaxSGElements()

__inline VOID FxDmaEnabler::SetMaxSGElements ( __in size_t  MaximumSGElements)
inline

Definition at line 190 of file fxdmaenabler.hpp.

193 {
194 m_MaxSGElements = (ULONG) MaximumSGElements;
195 }

◆ SupportsChainedMdls()

__inline BOOLEAN FxDmaEnabler::SupportsChainedMdls ( VOID  )
inline

Definition at line 208 of file fxdmaenabler.hpp.

211 {
212 //
213 // The only case where we don't support chained MDLS is DMAV2
214 // with packet mode.
215 //
216
217 if ((UsesDmaV3() == false) &&
218 (m_IsBusMaster == TRUE) &&
220 return false;
221 } else {
222 return true;
223 }
224 }

◆ UsesDmaV3()

Friends And Related Function Documentation

◆ FxDmaPacketTransaction

Definition at line 69 of file fxdmaenabler.hpp.

◆ FxDmaScatterGatherTransaction

Definition at line 70 of file fxdmaenabler.hpp.

◆ FxDmaSystemTransaction

Definition at line 71 of file fxdmaenabler.hpp.

◆ FxDmaTransactionBase

friend class FxDmaTransactionBase
friend

Definition at line 68 of file fxdmaenabler.hpp.

Member Data Documentation

◆ 

union { ... } FxDmaEnabler::@4831

◆ List

PSCATTER_GATHER_LIST FxDmaEnabler::List

Definition at line 418 of file fxdmaenabler.hpp.

◆ Lookaside

NPAGED_LOOKASIDE_LIST FxDmaEnabler::Lookaside

Definition at line 406 of file fxdmaenabler.hpp.

◆ m_CommonBufferAlignment

ULONG FxDmaEnabler::m_CommonBufferAlignment
protected

Definition at line 371 of file fxdmaenabler.hpp.

Referenced by ConfigureBusMasterAdapters(), FxDmaEnabler(), and GetAlignment().

◆ m_DmaEnablerEnableFailed

BOOLEAN FxDmaEnabler::m_DmaEnablerEnableFailed
private

Definition at line 444 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), PowerDown(), and PowerUp().

◆ m_DmaEnablerFillFailed

BOOLEAN FxDmaEnabler::m_DmaEnablerFillFailed
private

Definition at line 443 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), PowerDown(), and PowerUp().

◆ m_DmaEnablerSelfManagedIoStartFailed

BOOLEAN FxDmaEnabler::m_DmaEnablerSelfManagedIoStartFailed
private

Definition at line 445 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), and PowerUp().

◆ m_DuplexAdapterInfo

◆ m_EvtDmaEnablerDisable

FxEvtDmaEnablerDisableCallback FxDmaEnabler::m_EvtDmaEnablerDisable
private

Definition at line 436 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and PowerDown().

◆ m_EvtDmaEnablerEnable

FxEvtDmaEnablerEnableCallback FxDmaEnabler::m_EvtDmaEnablerEnable
private

Definition at line 435 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and PowerUp().

◆ m_EvtDmaEnablerFill

FxEvtDmaEnablerFillCallback FxDmaEnabler::m_EvtDmaEnablerFill
private

Definition at line 433 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and PowerUp().

◆ m_EvtDmaEnablerFlush

FxEvtDmaEnablerFlushCallback FxDmaEnabler::m_EvtDmaEnablerFlush
private

Definition at line 434 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and PowerDown().

◆ m_EvtDmaEnablerSelfManagedIoStart

FxEvtDmaEnablerSelfManagedIoStartCallback FxDmaEnabler::m_EvtDmaEnablerSelfManagedIoStart
private

Definition at line 437 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and PowerUp().

◆ m_EvtDmaEnablerSelfManagedIoStop

FxEvtDmaEnablerSelfManagedIoStopCallback FxDmaEnabler::m_EvtDmaEnablerSelfManagedIoStop
private

Definition at line 438 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and PowerDown().

◆ m_FDO

◆ m_IsAdded

BOOLEAN FxDmaEnabler::m_IsAdded
protected

Definition at line 343 of file fxdmaenabler.hpp.

Referenced by Dispose(), FxDmaEnabler(), and Initialize().

◆ m_IsBusMaster

BOOLEAN FxDmaEnabler::m_IsBusMaster
protected

◆ m_IsConfigured

BOOLEAN FxDmaEnabler::m_IsConfigured
protected

◆ m_IsDuplexTransfer

◆ m_IsScatterGather

BOOLEAN FxDmaEnabler::m_IsScatterGather
protected

◆ m_IsSGListAllocated

BOOLEAN FxDmaEnabler::m_IsSGListAllocated
protected

◆ m_MaximumLength

ULONG FxDmaEnabler::m_MaximumLength
protected

◆ m_MaxSGElements

◆ m_PDO

PDEVICE_OBJECT FxDmaEnabler::m_PDO
protected

Definition at line 320 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler(), Initialize(), and InitializeResources().

◆ m_Profile

WDF_DMA_PROFILE FxDmaEnabler::m_Profile
protected

◆ 

◆ m_SGListSize

size_t FxDmaEnabler::m_SGListSize
protected

◆ m_SimplexAdapterInfo

◆ m_TransactionLink

FxTransactionedEntry FxDmaEnabler::m_TransactionLink

Definition at line 314 of file fxdmaenabler.hpp.

Referenced by FxDmaEnabler().

◆ 

struct { ... } FxDmaEnabler::ScatterGatherProfile

◆ 

struct { ... } FxDmaEnabler::SystemProfile

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