Source code of Windows XP (NT5)
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.

137 lines
2.3 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. DbgPrint("IR-DMAUTIL: Transfer started at raised IRQL\n");
  32. ASSERT(0);
  33. return STATUS_UNSUCCESSFUL;
  34. }
  35. if (DmaUtil->Buffer != NULL) {
  36. DbgPrint("IR-DMAUTIL: Transfer started when one is already in progress\n");
  37. ASSERT(0);
  38. return STATUS_UNSUCCESSFUL;
  39. }
  40. DmaUtil->Buffer=Buffer;
  41. DmaUtil->Offset=Offset;
  42. DmaUtil->Length=Length;
  43. DmaUtil->Direction=ToDevice;
  44. NdisMSetupDmaTransfer(
  45. &Status,
  46. DmaUtil->NdisDmaHandle,
  47. Buffer,
  48. Offset,
  49. Length,
  50. ToDevice
  51. );
  52. if (Status != STATUS_SUCCESS) {
  53. DbgPrint("IR-DMAUTIL: NdisMSetupDmaTransfer() failed %08lx\n",Status);
  54. DmaUtil->Buffer=NULL;
  55. }
  56. return Status;
  57. }
  58. NTSTATUS
  59. CompleteDmaTransfer(
  60. PDMA_UTIL DmaUtil,
  61. BOOLEAN ToDevice
  62. )
  63. {
  64. NDIS_STATUS Status;
  65. if (IsIrqlGreaterThanDispatch()) {
  66. DbgPrint("IR-DMAUTIL: CompleteTransfer called at raised IRQL\n");
  67. ASSERT(0);
  68. return STATUS_UNSUCCESSFUL;
  69. }
  70. if (DmaUtil->Buffer == NULL) {
  71. DbgPrint("IR-DMAUTIL: CompleteTransfer called when no transfer it active\n");
  72. ASSERT(0);
  73. return STATUS_UNSUCCESSFUL;
  74. }
  75. if (ToDevice != DmaUtil->Direction) {
  76. DbgPrint("IR-DMAUTIL: CompleteTransfer called for the wrong direction of transfer\n");
  77. ASSERT(0);
  78. return STATUS_UNSUCCESSFUL;
  79. }
  80. NdisMCompleteDmaTransfer(
  81. &Status,
  82. DmaUtil->NdisDmaHandle,
  83. DmaUtil->Buffer,
  84. DmaUtil->Offset,
  85. DmaUtil->Length,
  86. DmaUtil->Direction
  87. );
  88. if (Status != STATUS_SUCCESS) {
  89. DbgPrint("IR-DMAUTIL: NdisMCompleteDmaTransfer() failed %08lx\n",Status);
  90. }
  91. DmaUtil->Buffer=NULL;
  92. return Status;
  93. }