3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/UefiRuntimeServicesTableLib.h>
22 #include <Protocol/MonotonicCounter.h>
24 UINT64 gCurrentMonotonicCount
= 0;
28 GetNextMonotonicCount (
33 return EFI_INVALID_PARAMETER
;
36 *Count
= gCurrentMonotonicCount
++;
42 GetNextHighMonotonicCount (
46 if (HighCount
== NULL
) {
47 return EFI_INVALID_PARAMETER
;
50 gCurrentMonotonicCount
+= 0x0000000100000000ULL
;
52 *HighCount
= (UINT32
)RShiftU64 (gCurrentMonotonicCount
, 32) & 0xFFFFFFFF;
60 MonotonicCounterDriverInitialize (
61 IN EFI_HANDLE ImageHandle
,
62 IN EFI_SYSTEM_TABLE
*SystemTable
66 EFI_HANDLE Handle
= NULL
;
68 // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system
69 ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL
, &gEfiMonotonicCounterArchProtocolGuid
);
71 // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields
72 gBS
->GetNextMonotonicCount
= GetNextMonotonicCount
;
73 gRT
->GetNextHighMonotonicCount
= GetNextHighMonotonicCount
;
75 // Install the Monotonic Counter Architectural Protocol onto a new handle
76 Status
= gBS
->InstallMultipleProtocolInterfaces (
78 &gEfiMonotonicCounterArchProtocolGuid
, NULL
,