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

📄 pnp.c

📁 winddk src目录下的WDM源码压缩!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*++

Copyright (c) 1998  Microsoft Corporation

Module Name: 

    pnp.c

Abstract


Author:

    Peter Binder (pbinder) 4/13/98

Revision History:
Date     Who       What
-------- --------- ------------------------------------------------------------
4/13/98  pbinder   taken from 1394diag/ohcidiag
--*/

#define INITGUID
#include "pch.h"

NTSTATUS
t1394VDev_PnpAddDevice(
    IN PDRIVER_OBJECT   DriverObject,
    IN PDEVICE_OBJECT   PhysicalDeviceObject
    )
{
    NTSTATUS                ntStatus = STATUS_SUCCESS;
    PDEVICE_OBJECT          DeviceObject;
    PDEVICE_EXTENSION       deviceExtension;
    GUID                    t1394VDevGUID;
    POWER_STATE             state;
    PNODE_DEVICE_EXTENSION  pNodeExt;

    ENTER("t1394VDev_PnpAddDevice");

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

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

    ntStatus = IoCreateDevice( DriverObject,
                               sizeof(DEVICE_EXTENSION),
                               NULL,
                               FILE_DEVICE_UNKNOWN,
                               0,
                               FALSE,
                               &DeviceObject
                               );

    if (!NT_SUCCESS(ntStatus))
	{
        TRACE(TL_ERROR, ("IoCreateDevice Failed!\n"));
        goto Exit_PnpAddDevice;
    } // if

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

    deviceExtension = DeviceObject->DeviceExtension;
    RtlZeroMemory(deviceExtension, sizeof(DEVICE_EXTENSION));

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

    t1394VDevGUID = GUID_1394VDEV;

    ntStatus = IoRegisterDeviceInterface( PhysicalDeviceObject,
                                          &t1394VDevGUID,
                                          NULL,
                                          &deviceExtension->SymbolicLinkName
                                          );

    if (!NT_SUCCESS(ntStatus))
	{
        TRACE(TL_ERROR, ("IoRegisterDeviceInterface Failed!\n"));
        IoDeleteDevice(DeviceObject);
        ntStatus = STATUS_NO_SUCH_DEVICE;
        goto Exit_PnpAddDevice;
    }

    deviceExtension->StackDeviceObject =
        IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);

    if (!deviceExtension->StackDeviceObject)
	{
        TRACE(TL_ERROR, ("IoAttachDeviceToDeviceStack Failed!\n"));
        IoDeleteDevice(DeviceObject);
        RtlFreeUnicodeString(&deviceExtension->SymbolicLinkName);
        ntStatus = STATUS_NO_SUCH_DEVICE;
        goto Exit_PnpAddDevice;
    } // if
    
    TRACE(TL_TRACE, ("StackDeviceObject = 0x%x\n", deviceExtension->StackDeviceObject));

    // save the device object we created as our physical device object
    deviceExtension->PhysicalDeviceObject = DeviceObject;
    TRACE(TL_TRACE, ("PhysicalDeviceObject = 0x%x\n", deviceExtension->PhysicalDeviceObject));

    // get the port device object from the passed in PhysicalDeviceObject created by the 1394 stack for us
	// Note: we can't use the top of the stack and get its device extension in case there is a filter driver
	// between us and our PDO
    pNodeExt = PhysicalDeviceObject->DeviceExtension;
    deviceExtension->PortDeviceObject = pNodeExt->PortDeviceObject;

    // initialize power states
    deviceExtension->CurrentDevicePowerState    = PowerDeviceD0;
    deviceExtension->CurrentSystemPowerState    = PowerSystemWorking;

    state.DeviceState = deviceExtension->CurrentDevicePowerState;
    PoSetPowerState(DeviceObject, DevicePowerState, state);

    TRACE(TL_TRACE, ("PortDeviceObject = 0x%x\n", deviceExtension->PortDeviceObject));

    // initialize the spinlock/list to store the bus reset irps...
    KeInitializeSpinLock(&deviceExtension->ResetSpinLock);
    KeInitializeSpinLock(&deviceExtension->CromSpinLock);
    KeInitializeSpinLock(&deviceExtension->AsyncSpinLock);
    KeInitializeSpinLock(&deviceExtension->IsochSpinLock);
    KeInitializeSpinLock(&deviceExtension->IsochResourceSpinLock);
    InitializeListHead(&deviceExtension->BusResetIrps);
    InitializeListHead(&deviceExtension->CromData);
    InitializeListHead(&deviceExtension->AsyncAddressData);
    InitializeListHead(&deviceExtension->IsochDetachData);
    InitializeListHead(&deviceExtension->IsochResourceData);

    DeviceObject->Flags |= DO_POWER_PAGABLE;
    DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

Exit_PnpAddDevice:

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

NTSTATUS
t1394VDev_Pnp(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp
    )
{
    NTSTATUS                ntStatus = STATUS_SUCCESS;
    PIO_STACK_LOCATION      IrpSp;
    PDEVICE_EXTENSION       deviceExtension = DeviceObject->DeviceExtension;

    PDEVICE_CAPABILITIES    DeviceCapabilities;

    ENTER("t1394VDev_Pnp");
    
    TRACE(TL_TRACE, ("DeviceObject = 0x%x\n", DeviceObject));
    TRACE(TL_TRACE, ("Irp = 0x%x\n", Irp));

    IrpSp = IoGetCurrentIrpStackLocation(Irp);

    switch (IrpSp->MinorFunction) {

        case IRP_MN_START_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_START_DEVICE\n"));

            // pass down to layer below us first.
            ntStatus = t1394_SubmitIrpSynch(deviceExtension->StackDeviceObject, Irp, NULL);

            if (!NT_SUCCESS(ntStatus)) {

                TRACE(TL_ERROR, ("Error submitting Irp!\n"))
            }
            else {
            
                ntStatus = t1394VDev_PnpStartDevice(DeviceObject, Irp);
            }
            
            Irp->IoStatus.Status = ntStatus;
            IoCompleteRequest(Irp, IO_NO_INCREMENT);
            break;

        case IRP_MN_QUERY_STOP_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_QUERY_STOP_DEVICE\n"));

            // pass down to layer below us...
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        case IRP_MN_STOP_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_STOP_DEVICE\n"));

            ntStatus = t1394VDev_PnpStopDevice(DeviceObject, Irp);

            // i'm not allowed to fail here. if i needed to fail, i should have done it
            // at the query_stop_device request.
            Irp->IoStatus.Status = STATUS_SUCCESS;

            // pass down to layer below us...
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        case IRP_MN_CANCEL_STOP_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_CANCEL_STOP_DEVICE\n"));

            // pass down to layer below us first.
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        case IRP_MN_QUERY_REMOVE_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_QUERY_REMOVE_DEVICE\n"));

            Irp->IoStatus.Status = STATUS_SUCCESS;

            // pass down to layer below us...
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        case IRP_MN_SURPRISE_REMOVAL:

            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_SURPRISE_REMOVAL\n"));
             
            // pass the request down
            Irp->IoStatus.Status = STATUS_SUCCESS;
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        case IRP_MN_REMOVE_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_REMOVE_DEVICE\n"));

            ntStatus = t1394VDev_PnpRemoveDevice(DeviceObject, Irp);
            
            // pass down to layer below us...
            Irp->IoStatus.Status = STATUS_SUCCESS;
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            
            // delete our device, we have to do this after we send the request down
            IoDetachDevice(deviceExtension->StackDeviceObject);
            IoDeleteDevice(DeviceObject);                                          
            break;

        case IRP_MN_CANCEL_REMOVE_DEVICE:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_CANCEL_REMOVE_DEVICE\n"));

            // pass down to layer below us first.
            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        case IRP_MN_QUERY_CAPABILITIES:
            TRACE(TL_TRACE, ("t1394VDev_Pnp: IRP_MN_QUERY_CAPABILITIES\n"));

            DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
            DeviceCapabilities->SurpriseRemovalOK = TRUE;

            ntStatus = t1394_SubmitIrpAsync(deviceExtension->StackDeviceObject, Irp, NULL);
            break;

        default:
            TRACE(TL_TRACE, ("Unsupported Pnp Function = 0x%x\n", IrpSp->MinorFunction));

            // pass down to layer below us...
            ntStatus = t1394_SubmitIrpAsync (deviceExtension->StackDeviceObject, Irp, NULL);
            break;

    } // switch

    EXIT("t1394VDev_Pnp", ntStatus);
    return(ntStatus);
} // t1394Vdev_Pnp

NTSTATUS
t1394VDev_PnpStartDevice(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp
    )

⌨️ 快捷键说明

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