18#include "../pci_lib.h"
27 PVOID pOpenData, PVOID *ppDrvContext);
37BOOL __cdecl KP_PCI_IntAtIrqlMSI(PVOID pIntContext, ULONG dwLastMessage,
39DWORD __cdecl KP_PCI_IntAtDpcMSI(PVOID pIntContext, DWORD dwCount,
40 ULONG dwLastMessage, DWORD dwReserved);
42BOOL __cdecl KP_PCI_Event(PVOID pDrvContext,
WD_EVENT *wd_event);
45static void KP_PCI_Err(
const CHAR *sFormat, ...);
46static void KP_PCI_Trace(
const CHAR *sFormat, ...);
53} PCI_DEV_ADDR_DESC_32B;
159 PCI_DEV_ADDR_DESC *pDevAddrDesc;
164 dwStatus = PCI_LibInit();
167 KP_PCI_Err(
"KP_PCI_Open: Failed to initialize the PCI library. "
168 "Last error [%s]\n", PCI_GetLastErr());
172 KP_PCI_Trace(
"KP_PCI_Open: Entered. PCI library initialized\n");
195 dwSize =
sizeof(PCI_DEV_ADDR_DESC);
196 pDevAddrDesc =
malloc(dwSize);
200 COPY_FROM_USER(pDevAddrDesc, pOpenData, dwSize);
202 dwSize =
sizeof(
WDC_ADDR_DESC) * pDevAddrDesc->dwNumAddrSpaces;
203 pAddrDesc =
malloc(dwSize);
207 COPY_FROM_USER(pAddrDesc, pDevAddrDesc->pAddrDesc, dwSize);
208 pDevAddrDesc->pAddrDesc = pAddrDesc;
210 *ppDrvContext = pDevAddrDesc;
214 *ppDrvContext =
NULL;
218 KP_PCI_Trace(
"KP_PCI_Open: Kernel PlugIn driver opened successfully\n");
223 KP_PCI_Err(
"KP_PCI_Open: Failed allocating [%ld] bytes\n", dwSize);
239 PVOID pOpenData, PVOID *ppDrvContext)
241 PCI_DEV_ADDR_DESC *pDevAddrDesc;
246 dwStatus = PCI_LibInit();
249 KP_PCI_Err(
"KP_PCI_Open_32_64: Failed to initialize the PCI library. "
250 "Last error [%s]\n", PCI_GetLastErr());
254 KP_PCI_Trace(
"KP_PCI_Open_32_64: Entered. PCI library initialized\n");
274 PCI_DEV_ADDR_DESC_32B devAddrDesc_32;
278 dwSize =
sizeof(PCI_DEV_ADDR_DESC);
279 pDevAddrDesc =
malloc(dwSize);
284 COPY_FROM_USER(&devAddrDesc_32, pOpenData,
285 sizeof(PCI_DEV_ADDR_DESC_32B));
288 pDevAddrDesc->dwNumAddrSpaces = devAddrDesc_32.dwNumAddrSpaces;
289 dwSize =
sizeof(
WDC_ADDR_DESC) * pDevAddrDesc->dwNumAddrSpaces;
290 pAddrDesc =
malloc(dwSize);
294 COPY_FROM_USER(pAddrDesc, (PVOID)(
KPTR)devAddrDesc_32.pAddrDesc,
296 pDevAddrDesc->pAddrDesc = pAddrDesc;
298 *ppDrvContext = pDevAddrDesc;
302 *ppDrvContext =
NULL;
306 KP_PCI_Trace(
"KP_PCI_Open_32_64: Kernel PlugIn driver opened "
312 KP_PCI_Err(
"KP_PCI_Open_32_64: Failed allocating [%ld] bytes\n", dwSize);
336 KP_PCI_Trace(
"KP_PCI_Close: Entered\n");
339 dwStatus = PCI_LibUninit();
342 KP_PCI_Err(
"KP_PCI_Close: Failed to uninit the PCI library. "
343 "Last error [%s]\n", PCI_GetLastErr());
349 if (((PCI_DEV_ADDR_DESC *)pDrvContext)->pAddrDesc)
350 free(((PCI_DEV_ADDR_DESC *)pDrvContext)->pAddrDesc);
385 KP_PCI_Trace(
"KP_PCI_Call: Entered. Message [0x%lx]\n", kpCall->
dwMessage);
387 kpCall->
dwResult = KP_PCI_STATUS_OK;
391 case KP_PCI_MSG_VERSION:
393 KP_PCI_VERSION *pUserKPVer = (KP_PCI_VERSION *)(kpCall->
pData);
394 KP_PCI_VERSION kernelKPVer;
397 kernelKPVer.dwVer = 100;
398#define DRIVER_VER_STR "My Driver V1.00"
400 COPY_TO_USER(pUserKPVer, &kernelKPVer,
sizeof(KP_PCI_VERSION));
401 kpCall->
dwResult = KP_PCI_STATUS_OK;
406 kpCall->
dwResult = KP_PCI_STATUS_MSG_NO_IMPL;
437 KP_PCI_Trace(
"KP_PCI_IntEnable: Entered\n");
443 *ppIntContext = pDrvContext;
503 static DWORD dwIntCount = 0;
504 PCI_DEV_ADDR_DESC *pDevAddrDesc = (PCI_DEV_ADDR_DESC *)pIntContext;
508 WDC_ADDR_DESC *pAddrDesc = &pDevAddrDesc->pAddrDesc[INTCSR_ADDR_SPACE];
510#define USE_MULTI_TRANSFER
511#if defined USE_MULTI_TRANSFER
570 PVOID pData = (DWORD *)(pAddrDesc->
pAddr + INTCSR);
578#undef USE_MULTI_TRANSFER
584 *pfIsMyInterrupt =
FALSE;
590 if (!(dwIntCount % 5))
661BOOL __cdecl KP_PCI_IntAtIrqlMSI(PVOID pIntContext, ULONG dwLastMessage,
664 static DWORD dwIntCount = 0;
673 if (!(dwIntCount % 5))
706DWORD __cdecl KP_PCI_IntAtDpcMSI(PVOID pIntContext, DWORD dwCount,
707 ULONG dwLastMessage, DWORD dwReserved)
730BOOL __cdecl KP_PCI_Event(PVOID pDrvContext,
WD_EVENT *wd_event)
740static void KP_PCI_Err(
const CHAR *sFormat, ...)
746 va_start(argp, sFormat);
747 vsnprintf(sMsg,
sizeof(sMsg) - 1, sFormat, argp);
748 WDC_Err(
"%s: %s", KP_PCI_DRIVER_NAME, sMsg);
753static void KP_PCI_Trace(
const CHAR *sFormat, ...)
759 va_start(argp, sFormat);
760 vsnprintf(sMsg,
sizeof(sMsg) - 1, sFormat, argp);
761 WDC_Trace(
"%s: %s", KP_PCI_DRIVER_NAME, sMsg);
BOOL __cdecl KP_PCI_Open(KP_OPEN_CALL *kpOpenCall, HANDLE hWD, PVOID pOpenData, PVOID *ppDrvContext)
Kernel PlugIn open function.
DWORD __cdecl KP_PCI_IntAtDpc(PVOID pIntContext, DWORD dwCount)
Deferred processing legacy interrupt handler routine.
BOOL __cdecl KP_PCI_IntEnable(PVOID pDrvContext, WD_KERNEL_PLUGIN_CALL *kpCall, PVOID *ppIntContext)
Called when WDC_IntEnable() / WD_IntEnable() is called from the user mode with a Kernel PlugIn handle...
BOOL __cdecl KP_PCI_IntAtIrql(PVOID pIntContext, BOOL *pfIsMyInterrupt)
High-priority legacy interrupt handler routine, which is run at high interrupt request level.
void __cdecl KP_PCI_Close(PVOID pDrvContext)
Called when WD_KernelPlugInClose() (see the WinDriver PCI Low-Level API Reference) is called from use...
void __cdecl KP_PCI_Call(PVOID pDrvContext, WD_KERNEL_PLUGIN_CALL *kpCall)
Called when the user-mode application calls WDC_CallKerPlug() (or the low-level WD_KernelPlugInCall()...
void __cdecl KP_PCI_IntDisable(PVOID pIntContext)
Called when WDC_IntDisable() / WD_IntDisable() is called from the user mode for interrupts that were ...
BOOL __cdecl KP_Init(KP_INIT *kpInit)
KP_Init is called when the Kernel PlugIn driver is loaded.
BOOL __cdecl KP_PCI_Open_32_64(KP_OPEN_CALL *kpOpenCall, HANDLE hWD, PVOID pOpenData, PVOID *ppDrvContext)
KP_PCI_Open_32_64 is called when WD_KernelPlugInOpen() is called from a 32-bit user mode application ...
void *__cdecl malloc(size_t size)
void __cdecl free(void *buf)
char *__cdecl strcpy(char *s1, const char *s2)
CHAR cDriverName[WD_MAX_KP_NAME_LENGTH]
return the device driver name
DWORD dwVerWD
version of the WinDriver Kernel PlugIn library
KP_FUNC_OPEN funcOpen
returns the KP_Open function
KP_FUNC_OPEN funcOpen_32_64
returns the KP_Open function for 32 bit app with 64 bit KP.
KP_FUNC_INT_AT_IRQL funcIntAtIrql
KP_FUNC_INT_AT_DPC_MSI funcIntAtDpcMSI
KP_FUNC_INT_ENABLE funcIntEnable
KP_FUNC_INT_AT_IRQL_MSI funcIntAtIrqlMSI
KP_FUNC_INT_AT_DPC funcIntAtDpc
KP_FUNC_INT_DISABLE funcIntDisable
KPTR pAddr
I/O / Memory kernel mapped address – for WD_Transfer(), WD_MultiTransfer(), or direct kernel access.
Address space information struct.
DWORD cmdTrans
Transfer command WD_TRANSFER_CMD.
UINT32 Dword
Use for 32 bit transfer.
KPTR pPort
I/O port for transfer or kernel memory address.
union WD_TRANSFER::@16 Data
#define WDC_ADDR_IS_MEM(pAddrDesc)
Check if memory or I/O address.
void DLLCALLCONV WDC_Trace(const CHAR *format,...)
Displays debug trace messages according to the WDC debug options.
DWORD DLLCALLCONV WDC_MultiTransfer(_In_ WD_TRANSFER *pTransCmds, _In_ DWORD dwNumTrans)
Performs a group of memory and/or I/O read/write transfers.
void DLLCALLCONV WDC_Err(const CHAR *format,...)
Displays debug error messages according to the WDC debug options.
#define WDC_ReadMem32(addr, off)
reads 4 byte (32 bits) from a specified memory address.
#define WDC_WriteMem32(addr, off, val)
writes 4 byte (32 bits) to a specified memory address.
@ WD_STATUS_SUCCESS
[0] Operation completed successfully
@ RM_DWORD
Read memory dword.
@ WP_DWORD
Write port dword.
@ WM_DWORD
Write memory dword.
@ RP_DWORD
Read port dword.