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.

213 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: sync.c
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pciidex.h"
  11. #ifdef ALLOC_PRAGMA
  12. #pragma alloc_text(PAGE, PciIdeCreateSyncChildAccess)
  13. #pragma alloc_text(PAGE, PciIdeDeleteSyncChildAccess)
  14. #pragma alloc_text(PAGE, PciIdeQuerySyncAccessInterface)
  15. #pragma alloc_text(PAGE, PciIdeSyncAccessRequired)
  16. #pragma alloc_text(NONPAGE, PciIdeAllocateAccessToken)
  17. #pragma alloc_text(NONPAGE, PciIdeFreeAccessToken)
  18. #endif // ALLOC_PRAGMA
  19. //
  20. // Must match mshdc.inf
  21. //
  22. static PWCHAR SyncAccess = L"SyncAccess";
  23. NTSTATUS
  24. PciIdeCreateSyncChildAccess (
  25. PCTRLFDO_EXTENSION FdoExtension
  26. )
  27. {
  28. BOOLEAN syncAccessNeeded;
  29. PAGED_CODE();
  30. syncAccessNeeded = FALSE;
  31. if (FdoExtension->TranslatedBusMasterBaseAddress) {
  32. UCHAR bmRawStatus;
  33. bmRawStatus = READ_PORT_UCHAR (&FdoExtension->TranslatedBusMasterBaseAddress->Status);
  34. if (bmRawStatus & BUSMASTER_DMA_SIMPLEX_BIT) {
  35. syncAccessNeeded = TRUE;
  36. }
  37. }
  38. if (syncAccessNeeded == FALSE) {
  39. syncAccessNeeded = PciIdeSyncAccessRequired (
  40. FdoExtension
  41. );
  42. }
  43. if (syncAccessNeeded) {
  44. DebugPrint ((1, "PCIIDEX: Serialize access to both channels\n"));
  45. FdoExtension->ControllerObject = IoCreateController (0);
  46. ASSERT (FdoExtension->ControllerObject);
  47. if (FdoExtension->ControllerObject) {
  48. return STATUS_SUCCESS;
  49. } else {
  50. return STATUS_INSUFFICIENT_RESOURCES;
  51. }
  52. }
  53. return STATUS_SUCCESS;
  54. } // PciIdeCreateSyncChildAccess
  55. VOID
  56. PciIdeDeleteSyncChildAccess (
  57. PCTRLFDO_EXTENSION FdoExtension
  58. )
  59. {
  60. PAGED_CODE();
  61. if (FdoExtension->ControllerObject) {
  62. IoDeleteController (FdoExtension->ControllerObject);
  63. FdoExtension->ControllerObject = NULL;
  64. }
  65. return;
  66. } // PciIdeDeleteSyncChildAccess
  67. NTSTATUS
  68. PciIdeQuerySyncAccessInterface (
  69. PCHANPDO_EXTENSION PdoExtension,
  70. PPCIIDE_SYNC_ACCESS_INTERFACE SyncAccessInterface
  71. )
  72. {
  73. PAGED_CODE();
  74. if (SyncAccessInterface == NULL) {
  75. return STATUS_INVALID_PARAMETER;
  76. }
  77. if (!PdoExtension->ParentDeviceExtension->ControllerObject) {
  78. SyncAccessInterface->AllocateAccessToken = NULL;
  79. SyncAccessInterface->FreeAccessToken = NULL;
  80. SyncAccessInterface->Token = NULL;
  81. } else {
  82. SyncAccessInterface->AllocateAccessToken = PciIdeAllocateAccessToken;
  83. SyncAccessInterface->FreeAccessToken = PciIdeFreeAccessToken;
  84. SyncAccessInterface->Token = PdoExtension;
  85. }
  86. return STATUS_SUCCESS;
  87. } // PciIdeQuerySyncAccessInterface
  88. static ULONG tokenAccessCount=0;
  89. //
  90. // IRQL must be DISPATCH_LEVEL;
  91. //
  92. NTSTATUS
  93. PciIdeAllocateAccessToken (
  94. PVOID Token,
  95. PDRIVER_CONTROL Callback,
  96. PVOID CallbackContext
  97. )
  98. {
  99. PCHANPDO_EXTENSION pdoExtension = Token;
  100. PCTRLFDO_EXTENSION FdoExtension;
  101. ASSERT (Token);
  102. ASSERT (KeGetCurrentIrql() == DISPATCH_LEVEL);
  103. FdoExtension = pdoExtension->ParentDeviceExtension;
  104. tokenAccessCount++;
  105. IoAllocateController (
  106. FdoExtension->ControllerObject,
  107. FdoExtension->DeviceObject,
  108. Callback,
  109. CallbackContext
  110. );
  111. return STATUS_SUCCESS;
  112. } // PciIdeAllocateAccessToken
  113. NTSTATUS
  114. PciIdeFreeAccessToken (
  115. PVOID Token
  116. )
  117. {
  118. PCHANPDO_EXTENSION pdoExtension = Token;
  119. PCTRLFDO_EXTENSION FdoExtension;
  120. FdoExtension = pdoExtension->ParentDeviceExtension;
  121. tokenAccessCount--;
  122. IoFreeController (
  123. FdoExtension->ControllerObject
  124. );
  125. return STATUS_SUCCESS;
  126. } // PciIdeFreeAccessToken
  127. BOOLEAN
  128. PciIdeSyncAccessRequired (
  129. IN PCTRLFDO_EXTENSION FdoExtension
  130. )
  131. {
  132. NTSTATUS status;
  133. ULONG syncAccess;
  134. PAGED_CODE();
  135. syncAccess = 0;
  136. status = PciIdeXGetDeviceParameter (
  137. FdoExtension->AttacheePdo,
  138. SyncAccess,
  139. &syncAccess
  140. );
  141. if (NT_SUCCESS(status)) {
  142. return (syncAccess != 0);
  143. } else {
  144. DebugPrint ((1, "PciIdeX: Unable to get SyncAccess flag from the registry\n"));
  145. }
  146. if (FdoExtension->ControllerProperties.PciIdeSyncAccessRequired) {
  147. return FdoExtension->ControllerProperties.PciIdeSyncAccessRequired (
  148. FdoExtension->VendorSpecificDeviceEntension
  149. );
  150. }
  151. DebugPrint ((1, "PciIdeX: assume sync access not required\n"));
  152. return FALSE;
  153. } // PciIdeSyncAccessRequired