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

📄 tmpnp.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:

tmmanPnpStartDeviceExit1:
	return Status;
}

NTSTATUS
tmmanPnpStopDevice(
	PDEVICE_OBJECT FunctionalDeviceObject )
{
	TMManDeviceObject*	TMManDevice = 
		(TMManDeviceObject*)FunctionalDeviceObject->DeviceExtension;

	tmmanExit ( TMManDevice->DSPNumber );	

	TMManGlobal->DeviceList[TMManDevice->DSPNumber] = NULL;

	TMManGlobal->DeviceCount--;

}


NTSTATUS tmmanPnpComplete (
	PDEVICE_OBJECT DeviceObject,
	PIRP Irp,
	PVOID Context  )
{
    PIO_STACK_LOCATION  IoStack;
    PKEVENT Event = (PKEVENT) Context;
    NTSTATUS status = STATUS_SUCCESS;

    UNREFERENCED_PARAMETER (DeviceObject);

    IoStack = IoGetCurrentIrpStackLocation (Irp);

    if (Irp->PendingReturned) 
	{
        IoMarkIrpPending( Irp );
    }

    switch (IoStack->MajorFunction) 
	{

        case IRP_MJ_PNP:
		KeSetEvent(Event, 0, FALSE);

		//
		// Take the IRP back so that we can continue using it during
		// the IRP_MN_START_DEVICE dispatch routine.
		// NB: we will have to call IoCompleteRequest
		//
		return STATUS_MORE_PROCESSING_REQUIRED;

		break;
    }

    return status;
}


char * tmmanPnpDumpMinorCode ( ULONG MinorFunction )
{
	switch ( MinorFunction )
	{
		case IRP_MN_START_DEVICE	: return "IRP_MN_START_DEVICE";
		case IRP_MN_QUERY_REMOVE_DEVICE : return "IRP_MN_QUERY_REMOVE_DEVICE";
		case IRP_MN_REMOVE_DEVICE : return "IRP_MN_REMOVE_DEVICE";
		case IRP_MN_CANCEL_REMOVE_DEVICE : return "IRP_MN_CANCEL_REMOVE_DEVICE";
		case IRP_MN_STOP_DEVICE : return "IRP_MN_STOP_DEVICE";
		case IRP_MN_QUERY_STOP_DEVICE : return "IRP_MN_QUERY_STOP_DEVICE";
		case IRP_MN_CANCEL_STOP_DEVICE : return "IRP_MN_CANCEL_STOP_DEVICE";

		case IRP_MN_QUERY_DEVICE_RELATIONS : return "IRP_MN_QUERY_DEVICE_RELATIONS";
		case IRP_MN_QUERY_INTERFACE  : return "IRP_MN_QUERY_INTERFACE";
		case IRP_MN_QUERY_CAPABILITIES : return "IRP_MN_QUERY_CAPABILITIES";
		case IRP_MN_QUERY_RESOURCES : return "IRP_MN_QUERY_RESOURCES";
		case IRP_MN_QUERY_RESOURCE_REQUIREMENTS : return "IRP_MN_QUERY_RESOURCE_REQUIREMENTS";
		case IRP_MN_QUERY_DEVICE_TEXT : return "IRP_MN_QUERY_DEVICE_TEXT";
		case IRP_MN_FILTER_RESOURCE_REQUIREMENTS : return "IRP_MN_FILTER_RESOURCE_REQUIREMENTS";
		case 0x0e : return "IRP_MN_FUNCTION_0x0e";

		case IRP_MN_READ_CONFIG : return "IRP_MN_READ_CONFIG";
		case IRP_MN_WRITE_CONFIG : return "IRP_MN_WRITE_CONFIG";
		case IRP_MN_EJECT : return "IRP_MN_EJECT";
		case IRP_MN_SET_LOCK : return "IRP_MN_SET_LOCK";
		case IRP_MN_QUERY_ID : return "IRP_MN_QUERY_ID";
		case IRP_MN_QUERY_PNP_DEVICE_STATE : return "IRP_MN_QUERY_PNP_DEVICE_STATE";
		case IRP_MN_QUERY_BUS_INFORMATION :  return "IRP_MN_QUERY_BUS_INFORMATION";
		case IRP_MN_DEVICE_USAGE_NOTIFICATION : return "IRP_MN_DEVICE_USAGE_NOTIFICATION";
		case IRP_MN_SURPRISE_REMOVAL : return "IRP_MN_SURPRISE_REMOVAL";
		//case IRP_MN_QUERY_LEGACY_BUS_INFORMATION : return "IRP_MN_QUERY_LEGACY_BUS_INFORMATION";

		default :  return "UNKNOWN";
	}
}

char * tmmanPnpDumpState ( ULONG State )
{
	switch ( State )
	{
		case	constTMMan_DEVICE_STATE_NEVERSTARTED : return "DEVICE_STATE_NEVERSTARTED";
		case	constTMMan_DEVICE_STATE_STARTED : return "DEVICE_STATE_STARTED";
		case	constTMMan_DEVICE_STATE_REMOVEPENDING : return "DEVICE_STATE_REMOVEPENDING";
		case	constTMMan_DEVICE_STATE_REMOVED : return "DEVICE_STATE_REMOVED";
		case	constTMMan_DEVICE_STATE_STOPPENDING : return "DEVICE_STATE_STOPPENDING";
		case	constTMMan_DEVICE_STATE_STOPPED : return "DEVICE_STATE_STOPPED";
		case	constTMMan_DEVICE_STATE_SURPRISEREMOVED : return "DEVICE_STATE_SURPRISEREMOVED";

		default :  return "UNKNOWN";
	}
}

BOOLEAN	tmmanDeviceProperty ( PDEVICE_OBJECT FunctionalDeviceObject )
{
	ULONG				BufferLength;
	PVOID				BufferAddress;

	// IoGetDeviceProperty BEGIN

	//DevicePropertyLocationInformation

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyLocationInformation,
		0,
		NULL,
		&BufferLength );

	if ( ( BufferAddress = ExAllocatePool ( PagedPool, BufferLength ) ) == NULL )
	{	
		return FALSE;
	}

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyLocationInformation,
		BufferLength,
		BufferAddress,
		&BufferLength );

	DPF (0,("DevicePropertyLocationInformation:BufferLength[0x%x]:Data[0x%x]\n", 
		BufferLength, *(PULONG)BufferAddress ));
			
	ExFreePool ( BufferAddress );

	//DevicePropertyClassName

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyClassName,
		0,
		NULL,
		&BufferLength );

	if ( ( BufferAddress = ExAllocatePool ( PagedPool, BufferLength ) ) == NULL )
	{	
		return FALSE;
	}

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyClassName,
		BufferLength,
		BufferAddress,
		&BufferLength );


	DPF (0,("DevicePropertyClassName:BufferLength[0x%x]:Data[%ws]\n", 
		BufferLength, (PWCHAR)BufferAddress ));	

	ExFreePool ( BufferAddress );

	//DevicePropertyDeviceDescription 

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyDeviceDescription,
		0,
		NULL,
		&BufferLength );

	if ( ( BufferAddress = ExAllocatePool ( PagedPool, BufferLength ) ) == NULL )
	{	
		return FALSE;
	}

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyDeviceDescription,
		BufferLength,
		BufferAddress,
		&BufferLength );


	DPF (0,("DevicePropertyDeviceDescription:BufferLength[0x%x]:Data[%ws]\n", 
		BufferLength, (PWCHAR)BufferAddress ));	

	ExFreePool ( BufferAddress );

	//DevicePropertyManufacturer 


	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyManufacturer,
		0,
		NULL,
		&BufferLength );

	if ( ( BufferAddress = ExAllocatePool ( PagedPool, BufferLength ) ) == NULL )
	{	
		return FALSE;
	}

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyManufacturer,
		BufferLength,
		BufferAddress,
		&BufferLength );


	DPF (0,("DevicePropertyManufacturer:BufferLength[0x%x]:Data[%ws]\n", 
		BufferLength, (PWCHAR)BufferAddress ));	

	ExFreePool ( BufferAddress );

	// DevicePropertyPhysicalDeviceObjectName 

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyManufacturer,
		0,
		NULL,
		&BufferLength );

	if ( ( BufferAddress = ExAllocatePool ( PagedPool, BufferLength ) ) == NULL )
	{	
		return FALSE;
	}

	IoGetDeviceProperty ( FunctionalDeviceObject,
		DevicePropertyManufacturer,
		BufferLength,
		BufferAddress,
		&BufferLength );


	DPF (0,("DevicePropertyManufacturer:BufferLength[0x%x]:Data[%ws]\n", 
		BufferLength, (PWCHAR)BufferAddress ));	

	ExFreePool ( BufferAddress );

	// IoGetDeviceProperty END
}



BOOLEAN	pnpGetPCIInformation ( 
	IN USHORT Vendor, 
	IN USHORT Device,
	IN ULONG  ReferenceAddress,
	OUT	PULONG	BusNumberPtr,
	PPCI_SLOT_NUMBER SlotNumberPtr )
{
    ULONG				n;
    BOOLEAN				fNotDone;
    PCI_COMMON_CONFIG	PciData;
    NTSTATUS			Status = STATUS_UNSUCCESSFUL;
    ULONG				i = 0, j = 0, Idx;
    ULONG				ulTmp;
	ULONG				BusNumber = 0;
	PCI_SLOT_NUMBER		SlotNumber;

	BusNumber = 0;
	SlotNumber.u.bits.DeviceNumber = 0;
	SlotNumber.u.bits.FunctionNumber = 0;
	SlotNumber.u.bits.Reserved = 0;


    for (BusNumber = 0, fNotDone = TRUE; fNotDone ; BusNumber++) 
	{
        for ( i = 0 ; i < PCI_MAX_DEVICES  &&  fNotDone ; i++ ) 
		{
            for ( j = 0 ; j < PCI_MAX_FUNCTION ; j++) 
			{
				SlotNumber.u.bits.DeviceNumber = i;
				SlotNumber.u.bits.FunctionNumber = j;

                n = HalGetBusData (
                    PCIConfiguration,
                    BusNumber,
                    SlotNumber.u.AsULONG,
                    &PciData,
                    PCI_COMMON_HDR_LENGTH
                    );
				/*
				DPF (0, 
					("pnpFindPCIDevices:[Bus:%x][Dev:%x][Func:%x][Vendor:%x][Device:%x]\n",
					BusNumber, i, j, PciData.VendorID, PciData.DeviceID ));
				*/

                if (n == 0) 
				{
                    // out of buses
                    fNotDone = FALSE;
                    break;
                }

                if (PciData.VendorID == PCI_INVALID_VENDORID) 
				{
                    // Nothing in this slot, skip to next slot
                    break;
                }

                if ( ( PciData.VendorID == Vendor ) &&  
					( PciData.DeviceID == Device ) && 
					( PciData.u.type0.BaseAddresses[0] == ReferenceAddress ) )   
				{
					*SlotNumberPtr = SlotNumber;
					*BusNumberPtr = BusNumber;
					return TRUE;
					// found device node
				}
			}
		}
	}
 	return FALSE;;
}

VOID	DumpPNPResources ( 
	PCM_RESOURCE_LIST	ResourceList )
{
	ULONG	i,j;
	DPF (0,("CM_RESOURCE_LIST:Count[%x]\n", ResourceList->Count ));

    for (i = 0; i < ResourceList->Count; i++) 
	{
        DPF (1,("CM_PARTIAL_RESOURCE_LIST:Version[%x]:Revision[%x]:Count[%x]\n",
            ResourceList->List[i].PartialResourceList.Version,
            ResourceList->List[i].PartialResourceList.Revision,
            ResourceList->List[i].PartialResourceList.Count));

        for (j = 0; j < ResourceList->List[i].PartialResourceList.Count; j++) 
		{
            DPF (1,("CM_PARTIAL_RESOURCE_DESCRIPTOR#[%x]:Type[%x]:ShareDisposition[%x]:Flags[%x]\n",
				j,
				ResourceList->List[i].PartialResourceList.PartialDescriptors[j].Type,
				ResourceList->List[i].PartialResourceList.PartialDescriptors[j].ShareDisposition,
				ResourceList->List[i].PartialResourceList.PartialDescriptors[j].Flags ));

            switch (ResourceList->List[i].PartialResourceList.PartialDescriptors[j].Type) 
			{
	            case CmResourceTypePort:
                DPF (1,("CmResourceTypePort:Start[%x]:Length[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Port.Start,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Port.Length));
                break;

		        case CmResourceTypeInterrupt:
                DPF (1,("CmResourceTypeInterrupt:Level[%x]:Vector[%x]:Affininty[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Level,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Vector,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Affinity));
                break;

			    case CmResourceTypeMemory:
                DPF (1,("CmResourceTypeMemory:Start[%x]:Length[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Memory.Start,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Memory.Length ));
                break;

				case CmResourceTypeDma:
                DPF (1,("CmResourceTypeDma:Channel[%x]:Port[%x]:Reserved1[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Dma.Channel,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Dma.Port,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.Dma.Reserved1 ));
                break;

				case CmResourceTypeDeviceSpecific:
                DPF (1,("CmResourceTypeDeviceSpecific:DataSize[%x]:Reserved1[%x]:Reserved2[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.DeviceSpecificData.DataSize,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.DeviceSpecificData.Reserved1,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.DeviceSpecificData.Reserved2 ));
                break;

				case CmResourceTypeBusNumber:
                DPF (1,("CmResourceTypeBusNumber:Start[%x]:Length[%x]:Reserved[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.BusNumber.Start,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.BusNumber.Length,
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.BusNumber.Reserved ));
				break;

				case CmResourceTypeDevicePrivate:
                DPF (1,("CmResourceTypeDevicePrivate:Data0[%x]:Data1[%x]:Data2[%x]\n",
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.DevicePrivate.Data[0],
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.DevicePrivate.Data[1],
                    ResourceList->List[i].PartialResourceList.PartialDescriptors[j].u.DevicePrivate.Data[2] ));
				break;

				default:
                DPF (0,("Unknown Reourcetype[0x%x]\n", 
					ResourceList->List[i].PartialResourceList.PartialDescriptors[j].Type ));
                break;
            } // end switch
        } // end for partial resource descriptors
    } // end for full resource descriptors	
}

⌨️ 快捷键说明

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