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.

203 lines
4.6 KiB

  1. /*--------------------------------------------------------------------------
  2. *
  3. * Copyright (C) Cyclades Corporation, 1996-2001.
  4. * All rights reserved.
  5. *
  6. * Cyclom-Y Port Driver
  7. *
  8. * This file: cyypurge.c
  9. *
  10. * Description: This module contains the code related to purge
  11. * operations in the Cyclom-Y Port driver.
  12. *
  13. * Notes: This code supports Windows 2000 and Windows XP,
  14. * x86 and IA64 processors.
  15. *
  16. * Complies with Cyclades SW Coding Standard rev 1.3.
  17. *
  18. *--------------------------------------------------------------------------
  19. */
  20. /*-------------------------------------------------------------------------
  21. *
  22. * Change History
  23. *
  24. *--------------------------------------------------------------------------
  25. *
  26. *
  27. *--------------------------------------------------------------------------
  28. */
  29. #include "precomp.h"
  30. #ifdef ALLOC_PRAGMA
  31. #pragma alloc_text(PAGESER,CyyStartPurge)
  32. #pragma alloc_text(PAGESER,CyyPurgeInterruptBuff)
  33. #endif
  34. NTSTATUS
  35. CyyStartPurge(
  36. IN PCYY_DEVICE_EXTENSION Extension
  37. )
  38. /*++
  39. Routine Description:
  40. Depending on the mask in the current irp, purge the interrupt
  41. buffer, the read queue, or the write queue, or all of the above.
  42. Arguments:
  43. Extension - Pointer to the device extension.
  44. Return Value:
  45. Will return STATUS_SUCCESS always. This is reasonable
  46. since the DPC completion code that calls this routine doesn't
  47. care and the purge request always goes through to completion
  48. once it's started.
  49. --*/
  50. {
  51. PIRP NewIrp;
  52. CYY_LOCKED_PAGED_CODE();
  53. do {
  54. ULONG Mask;
  55. Mask = *((ULONG *)
  56. (Extension->CurrentPurgeIrp->AssociatedIrp.SystemBuffer));
  57. if (Mask & SERIAL_PURGE_TXABORT) {
  58. CyyKillAllReadsOrWrites(
  59. Extension->DeviceObject,
  60. &Extension->WriteQueue,
  61. &Extension->CurrentWriteIrp
  62. );
  63. CyyKillAllReadsOrWrites(
  64. Extension->DeviceObject,
  65. &Extension->WriteQueue,
  66. &Extension->CurrentXoffIrp
  67. );
  68. }
  69. if (Mask & SERIAL_PURGE_RXABORT) {
  70. CyyKillAllReadsOrWrites(
  71. Extension->DeviceObject,
  72. &Extension->ReadQueue,
  73. &Extension->CurrentReadIrp
  74. );
  75. }
  76. if (Mask & SERIAL_PURGE_RXCLEAR) {
  77. KIRQL OldIrql;
  78. //
  79. // Clean out the interrupt buffer.
  80. //
  81. // Note that we do this under protection of the
  82. // the drivers control lock so that we don't hose
  83. // the pointers if there is currently a read that
  84. // is reading out of the buffer.
  85. //
  86. KeAcquireSpinLock(
  87. &Extension->ControlLock,
  88. &OldIrql
  89. );
  90. KeSynchronizeExecution(
  91. Extension->Interrupt,
  92. CyyPurgeInterruptBuff,
  93. Extension
  94. );
  95. KeReleaseSpinLock(
  96. &Extension->ControlLock,
  97. OldIrql
  98. );
  99. }
  100. Extension->CurrentPurgeIrp->IoStatus.Status = STATUS_SUCCESS;
  101. Extension->CurrentPurgeIrp->IoStatus.Information = 0;
  102. CyyGetNextIrp(
  103. &Extension->CurrentPurgeIrp,
  104. &Extension->PurgeQueue,
  105. &NewIrp,
  106. TRUE,
  107. Extension
  108. );
  109. } while (NewIrp);
  110. return STATUS_SUCCESS;
  111. }
  112. BOOLEAN
  113. CyyPurgeInterruptBuff(
  114. IN PVOID Context
  115. )
  116. /*++
  117. Routine Description:
  118. This routine simply resets the interrupt (typeahead) buffer.
  119. NOTE: This routine is being called from KeSynchronizeExecution.
  120. Arguments:
  121. Context - Really a pointer to the device extension.
  122. Return Value:
  123. Always false.
  124. --*/
  125. {
  126. PCYY_DEVICE_EXTENSION Extension = Context;
  127. CYY_LOCKED_PAGED_CODE();
  128. //
  129. // The typeahead buffer is by definition empty if there
  130. // currently is a read owned by the isr.
  131. //
  132. if (Extension->ReadBufferBase == Extension->InterruptReadBuffer) {
  133. Extension->CurrentCharSlot = Extension->InterruptReadBuffer;
  134. Extension->FirstReadableChar = Extension->InterruptReadBuffer;
  135. Extension->LastCharSlot = Extension->InterruptReadBuffer +
  136. (Extension->BufferSize - 1);
  137. Extension->CharsInInterruptBuffer = 0;
  138. CyyHandleReducedIntBuffer(Extension);
  139. }
  140. return FALSE;
  141. }
  142.