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.

286 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1991 - 2001 Microsoft Corporation
  3. Module Name:
  4. ## ## ### #### ## # #### ##### #####
  5. ### ### ### ## ### # ## # ## ## ## ##
  6. ######## ## ## ## #### # ## ## ## ## ##
  7. # ### ## ## ## ## # #### ## ## ## ## ##
  8. # # ## ####### ## # ### ## ##### #####
  9. # ## ## ## ## # ## ## ## # ## ##
  10. # ## ## ## #### # # ## #### ## ##
  11. Abstract:
  12. This module contains the driver initializtion code.
  13. Author:
  14. Wesley Witt (wesw) 23-Jan-2002
  15. Environment:
  16. Kernel mode only.
  17. Notes:
  18. --*/
  19. #include "internal.h"
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(INIT,DriverEntry)
  22. #pragma alloc_text(PAGE,WdSystemControl)
  23. #pragma alloc_text(PAGE,WdDefaultDispatch)
  24. #pragma alloc_text(PAGE,WdShutdown)
  25. #endif
  26. //
  27. // Watchdog timer resource table
  28. //
  29. PWATCHDOG_TIMER_RESOURCE_TABLE WdTable;
  30. //
  31. // Control values
  32. //
  33. ULONG ShutdownCountTime;
  34. ULONG RunningCountTime;
  35. NTSTATUS
  36. DriverEntry(
  37. IN PDRIVER_OBJECT DriverObject,
  38. IN PUNICODE_STRING RegistryPath
  39. )
  40. /*++
  41. Routine Description:
  42. Temporary entry point needed to initialize the scsi port driver.
  43. Arguments:
  44. DriverObject - Pointer to the driver object created by the system.
  45. RegistryPath - String containing the path to the driver's registry data
  46. Return Value:
  47. STATUS_SUCCESS
  48. --*/
  49. {
  50. NTSTATUS Status = STATUS_SUCCESS;
  51. PKEY_VALUE_FULL_INFORMATION KeyInformation = NULL;
  52. PVOID WdTableTmp;
  53. #if DBG
  54. //
  55. // Get the debug level value from the registry
  56. //
  57. WdDebugLevel = 0;
  58. Status = ReadRegistryValue( RegistryPath, L"DebugLevel", &KeyInformation );
  59. if (NT_SUCCESS(Status) && KeyInformation->Type == REG_DWORD) {
  60. WdDebugLevel = *(PULONG)((PUCHAR)KeyInformation + KeyInformation->DataOffset);
  61. }
  62. if (KeyInformation) {
  63. ExFreePool( KeyInformation );
  64. }
  65. //
  66. // Get the OS version; this is used by the
  67. // port driver and the mini-ports to have
  68. // OS dependent code that is dynamic at runtime
  69. //
  70. GetOsVersion();
  71. //
  72. // Print a banner that includes the
  73. // OS version and the version/build date
  74. // of the driver
  75. //
  76. PrintDriverVersion( DriverObject );
  77. #endif
  78. //
  79. // Read in the registry control values
  80. //
  81. Status = ReadRegistryValue( RegistryPath, L"RunningCountTime", &KeyInformation );
  82. if (NT_SUCCESS(Status) && KeyInformation->Type == REG_DWORD) {
  83. RunningCountTime = *(PULONG)((PUCHAR)KeyInformation + KeyInformation->DataOffset);
  84. }
  85. if (KeyInformation) {
  86. ExFreePool( KeyInformation );
  87. }
  88. Status = ReadRegistryValue( RegistryPath, L"ShutdownCountTime", &KeyInformation );
  89. if (NT_SUCCESS(Status) && KeyInformation->Type == REG_DWORD) {
  90. ShutdownCountTime = *(PULONG)((PUCHAR)KeyInformation + KeyInformation->DataOffset);
  91. }
  92. if (KeyInformation) {
  93. ExFreePool( KeyInformation );
  94. }
  95. //
  96. // Set up the device driver entry points.
  97. //
  98. for (ULONG i=0; i<=IRP_MJ_MAXIMUM_FUNCTION; i++) {
  99. DriverObject->MajorFunction[i] = WdDefaultDispatch;
  100. }
  101. //
  102. // Set up the device driver's pnp-power routine & add routine
  103. //
  104. DriverObject->DriverExtension->AddDevice = WdAddDevice;
  105. //
  106. // Get a copy of the watchdog ACPI fixed table
  107. //
  108. WdTableTmp = (PVOID) WdGetAcpiTable( WDTT_SIGNATURE );
  109. if (WdTableTmp) {
  110. DriverObject->MajorFunction[IRP_MJ_PNP] = WdPnp;
  111. DriverObject->MajorFunction[IRP_MJ_POWER] = WdPower;
  112. DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = WdShutdown;
  113. DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = WdSystemControl;
  114. WdTable = (PWATCHDOG_TIMER_RESOURCE_TABLE) ExAllocatePool( NonPagedPool, sizeof(WATCHDOG_TIMER_RESOURCE_TABLE) );
  115. if (WdTable == NULL) {
  116. return STATUS_INSUFFICIENT_RESOURCES;
  117. }
  118. RtlCopyMemory( WdTable, WdTableTmp, sizeof(WATCHDOG_TIMER_RESOURCE_TABLE) );
  119. //
  120. // Validate the registry settings
  121. //
  122. if (RunningCountTime) {
  123. RunningCountTime = ConvertTimeoutFromMilliseconds( WdTable->Units, RunningCountTime );
  124. if (RunningCountTime > WdTable->MaxCount) {
  125. RunningCountTime = WdTable->MaxCount;
  126. }
  127. }
  128. if (ShutdownCountTime) {
  129. ShutdownCountTime = ConvertTimeoutFromMilliseconds( WdTable->Units, ShutdownCountTime );
  130. if (ShutdownCountTime > WdTable->MaxCount) {
  131. ShutdownCountTime = WdTable->MaxCount;
  132. }
  133. }
  134. }
  135. return STATUS_SUCCESS;
  136. }
  137. NTSTATUS
  138. WdDefaultDispatch(
  139. IN PDEVICE_OBJECT DeviceObject,
  140. IN PIRP Irp
  141. )
  142. /*++
  143. Routine Description:
  144. This routine is the default dispatch which passes down to the next layer.
  145. Arguments:
  146. DeviceObject - Supplies the device object.
  147. Irp - Supplies the IO request packet.
  148. Return Value:
  149. NTSTATUS
  150. --*/
  151. {
  152. UNREFERENCED_PARAMETER(DeviceObject);
  153. return CompleteRequest( Irp, STATUS_INVALID_DEVICE_REQUEST, 0 );
  154. }
  155. NTSTATUS
  156. WdSystemControl(
  157. IN PDEVICE_OBJECT DeviceObject,
  158. IN PIRP Irp
  159. )
  160. /*++
  161. Routine Description:
  162. IRP_MJ_SYSTEM_CONTROL dispatch routine. Currently, we don't handle
  163. this. So, if this is FDO just pass it to the lower driver. If this
  164. is PDO complete the irp with changing the irp status.
  165. Arguments:
  166. DeviceObject - a pointer to the object that represents the device that I/O is to be done on.
  167. Irp - a pointer to the I/O Request Packet for this request.
  168. Return Value:
  169. --*/
  170. {
  171. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  172. IoSkipCurrentIrpStackLocation( Irp );
  173. return IoCallDriver( DeviceExtension->TargetObject, Irp );
  174. }
  175. NTSTATUS
  176. WdShutdown(
  177. IN PDEVICE_OBJECT DeviceObject,
  178. IN PIRP Irp
  179. )
  180. /*++
  181. Routine Description:
  182. This routine is called only rarely by the I/O system; it's mainly
  183. for layered drivers to call. All it does is complete the IRP
  184. successfully.
  185. Arguments:
  186. DeviceObject - a pointer to the object that represents the device that I/O is to be done on.
  187. Irp - a pointer to the I/O Request Packet for this request.
  188. Return Value:
  189. Always returns STATUS_SUCCESS, since this is a null operation.
  190. --*/
  191. {
  192. NTSTATUS Status = STATUS_SUCCESS;
  193. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  194. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
  195. return ForwardRequest( Irp, DeviceExtension->TargetObject );
  196. }