]>
Commit | Line | Data |
---|---|---|
8069d49e | 1 | /** @file\r |
eceb3a4c | 2 | Provide generic extract guided section functions for Dxe phase.\r |
0fa00159 | 3 | \r |
58380e9c | 4 | Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r |
19388d29 | 5 | This program and the accompanying materials\r |
8069d49e LG |
6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
2fc59a00 | 8 | http://opensource.org/licenses/bsd-license.php.\r |
0fa00159 | 9 | \r |
8069d49e LG |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
0fa00159 | 12 | \r |
8069d49e | 13 | **/\r |
0fa00159 LG |
14 | \r |
15 | #include <PiDxe.h>\r | |
16 | \r | |
17 | #include <Library/DebugLib.h>\r | |
0fa00159 LG |
18 | #include <Library/BaseMemoryLib.h>\r |
19 | #include <Library/MemoryAllocationLib.h>\r | |
20 | #include <Library/ExtractGuidedSectionLib.h>\r | |
21 | \r | |
de2314f8 LG |
22 | #define EXTRACT_HANDLER_TABLE_SIZE 0x10\r |
23 | \r | |
fe467413 | 24 | UINT32 mNumberOfExtractHandler = 0;\r |
de2314f8 | 25 | UINT32 mMaxNumberOfExtractHandler = 0;\r |
0fa00159 | 26 | \r |
de2314f8 LG |
27 | GUID *mExtractHandlerGuidTable = NULL;\r |
28 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable = NULL;\r | |
29 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable = NULL;\r | |
0fa00159 | 30 | \r |
4754c98b | 31 | /**\r |
de2314f8 | 32 | Reallocates more global memory to store the registered guid and Handler list.\r |
0fa00159 | 33 | \r |
58380e9c | 34 | @retval RETURN_SUCCESS Reallocated more global memory space to store guid and function tables.\r |
35 | @retval RETURN_OUT_OF_RESOURCES Not enough memory to allocate.\r | |
0fa00159 LG |
36 | **/\r |
37 | RETURN_STATUS\r | |
38 | EFIAPI\r | |
de2314f8 | 39 | ReallocateExtractHandlerTable (\r |
0fa00159 | 40 | )\r |
de2314f8 | 41 | { \r |
0fa00159 | 42 | //\r |
de2314f8 | 43 | // Reallocate memory for GuidTable\r |
0fa00159 | 44 | //\r |
de2314f8 LG |
45 | mExtractHandlerGuidTable = ReallocatePool (\r |
46 | mMaxNumberOfExtractHandler * sizeof (GUID), \r | |
47 | (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (GUID), \r | |
48 | mExtractHandlerGuidTable\r | |
49 | );\r | |
50 | \r | |
0fa00159 | 51 | if (mExtractHandlerGuidTable == NULL) {\r |
de2314f8 | 52 | goto Done;\r |
0fa00159 | 53 | }\r |
de2314f8 LG |
54 | \r |
55 | //\r | |
56 | // Reallocate memory for Decode handler Table\r | |
57 | //\r | |
58 | mExtractDecodeHandlerTable = ReallocatePool (\r | |
59 | mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER), \r | |
60 | (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER), \r | |
61 | mExtractDecodeHandlerTable\r | |
62 | );\r | |
63 | \r | |
0fa00159 | 64 | if (mExtractDecodeHandlerTable == NULL) {\r |
de2314f8 | 65 | goto Done;\r |
0fa00159 LG |
66 | }\r |
67 | \r | |
de2314f8 LG |
68 | //\r |
69 | // Reallocate memory for GetInfo handler Table\r | |
70 | //\r | |
71 | mExtractGetInfoHandlerTable = ReallocatePool (\r | |
72 | mMaxNumberOfExtractHandler * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER), \r | |
73 | (mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER), \r | |
74 | mExtractGetInfoHandlerTable\r | |
75 | );\r | |
76 | \r | |
0fa00159 | 77 | if (mExtractGetInfoHandlerTable == NULL) {\r |
de2314f8 LG |
78 | goto Done;\r |
79 | }\r | |
80 | \r | |
81 | //\r | |
82 | // Increase max handler number\r | |
83 | //\r | |
84 | mMaxNumberOfExtractHandler = mMaxNumberOfExtractHandler + EXTRACT_HANDLER_TABLE_SIZE;\r | |
85 | return RETURN_SUCCESS;\r | |
86 | \r | |
87 | Done:\r | |
88 | if (mExtractHandlerGuidTable != NULL) {\r | |
b911d09f | 89 | FreePool (mExtractHandlerGuidTable);\r |
de2314f8 LG |
90 | }\r |
91 | if (mExtractDecodeHandlerTable != NULL) {\r | |
b911d09f | 92 | FreePool (mExtractDecodeHandlerTable);\r |
de2314f8 LG |
93 | }\r |
94 | if (mExtractGetInfoHandlerTable != NULL) {\r | |
95 | FreePool (mExtractGetInfoHandlerTable);\r | |
0fa00159 LG |
96 | }\r |
97 | \r | |
de2314f8 LG |
98 | return RETURN_OUT_OF_RESOURCES;\r |
99 | }\r | |
100 | /**\r | |
101 | Constructor allocates the global memory to store the registered guid and Handler list.\r | |
102 | \r | |
103 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
104 | @param SystemTable A pointer to the EFI System Table.\r | |
105 | \r | |
58380e9c | 106 | @retval RETURN_SUCCESS Allocated the global memory space to store guid and function tables.\r |
107 | @retval RETURN_OUT_OF_RESOURCES Not enough memory to allocate.\r | |
de2314f8 LG |
108 | **/\r |
109 | RETURN_STATUS\r | |
110 | EFIAPI\r | |
111 | DxeExtractGuidedSectionLibConstructor (\r | |
112 | IN EFI_HANDLE ImageHandle,\r | |
113 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
114 | )\r | |
115 | {\r | |
116 | return ReallocateExtractHandlerTable ();\r | |
0fa00159 LG |
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 | |
124 | and caller must treat this array of GUIDs as read-only data. \r | |
125 | If ExtractHandlerGuidTable is NULL, then ASSERT().\r | |
126 | \r | |
0057fda6 | 127 | @param[out] ExtractHandlerGuidTable A pointer to the array of GUIDs that have been registered through\r |
f1db45f8 | 128 | ExtractGuidedSectionRegisterHandlers().\r |
0fa00159 | 129 | \r |
58380e9c | 130 | @return The number of the supported extract guided Handler.\r |
f1db45f8 | 131 | \r |
0fa00159 LG |
132 | **/\r |
133 | UINTN\r | |
134 | EFIAPI\r | |
135 | ExtractGuidedSectionGetGuidList (\r | |
eceb3a4c | 136 | OUT GUID **ExtractHandlerGuidTable\r |
0fa00159 LG |
137 | )\r |
138 | {\r | |
139 | ASSERT (ExtractHandlerGuidTable != NULL);\r | |
140 | \r | |
141 | *ExtractHandlerGuidTable = mExtractHandlerGuidTable;\r | |
142 | return mNumberOfExtractHandler;\r | |
143 | }\r | |
144 | \r | |
4754c98b | 145 | /**\r |
f1db45f8 | 146 | Registers handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and EXTRACT_GUIDED_SECTION_DECODE_HANDLER\r |
147 | for a specific GUID section type.\r | |
148 | \r | |
0057fda6 | 149 | Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.\r |
f1db45f8 | 150 | If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.\r |
151 | If there are not enough resources available to register the handlers then RETURN_OUT_OF_RESOURCES is returned.\r | |
57209470 | 152 | \r |
f1db45f8 | 153 | If SectionGuid is NULL, then ASSERT().\r |
154 | If GetInfoHandler is NULL, then ASSERT().\r | |
155 | If DecodeHandler is NULL, then ASSERT().\r | |
156 | \r | |
157 | @param[in] SectionGuid A pointer to the GUID associated with the the handlers\r | |
158 | of the GUIDed section type being registered.\r | |
2fc59a00 | 159 | @param[in] GetInfoHandler The pointer to a function that examines a GUIDed section and returns the\r |
f1db45f8 | 160 | size of the decoded buffer and the size of an optional scratch buffer\r |
161 | required to actually decode the data in a GUIDed section.\r | |
2fc59a00 | 162 | @param[in] DecodeHandler The pointer to a function that decodes a GUIDed section into a caller\r |
f1db45f8 | 163 | allocated output buffer. \r |
164 | \r | |
165 | @retval RETURN_SUCCESS The handlers were registered.\r | |
f1db45f8 | 166 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to register the handlers.\r |
0fa00159 | 167 | \r |
0fa00159 LG |
168 | **/\r |
169 | RETURN_STATUS\r | |
170 | EFIAPI\r | |
171 | ExtractGuidedSectionRegisterHandlers (\r | |
172 | IN CONST GUID *SectionGuid,\r | |
173 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r | |
174 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r | |
175 | )\r | |
176 | {\r | |
e2701217 | 177 | UINT32 Index;\r |
0fa00159 LG |
178 | //\r |
179 | // Check input paramter.\r | |
180 | //\r | |
f1db45f8 | 181 | ASSERT (SectionGuid != NULL);\r |
182 | ASSERT (GetInfoHandler != NULL);\r | |
183 | ASSERT (DecodeHandler != NULL);\r | |
e2701217 LG |
184 | \r |
185 | //\r | |
186 | // Search the match registered GetInfo handler for the input guided section.\r | |
187 | //\r | |
188 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
189 | if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {\r | |
b911d09f LG |
190 | //\r |
191 | // If the guided handler has been registered before, only update its handler.\r | |
192 | //\r | |
193 | mExtractDecodeHandlerTable [Index] = DecodeHandler;\r | |
194 | mExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r | |
195 | return RETURN_SUCCESS;\r | |
e2701217 LG |
196 | }\r |
197 | }\r | |
e2701217 | 198 | \r |
0fa00159 LG |
199 | //\r |
200 | // Check the global table is enough to contain new Handler.\r | |
201 | //\r | |
de2314f8 LG |
202 | if (mNumberOfExtractHandler >= mMaxNumberOfExtractHandler) {\r |
203 | if (ReallocateExtractHandlerTable () != RETURN_SUCCESS) {\r | |
204 | return RETURN_OUT_OF_RESOURCES;\r | |
205 | }\r | |
0fa00159 LG |
206 | }\r |
207 | \r | |
208 | //\r | |
209 | // Register new Handler and guid value.\r | |
210 | //\r | |
211 | CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);\r | |
212 | mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;\r | |
213 | mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;\r | |
214 | \r | |
215 | return RETURN_SUCCESS;\r | |
216 | }\r | |
217 | \r | |
4754c98b | 218 | /**\r |
0057fda6 | 219 | Retrieves a GUID from a GUIDed section and uses that GUID to select an associated handler of type\r |
f1db45f8 | 220 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r |
221 | The selected handler is used to retrieve and return the size of the decoded buffer and the size of an\r | |
222 | optional scratch buffer required to actually decode the data in a GUIDed section.\r | |
223 | \r | |
224 | Examines a GUIDed section specified by InputSection. \r | |
225 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r | |
226 | then RETURN_UNSUPPORTED is returned. \r | |
227 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler \r | |
228 | of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r | |
229 | is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of\r | |
230 | type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.\r | |
518db1d9 | 231 | \r |
f1db45f8 | 232 | If InputSection is NULL, then ASSERT().\r |
233 | If OutputBufferSize is NULL, then ASSERT().\r | |
234 | If ScratchBufferSize is NULL, then ASSERT().\r | |
235 | If SectionAttribute is NULL, then ASSERT().\r | |
236 | \r | |
237 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
238 | @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required if the buffer\r | |
239 | specified by InputSection were decoded.\r | |
240 | @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space if the buffer specified by\r | |
241 | InputSection were decoded.\r | |
242 | @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes field of\r | |
243 | EFI_GUID_DEFINED_SECTION in the PI Specification.\r | |
244 | \r | |
58380e9c | 245 | @retval RETURN_SUCCESS Successfully obtained the required information.\r |
f1db45f8 | 246 | @retval RETURN_UNSUPPORTED The GUID from the section specified by InputSection does not match any of\r |
247 | the GUIDs registered with ExtractGuidedSectionRegisterHandlers().\r | |
248 | @retval Others The return status from the handler associated with the GUID retrieved from\r | |
249 | the section specified by InputSection.\r | |
0fa00159 LG |
250 | \r |
251 | **/\r | |
252 | RETURN_STATUS\r | |
253 | EFIAPI\r | |
254 | ExtractGuidedSectionGetInfo (\r | |
255 | IN CONST VOID *InputSection,\r | |
256 | OUT UINT32 *OutputBufferSize,\r | |
257 | OUT UINT32 *ScratchBufferSize,\r | |
258 | OUT UINT16 *SectionAttribute \r | |
259 | )\r | |
260 | {\r | |
261 | UINT32 Index;\r | |
f1db45f8 | 262 | \r |
263 | ASSERT (InputSection != NULL); \r | |
0fa00159 LG |
264 | ASSERT (OutputBufferSize != NULL);\r |
265 | ASSERT (ScratchBufferSize != NULL);\r | |
266 | ASSERT (SectionAttribute != NULL);\r | |
267 | \r | |
268 | //\r | |
269 | // Search the match registered GetInfo handler for the input guided section.\r | |
270 | //\r | |
271 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
272 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
b911d09f LG |
273 | //\r |
274 | // Call the match handler to getinfo for the input section data.\r | |
275 | //\r | |
276 | return mExtractGetInfoHandlerTable [Index] (\r | |
277 | InputSection,\r | |
278 | OutputBufferSize,\r | |
279 | ScratchBufferSize,\r | |
280 | SectionAttribute\r | |
281 | );\r | |
0fa00159 LG |
282 | }\r |
283 | }\r | |
284 | \r | |
285 | //\r | |
286 | // Not found, the input guided section is not supported. \r | |
287 | //\r | |
b911d09f | 288 | return RETURN_UNSUPPORTED;\r |
0fa00159 LG |
289 | }\r |
290 | \r | |
4754c98b | 291 | /**\r |
0057fda6 | 292 | Retrieves the GUID from a GUIDed section and uses that GUID to select an associated handler of type\r |
f1db45f8 | 293 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r |
294 | The selected handler is used to decode the data in a GUIDed section and return the result in a caller\r | |
295 | allocated output buffer.\r | |
296 | \r | |
297 | Decodes the GUIDed section specified by InputSection. \r | |
298 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r | |
299 | then RETURN_UNSUPPORTED is returned. \r | |
300 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler\r | |
301 | of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r | |
302 | is used to decode InputSection into the buffer specified by OutputBuffer and the authentication status of this\r | |
303 | decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the data in InputSection,\r | |
304 | then OutputBuffer is set to point at the data in InputSection. Otherwise, the decoded data will be placed in caller\r | |
305 | allocated buffer specified by OutputBuffer. This function is responsible for computing the EFI_AUTH_STATUS_PLATFORM_OVERRIDE\r | |
518db1d9 | 306 | bit of in AuthenticationStatus. The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned. \r |
307 | \r | |
f1db45f8 | 308 | If InputSection is NULL, then ASSERT().\r |
309 | If OutputBuffer is NULL, then ASSERT().\r | |
310 | If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r | |
311 | If AuthenticationStatus is NULL, then ASSERT(). \r | |
312 | \r | |
313 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
314 | @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation. \r | |
315 | @param[in] ScratchBuffer A caller allocated buffer that may be required by this function as a scratch buffer to perform the decode operation. \r | |
0fa00159 | 316 | @param[out] AuthenticationStatus \r |
f1db45f8 | 317 | A pointer to the authentication status of the decoded output buffer. See the definition\r |
318 | of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI section of the PI\r | |
319 | Specification.\r | |
4754c98b | 320 | \r |
f1db45f8 | 321 | @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r |
322 | @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r | |
323 | @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r | |
4754c98b | 324 | \r |
0fa00159 LG |
325 | **/\r |
326 | RETURN_STATUS\r | |
327 | EFIAPI\r | |
328 | ExtractGuidedSectionDecode (\r | |
329 | IN CONST VOID *InputSection,\r | |
330 | OUT VOID **OutputBuffer,\r | |
f1db45f8 | 331 | IN VOID *ScratchBuffer, OPTIONAL\r |
0fa00159 LG |
332 | OUT UINT32 *AuthenticationStatus \r |
333 | )\r | |
334 | {\r | |
335 | UINT32 Index;\r | |
336 | \r | |
eceb3a4c LG |
337 | //\r |
338 | // Check the input parameters\r | |
339 | //\r | |
f1db45f8 | 340 | ASSERT (InputSection != NULL);\r |
0fa00159 LG |
341 | ASSERT (OutputBuffer != NULL);\r |
342 | ASSERT (AuthenticationStatus != NULL);\r | |
343 | \r | |
344 | //\r | |
eceb3a4c | 345 | // Search the match registered extract handler for the input guided section.\r |
0fa00159 LG |
346 | //\r |
347 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
348 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
b911d09f LG |
349 | //\r |
350 | // Call the match handler to extract raw data for the input section data.\r | |
351 | //\r | |
352 | return mExtractDecodeHandlerTable [Index] (\r | |
353 | InputSection,\r | |
354 | OutputBuffer,\r | |
355 | ScratchBuffer,\r | |
356 | AuthenticationStatus\r | |
357 | );\r | |
0fa00159 LG |
358 | }\r |
359 | }\r | |
360 | \r | |
361 | //\r | |
362 | // Not found, the input guided section is not supported. \r | |
363 | //\r | |
b911d09f | 364 | return RETURN_UNSUPPORTED;\r |
0fa00159 | 365 | }\r |