TianoCore EDK2 master
Loading...
Searching...
No Matches
DxePrmContextBufferLib.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
15#include <Protocol/PrmConfig.h>
16
17#define _DBGMSGID_ "[PRMCONTEXTBUFFERLIB]"
18
36 IN CONST EFI_GUID *HandlerGuid,
37 IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers,
38 OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer
39 )
40{
41 UINTN Index;
42
43 DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __func__));
44
45 if ((HandlerGuid == NULL) || (ModuleContextBuffers == NULL) || (ContextBuffer == NULL)) {
46 return EFI_INVALID_PARAMETER;
47 }
48
49 for (Index = 0; Index < ModuleContextBuffers->BufferCount; Index++) {
50 if (CompareGuid (&ModuleContextBuffers->Buffer[Index].HandlerGuid, HandlerGuid)) {
51 *ContextBuffer = &ModuleContextBuffers->Buffer[Index];
52 return EFI_SUCCESS;
53 }
54 }
55
56 return EFI_NOT_FOUND;
57}
58
80 IN PRM_GUID_SEARCH_TYPE GuidSearchType,
81 IN CONST EFI_GUID *Guid,
82 OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers
83 )
84{
85 EFI_STATUS Status;
86 UINTN HandleCount;
87 UINTN Index;
88 EFI_HANDLE *HandleBuffer;
89 PRM_CONFIG_PROTOCOL *PrmConfigProtocol;
90 CONST PRM_CONTEXT_BUFFER *PrmContextBuffer;
91
92 DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __func__));
93
94 if ((Guid == NULL) || (PrmModuleContextBuffers == NULL)) {
95 return EFI_INVALID_PARAMETER;
96 }
97
98 *PrmModuleContextBuffers = NULL;
99
100 Status = gBS->LocateHandleBuffer (
102 &gPrmConfigProtocolGuid,
103 NULL,
104 &HandleCount,
105 &HandleBuffer
106 );
107 if (!EFI_ERROR (Status)) {
108 for (Index = 0; Index < HandleCount; Index++) {
109 Status = gBS->HandleProtocol (
110 HandleBuffer[Index],
111 &gPrmConfigProtocolGuid,
112 (VOID **)&PrmConfigProtocol
113 );
114 ASSERT_EFI_ERROR (Status);
115 if (EFI_ERROR (Status) || (PrmConfigProtocol == NULL)) {
116 continue;
117 }
118
119 if (GuidSearchType == ByModuleGuid) {
120 if (CompareGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, Guid)) {
121 DEBUG ((
122 DEBUG_INFO,
123 " %a %a: Found a PRM configuration protocol for PRM module %g.\n",
124 _DBGMSGID_,
125 __func__,
126 Guid
127 ));
128
129 *PrmModuleContextBuffers = &PrmConfigProtocol->ModuleContextBuffers;
130 return EFI_SUCCESS;
131 }
132 } else {
133 Status = FindContextBufferInModuleBuffers (Guid, &PrmConfigProtocol->ModuleContextBuffers, &PrmContextBuffer);
134 if (!EFI_ERROR (Status)) {
135 *PrmModuleContextBuffers = &PrmConfigProtocol->ModuleContextBuffers;
136 return EFI_SUCCESS;
137 }
138 }
139 }
140 }
141
142 DEBUG ((
143 DEBUG_INFO,
144 " %a %a: Could not locate a PRM configuration protocol for PRM handler %g.\n",
145 _DBGMSGID_,
146 __func__,
147 Guid
148 ));
149
150 return EFI_NOT_FOUND;
151}
152
171 IN CONST EFI_GUID *PrmHandlerGuid,
172 IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTIONAL,
173 OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer
174 )
175{
176 EFI_STATUS Status;
177 CONST PRM_MODULE_CONTEXT_BUFFERS *ContextBuffers;
178
179 DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __func__));
180
181 if ((PrmHandlerGuid == NULL) || (PrmContextBuffer == NULL)) {
182 return EFI_INVALID_PARAMETER;
183 }
184
185 *PrmContextBuffer = NULL;
186
187 if (PrmModuleContextBuffers == NULL) {
188 Status = GetModuleContextBuffers (ByHandlerGuid, PrmHandlerGuid, &ContextBuffers);
189 if (EFI_ERROR (Status)) {
190 return EFI_NOT_FOUND;
191 }
192 } else {
193 ContextBuffers = PrmModuleContextBuffers;
194 }
195
196 Status = FindContextBufferInModuleBuffers (PrmHandlerGuid, ContextBuffers, PrmContextBuffer);
197
198 return Status;
199}
UINT64 UINTN
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS FindContextBufferInModuleBuffers(IN CONST EFI_GUID *HandlerGuid, IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers, OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer)
EFI_STATUS GetContextBuffer(IN CONST EFI_GUID *PrmHandlerGuid, IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTIONAL, OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer)
EFI_STATUS GetModuleContextBuffers(IN PRM_GUID_SEARCH_TYPE GuidSearchType, IN CONST EFI_GUID *Guid, OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
PRM_GUID_SEARCH_TYPE
@ ByModuleGuid
@ ByHandlerGuid
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ ByProtocol
Definition: UefiSpec.h:1518
Definition: Base.h:213