阅读:1322回复:2
关于地址转换的问题
我是一个驱动程序入门者,现在想做一个PCI控制卡的驱动程序,实现一个非常简单的功能,就是对该卡的寄存器内容进行写控制,本人通过上层程序只能读到配置空间里基址寄存器里的地址,而该地址为物理地址,所以想通过驱动程序来做一个转换函数,将该物理地址转换为逻辑地址供上层程序操作。但不知具体该怎样做?请各位高手指教,最好能通过MSN提供帮助,本人邮箱为:kh_sz@hotmail.com 马上给分。谢谢!
|
|
沙发#
发布于:2003-01-21 19:07
我是一个驱动程序入门者,现在想做一个PCI控制卡的驱动程序,实现一个非常简单的功能,就是对该卡的寄存器内容进行写控制,本人通过上层程序只能读到配置空间里基址寄存器里的地址,而该地址为物理地址,所以想通过驱动程序来做一个转换函数,将该物理地址转换为逻辑地址供上层程序操作。但不知具体该怎样做?请各位高手指教,最好能通过MSN提供帮助,本人邮箱为:kh_sz@hotmail.com 马上给分。谢谢! if (partialDescriptor->Type == CmResourceTypeMemory) use function HalTranslateBusAddress(...) else if (partialDescriptor->Type == CmResourceTypeInterrupt) use function HalGetInterruptVector(...) else if (partialDescriptor->Type == CmResourceTypePort) PHYSICAL_ADDRESS PortAddress = partialDescriptor->u.Port.Start; 不过先要用HalAssignSlotResources(...)得到槽相应信息... |
|
板凳#
发布于:2003-01-22 11:03
2k下,在IRP_MN_START_DEVICE里面
AllocatedResourcesTranslated = IrpStack->Parameters.StartDevice.AllocatedResourcesTranslated NTSTATUS RetrieveResources( IN PDEVICE_EXTENSION pDevExt, IN PCM_RESOURCE_LIST AllocatedResourcesTranslated) { if( (AllocatedResourcesTranslated == NULL) || (AllocatedResourcesTranslated->Count == 0) ) { return STATUS_UNSUCCESSFUL; //or whatever } ULONG i = 0, Length = 0; PCM_PARTIAL_RESOURCE_LIST list = &AllocatedResourcesTranslated->List[0].PartialResourceList; PCM_PARTIAL_RESOURCE_DESCRIPTOR pPRD = list->PartialDescriptors; ULONG NumResources = list->Count; for(i=0; i<NumResources; i++,pPRD++) { switch(pPRD->Type) { // IO Port Resource case CmResourceTypePort: { if ( 0 == pDevExt->IoEppBase ) { pDevExt->IoEppBase = (PUCHAR)pPRD->u.Port.Start.LowPart; pDevExt->IoEppLength = pPRD->u.Port.Length; // pDevExt->bIoEppNeedMap = (pPRD->Flags & CM_RESOURCE_PORT_IO) == 0; } else if ( 0 == pDevExt->IoCfgBase ) { pDevExt->IoCfgBase = (PUCHAR)pPRD->u.Port.Start.LowPart; pDevExt->IoCfgLength = pPRD->u.Port.Length; // pDevExt->bIoCfgNeedMap = (pPRD->Flags & CM_RESOURCE_PORT_IO) == 0; } else { DebugPrint((\"\\t RetrieveResources -- IO Port: Add = %X, Len = %d\\n\", pPRD->u.Port.Start, pPRD->u.Port.Length)); } break; } // Memory Resource case CmResourceTypeMemory: { // pDevExt->MemoryLength=Length; // pDevExt->MemPrimalBaseAddress=pPRD->u.Memory.Start; break; } // Interrupt Resource case CmResourceTypeInterrupt: { pDevExt->IntLevel = (KIRQL)pPRD->u.Interrupt.Level; pDevExt->IntVector = pPRD->u.Interrupt.Vector; pDevExt->IntAffinity = pPRD->u.Interrupt.Affinity; pDevExt->IntMode = (pPRD->Flags & CM_RESOURCE_INTERRUPT_LATCHED) ? Latched : LevelSensitive; break; } } } return STATUS_SUCCESS; } 如果仅仅用在x86上,那么io不需要映射, 否则 MmMapIoSpace |
|
|