EVT_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE 콜백 함수(wdfdmatransaction.h)

[KMDF에만 적용]

드라이버의 EvtDmaTransactionDmaTransferComplete 이벤트 콜백 함수는 시스템 모드 컨트롤러가 현재 DMA 전송을 완료할 때 호출됩니다.

구문

EVT_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE EvtWdfDmaTransactionDmaTransferComplete;

void EvtWdfDmaTransactionDmaTransferComplete(
  [in] WDFDMATRANSACTION Transaction,
  [in] WDFDEVICE Device,
  [in] WDFCONTEXT Context,
  [in] WDF_DMA_DIRECTION Direction,
  [in] DMA_COMPLETION_STATUS Status
)
{...}

매개 변수

[in] Transaction

방금 완료된 DMA 전송을 나타내는 DMA 트랜잭션 개체에 대한 핸들입니다.

[in] Device

드라이버가 WdfDmaTransactionCreate를 호출할 때 지정한 프레임워크 디바이스 개체에 대한 핸들입니다.

[in] Context

드라이버가 WdfDmaTransactionSetTransferCompleteCallback에 대한 이전 호출에서 지정한 컨텍스트 포인터입니다.

[in] Direction

완료된 DMA 전송 작업의 방향을 지정하는 WDF_DMA_DIRECTION 형식의 값입니다.

[in] Status

전송의 상태 지정하는 DMA_COMPLETION_STATUS 형식의 값입니다.

반환 값

없음

설명

버스 master DMA 디바이스의 하드웨어는 일반적으로 DMA 전송이 완료되면 인터럽트를 발급합니다. 그런 다음 드라이버는 EvtInterruptDpc 콜백 함수에서 DMA 전송을 완료합니다.

그러나 시스템 모드 DMA 디바이스의 하드웨어가 인터럽트를 실행하여 DMA 전송 완료를 항상 알리는 것은 아닙니다. DMA 전송 완료 알림을 받으려면 시스템 모드 DMA 디바이스의 드라이버가 대신 WdfDmaTransactionSetTransferCompleteCallback을 호출하여 EvtDmaTransactionDmaTransferCompleteComplete 이벤트 콜 함수를 등록할 수 있습니다.

프레임워크는 시스템 DMA 컨트롤러가 트랜잭션의 각 전송에 대해 한 번씩 전송을 완료한 후 EvtDmaTransactionDmaTransferComplete 를 호출합니다.

EvtDmaTransactionDmaTransferComplete 콜백 내에서 드라이버는 다음 메서드를 호출하여 프레임워크에 전송이 완료되었음을 알릴 수 있습니다.

WdfDmaTransactionDmaCompletedWdfDmaTransactionDmaCompletedFinalWdfDmaTransactionDmaCompletedWithLength 드라이버는 EvtDmaTransactionDmaTransferComplete에서 이전 메서드 중 하나를 호출하지 않을 수 있습니다. 대신 타이머 개체를 만들 거나 DPC가 나중에 전송을 완료하도록 예약하도록 선택합니다. WdfDmaTransactionDmaCompletedXxx가 TRUE를 반환하면 DMA 트랜잭션을 완료하는 데 더 이상 전송이 필요하지 않음을 나타내며, 드라이버는 필요에 따라 WdfDmaTransactionExecute를 호출하여 후속 트랜잭션을 시작할 수 있습니다.

드라이버가 WdfDmaTransactionStopSystemTransfer를 호출하는 경우 프레임워크는 상태 값이 DmaCancelledEvtDmaTransactionDmaTransferComplete를 호출합니다. 이 경우 드라이버는 EvtDmaTransactionDmaTransferComplete 내에서 WdfDmaTransactionDmaCompletedFinal을 호출한 다음 요청 처리를 계속할 수 있습니다.

WdfDmaTransactionDmaCompletedXxx가 TRUE를 반환할 때까지 드라이버는 트랜잭션과 연결된 데이터 버퍼를 조작해서는 안 됩니다.

DMA 트랜잭션을 종료해야 하는 경우 드라이버는 EvtDmaTransactionDmaTransferComplete 내에서 WdfDmaTransactionRelease를 호출할 수 있습니다.

시스템 모드 DMA에 대한 자세한 내용은 System-Mode DMA 지원을 참조하세요.

예제

EvtDmaTransactionDmaTransferComplete 콜백 함수를 정의하려면 먼저 정의 중인 콜백 함수의 형식을 식별하는 함수 선언을 제공해야 합니다. Windows는 드라이버에 대한 콜백 함수 형식 집합을 제공합니다. 콜백 함수 형식을 사용하여 함수를 선언하면 드라이버에 대한 코드 분석, SDV( 정적 드라이버 검증 도구 ) 및 기타 확인 도구에서 오류를 찾는 데 도움이 되며 Windows 운영 체제용 드라이버를 작성하기 위한 요구 사항입니다.

예를 들어 MyDmaTransactionDmaTransferComplete라는 EvtDmaTransactionDmaTransferComplete 콜백 함수를 정의하려면 이 코드 예제와 같이 EVT_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE 형식을 사용합니다.

EVT_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE  MyDmaTransactionDmaTransferComplete;

그런 다음 콜백 함수를 다음과 같이 구현합니다.


_Use_decl_annotations_
VOID
MyDmaTransactionDmaTransferComplete(
    WDFDMATRANSACTION Transaction,
    WDFDEVICE /* Device */,
    WDFCONTEXT Context,
    WDF_DMA_DIRECTION /* Direction */,
    DMA_COMPLETION_STATUS DmaStatus
    )
{
    PREQUEST_CONTEXT requestContext = (PREQUEST_CONTEXT) Context;
    NTSTATUS requestStatus;
    bool overrideStatus = true;
    size_t bytesTransferred;

    if (DmaStatus == DmaComplete) {
        //
        // Normal transfer completion.  Indicate this to the framework and see 
        // if there's more work to do.
        //
        if (WdfDmaTransactionDmaCompleted(Transaction, &requestStatus) == FALSE) {
            //
            // There are more DMA transfers to come.  The transaction 
            // may already have been completed on another processor.  
            // Return without touching it again.
            //
            goto exit;
        }

        requestStatus = STATUS_SUCCESS;
    }
    else {

        //
        // Complete the entire transaction.  But throw out the status and 
        // use one derived from the DmaStatus.
        //
        WdfDmaTransactionDmaCompletedFinal(Transaction, 0, &requestStatus);        
        
        //
        // Error or cancellation.  Indicate that this was the final transfer to 
        // the framework.
        //
        if (DmaStatus == DmaError) {
            requestStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else {

            //
            // Cancel status should only be triggered by timeout or cancel.  Rely on 
            // someone having already set the status, which means we should lose
            // the race for BeginCompletion below.
            //
            requestStatus = STATUS_PENDING;
            overrideStatus = false;
        }
    }

    //
    // Begin completion.  There's nothing special to do here if cancel or
    // timeout got there first.
    //
    BeginCompletion(requestContext, requestStatus, overrideStatus);

    //
    // Record the number of bytes we transferred.
    //
    bytesTransferred = WdfDmaTransactionGetBytesTransferred(
                        requestContext->DmaTransaction
                        );

    WdfRequestSetInformation(requestContext->Request, bytesTransferred);

    //
    // Success, error or cancel, this was the last transfer in the 
    // transaction.  Attempt to complete the request.
    //
    AttemptRequestCompletion(requestContext, true);

exit: 
    return;
}

bool
BeginCompletion(
    __in PREQUEST_CONTEXT  RequestContext,
    __in NTSTATUS          CompletionStatus,
    __in bool              ForceStatusUpdate
    )
{
    bool completionStarted;

    //
    // Grab the object lock and mark the beginning of 
    // completion.
    //
    WdfSpinLockAcquire(RequestContext->Lock);

    completionStarted = RequestContext->CompletionStarted;
    RequestContext->CompletionStarted = true;

    if ((completionStarted == false) || 
        (ForceStatusUpdate == true)) {
        RequestContext->CompletionStatus = CompletionStatus;
    }

    WdfSpinLockRelease(RequestContext->Lock);

    return !completionStarted;
}

VOID
AttemptRequestCompletion(
    __in PREQUEST_CONTEXT RequestContext,
    __in bool TransferComplete
    )
{
    LONG refCount;

    NT_ASSERTMSG("No thread has begun completion", 
                 RequestContext->CompletionStarted == true);

    if (TransferComplete) {
        //
        // Unmark the request cancelable.  If that succeeds then drop the cancel reference
        //
        if (WdfRequestUnmarkCancelable(RequestContext->Request) == STATUS_SUCCESS) {
            refCount = InterlockedDecrement(&(RequestContext->CompletionRefCount));
            NT_ASSERTMSGW(L"Reference count should not have gone to zero yet",
                          refCount != 0);
        }
                
        //
        // Stop the timer if it's been started.
        //
        if (RequestContext->TimerStarted == true) {
            if (WdfTimerStop(RequestContext->Timer, FALSE) == TRUE) {
                //
                // The timer was queued but will never run.  Drop its 
                // reference count.
                //
                refCount = InterlockedDecrement(&RequestContext->CompletionRefCount);
                NT_ASSERTMSG("Completion reference count should not reach zero until "
                             L"this routine calls AttemptRequestCompletion",
                             refCount > 0);
            }
        }
    }

    //
    // Drop this caller's reference.  If that was the last one then 
    // complete the request.
    //
    refCount = InterlockedDecrement(&(RequestContext->CompletionRefCount));

    if (refCount == 0) {
        NT_ASSERTMSGW(L"Execution reference was released, but execution "
                      L"path did not set a completion status for the "
                      L"request",
                      RequestContext->CompletionStatus != STATUS_PENDING);
        
        
        //
        // Timers are disposed of at passive level.  If we leave it attached to 
        // the request then we can hit a verifier issue, since the request 
        // needs to be immediately disposable at dispatch-level.
        //
        // Delete the timer now so that we can complete the request safely.
        // At this point the timer has either expired or been successfully 
        // cancelled so there's no race with the timer routine.
        //
        if (RequestContext->Timer != NULL) {
            WdfObjectDelete(RequestContext->Timer);
            RequestContext->Timer = NULL;
        }

        WdfRequestComplete(RequestContext->Request, 
                           RequestContext->CompletionStatus);
    }
}

EVT_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE 함수 형식은 WdfDmaTransaction.h 헤더 파일에 정의되어 있습니다. 코드 분석 도구를 실행할 때 오류를 보다 정확하게 식별하려면 함수 정의에 Use_decl_annotations 주석을 추가해야 합니다. Use_decl_annotations 주석은 헤더 파일의 EVT_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE 함수 형식에 적용되는 주석이 사용되도록 합니다. 함수 선언에 대한 요구 사항에 대한 자세한 내용은 KMDF 드라이버에 함수 역할 형식을 사용하여 함수 선언을 참조하세요. Use_decl_annotations 대한 자세한 내용은 함수 동작에 주석을 추가를 참조하세요.

요구 사항

요구 사항
지원되는 최소 클라이언트 Windows 8
대상 플랫폼 유니버설
최소 KMDF 버전 1.11
머리글 wdfdmatransaction.h(Wdf.h 포함)
IRQL DISPATCH_LEVEL

추가 정보

WdfDmaTransactionSetTransferCompleteCallback