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.

248 lines
7.0 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. EFI_TIME Time;
  34. EFI_STATUS Status;
  35. BOOLEAN bstatus;
  36. //
  37. // Read the realtime clock values provided by the EFI Runtime interface.
  38. //
  39. Status = HalpCallEfi (
  40. EFI_GET_TIME_INDEX,
  41. (ULONGLONG)&Time,
  42. 0,
  43. 0,
  44. 0,
  45. 0,
  46. 0,
  47. 0,
  48. 0
  49. );
  50. #if 0
  51. HalDebugPrint((HAL_INFO, "HalQueryRealTimeClock: EFI GetTime return status is %Id \n", Status));
  52. #endif // 0
  53. if ( EFI_ERROR( Status ) ) {
  54. // if EFI error, let's reset the passed TIME_FIELDS structure.
  55. // The caller should check the return status.
  56. TimeFields->Year = 0;
  57. TimeFields->Day = 0;
  58. TimeFields->Hour = 0;
  59. TimeFields->Minute = 0;
  60. TimeFields->Second = 0;
  61. TimeFields->Milliseconds = 0;
  62. TimeFields->Weekday = 0;
  63. bstatus = FALSE;
  64. }
  65. else {
  66. LARGE_INTEGER ntTime;
  67. TimeFields->Year = Time.Year;
  68. TimeFields->Month = Time.Month;
  69. TimeFields->Day = Time.Day;
  70. TimeFields->Hour = Time.Hour;
  71. TimeFields->Minute = Time.Minute;
  72. TimeFields->Second = Time.Second;
  73. TimeFields->Milliseconds = Time.Nanosecond / 1000000;
  74. //
  75. // Use RTL time functions to calculate the day of week.
  76. // 1/ RtlTimeFieldsToTime ignores the .Weekday field.
  77. // 2/ RtlTimeToTimeFields sets the .Weekday field.
  78. //
  79. RtlTimeFieldsToTime( TimeFields, &ntTime );
  80. RtlTimeToTimeFields( &ntTime, TimeFields );
  81. #if 0
  82. HalDebugPrint(( HAL_INFO, "%d / %d / %d , %d:%d:%d:%d, %d\n", TimeFields->Year,
  83. TimeFields->Month,
  84. TimeFields->Day,
  85. TimeFields->Hour,
  86. TimeFields->Minute,
  87. TimeFields->Second,
  88. TimeFields->Milliseconds,
  89. TimeFields->Weekday));
  90. HalDebugPrint((HAL_INFO, "Timezone is %d\n", Time.TimeZone));
  91. #endif // 0
  92. bstatus = TRUE;
  93. }
  94. return ( bstatus );
  95. } // HalQueryRealTimeClock()
  96. BOOLEAN
  97. HalSetRealTimeClock(
  98. IN PTIME_FIELDS TimeFields
  99. )
  100. /*++
  101. Routine Description:
  102. This routine sets the realtime clock.
  103. N.B. This routine assumes that the caller has provided any required
  104. synchronization to set the realtime clock information.
  105. Arguments:
  106. TimeFields - Supplies a pointer to a time structure that specifies the
  107. realtime clock information.
  108. Return Value:
  109. If the power to the realtime clock has not failed, then the time
  110. values are written to the realtime clock and a value of TRUE is
  111. returned. Otherwise, a value of FALSE is returned.
  112. --*/
  113. {
  114. EFI_TIME CurrentTime;
  115. EFI_TIME NewTime;
  116. EFI_STATUS Status;
  117. //
  118. // NOTE: One might think we need to raise IRQL here so that we don't get
  119. // pre-empted between reading the Timezone and Daylight Savings Time info
  120. // from the Realtime clock and writing it back. However the EFI spec
  121. // states that it doesn't actually use or maintain these values, it merely
  122. // stores them so that the eventual caller of GetTime can figure out what
  123. // time base was used (UTC or Local) and if DST adjustments were made.
  124. //
  125. // Of course the whole idea of getting these values from the realtime clock
  126. // is wrong. What we really want is the values associated with the time
  127. // value we were passed in and are about to write to the clock not what
  128. // currently is stored in the clock.
  129. //
  130. //
  131. // If the realtime clock battery is still functioning, then write
  132. // the realtime clock values, and return a function value of TRUE.
  133. // Otherwise, return a function value of FALSE.
  134. //
  135. Status = HalpCallEfi (
  136. EFI_GET_TIME_INDEX,
  137. (ULONGLONG)&CurrentTime,
  138. 0,
  139. 0,
  140. 0,
  141. 0,
  142. 0,
  143. 0,
  144. 0
  145. );
  146. if ( EFI_ERROR( Status ) ) {
  147. return FALSE;
  148. }
  149. NewTime.Year = TimeFields->Year;
  150. NewTime.Month = (UINT8)TimeFields->Month;
  151. NewTime.Day = (UINT8)TimeFields->Day;
  152. NewTime.Hour = (UINT8)TimeFields->Hour;
  153. NewTime.Minute = (UINT8)TimeFields->Minute;
  154. NewTime.Second = (UINT8)TimeFields->Second;
  155. NewTime.Nanosecond = TimeFields->Milliseconds * 1000000;
  156. NewTime.TimeZone = CurrentTime.TimeZone;
  157. NewTime.Daylight = CurrentTime.Daylight;
  158. //
  159. // Write the realtime clock values.
  160. //
  161. Status = HalpCallEfi (
  162. EFI_SET_TIME_INDEX,
  163. (ULONGLONG)&NewTime,
  164. 0,
  165. 0,
  166. 0,
  167. 0,
  168. 0,
  169. 0,
  170. 0
  171. );
  172. #if 0
  173. HalDebugPrint(( HAL_INFO, "HalSetRealTimeClock: EFI SetTime return status is %Id \n"
  174. "%d / %d / %d , %d:%d:%d:%d\n"
  175. "Timezone is %d\n"
  176. "Daylight is %d\n",
  177. Status,
  178. NewTime.Month,
  179. NewTime.Day,
  180. NewTime.Year,
  181. NewTime.Hour,
  182. NewTime.Minute,
  183. NewTime.Second,
  184. NewTime.Nanosecond,
  185. NewTime.TimeZone,
  186. NewTime.Daylight ));
  187. #endif // 0
  188. return( !EFI_ERROR( Status ) );
  189. } // HalSetRealTimeClock()