• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Implement EFI RealTimeClock runtime services via RTC Lib.
3 
4   Currently this driver does not support runtime virtual calling.
5 
6 
7   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
8 
9   This program and the accompanying materials
10   are licensed and made available under the terms and conditions of the BSD License
11   which accompanies this distribution.  The full text of the license may be found at
12   http://opensource.org/licenses/bsd-license.php
13 
14   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 
17 **/
18 
19 #include <PiDxe.h>
20 #include <Library/UefiLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/RealTimeClockLib.h>
23 #include <Protocol/RealTimeClock.h>
24 
25 EFI_HANDLE  mHandle = NULL;
26 
27 
28 
29 /**
30   Returns the current time and date information, and the time-keeping capabilities
31   of the hardware platform.
32 
33   @param  Time                  A pointer to storage to receive a snapshot of the current time.
34   @param  Capabilities          An optional pointer to a buffer to receive the real time clock
35                                 device's capabilities.
36 
37   @retval EFI_SUCCESS           The operation completed successfully.
38   @retval EFI_INVALID_PARAMETER Time is NULL.
39   @retval EFI_DEVICE_ERROR      The time could not be retrieved due to hardware error.
40 
41 **/
42 EFI_STATUS
43 EFIAPI
GetTime(OUT EFI_TIME * Time,OUT EFI_TIME_CAPABILITIES * Capabilities)44 GetTime (
45   OUT EFI_TIME                *Time,
46   OUT  EFI_TIME_CAPABILITIES  *Capabilities
47   )
48 {
49   return LibGetTime (Time, Capabilities);
50 }
51 
52 
53 
54 /**
55   Sets the current local time and date information.
56 
57   @param  Time                  A pointer to the current time.
58 
59   @retval EFI_SUCCESS           The operation completed successfully.
60   @retval EFI_INVALID_PARAMETER A time field is out of range.
61   @retval EFI_DEVICE_ERROR      The time could not be set due due to hardware error.
62 
63 **/
64 EFI_STATUS
65 EFIAPI
SetTime(IN EFI_TIME * Time)66 SetTime (
67   IN EFI_TIME                *Time
68   )
69 {
70   return LibSetTime (Time);
71 }
72 
73 
74 /**
75   Returns the current wakeup alarm clock setting.
76 
77   @param  Enabled               Indicates if the alarm is currently enabled or disabled.
78   @param  Pending               Indicates if the alarm signal is pending and requires acknowledgement.
79   @param  Time                  The current alarm setting.
80 
81   @retval EFI_SUCCESS           The alarm settings were returned.
82   @retval EFI_INVALID_PARAMETER Any parameter is NULL.
83   @retval EFI_DEVICE_ERROR      The wakeup time could not be retrieved due to a hardware error.
84 
85 **/
86 EFI_STATUS
87 EFIAPI
GetWakeupTime(OUT BOOLEAN * Enabled,OUT BOOLEAN * Pending,OUT EFI_TIME * Time)88 GetWakeupTime (
89   OUT BOOLEAN     *Enabled,
90   OUT BOOLEAN     *Pending,
91   OUT EFI_TIME    *Time
92   )
93 {
94   return LibGetWakeupTime (Enabled, Pending, Time);
95 }
96 
97 
98 /**
99   Sets the system wakeup alarm clock time.
100 
101   @param  Enabled               Enable or disable the wakeup alarm.
102   @param  Time                  If Enable is TRUE, the time to set the wakeup alarm for.
103 
104   @retval EFI_SUCCESS           If Enable is TRUE, then the wakeup alarm was enabled. If
105                                 Enable is FALSE, then the wakeup alarm was disabled.
106   @retval EFI_INVALID_PARAMETER A time field is out of range.
107   @retval EFI_DEVICE_ERROR      The wakeup time could not be set due to a hardware error.
108   @retval EFI_UNSUPPORTED       A wakeup timer is not supported on this platform.
109 
110 **/
111 EFI_STATUS
112 EFIAPI
SetWakeupTime(IN BOOLEAN Enabled,OUT EFI_TIME * Time)113 SetWakeupTime (
114   IN BOOLEAN      Enabled,
115   OUT EFI_TIME    *Time
116   )
117 {
118   return LibSetWakeupTime (Enabled, Time);
119 }
120 
121 
122 
123 /**
124   This is the declaration of an EFI image entry point. This can be the entry point to an application
125   written to this specification, an EFI boot service driver, or an EFI runtime driver.
126 
127   @param  ImageHandle           Handle that identifies the loaded image.
128   @param  SystemTable           System Table for this image.
129 
130   @retval EFI_SUCCESS           The operation completed successfully.
131 
132 **/
133 EFI_STATUS
134 EFIAPI
InitializeRealTimeClock(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)135 InitializeRealTimeClock (
136   IN EFI_HANDLE                            ImageHandle,
137   IN EFI_SYSTEM_TABLE                      *SystemTable
138   )
139 {
140   EFI_STATUS  Status;
141 
142   Status = LibRtcInitialize (ImageHandle, SystemTable);
143   if (EFI_ERROR (Status)) {
144     return Status;
145   }
146 
147   SystemTable->RuntimeServices->GetTime       = GetTime;
148   SystemTable->RuntimeServices->SetTime       = SetTime;
149   SystemTable->RuntimeServices->GetWakeupTime = GetWakeupTime;
150   SystemTable->RuntimeServices->SetWakeupTime = SetWakeupTime;
151 
152   Status = gBS->InstallMultipleProtocolInterfaces (
153                   &mHandle,
154                   &gEfiRealTimeClockArchProtocolGuid,
155                   NULL,
156                   NULL
157                   );
158 
159   return Status;
160 }
161 
162