18#include "../pci_lib.h"
27 PVOID pOpenData, PVOID *ppDrvContext);
39 ULONG dwLastMessage, DWORD dwReserved);
43static void KP_PCI_Err(
const CHAR *sFormat, ...);
44static void KP_PCI_Trace(
const CHAR *sFormat, ...);
51} PCI_DEV_ADDR_DESC_32B;
157 PCI_DEV_ADDR_DESC *pDevAddrDesc;
162 dwStatus = PCI_LibInit();
165 KP_PCI_Err(
"KP_PCI_Open: Failed to initialize the PCI library. "
166 "Last error [%s]\n", PCI_GetLastErr());
170 KP_PCI_Trace(
"KP_PCI_Open: Entered. PCI library initialized\n");
191 dwSize =
sizeof(PCI_DEV_ADDR_DESC);
192 pDevAddrDesc =
malloc(dwSize);
196 COPY_FROM_USER(pDevAddrDesc, pOpenData, dwSize);
198 dwSize =
sizeof(
WDC_ADDR_DESC) * pDevAddrDesc->dwNumAddrSpaces;
199 pAddrDesc =
malloc(dwSize);
203 COPY_FROM_USER(pAddrDesc, pDevAddrDesc->pAddrDesc, dwSize);
204 pDevAddrDesc->pAddrDesc = pAddrDesc;
206 *ppDrvContext = pDevAddrDesc;
210 *ppDrvContext =
NULL;
214 KP_PCI_Trace(
"KP_PCI_Open: Kernel PlugIn driver opened successfully\n");
219 KP_PCI_Err(
"KP_PCI_Open: Failed allocating [%ld] bytes\n", dwSize);
235 PVOID pOpenData, PVOID *ppDrvContext)
237 PCI_DEV_ADDR_DESC *pDevAddrDesc;
242 dwStatus = PCI_LibInit();
245 KP_PCI_Err(
"KP_PCI_Open_32_64: Failed to initialize the PCI library. "
246 "Last error [%s]\n", PCI_GetLastErr());
250 KP_PCI_Trace(
"KP_PCI_Open_32_64: Entered. PCI library initialized\n");
268 PCI_DEV_ADDR_DESC_32B devAddrDesc_32;
272 dwSize =
sizeof(PCI_DEV_ADDR_DESC);
273 pDevAddrDesc =
malloc(dwSize);
278 COPY_FROM_USER(&devAddrDesc_32, pOpenData,
279 sizeof(PCI_DEV_ADDR_DESC_32B));
282 pDevAddrDesc->dwNumAddrSpaces = devAddrDesc_32.dwNumAddrSpaces;
283 dwSize =
sizeof(
WDC_ADDR_DESC) * pDevAddrDesc->dwNumAddrSpaces;
284 pAddrDesc =
malloc(dwSize);
288 COPY_FROM_USER(pAddrDesc, (PVOID)(
KPTR)devAddrDesc_32.pAddrDesc,
290 pDevAddrDesc->pAddrDesc = pAddrDesc;
292 *ppDrvContext = pDevAddrDesc;
296 *ppDrvContext =
NULL;
300 KP_PCI_Trace(
"KP_PCI_Open_32_64: Kernel PlugIn driver opened "
306 KP_PCI_Err(
"KP_PCI_Open_32_64: Failed allocating [%ld] bytes\n", dwSize);
330 KP_PCI_Trace(
"KP_PCI_Close: Entered\n");
333 dwStatus = PCI_LibUninit();
336 KP_PCI_Err(
"KP_PCI_Close: Failed to uninit the PCI library. "
337 "Last error [%s]\n", PCI_GetLastErr());
343 if (((PCI_DEV_ADDR_DESC *)pDrvContext)->pAddrDesc)
344 free(((PCI_DEV_ADDR_DESC *)pDrvContext)->pAddrDesc);
379 KP_PCI_Trace(
"KP_PCI_Call: Entered. Message [0x%lx]\n", kpCall->
dwMessage);
381 kpCall->
dwResult = KP_PCI_STATUS_OK;
385 case KP_PCI_MSG_VERSION:
387 KP_PCI_VERSION *pUserKPVer = (KP_PCI_VERSION *)(kpCall->
pData);
388 KP_PCI_VERSION kernelKPVer;
391 kernelKPVer.dwVer = 100;
392#define DRIVER_VER_STR "My Driver V1.00"
394 COPY_TO_USER(pUserKPVer, &kernelKPVer,
sizeof(KP_PCI_VERSION));
395 kpCall->
dwResult = KP_PCI_STATUS_OK;
400 kpCall->
dwResult = KP_PCI_STATUS_MSG_NO_IMPL;
431 KP_PCI_Trace(
"KP_PCI_IntEnable: Entered\n");
437 *ppIntContext = pDrvContext;
497 static DWORD dwIntCount = 0;
498 PCI_DEV_ADDR_DESC *pDevAddrDesc = (PCI_DEV_ADDR_DESC *)pIntContext;
502 WDC_ADDR_DESC *pAddrDesc = &pDevAddrDesc->pAddrDesc[INTCSR_ADDR_SPACE];
504#define USE_MULTI_TRANSFER
505#if defined USE_MULTI_TRANSFER
554 PVOID pData = (DWORD *)(pAddrDesc->
pAddr + INTCSR);
562#undef USE_MULTI_TRANSFER
568 *pfIsMyInterrupt =
FALSE;
574 if (!(dwIntCount % 5))
646 static DWORD dwIntCount = 0;
655 if (!(dwIntCount % 5))
689 ULONG dwLastMessage, DWORD dwReserved)
721static void KP_PCI_Err(
const CHAR *sFormat, ...)
727 va_start(argp, sFormat);
728 vsnprintf(sMsg,
sizeof(sMsg) - 1, sFormat, argp);
729 WDC_Err(
"%s: %s", KP_PCI_DRIVER_NAME, sMsg);
734static void KP_PCI_Trace(
const CHAR *sFormat, ...)
740 va_start(argp, sFormat);
741 vsnprintf(sMsg,
sizeof(sMsg) - 1, sFormat, argp);
742 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.
BOOL __cdecl KP_PCI_IntAtIrqlMSI(PVOID pIntContext, ULONG dwLastMessage, DWORD dwReserved)
High-priority Message-Signaled Interrupts (MSI) / Extended Message-Signaled Interrupts (MSI-X) handle...
DWORD __cdecl KP_PCI_IntAtDpcMSI(PVOID pIntContext, DWORD dwCount, ULONG dwLastMessage, DWORD dwReserved)
Deferred processing Message-Signaled Interrupts (MSI) / Extended Message-Signaled Interrupts (MSI-X) ...
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_Event(PVOID pDrvContext, WD_EVENT *wd_event)
Called when a Plug-and-Play or power management event for the device is received, provided the user-m...
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(unsigned long 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.
union WD_TRANSFER::@14 Data
KPTR pPort
I/O port for transfer or kernel memory address.
#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.