TianoCore EDK2 master
Loading...
Searching...
No Matches
PeiExtractGuidedSectionLib.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10
11#include <Library/DebugLib.h>
12#include <Library/PcdLib.h>
14#include <Library/HobLib.h>
16
17#define PEI_EXTRACT_HANDLER_INFO_SIGNATURE SIGNATURE_32 ('P', 'E', 'H', 'I')
18
19typedef struct {
20 UINT32 Signature;
21 UINT32 NumberOfExtractHandler;
22 GUID *ExtractHandlerGuidTable;
23 EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;
24 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;
26
36RETURN_STATUS
39 )
40{
43
44 //
45 // First try to get handler information from guid hob specified by CallerId.
46 //
47 Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GetHobList ());
48 while (Hob.Raw != NULL) {
49 if (CompareGuid (&(Hob.Guid->Name), &gEfiCallerIdGuid)) {
50 HandlerInfo = (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *)GET_GUID_HOB_DATA (Hob.Guid);
51 if (HandlerInfo->Signature == PEI_EXTRACT_HANDLER_INFO_SIGNATURE) {
52 //
53 // Update Table Pointer when hob start address is changed.
54 //
55 if (HandlerInfo->ExtractHandlerGuidTable != (GUID *)(HandlerInfo + 1)) {
56 HandlerInfo->ExtractHandlerGuidTable = (GUID *)(HandlerInfo + 1);
57 HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)(
58 (UINT8 *)HandlerInfo->ExtractHandlerGuidTable +
59 PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)
60 );
61 HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)(
62 (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable +
63 PcdGet32 (PcdMaximumGuidedExtractHandler) *
65 );
66 }
67
68 //
69 // Return HandlerInfo pointer.
70 //
71 *InfoPointer = HandlerInfo;
72 return EFI_SUCCESS;
73 }
74 }
75
76 Hob.Raw = GET_NEXT_HOB (Hob);
77 Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, Hob.Raw);
78 }
79
80 //
81 // If Guid Hob is not found, Build CallerId Guid hob to store Handler Info
82 //
83 HandlerInfo = BuildGuidHob (
84 &gEfiCallerIdGuid,
86 PcdGet32 (PcdMaximumGuidedExtractHandler) *
88 );
89 if (HandlerInfo == NULL) {
90 //
91 // No enough resource to build guid hob.
92 //
93 *InfoPointer = NULL;
94 return EFI_OUT_OF_RESOURCES;
95 }
96
97 //
98 // Init HandlerInfo structure
99 //
100 HandlerInfo->Signature = PEI_EXTRACT_HANDLER_INFO_SIGNATURE;
101 HandlerInfo->NumberOfExtractHandler = 0;
102 HandlerInfo->ExtractHandlerGuidTable = (GUID *)(HandlerInfo + 1);
103 HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)(
104 (UINT8 *)HandlerInfo->ExtractHandlerGuidTable +
105 PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)
106 );
107 HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)(
108 (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable +
109 PcdGet32 (PcdMaximumGuidedExtractHandler) *
111 );
112 //
113 // return the created HandlerInfo.
114 //
115 *InfoPointer = HandlerInfo;
116 return EFI_SUCCESS;
117}
118
133UINTN
134EFIAPI
136 OUT GUID **ExtractHandlerGuidTable
137 )
138{
139 EFI_STATUS Status;
141
142 ASSERT (ExtractHandlerGuidTable != NULL);
143
144 //
145 // Get all registered handler information
146 //
147 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);
148 if (EFI_ERROR (Status)) {
149 *ExtractHandlerGuidTable = NULL;
150 return 0;
151 }
152
153 //
154 // Get GuidTable and Table Number
155 //
156 ASSERT (HandlerInfo != NULL);
157 *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;
158 return HandlerInfo->NumberOfExtractHandler;
159}
160
185RETURN_STATUS
186EFIAPI
188 IN CONST GUID *SectionGuid,
191 )
192{
193 EFI_STATUS Status;
194 UINT32 Index;
196
197 //
198 // Check input parameter
199 //
200 ASSERT (SectionGuid != NULL);
201 ASSERT (GetInfoHandler != NULL);
202 ASSERT (DecodeHandler != NULL);
203
204 //
205 // Get the registered handler information
206 //
207 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);
208 if (EFI_ERROR (Status)) {
209 return Status;
210 }
211
212 //
213 // Search the match registered GetInfo handler for the input guided section.
214 //
215 ASSERT (HandlerInfo != NULL);
216 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
217 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {
218 //
219 // If the guided handler has been registered before, only update its handler.
220 //
221 HandlerInfo->ExtractDecodeHandlerTable[Index] = DecodeHandler;
222 HandlerInfo->ExtractGetInfoHandlerTable[Index] = GetInfoHandler;
223 return RETURN_SUCCESS;
224 }
225 }
226
227 //
228 // Check the global table is enough to contain new Handler.
229 //
230 if (HandlerInfo->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {
232 }
233
234 //
235 // Register new Handler and guid value.
236 //
237 CopyGuid (HandlerInfo->ExtractHandlerGuidTable + HandlerInfo->NumberOfExtractHandler, SectionGuid);
238 HandlerInfo->ExtractDecodeHandlerTable[HandlerInfo->NumberOfExtractHandler] = DecodeHandler;
239 HandlerInfo->ExtractGetInfoHandlerTable[HandlerInfo->NumberOfExtractHandler++] = GetInfoHandler;
240
241 //
242 // Build the Guided Section GUID HOB to record the GUID itself.
243 // Then the content of the GUIDed HOB will be the same as the GUID value itself.
244 //
246 (EFI_GUID *)SectionGuid,
247 (VOID *)SectionGuid,
248 sizeof (GUID)
249 );
250
251 return RETURN_SUCCESS;
252}
253
288RETURN_STATUS
289EFIAPI
291 IN CONST VOID *InputSection,
292 OUT UINT32 *OutputBufferSize,
293 OUT UINT32 *ScratchBufferSize,
294 OUT UINT16 *SectionAttribute
295 )
296{
297 UINT32 Index;
298 EFI_STATUS Status;
300 EFI_GUID *SectionDefinitionGuid;
301
302 //
303 // Check input parameter
304 //
305 ASSERT (InputSection != NULL);
306 ASSERT (OutputBufferSize != NULL);
307 ASSERT (ScratchBufferSize != NULL);
308 ASSERT (SectionAttribute != NULL);
309
310 //
311 // Get all registered handler information.
312 //
313 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);
314 if (EFI_ERROR (Status)) {
315 return Status;
316 }
317
318 if (IS_SECTION2 (InputSection)) {
319 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
320 } else {
321 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
322 }
323
324 //
325 // Search the match registered GetInfo handler for the input guided section.
326 //
327 ASSERT (HandlerInfo != NULL);
328 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
329 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {
330 //
331 // Call the match handler to get information for the input section data.
332 //
333 return HandlerInfo->ExtractGetInfoHandlerTable[Index](
334 InputSection,
335 OutputBufferSize,
336 ScratchBufferSize,
337 SectionAttribute
338 );
339 }
340 }
341
342 //
343 // Not found, the input guided section is not supported.
344 //
345 return RETURN_UNSUPPORTED;
346}
347
383RETURN_STATUS
384EFIAPI
386 IN CONST VOID *InputSection,
387 OUT VOID **OutputBuffer,
388 IN VOID *ScratchBuffer OPTIONAL,
389 OUT UINT32 *AuthenticationStatus
390 )
391{
392 UINT32 Index;
393 EFI_STATUS Status;
395 EFI_GUID *SectionDefinitionGuid;
396
397 //
398 // Check input parameter
399 //
400 ASSERT (InputSection != NULL);
401 ASSERT (OutputBuffer != NULL);
402 ASSERT (AuthenticationStatus != NULL);
403
404 //
405 // Get all registered handler information.
406 //
407 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);
408 if (EFI_ERROR (Status)) {
409 return Status;
410 }
411
412 if (IS_SECTION2 (InputSection)) {
413 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
414 } else {
415 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
416 }
417
418 //
419 // Search the match registered Extract handler for the input guided section.
420 //
421 ASSERT (HandlerInfo != NULL);
422 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
423 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {
424 //
425 // Call the match handler to extract raw data for the input guided section.
426 //
427 return HandlerInfo->ExtractDecodeHandlerTable[Index](
428 InputSection,
429 OutputBuffer,
430 ScratchBuffer,
431 AuthenticationStatus
432 );
433 }
434 }
435
436 //
437 // Not found, the input guided section is not supported.
438 //
439 return RETURN_UNSUPPORTED;
440}
441
469RETURN_STATUS
470EFIAPI
472 IN CONST GUID *SectionGuid,
473 OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL,
474 OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL
475 )
476{
477 EFI_STATUS Status;
478 UINT32 Index;
480
481 //
482 // Check input parameter
483 //
484 ASSERT (SectionGuid != NULL);
485
486 //
487 // Get the registered handler information
488 //
489 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);
490 if (EFI_ERROR (Status)) {
491 return Status;
492 }
493
494 //
495 // Search the match registered GetInfo handler for the input guided section.
496 //
497 ASSERT (HandlerInfo != NULL);
498 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index++) {
499 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {
500 //
501 // If the guided handler has been registered before, then return the registered handlers.
502 //
503 if (GetInfoHandler != NULL) {
504 *GetInfoHandler = HandlerInfo->ExtractGetInfoHandlerTable[Index];
505 }
506
507 if (DecodeHandler != NULL) {
508 *DecodeHandler = HandlerInfo->ExtractDecodeHandlerTable[Index];
509 }
510
511 return RETURN_SUCCESS;
512 }
513 }
514
515 return RETURN_NOT_FOUND;
516}
UINT64 UINTN
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
Definition: HobLib.c:336
VOID *EFIAPI GetNextHob(IN UINT16 Type, IN CONST VOID *HobStart)
Definition: HobLib.c:103
VOID *EFIAPI GetHobList(VOID)
Definition: HobLib.c:76
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_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 PcdGet32(TokenName)
Definition: PcdLib.h:362
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 EFIAPI ExtractGuidedSectionGetHandlers(IN CONST GUID *SectionGuid, OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL, OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL)
RETURN_STATUS PeiGetExtractGuidedSectionHandlerInfo(IN OUT PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO **InfoPointer)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_GUID Name
Definition: PiHob.h:347
Definition: Base.h:213