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