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.

145 lines
2.5 KiB

  1. #include <ndis.h>
  2. #include "dmautil.h"
  3. BOOLEAN
  4. IsIrqlGreaterThanDispatch(
  5. VOID
  6. );
  7. VOID
  8. InitializeDmaUtil(
  9. PDMA_UTIL DmaUtil,
  10. NDIS_HANDLE DmaHandle
  11. )
  12. {
  13. RtlZeroMemory(
  14. DmaUtil,
  15. sizeof(*DmaUtil)
  16. );
  17. DmaUtil->NdisDmaHandle=DmaHandle;
  18. return;
  19. }
  20. NTSTATUS
  21. StartDmaTransfer(
  22. PDMA_UTIL DmaUtil,
  23. PNDIS_BUFFER Buffer,
  24. ULONG Offset,
  25. ULONG Length,
  26. BOOLEAN ToDevice
  27. )
  28. {
  29. NDIS_STATUS Status;
  30. if (IsIrqlGreaterThanDispatch()) {
  31. #if DBG
  32. DbgPrint("IR-DMAUTIL: Transfer started at raised IRQL\n");
  33. #endif
  34. ASSERT(0);
  35. return STATUS_UNSUCCESSFUL;
  36. }
  37. if (DmaUtil->Buffer != NULL) {
  38. #if DBG
  39. DbgPrint("IR-DMAUTIL: Transfer started when one is already in progress\n");
  40. #endif
  41. ASSERT(0);
  42. return STATUS_UNSUCCESSFUL;
  43. }
  44. DmaUtil->Buffer=Buffer;
  45. DmaUtil->Offset=Offset;
  46. DmaUtil->Length=Length;
  47. DmaUtil->Direction=ToDevice;
  48. NdisMSetupDmaTransfer(
  49. &Status,
  50. DmaUtil->NdisDmaHandle,
  51. Buffer,
  52. Offset,
  53. Length,
  54. ToDevice
  55. );
  56. if (Status != STATUS_SUCCESS) {
  57. #if DBG
  58. DbgPrint("IR-DMAUTIL: NdisMSetupDmaTransfer() failed %08lx\n",Status);
  59. #endif
  60. DmaUtil->Buffer=NULL;
  61. }
  62. return Status;
  63. }
  64. NTSTATUS
  65. CompleteDmaTransfer(
  66. PDMA_UTIL DmaUtil,
  67. BOOLEAN ToDevice
  68. )
  69. {
  70. NDIS_STATUS Status;
  71. if (IsIrqlGreaterThanDispatch()) {
  72. #if DBG
  73. DbgPrint("IR-DMAUTIL: CompleteTransfer called at raised IRQL\n");
  74. #endif
  75. ASSERT(0);
  76. return STATUS_UNSUCCESSFUL;
  77. }
  78. if (DmaUtil->Buffer == NULL) {
  79. #if DBG
  80. DbgPrint("IR-DMAUTIL: CompleteTransfer called when no transfer it active\n");
  81. #endif
  82. ASSERT(0);
  83. return STATUS_UNSUCCESSFUL;
  84. }
  85. if (ToDevice != DmaUtil->Direction) {
  86. #if DBG
  87. DbgPrint("IR-DMAUTIL: CompleteTransfer called for the wrong direction of transfer\n");
  88. #endif
  89. ASSERT(0);
  90. return STATUS_UNSUCCESSFUL;
  91. }
  92. NdisMCompleteDmaTransfer(
  93. &Status,
  94. DmaUtil->NdisDmaHandle,
  95. DmaUtil->Buffer,
  96. DmaUtil->Offset,
  97. DmaUtil->Length,
  98. DmaUtil->Direction
  99. );
  100. if (Status != STATUS_SUCCESS) {
  101. #if DBG
  102. DbgPrint("IR-DMAUTIL: NdisMCompleteDmaTransfer() failed %08lx\n",Status);
  103. #endif
  104. }
  105. DmaUtil->Buffer=NULL;
  106. return Status;
  107. }