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.

223 lines
4.9 KiB

4 years ago
  1. /*
  2. * Copyright (c) Microsoft Corporation 1993. All Rights Reserved
  3. */
  4. /*
  5. * vckpriv.h
  6. *
  7. * 32-bit Video Capture driver
  8. * kernel-mode helper library private definitions
  9. *
  10. * Geraint Davies, Feb 93
  11. */
  12. /*
  13. * we track stream init/fini, start/stop requests by maintaining
  14. * the current state of the driver, and only allowing requests that
  15. * move to the next logical state.
  16. * here are the valid states - current state is in DEVICE_INFO.State
  17. */
  18. typedef enum _VCSTATE {
  19. State_Idle = 0, // no streaming in progress
  20. State_Init, // stream-init done
  21. State_Start // streaming started
  22. } VCSTATE, * PVCSTATE;
  23. /*
  24. * definition of _DEVICE_INFO structure. This is declared in vckernel.h
  25. * so that the hw/specific code can use it as an opaque pointer.
  26. */
  27. struct _DEVICE_INFO {
  28. KMUTEX Mutex; // synchronise between calls to driver
  29. KSPIN_LOCK DeviceSpinLock; // sync with dpc
  30. PKINTERRUPT InterruptObject;
  31. PDEVICE_OBJECT pDeviceObject;
  32. int DeviceNumber; // index of device name created
  33. ULONG BusType; // isa, eisa etc
  34. ULONG BusNumber;
  35. ULONG PortMemType; // whether port is i/o or memory mapped
  36. ULONG FrameMemType; // whether frame-buffer is mapped or direct
  37. PUCHAR PortBase;
  38. ULONG NrOfPorts;
  39. PUCHAR FrameBase; // mapped frame address
  40. ULONG FrameLength; // length of frame buffer in system memory
  41. PWCHAR ParametersKey; // name of parameters subkey for this device
  42. int DeviceInUse;
  43. volatile BOOLEAN DpcRequested;
  44. ULONG nSkipped; // nr of unreported skipped frames
  45. int ImageSize; // minimum size for queued buffers
  46. LIST_ENTRY BufferHead; // head of queued irps containing buffers
  47. LIST_ENTRY WaitErrorHead; // head of queued Wait-Error Irps
  48. VCSTATE State;
  49. VC_CALLBACK Callback; // callback to h/w specific functions
  50. /*
  51. * for partial-frame requests (if we can't page-lock one whole
  52. * frame in memory, the user will request capture to a system buffer,
  53. * and then request small bits of it.
  54. */
  55. PUCHAR pSystemBuffer; // to support partial-frame requests
  56. ULONG SysBufInUse; // if it contains a valid frame
  57. ULONG SysBufTimeStamp; // time stamp of capture to sys buffer
  58. };
  59. /* the dispatch routine to which all IRPs go */
  60. NTSTATUS
  61. VC_Dispatch(
  62. IN PDEVICE_OBJECT pDeviceObject,
  63. IN PIRP pIrp
  64. );
  65. /* interrupt service routine - returns TRUE if interrupt handled.
  66. * all interrupts come in here and are then dispatched to hw ack routine
  67. * the Context pointer is a pointer to DEVICE_INFO.
  68. */
  69. BOOLEAN
  70. VC_InterruptService(
  71. IN PKINTERRUPT pInterruptObject,
  72. IN PVOID Context
  73. );
  74. /*
  75. * DPC routine scheduled in VC_InterruptService when the h/w func thinks
  76. * that it is time to fill a buffer with frame data.
  77. */
  78. VOID
  79. VC_Deferred(
  80. PKDPC pDpc,
  81. PDEVICE_OBJECT pDeviceObject,
  82. PIRP pIrpNotUsed,
  83. PVOID Context
  84. );
  85. /*
  86. * cancel routine - set as cancel routine for pending irps (wait-error
  87. * or add-buffer). Called to de-queue and complete them if cancelled.
  88. */
  89. VOID
  90. VC_Cancel(
  91. IN PDEVICE_OBJECT pDeviceObject,
  92. IN PIRP pIrp
  93. );
  94. /*
  95. * clean up any allocations etc that can be freed on last close.
  96. *
  97. * called at device unload and at last close
  98. */
  99. VOID
  100. VC_Close(PDEVICE_INFO pDevInfo);
  101. /*
  102. * interlocked queue access functions
  103. */
  104. /*
  105. * QueueRequest
  106. *
  107. * Add an irp to a cancellable queue.
  108. * Check the cancel flag and return FALSE if cancelled.
  109. * otherwise set the cancel routine and add to queue.
  110. *
  111. */
  112. BOOLEAN
  113. VC_QueueRequest(
  114. PIRP pIrp,
  115. PLIST_ENTRY pQueueHead,
  116. PDRIVER_CANCEL pCancelFunc
  117. );
  118. /*
  119. * VC_ReplaceRequest
  120. *
  121. * return a request to the head of a cancellable queue
  122. *
  123. */
  124. BOOLEAN
  125. VC_ReplaceRequest(
  126. PIRP pIrp,
  127. PLIST_ENTRY pQueueHead,
  128. PDRIVER_CANCEL pCancelFunc
  129. );
  130. /*
  131. * extract the next item from a cancellable queue of irps
  132. * if bCancelHeld is true, then we already hold the cancel spinlock so we
  133. * should not try to get it
  134. */
  135. PIRP
  136. VC_ExtractNextIrp(
  137. PLIST_ENTRY pQueueHead,
  138. BOOLEAN bCancelHeld
  139. );
  140. /*
  141. * extract a specific IRP from the given queue, while possibly holding the
  142. * cancel spinlock already.
  143. */
  144. PIRP
  145. VC_ExtractThisIrp(
  146. PLIST_ENTRY pHead,
  147. PIRP pIrpToFind,
  148. BOOLEAN bCancelHeld
  149. );
  150. /*
  151. * increment the skipcount, and complete a wait-error irp if there
  152. * is one waiting.
  153. */
  154. VOID
  155. VC_ReportSkip(
  156. PDEVICE_INFO pDevInfo
  157. );
  158. /*
  159. * queue a wait-error request to the queue of cancellable wait-error requests,
  160. * and return the irp's status (pending, cancelled, etc);
  161. *
  162. * When queuing, check the cancel flag and insert the correct cancel routine.
  163. *
  164. * If there is a skip-count to report, then:
  165. * --- if there is another irp on the q already complete that and leave
  166. * the current irp pending.
  167. * -- otherwise return STATUS_SUCCESSFUL for this IRP, having written out
  168. * the result data.
  169. *
  170. * Even if cancelled or complete, IoCompleteRequest will NOT have been called
  171. * for this request.
  172. */
  173. NTSTATUS
  174. VC_QueueWaitError(
  175. PDEVICE_INFO pDevInfo,
  176. PIRP pIrp
  177. );