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