2009-12-06 02:57:05 +01:00
|
|
|
/** @file
|
|
|
|
|
2010-04-29 14:40:51 +02:00
|
|
|
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2019-04-04 01:03:38 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Uefi.h>
|
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
#include <Library/UefiRuntimeServicesTableLib.h>
|
|
|
|
|
|
|
|
#include <Protocol/MonotonicCounter.h>
|
|
|
|
|
|
|
|
UINT64 gCurrentMonotonicCount = 0;
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
GetNextMonotonicCount (
|
|
|
|
OUT UINT64 *Count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Count == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
*Count = gCurrentMonotonicCount++;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
GetNextHighMonotonicCount (
|
|
|
|
OUT UINT32 *HighCount
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (HighCount == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
gCurrentMonotonicCount += 0x0000000100000000ULL;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-01-30 21:19:44 +01:00
|
|
|
*HighCount = (UINT32)RShiftU64 (gCurrentMonotonicCount, 32) & 0xFFFFFFFF;
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MonotonicCounterDriverInitialize (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE Handle = NULL;
|
|
|
|
|
|
|
|
// Make sure the Monotonic Counter Architectural Protocol is not already installed in the system
|
|
|
|
ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiMonotonicCounterArchProtocolGuid);
|
|
|
|
|
|
|
|
// Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields
|
|
|
|
gBS->GetNextMonotonicCount = GetNextMonotonicCount;
|
|
|
|
gRT->GetNextHighMonotonicCount = GetNextHighMonotonicCount;
|
|
|
|
|
2011-08-08 20:29:14 +02:00
|
|
|
// Install the Monotonic Counter Architectural Protocol onto a new handle
|
2009-12-06 02:57:05 +01:00
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&Handle,
|
|
|
|
&gEfiMonotonicCounterArchProtocolGuid, NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|