2 Provide generic extract guided section functions.
4 Copyright (c) 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/ExtractGuidedSectionLib.h>
23 #define PEI_EXTRACT_HANDLER_INFO_SIGNATURE EFI_SIGNATURE_32 ('P', 'E', 'H', 'I')
27 UINT32 NumberOfExtractHandler
;
28 GUID
*ExtractHandlerGuidTable
;
29 EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*ExtractDecodeHandlerTable
;
30 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*ExtractGetInfoHandlerTable
;
31 } PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
;
34 Build guid hob for the global memory to store the registered guid and Handler list.
35 If GuidHob exists, HandlerInfo will be directly got from Guid hob data.
37 @param[in, out] InfoPointer Pointer to pei handler info structure.
39 @retval RETURN_SUCCESS Build Guid hob for the global memory space to store guid and funciton tables.
40 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
44 PeiGetExtractGuidedSectionHandlerInfo (
45 IN OUT PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
**InfoPointer
48 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
49 EFI_PEI_HOB_POINTERS Hob
;
52 // First try to get handler info from guid hob specified by CallerId.
54 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GetHobList ());
55 while (Hob
.Raw
!= NULL
) {
56 if (CompareGuid (&(Hob
.Guid
->Name
), &gEfiCallerIdGuid
)) {
57 HandlerInfo
= (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*) GET_GUID_HOB_DATA (Hob
.Guid
);
58 if (HandlerInfo
->Signature
== PEI_EXTRACT_HANDLER_INFO_SIGNATURE
) {
60 // Update Table Pointer when hob start address is changed.
62 if (HandlerInfo
->ExtractHandlerGuidTable
!= (GUID
*) (HandlerInfo
+ 1)) {
63 HandlerInfo
->ExtractHandlerGuidTable
= (GUID
*) (HandlerInfo
+ 1);
64 HandlerInfo
->ExtractDecodeHandlerTable
= (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*) (
65 (UINT8
*)HandlerInfo
->ExtractHandlerGuidTable
+
66 PcdGet32 (PcdMaximumGuidedExtractHandler
) * sizeof (GUID
)
68 HandlerInfo
->ExtractGetInfoHandlerTable
= (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*) (
69 (UINT8
*)HandlerInfo
->ExtractDecodeHandlerTable
+
70 PcdGet32 (PcdMaximumGuidedExtractHandler
) *
71 sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
)
75 // Return HandlerInfo pointer.
77 *InfoPointer
= HandlerInfo
;
81 Hob
.Raw
= GET_NEXT_HOB (Hob
);
82 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, Hob
.Raw
);
86 // If Guid Hob is not found, Build CallerId Guid hob to store Handler Info
88 HandlerInfo
= BuildGuidHob (
90 sizeof (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
) +
91 PcdGet32 (PcdMaximumGuidedExtractHandler
) *
92 (sizeof (GUID
) + sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
) + sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
))
94 if (HandlerInfo
== NULL
) {
96 // No enough resource to build guid hob.
98 return EFI_OUT_OF_RESOURCES
;
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
)
107 HandlerInfo
->ExtractGetInfoHandlerTable
= (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*) (
108 (UINT8
*)HandlerInfo
->ExtractDecodeHandlerTable
+
109 PcdGet32 (PcdMaximumGuidedExtractHandler
) *
110 sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
)
113 *InfoPointer
= HandlerInfo
;
118 Get the supported exract guided section Handler guid list.
119 If ExtractHandlerGuidTable = NULL, then ASSERT.
121 @param[in, out] ExtractHandlerGuidTable The extract Handler guid pointer list.
123 @retval return the number of the supported extract guided Handler.
127 ExtractGuidedSectionGetGuidList (
128 IN OUT GUID
**ExtractHandlerGuidTable
132 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
134 ASSERT (ExtractHandlerGuidTable
!= NULL
);
136 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
137 if (EFI_ERROR (Status
)) {
141 *ExtractHandlerGuidTable
= HandlerInfo
->ExtractHandlerGuidTable
;
142 return HandlerInfo
->NumberOfExtractHandler
;
146 Register Guided Section Extract and GetInfo handler.
148 @param[in] SectionGuid The guid matches this Extraction function.
149 @param[in] GetInfoHandler Function to get info from guided section.
150 @param[in] DecodeHandler Function to extract guided section.
152 @retval RETURN_SUCCESS Register Guided Section Extract function successfully.
153 @retval RETURN_OUT_OF_RESOURCES Resource is not enough to register new function.
154 @retval RETURN_INVALID_PARAMETER Input pointer to Guid value is not valid.
158 ExtractGuidedSectionRegisterHandlers (
159 IN CONST GUID
*SectionGuid
,
160 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler
,
161 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler
166 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
169 // Check input paramter.
171 if (SectionGuid
== NULL
) {
172 return RETURN_INVALID_PARAMETER
;
176 // Get the registered handler information
178 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
179 if (EFI_ERROR (Status
)) {
184 // Search the match registered GetInfo handler for the input guided section.
186 for (Index
= 0; Index
< HandlerInfo
->NumberOfExtractHandler
; Index
++) {
187 if (CompareGuid (HandlerInfo
->ExtractHandlerGuidTable
+ Index
, SectionGuid
)) {
193 // If the guided handler has been registered before, only update its handler.
195 if (Index
< HandlerInfo
->NumberOfExtractHandler
) {
196 HandlerInfo
->ExtractDecodeHandlerTable
[Index
] = DecodeHandler
;
197 HandlerInfo
->ExtractGetInfoHandlerTable
[Index
] = GetInfoHandler
;
198 return RETURN_SUCCESS
;
202 // Check the global table is enough to contain new Handler.
204 if (HandlerInfo
->NumberOfExtractHandler
>= PcdGet32 (PcdMaximumGuidedExtractHandler
)) {
205 return RETURN_OUT_OF_RESOURCES
;
209 // Register new Handler and guid value.
211 CopyGuid (HandlerInfo
->ExtractHandlerGuidTable
+ HandlerInfo
->NumberOfExtractHandler
, SectionGuid
);
212 HandlerInfo
->ExtractDecodeHandlerTable
[HandlerInfo
->NumberOfExtractHandler
] = DecodeHandler
;
213 HandlerInfo
->ExtractGetInfoHandlerTable
[HandlerInfo
->NumberOfExtractHandler
++] = GetInfoHandler
;
215 return RETURN_SUCCESS
;
219 Get information from the guided section. This function first gets the guid value
220 from guided section header, then match this guid in the registered extract Handler list
221 to its corresponding getinfo Handler.
222 If not found, RETURN_INVALID_PARAMETER will be return.
223 If found, it will call the getinfo Handler to get the required size and attribute.
225 It will ASSERT () if the pointer to OutputBufferSize is NULL.
226 It will ASSERT () if the pointer to ScratchBufferSize is NULL.
227 It will ASSERT () if the pointer to SectionAttribute is NULL.
229 @param[in] InputSection Buffer containing the input GUIDed section to be processed.
230 @param[out] OutputBufferSize The size of OutputBuffer.
231 @param[out] ScratchBufferSize The size of ScratchBuffer.
232 @param[out] SectionAttribute The attribute of the input guided section.
234 @retval RETURN_SUCCESS Get the required information successfully.
235 @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly.
236 The GUID in InputSection does not match any registered guid list.
241 ExtractGuidedSectionGetInfo (
242 IN CONST VOID
*InputSection
,
243 OUT UINT32
*OutputBufferSize
,
244 OUT UINT32
*ScratchBufferSize
,
245 OUT UINT16
*SectionAttribute
250 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
253 // Check input paramter
255 if (InputSection
== NULL
) {
256 return RETURN_INVALID_PARAMETER
;
259 ASSERT (OutputBufferSize
!= NULL
);
260 ASSERT (ScratchBufferSize
!= NULL
);
261 ASSERT (SectionAttribute
!= NULL
);
264 // Get the registered handler information.
266 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
267 if (EFI_ERROR (Status
)) {
272 // Search the match registered GetInfo handler for the input guided section.
274 for (Index
= 0; Index
< HandlerInfo
->NumberOfExtractHandler
; Index
++) {
275 if (CompareGuid (HandlerInfo
->ExtractHandlerGuidTable
+ Index
, &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
281 // Not found, the input guided section is not supported.
283 if (Index
== HandlerInfo
->NumberOfExtractHandler
) {
284 return RETURN_INVALID_PARAMETER
;
288 // Call the match handler to getinfo for the input section data.
290 return HandlerInfo
->ExtractGetInfoHandlerTable
[Index
] (
299 Extract data from the guided section. This function first gets the guid value
300 from guided section header, then match this guid in the registered extract Handler list
301 to its corresponding extract Handler.
302 If not found, RETURN_INVALID_PARAMETER will be return.
303 If found, it will call this extract Handler to get output data and AuthenticationStatus.
305 It will ASSERT () if the pointer to OutputBuffer is NULL.
306 It will ASSERT () if the pointer to AuthenticationStatus is NULL.
308 @param[in] InputSection Buffer containing the input GUIDed section to be processed.
309 @param[out] OutputBuffer OutputBuffer to point the start of the section's contents
310 if guided data is not required prcessing. Otherwise,
311 OutputBuffer to contain the output data, which is
312 allocated by the caller.
313 @param[out] ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
314 @param[out] AuthenticationStatus
315 A pointer to a caller-allocated UINT32 that indicates the
316 authentication status of the output buffer.
318 @retval RETURN_SUCCESS Get the output data, size and AuthenticationStatus successfully.
319 @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly.
320 The GUID in InputSection does not match any registered guid list.
325 ExtractGuidedSectionDecode (
326 IN CONST VOID
*InputSection
,
327 OUT VOID
**OutputBuffer
,
328 OUT VOID
*ScratchBuffer
, OPTIONAL
329 OUT UINT32
*AuthenticationStatus
334 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
336 if (InputSection
== NULL
) {
337 return RETURN_INVALID_PARAMETER
;
340 ASSERT (OutputBuffer
!= NULL
);
341 ASSERT (AuthenticationStatus
!= NULL
);
343 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
344 if (EFI_ERROR (Status
)) {
349 // Search the match registered GetInfo handler for the input guided section.
351 for (Index
= 0; Index
< HandlerInfo
->NumberOfExtractHandler
; Index
++) {
352 if (CompareGuid (HandlerInfo
->ExtractHandlerGuidTable
+ Index
, &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
358 // Not found, the input guided section is not supported.
360 if (Index
== HandlerInfo
->NumberOfExtractHandler
) {
361 return RETURN_INVALID_PARAMETER
;
365 // Call the match handler to getinfo for the input section data.
367 return HandlerInfo
->ExtractDecodeHandlerTable
[Index
] (