VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.c@ 85718

Last change on this file since 85718 was 85718, checked in by vboxsync, 5 years ago

Devices/EFI: Merge edk-stable202005 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1/** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <Uefi.h>
10
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
13#include <Library/UefiBootServicesTableLib.h>
14#include <Library/UefiRuntimeServicesTableLib.h>
15
16#include <Protocol/MonotonicCounter.h>
17
18UINT64 gCurrentMonotonicCount = 0;
19
20EFI_STATUS
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
34EFI_STATUS
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
51
52EFI_STATUS
53EFIAPI
54MonotonicCounterDriverInitialize (
55 IN EFI_HANDLE ImageHandle,
56 IN EFI_SYSTEM_TABLE *SystemTable
57 )
58{
59 EFI_STATUS Status;
60 EFI_HANDLE Handle = NULL;
61
62 // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system
63 ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiMonotonicCounterArchProtocolGuid);
64
65 // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields
66 gBS->GetNextMonotonicCount = GetNextMonotonicCount;
67 gRT->GetNextHighMonotonicCount = GetNextHighMonotonicCount;
68
69 // Install the Monotonic Counter Architectural Protocol onto a new handle
70 Status = gBS->InstallMultipleProtocolInterfaces (
71 &Handle,
72 &gEfiMonotonicCounterArchProtocolGuid, NULL,
73 NULL
74 );
75 return Status;
76}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette