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.

354 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. sdbus.c
  5. Abstract:
  6. This module contains the code that controls the SD slots.
  7. Author:
  8. Neil Sandlin (neilsa) 1-Jan-2002
  9. Environment:
  10. Kernel mode
  11. Revision History :
  12. --*/
  13. #include "pch.h"
  14. //
  15. // Internal References
  16. //
  17. NTSTATUS
  18. DriverEntry(
  19. IN PDRIVER_OBJECT DriverObject,
  20. IN PUNICODE_STRING RegistryPath
  21. );
  22. VOID
  23. SdbusUnload(
  24. IN PDRIVER_OBJECT DriverObject
  25. );
  26. #ifdef ALLOC_PRAGMA
  27. #pragma alloc_text(INIT,DriverEntry)
  28. #pragma alloc_text(PAGE, SdbusUnload)
  29. #pragma alloc_text(PAGE, SdbusOpenCloseDispatch)
  30. #pragma alloc_text(PAGE, SdbusCleanupDispatch)
  31. #pragma alloc_text(PAGE, SdbusFdoSystemControl)
  32. #pragma alloc_text(PAGE, SdbusPdoSystemControl)
  33. #endif
  34. PUNICODE_STRING DriverRegistryPath;
  35. NTSTATUS
  36. DriverEntry(
  37. IN PDRIVER_OBJECT DriverObject,
  38. IN PUNICODE_STRING RegistryPath
  39. )
  40. /*++
  41. Routine Description:
  42. The entry point that the system point calls to initialize
  43. any driver.
  44. Since this is a plug'n'play driver, we should return after setting
  45. the entry points & initializing our dispatch table.
  46. Currently we also detect our own SDBUS controllers and report
  47. them - which should not be needed in the future when a root bus
  48. driver such as PCI or ISAPNP will locate the controllers for us.
  49. Arguments:
  50. DriverObject - Pointer to object representing this driver
  51. RegistryPath - Pointer the the registry key for this driver
  52. under \CurrentControlSet\Services
  53. Return Value:
  54. --*/
  55. {
  56. NTSTATUS status = STATUS_SUCCESS;
  57. ULONG i;
  58. PAGED_CODE();
  59. #if DBG
  60. SdbusInitializeDbgLog(ExAllocatePool(NonPagedPool, DBGLOGWIDTH * DBGLOGCOUNT));
  61. SdbusClearDbgLog();
  62. #endif
  63. DebugPrint((SDBUS_DEBUG_INFO,"Initializing Driver\n"));
  64. //
  65. // Load in common parameters from the registry
  66. //
  67. status = SdbusLoadGlobalRegistryValues();
  68. if (!NT_SUCCESS(status)) {
  69. return status;
  70. }
  71. //
  72. //
  73. // Set up the device driver entry points.
  74. //
  75. DriverObject->DriverExtension->AddDevice = SdbusAddDevice;
  76. DriverObject->DriverUnload = SdbusUnload;
  77. //
  78. //
  79. // Save our registry path
  80. DriverRegistryPath = RegistryPath;
  81. //
  82. // Initialize the event used by the delay execution
  83. // routine.
  84. //
  85. KeInitializeEvent (&SdbusDelayTimerEvent,
  86. NotificationEvent,
  87. FALSE);
  88. //
  89. // Initialize global lock
  90. //
  91. KeInitializeSpinLock(&SdbusGlobalLock);
  92. //
  93. // Init device dispatch table
  94. //
  95. SdbusInitDeviceDispatchTable(DriverObject);
  96. //
  97. // Ignore the status. Regardless of whether we found controllers or not
  98. // we need to stick around since we might get an AddDevice non-legacy
  99. // controllers
  100. //
  101. return STATUS_SUCCESS;
  102. }
  103. NTSTATUS
  104. SdbusOpenCloseDispatch(
  105. IN PDEVICE_OBJECT DeviceObject,
  106. IN PIRP Irp
  107. )
  108. /*++
  109. Routine Description:
  110. Open or Close device routine
  111. Arguments:
  112. DeviceObject - Pointer to the device object.
  113. Irp - Pointer to the IRP
  114. Return Value:
  115. Status
  116. --*/
  117. {
  118. NTSTATUS status;
  119. PAGED_CODE();
  120. DebugPrint((SDBUS_DEBUG_INFO, "SDBUS: Open / close of Sdbus controller for IO \n"));
  121. status = STATUS_SUCCESS;
  122. Irp->IoStatus.Status = STATUS_SUCCESS;
  123. Irp->IoStatus.Information = 0;
  124. IoCompleteRequest(Irp, 0);
  125. return status;
  126. }
  127. NTSTATUS
  128. SdbusCleanupDispatch(
  129. IN PDEVICE_OBJECT DeviceObject,
  130. IN PIRP Irp
  131. )
  132. /*++
  133. Routine Description:
  134. Handles IRP_MJ_CLEANUP
  135. Arguments:
  136. DeviceObject - Pointer to the device object.
  137. Irp - Pointer to the IRP
  138. Return Value:
  139. Status
  140. --*/
  141. {
  142. NTSTATUS status;
  143. PAGED_CODE();
  144. DebugPrint((SDBUS_DEBUG_INFO, "SDBUS: Cleanup of Sdbus controller for IO \n"));
  145. status = STATUS_SUCCESS;
  146. Irp->IoStatus.Status = STATUS_SUCCESS;
  147. Irp->IoStatus.Information = 0;
  148. IoCompleteRequest(Irp, 0);
  149. return status;
  150. }
  151. NTSTATUS
  152. SdbusFdoSystemControl(
  153. IN PDEVICE_OBJECT DeviceObject,
  154. IN PIRP Irp
  155. )
  156. /*++
  157. Routine Description:
  158. Handles IRP_MJ_SYSTEM_CONTROL
  159. Arguments:
  160. DeviceObject - Pointer to the device object.
  161. Irp - Pointer to the IRP
  162. Return Value:
  163. Status
  164. --*/
  165. {
  166. PFDO_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
  167. PAGED_CODE();
  168. IoSkipCurrentIrpStackLocation(Irp);
  169. return IoCallDriver(fdoExtension->LowerDevice, Irp);
  170. }
  171. NTSTATUS
  172. SdbusPdoSystemControl(
  173. IN PDEVICE_OBJECT DeviceObject,
  174. IN PIRP Irp
  175. )
  176. /*++
  177. Routine Description:
  178. Handles IRP_MJ_SYSTEM_CONTROL
  179. Arguments:
  180. DeviceObject - Pointer to the device object.
  181. Irp - Pointer to the IRP
  182. Return Value:
  183. Status
  184. --*/
  185. {
  186. NTSTATUS status;
  187. PPDO_EXTENSION pdoExtension = DeviceObject->DeviceExtension;
  188. PAGED_CODE();
  189. //
  190. // Complete the irp
  191. //
  192. status = Irp->IoStatus.Status;
  193. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  194. return status;
  195. }
  196. VOID
  197. SdbusUnload(
  198. IN PDRIVER_OBJECT DriverObject
  199. )
  200. /*++
  201. Description:
  202. Unloads the driver after cleaning up
  203. Arguments:
  204. DriverObject -- THe device drivers object
  205. Return Value:
  206. None
  207. --*/
  208. {
  209. PDEVICE_OBJECT fdo, pdo, nextFdo, nextPdo;
  210. PFDO_EXTENSION fdoExtension;
  211. PAGED_CODE();
  212. DebugPrint((SDBUS_DEBUG_INFO, "SdbusUnload Entered\n"));
  213. for (fdo = FdoList; fdo !=NULL ; fdo = nextFdo) {
  214. fdoExtension = fdo->DeviceExtension;
  215. MarkDeviceDeleted(fdoExtension);
  216. if (fdoExtension->SdbusInterruptObject) {
  217. IoDisconnectInterrupt(fdoExtension->SdbusInterruptObject);
  218. }
  219. //
  220. // Clean up all the PDOs
  221. //
  222. for (pdo=fdoExtension->PdoList; pdo != NULL; pdo=nextPdo) {
  223. nextPdo = ((PPDO_EXTENSION) pdo->DeviceExtension)->NextPdoInFdoChain;
  224. MarkDeviceDeleted((PPDO_EXTENSION)pdo->DeviceExtension);
  225. SdbusCleanupPdo(pdo);
  226. IoDeleteDevice(pdo);
  227. }
  228. IoDetachDevice(fdoExtension->LowerDevice);
  229. nextFdo = fdoExtension->NextFdo;
  230. IoDeleteDevice(fdo);
  231. }
  232. }