📄 dispatch.c
字号:
/*******************************************************************************
* Copyright (c) 2006 PLX Technology, Inc.
*
* PLX Technology Inc. licenses this software under specific terms and
* conditions. Use of any of the software or derviatives thereof in any
* product without a PLX Technology chip is strictly prohibited.
*
* PLX Technology, Inc. provides this software AS IS, WITHOUT ANY WARRANTY,
* EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. PLX makes no guarantee
* or representations regarding the use of, or the results of the use of,
* the software and documentation in terms of correctness, accuracy,
* reliability, currentness, or otherwise; and you rely on the software,
* documentation and results solely at your own risk.
*
* IN NO EVENT SHALL PLX BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
* LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
* OF ANY KIND. IN NO EVENT SHALL PLX'S TOTAL LIABILITY EXCEED THE SUM
* PAID TO PLX FOR THE PRODUCT LICENSED HEREUNDER.
*
******************************************************************************/
/******************************************************************************
*
* File Name:
*
* Dispatch.c
*
* Description:
*
* This file routes incoming I/O Request packets
*
* Revision History:
*
* 02-01-06 : PCI SDK v4.40
*
******************************************************************************/
#include "ApiFunctions.h"
#include "CommonApi.h"
#include "Dispatch.h"
#include "GlobalVars.h"
#include "PciSupport.h"
#include "PlxIoctl.h"
#include "SupportFunc.h"
#if defined(PLX_WDM_DRIVER)
#include "Driver.h"
#endif
/******************************************************************************
*
* Function : Dispatch_Create
*
* Description: Handle IRP_MJ_CREATE, which allows applications to open handles
* to our device
*
******************************************************************************/
NTSTATUS
Dispatch_Create(
PDEVICE_OBJECT fdo,
PIRP pIrp
)
{
DebugPrintf_NoInfo(("\n"));
DebugPrintf((
"Received message (IRP=0x%p) ===> IRP_MJ_CREATE\n",
pIrp
));
return PlxCompleteIrpWithInformation(
pIrp,
STATUS_SUCCESS,
0
);
}
/******************************************************************************
*
* Function : Dispatch_Cleanup
*
* Description: Handle the IRP_MJ_CLEANUP IRP
*
******************************************************************************/
NTSTATUS
Dispatch_Cleanup(
PDEVICE_OBJECT fdo,
PIRP pIrp
)
{
PIO_STACK_LOCATION pStack;
DebugPrintf_NoInfo(("\n"));
DebugPrintf((
"Received message (IRP=0x%p) ===> IRP_MJ_CLEANUP\n",
pIrp
));
pStack =
IoGetCurrentIrpStackLocation(
pIrp
);
// Release any pending notifications owned by proccess
PlxNotificationCancel(
fdo->DeviceExtension,
NULL,
pStack->FileObject
);
// Close DMA channels owned by the process
PlxDmaChannelCleanup(
fdo->DeviceExtension,
pStack->FileObject
);
// Unmap any mappings to PCI BAR spaces owned by process
PlxPciBarSpaceUnmapAll_ByOwner(
fdo->DeviceExtension,
pStack->FileObject
);
// Unmap any mappings to the common buffer owned by process
PlxPciPhysicalMemoryUnmapAll_ByOwner(
fdo->DeviceExtension,
pGbl_CommonBuffer,
pStack->FileObject
);
// Unmap and deallocate any physical memory owned by process
PlxPciPhysicalMemoryFreeAll_ByOwner(
fdo->DeviceExtension,
pStack->FileObject
);
return PlxCompleteIrpWithInformation(
pIrp,
STATUS_SUCCESS,
0
);
}
/******************************************************************************
*
* Function : Dispatch_Close
*
* Description: Handle IRP_MJ_CLOSE, which allows applications to close handles
* to our device
*
******************************************************************************/
NTSTATUS
Dispatch_Close(
PDEVICE_OBJECT fdo,
PIRP pIrp
)
{
DebugPrintf_NoInfo(("\n"));
DebugPrintf((
"Received message (IRP=0x%p) ===> IRP_MJ_CLOSE\n",
pIrp
));
return PlxCompleteIrpWithInformation(
pIrp,
STATUS_SUCCESS,
0
);
}
#if defined(PLX_WDM_DRIVER)
/******************************************************************************
*
* Function : Dispatch_SystemControl
*
* Description: The dispatch routine for WMI IRPs. It does nothing except
* forward the IRP to the next device in the stack.
*
* Note : This routine is required or DriverVerifier will bug check
*
******************************************************************************/
NTSTATUS
Dispatch_SystemControl(
PDEVICE_OBJECT fdo,
PIRP pIrp
)
{
DebugPrintf_NoInfo(("\n"));
DebugPrintf((
"Received WMI message (IRP=0x%p) ===> IRP_MJ_SYSTEM_CONTROL\n",
pIrp
));
DebugPrintf(("Forwarded IRP to next lower driver\n"));
IoSkipCurrentIrpStackLocation(
pIrp
);
return IoCallDriver(
((DEVICE_EXTENSION *)fdo->DeviceExtension)->pLowerDeviceObject,
pIrp
);
}
#endif
/******************************************************************************
*
* Function : Dispatch_IoControl
*
* Description: Processes the IOCTL messages sent to this device
*
******************************************************************************/
NTSTATUS
Dispatch_IoControl(
PDEVICE_OBJECT fdo,
PIRP pIrp
)
{
IOCTLDATA *pIoBuffer;
DEVICE_EXTENSION *pdx;
PIO_STACK_LOCATION pStack;
pdx = fdo->DeviceExtension;
pStack =
IoGetCurrentIrpStackLocation(
pIrp
);
pIoBuffer = pIrp->AssociatedIrp.SystemBuffer;
pIrp->IoStatus.Information = sizeof(IOCTLDATA);
// Lock device to record usage
PlxLockDevice(
pdx
);
DebugPrintf(("Received PLX message (IRP=0x%p) ===> ", pIrp));
// Handle the PLX specific message
switch (pStack->Parameters.DeviceIoControl.IoControlCode)
{
/***********************************
* PLX device management functions
**********************************/
case PLX_IOCTL_DEVICE_INIT:
DebugPrintf_NoInfo(("PLX_IOCTL_DEVICE_INIT\n"));
// Send the device location data back to the API
pIoBuffer->u.MgmtData.u.Device = pdx->Device;
break;
case PLX_IOCTL_PCI_DEVICE_FIND:
DebugPrintf_NoInfo(("PLX_IOCTL_PCI_DEVICE_FIND\n"));
pIoBuffer->ReturnCode =
PlxDeviceFind(
pdx,
&(pIoBuffer->u.MgmtData.u.Device),
(U32*)&(pIoBuffer->u.MgmtData.value)
);
break;
case PLX_IOCTL_DRIVER_VERSION:
DebugPrintf_NoInfo(("PLX_IOCTL_DRIVER_VERSION\n"));
pIoBuffer->u.MgmtData.value =
(PLX_SDK_VERSION_MAJOR << 16) |
(PLX_SDK_VERSION_MINOR << 8) |
(PLX_SDK_VERSION_REVISION << 0);
break;
case PLX_IOCTL_CHIP_TYPE_GET:
DebugPrintf_NoInfo(("PLX_IOCTL_CHIP_TYPE_GET\n"));
if (pdx->PowerState > MIN_WORKING_POWER_STATE)
{
pIoBuffer->ReturnCode = ApiPowerDown;
}
else
{
pIoBuffer->ReturnCode = ApiSuccess;
PlxChipTypeGet(
pdx,
(U32*)&(pIoBuffer->u.MiscData.data[0]),
(U8*)&(pIoBuffer->u.MiscData.data[1])
);
}
break;
case PLX_IOCTL_PCI_BOARD_RESET:
DebugPrintf_NoInfo(("PLX_IOCTL_PCI_BOARD_RESET\n"));
if (pdx->PowerState <= MIN_WORKING_POWER_STATE)
{
PlxPciBoardReset(
pdx
);
}
break;
case PLX_IOCTL_PCI_BAR_GET:
DebugPrintf_NoInfo(("PLX_IOCTL_PCI_BAR_GET\n"));
pIoBuffer->u.MgmtData.value =
pdx->PciBar[pIoBuffer->u.MgmtData.offset].Physical.QuadPart;
pIoBuffer->u.MgmtData.u.bFlag =
pdx->PciBar[pIoBuffer->u.MgmtData.offset].bIsIoSpace;
break;
case PLX_IOCTL_PCI_BAR_RANGE_GET:
DebugPrintf_NoInfo(("PLX_IOCTL_PCI_BAR_RANGE_GET\n"));
pIoBuffer->u.MgmtData.value =
pdx->PciBar[pIoBuffer->u.MgmtData.offset].Size;
break;
case PLX_IOCTL_PCI_BAR_MAP:
DebugPrintf_NoInfo(("PLX_IOCTL_PCI_BAR_MAP\n"));
pIoBuffer->ReturnCode =
PlxPciBarMap(
pdx,
(U8)(pIoBuffer->u.MgmtData.offset),
&(pIoBuffer->u.MgmtData.value),
pStack->FileObject
);
break;
case PLX_IOCTL_PCI_BAR_UNMAP:
DebugPrintf_NoInfo(("PLX_IOCTL_PCI_BAR_UNMAP\n"));
pIoBuffer->ReturnCode =
PlxPciBarUnmap(
pdx,
PLX_INT_TO_PTR(pIoBuffer->u.MgmtData.value),
pStack->FileObject
);
break;
case PLX_IOCTL_PHYSICAL_MEM_ALLOCATE:
DebugPrintf_NoInfo(("PLX_IOCTL_PHYSICAL_MEM_ALLOCATE\n"));
pIoBuffer->ReturnCode =
PlxPciPhysicalMemoryAllocate(
pdx,
&(pIoBuffer->u.MiscData.u.PciMemory),
(BOOLEAN)(pIoBuffer->u.MiscData.data[0]),
pStack->FileObject
);
break;
case PLX_IOCTL_PHYSICAL_MEM_FREE:
DebugPrintf_NoInfo(("PLX_IOCTL_PHYSICAL_MEM_FREE\n"));
pIoBuffer->ReturnCode =
PlxPciPhysicalMemoryFree(
pdx,
&(pIoBuffer->u.MiscData.u.PciMemory)
);
break;
case PLX_IOCTL_PHYSICAL_MEM_MAP:
DebugPrintf_NoInfo(("PLX_IOCTL_PHYSICAL_MEM_MAP\n"));
pIoBuffer->ReturnCode =
PlxPciPhysicalMemoryMap(
pdx,
&(pIoBuffer->u.MiscData.u.PciMemory),
(BOOLEAN)pIoBuffer->u.MiscData.data[0],
pStack->FileObject
);
break;
case PLX_IOCTL_PHYSICAL_MEM_UNMAP:
DebugPrintf_NoInfo(("PLX_IOCTL_PHYSICAL_MEM_UNMAP\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -