3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 PeiExtractGuidedSectionLib.c
18 Provide generic extract guided section functions.
24 #include <Library/DebugLib.h>
25 #include <Library/PcdLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/HobLib.h>
28 #include <Library/ExtractGuidedSectionLib.h>
30 #define PEI_EXTRACT_HANDLER_INFO_SIGNATURE EFI_SIGNATURE_32 ('P', 'E', 'H', 'I')
34 UINT32 NumberOfExtractHandler
;
35 GUID
*ExtractHandlerGuidTable
;
36 EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*ExtractDecodeHandlerTable
;
37 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*ExtractGetInfoHandlerTable
;
38 } PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
;
41 Build guid hob for the global memory to store the registered guid and Handler list.
42 If GuidHob exists, HandlerInfo will be directly got from Guid hob data.
44 @param[in, out] InfoPointer Pointer to pei handler info structure.
46 @retval RETURN_SUCCESS Build Guid hob for the global memory space to store guid and funciton tables.
47 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
51 PeiGetExtractGuidedSectionHandlerInfo (
52 IN OUT PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
**InfoPointer
55 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
56 EFI_PEI_HOB_POINTERS Hob
;
59 // First try to get handler info from guid hob specified by CallerId.
61 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GetHobList ());
62 while (Hob
.Raw
!= NULL
) {
63 if (CompareGuid (&(Hob
.Guid
->Name
), &gEfiCallerIdGuid
)) {
64 HandlerInfo
= (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*) GET_GUID_HOB_DATA (Hob
.Guid
);
65 if (HandlerInfo
->Signature
== PEI_EXTRACT_HANDLER_INFO_SIGNATURE
) {
66 *InfoPointer
= HandlerInfo
;
70 Hob
.Raw
= GET_NEXT_HOB (Hob
);
71 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, Hob
.Raw
);
75 // If Guid Hob is not found, Build CallerId Guid hob to store Handler Info
77 HandlerInfo
= BuildGuidHob (
79 sizeof (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
) +
80 PcdGet32 (PcdMaximumGuidedExtractHandler
) *
81 (sizeof (GUID
) + sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
) + sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
))
83 if (HandlerInfo
== NULL
) {
85 // No enough resource to build guid hob.
87 return EFI_OUT_OF_RESOURCES
;
89 HandlerInfo
->Signature
= PEI_EXTRACT_HANDLER_INFO_SIGNATURE
;
90 HandlerInfo
->NumberOfExtractHandler
= 0;
91 HandlerInfo
->ExtractHandlerGuidTable
= (GUID
*) (HandlerInfo
+ 1);
92 HandlerInfo
->ExtractDecodeHandlerTable
= (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*) (
93 (UINT8
*)HandlerInfo
->ExtractHandlerGuidTable
+
94 PcdGet32 (PcdMaximumGuidedExtractHandler
) * sizeof (GUID
)
96 HandlerInfo
->ExtractGetInfoHandlerTable
= (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*) (
97 (UINT8
*)HandlerInfo
->ExtractDecodeHandlerTable
+
98 PcdGet32 (PcdMaximumGuidedExtractHandler
) *
99 sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
)
102 *InfoPointer
= HandlerInfo
;
107 Get the supported exract guided section Handler guid list.
108 If ExtractHandlerGuidTable = NULL, then ASSERT.
110 @param[in, out] ExtractHandlerGuidTable The extract Handler guid pointer list.
112 @retval return the number of the supported extract guided Handler.
116 ExtractGuidedSectionGetGuidList (
117 IN OUT GUID
**ExtractHandlerGuidTable
121 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
123 ASSERT (ExtractHandlerGuidTable
!= NULL
);
125 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
126 if (EFI_ERROR (Status
)) {
130 *ExtractHandlerGuidTable
= HandlerInfo
->ExtractHandlerGuidTable
;
131 return HandlerInfo
->NumberOfExtractHandler
;
135 Register Guided Section Extract and GetInfo handler.
137 @param[in] SectionGuid The guid matches this Extraction function.
138 @param[in] GetInfoHandler Function to get info from guided section.
139 @param[in] DecodeHandler Function to extract guided section.
141 @retval RETURN_SUCCESS Register Guided Section Extract function successfully.
142 @retval RETURN_OUT_OF_RESOURCES Resource is not enough to register new function.
143 @retval RETURN_INVALID_PARAMETER Input pointer to Guid value is not valid.
147 ExtractGuidedSectionRegisterHandlers (
148 IN CONST GUID
*SectionGuid
,
149 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler
,
150 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler
154 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
157 // Check input paramter.
159 if (SectionGuid
== NULL
) {
160 return RETURN_INVALID_PARAMETER
;
164 // Get the registered handler information
166 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
167 if (EFI_ERROR (Status
)) {
171 // Check the global table is enough to contain new Handler.
173 if (HandlerInfo
->NumberOfExtractHandler
>= PcdGet32 (PcdMaximumGuidedExtractHandler
)) {
174 return RETURN_OUT_OF_RESOURCES
;
178 // Register new Handler and guid value.
180 CopyGuid (&(HandlerInfo
->ExtractHandlerGuidTable
[HandlerInfo
->NumberOfExtractHandler
]), SectionGuid
);
181 HandlerInfo
->ExtractDecodeHandlerTable
[HandlerInfo
->NumberOfExtractHandler
] = DecodeHandler
;
182 HandlerInfo
->ExtractGetInfoHandlerTable
[HandlerInfo
->NumberOfExtractHandler
++] = GetInfoHandler
;
184 return RETURN_SUCCESS
;
188 Get information from the guided section. This function first gets the guid value
189 from guided section header, then match this guid in the registered extract Handler list
190 to its corresponding getinfo Handler.
191 If not found, RETURN_INVALID_PARAMETER will be return.
192 If found, it will call the getinfo Handler to get the required size and attribute.
194 It will ASSERT () if the pointer to OutputBufferSize is NULL.
195 It will ASSERT () if the pointer to ScratchBufferSize is NULL.
196 It will ASSERT () if the pointer to SectionAttribute is NULL.
198 @param[in] InputSection Buffer containing the input GUIDed section to be processed.
199 @param[out] OutputBufferSize The size of OutputBuffer.
200 @param[out] ScratchBufferSize The size of ScratchBuffer.
201 @param[out] SectionAttribute The attribute of the input guided section.
203 @retval RETURN_SUCCESS Get the required information successfully.
204 @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly.
205 The GUID in InputSection does not match any registered guid list.
210 ExtractGuidedSectionGetInfo (
211 IN CONST VOID
*InputSection
,
212 OUT UINT32
*OutputBufferSize
,
213 OUT UINT32
*ScratchBufferSize
,
214 OUT UINT16
*SectionAttribute
219 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
222 // Check input paramter
224 if (InputSection
== NULL
) {
225 return RETURN_INVALID_PARAMETER
;
228 ASSERT (OutputBufferSize
!= NULL
);
229 ASSERT (ScratchBufferSize
!= NULL
);
230 ASSERT (SectionAttribute
!= NULL
);
233 // Get the registered handler information.
235 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
236 if (EFI_ERROR (Status
)) {
241 // Search the match registered GetInfo handler for the input guided section.
243 for (Index
= 0; Index
< HandlerInfo
->NumberOfExtractHandler
; Index
++) {
244 if (CompareGuid (&(HandlerInfo
->ExtractHandlerGuidTable
[Index
]), &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
250 // Not found, the input guided section is not supported.
252 if (Index
== HandlerInfo
->NumberOfExtractHandler
) {
253 return RETURN_INVALID_PARAMETER
;
257 // Call the match handler to getinfo for the input section data.
259 return HandlerInfo
->ExtractGetInfoHandlerTable
[Index
] (
268 Extract data from the guided section. This function first gets the guid value
269 from guided section header, then match this guid in the registered extract Handler list
270 to its corresponding extract Handler.
271 If not found, RETURN_INVALID_PARAMETER will be return.
272 If found, it will call this extract Handler to get output data and AuthenticationStatus.
274 It will ASSERT () if the pointer to OutputBuffer is NULL.
275 It will ASSERT () if the pointer to AuthenticationStatus is NULL.
277 @param[in] InputSection Buffer containing the input GUIDed section to be processed.
278 @param[out] OutputBuffer OutputBuffer to point the start of the section's contents
279 if guided data is not required prcessing. Otherwise,
280 OutputBuffer to contain the output data, which is
281 allocated by the caller.
282 @param[out] ScratchBuffer A pointer to a caller-allocated buffer for function internal use.
283 @param[out] AuthenticationStatus
284 A pointer to a caller-allocated UINT32 that indicates the
285 authentication status of the output buffer.
287 @retval RETURN_SUCCESS Get the output data, size and AuthenticationStatus successfully.
288 @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly.
289 The GUID in InputSection does not match any registered guid list.
294 ExtractGuidedSectionDecode (
295 IN CONST VOID
*InputSection
,
296 OUT VOID
**OutputBuffer
,
297 OUT VOID
*ScratchBuffer
, OPTIONAL
298 OUT UINT32
*AuthenticationStatus
303 PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO
*HandlerInfo
;
305 if (InputSection
== NULL
) {
306 return RETURN_INVALID_PARAMETER
;
309 ASSERT (OutputBuffer
!= NULL
);
310 ASSERT (AuthenticationStatus
!= NULL
);
312 Status
= PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo
);
313 if (EFI_ERROR (Status
)) {
318 // Search the match registered GetInfo handler for the input guided section.
320 for (Index
= 0; Index
< HandlerInfo
->NumberOfExtractHandler
; Index
++) {
321 if (CompareGuid (&(HandlerInfo
->ExtractHandlerGuidTable
[Index
]), &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
327 // Not found, the input guided section is not supported.
329 if (Index
== HandlerInfo
->NumberOfExtractHandler
) {
330 return RETURN_INVALID_PARAMETER
;
334 // Call the match handler to getinfo for the input section data.
336 return HandlerInfo
->ExtractDecodeHandlerTable
[Index
] (