2 Provide generic extract guided section functions for Dxe phase.
4 Copyright (c) 2007 - 2008, 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/MemoryAllocationLib.h>
21 #include <Library/ExtractGuidedSectionLib.h>
23 GUID
*mExtractHandlerGuidTable
;
24 UINT32 mNumberOfExtractHandler
= 0;
26 EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*mExtractDecodeHandlerTable
;
27 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*mExtractGetInfoHandlerTable
;
30 Constructor allocates the global memory to store the registered guid and Handler list.
32 @param ImageHandle The firmware allocated handle for the EFI image.
33 @param SystemTable A pointer to the EFI System Table.
35 @retval RETURN_SUCCESS Allocate the global memory space to store guid and function tables.
36 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
40 DxeExtractGuidedSectionLibConstructor (
41 IN EFI_HANDLE ImageHandle
,
42 IN EFI_SYSTEM_TABLE
*SystemTable
46 // Allocate global pool space to store the registered handler and its guid value.
48 mExtractHandlerGuidTable
= (GUID
*) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler
) * sizeof (GUID
));
49 if (mExtractHandlerGuidTable
== NULL
) {
50 return RETURN_OUT_OF_RESOURCES
;
53 mExtractDecodeHandlerTable
= (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
*) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler
) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER
));
54 if (mExtractDecodeHandlerTable
== NULL
) {
55 FreePool (mExtractHandlerGuidTable
);
56 return RETURN_OUT_OF_RESOURCES
;
59 mExtractGetInfoHandlerTable
= (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
*) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler
) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER
));
60 if (mExtractGetInfoHandlerTable
== NULL
) {
61 FreePool (mExtractHandlerGuidTable
);
62 FreePool (mExtractDecodeHandlerTable
);
63 return RETURN_OUT_OF_RESOURCES
;
66 return RETURN_SUCCESS
;
70 Retrieve the list GUIDs that have been registered through ExtractGuidedSectionRegisterHandlers().
72 Sets ExtractHandlerGuidTable so it points at a callee allocated array of registered GUIDs.
73 The total number of GUIDs in the array are returned. Since the array of GUIDs is callee allocated
74 and caller must treat this array of GUIDs as read-only data.
75 If ExtractHandlerGuidTable is NULL, then ASSERT().
77 @param[out] ExtractHandlerGuidTable A pointer to the array of GUIDs that have been registered through
78 ExtractGuidedSectionRegisterHandlers().
80 @return the number of the supported extract guided Handler.
85 ExtractGuidedSectionGetGuidList (
86 OUT GUID
**ExtractHandlerGuidTable
89 ASSERT (ExtractHandlerGuidTable
!= NULL
);
91 *ExtractHandlerGuidTable
= mExtractHandlerGuidTable
;
92 return mNumberOfExtractHandler
;
96 Registers handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and EXTRACT_GUIDED_SECTION_DECODE_HANDLER
97 for a specific GUID section type.
99 Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.
100 If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.
101 If there are not enough resources available to register the handlers then RETURN_OUT_OF_RESOURCES is returned.
103 If SectionGuid is NULL, then ASSERT().
104 If GetInfoHandler is NULL, then ASSERT().
105 If DecodeHandler is NULL, then ASSERT().
107 @param[in] SectionGuid A pointer to the GUID associated with the the handlers
108 of the GUIDed section type being registered.
109 @param[in] GetInfoHandler Pointer to a function that examines a GUIDed section and returns the
110 size of the decoded buffer and the size of an optional scratch buffer
111 required to actually decode the data in a GUIDed section.
112 @param[in] DecodeHandler Pointer to a function that decodes a GUIDed section into a caller
113 allocated output buffer.
115 @retval RETURN_SUCCESS The handlers were registered.
116 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to register the handlers.
121 ExtractGuidedSectionRegisterHandlers (
122 IN CONST GUID
*SectionGuid
,
123 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler
,
124 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler
129 // Check input paramter.
131 ASSERT (SectionGuid
!= NULL
);
132 ASSERT (GetInfoHandler
!= NULL
);
133 ASSERT (DecodeHandler
!= NULL
);
136 // Search the match registered GetInfo handler for the input guided section.
138 for (Index
= 0; Index
< mNumberOfExtractHandler
; Index
++) {
139 if (CompareGuid (&mExtractHandlerGuidTable
[Index
], SectionGuid
)) {
141 // If the guided handler has been registered before, only update its handler.
143 mExtractDecodeHandlerTable
[Index
] = DecodeHandler
;
144 mExtractGetInfoHandlerTable
[Index
] = GetInfoHandler
;
145 return RETURN_SUCCESS
;
150 // Check the global table is enough to contain new Handler.
152 if (mNumberOfExtractHandler
>= PcdGet32 (PcdMaximumGuidedExtractHandler
)) {
153 return RETURN_OUT_OF_RESOURCES
;
157 // Register new Handler and guid value.
159 CopyGuid (&mExtractHandlerGuidTable
[mNumberOfExtractHandler
], SectionGuid
);
160 mExtractDecodeHandlerTable
[mNumberOfExtractHandler
] = DecodeHandler
;
161 mExtractGetInfoHandlerTable
[mNumberOfExtractHandler
++] = GetInfoHandler
;
163 return RETURN_SUCCESS
;
167 Retrieves a GUID from a GUIDed section and uses that GUID to select an associated handler of type
168 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().
169 The selected handler is used to retrieve and return the size of the decoded buffer and the size of an
170 optional scratch buffer required to actually decode the data in a GUIDed section.
172 Examines a GUIDed section specified by InputSection.
173 If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),
174 then RETURN_UNSUPPORTED is returned.
175 If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler
176 of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()
177 is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of
178 type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.
180 If InputSection is NULL, then ASSERT().
181 If OutputBufferSize is NULL, then ASSERT().
182 If ScratchBufferSize is NULL, then ASSERT().
183 If SectionAttribute is NULL, then ASSERT().
185 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
186 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required if the buffer
187 specified by InputSection were decoded.
188 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space if the buffer specified by
189 InputSection were decoded.
190 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes field of
191 EFI_GUID_DEFINED_SECTION in the PI Specification.
193 @retval RETURN_SUCCESS Get the required information successfully.
194 @retval RETURN_UNSUPPORTED The GUID from the section specified by InputSection does not match any of
195 the GUIDs registered with ExtractGuidedSectionRegisterHandlers().
196 @retval Others The return status from the handler associated with the GUID retrieved from
197 the section specified by InputSection.
202 ExtractGuidedSectionGetInfo (
203 IN CONST VOID
*InputSection
,
204 OUT UINT32
*OutputBufferSize
,
205 OUT UINT32
*ScratchBufferSize
,
206 OUT UINT16
*SectionAttribute
211 ASSERT (InputSection
!= NULL
);
212 ASSERT (OutputBufferSize
!= NULL
);
213 ASSERT (ScratchBufferSize
!= NULL
);
214 ASSERT (SectionAttribute
!= NULL
);
217 // Search the match registered GetInfo handler for the input guided section.
219 for (Index
= 0; Index
< mNumberOfExtractHandler
; Index
++) {
220 if (CompareGuid (&mExtractHandlerGuidTable
[Index
], &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
222 // Call the match handler to getinfo for the input section data.
224 return mExtractGetInfoHandlerTable
[Index
] (
234 // Not found, the input guided section is not supported.
236 return RETURN_UNSUPPORTED
;
240 Retrieves the GUID from a GUIDed section and uses that GUID to select an associated handler of type
241 EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().
242 The selected handler is used to decode the data in a GUIDed section and return the result in a caller
243 allocated output buffer.
245 Decodes the GUIDed section specified by InputSection.
246 If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),
247 then RETURN_UNSUPPORTED is returned.
248 If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler
249 of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()
250 is used to decode InputSection into the buffer specified by OutputBuffer and the authentication status of this
251 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the data in InputSection,
252 then OutputBuffer is set to point at the data in InputSection. Otherwise, the decoded data will be placed in caller
253 allocated buffer specified by OutputBuffer. This function is responsible for computing the EFI_AUTH_STATUS_PLATFORM_OVERRIDE
254 bit of in AuthenticationStatus. The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned.
256 If InputSection is NULL, then ASSERT().
257 If OutputBuffer is NULL, then ASSERT().
258 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().
259 If AuthenticationStatus is NULL, then ASSERT().
261 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.
262 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.
263 @param[in] ScratchBuffer A caller allocated buffer that may be required by this function as a scratch buffer to perform the decode operation.
264 @param[out] AuthenticationStatus
265 A pointer to the authentication status of the decoded output buffer. See the definition
266 of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI section of the PI
269 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.
270 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.
271 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.
276 ExtractGuidedSectionDecode (
277 IN CONST VOID
*InputSection
,
278 OUT VOID
**OutputBuffer
,
279 IN VOID
*ScratchBuffer
, OPTIONAL
280 OUT UINT32
*AuthenticationStatus
286 // Check the input parameters
288 ASSERT (InputSection
!= NULL
);
289 ASSERT (OutputBuffer
!= NULL
);
290 ASSERT (AuthenticationStatus
!= NULL
);
293 // Search the match registered extract handler for the input guided section.
295 for (Index
= 0; Index
< mNumberOfExtractHandler
; Index
++) {
296 if (CompareGuid (&mExtractHandlerGuidTable
[Index
], &(((EFI_GUID_DEFINED_SECTION
*) InputSection
)->SectionDefinitionGuid
))) {
298 // Call the match handler to extract raw data for the input section data.
300 return mExtractDecodeHandlerTable
[Index
] (
310 // Not found, the input guided section is not supported.
312 return RETURN_UNSUPPORTED
;