📄 comeml_drv_if.cpp
字号:
&nRet,
NULL);
if (refCount)
if (out.status == NO_ERROR)
*refCount = out.referenceCount;
else
*refCount = 0;
return out.status;
}
//////////////////////////////////////////////////////////////////////////
// DWORD comemGetPCIInfoL(PCI_CONFIG_HEADER_0 *pciPtr, DWORD comemID)
//
// Function: Get the PCI configuration block for the specified comemID
// If the PCI device has not yet been found, it is found, or an error is returned.
//
// Input:
// pciPtr -- pointer to structure to fill with the PCI information.
//
// Returns:
// ERROR_NO_DRIVER -- Driver not detected
// ERROR_UNKNOWN -- Other error reported by driver
// NO_ERROR -- No errors
// Stuffs pciPtr structure with PCI configuration block
//
//////////////////////////////////////////////////////////////////////////
DWORD comemGetPCIInfoL(PCI_CONFIG_HEADER_0 *pciPtr, DWORD comemID)
{
if (comemID > COMEM_MAX_DEVICES)
return ERROR_INVALID_COMEM_ID;
GetPciCfgIn input;
GetPciCfgOut output;
DWORD nRet = 0;
input.ComemId = comemID;
if (hdevice[comemID] == INVALID_HANDLE_VALUE)
return ERROR_NO_DRIVER;
DWORD status =
DeviceIoControl(
hdevice[comemID],
IOCTL_COMEM_GETPCICFG,
&input,
sizeof(input),
&output,
sizeof(GetPciCfgOut),
&nRet,
NULL);
if (!status)
return ERROR_UNKNOWN;
if (output.status == NO_ERROR)
memmove(pciPtr, &output.VendorID, sizeof(PCI_CONFIG_HEADER_0));
return output.status;
}
//////////////////////////////////////////////////////////////////////////
// DWORD comemSetPCIInfoL(PCI_CONFIG_HEADER_0 *pciPtr, DWORD comemID)
//
// Function:
// Set the PCI configuration block (in the device) for the specified comemID
// If the PCI device has not yet been found, an
// error is returned.
// Returns:
// ERROR_NO_DRIVER -- Driver not detected
// ERROR_UNKNOWN -- Other error reported by driver, or driver call failed
// NO_ERROR -- No errors
//
//////////////////////////////////////////////////////////////////////////
DWORD comemSetPCIInfoL(PCI_CONFIG_HEADER_0 *pciPtr, DWORD comemID)
{
if (comemID > COMEM_MAX_DEVICES)
return ERROR_INVALID_COMEM_ID;
SetPciCfgIn input;
SetPciCfgOut output;
DWORD nRet = 0;
memcpy(&input, pciPtr, sizeof(PCI_CONFIG_HEADER_0));
input.ComemID = comemID;
if (hdevice[comemID] == INVALID_HANDLE_VALUE)
return ERROR_NO_DRIVER;
DWORD status =
DeviceIoControl(
hdevice[comemID],
IOCTL_COMEM_SETPCICFG,
&input,
sizeof(input),
&output,
sizeof(output),
&nRet,
NULL);
if (!status)
return ERROR_UNKNOWN;
return output.status;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// DWORD comemCreateBarPtrL(DWORD linBAR[COMEM_MAX_BARS], DWORD *linPage, DWORD *physPage, DWORD comemID)
//
// Function:
// Create linear pointers to the BARs (Base address registers).
// Can be called any time the driver is open. Since the BARs are fixed at Windows
// initialization time, there is no reason to call this function more than once.
//
// Inputs:
// linBAR -- Pointer to array of pointers to fill with the linear BAR pointers.
// linPage -- Pointer to a DWORD that will hold the linear page table pointer.
// physPage -- Pointer to a DWORD that will hold the physical page table pointer.
//
// Returns:
// ERROR_NO_DRIVER -- Driver not detected
// ERROR_UNKNOWN -- Other error reported by driver
// NO_ERROR -- No errors
/////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD comemCreateBarPtrL(DWORD linBAR[COMEM_MAX_BARS], DWORD comemID)
{
if (comemID > COMEM_MAX_DEVICES)
return ERROR_INVALID_COMEM_ID;
CreateBarPtrIn input;
CreateBarPtrOut output;
DWORD nRet = 0;
input.comemID = comemID;
if (hdevice[comemID] == INVALID_HANDLE_VALUE)
return ERROR_NO_DRIVER;
DWORD status =
DeviceIoControl(
hdevice[comemID],
IOCTL_COMEM_CREATEBARPTR,
&input,
sizeof(input),
&output,
sizeof(output),
&nRet,
NULL);
if (!status)
return ERROR_UNKNOWN;
for (int i = 0; i < COMEM_MAX_BARS; i++ )
{
linBAR[i] = output.linBAR[i];
}
return output.status;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// DWORD comemDestroyBarPtrL(DWORD comemID)
// Function: Destroy linear pointers to the BARs (Base address registers).
// Should be called on program exit, and before performing createBarPtr.
//
// Input:
// ComemID -- Zero based comemory id.
//
// Returns: ERROR_NO_DRIVER -- Driver not detected
// ERROR_UNKNOWN -- Other error reported by driver
// NO_ERROR -- No errors
/////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD comemDestroyBarPtrL(DWORD comemID)
{
if (comemID > COMEM_MAX_DEVICES)
return ERROR_INVALID_COMEM_ID;
DestroyBarPtrIn input;
DestroyBarPtrOut output;
DWORD nRet = 0;
input.comemID = comemID;
if (hdevice[comemID] == INVALID_HANDLE_VALUE)
return ERROR_NO_DRIVER;
DWORD status =
DeviceIoControl(
hdevice[comemID],
IOCTL_COMEM_DESTROYBARPTR,
&input,
sizeof(input),
&output,
sizeof(output),
&nRet,
NULL);
if (!status)
return ERROR_UNKNOWN;
return output.status;
}
/////////////////////////////////////////////////////////////////////
//
// DWORD comemAllocContigMemL()
//
// Function:
// Allocate Contiguous Memory call
//
// Input:
// ComemID
// pageCount - # of 4K pages (to be used later, currently defaults to 4)
//
// Returns:
// ERROR_NO_DRIVER -- Driver not detected
// ERROR_UNKNOWN -- Other error reported by driver
// NO_ERROR -- No errors
/////////////////////////////////////////////////////////////////////
DWORD comemAllocContigMemL(DWORD pageCount, DWORD *linearAddr, DWORD *physAddr, DWORD comemID)
{
if (comemID > COMEM_MAX_DEVICES)
return ERROR_INVALID_COMEM_ID;
DWORD nRet = 0;
if (hdevice[comemID] == INVALID_HANDLE_VALUE)
return ERROR_NO_DRIVER;
AllocContigMemIn in;
AllocContigMemOut out;
in.size = pageCount;
in.comemID = comemID;
DWORD status =
DeviceIoControl(
hdevice[comemID],
IOCTL_COMEM_ALLOCCONTIGMEM,
&in,
sizeof(AllocContigMemIn),
&out,
sizeof(AllocContigMemOut),
&nRet,
NULL);
if (!status)
return ERROR_UNKNOWN;
*linearAddr = out.linearAddr;
*physAddr = out.physAddr;
return out.status;
}
/////////////////////////////////////////////////////////////////////
//
// DWORD comemDeAllocContigMemL()
//
// Function:
// Free the memory allocated by the AllocContigMem call
//
// Input:
// ComemID
//
// Returns:
// ERROR_NO_DRIVER -- Driver not detected
// ERROR_UNKNOWN -- Other error reported by driver
// NO_ERROR -- No errors
/////////////////////////////////////////////////////////////////////
DWORD comemDeAllocContigMemL(DWORD *linearAddr, DWORD *physAddr, DWORD comemID)
{
if (comemID > COMEM_MAX_DEVICES)
return ERROR_INVALID_COMEM_ID;
DWORD nRet = 0;
if (hdevice[comemID] == INVALID_HANDLE_VALUE)
return ERROR_NO_DRIVER;
DeallocContigMemIn in;
DeallocContigMemOut out;
in.comemID = comemID;
in.linearAddr = *linearAddr;
in.physAddr = *physAddr;
DWORD status =
DeviceIoControl(
hdevice[comemID],
IOCTL_COMEM_DEALLOCCONTIGMEM,
&in,
sizeof(DeallocContigMemIn),
&out,
sizeof(DeallocContigMemOut),
&nRet,
NULL);
if (!status)
return ERROR_UNKNOWN;
return out.status;
}
////////////////////////////////////////////////////////////////////////////////
// DWORD comemGetVersionL()
// Function: Inform the user which version of the driver is running
// Returns: Driver version -- Major rev in upper word, minor rev in lower word
////////////////////////////////////////////////////////////////////////////////
DWORD comemGetVersionL(DWORD comemID)
{
return 0x20001; // NOTE: The driver must be modified to return the version
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -