ReactOS 0.4.16-dev-1946-g52006dd
fxdmatransaction.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxDmaTransaction.cpp
8
9Abstract:
10
11 WDF DMA Transaction Object
12
13Environment:
14
15 Kernel mode only.
16
17Notes:
18
19
20Revision History:
21
22--*/
23
24#include "fxdmapch.hpp"
25
26extern "C" {
27// #include "FxDmaTransaction.tmh"
28}
29
31 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
32 __in USHORT ObjectSize,
33 __in USHORT ExtraSize,
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}
72
75 VOID
76 )
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}
109
113 __in PFN_WDF_PROGRAM_DMA ProgramDmaFunction,
115 __in PMDL Mdl,
116 __in size_t Offset,
118 )
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}
184
189 )
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}
250
253 __in size_t TransferredLength,
254 __out NTSTATUS * ReturnStatus,
255 __in FxDmaCompletionType CompletionType
256 )
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}
416
417VOID
419 __in BOOLEAN ForceRelease
420 )
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}
485
486VOID
489 )
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) {
507 }
508 else {
509 m_Flags &= ~DMA_SYNCHRONOUS_CALLBACK;
510 }
511}
512
515 VOID
516 )
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}
560
561VOID
564 __in size_t CurrentOffset,
565 __in ULONG Transferred,
566 __deref_out PMDL *NextMdl,
567 __out size_t *NextOffset
568 )
569/*++
570
571Routine Description:
572
573 This function computes the next mdl and offset given the current MDL,
574 offset and bytes transfered.
575
576Arguments:
577
578 CurrentMdl - Mdl where the transfer currently took place.
579
580 CurrentVa - Current virtual address in the buffer
581
582 Transfered - Bytes transfered or to be transfered
583
584 NextMdl - Mdl where the next transfer will take place
585
586 NextVA - Offset within NextMdl where the transfer will start
587
588--*/
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}
630
634 __in PMDL Mdl,
635 __in size_t CurrentOffset,
637 __in ULONG AvailableMapRegisters,
638 __out_opt PULONG PossibleTransferLength,
639 __out PULONG MapRegistersRequired
640 )
641/*++
642
643Routine Description:
644
645 Used on Windows 2000 to compute number of map registered required
646 for this transfer. This is derived from HalCalculateScatterGatherListSize.
647
648Arguments:
649
650 Mdl - Pointer to the MDL that describes the pages of memory that are being
651 read or written.
652
653 CurrentVa - Current virtual address in the buffer described by the MDL
654 that the transfer is being done to or from.
655
656 Length - Supplies the length of the transfer.
657
658 AvailableMapRegisters - Map registers available to do the transfer
659
660 PossibleTransferLength - Length that can transfered for the
661
662 MapRegistersRequired - Map registers required to the entire transfer
663
664Return Value:
665
666 NTSTATUS
667
668Notes:
669
670--*/
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}
749
750// ----------------------------------------------------------------------------
751// ------------------- Scatter/Gather DMA Section -----------------------------
752// ----------------------------------------------------------------------------
753
755 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
756 __in USHORT ExtraSize,
758 ) :
759 FxDmaTransactionBase(FxDriverGlobals,
761 ExtraSize,
763{
765 m_SGList = NULL;
766}
767
771 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
774 __out WDFDMATRANSACTION* Transaction
775 )
776{
777 FxDmaScatterGatherTransaction* pTransaction;
778 WDFOBJECT hTransaction;
780
781 pTransaction = new (FxDriverGlobals, Attributes, DmaEnabler->GetTransferContextSize())
782 FxDmaScatterGatherTransaction(FxDriverGlobals,
783 DmaEnabler->GetTransferContextSize(),
784 DmaEnabler);
785
786 if (pTransaction == NULL) {
789 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDMA,
790 "Could not allocate memory for WDFTRANSACTION, %!STATUS!", status);
791 return status;
792 }
793
794 //
795 // Commit and apply the attributes
796 //
797 status = pTransaction->Commit(Attributes, &hTransaction, DmaEnabler);
798
799 if (NT_SUCCESS(status) && DmaEnabler->m_IsSGListAllocated) {
800
801 //
802 // Allocate buffer for SGList from lookaside list.
803 //
804 pTransaction->m_LookasideBuffer = (SCATTER_GATHER_LIST *)
806 &DmaEnabler->m_SGList.ScatterGatherProfile.Lookaside
807 );
808
809 if (pTransaction->m_LookasideBuffer == NULL) {
812 "Unable to allocate memory for SG List, "
813 "WDFDMATRANSACTION %p, %!STATUS! ",
814 pTransaction->GetHandle(), status);
815 }
816 else {
817 //
818 // Take a reference on the enabler to ensure that it remains valid
819 // if the transaction's disposal is deferred.
820 //
821 DmaEnabler->ADDREF(pTransaction);
822 }
823 }
824
825 if (NT_SUCCESS(status)) {
826 *Transaction = (WDFDMATRANSACTION)hTransaction;
827 }
828 else {
829 //
830 // This will properly clean up the target's state and free it
831 //
832 pTransaction->DeleteFromFailedCreate();
833 }
834
835 return status;
836}
837
840 VOID
841 )
842{
843 BOOLEAN ret;
844
845 ret = FxDmaTransactionBase::Dispose(); // __super call
846
847 //
848 // Free Lookaside Buffer which held SGList
849 //
850 if (m_LookasideBuffer != NULL) {
851
855 );
857 m_DmaEnabler->RELEASE(this);
858 }
859
860 return ret;
861}
862
866 VOID
867 )
868{
870 PMDL nextMdl;
871 size_t nextOffset;
872 ULONG mapRegistersRequired;
873 size_t remLength, transferLength, transferred, possibleLength=0;
875
877
878 //
879 // If the caller has specified a limit on the number of scatter-gather
880 // elements each transfer can support then make sure it's within the
881 // limit by breaking up the whole transfer into m_MaxFragmentLength and
882 // computing the number of map-registers required for each fragment.
883 // This check may not be valid if the driver starts to do partial
884 // transfers. So driver that do partial transfer with sg-element limit
885 // should be capable of handling STATUS_WDF_TOO_FRAGMENTED failures during
886 // dma execution.
887 //
888 remLength = m_TransactionLength;
889 transferred = 0;
890 nextMdl = m_StartMdl;
891 nextOffset = m_StartOffset;
892 transferLength = 0;
893
894 while (remLength != 0) {
895
897 nextOffset,
898 (ULONG) transferLength,
899 &nextMdl,
900 &nextOffset);
901
902 transferLength = FxSizeTMin(remLength, m_MaxFragmentLength);
903
905 nextOffset,
906 (ULONG) transferLength,
908 (PULONG) &possibleLength,
909 &mapRegistersRequired
910 );
911
912 if (!NT_SUCCESS(status)) {
915 "CalculateScatterGatherList failed for "
916 "WDFDMATRANSACTION %p, %!STATUS!", GetHandle(), status);
918 return status;
919 }
920
921 if (mapRegistersRequired > m_DmaEnabler->m_MaxSGElements) {
924 "WDFDMATRANSACTION %p for MDL %p is more fragmented (%d) "
925 "than the limit (%I64d) specified by the driver, %!STATUS! ",
926 GetHandle(), nextMdl, mapRegistersRequired,
928 return status;
929 }
930
931 transferred += transferLength;
932 remLength -= transferLength;
933 }
934
935 return status;
936}
937
938VOID
940 __in BOOLEAN /* ForceRelease */
941 )
942{
943 if (m_SGList != NULL) {
945 m_SGList = NULL;
946 }
948}
949
953 VOID
954 )
955{
959 ASSERT(m_Transferred == 0);
960
961 return StageTransfer();
962}
963
967 VOID
968 )
969{
971 ULONG mapRegistersRequired;
972 WDFDMATRANSACTION dmaTransaction;
974
975 //
976 // Use an invalid value to make the function fail if the var is not
977 // updated correctly below.
978 //
979 mapRegistersRequired = 0xFFFFFFFF;
980
981 //
982 // Client driver could complete and delete the object in
983 // EvtProgramDmaFunction. So, save the handle because we need it
984 // for tracing after we invoke the callback.
985 //
986 dmaTransaction = GetHandle();
987
990 "Enter WDFDMATRANSACTION %p ", GetHandle());
991 }
992
993 //
994 // Given the first MDL and the bytes transfered, find the next MDL
995 // and byteoffset within that MDL.
996 //
1002
1003 //
1004 // Get the next possible transfer size.
1005 //
1007
1008 //
1009 // Fix m_CurrentFragmentLength to meet the map registers limit. This is done
1010 // in case the MDL is a chained MDL for an highly fragmented buffer.
1011 //
1017 &mapRegistersRequired);
1018 //
1019 // We have already validated the entire transfer during initialize
1020 // to see each transfer meets the sglimit. So this call shouldn't fail.
1021 // But, if the driver does partial transfer and changes the fragment
1022 // boundaries then it's possible for the sg-elements to vary. So, check
1023 // one more time to see if we are within the bounds before building
1024 // the sglist and calling into the driver.
1025 //
1027
1028 if (mapRegistersRequired > m_DmaEnabler->m_MaxSGElements) {
1031 "WDFDMATRANSACTION %p for MDL %p is more fragmented (%d) "
1032 "than the limit (%I64d) specified by the driver, %!STATUS! ",
1033 dmaTransaction, m_CurrentFragmentMdl, mapRegistersRequired,
1035 return status;
1036 }
1037
1038
1040
1042
1047#pragma prefast(suppress: __WARNING_CLASS_MISMATCH_NONE, "This warning requires a wrapper class for the DRIVER_LIST_CONTROL type.")
1049 this,
1052
1053 } else {
1054
1058#pragma prefast(suppress: __WARNING_CLASS_MISMATCH_NONE, "This warning requires a wrapper class for the DRIVER_LIST_CONTROL type.")
1060 this);
1061 }
1062
1063 if (!NT_SUCCESS(status)) {
1065 "Build or GetScatterGatherList failed for "
1066 "WDFDMATRANSACTION %p, %!STATUS!",
1067 dmaTransaction, status);
1068 //
1069 // Readjust remaining bytes transfered.
1070 //
1072 return status;
1073 }
1074
1075 //
1076 // Before GetScatterGatherList returns, _AdapterListControl can get called
1077 // on another thread and the driver could delete the transaction object.
1078 // So don't touch the object after this point.
1079 //
1080
1083 "Exit WDFDMATRANSACTION %p, "
1084 "%!STATUS!", dmaTransaction, status);
1085 }
1086
1087 return status;
1088}
1089
1090
1091VOID
1094 __in PIRP Irp, // UNUSED
1097 )
1098{
1100 WDFDMATRANSACTION dmaTransaction;
1101 FxDmaScatterGatherTransaction * pDmaTransaction;
1102
1105
1106 pDmaTransaction = (FxDmaScatterGatherTransaction*) Context;
1107 pFxDriverGlobals = pDmaTransaction->GetDriverGlobals();
1108 dmaTransaction = pDmaTransaction->GetHandle();
1109
1112 "Enter WDFDMATRANSACTION %p",
1113 dmaTransaction);
1114 }
1115
1116 ASSERT(pDmaTransaction != NULL);
1117 ASSERT(pDmaTransaction->m_DmaAcquiredFunction.Method.ProgramDma != NULL);
1118
1119 ASSERT(SgList->NumberOfElements <= pDmaTransaction->m_DmaEnabler->GetMaxSGElements());
1120
1121 pDmaTransaction->m_SGList = SgList;
1122
1123 //
1124 // We ignore the return value. The pattern we want the driver to follow is
1125 // that if it fails to program DMA transfer, it should call DmaCompletedFinal
1126 // to abort the transfer.
1127 //
1128 (VOID) pDmaTransaction->m_DmaAcquiredFunction.InvokeProgramDma(
1129 dmaTransaction,
1130 pDmaTransaction->m_DmaEnabler->m_DeviceBase->GetHandle(),
1131 pDmaTransaction->m_DmaAcquiredContext,
1132 pDmaTransaction->m_DmaDirection,
1133 SgList);
1134
1137 "Exit WDFDMATRANSACTION %p",
1138 dmaTransaction);
1139 }
1140}
1141
1145 VOID
1146 )
1147{
1148 //
1149 // All we have to do is release the scatter-gather list.
1150 //
1151 if (m_SGList != NULL) {
1152
1154 m_SGList = NULL;
1155 }
1156
1157 return STATUS_SUCCESS;
1158}
1159
1160
1161// ----------------------------------------------------------------------------
1162// ------------------- PACKET DMA SECTION -------------------------------------
1163// ----------------------------------------------------------------------------
1164
1166 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
1167 __in USHORT ObjectSize,
1168 __in USHORT ExtraSize,
1170 ) :
1171 FxDmaTransactionBase(FxDriverGlobals, ObjectSize, ExtraSize, DmaEnabler)
1172{
1178
1180
1181 m_TransferState.CurrentStagingThread = NULL;
1182 m_TransferState.RerunStaging = FALSE;
1183 m_TransferState.RerunCompletion = FALSE;
1185}
1186
1190 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
1193 __out WDFDMATRANSACTION* Transaction
1194 )
1195{
1196 FxDmaPacketTransaction* pTransaction;
1197 WDFOBJECT hTransaction;
1199
1200 pTransaction = new (FxDriverGlobals, Attributes, DmaEnabler->GetTransferContextSize())
1201 FxDmaPacketTransaction(FxDriverGlobals,
1202 sizeof(FxDmaPacketTransaction),
1203 DmaEnabler->GetTransferContextSize(),
1204 DmaEnabler);
1205
1206 if (pTransaction == NULL) {
1209 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDMA,
1210 "Could not allocate memory for WDFTRANSACTION, %!STATUS!", status);
1211 return status;
1212 }
1213
1214 //
1215 // Commit and apply the attributes
1216 //
1217 status = pTransaction->Commit(Attributes, &hTransaction, DmaEnabler);
1218 if (NT_SUCCESS(status)) {
1219 *Transaction = (WDFDMATRANSACTION)hTransaction;
1220 }
1221 else {
1222 //
1223 // This will properly clean up the target's state and free it
1224 //
1225 pTransaction->DeleteFromFailedCreate();
1226 }
1227
1228 return status;
1229}
1230
1234 VOID
1235 )
1236{
1237 KIRQL oldIrql;
1239 LockTransferState(&oldIrql);
1241 UnlockTransferState(oldIrql);
1242 return STATUS_SUCCESS;
1243}
1244
1245VOID
1247 __in BOOLEAN ForceRelease
1248 )
1249{
1250 //
1251 // If the map register base hasn't been assigned, then just
1252 // skip this.
1253 //
1254
1255 if (IsMapRegisterBaseSet() == FALSE) {
1256 return;
1257 }
1258
1259 //
1260 // Map registers are reserved. Unless the caller is forcing
1261 // us to free them, just return. Otherwise updated the
1262 // number of map registers that FreeMapRegistersAndAdapter
1263 // is going to look at.
1264 //
1265 if ((m_MapRegistersReserved > 0) && (ForceRelease == FALSE))
1266 {
1267 return;
1268 }
1269
1270 //
1271 // Free the map registers and release the device.
1272 //
1274
1276
1277 ReleaseDevice();
1278
1281}
1282
1290 )
1291{
1294 WDFDMATRANSACTION dmaTransaction = GetHandle();
1295
1298 "Enter WDFDMATRANSACTION %p", dmaTransaction);
1299 }
1300
1301 //
1302 // If caller doesn't supply a map register count then we get the count
1303 // out of the transaction. So the transaction must be initialized.
1304 //
1305 // Otherwise the transaction can't be executing.
1306 //
1307 if (NumberOfMapRegisters == 0) {
1310
1312 "RequiredMapRegisters cannot be 0 because "
1313 "WDFDMATRANSACTION %p is not initialized ("
1314 "state is %!FxDmaTransactionState!) - %!STATUS!",
1315 GetHandle(),
1316 m_State,
1317 status);
1319 WDF_DMA_FATAL_ERROR, // specific type
1320 (ULONG_PTR) GetObjectHandle(), // parm 2
1321 (ULONG_PTR) m_State); // parm 3
1322 }
1323 }
1327
1329 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
1330 "is invalid", dmaTransaction, m_State);
1331
1333 WDF_DMA_FATAL_ERROR, // specific type
1334 (ULONG_PTR) GetObjectHandle(), // parm 2
1335 (ULONG_PTR) m_State); // parm 3
1336 }
1337
1338 //
1339 // Must not already have reserved map registers
1340 //
1341 if (m_MapRegistersReserved != 0)
1342 {
1344 "WDFDMATRANSACTION %p already has allocated map registers.",
1345 dmaTransaction);
1346
1348 WDF_DMA_FATAL_ERROR, // specific type
1349 (ULONG_PTR) GetObjectHandle(), // parm 2
1350 (ULONG_PTR) m_State); // parm 3
1351 }
1352
1353 //
1354 // Get the adapter
1355 //
1358 } else {
1360 }
1361
1362 //
1363 // Save the number of map registers being reserved.
1364 //
1365 if (NumberOfMapRegisters != 0) {
1366
1367 //
1368 // Use the number the caller passed us
1369 //
1371 }
1372 else if (m_DmaEnabler->IsBusMaster() == FALSE) {
1373
1374 //
1375 // For system DMA use all the map registers we have
1376 //
1378
1379 } else {
1380
1381 //
1382 // Compute the number of map registers required based on
1383 // the MDL and length passed in
1384 //
1386 m_StartMdl,
1390 NULL,
1392 );
1393
1394 if (!NT_SUCCESS(status)) {
1396 goto End;
1397 }
1398 }
1399
1400 //
1401 // Initialize the DmaTransaction object with enough data to
1402 // trick StartTransfer into allocating the adapter channel for us.
1403 //
1405 m_StartMdl = NULL;
1406 m_StartOffset = 0;
1409 m_Remaining = 0;
1411
1412 //
1413 // Save the callback and context
1414 //
1417
1418 //
1419 // If needed, initialize the transfer context.
1420 //
1421 if (m_DmaEnabler->UsesDmaV3()) {
1424 }
1425
1427 if (NT_SUCCESS(status)) {
1428 //
1429 // Set the state to reserved so _AdapterControl knows which
1430 // callback to invoke.
1431 //
1433 } else {
1435 goto End;
1436 }
1437
1438 //
1439 // Start the adapter channel allocation through StartTransfer
1440 //
1442
1443End:
1444 if (!NT_SUCCESS(status)) {
1449
1450 if (m_EncodedRequest != NULL) {
1452 }
1453 }
1454
1457 "Exit WDFDMATRANSACTION %p, %!STATUS!",
1458 dmaTransaction, status);
1459 }
1460
1461 return status;
1462}
1463
1464VOID
1466 VOID
1467 )
1468{
1470 WDFDMATRANSACTION dmaTransaction = GetHandle();
1471
1474 "Enter WDFDMATRANSACTION %p", dmaTransaction);
1475 }
1476
1477 //
1478 // Must not be in invalid, created, transfer or deleted state
1479 //
1484
1486 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
1487 "is invalid", dmaTransaction, m_State);
1488
1490 WDF_DMA_FATAL_ERROR, // specific type
1491 (ULONG_PTR) GetObjectHandle(), // parm 2
1492 (ULONG_PTR) m_State); // parm 3
1493 }
1494
1495 //
1496 // The caller wants to free the reserved map registers, so force their
1497 // release.
1498 //
1500
1503 "Exit WDFDMATRANSACTION %p",
1504 dmaTransaction);
1505 }
1506
1507 return;
1508}
1509
1513 VOID
1514 )
1515{
1518 WDFDMATRANSACTION dmaTransaction;
1519
1520 //
1521 // Client driver could complete and delete the object in
1522 // EvtProgramDmaFunction. So, save the handle because we need it
1523 // for tracing after we invoke the callback.
1524 //
1525 dmaTransaction = GetHandle();
1526
1529 "Enter WDFDMATRANSACTION %p",
1530 dmaTransaction);
1531
1533 "Starting WDFDMATRANSACTION %p - MDL %#p, "
1534 "offset %I64x, length %I64x",
1535 dmaTransaction,
1536 m_StartMdl,
1539 }
1540
1541 //
1542 // Reference the device when using DMA v2. For DMA v3 we can support
1543 // concurrent attempts to allocate the channel.
1544 //
1546 if (!NT_SUCCESS(status)) {
1547
1548 NT_ASSERTMSG("AcquireDevice should never fail when DMAv3 is in use",
1550
1552 "Only one transaction can be queued "
1553 "at one time on a packet based WDFDMAENABLER %p "
1554 "%!STATUS!", m_DmaEnabler->GetHandle(),
1555 status);
1557 return status;
1558 }
1559
1560 //
1561 // Calculate the initial DMA transfer length.
1562 //
1564
1566
1568 //
1569 // Caller is simply reserving the DMA adapter for later use. Ask for
1570 // as many map registers as the driver requested.
1571 //
1573
1574 ASSERT(m_MapRegistersNeeded <= m_AdapterInfo->NumberOfMapRegisters);
1575
1577
1578 }
1579 else {
1580
1581 if (m_DmaEnabler->IsBusMaster() == FALSE) {
1582
1583 //
1584 // Use as many map registers as we were granted.
1585 //
1587 } else {
1588
1589 //
1590 // If the transfer is the size of the transaction then use the offset
1591 // to determine the number of map registers needed. If it's smaller
1592 // then use the worst-case offset to make sure we ask for enough MR's
1593 // to account for a bigger offset in one of the later transfers.
1594 //
1595 // Example:
1596 // Transaction is 8 KB and is page aligned
1597 // if max transfer is >= 8KB then this will be one transfer and only
1598 // requires two map registers. Even if the driver completes a partial
1599 // transfer and we have to do the rest in a second transfer it will
1600 // fit within two map registers becuase the overall transaction does
1601 // (and a partial transfer can't take more map registers than the
1602 // whole transaction would).
1603 //
1604 // If max transfer is 2KB then this nominally requires 4 2KB transfers.
1605 // In this case however, a partial completion of one of those transfers
1606 // would leave us attempting a second 2KB transfer starting on an
1607 // unaligned address. For example, we might transfer 2KB, then 1KB
1608 // then 2KB. Even though the first transfer was page aligned, the
1609 // 3rd transfer isn't and could cross a page boundary, requiring two
1610 // map registers rather than one.
1611 //
1612 // To account for this second case, ignore the actual MDL offset and
1613 // instead compute the maximum number of map registers than an N byte
1614 // transfer could take (with worst-case alignment).
1615 //
1616 //
1622 (PVOID)(ULONG_PTR) (PAGE_SIZE -1)),
1624 );
1625
1626
1627 ASSERT(m_MapRegistersNeeded <= m_AdapterInfo->NumberOfMapRegisters);
1628 }
1629
1630 //
1631 // NOTE: the number of map registers needed for this transfer may
1632 // exceed the number that we've reserved. StageTransfer will
1633 // take care of fragmenting the transaction accordingly.
1634 //
1636 }
1637
1638 if (!NT_SUCCESS(status)) {
1640 "AllocateAdapterChannel failed for "
1641 "WDFDMATRANSACTION %p, %!STATUS!",
1642 dmaTransaction, status);
1643 ReleaseDevice();
1644 }
1645
1646 //
1647 // Before AllocateAdapterChannel returns, _AdapterControl can get called
1648 // on another thread and the driver could delete the transaction object.
1649 // So don't touch the object after this point.
1650 //
1653 "Exit WDFDMATRANSACTION %p, "
1654 "%!STATUS!", dmaTransaction, status);
1655 }
1656
1657 return status;
1658}
1659
1663 __in PIRP Irp,
1666 )
1667{
1668 FxDmaPacketTransaction * pDmaTransaction;
1672
1675
1676 pDmaTransaction = (FxDmaPacketTransaction*) Context;
1677 ASSERT(pDmaTransaction);
1678
1679 pFxDriverGlobals = pDmaTransaction->GetDriverGlobals();
1680
1681 //
1682 // Cache the return value while we can still touch the transaction
1683 //
1684 action = pDmaTransaction->GetAdapterControlReturnValue();
1685
1686 //
1687 // Save the MapRegister base, unless it was previously set
1688 // during a reserve.
1689 //
1690 if (pDmaTransaction->IsMapRegisterBaseSet() == FALSE) {
1691 pDmaTransaction->SetMapRegisterBase(MapRegisterBase);
1692 }
1693 else {
1694 NT_ASSERTMSG("Caller was expected to use existing map register base",
1695 MapRegisterBase == pDmaTransaction->m_MapRegisterBase);
1696 }
1697
1700 "Map registers for WDFDMATRANSACTION %p allocated "
1701 "(base %p)",
1702 pDmaTransaction->GetHandle(),
1704 }
1705
1706 //
1707 // NOTE: KMDF used to call KeFlushIoBuffers() here to "ensure the
1708 // data buffers were flushed." However KeFlushIoBuffers did
1709 // nothing on x86 & amd64 (which are cache coherent WRT DMA)
1710 // and calling FlushAdapterBuffers() does any necessary
1711 // flushing anyway. Plus on non-cache-coherent architectures
1712 // (such as ARM) the flush operation has to be cache-line aligned
1713 // to avoid cache line tearing. So the flush is not necessary
1714 // and has been removed.
1715
1716 //
1717 // Check the state of the transaction. If it's reserve then call the
1718 // reserve callback and return. Otherwise stage the first fragment.
1719 //
1720 if (pDmaTransaction->m_State == FxDmaTransactionStateReserved)
1721 {
1723
1724 //
1725 // Save off and clear the callback before calling it.
1726 //
1727 callback = pDmaTransaction->m_DmaAcquiredFunction;
1728 pDmaTransaction->m_DmaAcquiredFunction.Clear();
1729
1730 ASSERTMSG("Mismatch between map register counts",
1731 (pDmaTransaction->m_MapRegistersReserved ==
1732 pDmaTransaction->m_MapRegistersNeeded));
1733
1734 //
1735 // Invoke the callback. Note that from here the driver may initialize
1736 // and execute the transaction.
1737 //
1738 callback.InvokeReserveDma(
1739 pDmaTransaction->GetHandle(),
1740 pDmaTransaction->m_DmaAcquiredContext
1741 );
1742 }
1743 else {
1744
1745 //
1746 // Stage next fragment
1747 //
1748 status = pDmaTransaction->StageTransfer();
1749
1750 if (!NT_SUCCESS(status)) {
1751
1752 DMA_COMPLETION_STATUS dmaStatus =
1755
1756 //
1757 // Map transfer failed. There will be no DMA completion callback
1758 // and no call to EvtProgramDma. And we have no way to hand this
1759 // status back directly to the driver. Fake a DMA completion with
1760 // the appropriate status.
1761 //
1762 // This should only happen for system DMA (and there most likely
1763 // only during cancelation, though we leave the possibility that
1764 // the DMA extension may fail the transfer)
1765 //
1766 ASSERTMSG("Unexpected failure of StageTransfer for packet based "
1767 "DMA",
1768 (pDmaTransaction->GetDmaEnabler()->IsBusMaster() == false));
1769
1772 "Invoking DmaCompleted callback %p (context %p) "
1773 "for WDFDMATRANSACTION %p (status %x) "
1774 "due to staging failure (%!STATUS!)",
1777 pDmaTransaction->GetHandle(),
1778 dmaStatus,
1779 status);
1780 }
1781
1782 pDmaTransaction->CallEvtDmaCompleted(
1784 );
1785 }
1786 }
1787
1788 //
1789 // Indicate that MapRegs are to be kept
1790 //
1791 return action;
1792}
1793
1797 VOID
1798 )
1799{
1800 PSCATTER_GATHER_LIST sgList;
1801
1803#ifndef __REACTOS__
1804 UCHAR_MEMORY_ALIGNED sgListBuffer[sizeof(SCATTER_GATHER_LIST)
1805 + sizeof(SCATTER_GATHER_ELEMENT)];
1806#else
1807 UCHAR sgListBuffer[sizeof(SCATTER_GATHER_LIST)
1808 + sizeof(SCATTER_GATHER_ELEMENT)];
1809#endif
1810
1811 WDFDMATRANSACTION dmaTransaction;
1812
1813 KIRQL oldIrql;
1814 BOOLEAN stagingNeeded;
1815
1817
1818 //
1819 // Client driver could complete and delete the object in
1820 // EvtProgramDmaFunction. So, save the handle because we need it
1821 // for tracing after we invoke the callback.
1822 //
1824 dmaTransaction = GetHandle();
1825
1828 "Enter WDFDMATRANSACTION %p ", dmaTransaction);
1829 }
1830
1831 //
1832 // For packet base DMA, current and startMDL will always be
1833 // same. For V2 DMA we don't support MDL chains. For V3 DMA
1834 // we use the HAL's support for MDL chains and don't walk through
1835 // the MDL chain on our own.
1836 //
1838
1839 LockTransferState(&oldIrql);
1840
1841 if (m_TransferState.CurrentStagingThread != NULL) {
1842
1843 //
1844 // Staging in progress. Indicate that another staging will
1845 // be needed.
1846 //
1847 m_TransferState.RerunStaging = TRUE;
1848
1849 stagingNeeded = FALSE;
1850
1854 "Staging next fragment of WDFDMATRANSACTION %p "
1855 "deferred",
1856 dmaTransaction
1857 );
1858 }
1859 }
1860 else {
1861 //
1862 // Staging isn't in progress anyplace else. Indicate that it's
1863 // running now so that any parallel attempt is blocked.
1864 //
1865 m_TransferState.CurrentStagingThread = KeGetCurrentThread();
1866
1867 ASSERTMSG("The thread which was staging didn't clear "
1868 "RerunStaging",
1869 (m_TransferState.RerunStaging == FALSE));
1870
1871 stagingNeeded = TRUE;
1872 }
1873
1874 UnlockTransferState(oldIrql);
1875
1876 //
1877 // Take a reference on the transaction so that we can safely
1878 // manipulate the transfer state even after it's destroyed.
1879 //
1881
1882 //
1883 // Loop for as long as staging is required
1884 //
1885 while (stagingNeeded) {
1886
1887 //
1888 // Calculate length for this packet.
1889 //
1891
1892 //
1893 // Calculate address for this packet.
1894 //
1896
1897 //
1898 // Adjust the fragment length for the number of reserved map registers.
1899 //
1900 if ((m_MapRegistersReserved > 0) &&
1902 {
1903 size_t currentOffset = m_CurrentFragmentOffset;
1904 size_t currentPageOffset;
1905 PMDL mdl;
1906
1907 for (mdl = m_CurrentFragmentMdl; mdl != NULL; mdl = mdl->Next)
1908 {
1909 //
1910 // For packet/system transfers of chained MDLs, m_CurrentFragmentMdl
1911 // is never adjusted, and m_CurrentFragmentOFfset is the offset
1912 // into the entire chain.
1913 //
1914 // Locate the MDL which contains the current fragment.
1915 //
1916 ULONG mdlBytes = MmGetMdlByteCount(mdl);
1917 if (mdlBytes >= currentOffset)
1918 {
1919 //
1920 // This MDL is larger than the remaining offset, so it
1921 // contains the start address.
1922 //
1923 break;
1924 }
1925
1926 currentOffset -= mdlBytes;
1927 }
1928
1929 ASSERT(mdl != NULL);
1930
1931 //
1932 // Compute page offset from current MDL's initial page offset
1933 // and the offset into that MDL
1934 //
1935
1936 currentPageOffset = BYTE_OFFSET(MmGetMdlByteOffset(mdl) +
1937 currentOffset);
1938
1939 //
1940 // Compute the maximum number of bytes we can transfer with
1941 // the number of map registers we have reserved, taking into
1942 // account the offset of the first page.
1943 //
1944 size_t l = ((PAGE_SIZE * (m_MapRegistersReserved - 1)) +
1945 (PAGE_SIZE - currentPageOffset));
1946
1948 }
1949
1951
1954 "Initiating %s transfer for WDFDMATRANSACTION %p. "
1955 "Mdl %p, Offset %I64x, Length %I64x",
1956 m_Transferred == 0 ? "first" : "next",
1957 GetHandle(),
1961 }
1962
1963 //
1964 // Check for a pending cancellation. This can happen if the cancel
1965 // occurred between DMA completion and FlushAdapterBuffers -
1966 // FlushAdapterBuffers will clear the canceled bit in the transfer
1967 // context (TC), which would allow MapTransfer to succeed.
1968 //
1969 // An unprotected check of IsCancelled here is safe. A concurrent
1970 // cancel at this point would mark the TC cancelled such that
1971 // MapTransfer will fail.
1972 //
1973 if (m_IsCancelled == TRUE) {
1975 goto End;
1976 }
1977
1978 //
1979 // Profile specific work before mapping the transfer. if this
1980 // fails consider 'this' invalid.
1981 //
1982 if (PreMapTransfer() == FALSE) {
1984 goto End;
1985 }
1986
1987 //
1988 // Map this packet for transfer.
1989 //
1990
1991 //
1992 // For packet based DMA we use a single entry on-stack SGL. This
1993 // allows us to map multiple packet-based requests concurrently and
1994 // we know packet base DMA only requires a single SGL
1995 //
1996 // NOTE: It turns out the HAL doesn't handle chained MDLs in packet
1997 // mode correctly. It makes each MDL continguous, but returns
1998 // a list of SG elements - one for each MDL. That's scatter
1999 // gather DMA, not packet DMA.
2000 //
2001 // So it's actually very important in Win8 that we only use a
2002 // single entry SGL when calling MapTransferEx. This ensures
2003 // we only map the first MDL in the chain and thus get a
2004 // contiguous buffer
2005 //
2006 // For system DMA we use the SystemSGList stored in the DMA enabler
2007 // We can use a shared one in that case because we won't be mapping
2008 // multiple system DMA requests concurrently (HAL doesn't allow it)
2009 //
2010 FxDmaEnabler* enabler;
2011 size_t sgListSize;
2012
2013 enabler = GetDmaEnabler();
2014
2015 if (enabler->IsBusMaster()) {
2016 sgList = (PSCATTER_GATHER_LIST)sgListBuffer;
2017 sgListSize = sizeof(sgListBuffer);
2018 } else {
2019 sgList = enabler->m_SGList.SystemProfile.List;
2020 sgListSize = enabler->m_SGListSize;
2021 }
2022
2023 ULONG mappedBytes;
2024
2025 status = MapTransfer(sgList,
2026 (ULONG) sgListSize,
2028 this,
2029 &mappedBytes);
2030
2031 NT_ASSERTMSG("Unexpected failure of MapTransfer",
2032 ((NT_SUCCESS(status) == TRUE) ||
2033 (status == STATUS_CANCELLED)));
2034
2035 if (NT_SUCCESS(status)) {
2036
2037 NT_ASSERTMSG("unexpected number of mapped bytes",
2038 ((mappedBytes > 0) &&
2039 (mappedBytes <= m_CurrentFragmentLength)));
2040
2041 //
2042 // Adjust the remaining byte count if the HAL mapped less data than we
2043 // requested.
2044 //
2045 if (mappedBytes < m_CurrentFragmentLength) {
2046 m_Remaining += m_CurrentFragmentLength - mappedBytes;
2047 m_CurrentFragmentLength = mappedBytes;
2048 }
2049
2050 //
2051 // Do client PFN_WDF_PROGRAM_DMA callback.
2052 //
2054
2057 "Invoking ProgramDma callback %p (context %p) for "
2058 "WDFDMATRANSACTION %p.",
2061 GetHandle()
2062 );
2063 }
2064
2065 //
2066 // Call program DMA
2067 //
2069 GetHandle(),
2073 sgList
2074 );
2075 }
2076 }
2077
2078End:
2079 //
2080 // Process any pending completion or nested staging.
2081 //
2082 {
2083 LockTransferState(&oldIrql);
2084
2085 //
2086 // While staging we could either have deferred a call to the
2087 // completion routine or deferred another call to stage the
2088 // next fragment. We should not ever have to do both - this
2089 // would imply that the driver didn't wait for its DMA completion
2090 // routine to run when calling TransferComplete*.
2091 //
2092 ASSERTMSG("driver called TransferComplete with pending DMA "
2093 "completion callback",
2094 !((m_TransferState.RerunCompletion == TRUE) &&
2095 (m_TransferState.RerunStaging == TRUE)));
2096
2097 //
2098 // Check for pending completion. save the status away and clear it
2099 // before dropping the lock.
2100 //
2101 if (m_TransferState.RerunCompletion == TRUE) {
2102 DMA_COMPLETION_STATUS completionStatus;
2104
2105 //
2106 // Save the completion status for when we drop the lock.
2107 //
2108 completionStatus = m_TransferState.CompletionStatus;
2109
2110 ASSERTMSG("completion needed, but status was not set or was "
2111 "already cleared",
2112 completionStatus != UNDEFINED_DMA_COMPLETION_STATUS);
2113
2114 ASSERTMSG("completion needed, but mapping failed so there shouldn't "
2115 "be any parallel work going on",
2117
2118 //
2119 // Clear the completion needed state.
2120 //
2121 m_TransferState.RerunCompletion = FALSE;
2123
2124 //
2125 // Drop the lock, call the completion routine, then take the
2126 // lock again.
2127 //
2128 UnlockTransferState(oldIrql);
2131 "Invoking DmaCompleted callback %p (context %p) "
2132 "for WDFDMATRANSACTION %p (status %x) "
2133 "after deferral",
2136 GetHandle(),
2137 completionStatus);
2138 }
2139 CallEvtDmaCompleted(completionStatus);
2140 LockTransferState(&oldIrql);
2141
2142 //
2143 // Staging is blocked, which means we aren't starting up the
2144 // next transfer. Therefore we cannot have a queued completion.
2145 //
2146 ASSERTMSG("RerunCompletion should not be set on an unstaged "
2147 "transaction",
2148 m_TransferState.RerunCompletion == FALSE);
2149 }
2150
2151 //
2152 // Capture whether another staging is needed. If none is needed
2153 // then we can clear staging in progress.
2154 //
2155 if (m_TransferState.RerunStaging == TRUE) {
2156 stagingNeeded = TRUE;
2157 m_TransferState.RerunStaging = FALSE;
2158 }
2159 else {
2160 m_TransferState.CurrentStagingThread = NULL;
2161 stagingNeeded = FALSE;
2162 }
2163
2164 UnlockTransferState(oldIrql);
2165 }
2166
2167#if DBG
2168 if (!NT_SUCCESS(status)) {
2169 ASSERTMSG("MapTransfer returned an error - there should not be any "
2170 "deferred work.",
2171 (stagingNeeded == FALSE));
2172 }
2173#endif
2174
2175 } // while(stagingNeeded)
2176
2178
2181 "Exit WDFDMATRANSACTION %p, "
2182 "%!STATUS!", dmaTransaction,
2183 status);
2184 }
2185
2186 return status;
2187}
2188
2192 VOID
2193 )
2194{
2197
2198 //
2199 // Flush the buffers
2200 //
2202
2203 if (!NT_SUCCESS(status)) {
2205 "FlushAdapterBuffers on WDFDMATRANSACTION %p "
2206 "failed, %!STATUS!",
2207 GetHandle(), status);
2209 }
2210
2211 return status;
2212}
2213
2214// ----------------------------------------------------------------------------
2215// ------------------- SYSTEM DMA SECTION -------------------------------------
2216// ----------------------------------------------------------------------------
2217
2219 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
2220 __in USHORT ExtraSize,
2222 ) :
2223 FxDmaPacketTransaction(FxDriverGlobals, sizeof(FxDmaSystemTransaction), ExtraSize, DmaEnabler)
2224{
2225 return;
2226}
2227
2231 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
2234 __out WDFDMATRANSACTION* Transaction
2235 )
2236{
2237 FxDmaPacketTransaction* pTransaction;
2238 WDFOBJECT hTransaction;
2240
2241 pTransaction = new (FxDriverGlobals, Attributes, DmaEnabler->GetTransferContextSize())
2242 FxDmaSystemTransaction(FxDriverGlobals, DmaEnabler->GetTransferContextSize(), DmaEnabler);
2243
2244 if (pTransaction == NULL) {
2247 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDMA,
2248 "Could not allocate memory for WDFTRANSACTION, %!STATUS!", status);
2249 return status;
2250 }
2251
2252 //
2253 // Commit and apply the attributes
2254 //
2255 status = pTransaction->Commit(Attributes, &hTransaction, DmaEnabler);
2256 if (NT_SUCCESS(status)) {
2257 *Transaction = (WDFDMATRANSACTION)hTransaction;
2258 }
2259 else {
2260 //
2261 // This will properly clean up the target's state and free it
2262 //
2263 pTransaction->DeleteFromFailedCreate();
2264 }
2265
2266 return status;
2267}
2268
2269BOOLEAN
2271 VOID
2272 )
2273{
2276
2278 //
2279 // Invoke the callback. If it returns false then the driver has
2280 // completed the transaction in the callback and we must abort
2281 // processing.
2282 //
2283
2286 "Invoking ConfigureChannel callback %p (context "
2287 "%p) for WDFDMATRANSACTION %p.",
2290 GetHandle());
2291 }
2292
2294 GetHandle(),
2300 );
2301 }
2302
2303 return result;
2304}
2305
2306
2309 VOID
2310 )
2311{
2313 return NULL;
2314 }
2315 else {
2316 return _SystemDmaCompletion;
2317 }
2318}
2319
2320VOID
2323 )
2324{
2325 //
2326 // Call the TransferComplete callback to indicate that the
2327 // transfer was aborted.
2328 //
2330 GetHandle(),
2334 Status
2335 );
2336}
2337
2338VOID
2342 )
2343{
2346
2348 "WDFDMATRANSACTION %p state %!FxDmaTransactionState! "
2349 "is invalid", GetHandle(), m_State);
2350
2352 WDF_DMA_FATAL_ERROR, // specific type
2353 (ULONG_PTR) GetObjectHandle(), // parm 2
2354 (ULONG_PTR) m_State); // parm 3
2355 }
2356
2357 DMA_TRANSFER_INFO info = {0};
2358
2359
2360
2361
2362
2363
2364 if (m_DmaEnabler->UsesDmaV3()) {
2365
2366 //
2367 // Ask the HAL for information about the MDL and how many resources
2368 // it will require to transfer.
2369 //
2370 m_AdapterInfo->AdapterObject->DmaOperations->GetDmaTransferInfo(
2372 m_StartMdl,
2374 (ULONG) this->m_TransactionLength,
2375 this->m_DmaDirection == WDF_DMA_DIRECTION::WdfDmaDirectionWriteToDevice,
2376 &info
2377 );
2378 } else {
2379 size_t offset = m_StartOffset;
2380 size_t length = m_TransactionLength;
2381
2382 //
2383 // Walk through the MDL chain and make a worst-case computation of
2384 // the number of scatter gather entries and map registers the
2385 // transaction would require.
2386 //
2387 for(PMDL mdl = m_StartMdl;
2388 mdl != NULL && length != 0;
2389 mdl = mdl->Next) {
2390
2392 if (byteCount <= offset) {
2393 offset -= byteCount;
2394 } else {
2396
2397 startVa += offset;
2398 byteCount -= offset;
2399
2400 info.V1.MapRegisterCount +=
2402 startVa,
2404 );
2405
2407 }
2408 }
2409
2410 info.V1.ScatterGatherElementCount = info.V1.MapRegisterCount;
2411 }
2412
2414 *MapRegisterCount = info.V1.MapRegisterCount;
2415 }
2416
2418 *ScatterGatherElementCount = info.V1.ScatterGatherElementCount;
2419 }
2420
2421 return;
2422}
2423
2424VOID
2426 __in PDMA_ADAPTER /* DmaAdapter */,
2427 __in PDEVICE_OBJECT /* DeviceObject */,
2430 )
2431{
2434 KIRQL oldIrql;
2435 BOOLEAN completionDeferred;
2436
2437 //
2438 // Lock the transfer state so that a staging or cancelling thread
2439 // cannot change it.
2440 //
2441 transaction->LockTransferState(&oldIrql);
2442
2443 ASSERTMSG("Completion state was already set",
2444 (transaction->m_TransferState.CompletionStatus ==
2446 ASSERTMSG("Deferred completion is already pending",
2447 (transaction->m_TransferState.RerunCompletion == FALSE));
2448
2449 //
2450 // If a staging is in progress then defer the completion.
2451 //
2452 if (transaction->m_TransferState.CurrentStagingThread != NULL) {
2453 transaction->m_TransferState.CompletionStatus = Status;
2454 transaction->m_TransferState.RerunCompletion = TRUE;
2455 completionDeferred = TRUE;
2456 }
2457 else {
2458 completionDeferred = FALSE;
2459 }
2460
2461 transaction->UnlockTransferState(oldIrql);
2462
2463 //
2464 // Process the old state.
2465 //
2466 if (completionDeferred == TRUE) {
2467 //
2468 // The staging thread has not moved past EvtProgramDma. The staging thread
2469 // will detect the state change and call the completion routine.
2470 //
2471 // Nothing to do in this case.
2472 //
2475 "Deferring DmaCompleted callback for WDFDMATRANSACTION %p"
2476 "(status %x)",
2477 transaction->GetHandle(),
2478 Status);
2479 }
2480 }
2481 else {
2482 //
2483 // Completion occurred while the transfer was running or
2484 // being cancelled. Call the completion routine.
2485 //
2486 // Note: a cancel when in programming state leaves the
2487 // state as programming. that we're not in programming
2488 // means we don't need to worry about racing with
2489 // EvtProgramDma.
2490 //
2491
2494 "Invoking DmaCompleted callback %p (context %p) "
2495 "for WDFDMATRANSACTION %p (status %x)",
2497 transaction->m_TransferCompleteContext,
2498 transaction->GetHandle(),
2499 Status);
2500 }
2501 transaction->CallEvtDmaCompleted(Status);
2502 }
2503}
2504
2505VOID
2507 VOID
2508 )
2509{
2510 //
2511 // Mark the transfer cancelled so we have a record of it even if
2512 // a racing call to FlushAdapterBuffers clears the TC.
2513 //
2515
2516 //
2517 // Cancel the system DMA transfer. This arranges for one of two things
2518 // to happen:
2519 // * the next call to MapTransfer will fail
2520 // * the DMA completion routine will run
2521 //
2522 if (CancelMappedTransfer() == FALSE) {
2523
2524 //
2525 // The cancel failed. Someone has already stopped this transfer.
2526 // That's illegal.
2527 //
2529
2531 "WDFDMATRANSACTION %p has already been stopped",
2532 GetHandle());
2533
2536 WDF_DMA_FATAL_ERROR, // type
2537 (ULONG_PTR) GetObjectHandle(), // parm 2
2538 (ULONG_PTR) m_State); // parm 3
2539 }
2540 }
2541}
static PMDL CurrentMdl
unsigned char BOOLEAN
#define VOID
Definition: acefi.h:82
LONG NTSTATUS
Definition: precomp.h:26
r l[0]
Definition: byte_order.h:168
_In_ BOOLEAN Release
Definition: cdrom.h:920
WDFDEVICE __inline GetHandle(VOID)
Definition: fxdevice.hpp:237
BOOLEAN m_IsSGListAllocated
VOID InitializeTransferContext(__out PVOID Context, __in WDF_DMA_DIRECTION Direction)
BOOLEAN UsesDmaV3(VOID)
__inline FxDmaDescription * GetWriteDmaDescription(VOID)
size_t m_SGListSize
__inline FxDmaDescription * GetReadDmaDescription(VOID)
__inline BOOLEAN IsBusMaster(VOID)
struct FxDmaEnabler::@5118::@5119 ScatterGatherProfile
struct FxDmaEnabler::@5118::@5120 SystemProfile
__inline WDFDMAENABLER GetHandle(VOID)
__inline size_t GetMaxSGElements(VOID)
PDEVICE_OBJECT m_FDO
ULONG m_MaxSGElements
union FxDmaEnabler::@5118 m_SGList
void SetMapRegisterBase(__in PVOID Value)
virtual VOID FreeMapRegistersAndAdapter(VOID)
FxDmaPacketTransaction(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in USHORT ExtraSize, __in FxDmaEnabler *DmaEnabler)
FORCEINLINE NTSTATUS MapTransfer(__out_bcount_opt(ScatterGatherListCb) PSCATTER_GATHER_LIST ScatterGatherList, __in ULONG ScatterGatherListCb, __in_opt PDMA_COMPLETION_ROUTINE CompletionRoutine, __in_opt PVOID CompletionContext, __out ULONG *TransferLength)
FORCEINLINE NTSTATUS FlushAdapterBuffers(VOID)
virtual VOID CallEvtDmaCompleted(__in DMA_COMPLETION_STATUS)
struct FxDmaPacketTransaction::@4631 m_TransferState
static IO_ALLOCATION_ACTION NTAPI _AdapterControl(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp, __in PVOID MapRegisterBase, __in PVOID Context)
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxDmaEnabler *DmaEnabler, __out WDFDMATRANSACTION *Transaction)
FORCEINLINE VOID ReleaseDevice(VOID)
_Must_inspect_result_ NTSTATUS AllocateAdapterChannel(__in BOOLEAN MapRegistersReserved)
BOOLEAN IsMapRegisterBaseSet(VOID)
virtual BOOLEAN PreMapTransfer(VOID)
_Must_inspect_result_ NTSTATUS ReserveAdapter(__in ULONG NumberOfMapRegisters, __in WDF_DMA_DIRECTION Direction, __in PFN_WDF_RESERVE_DMA Callback, __in_opt PVOID Context)
virtual _Must_inspect_result_ NTSTATUS TransferCompleted(VOID)
_Must_inspect_result_ NTSTATUS AcquireDevice(VOID)
virtual _Must_inspect_result_ NTSTATUS StartTransfer(VOID)
virtual VOID ReleaseResources(__in BOOLEAN ForceRelease)
virtual _Must_inspect_result_ NTSTATUS StageTransfer(VOID)
virtual PDMA_COMPLETION_ROUTINE GetTransferCompletionRoutine(VOID)
virtual _Must_inspect_result_ NTSTATUS InitializeResources(VOID)
virtual IO_ALLOCATION_ACTION GetAdapterControlReturnValue(VOID)
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxDmaEnabler *DmaEnabler, __out WDFDMATRANSACTION *Transaction)
virtual _Must_inspect_result_ NTSTATUS InitializeResources(VOID)
static VOID _AdapterListControl(__in DEVICE_OBJECT *DeviceObject, __in IRP *Irp, __in SCATTER_GATHER_LIST *SgList, __in VOID *Context)
FxDmaScatterGatherTransaction(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ExtraSize, __in FxDmaEnabler *DmaEnabler)
virtual _Must_inspect_result_ NTSTATUS StartTransfer(VOID)
_Must_inspect_result_ NTSTATUS BuildScatterGatherList(__in PMDL Mdl, __in size_t CurrentOffset, __in ULONG Length, __in PDRIVER_LIST_CONTROL ExecutionRoutine, __in PVOID Context, __in PVOID ScatterGatherBuffer, __in ULONG ScatterGatherBufferLength)
virtual _Must_inspect_result_ NTSTATUS TransferCompleted(VOID)
_Must_inspect_result_ NTSTATUS GetScatterGatherList(__in PMDL Mdl, __in size_t CurrentOffset, __in ULONG Length, __in PDRIVER_LIST_CONTROL ExecutionRoutine, __in PVOID Context)
virtual _Must_inspect_result_ NTSTATUS StageTransfer(VOID)
VOID PutScatterGatherList(__in PSCATTER_GATHER_LIST ScatterGather)
virtual VOID ReleaseResources(__in BOOLEAN ForceRelease)
static DMA_COMPLETION_ROUTINE _SystemDmaCompletion
FxDmaSystemTransaction(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ExtraSize, __in FxDmaEnabler *DmaEnabler)
BOOLEAN CancelMappedTransfer(VOID)
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxDmaEnabler *DmaEnabler, __out WDFDMATRANSACTION *Transaction)
VOID CallEvtDmaCompleted(__in DMA_COMPLETION_STATUS Status)
FxDmaTransactionConfigureChannel m_ConfigureChannelFunction
virtual PDMA_COMPLETION_ROUTINE GetTransferCompletionRoutine(VOID)
virtual BOOLEAN PreMapTransfer(VOID)
FxDmaTransactionTransferComplete m_TransferCompleteFunction
__forceinline VOID ReleaseButRetainRequest(VOID)
VOID SetImmediateExecution(__in BOOLEAN Value)
static PVOID GetStartVaFromOffset(__in PMDL Mdl, __in size_t Offset)
virtual _Must_inspect_result_ NTSTATUS TransferCompleted(VOID)=0
virtual VOID ReleaseResources(__in BOOLEAN ForceRelease)=0
FxDmaTransactionProgramOrReserveDma m_DmaAcquiredFunction
FxDmaDescription * m_AdapterInfo
virtual _Must_inspect_result_ NTSTATUS StartTransfer(VOID)=0
FxDmaEnabler * m_DmaEnabler
VOID ReleaseForReuse(__in BOOLEAN ForceRelease)
virtual _Must_inspect_result_ NTSTATUS StageTransfer(VOID)=0
__forceinline VOID ReferenceRequest(VOID)
WDF_DMA_DIRECTION m_DmaDirection
__forceinline FxDmaEnabler * GetDmaEnabler(VOID)
FxDmaTransactionBase(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in USHORT ExtraSize, __in FxDmaEnabler *DmaEnabler)
__forceinline VOID ClearRequest(VOID)
_Must_inspect_result_ NTSTATUS Execute(__in PVOID Context)
FxDmaTransactionState m_State
VOID GetTransferInfo(__out_opt ULONG *MapRegisterCount, __out_opt ULONG *ScatterGatherElementCount)
virtual _Must_inspect_result_ NTSTATUS InitializeResources(VOID)=0
virtual BOOLEAN Dispose(VOID)
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 VOID _ComputeNextTransferAddress(__in PMDL CurrentMdl, __in size_t CurrentOffset, __in ULONG Transferred, __deref_out PMDL *NextMdl, __out size_t *NextOffset)
_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)
BOOLEAN CancelResourceAllocation(VOID)
BOOLEAN DmaCompleted(__in size_t TransferredLength, __out NTSTATUS *ReturnStatus, __in FxDmaCompletionType CompletionType)
__forceinline WDFDMATRANSACTION GetHandle(VOID)
_Must_inspect_result_ BOOLEAN Invoke(__in WDFDMATRANSACTION DmaTransaction, __in WDFDEVICE Device, __in PVOID Context, __in_opt PMDL Mdl, __in size_t Offset, __in size_t Length)
PFN_WDF_DMA_TRANSACTION_CONFIGURE_DMA_CHANNEL Method
BOOLEAN InvokeProgramDma(__in WDFDMATRANSACTION Transaction, __in WDFDEVICE Device, __in PVOID Context, __in WDF_DMA_DIRECTION Direction, __in PSCATTER_GATHER_LIST SgList)
union FxDmaTransactionProgramOrReserveDma::@4632 Method
VOID Invoke(__in WDFDMATRANSACTION Transaction, __in WDFDEVICE Device, __in WDFCONTEXT Context, __in WDF_DMA_DIRECTION Direction, __in DMA_COMPLETION_STATUS Status)
PFN_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE Method
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
CfxDevice * m_Device
Definition: fxobject.hpp:329
ULONG __inline AddRef(__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
Definition: fxobject.hpp:826
CfxDeviceBase * m_DeviceBase
Definition: fxobject.hpp:328
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
_In_ PIRP Irp
Definition: csq.h:116
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __deref_out
Definition: dbghelp.h:26
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRACINGDMA
Definition: dbgtrace.h:71
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
return ret
Definition: mutex.c:146
action
Definition: namespace.c:707
#define ULONG_PTR
Definition: config.h:101
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
return pObject GetObjectHandle()
FxVerifierDbgBreakPoint(pFxDriverGlobals)
#define UNDEFINED_DMA_COMPLETION_STATUS
@ FxDmaTransactionStateDeleted
@ FxDmaTransactionStateInitialized
@ FxDmaTransactionStateTransferCompleted
@ FxDmaTransactionStateInvalid
@ FxDmaTransactionStateReleased
@ FxDmaTransactionStateReserved
@ FxDmaTransactionStateTransfer
@ FxDmaTransactionStateCreated
@ FxDmaTransactionStateTransferFailed
FxDmaCompletionType
@ FxDmaCompletionTypeAbort
@ FxDmaCompletionTypePartial
return pDmaTrans GetDmaEnabler() -> GetDeviceHandle()
MDL * mdl
FxDmaSystemTransaction * systemTransaction
return pDmaTrans GetTransferContext()
@ OkForDownLevel
Definition: fxglobals.h:80
__inline size_t FxSizeTMin(__in size_t A, __in size_t B)
Definition: fxglobals.h:997
__inline PVOID FxAllocateFromNPagedLookasideList(_In_ PNPAGED_LOOKASIDE_LIST Lookaside, _In_opt_ size_t ElementSize=0)
Definition: fxglobalskm.h:565
__inline VOID FxFreeToNPagedLookasideList(__in PNPAGED_LOOKASIDE_LIST Lookaside, __in PVOID Entry)
Definition: fxglobalskm.h:611
#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
#define FxVerifierBugCheck(FxDriverGlobals, Error,...)
Definition: fxverifier.h:58
Status
Definition: gdiplustypes.h:25
GLintptr offset
Definition: glext.h:5920
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
#define KeGetCurrentThread
Definition: hal.h:55
boolean suppress
Definition: jpeglib.h:1006
#define ASSERT(a)
Definition: mode.c:44
static IPrintDialogCallback callback
Definition: printdlg.c:326
#define min(a, b)
Definition: monoChain.cc:55
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define ARGUMENT_PRESENT(ArgumentPointer)
unsigned short USHORT
Definition: pedump.c:61
UCHAR byteCount
Definition: scsi.h:3755
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
STDMETHOD() Next(THIS_ ULONG celt, IAssociationElement *pElement, ULONG *pceltFetched) PURE
#define TRACE_LEVEL_WARNING
Definition: storswtr.h:28
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2297
PCANCEL_ADAPTER_CHANNEL CancelAdapterChannel
Definition: iotypes.h:2657
BOOLEAN FxVerifierOn
Definition: fxglobals.h:420
_Must_inspect_result_ BOOLEAN IsVerificationEnabled(__in ULONG Major, __in ULONG Minor, __in FxVerifierDownlevelOption DownLevel)
Definition: fxglobals.h:286
PDMA_ADAPTER AdapterObject
size_t MaximumFragmentLength
size_t PreallocatedSGListSize
Definition: ps.c:97
#define __WARNING_CLASS_MISMATCH_NONE
Definition: suppress.h:563
#define GetHandle(h)
Definition: treelist.c:116
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
@ WDF_DMA_FATAL_ERROR
Definition: wdfbugcodes.h:65
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDMAENABLER DmaEnabler
#define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type)
Definition: wdfcore.h:141
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ WDFDMAENABLER _In_ WDF_DMA_DIRECTION DmaDirection
enum _WDF_DMA_DIRECTION WDF_DMA_DIRECTION
@ WdfDmaDirectionReadFromDevice
Definition: wdfdmaenabler.h:65
EVT_WDF_PROGRAM_DMA * PFN_WDF_PROGRAM_DMA
EVT_WDF_RESERVE_DMA * PFN_WDF_RESERVE_DMA
WDF_EXTERN_C_START typedef _In_ WDFDEVICE _In_ WDFCONTEXT _In_ WDF_DMA_DIRECTION _In_ PSCATTER_GATHER_LIST SgList
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_In_ WDFDMATRANSACTION _Out_opt_ ULONG * MapRegisterCount
_In_ WDFDMATRANSACTION _In_ size_t TransferredLength
_In_ WDFDMATRANSACTION _Out_opt_ ULONG _Out_opt_ ULONG * ScatterGatherElementCount
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE _In_opt_ __drv_aliasesMem WDFCONTEXT CompletionContext
Definition: wdfrequest.h:898
#define STATUS_WDF_TOO_FRAGMENTED
Definition: wdfstatus.h:180
_Out_ PULONG NumberOfMapRegisters
Definition: halfuncs.h:209
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST
Definition: iotypes.h:2206
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2206
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:213
enum _IO_ALLOCATION_ACTION IO_ALLOCATION_ACTION
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099
DRIVER_LIST_CONTROL * PDRIVER_LIST_CONTROL
Definition: iotypes.h:2379
DMA_COMPLETION_STATUS
Definition: iotypes.h:2301
@ DmaError
Definition: iotypes.h:2304
@ DmaCancelled
Definition: iotypes.h:2305
#define DMA_SYNCHRONOUS_CALLBACK
Definition: iotypes.h:2151
DMA_COMPLETION_ROUTINE * PDMA_COMPLETION_ROUTINE
Definition: iotypes.h:2490
#define MmGetMdlByteOffset(_Mdl)
#define MmGetMdlByteCount(_Mdl)
#define MmGetMdlVirtualAddress(_Mdl)
#define BYTE_OFFSET(Va)
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define NT_ASSERTMSG
Definition: rtlfuncs.h:3328
unsigned char UCHAR
Definition: xmlstorage.h:181