TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeExtractGuidedSectionLib.c
Go to the documentation of this file.
1
9#include <PiDxe.h>
10
11#include <Library/DebugLib.h>
16
17#define EXTRACT_HANDLER_TABLE_SIZE 0x10
18
19UINT32 mNumberOfExtractHandler = 0;
20UINT32 mMaxNumberOfExtractHandler = 0;
21
22GUID *mExtractHandlerGuidTable = NULL;
23EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable = NULL;
24EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable = NULL;
25
32RETURN_STATUS
33EFIAPI
35 VOID
36 )
37{
38 //
39 // Reallocate memory for GuidTable
40 //
41 mExtractHandlerGuidTable = ReallocatePool (
42 mMaxNumberOfExtractHandler * sizeof (GUID),
43 (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (GUID),
44 mExtractHandlerGuidTable
45 );
46
47 if (mExtractHandlerGuidTable == NULL) {
48 goto Done;
49 }
50
51 //
52 // Reallocate memory for Decode handler Table
53 //
54 mExtractDecodeHandlerTable = ReallocatePool (
55 mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER),
56 (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER),
57 mExtractDecodeHandlerTable
58 );
59
60 if (mExtractDecodeHandlerTable == NULL) {
61 goto Done;
62 }
63
64 //
65 // Reallocate memory for GetInfo handler Table
66 //
67 mExtractGetInfoHandlerTable = ReallocatePool (
68 mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER),
69 (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER),
70 mExtractGetInfoHandlerTable
71 );
72
73 if (mExtractGetInfoHandlerTable == NULL) {
74 goto Done;
75 }
76
77 //
78 // Increase max handler number
79 //
80 mMaxNumberOfExtractHandler = mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE;
81 return RETURN_SUCCESS;
82
83Done:
84 if (mExtractHandlerGuidTable != NULL) {
85 FreePool (mExtractHandlerGuidTable);
86 }
87
88 if (mExtractDecodeHandlerTable != NULL) {
89 FreePool (mExtractDecodeHandlerTable);
90 }
91
92 if (mExtractGetInfoHandlerTable != NULL) {
93 FreePool (mExtractGetInfoHandlerTable);
94 }
95
97}
98
108RETURN_STATUS
109EFIAPI
111 IN EFI_HANDLE ImageHandle,
112 IN EFI_SYSTEM_TABLE *SystemTable
113 )
114{
116}
117
132UINTN
133EFIAPI
135 OUT GUID **ExtractHandlerGuidTable
136 )
137{
138 ASSERT (ExtractHandlerGuidTable != NULL);
139
140 *ExtractHandlerGuidTable = mExtractHandlerGuidTable;
141 return mNumberOfExtractHandler;
142}
143
168RETURN_STATUS
169EFIAPI
171 IN CONST GUID *SectionGuid,
174 )
175{
176 UINT32 Index;
177 VOID *GuidData;
178
179 //
180 // Check input parameter.
181 //
182 ASSERT (SectionGuid != NULL);
183 ASSERT (GetInfoHandler != NULL);
184 ASSERT (DecodeHandler != NULL);
185
186 //
187 // Search the match registered GetInfo handler for the input guided section.
188 //
189 for (Index = 0; Index < mNumberOfExtractHandler; Index++) {
190 if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {
191 //
192 // If the guided handler has been registered before, only update its handler.
193 //
194 mExtractDecodeHandlerTable[Index] = DecodeHandler;
195 mExtractGetInfoHandlerTable[Index] = GetInfoHandler;
196 return RETURN_SUCCESS;
197 }
198 }
199
200 //
201 // Check the global table is enough to contain new Handler.
202 //
203 if (mNumberOfExtractHandler >= mMaxNumberOfExtractHandler) {
206 }
207 }
208
209 //
210 // Register new Handler and guid value.
211 //
212 CopyGuid (&mExtractHandlerGuidTable[mNumberOfExtractHandler], SectionGuid);
213 mExtractDecodeHandlerTable[mNumberOfExtractHandler] = DecodeHandler;
214 mExtractGetInfoHandlerTable[mNumberOfExtractHandler++] = GetInfoHandler;
215
216 //
217 // Install the Guided Section GUID configuration table to record the GUID itself.
218 // Then the content of the configuration table buffer will be the same as the GUID value itself.
219 //
220 GuidData = AllocateCopyPool (sizeof (GUID), (VOID *)SectionGuid);
221 if (GuidData != NULL) {
222 gBS->InstallConfigurationTable ((EFI_GUID *)SectionGuid, GuidData);
223 }
224
225 return RETURN_SUCCESS;
226}
227
262RETURN_STATUS
263EFIAPI
265 IN CONST VOID *InputSection,
266 OUT UINT32 *OutputBufferSize,
267 OUT UINT32 *ScratchBufferSize,
268 OUT UINT16 *SectionAttribute
269 )
270{
271 UINT32 Index;
272 EFI_GUID *SectionDefinitionGuid;
273
274 ASSERT (InputSection != NULL);
275 ASSERT (OutputBufferSize != NULL);
276 ASSERT (ScratchBufferSize != NULL);
277 ASSERT (SectionAttribute != NULL);
278
279 if (IS_SECTION2 (InputSection)) {
280 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
281 } else {
282 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
283 }
284
285 //
286 // Search the match registered GetInfo handler for the input guided section.
287 //
288 for (Index = 0; Index < mNumberOfExtractHandler; Index++) {
289 if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionDefinitionGuid)) {
290 //
291 // Call the match handler to getinfo for the input section data.
292 //
293 return mExtractGetInfoHandlerTable[Index](
294 InputSection,
295 OutputBufferSize,
296 ScratchBufferSize,
297 SectionAttribute
298 );
299 }
300 }
301
302 //
303 // Not found, the input guided section is not supported.
304 //
305 return RETURN_UNSUPPORTED;
306}
307
343RETURN_STATUS
344EFIAPI
346 IN CONST VOID *InputSection,
347 OUT VOID **OutputBuffer,
348 IN VOID *ScratchBuffer OPTIONAL,
349 OUT UINT32 *AuthenticationStatus
350 )
351{
352 UINT32 Index;
353 EFI_GUID *SectionDefinitionGuid;
354
355 //
356 // Check the input parameters
357 //
358 ASSERT (InputSection != NULL);
359 ASSERT (OutputBuffer != NULL);
360 ASSERT (AuthenticationStatus != NULL);
361
362 if (IS_SECTION2 (InputSection)) {
363 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
364 } else {
365 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
366 }
367
368 //
369 // Search the match registered extract handler for the input guided section.
370 //
371 for (Index = 0; Index < mNumberOfExtractHandler; Index++) {
372 if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionDefinitionGuid)) {
373 //
374 // Call the match handler to extract raw data for the input section data.
375 //
376 return mExtractDecodeHandlerTable[Index](
377 InputSection,
378 OutputBuffer,
379 ScratchBuffer,
380 AuthenticationStatus
381 );
382 }
383 }
384
385 //
386 // Not found, the input guided section is not supported.
387 //
388 return RETURN_UNSUPPORTED;
389}
390
418RETURN_STATUS
419EFIAPI
421 IN CONST GUID *SectionGuid,
422 OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL,
423 OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL
424 )
425{
426 UINT32 Index;
427
428 //
429 // Check input parameter.
430 //
431 ASSERT (SectionGuid != NULL);
432
433 //
434 // Search the match registered GetInfo handler for the input guided section.
435 //
436 for (Index = 0; Index < mNumberOfExtractHandler; Index++) {
437 if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {
438 //
439 // If the guided handler has been registered before, then return the registered handlers.
440 //
441 if (GetInfoHandler != NULL) {
442 *GetInfoHandler = mExtractGetInfoHandlerTable[Index];
443 }
444
445 if (DecodeHandler != NULL) {
446 *DecodeHandler = mExtractDecodeHandlerTable[Index];
447 }
448
449 return RETURN_SUCCESS;
450 }
451 }
452
453 return RETURN_NOT_FOUND;
454}
UINT64 UINTN
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 ReallocateExtractHandlerTable(VOID)
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 DxeExtractGuidedSectionLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
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)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
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
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
Definition: Base.h:213