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.

295 lines
8.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 entire implementation of
  13. the watchdog miniport for the ServerWorks
  14. CSB5 server chip set.
  15. Author:
  16. Wesley Witt (wesw) 1-Oct-2001
  17. Environment:
  18. Kernel mode only.
  19. Notes:
  20. --*/
  21. #include "swwd.h"
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text(INIT,DriverEntry)
  24. #endif
  25. NTSTATUS
  26. SaWdDeviceIoctl(
  27. IN PVOID DeviceExtensionIn,
  28. IN PIRP Irp,
  29. IN PVOID FsContext,
  30. IN ULONG FunctionCode,
  31. IN PVOID InputBuffer,
  32. IN ULONG InputBufferLength,
  33. IN PVOID OutputBuffer,
  34. IN ULONG OutputBufferLength
  35. )
  36. /*++
  37. Routine Description:
  38. This function is called by the SAPORT driver so that
  39. the mini-port driver can service an IOCTL call.
  40. Arguments:
  41. DeviceExtensionIn - A pointer to the mini-port's device extension
  42. Irp - IO request packet pointer
  43. FsContext - Context pointer
  44. FunctionCode - The IOCTL function code
  45. InputBuffer - Pointer to the input buffer, contains the data sent down by the I/O
  46. InputBufferLength - Length in bytes of the InputBuffer
  47. OutputBuffer - Pointer to the output buffer, contains the data generated by this call
  48. OutputBufferLength - Length in bytes of the OutputBuffer
  49. Context:
  50. IRQL: IRQL PASSIVE_LEVEL, arbitrary thread context
  51. Return Value:
  52. If the function succeeds, it must return STATUS_SUCCESS.
  53. Otherwise, it must return one of the error status values defined in ntstatus.h.
  54. --*/
  55. {
  56. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceExtensionIn;
  57. NTSTATUS Status = STATUS_SUCCESS;
  58. PSA_WD_CAPS WdCaps = NULL;
  59. UCHAR Control;
  60. ULONG TimerValue;
  61. switch (FunctionCode) {
  62. case FUNC_SA_GET_VERSION:
  63. *((PULONG)OutputBuffer) = SA_INTERFACE_VERSION;
  64. break;
  65. case FUNC_SA_GET_CAPABILITIES:
  66. WdCaps = (PSA_WD_CAPS)OutputBuffer;
  67. WdCaps->SizeOfStruct = sizeof(SA_WD_CAPS);
  68. WdCaps->Minimum = 1;
  69. WdCaps->Maximum = 512;
  70. break;
  71. case FUNC_SAWD_DISABLE:
  72. ExAcquireFastMutex( &DeviceExtension->WdIoLock );
  73. Control = READ_REGISTER_UCHAR( DeviceExtension->WdMemBase );
  74. if (*((PULONG)InputBuffer) == 1) {
  75. SETBITS( Control, WATCHDOG_CONTROL_ENABLE );
  76. SETBITS( Control, WATCHDOG_CONTROL_TRIGGER );
  77. } else {
  78. CLEARBITS( Control, WATCHDOG_CONTROL_ENABLE );
  79. }
  80. WRITE_REGISTER_UCHAR( DeviceExtension->WdMemBase, Control );
  81. ExReleaseFastMutex( &DeviceExtension->WdIoLock );
  82. break;
  83. case FUNC_SAWD_QUERY_EXPIRE_BEHAVIOR:
  84. ExAcquireFastMutex( &DeviceExtension->WdIoLock );
  85. Control = READ_REGISTER_UCHAR( DeviceExtension->WdMemBase );
  86. if (Control & WATCHDOG_CONTROL_TIMER_MODE) {
  87. *((PULONG)OutputBuffer) = 1;
  88. } else {
  89. *((PULONG)OutputBuffer) = 0;
  90. }
  91. ExReleaseFastMutex( &DeviceExtension->WdIoLock );
  92. break;
  93. case FUNC_SAWD_SET_EXPIRE_BEHAVIOR:
  94. ExAcquireFastMutex( &DeviceExtension->WdIoLock );
  95. Control = READ_REGISTER_UCHAR( DeviceExtension->WdMemBase );
  96. if (*((PULONG)InputBuffer) == 1) {
  97. SETBITS( Control, WATCHDOG_CONTROL_TIMER_MODE );
  98. } else {
  99. CLEARBITS( Control, WATCHDOG_CONTROL_TIMER_MODE );
  100. }
  101. WRITE_REGISTER_UCHAR( DeviceExtension->WdMemBase, Control );
  102. ExReleaseFastMutex( &DeviceExtension->WdIoLock );
  103. break;
  104. case FUNC_SAWD_PING:
  105. ExAcquireFastMutex( &DeviceExtension->WdIoLock );
  106. Control = READ_REGISTER_UCHAR( DeviceExtension->WdMemBase );
  107. SETBITS( Control, WATCHDOG_CONTROL_TRIGGER );
  108. WRITE_REGISTER_UCHAR( DeviceExtension->WdMemBase, Control );
  109. ExReleaseFastMutex( &DeviceExtension->WdIoLock );
  110. break;
  111. case FUNC_SAWD_QUERY_TIMER:
  112. ExAcquireFastMutex( &DeviceExtension->WdIoLock );
  113. TimerValue = READ_REGISTER_ULONG( (PULONG)(DeviceExtension->WdMemBase+4) );
  114. *((PULONG)OutputBuffer) = TimerValue & 0x1ff;
  115. ExReleaseFastMutex( &DeviceExtension->WdIoLock );
  116. break;
  117. case FUNC_SAWD_SET_TIMER:
  118. ExAcquireFastMutex( &DeviceExtension->WdIoLock );
  119. TimerValue = *((PULONG)InputBuffer) & 0x1ff;
  120. WRITE_REGISTER_ULONG( (PULONG)(DeviceExtension->WdMemBase+4), TimerValue );
  121. ExReleaseFastMutex( &DeviceExtension->WdIoLock );
  122. break;
  123. default:
  124. Status = STATUS_NOT_SUPPORTED;
  125. REPORT_ERROR( SA_DEVICE_WATCHDOG, "Unsupported device control", Status );
  126. break;
  127. }
  128. return Status;
  129. }
  130. NTSTATUS
  131. SaWdHwInitialize(
  132. IN PDEVICE_OBJECT DeviceObject,
  133. IN PIRP Irp,
  134. IN PVOID DeviceExtensionIn,
  135. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialResources,
  136. IN ULONG PartialResourceCount
  137. )
  138. /*++
  139. Routine Description:
  140. This function is called by the SAPORT driver so that
  141. the mini-port driver can initialize it's hardware
  142. resources.
  143. Arguments:
  144. DeviceObject - Pointer to the target device object.
  145. Irp - Pointer to an IRP structure that describes the requested I/O operation.
  146. DeviceExtension - A pointer to the mini-port's device extension.
  147. PartialResources - Pointer to the translated resources alloacted by the system.
  148. PartialResourceCount - The number of resources in the PartialResources array.
  149. Context:
  150. IRQL: IRQL PASSIVE_LEVEL, system thread context
  151. Return Value:
  152. If the function succeeds, it must return STATUS_SUCCESS.
  153. Otherwise, it must return one of the error status values defined in ntstatus.h.
  154. --*/
  155. {
  156. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceExtensionIn;
  157. NTSTATUS Status;
  158. ULONG i;
  159. PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceMemory = NULL;
  160. for (i=0; i<PartialResourceCount; i++) {
  161. if (PartialResources[i].Type == CmResourceTypeMemory) {
  162. ResourceMemory = &PartialResources[i];
  163. }
  164. }
  165. if (ResourceMemory == NULL) {
  166. REPORT_ERROR( SA_DEVICE_WATCHDOG, "Missing memory resource", STATUS_UNSUCCESSFUL );
  167. return STATUS_UNSUCCESSFUL;
  168. }
  169. //
  170. // Setup the memory base address
  171. //
  172. DeviceExtension->WdMemBase = (PUCHAR) SaPortGetVirtualAddress(
  173. DeviceExtension,
  174. ResourceMemory->u.Memory.Start,
  175. ResourceMemory->u.Memory.Length
  176. );
  177. if (DeviceExtension->WdMemBase == NULL) {
  178. REPORT_ERROR( SA_DEVICE_WATCHDOG, "SaPortGetVirtualAddress failed", STATUS_NO_MEMORY );
  179. return STATUS_NO_MEMORY;
  180. }
  181. ExInitializeFastMutex( &DeviceExtension->WdIoLock );
  182. return STATUS_SUCCESS;
  183. }
  184. NTSTATUS
  185. DriverEntry(
  186. IN PDRIVER_OBJECT DriverObject,
  187. IN PUNICODE_STRING RegistryPath
  188. )
  189. /*++
  190. Routine Description:
  191. This routine is the driver's entry point, called by the I/O system
  192. to load the driver. The driver's entry points are initialized and
  193. a mutex to control paging is initialized.
  194. In DBG mode, this routine also examines the registry for special
  195. debug parameters.
  196. Arguments:
  197. DriverObject - a pointer to the object that represents this device driver.
  198. RegistryPath - a pointer to this driver's key in the Services tree.
  199. Return Value:
  200. STATUS_SUCCESS
  201. --*/
  202. {
  203. NTSTATUS Status;
  204. SAPORT_INITIALIZATION_DATA SaPortInitData;
  205. RtlZeroMemory( &SaPortInitData, sizeof(SAPORT_INITIALIZATION_DATA) );
  206. SaPortInitData.StructSize = sizeof(SAPORT_INITIALIZATION_DATA);
  207. SaPortInitData.DeviceType = SA_DEVICE_WATCHDOG;
  208. SaPortInitData.HwInitialize = SaWdHwInitialize;
  209. SaPortInitData.DeviceIoctl = SaWdDeviceIoctl;
  210. SaPortInitData.DeviceExtensionSize = sizeof(DEVICE_EXTENSION);
  211. Status = SaPortInitialize( DriverObject, RegistryPath, &SaPortInitData );
  212. if (!NT_SUCCESS(Status)) {
  213. REPORT_ERROR( SA_DEVICE_WATCHDOG, "SaPortInitialize failed\n", Status );
  214. return Status;
  215. }
  216. return STATUS_SUCCESS;
  217. }