⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pnp.c

📁 winddk src目录下的WDM源码压缩!
💻 C
📖 第 1 页 / 共 2 页
字号:
{
    NTSTATUS                ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION       deviceExtension = DeviceObject->DeviceExtension;

    ENTER("t1394VDev_PnpStartDevice");

    deviceExtension->bShutdown = FALSE;

    ntStatus = t1394_BusResetNotification( DeviceObject,
                                               Irp,
                                               REGISTER_NOTIFICATION_ROUTINE
                                               );

    // update the generation count
    t1394_UpdateGenerationCount(DeviceObject, NULL);

    // activate the interface...
    ntStatus = IoSetDeviceInterfaceState(&deviceExtension->SymbolicLinkName, TRUE);

    if (!NT_SUCCESS(ntStatus)) {

        TRACE(TL_ERROR, ("Failed to activate interface!\n"));
    }

    EXIT("t1394VDev_PnpStartDevice", ntStatus);
    return(ntStatus);
} // t1394VDev_PnpStartDevice

NTSTATUS
t1394VDev_PnpStopDevice(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp
    )
{
    NTSTATUS            ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION   deviceExtension = DeviceObject->DeviceExtension;
    
    ENTER("t1394VDev_PnpStopDevice");

    deviceExtension->bShutdown = TRUE;

    ntStatus = t1394_BusResetNotification( DeviceObject,
                                               Irp,
                                               DEREGISTER_NOTIFICATION_ROUTINE
                                               );

    EXIT("t1394VDev_PnpStopDevice", ntStatus);
    return(ntStatus);
} // t1394VDev_PnpStopDevice

NTSTATUS
t1394VDev_PnpRemoveDevice(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp
    )
{
    NTSTATUS            ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION   deviceExtension = DeviceObject->DeviceExtension;
    KIRQL               Irql;

    ENTER("t1394VDev_PnpRemoveDevice");

    TRACE(TL_WARNING, ("Removing 1394VDEV.SYS.\n"));

    if (!deviceExtension->bShutdown) {

        // haven't stopped yet, lets do so
        ntStatus = t1394VDev_PnpStopDevice(DeviceObject, Irp);
    }

    // deactivate the interface...
    ntStatus = IoSetDeviceInterfaceState(&deviceExtension->SymbolicLinkName, FALSE);

    if (!NT_SUCCESS(ntStatus)) {

        TRACE(TL_ERROR, ("Failed to deactivate interface!\n"));
    }

    // lets free up any crom data structs we've allocated...
    KeAcquireSpinLock(&deviceExtension->CromSpinLock, &Irql);

    while (!IsListEmpty(&deviceExtension->CromData)) {

        PCROM_DATA      CromData;

        // get struct off list
        CromData = (PCROM_DATA) RemoveHeadList(&deviceExtension->CromData);

        // need to free up everything associated with this allocate...        
        if (CromData)
        {
            if (CromData->Buffer)
                ExFreePool(CromData->Buffer);
    
            if (CromData->pMdl)
                IoFreeMdl(CromData->pMdl);
    
            // we already checked CromData
            ExFreePool(CromData);
        }
    }

    KeReleaseSpinLock(&deviceExtension->CromSpinLock, Irql);

    // lets free up any allocated addresses and deallocate all
    // memory associated with them...
    KeAcquireSpinLock(&deviceExtension->AsyncSpinLock, &Irql);

    while (!IsListEmpty(&deviceExtension->AsyncAddressData)) {

        PASYNC_ADDRESS_DATA     AsyncAddressData;

        // get struct off list
        AsyncAddressData = (PASYNC_ADDRESS_DATA) RemoveHeadList(&deviceExtension->AsyncAddressData);

        // need to free up everything associated with this allocate...
        if (AsyncAddressData->pMdl)
            IoFreeMdl(AsyncAddressData->pMdl);

        if (AsyncAddressData->Buffer)
            ExFreePool(AsyncAddressData->Buffer);

        if (AsyncAddressData->AddressRange)
            ExFreePool(AsyncAddressData->AddressRange);

        if (AsyncAddressData)
            ExFreePool(AsyncAddressData);
    }

    KeReleaseSpinLock(&deviceExtension->AsyncSpinLock, Irql);

    // free up any attached isoch buffers
    while (TRUE) {

        KeAcquireSpinLock(&deviceExtension->IsochSpinLock, &Irql);

        if (!IsListEmpty(&deviceExtension->IsochDetachData)) {

            PISOCH_DETACH_DATA      IsochDetachData;
            ULONG                   i;

            IsochDetachData = (PISOCH_DETACH_DATA)RemoveHeadList(&deviceExtension->IsochDetachData);

            TRACE(TL_TRACE, ("Surprise Removal: IsochDetachData = 0x%x\n", IsochDetachData));

            KeCancelTimer(&IsochDetachData->Timer);
            KeReleaseSpinLock(&deviceExtension->IsochSpinLock, Irql);

            TRACE(TL_TRACE, ("Surprise Removal: IsochDetachData->Irp = 0x%x\n", IsochDetachData->Irp));

            // need to save the status of the attach
            // we'll clean up in the same spot for success's and timeout's
            IsochDetachData->AttachStatus = STATUS_SUCCESS;

            // detach no matter what...
            IsochDetachData->bDetach = TRUE;

            t1394_IsochCleanup(IsochDetachData);
        }
        else {

            KeReleaseSpinLock(&deviceExtension->IsochSpinLock, Irql);
            break;
        }
    }

    // remove any isoch resource data
    while (TRUE) {

        KeAcquireSpinLock(&deviceExtension->IsochResourceSpinLock, &Irql);

        if (!IsListEmpty(&deviceExtension->IsochResourceData)) {

            PISOCH_RESOURCE_DATA    IsochResourceData;

            IsochResourceData = (PISOCH_RESOURCE_DATA)RemoveHeadList(&deviceExtension->IsochResourceData);

            KeReleaseSpinLock(&deviceExtension->IsochResourceSpinLock, Irql);

            TRACE(TL_TRACE, ("Surprise Removal: IsochResourceData = 0x%x\n", IsochResourceData));

            if (IsochResourceData) {

                PIRB                pIrb;
                PIRP                ResourceIrp;
                CCHAR               StackSize;

                TRACE(TL_TRACE, ("Surprise Removal: Freeing hResource = 0x%x\n", IsochResourceData->hResource));

                StackSize = deviceExtension->StackDeviceObject->StackSize;
                ResourceIrp = IoAllocateIrp(StackSize, FALSE);

                if (ResourceIrp == NULL) {

                    TRACE(TL_ERROR, ("Failed to allocate ResourceIrp!\n"));
                }
                else {

                    pIrb = ExAllocatePool(NonPagedPool, sizeof(IRB));

                    if (!pIrb) {

                        IoFreeIrp(ResourceIrp);

                        TRACE(TL_ERROR, ("Failed to allocate pIrb!\n"));
                    }
                    else {

                        RtlZeroMemory (pIrb, sizeof (IRB));
                        pIrb->FunctionNumber = REQUEST_ISOCH_FREE_RESOURCES;
                        pIrb->Flags = 0;
                        pIrb->u.IsochFreeResources.hResource = IsochResourceData->hResource;

                        ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, ResourceIrp, pIrb);

                        if (!NT_SUCCESS(ntStatus)) {

                            TRACE(TL_ERROR, ("SubmitIrpSync failed = 0x%x\n", ntStatus));
                        }

                        ExFreePool(pIrb);
                        IoFreeIrp(ResourceIrp);
                    }
                }
            }
        }
        else {

            KeReleaseSpinLock(&deviceExtension->IsochResourceSpinLock, Irql);
            break;
        }
    }

    // get rid of any pending bus reset notify requests
    KeAcquireSpinLock(&deviceExtension->ResetSpinLock, &Irql);

    while (!IsListEmpty(&deviceExtension->BusResetIrps)) {

        PBUS_RESET_IRP  BusResetIrp;
        PDRIVER_CANCEL  prevCancel = NULL;

        // get the irp off of the list
        BusResetIrp = (PBUS_RESET_IRP)RemoveHeadList(&deviceExtension->BusResetIrps);

        TRACE(TL_TRACE, ("BusResetIrp = 0x%x\n", BusResetIrp));

        // make this irp non-cancelable...
        prevCancel = IoSetCancelRoutine(BusResetIrp->Irp, NULL);

        TRACE(TL_TRACE, ("Surprise Removal: BusResetIrp->Irp = 0x%x\n", BusResetIrp->Irp));

        // and complete it...
        BusResetIrp->Irp->IoStatus.Status = STATUS_SUCCESS;
        IoCompleteRequest(BusResetIrp->Irp, IO_NO_INCREMENT);

        ExFreePool(BusResetIrp);
    }

    KeReleaseSpinLock(&deviceExtension->ResetSpinLock, Irql);

    // free up the symbolic link
    RtlFreeUnicodeString(&deviceExtension->SymbolicLinkName);

    EXIT("t1394VDev_PnpRemoveDevice", ntStatus);
    return(ntStatus);
} // t1394VDev_PnpRemoveDevice

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -