コード例 #1
0
ファイル: fxdeviceapikm.cpp プロジェクト: AntejaVM/WDF
NTSTATUS
WDFEXPORT(WdfDeviceIndicateWakeStatus)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFDEVICE Device,
    __in
    NTSTATUS WaitWakeStatus
    )
{
    NTSTATUS status;
    FxDevice *pDevice;
    PFX_DRIVER_GLOBALS pFxDriverGlobals;

    FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
                                   Device,
                                   FX_TYPE_DEVICE,
                                   (PVOID *) &pDevice,
                                   &pFxDriverGlobals);

    if (Device == NULL ||
        WaitWakeStatus == STATUS_PENDING || WaitWakeStatus == STATUS_CANCELLED) {
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
                            "NULL WDFDEVICE handle %p or invalid %!STATUS!",
                            Device, WaitWakeStatus);
        return STATUS_INVALID_PARAMETER;
    }

    if (pDevice->m_PkgPnp->m_SharedPower.m_WaitWakeOwner) {
        if (pDevice->m_PkgPnp->PowerIndicateWaitWakeStatus(WaitWakeStatus)) {
            status = STATUS_SUCCESS;
        }
        else {
            //
            // There was no request to complete
            //
            DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
                                "WDFDEVICE 0x%p  No request to complete"
                                " STATUS_INVALID_DEVICE_REQUEST",
                                Device);

            status = STATUS_INVALID_DEVICE_REQUEST;
        }
    }
    else {
        //
        // We cannot complete what we do not own
        //
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
                            "WDFDEVICE 0x%p  Not the waitwake owner"
                            " STATUS_INVALID_DEVICE_STATE",
                            Device);

        status = STATUS_INVALID_DEVICE_STATE;
    }

    return status;
}
コード例 #2
0
VOID
FxPoxInterface::ComponentIdleCallback(
    __in PVOID Context,
    __in ULONG Component
    )
{
    PPOX_SETTINGS poxSettings = NULL;
    FxPoxInterface * pThis = NULL;
    
    pThis = (FxPoxInterface*) Context;

    DoTraceLevelMessage(
        pThis->m_PkgPnp->GetDriverGlobals(), 
        TRACE_LEVEL_VERBOSE, 
        TRACINGPNP,
        "WDFDEVICE 0x%p !devobj 0x%p PO_FX_COMPONENT_IDLE_CONDITION_CALLBACK "
        "invoked.",
        pThis->m_PkgPnp->GetDevice()->GetHandle(),
        pThis->m_PkgPnp->GetDevice()->GetDeviceObject()
        );

    //
    // If the client driver has specified power framework settings, retrieve 
    // them.
    //
    poxSettings = pThis->GetPowerFrameworkSettings();
                    
    //
    // If the client driver has specified a component-idle callback, invoke it
    //
    if ((NULL != poxSettings) && 
        (NULL != poxSettings->ComponentIdleConditionCallback)) {
        
        DoTraceLevelMessage(
            pThis->m_PkgPnp->GetDriverGlobals(), 
            TRACE_LEVEL_VERBOSE, 
            TRACINGPNP,
            "WDFDEVICE 0x%p !devobj 0x%p Invoking client driver's "
            "PO_FX_COMPONENT_IDLE_CONDITION_CALLBACK.",
            pThis->m_PkgPnp->GetDevice()->GetHandle(),
            pThis->m_PkgPnp->GetDevice()->GetDeviceObject()
            );
            
        poxSettings->ComponentIdleConditionCallback(
                           poxSettings->PoFxDeviceContext,
                           Component
                           );
    } else {
        //
        // We're being notified that we're idle, but there is no action that we
        // need to take here. We power down the device only when we get the 
        // device-power-not-required event.
        //
        PoFxCompleteIdleCondition(pThis->m_PoHandle, Component);
    }
    return;
}
コード例 #3
0
VOID
FxInterrupt::ReportInactive(
    _In_ BOOLEAN Internal
    )
{
    IO_REPORT_INTERRUPT_ACTIVE_STATE_PARAMETERS parameters;
    FxPkgPnp* fxPkgPnp;

    fxPkgPnp = m_Device->m_PkgPnp;

    if (Internal == FALSE) {
        //
        // if the interrupt is not connected, you can't report active or inactive
        //
        if(m_Connected == FALSE || m_Interrupt == NULL) {
            DoTraceLevelMessage(
                GetDriverGlobals(), TRACE_LEVEL_WARNING, TRACINGPNP,
                "Driver is reporting WDFINTERRUPT %p as being inactive even though"
                " it is not connected.",  GetHandle());
            FxVerifierDbgBreakPoint(GetDriverGlobals());
            return;
        }
        
        if (fxPkgPnp->m_IoReportInterruptInactive == NULL) {
            DoTraceLevelMessage(
                GetDriverGlobals(), TRACE_LEVEL_WARNING, TRACINGPNP,
                "Driver is calling DDI WdfInterruptReportInactive() on an OS that "
                "doesn't support the DDI.");
            FxVerifierDbgBreakPoint(GetDriverGlobals());
            return;
        }
    }
    
    //
    // No need to report Inactive if interrupt is already Inactive
    //
    if (m_Active == FALSE) {
        return;
    }

    RtlZeroMemory(&parameters, sizeof(parameters));

    if (FxIsProcessorGroupSupported()) {
        parameters.Version = CONNECT_FULLY_SPECIFIED_GROUP;
    }
    else {
        parameters.Version = CONNECT_FULLY_SPECIFIED;
    }

    parameters.ConnectionContext.InterruptObject = m_Interrupt;

    fxPkgPnp->m_IoReportInterruptInactive(&parameters);
    m_Active = FALSE;

    return;
}
コード例 #4
0
VOID
FxPoxInterface::ComponentActiveCallback(
    __in PVOID Context,
    __in ULONG Component
    )
{
    PPOX_SETTINGS poxSettings = NULL;
    FxPoxInterface * pThis = NULL;
    
    pThis = (FxPoxInterface*) Context;

    DoTraceLevelMessage(
        pThis->m_PkgPnp->GetDriverGlobals(), 
        TRACE_LEVEL_VERBOSE, 
        TRACINGPNP,
        "WDFDEVICE 0x%p !devobj 0x%p PO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK "
        "invoked.",
        pThis->m_PkgPnp->GetDevice()->GetHandle(),
        pThis->m_PkgPnp->GetDevice()->GetDeviceObject()
        );

    //
    // If the client driver has specified power framework settings, retrieve 
    // them.
    //
    poxSettings = pThis->GetPowerFrameworkSettings();
                    
    //
    // If the client driver has specified a component-active callback, invoke it
    //
    if ((NULL != poxSettings) && 
        (NULL != poxSettings->ComponentActiveConditionCallback)) {
        
        DoTraceLevelMessage(
            pThis->m_PkgPnp->GetDriverGlobals(), 
            TRACE_LEVEL_VERBOSE, 
            TRACINGPNP,
            "WDFDEVICE 0x%p !devobj 0x%p Invoking client driver's "
            "PO_FX_COMPONENT_ACTIVE_CONDITION_CALLBACK.",
            pThis->m_PkgPnp->GetDevice()->GetHandle(),
            pThis->m_PkgPnp->GetDevice()->GetDeviceObject()
            );
            
        poxSettings->ComponentActiveConditionCallback(
                           poxSettings->PoFxDeviceContext,
                           Component
                           );
    } else {
        //
        // Nothing to do.
        //
        DO_NOTHING();
    }
    
    return;
}
コード例 #5
0
ファイル: fxdeviceapikm.cpp プロジェクト: AntejaVM/WDF
NTSTATUS
WDFEXPORT(WdfDeviceAssignMofResourceName)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFDEVICE Device,
    __in
    PCUNICODE_STRING MofResourceName
    )
{
    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    FxDevice *pDevice;
    NTSTATUS status;

    FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
                                   Device,
                                   FX_TYPE_DEVICE,
                                   (PVOID *) &pDevice,
                                   &pFxDriverGlobals);

    FxPointerNotNull(pFxDriverGlobals, MofResourceName);

    status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL);
    if (!NT_SUCCESS(status)) {
        return status;
    }

    status = FxValidateUnicodeString(pFxDriverGlobals, MofResourceName);
    if (!NT_SUCCESS(status)) {
        return status;
    }

    if (pDevice->m_MofResourceName.Buffer !=  NULL) {
        status = STATUS_INVALID_DEVICE_REQUEST;

        DoTraceLevelMessage(
            pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
            "WDFDEVICE %p MofResourceName already assigned, %!STATUS!",
            Device, status);

        return status;
    }

    status = FxDuplicateUnicodeString(pFxDriverGlobals,
                                      MofResourceName,
                                      &pDevice->m_MofResourceName);

    if (!NT_SUCCESS(status)) {
        DoTraceLevelMessage(
            pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
            "WDFDEVICE %p couldn't creat duplicate buffer, %!STATUS!",
            Device, status);
    }

    return status;
}
コード例 #6
0
ファイル: fxdeviceapikm.cpp プロジェクト: AntejaVM/WDF
VOID
FX_VF_FUNCTION(VerifyWdfDeviceWdmDispatchIrp) (
    _In_ PFX_DRIVER_GLOBALS FxDriverGlobals,
    _In_ PWDF_DRIVER_GLOBALS DriverGlobals,
    _In_ FxDevice* device, 
    _In_ WDFCONTEXT  DispatchContext
    )
{    
    UNREFERENCED_PARAMETER(FxDriverGlobals);
    FxDriver*   driver;
    BOOLEAN     ctxValid;
    PLIST_ENTRY next;
    NTSTATUS    status;

    PAGED_CODE_LOCKED();

    status = STATUS_SUCCESS;
    driver = GetFxDriverGlobals(DriverGlobals)->Driver;
    ctxValid = (PLIST_ENTRY)DispatchContext == 
                &device->m_PreprocessInfoListHead ? TRUE : FALSE;
    //
    // Driver should be a cx.
    //
    if (device->IsCxDriverInIoPath(driver) == FALSE) {
        status = STATUS_INVALID_DEVICE_REQUEST;
        DoTraceLevelMessage(
                device->GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIO,
                "This API can only be called by wdf extension driver "
                "from its pre-process IRP callback, %!STATUS!",
                status);
        FxVerifierDbgBreakPoint(device->GetDriverGlobals());
    }
    
    //
    // Validate DispatchContext.
    //

    for (next = device->m_PreprocessInfoListHead.Flink;
         next != &device->m_PreprocessInfoListHead;
         next = next->Flink) {
        if ((PLIST_ENTRY)DispatchContext == next) {
            ctxValid = TRUE;
            break;
        }
    }

    if (FALSE == ctxValid) {
        status = STATUS_INVALID_PARAMETER;
        DoTraceLevelMessage(
                device->GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIO,
                "DispatchContext 0x%p is invalid, %!STATUS!",
                DispatchContext, status);
        FxVerifierDbgBreakPoint(device->GetDriverGlobals());
    }
}
コード例 #7
0
VOID
FxPoxInterface::StateCallback(
    __in PVOID Context,
    __in ULONG Component,
    __in ULONG State
    )
{
    PPOX_SETTINGS poxSettings = NULL;
    FxPoxInterface * pThis = NULL;
    
    pThis = (FxPoxInterface*) Context;

    DoTraceLevelMessage(
        pThis->m_PkgPnp->GetDriverGlobals(), 
        TRACE_LEVEL_VERBOSE, 
        TRACINGPNP,
        "WDFDEVICE 0x%p !devobj 0x%p PO_FX_COMPONENT_IDLE_STATE_CALLBACK "
        "invoked.",
        pThis->m_PkgPnp->GetDevice()->GetHandle(),
        pThis->m_PkgPnp->GetDevice()->GetDeviceObject()
        );

    //
    // If the client driver has specified power framework settings, retrieve 
    // them.
    //
    poxSettings = pThis->GetPowerFrameworkSettings();
                    
    //
    // If the client driver has specified an F-state change callback, invoke it.
    //
    if ((NULL != poxSettings) && 
        (NULL != poxSettings->ComponentIdleStateCallback)) {
        
        DoTraceLevelMessage(
            pThis->m_PkgPnp->GetDriverGlobals(), 
            TRACE_LEVEL_VERBOSE, 
            TRACINGPNP,
            "WDFDEVICE 0x%p !devobj 0x%p Invoking client driver's "
            "PO_FX_COMPONENT_IDLE_STATE_CALLBACK.",
            pThis->m_PkgPnp->GetDevice()->GetHandle(),
            pThis->m_PkgPnp->GetDevice()->GetDeviceObject()
            );
            
        poxSettings->ComponentIdleStateCallback(
                       poxSettings->PoFxDeviceContext,
                       Component,
                       State);
    } else {
        PoFxCompleteIdleState(pThis->m_PoHandle, Component);
    }
}
コード例 #8
0
HRESULT
FxInterruptWaitblock::Initialize(
    __in FxInterruptThreadpool* Threadpool,
    __in FxInterrupt* Interrupt,
    __in PTP_WAIT_CALLBACK WaitCallback
    ) 
{
    HRESULT hr = S_OK;
    DWORD error;
   
    //
    // create a per-interrupt auto-reset event, non-signalled to begin with.
    //
    m_Event = CreateEvent(
                          NULL,  // LPSECURITY_ATTRIBUTES lpEventAttributes,
                          FALSE, // BOOL bManualReset,
                          FALSE, // BOOL bInitialState,
                          NULL   // LPCTSTR lpName
                          );
    
    if (m_Event == NULL) {
        error = GetLastError();
        hr = HRESULT_FROM_WIN32(error);
        DoTraceLevelMessage(GetDriverGlobals(), 
                    TRACE_LEVEL_ERROR, TRACINGPNP,
                    "Event creation failed for FxInterrupt object"
                    " %!winerr!", error);           
        goto exit;
    }
    
    //
    // create a per-interrupt thread pool wait structure. This wait structure is
    // needed to associate an event-based wait callback with threadpool. 
    //
    m_Wait = Threadpool->CreateThreadpoolWait(WaitCallback, 
                                              Interrupt);
    if (m_Wait == NULL) {
        error = GetLastError();
        hr = HRESULT_FROM_WIN32(error);
        DoTraceLevelMessage(GetDriverGlobals(), 
                    TRACE_LEVEL_ERROR, TRACINGPNP,
                    "Event creation failed for FxInterrupt object"
                    " %!winerr!", error);           
        goto exit;
    }

exit:

    return hr;
}
コード例 #9
0
VOID
FxWorkItem::Enqueue(
    VOID
    )
{
    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    KIRQL irql;
    BOOLEAN enqueue;

    pFxDriverGlobals = GetDriverGlobals();
    enqueue = FALSE;

    Lock(&irql);

    if (m_Enqueued) {
        DoTraceLevelMessage(
            pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGDEVICE,
            "Previously queued WDFWORKITEM 0x%p is already pending. "
            "Ignoring the request to queue again", GetHandle());
    }
    else if (m_RunningDown) {
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
                "WDFWORKITEM 0x%p is already deleted", GetHandle());
        FxVerifierDbgBreakPoint(pFxDriverGlobals);
    }
    else {
        m_WorkItemCompleted.Clear();

        m_Enqueued = TRUE;

        //
        // We are going to enqueue the work item. Reference this FxWorkItem 
        // object and Globals while they are outstanding.
        // These will be released when the workitem completes.
        //
        ADDREF(WorkItemThunk);
        pFxDriverGlobals->ADDREF(WorkItemThunk);

        enqueue = TRUE;
    }

    Unlock(irql);

    if (enqueue) {
        m_WorkItem. Enqueue(FxWorkItem::WorkItemThunk, this);
    }

    return;
}
コード例 #10
0
HRESULT
FxInterruptWaitblock::_CreateAndInit(
    _In_ FxInterruptThreadpool* Threadpool,
    _In_ FxInterrupt* Interrupt,
    _In_ PTP_WAIT_CALLBACK WaitCallback,
    _Out_ FxInterruptWaitblock** Waitblock
    ) 
{
    HRESULT hr = S_OK;
    FxInterruptWaitblock* waitblock = NULL;
    PFX_DRIVER_GLOBALS driverGlobals;
        
    FX_VERIFY(INTERNAL, CHECK_NOT_NULL(Waitblock));
    *Waitblock = NULL;
    driverGlobals = Interrupt->GetDriverGlobals();

    //
    // create an instance of interrupt wait block
    //
    waitblock = new (driverGlobals) FxInterruptWaitblock(driverGlobals);
    if (waitblock == NULL) {
        hr = E_OUTOFMEMORY;
        DoTraceLevelMessage(driverGlobals, 
                    TRACE_LEVEL_ERROR, TRACINGPNP,
                    "Waitblock creation failed %!hresult!", hr);           
        goto exit;
    }

    hr = waitblock->Initialize(Threadpool, 
                               Interrupt,
                               WaitCallback);
    if (SUCCEEDED(hr)) {
        *Waitblock = waitblock;
    }
    else {
        DoTraceLevelMessage(driverGlobals, 
                    TRACE_LEVEL_ERROR, TRACINGPNP,
                    "Waitblock init failed %!hresult!", hr);           
    }

exit:

    if(FAILED(hr) && waitblock != NULL) {
        delete waitblock;
    }

    return hr;
}
コード例 #11
0
FxDriver::~FxDriver()
{
    // Make it always present right now even on free builds
    if (IsDisposed() == FALSE) {
        DoTraceLevelMessage(
            GetDriverGlobals(), TRACE_LEVEL_FATAL, TRACINGDRIVER,
            "FxDriver 0x%p not disposed: this maybe a driver reference count "
            "problem with WDFDRIVER 0x%p", this, GetObjectHandleUnchecked());

        FxVerifierBugCheck(GetDriverGlobals(),
                           WDF_OBJECT_ERROR,
                           (ULONG_PTR) GetObjectHandleUnchecked(),
                           (ULONG_PTR) this);
    }

    //
    // Free the memory for the registry path if required.
    //
    if (m_RegistryPath.Buffer) {
        FxPoolFree(m_RegistryPath.Buffer);
    }

    if (m_DisposeList != NULL) {
        m_DisposeList->DeleteObject();
    }

#if FX_IS_USER_MODE
    //
    // Close the R/W handle to the driver's service parameters key
    // that we opened during Initialize.
    //
    if (m_DriverParametersKey != NULL) {
        NTSTATUS status = FxRegKey::_Close(m_DriverParametersKey);
        if (!NT_SUCCESS(status)) {
            DoTraceLevelMessage(GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGDRIVER,
                                "Cannot close Driver Parameters key %!STATUS!",
                                status);
        }
        m_DriverParametersKey = NULL;
    }

    //
    // The host-created driver object holds a reference to this
    // FxDriver object. Clear it, since this object was deleted.
    //
    ClearDriverObjectFxDriver();
#endif
}
コード例 #12
0
NTSTATUS
WDFAPI
WDFEXPORT(WdfUsbTargetPipeReadSynchronously)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFUSBPIPE Pipe,
    __in_opt
    WDFREQUEST Request,
    __in_opt
    PWDF_REQUEST_SEND_OPTIONS RequestOptions,
    __in_opt
    PWDF_MEMORY_DESCRIPTOR MemoryDescriptor,
    __out_opt
    PULONG BytesRead
    )
{
    DDI_ENTRY();

    DoTraceLevelMessage(GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
                        "WDFUSBPIPE %p", Pipe);

    return FxUsbPipe::_SendTransfer(
        GetFxDriverGlobals(DriverGlobals),
        Pipe,
        Request,
        RequestOptions,
        MemoryDescriptor,
        BytesRead,
        USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK
        );
}
コード例 #13
0
NTSTATUS
WDFAPI
WDFEXPORT(WdfUsbTargetPipeFormatRequestForWrite)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFUSBPIPE Pipe,
    __in
    WDFREQUEST Request,
    __in_opt
    WDFMEMORY WriteMemory,
    __in_opt
    PWDFMEMORY_OFFSET WriteOffsets
    )
{
    DDI_ENTRY();

    DoTraceLevelMessage(GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
                        "WDFUSBPIPE %p, WDFREQUEST %p, WDFMEMORY %p",
                        Pipe, Request, WriteMemory);

    return FxUsbPipe::_FormatTransfer(GetFxDriverGlobals(DriverGlobals),
                                      Pipe,
                                      Request,
                                      WriteMemory,
                                      WriteOffsets,
                                      0);
}
コード例 #14
0
VOID
WDFAPI
WDFEXPORT(WdfUsbTargetPipeSetNoMaximumPacketSizeCheck)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFUSBPIPE Pipe
    )
{
    DDI_ENTRY();

    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    FxUsbPipe* pUsbPipe;

    FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
                                   Pipe,
                                   FX_TYPE_IO_TARGET_USB_PIPE,
                                   (PVOID*) &pUsbPipe,
                                   &pFxDriverGlobals);

    DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
                        "WDFUSBPIPE %p", Pipe);

    pUsbPipe->SetNoCheckPacketSize();
}
コード例 #15
0
VOID
FxWorkItem::FlushAndWait()
{
    PFX_DRIVER_GLOBALS pFxDriverGlobals;

    pFxDriverGlobals = GetDriverGlobals();

    if (m_WorkItemThread == Mx::MxGetCurrentThread()) {
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
                        "Calling WdfWorkItemFlush from within the WDFWORKITEM "
                        "%p callback will lead to deadlock, PRKTHREAD %p", 
                        GetHandle(), m_WorkItemThread);
        FxVerifierDbgBreakPoint(pFxDriverGlobals);
        return;
    }

    //
    // Wait for any outstanding workitem to complete.
    // The event is only set upon return from the callback
    // into the driver *and* the driver did not re-queue
    // the workitem. See similar comment in WorkItemHandler().
    //
    WaitForSignal();
    return;
}
コード例 #16
0
ファイル: fxpkgio.cpp プロジェクト: AntejaVM/WDF
FxPkgIo::FxPkgIo(
    __in PFX_DRIVER_GLOBALS FxDriverGlobals,
    __in CfxDevice *Device
) :
    FxPackage(FxDriverGlobals, Device, FX_TYPE_PACKAGE_IO),
    m_InCallerContextCallback(FxDriverGlobals)
{
    LARGE_INTEGER  tickCount;

    m_Device = Device;

    m_DefaultQueue = NULL;

    RtlZeroMemory(m_DispatchTable, sizeof(m_DispatchTable));

    m_Filter = FALSE;

    m_PowerStateOn = FALSE;

    m_QueuesAreShuttingDown = FALSE;

    InitializeListHead(&m_IoQueueListHead);

    InitializeListHead(&m_DynamicDispatchInfoListHead);

    Mx::MxQueryTickCount(&tickCount);

    m_RandomSeed = tickCount.LowPart;

    DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIO,
                        "Constructed FxPkgIo 0x%p",this);
}
コード例 #17
0
NTSTATUS
WDFAPI
WDFEXPORT(WdfUsbTargetPipeFormatRequestForRead)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFUSBPIPE Pipe,
    __in
    WDFREQUEST Request,
    __in_opt
    WDFMEMORY ReadMemory,
    __in_opt
    PWDFMEMORY_OFFSET ReadOffsets
    )
{
    DDI_ENTRY();

    DoTraceLevelMessage(
        GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
        "WDFUSBPIPE %p, WDFREQUEST %p, WDFMEMORY %p",
        Pipe, Request, ReadMemory);

    return FxUsbPipe::_FormatTransfer(
        GetFxDriverGlobals(DriverGlobals),
        Pipe,
        Request,
        ReadMemory,
        ReadOffsets,
        USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK
        );
}
コード例 #18
0
ファイル: fxpkgio.cpp プロジェクト: AntejaVM/WDF
VOID
FxPkgIo::ResetStateForRestart(
    VOID
)
/*++

Routine Description:
    This is called on a device which has been restarted from the removed
    state.  It will reset purged queues so that they can accept new requests
    when ResumeProcessingForPower is called afterwards.

Arguments:
    None

Return Value:
    None

  --*/
{
    KIRQL irql;
    FxIoQueue* queue;
    SINGLE_LIST_ENTRY queueList, *ple;

    DoTraceLevelMessage(GetDriverGlobals(), TRACE_LEVEL_INFORMATION, TRACINGIO,
                        "Restart queues from purged state for WDFDEVICE 0x%p due to "
                        "device restart", m_Device->GetHandle());

    queueList.Next = NULL;

    Lock(&irql);

    GetIoQueueListLocked(&queueList, FxIoQueueIteratorListPowerOn);

    Unlock(irql);

    for (ple = PopEntryList(&queueList);
            ple != NULL;
            ple = PopEntryList(&queueList)) {

        queue = FxIoQueue::_FromPowerSListEntry(ple);

        queue->ResetStateForRestart();

        ple->Next = NULL;

        queue->RELEASE(IO_ITERATOR_POWER_TAG);
    }

    Lock(&irql);

    m_PowerStateOn = TRUE;

    m_QueuesAreShuttingDown = FALSE;

    Unlock(irql);

    return;

}
コード例 #19
0
ファイル: fxpkgio.cpp プロジェクト: AntejaVM/WDF
_Must_inspect_result_
NTSTATUS
FxPkgIo::FlushAllQueuesByFileObject(
    __in MdFileObject FileObject
)

/*++

    Routine Description:

        Enumerate all the queues and cancel the requests that have
        the same fileobject as the Cleanup IRP.

        We are making an assumption that cleanup irps are sent only
        at passive-level.

    Return Value:

    NTSTATUS

--*/
{
    FxIoQueue* queue = NULL;
    PFX_DRIVER_GLOBALS pFxDriverGlobals = GetDriverGlobals();
    FxIoQueueNode flushBookmark(FxIoQueueNodeTypeBookmark);
    KIRQL irql;

    if(Mx::MxGetCurrentIrql() != PASSIVE_LEVEL) {

        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIO,
                            "Currently framework allow flushing of queues "
                            "by fileobject on cleanup only at PASSIVE_LEVEL");

        FxVerifierDbgBreakPoint(pFxDriverGlobals);
        return STATUS_SUCCESS;
    }

    //
    // Iterate through the queue list and flush each one.
    //
    Lock(&irql);
    queue = GetFirstIoQueueLocked(&flushBookmark, IO_ITERATOR_FLUSH_TAG);
    Unlock(irql);

    while(queue != NULL) {

        queue->FlushByFileObject(FileObject);

        queue->RELEASE(IO_ITERATOR_FLUSH_TAG);

        Lock(&irql);
        queue = GetNextIoQueueLocked(&flushBookmark, IO_ITERATOR_FLUSH_TAG);
        Unlock(irql);
    }

    return STATUS_SUCCESS;
}
コード例 #20
0
VOID
WDFEXPORT(WdfCollectionRemove)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFCOLLECTION Collection,
    __in
    WDFOBJECT Item
    )
{
    DDI_ENTRY();

    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    FxCollection *pCollection;
    FxCollectionEntry *pEntry;
    FxObject* pObject;
    NTSTATUS status;
    KIRQL irql;

    FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
                                   Collection,
                                   FX_TYPE_COLLECTION,
                                   (PVOID*) &pCollection,
                                   &pFxDriverGlobals);

    FxObjectHandleGetPtr(pFxDriverGlobals,
                         Item,
                         FX_TYPE_OBJECT,
                         (PVOID*) &pObject);

    pCollection->Lock(&irql);

    pEntry = pCollection->FindEntryByObject(pObject);

    if (pEntry != NULL) {
        pCollection->CleanupEntry(pEntry);
        status = STATUS_SUCCESS;
    }
    else {
        pObject = NULL;
        status = STATUS_NOT_FOUND;
    }

    pCollection->Unlock(irql);

    if (pObject != NULL) {
        pCollection->CleanupEntryObject(pObject);
    }

    if (!NT_SUCCESS(status)) {
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR,
                            "WDFOBJECT %p not in WDFCOLLECTION %p, %!STATUS!",
                            Item, Collection, status);
        FxVerifierDbgBreakPoint(pFxDriverGlobals);
    }
}
コード例 #21
0
NTSTATUS
WDFEXPORT(WdfWmiProviderCreate)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFDEVICE Device,
    __in
    PWDF_WMI_PROVIDER_CONFIG WmiProviderConfig,
    __in_opt
    PWDF_OBJECT_ATTRIBUTES ProviderAttributes,
    __out
    WDFWMIPROVIDER* WmiProvider
    )
{
    FxDevice* pDevice;
    FxPowerPolicyOwnerSettings* ownerSettings;
    FxWmiProvider* pProvider;

    FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals),
                         Device,
                         FX_TYPE_DEVICE,
                         (PVOID*) &pDevice);

    FxPointerNotNull(GetFxDriverGlobals(DriverGlobals), WmiProviderConfig);
    FxPointerNotNull(GetFxDriverGlobals(DriverGlobals), WmiProvider);

    //
    // If the Device is a power policy owner then do not allow client drivers
    // to register for GUID_POWER_DEVICE_ENABLE or GUID_POWER_DEVICE_WAKE_ENABLE
    // if the framework has already register a provider for those guids.
    //
    if (pDevice->m_PkgPnp->IsPowerPolicyOwner()) {
        ownerSettings = pDevice->m_PkgPnp->m_PowerPolicyMachine.m_Owner;

        if ((FxIsEqualGuid(&WmiProviderConfig->Guid,
                           &GUID_POWER_DEVICE_ENABLE) &&
             ownerSettings->m_IdleSettings.WmiInstance != NULL) ||

            (FxIsEqualGuid(&WmiProviderConfig->Guid,
                           &GUID_POWER_DEVICE_WAKE_ENABLE) &&
             ownerSettings->m_WakeSettings.WmiInstance != NULL)) {

            DoTraceLevelMessage(GetFxDriverGlobals(DriverGlobals), TRACE_LEVEL_ERROR,
                                TRACINGDEVICE, "WMI Guid already registered by "
                                "framework");
            return STATUS_WMI_GUID_DISCONNECTED;
        }
    }

    return FxWmiProvider::_Create(GetFxDriverGlobals(DriverGlobals),
                                  Device,
                                  ProviderAttributes,
                                  WmiProviderConfig,
                                  WmiProvider,
                                  &pProvider);
}
コード例 #22
0
_Must_inspect_result_
NTSTATUS
FxPkgFdo::_PnpQueryPnpDeviceState(
    __inout FxPkgPnp* This,
    __inout FxIrp *Irp
    )

/*++

Routine Description:

    This method is invoked in response to a Pnp QueryPnpDeviceState IRP.

Arguments:

    Irp - a pointer to the FxIrp

Returns:

    NTSTATUS

--*/

{
    FxPkgFdo* pThis;
    NTSTATUS status;

    pThis = (FxPkgFdo*) This;

    status = pThis->SendIrpSynchronously(Irp);

    if (status == STATUS_NOT_SUPPORTED) {
        //
        // Morph into a successful code so that we process the request
        //
        status = STATUS_SUCCESS;
        Irp->SetStatus(status);
    }

    if (NT_SUCCESS(status)) {
        pThis->HandleQueryPnpDeviceStateCompletion(Irp);
    }
    else {
        DoTraceLevelMessage(
            This->GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGPNP,
            "Lower stack returned error for query pnp device state, %!STATUS!",
            status);
    }

    //
    // Since we already sent the request down the stack, we must complete it 
    // now.
    //
    return pThis->CompletePnpRequest(Irp, status);
}
コード例 #23
0
__checkReturn
NTSTATUS
FxWaitLock::_Create(
    __in PFX_DRIVER_GLOBALS         FxDriverGlobals,
    __in_opt PWDF_OBJECT_ATTRIBUTES Attributes,
    __in_opt FxObject*              ParentObject,
    __in BOOLEAN                    AssignDriverAsDefaultParent,
    __out WDFWAITLOCK*              LockHandle
    )
{
    FxWaitLock*     lock;
    NTSTATUS        status;

    *LockHandle = NULL;
    
    lock = new (FxDriverGlobals, Attributes) FxWaitLock(FxDriverGlobals);
    if (lock == NULL) {
        status = STATUS_INSUFFICIENT_RESOURCES;
        DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIO,
                            "Memory allocation failed: %!STATUS!", status);
        return status;
    }

    status = lock->Initialize();
    if (!NT_SUCCESS(status)) {
        lock->DeleteFromFailedCreate();
        DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIO,
                            "faield to initialize wait lock: %!STATUS!", status);
        return status;
    }    

    status = lock->Commit(Attributes, 
                          (WDFOBJECT*)LockHandle, 
                          ParentObject,
                          AssignDriverAsDefaultParent);
    
    if (!NT_SUCCESS(status)) {
        lock->DeleteFromFailedCreate();
    }

    return status;
}
コード例 #24
0
VOID
FxPkgPnp::RemoveDmaEnabler(
    __in FxDmaEnabler* Enabler
    )
{
    DoTraceLevelMessage(GetDriverGlobals(), TRACE_LEVEL_VERBOSE, TRACINGPNP,
                        "Removing DmaEnabler %p, WDFDMAENABLER %p",
                        Enabler, Enabler->GetObjectHandle());

    m_DmaEnablerList->Remove(GetDriverGlobals(), &Enabler->m_TransactionLink);
}
コード例 #25
0
ファイル: fxpkgio.cpp プロジェクト: AntejaVM/WDF
_Must_inspect_result_
NTSTATUS
FxPkgIo::InitializeDefaultQueue(
    __in    CfxDevice               * Device,
    __inout FxIoQueue               * Queue
)

/*++

    Routine Description:

    Make the input queue as the default queue. There can be
    only one queue as the default queue.

    The default queue is the place all requests go to
    automatically if a specific queue was not configured
    for them.

Arguments:


Return Value:

    NTSTATUS

--*/
{
    PFX_DRIVER_GLOBALS FxDriverGlobals = GetDriverGlobals();
    ULONG index;

    if (m_DefaultQueue != NULL) {
        DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIO,
                            "Default Queue Already Configured for "
                            "FxPkgIo 0x%p, WDFDEVICE 0x%p %!STATUS!",this,
                            Device->GetHandle(), STATUS_UNSUCCESSFUL);
        return STATUS_UNSUCCESSFUL;
    }

    for (index=0; index <= IRP_MJ_MAXIMUM_FUNCTION; index++) {
        if (m_DispatchTable[index] == NULL) {
            m_DispatchTable[index] = Queue;
        }
    }

    m_DefaultQueue = Queue;

    //
    // Default queue can't be deleted. So mark the object to fail WdfObjectDelete on
    // the default queue.
    //
    Queue->MarkNoDeleteDDI();
    return STATUS_SUCCESS;
}
コード例 #26
0
ファイル: fxusbdeviceum.cpp プロジェクト: AntejaVM/WDF
_Must_inspect_result_
NTSTATUS
FxUsbDevice::SendSyncUmUrb(
    __inout PUMURB Urb,
    __in ULONGLONG Time,
    __in_opt WDFREQUEST Request,
    __in_opt PWDF_REQUEST_SEND_OPTIONS Options
    )
{
    NTSTATUS status;
    WDF_REQUEST_SEND_OPTIONS options;
    FxSyncRequest request(GetDriverGlobals(), NULL, Request);

    status = request.Initialize();
    if (!NT_SUCCESS(status)) {
        DoTraceLevelMessage(GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIOTARGET,
                            "Failed to initialize FxSyncRequest");
        return status;
    }

    if (NULL == Options) {
        Options = &options;
    }
    
    WDF_REQUEST_SEND_OPTIONS_INIT(Options, 0);
    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(Options, WDF_REL_TIMEOUT_IN_SEC(Time));
    
    status = request.m_TrueRequest->ValidateTarget(this);
    if (NT_SUCCESS(status)) {
        FxUsbUmFormatRequest(request.m_TrueRequest, &Urb->UmUrbHeader, m_pHostTargetFile);
        status = SubmitSync(request.m_TrueRequest, Options);
        if (!NT_SUCCESS(status)) {
            DoTraceLevelMessage(GetDriverGlobals(), TRACE_LEVEL_ERROR, TRACINGIOTARGET,
                                "FxUsbDevice SubmitSync failed");
            return status;
        }
    }

    return status;
}
コード例 #27
0
NTSTATUS
WDFAPI
WDFEXPORT(WdfUsbTargetPipeFormatRequestForReset)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFUSBPIPE Pipe,
    __in
    WDFREQUEST Request
    )
{
    DDI_ENTRY();

    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    FxRequest* pRequest;
    FxUsbPipe* pUsbPipe;
    NTSTATUS status;

    FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
                                   Pipe,
                                   FX_TYPE_IO_TARGET_USB_PIPE,
                                   (PVOID*) &pUsbPipe,
                                   &pFxDriverGlobals);

    DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
                        "Pipe %p, Request %p", Pipe, Request);

    FxObjectHandleGetPtr(pFxDriverGlobals,
                         Request,
                         FX_TYPE_REQUEST,
                         (PVOID*) &pRequest);

    status = pUsbPipe->FormatResetRequest(pRequest);

    DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGIOTARGET,
                        "Pipe %p, Request %p = 0x%x",
                        Pipe, Request, status);

    return status;
}
コード例 #28
0
VOID
FxDriver::Unload(
    __in MdDriverObject DriverObject
    )
{
    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    FxDriver *pDriver;

    pDriver = FxDriver::GetFxDriver(DriverObject);
    if (pDriver == NULL) {
        return;
    }
    
    pFxDriverGlobals = pDriver->GetDriverGlobals();

    DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGDRIVER,
                        "Unloading WDFDRIVER %p, PDRIVER_OBJECT_UM %p",
                        pDriver->GetHandle(), DriverObject);
    //
    // Invoke the driver if they specified an unload routine.
    //
    if (pDriver->m_DriverUnload.Method) {
        pDriver->m_DriverUnload.Invoke(pDriver->GetHandle());
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGDRIVER,
                            "Driver unload routine Exit WDFDRIVER %p, PDRIVER_OBJECT_UM %p",
                            pDriver->GetHandle(), DriverObject);
    }

    //
    // Delete the FxDriver object.
    //
    // This releases the FxDriver reference.  Must be called at PASSIVE
    //
    pDriver->DeleteObject();

    pFxDriverGlobals->Driver = NULL;

    FxDestroy(pFxDriverGlobals);
}
コード例 #29
0
ファイル: fxdeviceapikm.cpp プロジェクト: AntejaVM/WDF
NTSTATUS
WDFEXPORT(WdfDeviceWdmDispatchPreprocessedIrp)(
    __in
    PWDF_DRIVER_GLOBALS DriverGlobals,
    __in
    WDFDEVICE Device,
    __in
    MdIrp Irp
    )
{
    FxDevice            *device;
    PFX_DRIVER_GLOBALS  fxDriverGlobals;

    FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
                                   Device,
                                   FX_TYPE_DEVICE,
                                   (PVOID*) &device,
                                   &fxDriverGlobals);

    FxPointerNotNull(fxDriverGlobals, Irp);
    
    //
    // Verifier checks. 
    // This API can only be called by the client driver, Cx must call 
    // WdfDeviceWdmDispatchIrp from its preprocess callback.
    // Also, Cx must register for a Preprocessor routine using 
    // WdfCxDeviceInitAssignWdmIrpPreprocessCallback.
    //
    if (fxDriverGlobals->IsVerificationEnabled(1, 11, OkForDownLevel)) {
        if (device->IsCxInIoPath()) {
            FxDriver* driver = GetFxDriverGlobals(DriverGlobals)->Driver;
            
            if (IsListEmpty(&device->m_PreprocessInfoListHead) ||
                device->IsCxDriverInIoPath(driver)) {

                DoTraceLevelMessage(
                        fxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGIO,
                        "This API can only be called by client driver from its "
                        "pre-process IRP callback, STATUS_INVALID_DEVICE_REQUEST");
                FxVerifierDbgBreakPoint(fxDriverGlobals);
            }
        }
    }

    //
    // OK, ready to dispatch IRP.
    //
    return device->DispatchPreprocessedIrp(
                        Irp, 
                        device->m_PreprocessInfoListHead.Flink->Flink);
}
コード例 #30
0
ファイル: kmdf_vdev_pnp.c プロジェクト: 340211173/Driver
NTSTATUS
kmdf1394_EvtDeviceD0Entry (
                       IN  WDFDEVICE Device,
                       IN  WDF_POWER_DEVICE_STATE PreviousState)
/*++

Routine Description:

   EvtDeviceD0Entry event callback must perform any operations that are
   necessary before the specified device is used.  It will be called every
   time the hardware needs to be (re-)initialized.  This includes after
   IRP_MN_START_DEVICE, IRP_MN_CANCEL_STOP_DEVICE, IRP_MN_CANCEL_REMOVE_DEVICE,
   IRP_MN_SET_POWER-D0.

   This function runs at PASSIVE_LEVEL, though it is generally not paged.  A
   driver can optionally make this function pageable if DO_POWER_PAGABLE is set.

   Even if DO_POWER_PAGABLE isn't set, this function still runs at
   PASSIVE_LEVEL.  In this case, though, the function absolutely must not do
   anything that will cause a page fault.

Arguments:

    Device - Handle to a framework device object.

    PreviousState - Device power state which the device was in most recently.
        If the device is being newly started, this will be
        PowerDeviceUnspecified.

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS   ntStatus = STATUS_SUCCESS;

    UNREFERENCED_PARAMETER(PreviousState);

    Enter();
    DoTraceLevelMessage(TRACE_LEVEL_INFORMATION, 
                        TRACE_FLAG_PNP,
                        "-->kmdf1394_EvtDeviceD0Entry - coming from %s\n",
                        DbgDevicePowerString(PreviousState));

    ntStatus = kmdf1394_UpdateGenerationCount (Device);

    Exit();

    return ntStatus;
}