]>
Commit | Line | Data |
---|---|---|
6a0d41c0 SQ |
1 | /** @file\r |
2 | Implementation of Timestamp Protocol using UEFI APIs.\r | |
3 | \r | |
4 | Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include <Uefi.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/UefiDriverEntryPoint.h>\r | |
18 | #include <Library/UefiBootServicesTableLib.h>\r | |
19 | #include <Library/TimerLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Protocol/Timestamp.h>\r | |
22 | \r | |
23 | //\r | |
24 | // The StartValue in TimerLib\r | |
25 | //\r | |
26 | UINT64 mTimerLibStartValue = 0;\r | |
27 | \r | |
28 | //\r | |
29 | // The EndValue in TimerLib\r | |
30 | //\r | |
31 | UINT64 mTimerLibEndValue = 0;\r | |
32 | \r | |
33 | //\r | |
34 | // The properties of timestamp\r | |
35 | //\r | |
36 | EFI_TIMESTAMP_PROPERTIES mTimestampProperties = {\r | |
37 | 0,\r | |
38 | 0\r | |
39 | };\r | |
40 | \r | |
41 | /**\r | |
42 | Retrieves the current value of a 64-bit free running timestamp counter.\r | |
43 | \r | |
44 | The counter shall count up in proportion to the amount of time that has passed. The counter value\r | |
45 | will always roll over to zero. The properties of the counter can be retrieved from GetProperties().\r | |
46 | The caller should be prepared for the function to return the same value twice across successive calls.\r | |
47 | The counter value will not go backwards other than when wrapping, as defined by EndValue in GetProperties().\r | |
48 | The frequency of the returned timestamp counter value must remain constant. Power management operations that \r | |
49 | affect clocking must not change the returned counter frequency. The quantization of counter value updates may \r | |
50 | vary as long as the value reflecting time passed remains consistent. \r | |
51 | \r | |
52 | @retval The current value of the free running timestamp counter.\r | |
53 | \r | |
54 | **/\r | |
55 | UINT64\r | |
56 | EFIAPI\r | |
57 | TimestampDriverGetTimestamp (\r | |
58 | VOID\r | |
59 | )\r | |
60 | {\r | |
61 | //\r | |
62 | // The timestamp of Timestamp Protocol\r | |
63 | //\r | |
64 | UINT64 TimestampValue;\r | |
65 | TimestampValue = 0;\r | |
66 | \r | |
67 | //\r | |
68 | // Get the timestamp\r | |
69 | //\r | |
70 | if (mTimerLibStartValue > mTimerLibEndValue) {\r | |
71 | TimestampValue = mTimerLibStartValue - GetPerformanceCounter();\r | |
72 | } else {\r | |
73 | TimestampValue = GetPerformanceCounter() - mTimerLibStartValue;\r | |
74 | }\r | |
75 | \r | |
76 | return TimestampValue;\r | |
77 | }\r | |
78 | \r | |
79 | /**\r | |
80 | Obtains timestamp counter properties including frequency and value limits.\r | |
81 | \r | |
82 | @param[out] Properties The properties of the timestamp counter.\r | |
83 | \r | |
84 | @retval EFI_SUCCESS The properties were successfully retrieved. \r | |
85 | @retval EFI_DEVICE_ERROR An error occurred trying to retrieve the properties of the timestamp \r | |
86 | counter subsystem. Properties is not pedated. \r | |
87 | @retval EFI_INVALID_PARAMETER Properties is NULL.\r | |
88 | \r | |
89 | **/\r | |
90 | EFI_STATUS\r | |
91 | EFIAPI\r | |
92 | TimestampDriverGetProperties(\r | |
93 | OUT EFI_TIMESTAMP_PROPERTIES *Properties\r | |
94 | )\r | |
95 | {\r | |
96 | if (Properties == NULL) {\r | |
97 | return EFI_INVALID_PARAMETER;\r | |
98 | }\r | |
99 | \r | |
100 | //\r | |
101 | // Get timestamp properties\r | |
102 | //\r | |
103 | CopyMem((VOID *) Properties, (VOID *) &mTimestampProperties, sizeof (mTimestampProperties));\r | |
104 | \r | |
105 | return EFI_SUCCESS;\r | |
106 | }\r | |
107 | \r | |
108 | //\r | |
109 | // The Timestamp Protocol instance produced by this driver\r | |
110 | //\r | |
111 | EFI_TIMESTAMP_PROTOCOL mTimestamp = {\r | |
112 | TimestampDriverGetTimestamp,\r | |
113 | TimestampDriverGetProperties\r | |
114 | };\r | |
115 | \r | |
116 | /**\r | |
117 | Entry point of the Timestamp Protocol driver.\r | |
118 | \r | |
119 | @param ImageHandle The image handle of this driver.\r | |
120 | @param SystemTable The pointer of EFI_SYSTEM_TABLE.\r | |
121 | \r | |
122 | @retval EFI_SUCCESS Watchdog Timer Architectural Protocol successfully installed.\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_STATUS\r | |
126 | EFIAPI\r | |
127 | TimestampDriverInitialize (\r | |
128 | IN EFI_HANDLE ImageHandle,\r | |
129 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
130 | )\r | |
131 | {\r | |
132 | EFI_STATUS Status;\r | |
133 | \r | |
134 | EFI_HANDLE TimestampHandle;\r | |
135 | TimestampHandle = NULL;\r | |
136 | \r | |
137 | //\r | |
138 | // Get the start value, end value and frequency in Timerlib\r | |
139 | //\r | |
140 | mTimestampProperties.Frequency = GetPerformanceCounterProperties(&mTimerLibStartValue, &mTimerLibEndValue);\r | |
141 | \r | |
142 | //\r | |
143 | // Set the EndValue \r | |
144 | //\r | |
145 | if (mTimerLibEndValue > mTimerLibStartValue) {\r | |
146 | mTimestampProperties.EndValue = mTimerLibEndValue - mTimerLibStartValue;\r | |
147 | } else {\r | |
148 | mTimestampProperties.EndValue = mTimerLibStartValue - mTimerLibEndValue;\r | |
149 | }\r | |
150 | \r | |
151 | DEBUG ((EFI_D_INFO, "TimerFrequency:0x%lx, TimerLibStartTime:0x%lx, TimerLibEndtime:0x%lx\n", mTimestampProperties.Frequency, mTimerLibStartValue, mTimerLibEndValue));\r | |
152 | \r | |
153 | //\r | |
154 | // Install the Timestamp Protocol onto a new handle\r | |
155 | //\r | |
156 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
157 | &TimestampHandle,\r | |
158 | &gEfiTimestampProtocolGuid,\r | |
159 | &mTimestamp,\r | |
160 | NULL\r | |
161 | );\r | |
162 | \r | |
163 | ASSERT_EFI_ERROR (Status);\r | |
164 | \r | |
165 | return EFI_SUCCESS;\r | |
166 | }\r |