3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/UefiRuntimeServicesTableLib.h>
16 #include <Protocol/MonotonicCounter.h>
18 UINT64 gCurrentMonotonicCount
= 0;
22 GetNextMonotonicCount (
27 return EFI_INVALID_PARAMETER
;
30 *Count
= gCurrentMonotonicCount
++;
36 GetNextHighMonotonicCount (
40 if (HighCount
== NULL
) {
41 return EFI_INVALID_PARAMETER
;
44 gCurrentMonotonicCount
+= 0x0000000100000000ULL
;
46 *HighCount
= (UINT32
)RShiftU64 (gCurrentMonotonicCount
, 32) & 0xFFFFFFFF;
54 MonotonicCounterDriverInitialize (
55 IN EFI_HANDLE ImageHandle
,
56 IN EFI_SYSTEM_TABLE
*SystemTable
60 EFI_HANDLE Handle
= NULL
;
62 // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system
63 ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL
, &gEfiMonotonicCounterArchProtocolGuid
);
65 // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields
66 gBS
->GetNextMonotonicCount
= GetNextMonotonicCount
;
67 gRT
->GetNextHighMonotonicCount
= GetNextHighMonotonicCount
;
69 // Install the Monotonic Counter Architectural Protocol onto a new handle
70 Status
= gBS
->InstallMultipleProtocolInterfaces (
72 &gEfiMonotonicCounterArchProtocolGuid
, NULL
,