]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/PlatformDxe/Rtc.c
Set RTC initial time to be BIOS Release time.
[mirror_edk2.git] / Vlv2TbltDevicePkg / PlatformDxe / Rtc.c
CommitLineData
d71c25cf
DW
1/** @file\r
2 Adjust Default System Time.\r
3 \r
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
5 \r
6 This program and the accompanying materials are licensed and made available under\r
7 the terms and conditions of the BSD License that accompanies this distribution. \r
8 The full text of the license may be found at \r
9 http://opensource.org/licenses/bsd-license.php. \r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
13 \r
14--*/\r
15\r
16#include <PlatformDxe.h>\r
17\r
18//\r
19// Date and time initial values.\r
20// They are used if the RTC values are invalid during driver initialization\r
21//\r
22#define RTC_INIT_SECOND 0\r
23#define RTC_INIT_MINUTE 0\r
24#define RTC_INIT_HOUR 0\r
25 \r
26CHAR16 mBiosReleaseDate[20]; \r
27 \r
28/**\r
29 Convert a single character to number.\r
30 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
31 \r
32 @param Char The input char which need to change to a hex number.\r
33 \r
34**/\r
35UINTN\r
36CharToUint (\r
37 IN CHAR16 Char\r
38 )\r
39{\r
40 if ((Char >= L'0') && (Char <= L'9')) {\r
41 return (UINTN) (Char - L'0');\r
42 }\r
43\r
44 if ((Char >= L'A') && (Char <= L'F')) {\r
45 return (UINTN) (Char - L'A' + 0xA);\r
46 }\r
47\r
48 ASSERT (FALSE);\r
49 return 0;\r
50}\r
51\r
52/**\r
53 See if YEAR field of a variable of EFI_TIME type is correct.\r
54\r
55 @param Time The time to be checked.\r
56\r
57 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.\r
58 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.\r
59\r
60**/\r
61EFI_STATUS\r
62CheckRtcTimeFields (\r
63 IN EFI_TIME *Time\r
64 )\r
65{\r
66 UINT16 YearBuilt;\r
67 \r
68 YearBuilt = (UINT16)(CharToUint(mBiosReleaseDate[8])*10 + CharToUint(mBiosReleaseDate[9]) + 2000);\r
69 \r
70 if ((Time->Year) < YearBuilt) {\r
71 return EFI_INVALID_PARAMETER;\r
72 }\r
73\r
74 return EFI_SUCCESS;\r
75}\r
76\r
77/**\r
78 ExitPmAuth Protocol notification event handler, which set initial system time to be\r
79 the time when BIOS was built.\r
80\r
81 @param[in] Event Event whose notification function is being invoked.\r
82 @param[in] Context Pointer to the notification function's context.\r
83\r
84**/\r
85VOID\r
86EFIAPI\r
87AdjustDefaultRtcTimeCallback (\r
88 IN EFI_EVENT Event,\r
89 IN VOID *Context\r
90 )\r
91{\r
92 EFI_STATUS Status;\r
93 EFI_TIME EfiTime;\r
94 CHAR16 BiosVersion[60]; \r
95 CHAR16 BiosReleaseTime[20]; \r
96 //\r
97 // Get BIOS built time from Bios-ID. \r
98 //\r
99 \r
100 SetMem(BiosVersion, sizeof(BiosVersion), 0);\r
101 SetMem(mBiosReleaseDate, sizeof(mBiosReleaseDate), 0);\r
102 SetMem(BiosReleaseTime, sizeof(BiosReleaseTime), 0);\r
103 \r
104 Status = GetBiosVersionDateTime (BiosVersion, mBiosReleaseDate, BiosReleaseTime);\r
105 ASSERT_EFI_ERROR(Status);\r
106 if (EFI_ERROR (Status)) {\r
107 return; \r
108 }\r
109 \r
110 //\r
111 // Get current RTC time.\r
112 // \r
113 Status = gRT->GetTime (&EfiTime, NULL);\r
114 \r
115 //\r
116 // Validate RTC time fields\r
117 //\r
118 Status = CheckRtcTimeFields (&EfiTime);\r
119 \r
120 if (EFI_ERROR (Status)) {\r
121 //\r
122 // Date such as Dec 28th of 2015\r
123 //\r
124 // Month\r
125 // BiosReleaseDate[0] = '1';\r
126 // BiosReleaseDate[1] = '2';\r
127 //\r
128 // Day\r
129 // BiosReleaseDate[3] = '2';\r
130 // BiosReleaseDate[4] = '8';\r
131 // \r
132 //\r
133 // Year\r
134 //\r
135 // BiosReleaseDate[6] = '2';\r
136 // BiosReleaseDate[7] = '0';\r
137 // BiosReleaseDate[8] = '1'\r
138 // BiosReleaseDate[9] = '5';\r
139 \r
140 EfiTime.Second = RTC_INIT_SECOND;\r
141 EfiTime.Minute = RTC_INIT_MINUTE;\r
142 EfiTime.Hour = RTC_INIT_HOUR;\r
143 EfiTime.Day = (UINT8)(CharToUint(mBiosReleaseDate[3])*10 + CharToUint(mBiosReleaseDate[4]));\r
144 EfiTime.Month = (UINT8)(CharToUint(mBiosReleaseDate[0])*10 + CharToUint(mBiosReleaseDate[1]));\r
145 EfiTime.Year = (UINT16)(CharToUint(mBiosReleaseDate[8])*10 + CharToUint(mBiosReleaseDate[9]) + 2000);\r
146 EfiTime.Nanosecond = 0;\r
147 EfiTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
148 EfiTime.Daylight = 1; \r
149\r
150 DEBUG ((EFI_D_INFO, "Day:%d Month:%d Year:%d \n", (UINT32)EfiTime.Day, (UINT32)EfiTime.Month, (UINT32)EfiTime.Year));\r
151\r
152 //\r
153 // Reset time value according to new RTC configuration\r
154 //\r
155 Status = gRT->SetTime (&EfiTime);\r
156 ASSERT_EFI_ERROR(Status);\r
157 }\r
158\r
159 return;\r
160}\r