]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / EmbeddedMonotonicCounter / EmbeddedMonotonicCounter.c
CommitLineData
2ef2b01e
A
1/** @file\r
2\r
60274cca 3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
3402aac7 4\r
878b807a 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
2ef2b01e
A
6\r
7**/\r
8\r
9#include <Uefi.h>\r
10\r
11#include <Library/BaseLib.h>\r
12#include <Library/DebugLib.h>\r
13#include <Library/UefiBootServicesTableLib.h>\r
14#include <Library/UefiRuntimeServicesTableLib.h>\r
15\r
16#include <Protocol/MonotonicCounter.h>\r
17\r
e7108d0e 18UINT64 gCurrentMonotonicCount = 0;\r
2ef2b01e
A
19\r
20EFI_STATUS\r
21EFIAPI\r
22GetNextMonotonicCount (\r
23 OUT UINT64 *Count\r
24 )\r
25{\r
26 if (Count == NULL) {\r
27 return EFI_INVALID_PARAMETER;\r
28 }\r
3402aac7 29\r
2ef2b01e
A
30 *Count = gCurrentMonotonicCount++;\r
31 return EFI_SUCCESS;\r
32}\r
33\r
34EFI_STATUS\r
35EFIAPI\r
36GetNextHighMonotonicCount (\r
37 OUT UINT32 *HighCount\r
38 )\r
39{\r
40 if (HighCount == NULL) {\r
41 return EFI_INVALID_PARAMETER;\r
42 }\r
3402aac7 43\r
2ef2b01e 44 gCurrentMonotonicCount += 0x0000000100000000ULL;\r
3402aac7 45\r
33e4913c 46 *HighCount = (UINT32)RShiftU64 (gCurrentMonotonicCount, 32) & 0xFFFFFFFF;\r
2ef2b01e
A
47\r
48 return EFI_SUCCESS;\r
49}\r
50\r
2ef2b01e
A
51EFI_STATUS\r
52EFIAPI\r
53MonotonicCounterDriverInitialize (\r
54 IN EFI_HANDLE ImageHandle,\r
55 IN EFI_SYSTEM_TABLE *SystemTable\r
56 )\r
57{\r
58 EFI_STATUS Status;\r
59 EFI_HANDLE Handle = NULL;\r
60\r
61 // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system\r
e7108d0e 62 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiMonotonicCounterArchProtocolGuid);\r
2ef2b01e
A
63\r
64 // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields\r
65 gBS->GetNextMonotonicCount = GetNextMonotonicCount;\r
66 gRT->GetNextHighMonotonicCount = GetNextHighMonotonicCount;\r
67\r
7ca9e5a4 68 // Install the Monotonic Counter Architectural Protocol onto a new handle\r
2ef2b01e
A
69 Status = gBS->InstallMultipleProtocolInterfaces (\r
70 &Handle,\r
e7108d0e
MK
71 &gEfiMonotonicCounterArchProtocolGuid,\r
72 NULL,\r
2ef2b01e
A
73 NULL\r
74 );\r
75 return Status;\r
76}\r