soliven
驱动牛犊
驱动牛犊
  • 注册日期2010-08-27
  • 最后登录2011-05-30
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望51点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2043回复:4

求教:plx9054驱动一卸载后板卡就死掉。

楼主#
更多 发布于:2010-09-26 10:01
我是一个驱动新手,写了一个9054驱动,但是现在一卸载驱动板子就会死掉。就是卸载掉我写的驱动后,用WinDriver读bar0和bar2的寄存器都是0xffffffff。
通过dbgview查看,卸载的时候有三个irp:IRP_MN_QUERY_DEVICE_RELATIONS、IRP_MN_QUERY_REMOVE_DEVICE和IRP_MN_REMOVE_DEVICE。前两个我都是默认处理,主要的卸载操作都是在第三个irp中做的。
目前我的驱动里没加dma功能,只是读写寄存器,和中断事件。
不知道有人遇到过如此问题吗?请不啬赐教。能提供点思路也不胜感激。
代码如下:
VOID StopDevice(IN PDEVICE_EXTENSION pdx)
{
 //DEVICE_EXTENSION *pdx;
 //pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
 //if(!pdx->GotResource)
 // return
 pdx->bStopping = TRUE;
 KeResetEvent(&pdx->StoppingEvent);
 UnlockDevice(pdx); //have to double unlock device
 UnlockDevice(pdx);
 KeWaitForSingleObject(&pdx->StoppingEvent, Executive, KernelMode, FALSE, NULL);
 KdPrint(("all pending I/O completed\n"));
 pdx->bStopping = FALSE;
 //pdx->GotResource = FALSE;
 KdPrint(("device is being stopped...\n"));
 //free all interrupt resource after all IRP have been released
 if(pdx->pInterruptObject != NULL)
 {
  KeSynchronizeExecution(pdx->pInterruptObject, (PKSYNCHRONIZE_ROUTINE)DisablePciInterrupt, (PVOID)pdx);
  IoDisconnectInterrupt(pdx->pInterruptObject);
  pdx->pInterruptObject = NULL;
  KdPrint(("disconnected interrupt resource\n"));
 }
 // Free all the mem map
 if(pdx->MemBar0)
 {
  MmUnmapIoSpace(pdx->MemBar0, pdx->nMem0);
  pdx->MemBar0 = NULL;
  pdx->nMem0 = 0;
  KdPrint(("Free bar0\n"));
 }
 if(pdx->MemBar2)
 {
  MmUnmapIoSpace(pdx->MemBar2, pdx->nMem2);
  pdx->MemBar2 = NULL;
  pdx->nMem2 = 0;
  KdPrint(("Free bar2\n"));
 }
 //Free DMA Common Buffer here
 //Bump usage count back up again
 LockDevice(pdx);
 LockDevice(pdx);
 KdPrint(("device have been stopped.\n"));
}

#pragma PAGEDCODE
NTSTATUS PnpRemoveDeviceHandler(PDEVICE_EXTENSION pdx, PIRP Irp)
{
 PAGED_CODE();
 KdPrint(("Enter PnpRemoveDeviceHandler\n"));
 StopDevice(pdx);
 Irp->IoStatus.Status = STATUS_SUCCESS;
 // let lower-level drivers handle this request & ignore the result
 NTSTATUS status = PnpDefaultHandler(pdx, Irp);
 IoSetDeviceInterfaceState(&pdx->interfaceName, FALSE);
 RtlFreeUnicodeString(&pdx->interfaceName);
    // detach device from the device object stack
    if (pdx->pNextStackDevice)
        IoDetachDevice(pdx->pNextStackDevice);
 
    //delete the functional device object
    IoDeleteDevice(pdx->fdo);
 //delete interrupt resource
 /*if(pdx->pInterruptObject != NULL)
 {
  IoDisconnectInterrupt(pdx->pInterruptObject);
 }*/
 KdPrint(("Leave PnpRemoveDeviceHandler\n"));
 return status;
}

soliven
驱动牛犊
驱动牛犊
  • 注册日期2010-08-27
  • 最后登录2011-05-30
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望51点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2010-09-29 16:04
自己顶一下。
soliven
驱动牛犊
驱动牛犊
  • 注册日期2010-08-27
  • 最后登录2011-05-30
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望51点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2010-12-01 14:53
自己再顶。
fanzi
驱动小牛
驱动小牛
  • 注册日期2004-12-09
  • 最后登录2013-12-19
  • 粉丝1
  • 关注0
  • 积分1004分
  • 威望754点
  • 贡献值0点
  • 好评度93点
  • 原创分0分
  • 专家分0分
地板#
发布于:2010-12-03 15:57
你死机的意思是蓝屏,还是系统hang住?

------------------------------------------------------------------
张帆的驱动开发论坛 http://bbs.kerneldev.com/
张帆的驱动开发QQ群1# 49944346(满)
张帆的驱动开发QQ群2# 64778681(目前开放中...)
张帆的内核学习论坛 http://bbs.kerneldev.com
ywj7891
驱动牛犊
驱动牛犊
  • 注册日期2010-12-09
  • 最后登录2011-04-13
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望81点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2010-12-09 18:05
是屏幕卡死了,并没有蓝屏的情况吗?
游客

返回顶部