Updated to support passing PE/COFF and LZMA decompress up via HOBS. Currently turned...
[mirror_edk2.git] / EmbeddedPkg / EmbeddedMonotonicCounter / EmbeddedMonotonicCounter.c
CommitLineData
2ef2b01e
A
1/** @file\r
2\r
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
4 \r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Uefi.h>\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/UefiBootServicesTableLib.h>\r
20#include <Library/UefiRuntimeServicesTableLib.h>\r
21\r
22#include <Protocol/MonotonicCounter.h>\r
23\r
24UINT64 gCurrentMonotonicCount = 0;\r
25\r
26EFI_STATUS\r
27EFIAPI\r
28GetNextMonotonicCount (\r
29 OUT UINT64 *Count\r
30 )\r
31{\r
32 if (Count == NULL) {\r
33 return EFI_INVALID_PARAMETER;\r
34 }\r
35 \r
36 *Count = gCurrentMonotonicCount++;\r
37 return EFI_SUCCESS;\r
38}\r
39\r
40EFI_STATUS\r
41EFIAPI\r
42GetNextHighMonotonicCount (\r
43 OUT UINT32 *HighCount\r
44 )\r
45{\r
46 if (HighCount == NULL) {\r
47 return EFI_INVALID_PARAMETER;\r
48 }\r
49 \r
50 gCurrentMonotonicCount += 0x0000000100000000ULL;\r
51 \r
33e4913c 52 *HighCount = (UINT32)RShiftU64 (gCurrentMonotonicCount, 32) & 0xFFFFFFFF;\r
2ef2b01e
A
53\r
54 return EFI_SUCCESS;\r
55}\r
56\r
57\r
58EFI_STATUS\r
59EFIAPI\r
60MonotonicCounterDriverInitialize (\r
61 IN EFI_HANDLE ImageHandle,\r
62 IN EFI_SYSTEM_TABLE *SystemTable\r
63 )\r
64{\r
65 EFI_STATUS Status;\r
66 EFI_HANDLE Handle = NULL;\r
67\r
68 // Make sure the Monotonic Counter Architectural Protocol is not already installed in the system\r
69 ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiMonotonicCounterArchProtocolGuid);\r
70\r
71 // Fill in the EFI Boot Services and EFI Runtime Services Monotonic Counter Fields\r
72 gBS->GetNextMonotonicCount = GetNextMonotonicCount;\r
73 gRT->GetNextHighMonotonicCount = GetNextHighMonotonicCount;\r
74\r
75 // Install the Monotonic Counter Architctural Protocol onto a new handle\r
76 Status = gBS->InstallMultipleProtocolInterfaces (\r
77 &Handle,\r
78 &gEfiMonotonicCounterArchProtocolGuid, NULL,\r
79 NULL\r
80 );\r
81 return Status;\r
82}\r