]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.c
MdePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdePkg / Library / PeiExtractGuidedSectionLib / PeiExtractGuidedSectionLib.c
CommitLineData
8069d49e 1/** @file\r
eceb3a4c 2 Provide generic extract guided section functions for PEI phase.\r
0fa00159 3\r
9095d37b 4 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
0fa00159 6\r
8069d49e 7**/\r
0fa00159
LG
8\r
9#include <PiPei.h>\r
10\r
11#include <Library/DebugLib.h>\r
12#include <Library/PcdLib.h>\r
13#include <Library/BaseMemoryLib.h>\r
14#include <Library/HobLib.h>\r
15#include <Library/ExtractGuidedSectionLib.h>\r
16\r
07636730 17#define PEI_EXTRACT_HANDLER_INFO_SIGNATURE SIGNATURE_32 ('P', 'E', 'H', 'I')\r
0fa00159
LG
18\r
19typedef struct {\r
20 UINT32 Signature;\r
21 UINT32 NumberOfExtractHandler;\r
22 GUID *ExtractHandlerGuidTable;\r
23 EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;\r
24 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;\r
25} PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO;\r
26\r
4754c98b 27/**\r
0fa00159
LG
28 Build guid hob for the global memory to store the registered guid and Handler list.\r
29 If GuidHob exists, HandlerInfo will be directly got from Guid hob data.\r
30\r
58380e9c 31 @param[in, out] InfoPointer The pointer to pei handler information structure.\r
0fa00159 32\r
3e5c3238 33 @retval RETURN_SUCCESS Build Guid hob for the global memory space to store guid and function tables.\r
4754c98b 34 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.\r
0fa00159
LG
35**/\r
36RETURN_STATUS\r
0fa00159
LG
37PeiGetExtractGuidedSectionHandlerInfo (\r
38 IN OUT PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO **InfoPointer\r
39 )\r
40{\r
41 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
42 EFI_PEI_HOB_POINTERS Hob;\r
9095d37b 43\r
0fa00159 44 //\r
58380e9c 45 // First try to get handler information from guid hob specified by CallerId.\r
0fa00159
LG
46 //\r
47 Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GetHobList ());\r
48 while (Hob.Raw != NULL) {\r
49 if (CompareGuid (&(Hob.Guid->Name), &gEfiCallerIdGuid)) {\r
50 HandlerInfo = (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *) GET_GUID_HOB_DATA (Hob.Guid);\r
51 if (HandlerInfo->Signature == PEI_EXTRACT_HANDLER_INFO_SIGNATURE) {\r
e111752c
LG
52 //\r
53 // Update Table Pointer when hob start address is changed.\r
54 //\r
55 if (HandlerInfo->ExtractHandlerGuidTable != (GUID *) (HandlerInfo + 1)) {\r
56 HandlerInfo->ExtractHandlerGuidTable = (GUID *) (HandlerInfo + 1);\r
57 HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) (\r
9095d37b 58 (UINT8 *)HandlerInfo->ExtractHandlerGuidTable +\r
e111752c
LG
59 PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)\r
60 );\r
61 HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) (\r
9095d37b
LG
62 (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable +\r
63 PcdGet32 (PcdMaximumGuidedExtractHandler) *\r
b9d5a7f1 64 sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER)\r
e111752c
LG
65 );\r
66 }\r
67 //\r
68 // Return HandlerInfo pointer.\r
69 //\r
0fa00159
LG
70 *InfoPointer = HandlerInfo;\r
71 return EFI_SUCCESS;\r
72 }\r
73 }\r
74 Hob.Raw = GET_NEXT_HOB (Hob);\r
75 Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, Hob.Raw);\r
76 }\r
9095d37b 77\r
0fa00159
LG
78 //\r
79 // If Guid Hob is not found, Build CallerId Guid hob to store Handler Info\r
80 //\r
81 HandlerInfo = BuildGuidHob (\r
9095d37b 82 &gEfiCallerIdGuid,\r
0fa00159 83 sizeof (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO) +\r
9095d37b 84 PcdGet32 (PcdMaximumGuidedExtractHandler) *\r
0fa00159
LG
85 (sizeof (GUID) + sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER) + sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER))\r
86 );\r
87 if (HandlerInfo == NULL) {\r
88 //\r
89 // No enough resource to build guid hob.\r
90 //\r
b9d5a7f1 91 *InfoPointer = NULL;\r
0fa00159
LG
92 return EFI_OUT_OF_RESOURCES;\r
93 }\r
eceb3a4c
LG
94 //\r
95 // Init HandlerInfo structure\r
96 //\r
0fa00159
LG
97 HandlerInfo->Signature = PEI_EXTRACT_HANDLER_INFO_SIGNATURE;\r
98 HandlerInfo->NumberOfExtractHandler = 0;\r
99 HandlerInfo->ExtractHandlerGuidTable = (GUID *) (HandlerInfo + 1);\r
100 HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) (\r
9095d37b 101 (UINT8 *)HandlerInfo->ExtractHandlerGuidTable +\r
0fa00159
LG
102 PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)\r
103 );\r
104 HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) (\r
9095d37b
LG
105 (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable +\r
106 PcdGet32 (PcdMaximumGuidedExtractHandler) *\r
b9d5a7f1 107 sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER)\r
0fa00159 108 );\r
eceb3a4c
LG
109 //\r
110 // return the created HandlerInfo.\r
111 //\r
0fa00159
LG
112 *InfoPointer = HandlerInfo;\r
113 return EFI_SUCCESS;\r
114}\r
115\r
4754c98b 116/**\r
f1db45f8 117 Retrieve the list GUIDs that have been registered through ExtractGuidedSectionRegisterHandlers().\r
0fa00159 118\r
f1db45f8 119 Sets ExtractHandlerGuidTable so it points at a callee allocated array of registered GUIDs.\r
120 The total number of GUIDs in the array are returned. Since the array of GUIDs is callee allocated\r
9095d37b 121 and caller must treat this array of GUIDs as read-only data.\r
f1db45f8 122 If ExtractHandlerGuidTable is NULL, then ASSERT().\r
123\r
3e5c3238 124 @param[out] ExtractHandlerGuidTable A pointer to the array of GUIDs that have been registered through\r
f1db45f8 125 ExtractGuidedSectionRegisterHandlers().\r
0fa00159 126\r
4754c98b 127 @return the number of the supported extract guided Handler.\r
f1db45f8 128\r
0fa00159
LG
129**/\r
130UINTN\r
131EFIAPI\r
132ExtractGuidedSectionGetGuidList (\r
eceb3a4c 133 OUT GUID **ExtractHandlerGuidTable\r
0fa00159
LG
134 )\r
135{\r
136 EFI_STATUS Status;\r
137 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
138\r
139 ASSERT (ExtractHandlerGuidTable != NULL);\r
140\r
eceb3a4c
LG
141 //\r
142 // Get all registered handler information\r
143 //\r
0fa00159
LG
144 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
145 if (EFI_ERROR (Status)) {\r
b9d5a7f1
LG
146 *ExtractHandlerGuidTable = NULL;\r
147 return 0;\r
0fa00159
LG
148 }\r
149\r
eceb3a4c
LG
150 //\r
151 // Get GuidTable and Table Number\r
152 //\r
3dbef428 153 ASSERT (HandlerInfo != NULL);\r
0fa00159
LG
154 *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;\r
155 return HandlerInfo->NumberOfExtractHandler;\r
156}\r
157\r
4754c98b 158/**\r
f1db45f8 159 Registers handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and EXTRACT_GUIDED_SECTION_DECODE_HANDLER\r
160 for a specific GUID section type.\r
161\r
3e5c3238 162 Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.\r
f1db45f8 163 If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.\r
164 If there are not enough resources available to register the handlers then RETURN_OUT_OF_RESOURCES is returned.\r
9095d37b 165\r
f1db45f8 166 If SectionGuid is NULL, then ASSERT().\r
167 If GetInfoHandler is NULL, then ASSERT().\r
168 If DecodeHandler is NULL, then ASSERT().\r
169\r
170 @param[in] SectionGuid A pointer to the GUID associated with the the handlers\r
171 of the GUIDed section type being registered.\r
2fc59a00 172 @param[in] GetInfoHandler The pointer to a function that examines a GUIDed section and returns the\r
f1db45f8 173 size of the decoded buffer and the size of an optional scratch buffer\r
174 required to actually decode the data in a GUIDed section.\r
2fc59a00 175 @param[in] DecodeHandler The pointer to a function that decodes a GUIDed section into a caller\r
9095d37b 176 allocated output buffer.\r
f1db45f8 177\r
178 @retval RETURN_SUCCESS The handlers were registered.\r
f1db45f8 179 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to register the handlers.\r
4754c98b 180\r
0fa00159
LG
181**/\r
182RETURN_STATUS\r
183EFIAPI\r
184ExtractGuidedSectionRegisterHandlers (\r
185 IN CONST GUID *SectionGuid,\r
186 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r
187 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r
188 )\r
189{\r
190 EFI_STATUS Status;\r
e2701217 191 UINT32 Index;\r
0fa00159
LG
192 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
193\r
194 //\r
a750b4ae 195 // Check input parameter\r
0fa00159 196 //\r
f1db45f8 197 ASSERT (SectionGuid != NULL);\r
198 ASSERT (GetInfoHandler != NULL);\r
199 ASSERT (DecodeHandler != NULL);\r
200\r
201\r
0fa00159
LG
202\r
203 //\r
204 // Get the registered handler information\r
205 //\r
206 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
207 if (EFI_ERROR (Status)) {\r
208 return Status;\r
209 }\r
e2701217
LG
210\r
211 //\r
212 // Search the match registered GetInfo handler for the input guided section.\r
213 //\r
3dbef428 214 ASSERT (HandlerInfo != NULL);\r
e2701217 215 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
e111752c 216 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r
b911d09f
LG
217 //\r
218 // If the guided handler has been registered before, only update its handler.\r
219 //\r
220 HandlerInfo->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r
221 HandlerInfo->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
222 return RETURN_SUCCESS;\r
e2701217
LG
223 }\r
224 }\r
225\r
0fa00159
LG
226 //\r
227 // Check the global table is enough to contain new Handler.\r
228 //\r
229 if (HandlerInfo->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r
230 return RETURN_OUT_OF_RESOURCES;\r
231 }\r
9095d37b 232\r
0fa00159
LG
233 //\r
234 // Register new Handler and guid value.\r
235 //\r
e111752c 236 CopyGuid (HandlerInfo->ExtractHandlerGuidTable + HandlerInfo->NumberOfExtractHandler, SectionGuid);\r
0fa00159
LG
237 HandlerInfo->ExtractDecodeHandlerTable [HandlerInfo->NumberOfExtractHandler] = DecodeHandler;\r
238 HandlerInfo->ExtractGetInfoHandlerTable [HandlerInfo->NumberOfExtractHandler++] = GetInfoHandler;\r
b9d5a7f1 239\r
8472f1f5
SZ
240 //\r
241 // Build the Guided Section GUID HOB to record the GUID itself.\r
242 // Then the content of the GUIDed HOB will be the same as the GUID value itself.\r
243 //\r
244 BuildGuidDataHob (\r
245 (EFI_GUID *) SectionGuid,\r
246 (VOID *) SectionGuid,\r
247 sizeof (GUID)\r
248 );\r
249\r
0fa00159
LG
250 return RETURN_SUCCESS;\r
251}\r
252\r
4754c98b 253/**\r
3e5c3238 254 Retrieves a GUID from a GUIDed section and uses that GUID to select an associated handler of type\r
f1db45f8 255 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r
256 The selected handler is used to retrieve and return the size of the decoded buffer and the size of an\r
257 optional scratch buffer required to actually decode the data in a GUIDed section.\r
258\r
9095d37b 259 Examines a GUIDed section specified by InputSection.\r
f1db45f8 260 If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r
9095d37b
LG
261 then RETURN_UNSUPPORTED is returned.\r
262 If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler\r
f1db45f8 263 of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r
264 is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of\r
265 type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.\r
9095d37b 266\r
f1db45f8 267 If InputSection is NULL, then ASSERT().\r
268 If OutputBufferSize is NULL, then ASSERT().\r
269 If ScratchBufferSize is NULL, then ASSERT().\r
270 If SectionAttribute is NULL, then ASSERT().\r
271\r
272 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
273 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required if the buffer\r
274 specified by InputSection were decoded.\r
275 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space if the buffer specified by\r
276 InputSection were decoded.\r
277 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes field of\r
278 EFI_GUID_DEFINED_SECTION in the PI Specification.\r
279\r
280 @retval RETURN_SUCCESS Get the required information successfully.\r
281 @retval RETURN_UNSUPPORTED The GUID from the section specified by InputSection does not match any of\r
282 the GUIDs registered with ExtractGuidedSectionRegisterHandlers().\r
283 @retval Others The return status from the handler associated with the GUID retrieved from\r
284 the section specified by InputSection.\r
0fa00159
LG
285\r
286**/\r
287RETURN_STATUS\r
288EFIAPI\r
289ExtractGuidedSectionGetInfo (\r
290 IN CONST VOID *InputSection,\r
291 OUT UINT32 *OutputBufferSize,\r
292 OUT UINT32 *ScratchBufferSize,\r
9095d37b 293 OUT UINT16 *SectionAttribute\r
0fa00159
LG
294 )\r
295{\r
296 UINT32 Index;\r
297 EFI_STATUS Status;\r
298 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
30f001ca 299 EFI_GUID *SectionDefinitionGuid;\r
9095d37b 300\r
0fa00159 301 //\r
a750b4ae 302 // Check input parameter\r
0fa00159 303 //\r
f1db45f8 304 ASSERT (InputSection != NULL);\r
0fa00159
LG
305 ASSERT (OutputBufferSize != NULL);\r
306 ASSERT (ScratchBufferSize != NULL);\r
307 ASSERT (SectionAttribute != NULL);\r
308\r
309 //\r
eceb3a4c 310 // Get all registered handler information.\r
0fa00159
LG
311 //\r
312 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
313 if (EFI_ERROR (Status)) {\r
314 return Status;\r
315 }\r
30f001ca
SZ
316\r
317 if (IS_SECTION2 (InputSection)) {\r
318 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid);\r
319 } else {\r
320 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid);\r
321 }\r
322\r
0fa00159
LG
323 //\r
324 // Search the match registered GetInfo handler for the input guided section.\r
325 //\r
3dbef428 326 ASSERT (HandlerInfo != NULL);\r
0fa00159 327 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
30f001ca 328 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {\r
b911d09f 329 //\r
58380e9c 330 // Call the match handler to get information for the input section data.\r
b911d09f
LG
331 //\r
332 return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r
333 InputSection,\r
334 OutputBufferSize,\r
335 ScratchBufferSize,\r
336 SectionAttribute\r
337 );\r
0fa00159
LG
338 }\r
339 }\r
340\r
341 //\r
9095d37b 342 // Not found, the input guided section is not supported.\r
0fa00159 343 //\r
b911d09f 344 return RETURN_UNSUPPORTED;\r
0fa00159
LG
345}\r
346\r
4754c98b 347/**\r
3e5c3238 348 Retrieves the GUID from a GUIDed section and uses that GUID to select an associated handler of type\r
f1db45f8 349 EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r
350 The selected handler is used to decode the data in a GUIDed section and return the result in a caller\r
351 allocated output buffer.\r
352\r
9095d37b 353 Decodes the GUIDed section specified by InputSection.\r
f1db45f8 354 If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r
9095d37b 355 then RETURN_UNSUPPORTED is returned.\r
f1db45f8 356 If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler\r
357 of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r
358 is used to decode InputSection into the buffer specified by OutputBuffer and the authentication status of this\r
359 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the data in InputSection,\r
360 then OutputBuffer is set to point at the data in InputSection. Otherwise, the decoded data will be placed in caller\r
361 allocated buffer specified by OutputBuffer. This function is responsible for computing the EFI_AUTH_STATUS_PLATFORM_OVERRIDE\r
9095d37b
LG
362 bit of in AuthenticationStatus. The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned.\r
363\r
f1db45f8 364 If InputSection is NULL, then ASSERT().\r
365 If OutputBuffer is NULL, then ASSERT().\r
366 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
9095d37b 367 If AuthenticationStatus is NULL, then ASSERT().\r
f1db45f8 368\r
369 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
9095d37b
LG
370 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
371 @param[in] ScratchBuffer A caller allocated buffer that may be required by this function as a scratch buffer to perform the decode operation.\r
372 @param[out] AuthenticationStatus\r
f1db45f8 373 A pointer to the authentication status of the decoded output buffer. See the definition\r
374 of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI section of the PI\r
375 Specification.\r
4754c98b 376\r
f1db45f8 377 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
378 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
379 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
4754c98b 380\r
0fa00159
LG
381**/\r
382RETURN_STATUS\r
383EFIAPI\r
384ExtractGuidedSectionDecode (\r
385 IN CONST VOID *InputSection,\r
386 OUT VOID **OutputBuffer,\r
d0e2f823 387 IN VOID *ScratchBuffer OPTIONAL,\r
9095d37b 388 OUT UINT32 *AuthenticationStatus\r
0fa00159
LG
389 )\r
390{\r
391 UINT32 Index;\r
392 EFI_STATUS Status;\r
393 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
30f001ca 394 EFI_GUID *SectionDefinitionGuid;\r
9095d37b 395\r
eceb3a4c
LG
396 //\r
397 // Check input parameter\r
398 //\r
f1db45f8 399 ASSERT (InputSection != NULL);\r
0fa00159
LG
400 ASSERT (OutputBuffer != NULL);\r
401 ASSERT (AuthenticationStatus != NULL);\r
eceb3a4c
LG
402\r
403 //\r
404 // Get all registered handler information.\r
9095d37b 405 //\r
0fa00159
LG
406 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
407 if (EFI_ERROR (Status)) {\r
408 return Status;\r
409 }\r
410\r
30f001ca
SZ
411 if (IS_SECTION2 (InputSection)) {\r
412 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid);\r
413 } else {\r
414 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid);\r
415 }\r
416\r
0fa00159 417 //\r
eceb3a4c 418 // Search the match registered Extract handler for the input guided section.\r
0fa00159 419 //\r
3dbef428 420 ASSERT (HandlerInfo != NULL);\r
0fa00159 421 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
30f001ca 422 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionDefinitionGuid)) {\r
b911d09f
LG
423 //\r
424 // Call the match handler to extract raw data for the input guided section.\r
425 //\r
426 return HandlerInfo->ExtractDecodeHandlerTable [Index] (\r
427 InputSection,\r
428 OutputBuffer,\r
429 ScratchBuffer,\r
430 AuthenticationStatus\r
431 );\r
0fa00159
LG
432 }\r
433 }\r
434\r
435 //\r
9095d37b 436 // Not found, the input guided section is not supported.\r
0fa00159 437 //\r
b911d09f 438 return RETURN_UNSUPPORTED;\r
0fa00159 439}\r
9be899c5
ED
440\r
441/**\r
9095d37b 442 Retrieves handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and\r
9be899c5 443 EXTRACT_GUIDED_SECTION_DECODE_HANDLER for a specific GUID section type.\r
9095d37b
LG
444\r
445 Retrieves the handlers associated with SectionGuid and returns them in\r
9be899c5
ED
446 GetInfoHandler and DecodeHandler.\r
447\r
9095d37b 448 If the GUID value specified by SectionGuid has not been registered, then\r
9be899c5 449 return RETURN_NOT_FOUND.\r
9095d37b 450\r
9be899c5
ED
451 If SectionGuid is NULL, then ASSERT().\r
452\r
9095d37b 453 @param[in] SectionGuid A pointer to the GUID associated with the handlersof the GUIDed\r
9be899c5 454 section type being retrieved.\r
9095d37b
LG
455 @param[out] GetInfoHandler Pointer to a function that examines a GUIDed section and returns\r
456 the size of the decoded buffer and the size of an optional scratch\r
457 buffer required to actually decode the data in a GUIDed section.\r
458 This is an optional parameter that may be NULL. If it is NULL, then\r
9be899c5
ED
459 the previously registered handler is not returned.\r
460 @param[out] DecodeHandler Pointer to a function that decodes a GUIDed section into a caller\r
461 allocated output buffer. This is an optional parameter that may be NULL.\r
462 If it is NULL, then the previously registered handler is not returned.\r
463\r
464 @retval RETURN_SUCCESS The handlers were retrieved.\r
465 @retval RETURN_NOT_FOUND No handlers have been registered with the specified GUID.\r
466\r
467**/\r
468RETURN_STATUS\r
469EFIAPI\r
470ExtractGuidedSectionGetHandlers (\r
471 IN CONST GUID *SectionGuid,\r
d0e2f823 472 OUT EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *GetInfoHandler OPTIONAL,\r
9be899c5
ED
473 OUT EXTRACT_GUIDED_SECTION_DECODE_HANDLER *DecodeHandler OPTIONAL\r
474 )\r
475{\r
476 EFI_STATUS Status;\r
477 UINT32 Index;\r
478 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r
479\r
480 //\r
481 // Check input parameter\r
482 //\r
483 ASSERT (SectionGuid != NULL);\r
484\r
485 //\r
486 // Get the registered handler information\r
487 //\r
488 Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r
489 if (EFI_ERROR (Status)) {\r
490 return Status;\r
491 }\r
492\r
493 //\r
494 // Search the match registered GetInfo handler for the input guided section.\r
495 //\r
496 ASSERT (HandlerInfo != NULL);\r
497 for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r
498 if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r
499\r
500 //\r
501 // If the guided handler has been registered before, then return the registered handlers.\r
502 //\r
503 if (GetInfoHandler != NULL) {\r
504 *GetInfoHandler = HandlerInfo->ExtractGetInfoHandlerTable[Index];\r
505 }\r
506 if (DecodeHandler != NULL) {\r
507 *DecodeHandler = HandlerInfo->ExtractDecodeHandlerTable[Index];\r
508 }\r
509 return RETURN_SUCCESS;\r
510 }\r
511 }\r
512 return RETURN_NOT_FOUND;\r
513}\r