]>
Commit | Line | Data |
---|---|---|
8069d49e | 1 | /** @file\r |
eceb3a4c | 2 | Provide generic extract guided section functions for PEI 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 <PiPei.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/HobLib.h>\r | |
21 | #include <Library/ExtractGuidedSectionLib.h>\r | |
22 | \r | |
23 | #define PEI_EXTRACT_HANDLER_INFO_SIGNATURE EFI_SIGNATURE_32 ('P', 'E', 'H', 'I')\r | |
24 | \r | |
25 | typedef struct {\r | |
26 | UINT32 Signature;\r | |
27 | UINT32 NumberOfExtractHandler;\r | |
28 | GUID *ExtractHandlerGuidTable;\r | |
29 | EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;\r | |
30 | EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;\r | |
31 | } PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO;\r | |
32 | \r | |
33 | /** | |
34 | Build guid hob for the global memory to store the registered guid and Handler list.\r | |
35 | If GuidHob exists, HandlerInfo will be directly got from Guid hob data.\r | |
36 | \r | |
37 | @param[in, out] InfoPointer Pointer to pei handler info structure. | |
38 | \r | |
39 | @retval RETURN_SUCCESS Build Guid hob for the global memory space to store guid and funciton tables.\r | |
40 | @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated. | |
41 | **/\r | |
42 | RETURN_STATUS\r | |
43 | EFIAPI\r | |
44 | PeiGetExtractGuidedSectionHandlerInfo (\r | |
45 | IN OUT PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO **InfoPointer\r | |
46 | )\r | |
47 | {\r | |
48 | PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
49 | EFI_PEI_HOB_POINTERS Hob;\r | |
50 | \r | |
51 | //\r | |
52 | // First try to get handler info from guid hob specified by CallerId.\r | |
53 | //\r | |
54 | Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GetHobList ());\r | |
55 | while (Hob.Raw != NULL) {\r | |
56 | if (CompareGuid (&(Hob.Guid->Name), &gEfiCallerIdGuid)) {\r | |
57 | HandlerInfo = (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *) GET_GUID_HOB_DATA (Hob.Guid);\r | |
58 | if (HandlerInfo->Signature == PEI_EXTRACT_HANDLER_INFO_SIGNATURE) {\r | |
e111752c LG |
59 | //\r |
60 | // Update Table Pointer when hob start address is changed.\r | |
61 | //\r | |
62 | if (HandlerInfo->ExtractHandlerGuidTable != (GUID *) (HandlerInfo + 1)) {\r | |
63 | HandlerInfo->ExtractHandlerGuidTable = (GUID *) (HandlerInfo + 1);\r | |
64 | HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) (\r | |
65 | (UINT8 *)HandlerInfo->ExtractHandlerGuidTable + \r | |
66 | PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)\r | |
67 | );\r | |
68 | HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) (\r | |
69 | (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable + \r | |
70 | PcdGet32 (PcdMaximumGuidedExtractHandler) * \r | |
71 | sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)\r | |
72 | );\r | |
73 | }\r | |
74 | //\r | |
75 | // Return HandlerInfo pointer.\r | |
76 | //\r | |
0fa00159 LG |
77 | *InfoPointer = HandlerInfo;\r |
78 | return EFI_SUCCESS;\r | |
79 | }\r | |
80 | }\r | |
81 | Hob.Raw = GET_NEXT_HOB (Hob);\r | |
82 | Hob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, Hob.Raw);\r | |
83 | }\r | |
84 | \r | |
85 | //\r | |
86 | // If Guid Hob is not found, Build CallerId Guid hob to store Handler Info\r | |
87 | //\r | |
88 | HandlerInfo = BuildGuidHob (\r | |
89 | &gEfiCallerIdGuid, \r | |
90 | sizeof (PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO) +\r | |
91 | PcdGet32 (PcdMaximumGuidedExtractHandler) * \r | |
92 | (sizeof (GUID) + sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER) + sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER))\r | |
93 | );\r | |
94 | if (HandlerInfo == NULL) {\r | |
95 | //\r | |
96 | // No enough resource to build guid hob.\r | |
97 | //\r | |
98 | return EFI_OUT_OF_RESOURCES;\r | |
99 | }\r | |
eceb3a4c LG |
100 | //\r |
101 | // Init HandlerInfo structure\r | |
102 | //\r | |
0fa00159 LG |
103 | HandlerInfo->Signature = PEI_EXTRACT_HANDLER_INFO_SIGNATURE;\r |
104 | HandlerInfo->NumberOfExtractHandler = 0;\r | |
105 | HandlerInfo->ExtractHandlerGuidTable = (GUID *) (HandlerInfo + 1);\r | |
106 | HandlerInfo->ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) (\r | |
107 | (UINT8 *)HandlerInfo->ExtractHandlerGuidTable + \r | |
108 | PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID)\r | |
109 | );\r | |
110 | HandlerInfo->ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) (\r | |
111 | (UINT8 *)HandlerInfo->ExtractDecodeHandlerTable + \r | |
112 | PcdGet32 (PcdMaximumGuidedExtractHandler) * \r | |
113 | sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)\r | |
114 | );\r | |
eceb3a4c LG |
115 | //\r |
116 | // return the created HandlerInfo.\r | |
117 | //\r | |
0fa00159 LG |
118 | *InfoPointer = HandlerInfo;\r |
119 | return EFI_SUCCESS;\r | |
120 | }\r | |
121 | \r | |
122 | /** | |
123 | Get the supported exract guided section Handler guid list.\r | |
124 | If ExtractHandlerGuidTable = NULL, then ASSERT.\r | |
125 | \r | |
eceb3a4c | 126 | @param[out] ExtractHandlerGuidTable The extract Handler guid pointer list. |
0fa00159 | 127 | \r |
eceb3a4c | 128 | @return the number of the supported extract guided Handler. |
0fa00159 LG |
129 | **/\r |
130 | UINTN\r | |
131 | EFIAPI\r | |
132 | ExtractGuidedSectionGetGuidList (\r | |
eceb3a4c | 133 | OUT GUID **ExtractHandlerGuidTable\r |
0fa00159 LG |
134 | )\r |
135 | {\r | |
136 | EFI_STATUS Status;\r | |
137 | PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
138 | \r | |
139 | ASSERT (ExtractHandlerGuidTable != NULL);\r | |
140 | \r | |
eceb3a4c LG |
141 | //\r |
142 | // Get all registered handler information\r | |
143 | //\r | |
0fa00159 LG |
144 | Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r |
145 | if (EFI_ERROR (Status)) {\r | |
146 | return Status;\r | |
147 | }\r | |
148 | \r | |
eceb3a4c LG |
149 | //\r |
150 | // Get GuidTable and Table Number\r | |
151 | //\r | |
0fa00159 LG |
152 | *ExtractHandlerGuidTable = HandlerInfo->ExtractHandlerGuidTable;\r |
153 | return HandlerInfo->NumberOfExtractHandler;\r | |
154 | }\r | |
155 | \r | |
156 | /** | |
157 | Register Guided Section Extract and GetInfo handler.\r | |
158 | \r | |
159 | @param[in] SectionGuid The guid matches this Extraction function. | |
160 | @param[in] GetInfoHandler Function to get info from guided section.\r | |
161 | @param[in] DecodeHandler Function to extract guided section. | |
162 | ||
163 | @retval RETURN_SUCCESS Register Guided Section Extract function successfully. | |
164 | @retval RETURN_OUT_OF_RESOURCES Resource is not enough to register new function. \r | |
165 | @retval RETURN_INVALID_PARAMETER Input pointer to Guid value is not valid.\r | |
166 | **/\r | |
167 | RETURN_STATUS\r | |
168 | EFIAPI\r | |
169 | ExtractGuidedSectionRegisterHandlers (\r | |
170 | IN CONST GUID *SectionGuid,\r | |
171 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r | |
172 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r | |
173 | )\r | |
174 | {\r | |
175 | EFI_STATUS Status;\r | |
e2701217 | 176 | UINT32 Index;\r |
0fa00159 LG |
177 | PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r |
178 | \r | |
179 | //\r | |
180 | // Check input paramter.\r | |
181 | //\r | |
182 | if (SectionGuid == NULL) {\r | |
183 | return RETURN_INVALID_PARAMETER;\r | |
184 | }\r | |
185 | \r | |
186 | //\r | |
187 | // Get the registered handler information\r | |
188 | //\r | |
189 | Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r | |
190 | if (EFI_ERROR (Status)) {\r | |
191 | return Status;\r | |
192 | }\r | |
e2701217 LG |
193 | \r |
194 | //\r | |
195 | // Search the match registered GetInfo handler for the input guided section.\r | |
196 | //\r | |
197 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r | |
e111752c | 198 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, SectionGuid)) {\r |
b911d09f LG |
199 | //\r |
200 | // If the guided handler has been registered before, only update its handler.\r | |
201 | //\r | |
202 | HandlerInfo->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r | |
203 | HandlerInfo->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r | |
204 | return RETURN_SUCCESS;\r | |
e2701217 LG |
205 | }\r |
206 | }\r | |
207 | \r | |
0fa00159 LG |
208 | //\r |
209 | // Check the global table is enough to contain new Handler.\r | |
210 | //\r | |
211 | if (HandlerInfo->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r | |
212 | return RETURN_OUT_OF_RESOURCES;\r | |
213 | }\r | |
214 | \r | |
215 | //\r | |
216 | // Register new Handler and guid value.\r | |
217 | //\r | |
e111752c | 218 | CopyGuid (HandlerInfo->ExtractHandlerGuidTable + HandlerInfo->NumberOfExtractHandler, SectionGuid);\r |
0fa00159 LG |
219 | HandlerInfo->ExtractDecodeHandlerTable [HandlerInfo->NumberOfExtractHandler] = DecodeHandler;\r |
220 | HandlerInfo->ExtractGetInfoHandlerTable [HandlerInfo->NumberOfExtractHandler++] = GetInfoHandler;\r | |
221 | \r | |
222 | return RETURN_SUCCESS;\r | |
223 | }\r | |
224 | \r | |
225 | /** | |
226 | Get information from the guided section. This function first gets the guid value\r | |
227 | from guided section header, then match this guid in the registered extract Handler list\r | |
228 | to its corresponding getinfo Handler. \r | |
e6c560aa | 229 | If not found, RETURN_INVALID_PARAMETER will be return. \r |
0fa00159 LG |
230 | If found, it will call the getinfo Handler to get the required size and attribute.\r |
231 | \r | |
232 | It will ASSERT () if the pointer to OutputBufferSize is NULL.\r | |
233 | It will ASSERT () if the pointer to ScratchBufferSize is NULL. | |
234 | It will ASSERT () if the pointer to SectionAttribute is NULL.\r | |
235 | \r | |
236 | @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r | |
237 | @param[out] OutputBufferSize The size of OutputBuffer.\r | |
238 | @param[out] ScratchBufferSize The size of ScratchBuffer. \r | |
239 | @param[out] SectionAttribute The attribute of the input guided section.\r | |
240 | ||
241 | @retval RETURN_SUCCESS Get the required information successfully.\r | |
eceb3a4c LG |
242 | @retval RETURN_UNSUPPORTED Guided section data is not supported.\r |
243 | @retval RETURN_INVALID_PARAMETER The input data is not the valid guided section.\r | |
0fa00159 LG |
244 | \r |
245 | **/\r | |
246 | RETURN_STATUS\r | |
247 | EFIAPI\r | |
248 | ExtractGuidedSectionGetInfo (\r | |
249 | IN CONST VOID *InputSection,\r | |
250 | OUT UINT32 *OutputBufferSize,\r | |
251 | OUT UINT32 *ScratchBufferSize,\r | |
252 | OUT UINT16 *SectionAttribute \r | |
253 | )\r | |
254 | {\r | |
255 | UINT32 Index;\r | |
256 | EFI_STATUS Status;\r | |
257 | PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
258 | \r | |
259 | //\r | |
260 | // Check input paramter\r | |
261 | //\r | |
262 | if (InputSection == NULL) {\r | |
263 | return RETURN_INVALID_PARAMETER;\r | |
264 | }\r | |
265 | \r | |
266 | ASSERT (OutputBufferSize != NULL);\r | |
267 | ASSERT (ScratchBufferSize != NULL);\r | |
268 | ASSERT (SectionAttribute != NULL);\r | |
269 | \r | |
270 | //\r | |
eceb3a4c | 271 | // Get all registered handler information.\r |
0fa00159 LG |
272 | //\r |
273 | Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r | |
274 | if (EFI_ERROR (Status)) {\r | |
275 | return Status;\r | |
276 | }\r | |
277 | \r | |
278 | //\r | |
279 | // Search the match registered GetInfo handler for the input guided section.\r | |
280 | //\r | |
281 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r | |
e111752c | 282 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r |
b911d09f LG |
283 | //\r |
284 | // Call the match handler to getinfo for the input section data.\r | |
285 | //\r | |
286 | return HandlerInfo->ExtractGetInfoHandlerTable [Index] (\r | |
287 | InputSection,\r | |
288 | OutputBufferSize,\r | |
289 | ScratchBufferSize,\r | |
290 | SectionAttribute\r | |
291 | );\r | |
0fa00159 LG |
292 | }\r |
293 | }\r | |
294 | \r | |
295 | //\r | |
296 | // Not found, the input guided section is not supported. \r | |
297 | //\r | |
b911d09f | 298 | return RETURN_UNSUPPORTED;\r |
0fa00159 LG |
299 | }\r |
300 | \r | |
301 | /** | |
302 | Extract data from the guided section. This function first gets the guid value\r | |
303 | from guided section header, then match this guid in the registered extract Handler list\r | |
304 | to its corresponding extract Handler. \r | |
e6c560aa | 305 | If not found, RETURN_INVALID_PARAMETER will be return. \r |
0fa00159 LG |
306 | If found, it will call this extract Handler to get output data and AuthenticationStatus. |
307 | \r | |
308 | It will ASSERT () if the pointer to OutputBuffer is NULL.\r | |
309 | It will ASSERT () if the pointer to AuthenticationStatus is NULL.\r | |
310 | \r | |
311 | @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r | |
312 | @param[out] OutputBuffer OutputBuffer to point the start of the section's contents \r | |
313 | if guided data is not required prcessing. Otherwise,\r | |
314 | OutputBuffer to contain the output data, which is \r | |
315 | allocated by the caller.\r | |
316 | @param[out] ScratchBuffer A pointer to a caller-allocated buffer for function internal use. \r | |
317 | @param[out] AuthenticationStatus \r | |
318 | A pointer to a caller-allocated UINT32 that indicates the\r | |
319 | authentication status of the output buffer. | |
320 | ||
321 | @retval RETURN_SUCCESS Get the output data, size and AuthenticationStatus successfully.\r | |
eceb3a4c LG |
322 | @retval RETURN_UNSUPPORTED Guided section data is not supported to be decoded.\r |
323 | @retval RETURN_INVALID_PARAMETER The input data is not the valid guided section. | |
0fa00159 LG |
324 | |
325 | **/\r | |
326 | RETURN_STATUS\r | |
327 | EFIAPI\r | |
328 | ExtractGuidedSectionDecode (\r | |
329 | IN CONST VOID *InputSection,\r | |
330 | OUT VOID **OutputBuffer,\r | |
331 | OUT VOID *ScratchBuffer, OPTIONAL\r | |
332 | OUT UINT32 *AuthenticationStatus \r | |
333 | )\r | |
334 | {\r | |
335 | UINT32 Index;\r | |
336 | EFI_STATUS Status;\r | |
337 | PEI_EXTRACT_GUIDED_SECTION_HANDLER_INFO *HandlerInfo;\r | |
338 | \r | |
eceb3a4c LG |
339 | //\r |
340 | // Check input parameter\r | |
341 | //\r | |
0fa00159 LG |
342 | if (InputSection == NULL) {\r |
343 | return RETURN_INVALID_PARAMETER;\r | |
eceb3a4c | 344 | } \r |
0fa00159 LG |
345 | ASSERT (OutputBuffer != NULL);\r |
346 | ASSERT (AuthenticationStatus != NULL);\r | |
eceb3a4c LG |
347 | \r |
348 | //\r | |
349 | // Get all registered handler information.\r | |
350 | // \r | |
0fa00159 LG |
351 | Status = PeiGetExtractGuidedSectionHandlerInfo (&HandlerInfo);\r |
352 | if (EFI_ERROR (Status)) {\r | |
353 | return Status;\r | |
354 | }\r | |
355 | \r | |
356 | //\r | |
eceb3a4c | 357 | // Search the match registered Extract handler for the input guided section.\r |
0fa00159 LG |
358 | //\r |
359 | for (Index = 0; Index < HandlerInfo->NumberOfExtractHandler; Index ++) {\r | |
e111752c | 360 | if (CompareGuid (HandlerInfo->ExtractHandlerGuidTable + Index, &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r |
b911d09f LG |
361 | //\r |
362 | // Call the match handler to extract raw data for the input guided section.\r | |
363 | //\r | |
364 | return HandlerInfo->ExtractDecodeHandlerTable [Index] (\r | |
365 | InputSection,\r | |
366 | OutputBuffer,\r | |
367 | ScratchBuffer,\r | |
368 | AuthenticationStatus\r | |
369 | );\r | |
0fa00159 LG |
370 | }\r |
371 | }\r | |
372 | \r | |
373 | //\r | |
374 | // Not found, the input guided section is not supported. \r | |
375 | //\r | |
b911d09f | 376 | return RETURN_UNSUPPORTED;\r |
0fa00159 | 377 | }\r |