TianoCore EDK2 master
Loading...
Searching...
No Matches
EmbeddedMonotonicCounter.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
15
17
18UINT64 gCurrentMonotonicCount = 0;
19
21EFIAPI
22GetNextMonotonicCount (
23 OUT UINT64 *Count
24 )
25{
26 if (Count == NULL) {
27 return EFI_INVALID_PARAMETER;
28 }
29
30 *Count = gCurrentMonotonicCount++;
31 return EFI_SUCCESS;
32}
33
35EFIAPI
36GetNextHighMonotonicCount (
37 OUT UINT32 *HighCount
38 )
39{
40 if (HighCount == NULL) {
41 return EFI_INVALID_PARAMETER;
42 }
43
44 gCurrentMonotonicCount += 0x0000000100000000ULL;
45
46 *HighCount = (UINT32)RShiftU64 (gCurrentMonotonicCount, 32) & 0xFFFFFFFF;
47
48 return EFI_SUCCESS;
49}
50
52EFIAPI
53MonotonicCounterDriverInitialize (
54 IN EFI_HANDLE ImageHandle,
55 IN EFI_SYSTEM_TABLE *SystemTable
56 )
57{
58 EFI_STATUS Status;
59 EFI_HANDLE Handle = NULL;
60
61 // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system
62 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMonotonicCounterArchProtocolGuid);
63
64 // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields
65 gBS->GetNextMonotonicCount = GetNextMonotonicCount;
66 gRT->GetNextHighMonotonicCount = GetNextHighMonotonicCount;
67
68 // Install the Monotonic Counter Architectural Protocol onto a new handle
69 Status = gBS->InstallMultipleProtocolInterfaces (
70 &Handle,
71 &gEfiMonotonicCounterArchProtocolGuid,
72 NULL,
73 NULL
74 );
75 return Status;
76}
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: RShiftU64.c:28
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
Definition: DebugLib.h:535
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