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.

171 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1991 - 2002 Microsoft Corporation
  3. Module Name:
  4. ###### #### ## ## ##### ##### #### ##### #####
  5. ## ## ### ### ## ## ## ## # ## ## ## ##
  6. ## ## ######## ## ## ## ## ## ## ## ##
  7. ## ## # ### ## ##### ##### ## ## ## ## ##
  8. ## ## # # ## ## #### ## ##### #####
  9. ## ## # ## ## ## ## ## ## # ## ##
  10. ## #### # ## ##### ## ## ## #### ## ##
  11. Abstract:
  12. This module implements the software watchdog timer
  13. component. The timer's responsibility is to simply
  14. ping the hardware timer if it is determined that the
  15. system is in a healthy state.
  16. Author:
  17. Wesley Witt (wesw) 1-Mar-2002
  18. Environment:
  19. Kernel mode only.
  20. Notes:
  21. --*/
  22. #include "internal.h"
  23. VOID
  24. PingWatchdogTimer(
  25. IN PDEVICE_EXTENSION DeviceExtension,
  26. IN BOOLEAN LockResources
  27. )
  28. /*++
  29. Routine Description:
  30. This function pings the hardware watchdog timer
  31. device. The ping occurs only if the system
  32. health is determined to be good.
  33. Arguments:
  34. DeviceExtension - Pointer to a device extension object
  35. LockResources - Specifies whether the hardware resources
  36. are to be locked for exclusive access.
  37. Return Value:
  38. None.
  39. Notes:
  40. --*/
  41. {
  42. BOOLEAN b;
  43. KLOCK_QUEUE_HANDLE LockHandle;
  44. LARGE_INTEGER DueTime;
  45. ULONG Control;
  46. b = WdCheckSystemHealth( &DeviceExtension->Health );
  47. if (b) {
  48. if (LockResources) {
  49. KeAcquireInStackQueuedSpinLockAtDpcLevel( &DeviceExtension->DeviceLock, &LockHandle );
  50. }
  51. Control = READ_REGISTER_ULONG( DeviceExtension->ControlRegisterAddress );
  52. SETBITS( Control, WATCHDOG_CONTROL_TRIGGER );
  53. WRITE_REGISTER_ULONG( DeviceExtension->ControlRegisterAddress, Control );
  54. if (LockResources) {
  55. KeReleaseInStackQueuedSpinLockFromDpcLevel( &LockHandle );
  56. }
  57. DueTime.QuadPart = -((LONGLONG)DeviceExtension->DpcTimeout);
  58. KeSetTimer( &DeviceExtension->Timer, DueTime, &DeviceExtension->TimerDpc );
  59. }
  60. }
  61. VOID
  62. WdTimerDpc(
  63. IN PKDPC Dpc,
  64. IN PVOID DeferredContext,
  65. IN PVOID SystemArgument1,
  66. IN PVOID SystemArgument2
  67. )
  68. /*++
  69. Routine Description:
  70. This is the function is called when the DPC timer
  71. expires. The hardware timer is simply pinged at
  72. this time.
  73. Arguments:
  74. Dpc - Pointer to the kernel DPC object
  75. DeferredContext - Really a device extension
  76. SystemArgument1 - unused
  77. SystemArgument2 - unused
  78. Return Value:
  79. None.
  80. Notes:
  81. --*/
  82. {
  83. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeferredContext;
  84. PingWatchdogTimer( DeviceExtension, TRUE );
  85. }
  86. NTSTATUS
  87. WdInitializeSoftwareTimer(
  88. PDEVICE_EXTENSION DeviceExtension
  89. )
  90. /*++
  91. Routine Description:
  92. This function initializes the software DPC timer.
  93. Arguments:
  94. DeviceExtension - Pointer to a device extension object
  95. Return Value:
  96. If we successfully create a device object, STATUS_SUCCESS is
  97. returned. Otherwise, return the appropriate error code.
  98. Notes:
  99. --*/
  100. {
  101. DeviceExtension->DpcTimeout = ConvertTimeoutToMilliseconds(
  102. WdTable->Units, DeviceExtension->HardwareTimeout >> 2 ) * 10000;
  103. WdInitializeSystemHealth( &DeviceExtension->Health );
  104. KeInitializeTimer( &DeviceExtension->Timer );
  105. KeInitializeDpc( &DeviceExtension->TimerDpc, WdTimerDpc, DeviceExtension );
  106. PingWatchdogTimer( DeviceExtension, FALSE );
  107. return STATUS_SUCCESS;
  108. }