Source code of Windows XP (NT5)
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.

247 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. xxtime.c
  5. Abstract:
  6. This module implements the HAL set/query realtime clock routines for
  7. an x86 system.
  8. Author:
  9. David N. Cutler (davec) 5-May-1991
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "halp.h"
  15. BOOLEAN
  16. HalQueryRealTimeClock (
  17. OUT PTIME_FIELDS TimeFields
  18. )
  19. /*++
  20. Routine Description:
  21. This routine queries the realtime clock.
  22. N.B. This routine assumes that the caller has provided any required
  23. synchronization to query the realtime clock information.
  24. Arguments:
  25. TimeFields - Supplies a pointer to a time structure that receives
  26. the realtime clock information.
  27. Return Value:
  28. If the power to the realtime clock has not failed, then the time
  29. values are read from the realtime clock and a value of TRUE is
  30. returned. Otherwise, a value of FALSE is returned.
  31. --*/
  32. {
  33. KIRQL OldIrql;
  34. EFI_TIME Time;
  35. EFI_STATUS Status;
  36. BOOLEAN bstatus;
  37. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  38. //
  39. // Read the realtime clock values provided by the EFI Runtime interface.
  40. //
  41. Status = HalpCallEfi (
  42. EFI_GET_TIME_INDEX,
  43. (ULONGLONG)&Time,
  44. 0,
  45. 0,
  46. 0,
  47. 0,
  48. 0,
  49. 0,
  50. 0
  51. );
  52. #if 0
  53. HalDebugPrint((HAL_INFO, "HalQueryRealTimeClock: EFI GetTime return status is %Id \n", Status));
  54. #endif // 0
  55. if ( EFI_ERROR( Status ) ) {
  56. // if EFI error, let's reset the passed TIME_FIELDS structure.
  57. // The caller should check the return status.
  58. TimeFields->Year = 0;
  59. TimeFields->Day = 0;
  60. TimeFields->Hour = 0;
  61. TimeFields->Minute = 0;
  62. TimeFields->Second = 0;
  63. TimeFields->Milliseconds = 0;
  64. TimeFields->Weekday = 0;
  65. bstatus = FALSE;
  66. }
  67. else {
  68. LARGE_INTEGER ntTime;
  69. TimeFields->Year = Time.Year;
  70. TimeFields->Month = Time.Month;
  71. TimeFields->Day = Time.Day;
  72. TimeFields->Hour = Time.Hour;
  73. TimeFields->Minute = Time.Minute;
  74. TimeFields->Second = Time.Second;
  75. TimeFields->Milliseconds = Time.Nanosecond / 1000000;
  76. //
  77. // Use RTL time functions to calculate the day of week.
  78. // 1/ RtlTimeFieldsToTime ignores the .Weekday field.
  79. // 2/ RtlTimeToTimeFields sets the .Weekday field.
  80. //
  81. RtlTimeFieldsToTime( TimeFields, &ntTime );
  82. RtlTimeToTimeFields( &ntTime, TimeFields );
  83. #if 0
  84. HalDebugPrint(( HAL_INFO, "%d / %d / %d , %d:%d:%d:%d, %d\n", TimeFields->Year,
  85. TimeFields->Month,
  86. TimeFields->Day,
  87. TimeFields->Hour,
  88. TimeFields->Minute,
  89. TimeFields->Second,
  90. TimeFields->Milliseconds,
  91. TimeFields->Weekday));
  92. HalDebugPrint((HAL_INFO, "Timezone is %d\n", Time.TimeZone));
  93. #endif // 0
  94. bstatus = TRUE;
  95. }
  96. KeLowerIrql(OldIrql);
  97. return ( bstatus );
  98. } // HalQueryRealTimeClock()
  99. BOOLEAN
  100. HalSetRealTimeClock (
  101. IN PTIME_FIELDS TimeFields
  102. )
  103. /*++
  104. Routine Description:
  105. This routine sets the realtime clock.
  106. N.B. This routine assumes that the caller has provided any required
  107. synchronization to set the realtime clock information.
  108. Arguments:
  109. TimeFields - Supplies a pointer to a time structure that specifies the
  110. realtime clock information.
  111. Return Value:
  112. If the power to the realtime clock has not failed, then the time
  113. values are written to the realtime clock and a value of TRUE is
  114. returned. Otherwise, a value of FALSE is returned.
  115. --*/
  116. {
  117. KIRQL OldIrql;
  118. EFI_TIME CurrentTime;
  119. EFI_TIME NewTime;
  120. EFI_STATUS Status;
  121. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  122. //
  123. // If the realtime clock battery is still functioning, then write
  124. // the realtime clock values, and return a function value of TRUE.
  125. // Otherwise, return a function value of FALSE.
  126. //
  127. Status = HalpCallEfi (
  128. EFI_GET_TIME_INDEX,
  129. (ULONGLONG)&CurrentTime,
  130. 0,
  131. 0,
  132. 0,
  133. 0,
  134. 0,
  135. 0,
  136. 0
  137. );
  138. if ( EFI_ERROR( Status ) ) {
  139. KeLowerIrql(OldIrql);
  140. return FALSE;
  141. }
  142. NewTime.Year = TimeFields->Year;
  143. NewTime.Month = (UINT8)TimeFields->Month;
  144. NewTime.Day = (UINT8)TimeFields->Day;
  145. NewTime.Hour = (UINT8)TimeFields->Hour;
  146. NewTime.Minute = (UINT8)TimeFields->Minute;
  147. NewTime.Second = (UINT8)TimeFields->Second;
  148. NewTime.Nanosecond = TimeFields->Milliseconds * 1000000;
  149. NewTime.TimeZone = CurrentTime.TimeZone;
  150. NewTime.Daylight = CurrentTime.Daylight;
  151. //
  152. // Write the realtime clock values.
  153. //
  154. Status = HalpCallEfi (
  155. EFI_SET_TIME_INDEX,
  156. (ULONGLONG)&NewTime,
  157. 0,
  158. 0,
  159. 0,
  160. 0,
  161. 0,
  162. 0,
  163. 0
  164. );
  165. #if 0
  166. HalDebugPrint(( HAL_INFO, "HalSetRealTimeClock: EFI SetTime return status is %Id \n"
  167. "%d / %d / %d , %d:%d:%d:%d\n"
  168. "Timezone is %d\n"
  169. "Daylight is %d\n",
  170. Status,
  171. NewTime.Month,
  172. NewTime.Day,
  173. NewTime.Year,
  174. NewTime.Hour,
  175. NewTime.Minute,
  176. NewTime.Second,
  177. NewTime.Nanosecond,
  178. NewTime.TimeZone,
  179. NewTime.Daylight ));
  180. #endif // 0
  181. KeLowerIrql(OldIrql);
  182. return( !EFI_ERROR( Status ) );
  183. } // HalSetRealTimeClock()