TianoCore EDK2 master
Loading...
Searching...
No Matches
BaseExtractGuidedSectionLib.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10
11#include <Library/DebugLib.h>
12#include <Library/PcdLib.h>
15
16#define EXTRACT_HANDLER_INFO_SIGNATURE SIGNATURE_32 ('E', 'G', 'S', 'I')
17
18typedef struct {
19 UINT32 Signature;
20 UINT32 NumberOfExtractHandler;
21 GUID *ExtractHandlerGuidTable;
22 EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;
23 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;
25
36RETURN_STATUS
39 )
40{
42
43 //
44 // Set the available memory address to handler info.
45 //
46 HandlerInfo = (EXTRACT_GUIDED_SECTION_HANDLER_INFO *)(VOID *)(UINTN)PcdGet64 (PcdGuidedExtractHandlerTableAddress);
47 if (HandlerInfo == NULL) {
48 *InfoPointer = NULL;
49 return EFI_OUT_OF_RESOURCES;
50 }
51
52 //
53 // First check whether the handler information structure is initialized.
54 //
55 if (HandlerInfo->Signature == EXTRACT_HANDLER_INFO_SIGNATURE) {
56 //
57 // The handler information has been initialized and is returned.
58 //
59 *InfoPointer = HandlerInfo;
60 return RETURN_SUCCESS;
61 }
62
63 //
64 // Try to initialize the handler information structure
65 //
66 HandlerInfo->Signature = EXTRACT_HANDLER_INFO_SIGNATURE;
67 if (HandlerInfo->Signature != EXTRACT_HANDLER_INFO_SIGNATURE) {
68 //
69 // The handler information structure was not writeable because the memory is not ready.
70 //
71 *InfoPointer = NULL;
73 }
74
75 //
76 // Init HandlerInfo structure
77 //
78 HandlerInfo->NumberOfExtractHandler = 0;
79 HandlerInfo->ExtractHandlerGuidTable = (GUID *)(HandlerInfo + 1);
80 HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)(
81 (UINT8 *)HandlerInfo->ExtractHandlerGuidTable +
82 PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)
83 );
84 HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)(
85 (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable +
86 PcdGet32 (PcdMaximumGuidedExtractHandler) *
88 );
89 *InfoPointer = HandlerInfo;
90 return RETURN_SUCCESS;
91}
92
107UINTN
108EFIAPI
110 OUT GUID **ExtractHandlerGuidTable
111 )
112{
113 RETURN_STATUS Status;
115
116 ASSERT (ExtractHandlerGuidTable != NULL);
117
118 //
119 // Get all registered handler information
120 //
121 Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);
122 if (RETURN_ERROR (Status)) {
123 *ExtractHandlerGuidTable = NULL;
124 return 0;
125 }
126
127 //
128 // Get GuidTable and Table Number
129 //
130 ASSERT (HandlerInfo != NULL);
131 *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;
132 return HandlerInfo->NumberOfExtractHandler;
133}
134
159RETURN_STATUS
160EFIAPI
162 IN CONST GUID *SectionGuid,
165 )
166{
167 UINT32 Index;
168 RETURN_STATUS Status;
170
171 //
172 // Check input parameter
173 //
174 ASSERT (SectionGuid != NULL);
175 ASSERT (GetInfoHandler != NULL);
176 ASSERT (DecodeHandler != NULL);
177
178 //
179 // Get the registered handler information
180 //
181 Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);
182 if (RETURN_ERROR (Status)) {
183 return Status;
184 }
185
186 //
187 // Search the match registered GetInfo handler for the input guided section.
188 //
189 ASSERT (HandlerInfo != NULL);
190 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
191 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {
192 //
193 // If the guided handler has been registered before, only update its handler.
194 //
195 HandlerInfo->ExtractDecodeHandlerTable[Index] = DecodeHandler;
196 HandlerInfo->ExtractGetInfoHandlerTable[Index] = GetInfoHandler;
197 return RETURN_SUCCESS;
198 }
199 }
200
201 //
202 // Check the global table is enough to contain new Handler.
203 //
204 if (HandlerInfo->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {
206 }
207
208 //
209 // Register new Handler and guid value.
210 //
211 CopyGuid (HandlerInfo->ExtractHandlerGuidTable + HandlerInfo->NumberOfExtractHandler, SectionGuid);
212 HandlerInfo->ExtractDecodeHandlerTable[HandlerInfo->NumberOfExtractHandler] = DecodeHandler;
213 HandlerInfo->ExtractGetInfoHandlerTable[HandlerInfo->NumberOfExtractHandler++] = GetInfoHandler;
214
215 return RETURN_SUCCESS;
216}
217
252RETURN_STATUS
253EFIAPI
255 IN CONST VOID *InputSection,
256 OUT UINT32 *OutputBufferSize,
257 OUT UINT32 *ScratchBufferSize,
258 OUT UINT16 *SectionAttribute
259 )
260{
261 UINT32 Index;
262 RETURN_STATUS Status;
264 EFI_GUID *SectionDefinitionGuid;
265
266 //
267 // Check input parameter
268 //
269 ASSERT (InputSection != NULL);
270 ASSERT (OutputBufferSize != NULL);
271 ASSERT (ScratchBufferSize != NULL);
272 ASSERT (SectionAttribute != NULL);
273
274 //
275 // Get all registered handler information.
276 //
277 Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);
278 if (RETURN_ERROR (Status)) {
279 return Status;
280 }
281
282 if (IS_SECTION2 (InputSection)) {
283 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
284 } else {
285 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
286 }
287
288 //
289 // Search the match registered GetInfo handler for the input guided section.
290 //
291 ASSERT (HandlerInfo != NULL);
292 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
293 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {
294 //
295 // Call the match handler to get information for the input section data.
296 //
297 return HandlerInfo->ExtractGetInfoHandlerTable[Index](
298 InputSection,
299 OutputBufferSize,
300 ScratchBufferSize,
301 SectionAttribute
302 );
303 }
304 }
305
306 //
307 // Not found, the input guided section is not supported.
308 //
309 return RETURN_UNSUPPORTED;
310}
311
347RETURN_STATUS
348EFIAPI
350 IN CONST VOID *InputSection,
351 OUT VOID **OutputBuffer,
352 IN VOID *ScratchBuffer OPTIONAL,
353 OUT UINT32 *AuthenticationStatus
354 )
355{
356 UINT32 Index;
357 RETURN_STATUS Status;
359 EFI_GUID *SectionDefinitionGuid;
360
361 //
362 // Check input parameter
363 //
364 ASSERT (InputSection != NULL);
365 ASSERT (OutputBuffer != NULL);
366 ASSERT (AuthenticationStatus != NULL);
367
368 //
369 // Get all registered handler information.
370 //
371 Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);
372 if (RETURN_ERROR (Status)) {
373 return Status;
374 }
375
376 if (IS_SECTION2 (InputSection)) {
377 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
378 } else {
379 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
380 }
381
382 //
383 // Search the match registered Extract handler for the input guided section.
384 //
385 ASSERT (HandlerInfo != NULL);
386 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
387 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {
388 //
389 // Call the match handler to extract raw data for the input guided section.
390 //
391 return HandlerInfo->ExtractDecodeHandlerTable[Index](
392 InputSection,
393 OutputBuffer,
394 ScratchBuffer,
395 AuthenticationStatus
396 );
397 }
398 }
399
400 //
401 // Not found, the input guided section is not supported.
402 //
403 return RETURN_UNSUPPORTED;
404}
405
433RETURN_STATUS
434EFIAPI
436 IN CONST GUID *SectionGuid,
437 OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL,
438 OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL
439 )
440{
441 UINT32 Index;
442 RETURN_STATUS Status;
444
445 //
446 // Check input parameter
447 //
448 ASSERT (SectionGuid != NULL);
449
450 //
451 // Get the registered handler information
452 //
453 Status = GetExtractGuidedSectionHandlerInfo (&HandlerInfo);
454 if (RETURN_ERROR (Status)) {
455 return Status;
456 }
457
458 //
459 // Search the match registered GetInfo handler for the input guided section.
460 //
461 ASSERT (HandlerInfo != NULL);
462 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
463 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {
464 //
465 // If the guided handler has been registered before, then return the registered handlers.
466 //
467 if (GetInfoHandler != NULL) {
468 *GetInfoHandler = HandlerInfo->ExtractGetInfoHandlerTable[Index];
469 }
470
471 if (DecodeHandler != NULL) {
472 *DecodeHandler = HandlerInfo->ExtractDecodeHandlerTable[Index];
473 }
474
475 return RETURN_SUCCESS;
476 }
477 }
478
479 return RETURN_NOT_FOUND;
480}
UINT64 UINTN
RETURN_STATUS EFIAPI ExtractGuidedSectionGetInfo(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
UINTN EFIAPI ExtractGuidedSectionGetGuidList(OUT GUID **ExtractHandlerGuidTable)
RETURN_STATUS EFIAPI ExtractGuidedSectionDecode(IN CONST VOID *InputSection, OUT VOID **OutputBuffer, IN VOID *ScratchBuffer OPTIONAL, OUT UINT32 *AuthenticationStatus)
RETURN_STATUS EFIAPI ExtractGuidedSectionRegisterHandlers(IN CONST GUID *SectionGuid, IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler, IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler)
RETURN_STATUS GetExtractGuidedSectionHandlerInfo(IN OUT EXTRACT_GUIDED_SECTION_HANDLER_INFO **InfoPointer)
RETURN_STATUS EFIAPI ExtractGuidedSectionGetHandlers(IN CONST GUID *SectionGuid, OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL, OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
RETURN_STATUS(EFIAPI * EXTRACT_GUIDED_SECTION_DECODE_HANDLER)(IN CONST VOID *InputSection, OUT VOID **OutputBuffer, IN VOID *ScratchBuffer OPTIONAL, OUT UINT32 *AuthenticationStatus)
RETURN_STATUS(EFIAPI * EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define RETURN_NOT_FOUND
Definition: Base.h:1142
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_OUT_OF_RESOURCES
Definition: Base.h:1114
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
Definition: Base.h:213