阅读:1421回复:5
编写pci的WDM驱动应如何获得总线资源信息?
编写pci的WDM驱动应如何获得总线资源信息?
有的说用PCIReadConfig,但不知怎么用 也有的说可以用RetrieveResources,真不知该怎么办好! |
|
沙发#
发布于:2004-04-27 10:38
在即插即用的IRP_MN_START_DEVICE处理程序中可从IRP中获得。
|
|
|
板凳#
发布于:2004-04-27 10:46
您能否具体解释一下IRP_MN_START_DEVICE的用法,我看书看得不太明白。不知您那有没有例子程序可以参考?
谢谢 |
|
地板#
发布于:2004-04-27 11:34
点到为止,别的只能自己看书了。况且我不可能说的比书还好。
|
|
|
地下室#
发布于:2004-04-27 11:37
经典!
谢了 |
|
5楼#
发布于:2004-04-29 17:10
static NTSTATUS
PnpStartDevice( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { PIO_STACK_LOCATION IrpStack; PADAPTER Adapter = ( PADAPTER )DeviceObject->DeviceExtension; PCM_RESOURCE_LIST ResTranslated; NTSTATUS Status; IrpStack = IoGetCurrentIrpStackLocation(Irp); if( IrpStack->Parameters.StartDevice.AllocatedResourcesTranslated ) ResTranslated = IrpStack->Parameters.StartDevice.AllocatedResourcesTranslated; else ResTranslated = NULL; Status = StartDevice( Adapter, ResTranslated ); return CompleteIrp( Irp, Status, 0 ); } /************************************************************* * * 名称:AdapterQueryHardwareResource * 功能:获取硬件资源 * 参数:Adapter: 设备上下文 * pTranslatedResourceList: 经过转换后的硬件资源列表 * pUntranslatedResourceList: 原始的硬件资源列表 * 返回:成功返回TRUE, 失败返回FALSE * ***************************************************************/ BOOL AdapterQueryHardwareResource( IN PADAPTER Adapter, IN PCM_RESOURCE_LIST pTranslatedResourceList OPTIONAL, IN PCM_RESOURCE_LIST pUntranslatedResourceList OPTIONAL ) { PCM_PARTIAL_RESOURCE_LIST pPatiresource; // 硬件资源信息 PCM_PARTIAL_RESOURCE_LIST pPatiunresource;// 未知的硬件资源信息 ULONG Count; // 枚举到的资源个数资源 UINT i; // 循环变量 PCM_PARTIAL_RESOURCE_DESCRIPTOR pResDes; // 具体的资源描述信息 // 判断硬件资源列表的有效性 if( !pTranslatedResourceList || !pUntranslatedResourceList ) return FALSE; TRACE_IN( \"AdapterQueryHardwareResource\" ); // 获取指向资源信息的指针 pPatiresource = &( pTranslatedResourceList->List[0].PartialResourceList ); pPatiunresource = &( pUntranslatedResourceList->List[0].PartialResourceList ); // 获取硬件的原始资源 #if USE_INTERRUPT Adapter->IrqLevel = -1L; Adapter->IrqVector = -1L; #endif Count = pPatiresource->Count; for( i = 0; i < Count; i++ ) { pResDes = &pPatiresource->PartialDescriptors[ i ]; if( pResDes == NULL ) continue; switch( pResDes->Type ) { case CmResourceTypePort: // 端口信息 Adapter->RawPortBase = pResDes->u.Port.Start; Adapter->PortSpan = pResDes->u.Port.Length; Adapter->isNeedMapIO = !( pResDes->Flags & CM_RESOURCE_PORT_IO ); TRACE1( \"The Port flags is 0x%x\", pResDes->Flags ); break; #if USE_INTERRUPT case CmResourceTypeInterrupt: // 中断信息 Adapter->IrqVector = pResDes->u.Interrupt.Vector; Adapter->IrqLevel = pResDes->u.Interrupt.Level; Adapter->IrqType = pResDes->Flags; Adapter->IrqAffinity = pResDes->u.Interrupt.Affinity; Adapter->IrqShare = pResDes->ShareDisposition; break; #endif default: // 其它信息我们目前不需要 TRACE1( \"The resource tye( %d ) is not need\", pResDes->Type ); break; }//switch }// for i // 检查获得的资源是否有效 do { // 端口 if( Adapter->RawPortBase.QuadPart == 0 || Adapter->PortSpan == 0 ) { TRACE2( \"The IO Port( 0x%x, 0x%x ) is error\", Adapter->RawPortBase.QuadPart, Adapter->PortSpan ); break; } #if USE_INTERRUPT //中断 if( Adapter->IrqLevel == -1L || Adapter->IrqVector == -1L ) { TRACE2( \"The IRQL( 0x%x, 0x%x ) is error\", Adapter->IrqLevel, Adapter->IrqVector ); break; } #endif // 映射端口,如果需要的话( 在alpha系统 ) if( Adapter->isNeedMapIO ) { Adapter->PortBase = ( ULONG )MmMapIoSpace( Adapter->RawPortBase, // 基地址 Adapter->PortSpan, // 范围 MmNonCached ); // 类型 TRACE0( \"The IO port is mapped\" ); } else { // 已经被映射过了 Adapter->PortBase = (ULONG)Adapter->RawPortBase.QuadPart; } // 判断IO基地址的有效性 if( Adapter->PortBase == 0 ) { TRACE0( \"The PortBase is error\" ); break; } TRACE1( \"The I/O PortBase is 0x%x\", Adapter->PortBase ); TRACE_OUT( \"AdapterQueryHardwareResource\", TRUE ); return TRUE; }while( FALSE ); TRACE_OUT( \"AdapterQueryHardwareResource\", FALSE ); return FALSE; } |
|