TianoCore EDK2 master
Loading...
Searching...
No Matches
LockBoxDxe.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10
14#include <Library/DebugLib.h>
15#include <Protocol/LockBox.h>
16#include <LockBoxLib.h>
17
30VOID *
32 IN EFI_MEMORY_TYPE MemoryType,
33 IN UINTN Size
34 )
35{
36 UINTN Pages;
38 EFI_STATUS Status;
39 VOID *Buffer;
40 UINTN AllocRemaining;
41
42 Pages = EFI_SIZE_TO_PAGES (Size);
43 Address = 0xffffffff;
44
45 //
46 // Since we need to use gBS->AllocatePages to get a buffer below
47 // 4GB, there is a good chance that space will be wasted for very
48 // small allocation. We keep track of unused portions of the page
49 // allocations, and use these to allocate memory for small buffers.
50 //
51 ASSERT (mLockBoxGlobal->Signature == LOCK_BOX_GLOBAL_SIGNATURE);
52 if ((UINTN)mLockBoxGlobal->SubPageRemaining >= Size) {
53 Buffer = (VOID *)(UINTN)mLockBoxGlobal->SubPageBuffer;
54 mLockBoxGlobal->SubPageBuffer += (UINT32)Size;
55 mLockBoxGlobal->SubPageRemaining -= (UINT32)Size;
56 return Buffer;
57 }
58
59 Status = gBS->AllocatePages (
61 MemoryType,
62 Pages,
63 &Address
64 );
65 if (EFI_ERROR (Status)) {
66 return NULL;
67 }
68
69 Buffer = (VOID *)(UINTN)Address;
70 ZeroMem (Buffer, EFI_PAGES_TO_SIZE (Pages));
71
72 AllocRemaining = EFI_PAGES_TO_SIZE (Pages) - Size;
73 if (AllocRemaining > (UINTN)mLockBoxGlobal->SubPageRemaining) {
74 mLockBoxGlobal->SubPageBuffer = (UINT32)(Address + Size);
75 mLockBoxGlobal->SubPageRemaining = (UINT32)AllocRemaining;
76 }
77
78 return Buffer;
79}
80
95VOID *
96EFIAPI
98 IN UINTN AllocationSize
99 )
100{
101 return AllocateMemoryBelow4G (EfiACPIMemoryNVS, AllocationSize);
102}
103
105EFIAPI
106LockBoxDxeLibInitialize (
107 IN EFI_HANDLE ImageHandle,
108 IN EFI_SYSTEM_TABLE *SystemTable
109 )
110{
111 EFI_STATUS Status;
112 VOID *Interface;
113
114 Status = LockBoxLibInitialize ();
115 if (!EFI_ERROR (Status)) {
116 if (PcdGetBool (PcdAcpiS3Enable)) {
117 //
118 // When S3 enabled, the first driver run with this library linked will
119 // have this library constructor to install LockBox protocol on the
120 // ImageHandle. As other drivers may have gEfiLockBoxProtocolGuid
121 // dependency, the first driver should run before them.
122 //
123 Status = gBS->LocateProtocol (&gEfiLockBoxProtocolGuid, NULL, &Interface);
124 if (EFI_ERROR (Status)) {
125 Status = gBS->InstallProtocolInterface (
126 &ImageHandle,
127 &gEfiLockBoxProtocolGuid,
129 NULL
130 );
131 ASSERT_EFI_ERROR (Status);
132 }
133 }
134 }
135
136 return Status;
137}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateAcpiNvsPool(IN UINTN AllocationSize)
Definition: LockBoxDxe.c:97
STATIC VOID * AllocateMemoryBelow4G(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Size)
Definition: LockBoxDxe.c:31
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
EFI_MEMORY_TYPE
@ EfiACPIMemoryNVS
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
@ AllocateMaxAddress
Definition: UefiSpec.h:38