]>
Commit | Line | Data |
---|---|---|
0fa00159 LG |
1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | DxeExtractGuidedSectionLib.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Provide generic extract guided section functions. \r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include <PiDxe.h>\r | |
23 | \r | |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/PcdLib.h>\r | |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/MemoryAllocationLib.h>\r | |
28 | #include <Library/ExtractGuidedSectionLib.h>\r | |
29 | \r | |
30 | STATIC GUID *mExtractHandlerGuidTable;\r | |
31 | STATIC UINT32 mNumberOfExtractHandler;\r | |
32 | \r | |
33 | STATIC EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable;\r | |
34 | STATIC EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable;\r | |
35 | \r | |
36 | /** | |
37 | Construtor allocates the global memory to store the registered guid and Handler list.\r | |
38 | \r | |
39 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
40 | @param SystemTable A pointer to the EFI System Table. | |
41 | \r | |
42 | @retval RETURN_SUCCESS Allocate the global memory space to store guid and funciton tables.\r | |
43 | @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated. | |
44 | **/\r | |
45 | RETURN_STATUS\r | |
46 | EFIAPI\r | |
47 | DxeExtractGuidedSectionLibConstructor (\r | |
48 | IN EFI_HANDLE ImageHandle,\r | |
49 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
50 | )\r | |
51 | {\r | |
52 | //\r | |
53 | // Allocate global pool space to store the registered handler and its guid value.\r | |
54 | //\r | |
55 | mExtractHandlerGuidTable = (GUID *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID));\r | |
56 | if (mExtractHandlerGuidTable == NULL) {\r | |
57 | return RETURN_OUT_OF_RESOURCES;\r | |
58 | }\r | |
59 | \r | |
60 | mExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r | |
61 | if (mExtractDecodeHandlerTable == NULL) {\r | |
62 | return RETURN_OUT_OF_RESOURCES;\r | |
63 | }\r | |
64 | \r | |
65 | mExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r | |
66 | if (mExtractGetInfoHandlerTable == NULL) {\r | |
67 | return RETURN_OUT_OF_RESOURCES;\r | |
68 | }\r | |
69 | \r | |
70 | //\r | |
71 | // the initialized number is Zero.\r | |
72 | //\r | |
73 | mNumberOfExtractHandler = 0;\r | |
74 | \r | |
75 | return RETURN_SUCCESS;\r | |
76 | }\r | |
77 | \r | |
78 | /** | |
79 | Get the supported exract guided section Handler guid list.\r | |
80 | If ExtractHandlerGuidTable = NULL, then ASSERT.\r | |
81 | \r | |
82 | @param[in, out] ExtractHandlerGuidTable The extract Handler guid pointer list. | |
83 | \r | |
84 | @retval return the number of the supported extract guided Handler. | |
85 | **/\r | |
86 | UINTN\r | |
87 | EFIAPI\r | |
88 | ExtractGuidedSectionGetGuidList (\r | |
89 | IN OUT GUID **ExtractHandlerGuidTable\r | |
90 | )\r | |
91 | {\r | |
92 | ASSERT (ExtractHandlerGuidTable != NULL);\r | |
93 | \r | |
94 | *ExtractHandlerGuidTable = mExtractHandlerGuidTable;\r | |
95 | return mNumberOfExtractHandler;\r | |
96 | }\r | |
97 | \r | |
98 | /** | |
99 | Register Guided Section Extract and GetInfo handler.\r | |
100 | \r | |
101 | @param[in] SectionGuid The guid matches this Extraction function. | |
102 | @param[in] GetInfoHandler Function to get info from guided section.\r | |
103 | @param[in] DecodeHandler Function to extract guided section. | |
104 | ||
105 | @retval RETURN_SUCCESS Register Guided Section Extract function successfully. | |
106 | @retval RETURN_OUT_OF_RESOURCES Resource is not enough to register new function. \r | |
107 | @retval RETURN_INVALID_PARAMETER Input pointer to Guid value is not valid.\r | |
108 | **/\r | |
109 | RETURN_STATUS\r | |
110 | EFIAPI\r | |
111 | ExtractGuidedSectionRegisterHandlers (\r | |
112 | IN CONST GUID *SectionGuid,\r | |
113 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r | |
114 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r | |
115 | )\r | |
116 | {\r | |
e2701217 | 117 | UINT32 Index;\r |
0fa00159 LG |
118 | //\r |
119 | // Check input paramter.\r | |
120 | //\r | |
121 | if (SectionGuid == NULL) {\r | |
122 | return RETURN_INVALID_PARAMETER;\r | |
123 | }\r | |
e2701217 LG |
124 | \r |
125 | //\r | |
126 | // Search the match registered GetInfo handler for the input guided section.\r | |
127 | //\r | |
128 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
129 | if (CompareGuid (&mExtractHandlerGuidTable[Index], SectionGuid)) {\r | |
130 | break;\r | |
131 | }\r | |
132 | }\r | |
133 | \r | |
134 | //\r | |
135 | // If the guided handler has been registered before, only update its handler.\r | |
136 | //\r | |
137 | if (Index < mNumberOfExtractHandler) {\r | |
138 | mExtractDecodeHandlerTable [Index] = DecodeHandler;\r | |
139 | mExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r | |
140 | return RETURN_SUCCESS;\r | |
141 | }\r | |
142 | \r | |
0fa00159 LG |
143 | //\r |
144 | // Check the global table is enough to contain new Handler.\r | |
145 | //\r | |
146 | if (mNumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r | |
147 | return RETURN_OUT_OF_RESOURCES;\r | |
148 | }\r | |
149 | \r | |
150 | //\r | |
151 | // Register new Handler and guid value.\r | |
152 | //\r | |
153 | CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);\r | |
154 | mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;\r | |
155 | mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;\r | |
156 | \r | |
157 | return RETURN_SUCCESS;\r | |
158 | }\r | |
159 | \r | |
160 | /** | |
161 | Get information from the guided section. This function first gets the guid value\r | |
162 | from guided section header, then match this guid in the registered extract Handler list\r | |
163 | to its corresponding getinfo Handler. \r | |
e6c560aa | 164 | If not found, RETURN_INVALID_PARAMETER will be return. \r |
0fa00159 LG |
165 | If found, it will call the getinfo Handler to get the required size and attribute.\r |
166 | \r | |
167 | It will ASSERT () if the pointer to OutputBufferSize is NULL.\r | |
168 | It will ASSERT () if the pointer to ScratchBufferSize is NULL. | |
169 | It will ASSERT () if the pointer to SectionAttribute is NULL.\r | |
170 | \r | |
171 | @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r | |
172 | @param[out] OutputBufferSize The size of OutputBuffer.\r | |
173 | @param[out] ScratchBufferSize The size of ScratchBuffer. \r | |
174 | @param[out] SectionAttribute The attribute of the input guided section.\r | |
175 | ||
176 | @retval RETURN_SUCCESS Get the required information successfully.\r | |
e6c560aa LG |
177 | @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly. \r |
178 | The GUID in InputSection does not match any registered guid list.\r | |
0fa00159 LG |
179 | \r |
180 | **/\r | |
181 | RETURN_STATUS\r | |
182 | EFIAPI\r | |
183 | ExtractGuidedSectionGetInfo (\r | |
184 | IN CONST VOID *InputSection,\r | |
185 | OUT UINT32 *OutputBufferSize,\r | |
186 | OUT UINT32 *ScratchBufferSize,\r | |
187 | OUT UINT16 *SectionAttribute \r | |
188 | )\r | |
189 | {\r | |
190 | UINT32 Index;\r | |
191 | \r | |
192 | if (InputSection == NULL) {\r | |
193 | return RETURN_INVALID_PARAMETER;\r | |
194 | }\r | |
195 | \r | |
196 | ASSERT (OutputBufferSize != NULL);\r | |
197 | ASSERT (ScratchBufferSize != NULL);\r | |
198 | ASSERT (SectionAttribute != NULL);\r | |
199 | \r | |
200 | //\r | |
201 | // Search the match registered GetInfo handler for the input guided section.\r | |
202 | //\r | |
203 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
204 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
205 | break;\r | |
206 | }\r | |
207 | }\r | |
208 | \r | |
209 | //\r | |
210 | // Not found, the input guided section is not supported. \r | |
211 | //\r | |
212 | if (Index == mNumberOfExtractHandler) {\r | |
e6c560aa | 213 | return RETURN_INVALID_PARAMETER;\r |
0fa00159 LG |
214 | }\r |
215 | \r | |
216 | //\r | |
217 | // Call the match handler to getinfo for the input section data.\r | |
218 | //\r | |
219 | return mExtractGetInfoHandlerTable [Index] (\r | |
220 | InputSection,\r | |
221 | OutputBufferSize,\r | |
222 | ScratchBufferSize,\r | |
223 | SectionAttribute\r | |
224 | );\r | |
225 | }\r | |
226 | \r | |
227 | /** | |
228 | Extract data from the guided section. This function first gets the guid value\r | |
229 | from guided section header, then match this guid in the registered extract Handler list\r | |
230 | to its corresponding extract Handler. \r | |
e6c560aa | 231 | If not found, RETURN_INVALID_PARAMETER will be return. \r |
0fa00159 LG |
232 | If found, it will call this extract Handler to get output data and AuthenticationStatus. |
233 | \r | |
234 | It will ASSERT () if the pointer to OutputBuffer is NULL.\r | |
235 | It will ASSERT () if the pointer to AuthenticationStatus is NULL.\r | |
236 | \r | |
237 | @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r | |
238 | @param[out] OutputBuffer OutputBuffer to point the start of the section's contents \r | |
239 | if guided data is not required prcessing. Otherwise,\r | |
240 | OutputBuffer to contain the output data, which is \r | |
241 | allocated by the caller.\r | |
242 | @param[out] ScratchBuffer A pointer to a caller-allocated buffer for function internal use. \r | |
243 | @param[out] AuthenticationStatus \r | |
244 | A pointer to a caller-allocated UINT32 that indicates the\r | |
245 | authentication status of the output buffer. | |
246 | ||
247 | @retval RETURN_SUCCESS Get the output data, size and AuthenticationStatus successfully.\r | |
e6c560aa LG |
248 | @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly. \r |
249 | The GUID in InputSection does not match any registered guid.\r | |
0fa00159 LG |
250 | |
251 | **/\r | |
252 | RETURN_STATUS\r | |
253 | EFIAPI\r | |
254 | ExtractGuidedSectionDecode (\r | |
255 | IN CONST VOID *InputSection,\r | |
256 | OUT VOID **OutputBuffer,\r | |
257 | OUT VOID *ScratchBuffer, OPTIONAL\r | |
258 | OUT UINT32 *AuthenticationStatus \r | |
259 | )\r | |
260 | {\r | |
261 | UINT32 Index;\r | |
262 | \r | |
263 | if (InputSection == NULL) {\r | |
264 | return RETURN_INVALID_PARAMETER;\r | |
265 | }\r | |
266 | \r | |
267 | ASSERT (OutputBuffer != NULL);\r | |
268 | ASSERT (AuthenticationStatus != NULL);\r | |
269 | \r | |
270 | //\r | |
271 | // Search the match registered GetInfo handler for the input guided section.\r | |
272 | //\r | |
273 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
274 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
275 | break;\r | |
276 | }\r | |
277 | }\r | |
278 | \r | |
279 | //\r | |
280 | // Not found, the input guided section is not supported. \r | |
281 | //\r | |
282 | if (Index == mNumberOfExtractHandler) {\r | |
e6c560aa | 283 | return RETURN_INVALID_PARAMETER;\r |
0fa00159 LG |
284 | }\r |
285 | \r | |
286 | //\r | |
287 | // Call the match handler to getinfo for the input section data.\r | |
288 | //\r | |
289 | return mExtractDecodeHandlerTable [Index] (\r | |
290 | InputSection,\r | |
291 | OutputBuffer,\r | |
292 | ScratchBuffer,\r | |
293 | AuthenticationStatus\r | |
294 | );\r | |
295 | }\r |