]>
Commit | Line | Data |
---|---|---|
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 | |
18 | UINT64 gCurrentMonotonicCount = 0;\r | |
19 | \r | |
20 | EFI_STATUS\r | |
21 | EFIAPI\r | |
22 | GetNextMonotonicCount (\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 | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | GetNextHighMonotonicCount (\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 | |
51 | \r | |
52 | EFI_STATUS\r | |
53 | EFIAPI\r | |
54 | MonotonicCounterDriverInitialize (\r | |
55 | IN EFI_HANDLE ImageHandle,\r | |
56 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
57 | )\r | |
58 | {\r | |
59 | EFI_STATUS Status;\r | |
60 | EFI_HANDLE Handle = NULL;\r | |
61 | \r | |
62 | // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system\r | |
63 | ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiMonotonicCounterArchProtocolGuid);\r | |
64 | \r | |
65 | // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields\r | |
66 | gBS->GetNextMonotonicCount = GetNextMonotonicCount;\r | |
67 | gRT->GetNextHighMonotonicCount = GetNextHighMonotonicCount;\r | |
68 | \r | |
7ca9e5a4 | 69 | // Install the Monotonic Counter Architectural Protocol onto a new handle\r |
2ef2b01e A |
70 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
71 | &Handle,\r | |
72 | &gEfiMonotonicCounterArchProtocolGuid, NULL,\r | |
73 | NULL\r | |
74 | );\r | |
75 | return Status;\r | |
76 | }\r |