Leaked source code of windows server 2003
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.

406 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1990-2000 Microsoft Corporation
  3. Module Name:
  4. sync.c
  5. Abstract:
  6. This file contains code for the video port synchronization routines.
  7. Environment:
  8. kernel mode only
  9. --*/
  10. #include "videoprt.h"
  11. #ifdef ALLOC_PRAGMA
  12. #pragma alloc_text(PAGE, VideoPortCreateEvent)
  13. #pragma alloc_text(PAGE, VideoPortCreateSpinLock)
  14. #endif
  15. VP_STATUS
  16. VideoPortCreateSpinLock(
  17. IN PVOID HwDeviceExtension,
  18. OUT PSPIN_LOCK *SpinLock
  19. )
  20. /*++
  21. Routine Description:
  22. Creates a spin lock object
  23. Arguments:
  24. HwDeviceExtension - pointer to the miniports device extension
  25. SpinLock - Location in which to store the pointer to the newly
  26. acquired spin lock.
  27. Returns:
  28. NO_ERROR if the spin lock was created successfully, otherwise
  29. an appropriate error message is returned.
  30. Notes:
  31. none
  32. --*/
  33. {
  34. PAGED_CODE();
  35. ASSERT(HwDeviceExtension != NULL);
  36. *SpinLock = ExAllocatePoolWithTag(NonPagedPool,
  37. sizeof(VIDEO_PORT_SPIN_LOCK),
  38. VP_TAG);
  39. if (*SpinLock) {
  40. KeInitializeSpinLock(&(*SpinLock)->Lock);
  41. return NO_ERROR;
  42. } else {
  43. return ERROR_NOT_ENOUGH_MEMORY;
  44. }
  45. }
  46. VP_STATUS
  47. VideoPortDeleteSpinLock(
  48. IN PVOID HwDeviceExtension,
  49. IN PSPIN_LOCK SpinLock
  50. )
  51. /*++
  52. Routine Description:
  53. Deletes the given spin lock
  54. Arguments:
  55. HwDeviceExtension - pointer to the miniports device extension
  56. SpinLock - A pointer to the spin lock being deleted.
  57. Returns:
  58. NO_ERROR if the spin lock is deleted successfully.
  59. Notes:
  60. --*/
  61. {
  62. ASSERT(HwDeviceExtension != NULL);
  63. ASSERT(SpinLock != NULL);
  64. ExFreePool(SpinLock);
  65. return NO_ERROR;
  66. }
  67. VOID
  68. VideoPortAcquireSpinLock(
  69. IN PVOID HwDeviceExtension,
  70. IN PSPIN_LOCK SpinLock,
  71. OUT PUCHAR OldIrql
  72. )
  73. /*++
  74. Routine Description:
  75. Acquires the given spin lock
  76. Arguments:
  77. HwDeviceExtension - pointer to the miniports device extension
  78. SpinLock - The spin lock being acquired
  79. OldIrql - location in which to store the old IRQL level
  80. Returns:
  81. none
  82. Notes:
  83. --*/
  84. {
  85. ASSERT(HwDeviceExtension != NULL);
  86. ASSERT(SpinLock != NULL);
  87. KeAcquireSpinLock(&SpinLock->Lock, OldIrql);
  88. }
  89. VOID
  90. VideoPortAcquireSpinLockAtDpcLevel(
  91. IN PVOID HwDeviceExtension,
  92. IN PSPIN_LOCK SpinLock
  93. )
  94. /*++
  95. Routine Description:
  96. Acquires the given spin lock.
  97. Arguments:
  98. HwDeviceExtension - pointer to the miniports device extension
  99. SpinLock - The spin lock being acquired
  100. Returns:
  101. none
  102. Notes:
  103. This routine can only be called inside a DPC.
  104. --*/
  105. {
  106. ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
  107. ASSERT(HwDeviceExtension != NULL);
  108. ASSERT(SpinLock != NULL);
  109. KeAcquireSpinLockAtDpcLevel(&SpinLock->Lock);
  110. }
  111. VOID
  112. VideoPortReleaseSpinLock(
  113. IN PVOID HwDeviceExtension,
  114. IN PSPIN_LOCK SpinLock,
  115. IN UCHAR NewIrql
  116. )
  117. /*++
  118. Routine Description:
  119. Releases ownership of a given spin lock
  120. Arguments:
  121. HwDeviceExtension - pointer to the miniports device extension
  122. SpinLock - the spin lock being released
  123. NewIrql - Irql level to restore to.
  124. Returns:
  125. none
  126. Notes:
  127. --*/
  128. {
  129. ASSERT(HwDeviceExtension != NULL);
  130. ASSERT(SpinLock != NULL);
  131. KeReleaseSpinLock(&SpinLock->Lock, NewIrql);
  132. }
  133. VOID
  134. VideoPortReleaseSpinLockFromDpcLevel(
  135. IN PVOID HwDeviceExtension,
  136. IN PSPIN_LOCK SpinLock
  137. )
  138. /*++
  139. Routine Description:
  140. Releases ownership of a given spin lock
  141. Arguments:
  142. HwDeviceExtension - pointer to the miniports device extension
  143. SpinLock - the spin lock being released
  144. Returns:
  145. none
  146. Notes:
  147. This routine can only be called inside a DPC.
  148. --*/
  149. {
  150. ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
  151. ASSERT(HwDeviceExtension != NULL);
  152. ASSERT(SpinLock != NULL);
  153. KeReleaseSpinLockFromDpcLevel(&SpinLock->Lock);
  154. }
  155. VP_STATUS
  156. VideoPortCreateEvent(
  157. IN PVOID HwDeviceExtension,
  158. IN ULONG EventFlag,
  159. PVOID Unused,
  160. OUT PEVENT *ppEvent
  161. )
  162. {
  163. ULONG size;
  164. PEVENT p;
  165. EVENT_TYPE EventType;
  166. size = sizeof(VIDEO_PORT_EVENT);
  167. //
  168. // Align size to next higher multiple of 8.
  169. //
  170. size = (size + 7) & ~7;
  171. p = (PEVENT) ExAllocatePoolWithTag( NonPagedPool,
  172. size + sizeof(KEVENT),
  173. VP_TAG );
  174. if ( p ) {
  175. p->fFlags = 0;
  176. p->pKEvent = (PUCHAR) p + size;
  177. if( (EventFlag & EVENT_TYPE_MASK) == NOTIFICATION_EVENT ) {
  178. EventType = NotificationEvent;
  179. } else {
  180. EventType = SynchronizationEvent;
  181. }
  182. KeInitializeEvent( p->pKEvent,
  183. EventType,
  184. (BOOLEAN) (EventFlag & INITIAL_EVENT_STATE_MASK ) );
  185. *ppEvent = p;
  186. return NO_ERROR;
  187. } else {
  188. return ERROR_NOT_ENOUGH_MEMORY;
  189. }
  190. }
  191. VP_STATUS
  192. VideoPortDeleteEvent(
  193. IN PVOID HwDeviceExtension,
  194. IN PEVENT pEvent
  195. )
  196. {
  197. if ( pEvent == NULL ) {
  198. pVideoDebugPrint((Error, "VideoPortDeleteEvent: Can't delete NULL event\n"));
  199. ASSERT(FALSE);
  200. return ERROR_INVALID_PARAMETER;
  201. }
  202. if ( pEvent->fFlags & ENG_EVENT_FLAG_IS_MAPPED_USER ) {
  203. pVideoDebugPrint((Error, "VideoPortDeleteEvent: Can't delete mapped user event\n"));
  204. ASSERT(FALSE);
  205. return ERROR_INVALID_PARAMETER;
  206. }
  207. if( pEvent->pKEvent == NULL ) {
  208. pVideoDebugPrint((Error, "VideoPortDeleteEvent: pKEvent is NULL\n"));
  209. ASSERT(FALSE);
  210. return ERROR_INVALID_PARAMETER;
  211. }
  212. ExFreePool( (PVOID) pEvent );
  213. return NO_ERROR;
  214. }
  215. LONG
  216. VideoPortSetEvent(
  217. IN PVOID HwDeviceExtension,
  218. IN PEVENT pEvent
  219. )
  220. {
  221. return( KeSetEvent(pEvent->pKEvent, 0, FALSE) );
  222. }
  223. VOID
  224. VideoPortClearEvent(
  225. IN PVOID HwDeviceExtension,
  226. IN PEVENT pEvent
  227. )
  228. {
  229. KeClearEvent(pEvent->pKEvent);
  230. }
  231. LONG
  232. VideoPortReadStateEvent(
  233. IN PVOID HwDeviceExtension,
  234. IN PEVENT pEvent
  235. )
  236. {
  237. return ( KeReadStateEvent(pEvent->pKEvent) );
  238. }
  239. VP_STATUS
  240. VideoPortWaitForSingleObject(
  241. IN PVOID HwDeviceExtension,
  242. IN PVOID pEvent,
  243. IN PLARGE_INTEGER Timeout
  244. )
  245. {
  246. NTSTATUS status;
  247. if ( pEvent == NULL ) {
  248. return ERROR_INVALID_PARAMETER;
  249. }
  250. if( ((PEVENT) pEvent)->pKEvent == NULL) {
  251. return ERROR_INVALID_PARAMETER;
  252. }
  253. if (( (PEVENT) pEvent)->fFlags & ENG_EVENT_FLAG_IS_MAPPED_USER ) {
  254. pVideoDebugPrint((Error, "VideoPortVideoPortWaitForSingleObject: No wait ing on mapped user event\n")) ;
  255. ASSERT(FALSE);
  256. return ERROR_INVALID_PARAMETER;
  257. }
  258. status = KeWaitForSingleObject( ((PEVENT) pEvent)->pKEvent,
  259. Executive,
  260. KernelMode,
  261. FALSE,
  262. Timeout );
  263. if (status == STATUS_TIMEOUT) {
  264. return WAIT_TIMEOUT;
  265. } else if (NT_SUCCESS(status)) {
  266. return NO_ERROR;
  267. } else {
  268. return ERROR_INVALID_PARAMETER;
  269. }
  270. }