Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

359 lines
10 KiB

4 years ago
  1. /*
  2. * vckernel.h
  3. *
  4. *
  5. * 32-bit Video Capture driver
  6. *
  7. * definition of interface between hardware-specific portions of
  8. * kernel driver and the helper library vckernel.lib
  9. *
  10. *
  11. * The hardware-specific portion of a video capture driver will
  12. * have an NT-specific DriverEntry function that will call VC_Init
  13. * to initialise the helper library after performing hardware detect and
  14. * initialise. All NT interaction will then be done by the library vckernel.lib
  15. * calling back to the hardware-specific code only through the dispatch
  16. * table below.
  17. *
  18. *
  19. * All h/w specific functions are given a pointer to a PDEVICE_INFO structure
  20. * which they can pass to VC_IN(), VC_OUT(). VC_GetHWInfo() will return a
  21. * pointer to the hardware-specific data structure requested from VC_Init().
  22. *
  23. * Geraint Davies, Feb 93
  24. */
  25. #ifndef _VCKERNEL_
  26. #define _VCKERNEL_
  27. /* include necessary headers so that hardware-specific callers do not
  28. * explicitly reference NT-specific headers.
  29. */
  30. #include <ntddk.h>
  31. #include <windef.h>
  32. #include <wingdi.h> // for RGBQUAD
  33. #include <vcstruct.h>
  34. #include <ntddvidc.h>
  35. /*
  36. * hardware-independent device-extension data structure - opaque to
  37. * h/w specific functions.
  38. */
  39. typedef struct _DEVICE_INFO DEVICE_INFO, *PDEVICE_INFO;
  40. /* --- callbacks to h/w specific code --------------------------*/
  41. /* these are the hardware-specific functions called from the dispatcher */
  42. typedef struct _VC_CALLBACK {
  43. /* return TRUE for success */
  44. /* called on device open/close - optional routines */
  45. BOOLEAN (*DeviceOpenFunc)(PDEVICE_INFO);
  46. BOOLEAN (*DeviceCloseFunc)(PDEVICE_INFO);
  47. BOOLEAN (*ConfigFormatFunc)(PDEVICE_INFO, PCONFIG_INFO);
  48. BOOLEAN (*ConfigDisplayFunc)(PDEVICE_INFO, PCONFIG_INFO);
  49. BOOLEAN (*ConfigSourceFunc)(PDEVICE_INFO, PCONFIG_INFO);
  50. /* overlay functions - all optional */
  51. /* return overlay mode DWORD */
  52. DWORD (*GetOverlayModeFunc) (PDEVICE_INFO);
  53. /* return TRUE for success */
  54. BOOLEAN (*SetKeyRGBFunc)(PDEVICE_INFO, PRGBQUAD);
  55. BOOLEAN (*SetKeyPalIdxFunc)(PDEVICE_INFO, ULONG);
  56. BOOLEAN (*SetOverlayRectsFunc)(PDEVICE_INFO, POVERLAY_RECTS);
  57. BOOLEAN (*SetOverlayOffsetFunc)(PDEVICE_INFO, PRECT);
  58. ULONG (*GetKeyColourFunc)(PDEVICE_INFO);
  59. BOOLEAN (*CaptureFunc)(PDEVICE_INFO, BOOL);
  60. BOOLEAN (*OverlayFunc)(PDEVICE_INFO, BOOL);
  61. /* capture routines - start/stop, interrupt and capture are
  62. * required routines
  63. */
  64. BOOLEAN (*StreamInitFunc)(PDEVICE_INFO pDevInfo, ULONG microsecperframe);
  65. BOOLEAN (*StreamFiniFunc)(PDEVICE_INFO);
  66. BOOLEAN (*StreamStartFunc)(PDEVICE_INFO);
  67. BOOLEAN (*StreamStopFunc)(PDEVICE_INFO);
  68. ULONG (*StreamGetPositionFunc)(PDEVICE_INFO);
  69. /* returns TRUE if Capture Service should happen */
  70. BOOLEAN (*InterruptAcknowledge)(PDEVICE_INFO);
  71. /*
  72. * returns bytes written to buffer PUCHAR (whose length is ULONG)
  73. * - not called if no buffer
  74. */
  75. ULONG (*CaptureService)(PDEVICE_INFO, PUCHAR, PULONG, ULONG);
  76. /*
  77. * writes a frame to the device for display
  78. */
  79. BOOLEAN (*DrawFrameFunc)(PDEVICE_INFO, PDRAWBUFFER);
  80. /* called on driver-unload */
  81. BOOLEAN (*CleanupFunc)(PDEVICE_INFO);
  82. } VC_CALLBACK, * PVC_CALLBACK;
  83. /* --- support functions in vckernel.lib -------------------------- */
  84. /*
  85. * VC_Init
  86. *
  87. * Create the device object, and any necessary related setup, and
  88. * allocate device extension data. The device extension data is
  89. * a DEVICE_INFO struct plus however much data the caller wants for
  90. * hardware-specific data.
  91. *
  92. * parameters:
  93. * pDriverObject - pointer to driver object (arg to DriverEntry)
  94. * RegistryPathName - entry for this driver in registry (arg to DriverEntry)
  95. * HWInfoSize - amount of data to allocate at end of DeviceExtension
  96. *
  97. * returns pointer to device extension data as DEVICE_INFO struct.
  98. */
  99. PDEVICE_INFO
  100. VC_Init(
  101. PDRIVER_OBJECT pDriverObject,
  102. PUNICODE_STRING RegistryPathName,
  103. ULONG HWInfoSize);
  104. /*
  105. * VC_GetResources
  106. *
  107. * map port and frame buffer into system address space or i/o space, and
  108. * report resource usage of the ports, interrupt and physical memory
  109. * address used.
  110. *
  111. * Note: We do not connect the interrupt: this is not done until
  112. * a subsequent call to VC_ConnectInterrupt. We do, however, report
  113. * usage of the interrupt.
  114. *
  115. * we return TRUE if success, or FALSE if we couldn't get the resources.
  116. */
  117. BOOLEAN
  118. VC_GetResources(
  119. PDEVICE_INFO pDevInfo,
  120. PDRIVER_OBJECT pDriverObject,
  121. PUCHAR PortBase,
  122. ULONG NrOfPorts,
  123. ULONG Interrupt,
  124. BOOLEAN bLatched,
  125. PUCHAR pFrameBuffer,
  126. ULONG FrameLength);
  127. /*
  128. * VC_ConnectInterrupt
  129. *
  130. * This assumes that VC_GetResources has already been called to report the
  131. * resource usage, and that the VC_CALLBACK table has been set up
  132. * to handle interrupts.
  133. *
  134. * returns TRUE if success.
  135. */
  136. BOOLEAN VC_ConnectInterrupt(
  137. PDEVICE_INFO pDevInfo,
  138. ULONG Interrupt,
  139. BOOLEAN bLatched);
  140. /* call to unload or abort load of the driver */
  141. VOID
  142. VC_Cleanup(
  143. PDRIVER_OBJECT pDriverObject
  144. );
  145. /*
  146. * get the hardware specific portion of the device extension
  147. */
  148. PVOID VC_GetHWInfo(PDEVICE_INFO);
  149. /*
  150. * output one BYTE to the port. bOffset is the offset from
  151. * the port base address.
  152. */
  153. VOID VC_Out(PDEVICE_INFO pDevInfo, BYTE bOffset, BYTE bData);
  154. /*
  155. * input one byte from the port at bOffset offset from the port base address
  156. */
  157. BYTE VC_In(PDEVICE_INFO pDevInfo, BYTE bOffset);
  158. /*
  159. * i/o memory on adapter cards such as the frame buffer memory cannot
  160. * be accessed like ordinary memory on all processors (especially alpha).
  161. * You must read and write this memory using the following macros. These are
  162. * wrappers for the appropriate NT macros.
  163. */
  164. // return one ULONG from the frame buffer at p
  165. #ifdef i386
  166. #define VC_ReadIOMemoryULONG(p) ( * (DWORD volatile *)p)
  167. // return a word from the frame buffer at p
  168. #define VC_ReadIOMemoryUSHORT(p) ( * (USHORT volatile *)p)
  169. // return a byte from the frame buffer at p
  170. #define VC_ReadIOMemoryBYTE(p) ( * (unsigned char volatile *) p)
  171. #else
  172. #define VC_ReadIOMemoryULONG(p) READ_REGISTER_ULONG((PULONG)p)
  173. // return a word from the frame buffer at p
  174. #define VC_ReadIOMemoryUSHORT(p) READ_REGISTER_USHORT((PUSHORT)p)
  175. // return a byte from the frame buffer at p
  176. #define VC_ReadIOMemoryBYTE(p) READ_REGISTER_UCHAR(p)
  177. #endif
  178. // read a block of c bytes (in ULONGS) from the frame buffer at s
  179. //to memory at d. length must be multiple of ulongs.
  180. #define VC_ReadIOMemoryBlock(d, s, c) \
  181. READ_REGISTER_BUFFER_ULONG( \
  182. (PULONG) s, \
  183. (PULONG) d, \
  184. (c)/sizeof(DWORD))
  185. // write a byte b to the frame buffer at p
  186. #define VC_WriteIOMemoryBYTE(p, b) WRITE_REGISTER_UCHAR(p, b)
  187. // write a word w to the frame buffer at p
  188. #define VC_WriteIOMemoryUSHORT(p, w) WRITE_REGISTER_USHORT((PUSHORT)p, w)
  189. // write a ULONG l to the frame buffer at p
  190. #define VC_WriteIOMemoryULONG(p, l) WRITE_REGISTER_ULONG((PULONG)p, l)
  191. // write a block of c bytes to the frame buffer d from memory at s
  192. #define VC_WriteIOMemoryBlock(d, s, c) WRITE_REGISTER_BUFFER_UCHAR(d, s, c)
  193. PVC_CALLBACK VC_GetCallbackTable(PDEVICE_INFO);
  194. /* get a pointer to the frame buffer mapped into system memory */
  195. PUCHAR VC_GetFrameBuffer(PDEVICE_INFO);
  196. /*
  197. * report the expected image size. attempts to queue buffers with a size
  198. * smaller than this will be rejected by vckernel.
  199. */
  200. VOID VC_SetImageSize(PDEVICE_INFO, int);
  201. /* this function is a wrapper for KeSynchronizeExecution (at least in the NT
  202. * version). It will call back the function specified with the context
  203. * argument specified, having first disabled the video interrupt in
  204. * a multi-processor safe way.
  205. */
  206. typedef BOOLEAN (*PSYNC_ROUTINE)(PVOID);
  207. BOOLEAN VC_SynchronizeExecution(PDEVICE_INFO, PSYNC_ROUTINE, PVOID);
  208. /*
  209. * This function can be used like VC_SynchronizeExecution, to sync
  210. * between the captureservice routine and the passive-level requests. This
  211. * will not necessarily disable interrupts. On win-16, this function may be
  212. * the same as VC_SynchronizeExecution. On NT, the CaptureService func
  213. * runs as a DPC, at a lower interrupt priority than the isr itself, and
  214. * so can be protected using this (spinlock-based) function without having
  215. * to disable all interrupts.
  216. */
  217. BOOLEAN VC_SynchronizeDPC(PDEVICE_INFO, PSYNC_ROUTINE, PVOID);
  218. /*
  219. * VC_AccessData gives access to the data in kernel mode in a safe way.
  220. * It calls the given function with the address and size of the buffer
  221. * after any necessary mapping, and wrapped in exception handlers
  222. * as necessary.
  223. *
  224. * This function cannot be called from the InterruptAcknowledge or
  225. * ServiceCapture call back functions - it must be running in the
  226. * context of the calling thread (in kernel mode).
  227. */
  228. typedef BOOLEAN (*PACCESS_ROUTINE)(PDEVICE_INFO, PUCHAR, ULONG, PVOID);
  229. BOOLEAN VC_AccessData(PDEVICE_INFO, PUCHAR, ULONG, PACCESS_ROUTINE, PVOID);
  230. /* these functions allocate and free non-paged memory for use
  231. * in kernel mode, including at interrupt time.
  232. */
  233. PVOID VC_AllocMem(PDEVICE_INFO, ULONG);
  234. VOID VC_FreeMem(PDEVICE_INFO, PVOID, ULONG);
  235. /*
  236. * delay for a number of milliseconds. This is accurate only to
  237. * +- 15msecs at best.
  238. */
  239. VOID VC_Delay(int nMillisecs);
  240. /* block for given number of microseconds by polling. Not recommended
  241. * for more than 25 usecs.
  242. */
  243. VOID VC_Stall(int nMicrosecs);
  244. /*
  245. * read a value from this device's section of the registry or profile.
  246. * returns the dword value associated with ValueName, or Default if ValueName
  247. * cannot be found.
  248. */
  249. DWORD VC_ReadProfile(PDEVICE_INFO pDevInfo, PWCHAR ValueName, DWORD Default);
  250. /*
  251. * write a dword value to this device's section of the registry or profile.
  252. * ValueName is a unicode string representing the registry value name or
  253. * profile key, and ValueData is the dword data written. Returns TRUE if
  254. * successfully written.
  255. */
  256. BOOL VC_WriteProfile(PDEVICE_INFO pDevInfo, PWCHAR ValueName, DWORD ValueData);
  257. #if DBG
  258. extern ULONG VCDebugLevel;
  259. void dbgPrintf(char * szFormat, ...);
  260. #define dprintf(_x_) dbgPrintf _x_
  261. #define dprintf1(_x_) if (VCDebugLevel >= 1) dbgPrintf _x_
  262. #define dprintf2(_x_) if (VCDebugLevel >= 2) dbgPrintf _x_
  263. #define dprintf3(_x_) if (VCDebugLevel >= 3) dbgPrintf _x_
  264. #define dprintf4(_x_) if (VCDebugLevel >= 4) dbgPrintf _x_
  265. #else
  266. #define dprintf(_x_)
  267. #define dprintf1(_x_)
  268. #define dprintf2(_x_)
  269. #define dprintf3(_x_)
  270. #define dprintf4(_x_)
  271. #endif
  272. #endif // _VCKERNEL_