TianoCore EDK2 master
Loading...
Searching...
No Matches
TimestampDxe.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10#include <Library/DebugLib.h>
13#include <Library/TimerLib.h>
15#include <Protocol/Timestamp.h>
16
17//
18// The StartValue in TimerLib
19//
20UINT64 mTimerLibStartValue = 0;
21
22//
23// The EndValue in TimerLib
24//
25UINT64 mTimerLibEndValue = 0;
26
27//
28// The properties of timestamp
29//
30EFI_TIMESTAMP_PROPERTIES mTimestampProperties = {
31 0,
32 0
33};
34
49UINT64
50EFIAPI
52 VOID
53 )
54{
55 //
56 // The timestamp of Timestamp Protocol
57 //
58 UINT64 TimestampValue;
59
60 TimestampValue = 0;
61
62 //
63 // Get the timestamp
64 //
65 if (mTimerLibStartValue > mTimerLibEndValue) {
66 TimestampValue = mTimerLibStartValue - GetPerformanceCounter ();
67 } else {
68 TimestampValue = GetPerformanceCounter () - mTimerLibStartValue;
69 }
70
71 return TimestampValue;
72}
73
86EFIAPI
89 )
90{
91 if (Properties == NULL) {
92 return EFI_INVALID_PARAMETER;
93 }
94
95 //
96 // Get timestamp properties
97 //
98 CopyMem ((VOID *)Properties, (VOID *)&mTimestampProperties, sizeof (mTimestampProperties));
99
100 return EFI_SUCCESS;
101}
102
103//
104// The Timestamp Protocol instance produced by this driver
105//
106EFI_TIMESTAMP_PROTOCOL mTimestamp = {
109};
110
121EFIAPI
123 IN EFI_HANDLE ImageHandle,
124 IN EFI_SYSTEM_TABLE *SystemTable
125 )
126{
127 EFI_STATUS Status;
128
129 EFI_HANDLE TimestampHandle;
130
131 TimestampHandle = NULL;
132
133 //
134 // Get the start value, end value and frequency in Timerlib
135 //
136 mTimestampProperties.Frequency = GetPerformanceCounterProperties (&mTimerLibStartValue, &mTimerLibEndValue);
137
138 //
139 // Set the EndValue
140 //
141 if (mTimerLibEndValue > mTimerLibStartValue) {
142 mTimestampProperties.EndValue = mTimerLibEndValue - mTimerLibStartValue;
143 } else {
144 mTimestampProperties.EndValue = mTimerLibStartValue - mTimerLibEndValue;
145 }
146
147 DEBUG ((DEBUG_INFO, "TimerFrequency:0x%lx, TimerLibStartTime:0x%lx, TimerLibEndtime:0x%lx\n", mTimestampProperties.Frequency, mTimerLibStartValue, mTimerLibEndValue));
148
149 //
150 // Install the Timestamp Protocol onto a new handle
151 //
152 Status = gBS->InstallMultipleProtocolInterfaces (
153 &TimestampHandle,
154 &gEfiTimestampProtocolGuid,
155 &mTimestamp,
156 NULL
157 );
158
159 ASSERT_EFI_ERROR (Status);
160
161 return EFI_SUCCESS;
162}
UINT64 EFIAPI GetPerformanceCounterProperties(OUT UINT64 *StartValue OPTIONAL, OUT UINT64 *EndValue OPTIONAL)
UINT64 EFIAPI GetPerformanceCounter(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT64 EFIAPI TimestampDriverGetTimestamp(VOID)
Definition: TimestampDxe.c:51
EFI_STATUS EFIAPI TimestampDriverGetProperties(OUT EFI_TIMESTAMP_PROPERTIES *Properties)
Definition: TimestampDxe.c:87
EFI_STATUS EFIAPI TimestampDriverInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimestampDxe.c:122
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS