]>
Commit | Line | Data |
---|---|---|
8069d49e | 1 | /** @file\r |
eceb3a4c | 2 | Provide generic extract guided section functions for Dxe phase.\r |
0fa00159 | 3 | \r |
eceb3a4c | 4 | Copyright (c) 2007 - 2008, Intel Corporation<BR>\r |
8069d49e LG |
5 | All rights reserved. This program and the accompanying materials\r |
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 | |
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 | |
18 | #include <Library/PcdLib.h>\r | |
19 | #include <Library/BaseMemoryLib.h>\r | |
20 | #include <Library/MemoryAllocationLib.h>\r | |
21 | #include <Library/ExtractGuidedSectionLib.h>\r | |
22 | \r | |
fe467413 | 23 | GUID *mExtractHandlerGuidTable;\r |
24 | UINT32 mNumberOfExtractHandler = 0;\r | |
0fa00159 | 25 | \r |
fe467413 | 26 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable;\r |
27 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable;\r | |
0fa00159 | 28 | \r |
4754c98b | 29 | /**\r |
0057fda6 | 30 | Constructor allocates the global memory to store the registered guid and Handler list.\r |
0fa00159 LG |
31 | \r |
32 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
4754c98b | 33 | @param SystemTable A pointer to the EFI System Table.\r |
0fa00159 | 34 | \r |
0057fda6 | 35 | @retval RETURN_SUCCESS Allocate the global memory space to store guid and function tables.\r |
4754c98b | 36 | @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.\r |
0fa00159 LG |
37 | **/\r |
38 | RETURN_STATUS\r | |
39 | EFIAPI\r | |
40 | DxeExtractGuidedSectionLibConstructor (\r | |
41 | IN EFI_HANDLE ImageHandle,\r | |
42 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
43 | )\r | |
44 | {\r | |
45 | //\r | |
46 | // Allocate global pool space to store the registered handler and its guid value.\r | |
47 | //\r | |
48 | mExtractHandlerGuidTable = (GUID *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID));\r | |
49 | if (mExtractHandlerGuidTable == NULL) {\r | |
50 | return RETURN_OUT_OF_RESOURCES;\r | |
51 | }\r | |
52 | \r | |
53 | mExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r | |
54 | if (mExtractDecodeHandlerTable == NULL) {\r | |
b911d09f | 55 | FreePool (mExtractHandlerGuidTable);\r |
0fa00159 LG |
56 | return RETURN_OUT_OF_RESOURCES;\r |
57 | }\r | |
58 | \r | |
59 | mExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r | |
60 | if (mExtractGetInfoHandlerTable == NULL) {\r | |
b911d09f LG |
61 | FreePool (mExtractHandlerGuidTable);\r |
62 | FreePool (mExtractDecodeHandlerTable);\r | |
0fa00159 LG |
63 | return RETURN_OUT_OF_RESOURCES;\r |
64 | }\r | |
65 | \r | |
0fa00159 LG |
66 | return RETURN_SUCCESS;\r |
67 | }\r | |
68 | \r | |
4754c98b | 69 | /**\r |
f1db45f8 | 70 | Retrieve the list GUIDs that have been registered through ExtractGuidedSectionRegisterHandlers().\r |
0fa00159 | 71 | \r |
f1db45f8 | 72 | Sets ExtractHandlerGuidTable so it points at a callee allocated array of registered GUIDs.\r |
73 | The total number of GUIDs in the array are returned. Since the array of GUIDs is callee allocated\r | |
74 | and caller must treat this array of GUIDs as read-only data. \r | |
75 | If ExtractHandlerGuidTable is NULL, then ASSERT().\r | |
76 | \r | |
0057fda6 | 77 | @param[out] ExtractHandlerGuidTable A pointer to the array of GUIDs that have been registered through\r |
f1db45f8 | 78 | ExtractGuidedSectionRegisterHandlers().\r |
0fa00159 | 79 | \r |
4754c98b | 80 | @return the number of the supported extract guided Handler.\r |
f1db45f8 | 81 | \r |
0fa00159 LG |
82 | **/\r |
83 | UINTN\r | |
84 | EFIAPI\r | |
85 | ExtractGuidedSectionGetGuidList (\r | |
eceb3a4c | 86 | OUT GUID **ExtractHandlerGuidTable\r |
0fa00159 LG |
87 | )\r |
88 | {\r | |
89 | ASSERT (ExtractHandlerGuidTable != NULL);\r | |
90 | \r | |
91 | *ExtractHandlerGuidTable = mExtractHandlerGuidTable;\r | |
92 | return mNumberOfExtractHandler;\r | |
93 | }\r | |
94 | \r | |
4754c98b | 95 | /**\r |
f1db45f8 | 96 | Registers handlers of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER and EXTRACT_GUIDED_SECTION_DECODE_HANDLER\r |
97 | for a specific GUID section type.\r | |
98 | \r | |
0057fda6 | 99 | Registers the handlers specified by GetInfoHandler and DecodeHandler with the GUID specified by SectionGuid.\r |
f1db45f8 | 100 | If the GUID value specified by SectionGuid has already been registered, then return RETURN_ALREADY_STARTED.\r |
101 | If there are not enough resources available to register the handlers then RETURN_OUT_OF_RESOURCES is returned.\r | |
57209470 | 102 | \r |
f1db45f8 | 103 | If SectionGuid is NULL, then ASSERT().\r |
104 | If GetInfoHandler is NULL, then ASSERT().\r | |
105 | If DecodeHandler is NULL, then ASSERT().\r | |
106 | \r | |
107 | @param[in] SectionGuid A pointer to the GUID associated with the the handlers\r | |
108 | of the GUIDed section type being registered.\r | |
109 | @param[in] GetInfoHandler Pointer to a function that examines a GUIDed section and returns the\r | |
110 | size of the decoded buffer and the size of an optional scratch buffer\r | |
111 | required to actually decode the data in a GUIDed section.\r | |
112 | @param[in] DecodeHandler Pointer to a function that decodes a GUIDed section into a caller\r | |
113 | allocated output buffer. \r | |
114 | \r | |
115 | @retval RETURN_SUCCESS The handlers were registered.\r | |
f1db45f8 | 116 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to register the handlers.\r |
0fa00159 | 117 | \r |
0fa00159 LG |
118 | **/\r |
119 | RETURN_STATUS\r | |
120 | EFIAPI\r | |
121 | ExtractGuidedSectionRegisterHandlers (\r | |
122 | IN CONST GUID *SectionGuid,\r | |
123 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r | |
124 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r | |
125 | )\r | |
126 | {\r | |
e2701217 | 127 | UINT32 Index;\r |
0fa00159 LG |
128 | //\r |
129 | // Check input paramter.\r | |
130 | //\r | |
f1db45f8 | 131 | ASSERT (SectionGuid != NULL);\r |
132 | ASSERT (GetInfoHandler != NULL);\r | |
133 | ASSERT (DecodeHandler != NULL);\r | |
e2701217 LG |
134 | \r |
135 | //\r | |
136 | // Search the match registered GetInfo handler for the input guided section.\r | |
137 | //\r | |
138 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
139 | if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {\r | |
b911d09f LG |
140 | //\r |
141 | // If the guided handler has been registered before, only update its handler.\r | |
142 | //\r | |
143 | mExtractDecodeHandlerTable [Index] = DecodeHandler;\r | |
144 | mExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r | |
145 | return RETURN_SUCCESS;\r | |
e2701217 LG |
146 | }\r |
147 | }\r | |
e2701217 | 148 | \r |
0fa00159 LG |
149 | //\r |
150 | // Check the global table is enough to contain new Handler.\r | |
151 | //\r | |
152 | if (mNumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r | |
153 | return RETURN_OUT_OF_RESOURCES;\r | |
154 | }\r | |
155 | \r | |
156 | //\r | |
157 | // Register new Handler and guid value.\r | |
158 | //\r | |
159 | CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);\r | |
160 | mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;\r | |
161 | mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;\r | |
162 | \r | |
163 | return RETURN_SUCCESS;\r | |
164 | }\r | |
165 | \r | |
4754c98b | 166 | /**\r |
0057fda6 | 167 | Retrieves a GUID from a GUIDed section and uses that GUID to select an associated handler of type\r |
f1db45f8 | 168 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r |
169 | The selected handler is used to retrieve and return the size of the decoded buffer and the size of an\r | |
170 | optional scratch buffer required to actually decode the data in a GUIDed section.\r | |
171 | \r | |
172 | Examines a GUIDed section specified by InputSection. \r | |
173 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r | |
174 | then RETURN_UNSUPPORTED is returned. \r | |
175 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler \r | |
176 | of type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r | |
177 | is used to retrieve the OututBufferSize, ScratchSize, and Attributes values. The return status from the handler of\r | |
178 | type EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER is returned.\r | |
179 | If InputSection is NULL, then ASSERT().\r | |
180 | If OutputBufferSize is NULL, then ASSERT().\r | |
181 | If ScratchBufferSize is NULL, then ASSERT().\r | |
182 | If SectionAttribute is NULL, then ASSERT().\r | |
183 | \r | |
184 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
185 | @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required if the buffer\r | |
186 | specified by InputSection were decoded.\r | |
187 | @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space if the buffer specified by\r | |
188 | InputSection were decoded.\r | |
189 | @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes field of\r | |
190 | EFI_GUID_DEFINED_SECTION in the PI Specification.\r | |
191 | \r | |
192 | @retval RETURN_SUCCESS Get the required information successfully.\r | |
193 | @retval RETURN_UNSUPPORTED The GUID from the section specified by InputSection does not match any of\r | |
194 | the GUIDs registered with ExtractGuidedSectionRegisterHandlers().\r | |
195 | @retval Others The return status from the handler associated with the GUID retrieved from\r | |
196 | the section specified by InputSection.\r | |
0fa00159 LG |
197 | \r |
198 | **/\r | |
199 | RETURN_STATUS\r | |
200 | EFIAPI\r | |
201 | ExtractGuidedSectionGetInfo (\r | |
202 | IN CONST VOID *InputSection,\r | |
203 | OUT UINT32 *OutputBufferSize,\r | |
204 | OUT UINT32 *ScratchBufferSize,\r | |
205 | OUT UINT16 *SectionAttribute \r | |
206 | )\r | |
207 | {\r | |
208 | UINT32 Index;\r | |
f1db45f8 | 209 | \r |
210 | ASSERT (InputSection != NULL); \r | |
0fa00159 LG |
211 | ASSERT (OutputBufferSize != NULL);\r |
212 | ASSERT (ScratchBufferSize != NULL);\r | |
213 | ASSERT (SectionAttribute != NULL);\r | |
214 | \r | |
215 | //\r | |
216 | // Search the match registered GetInfo handler for the input guided section.\r | |
217 | //\r | |
218 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
219 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
b911d09f LG |
220 | //\r |
221 | // Call the match handler to getinfo for the input section data.\r | |
222 | //\r | |
223 | return mExtractGetInfoHandlerTable [Index] (\r | |
224 | InputSection,\r | |
225 | OutputBufferSize,\r | |
226 | ScratchBufferSize,\r | |
227 | SectionAttribute\r | |
228 | );\r | |
0fa00159 LG |
229 | }\r |
230 | }\r | |
231 | \r | |
232 | //\r | |
233 | // Not found, the input guided section is not supported. \r | |
234 | //\r | |
b911d09f | 235 | return RETURN_UNSUPPORTED;\r |
0fa00159 LG |
236 | }\r |
237 | \r | |
4754c98b | 238 | /**\r |
0057fda6 | 239 | Retrieves the GUID from a GUIDed section and uses that GUID to select an associated handler of type\r |
f1db45f8 | 240 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers().\r |
241 | The selected handler is used to decode the data in a GUIDed section and return the result in a caller\r | |
242 | allocated output buffer.\r | |
243 | \r | |
244 | Decodes the GUIDed section specified by InputSection. \r | |
245 | If GUID for InputSection does not match any of the GUIDs registered through ExtractGuidedSectionRegisterHandlers(),\r | |
246 | then RETURN_UNSUPPORTED is returned. \r | |
247 | If the GUID of InputSection does match the GUID that this handler supports, then the the associated handler\r | |
248 | of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER that was registered with ExtractGuidedSectionRegisterHandlers()\r | |
249 | is used to decode InputSection into the buffer specified by OutputBuffer and the authentication status of this\r | |
250 | decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the data in InputSection,\r | |
251 | then OutputBuffer is set to point at the data in InputSection. Otherwise, the decoded data will be placed in caller\r | |
252 | allocated buffer specified by OutputBuffer. This function is responsible for computing the EFI_AUTH_STATUS_PLATFORM_OVERRIDE\r | |
253 | bit of in AuthenticationStatus. The return status from the handler of type EXTRACT_GUIDED_SECTION_DECODE_HANDLER is returned. \r | |
254 | If InputSection is NULL, then ASSERT().\r | |
255 | If OutputBuffer is NULL, then ASSERT().\r | |
256 | If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r | |
257 | If AuthenticationStatus is NULL, then ASSERT(). \r | |
258 | \r | |
259 | @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r | |
260 | @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation. \r | |
261 | @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 | 262 | @param[out] AuthenticationStatus \r |
f1db45f8 | 263 | A pointer to the authentication status of the decoded output buffer. See the definition\r |
264 | of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI section of the PI\r | |
265 | Specification.\r | |
4754c98b | 266 | \r |
f1db45f8 | 267 | @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r |
268 | @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r | |
269 | @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r | |
4754c98b | 270 | \r |
0fa00159 LG |
271 | **/\r |
272 | RETURN_STATUS\r | |
273 | EFIAPI\r | |
274 | ExtractGuidedSectionDecode (\r | |
275 | IN CONST VOID *InputSection,\r | |
276 | OUT VOID **OutputBuffer,\r | |
f1db45f8 | 277 | IN VOID *ScratchBuffer, OPTIONAL\r |
0fa00159 LG |
278 | OUT UINT32 *AuthenticationStatus \r |
279 | )\r | |
280 | {\r | |
281 | UINT32 Index;\r | |
282 | \r | |
eceb3a4c LG |
283 | //\r |
284 | // Check the input parameters\r | |
285 | //\r | |
f1db45f8 | 286 | ASSERT (InputSection != NULL);\r |
0fa00159 LG |
287 | ASSERT (OutputBuffer != NULL);\r |
288 | ASSERT (AuthenticationStatus != NULL);\r | |
289 | \r | |
290 | //\r | |
eceb3a4c | 291 | // Search the match registered extract handler for the input guided section.\r |
0fa00159 LG |
292 | //\r |
293 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
294 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
b911d09f LG |
295 | //\r |
296 | // Call the match handler to extract raw data for the input section data.\r | |
297 | //\r | |
298 | return mExtractDecodeHandlerTable [Index] (\r | |
299 | InputSection,\r | |
300 | OutputBuffer,\r | |
301 | ScratchBuffer,\r | |
302 | AuthenticationStatus\r | |
303 | );\r | |
0fa00159 LG |
304 | }\r |
305 | }\r | |
306 | \r | |
307 | //\r | |
308 | // Not found, the input guided section is not supported. \r | |
309 | //\r | |
b911d09f | 310 | return RETURN_UNSUPPORTED;\r |
0fa00159 | 311 | }\r |