]>
Commit | Line | Data |
---|---|---|
18fd8d65 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 | PeiDxeExtractGuidedSectionLib.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 <PiPei.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 | ||
39 | @retval RETURN_SUCCESS Allocate 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 | PeiDxeExtractGuidedSectionLibConstructor (\r | |
45 | )\r | |
46 | {\r | |
47 | //\r | |
48 | // Allocate global pool space to store the registered handler and its guid value.\r | |
49 | //\r | |
50 | mExtractHandlerGuidTable = (GUID *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID));\r | |
51 | if (mExtractHandlerGuidTable == NULL) {\r | |
52 | return RETURN_OUT_OF_RESOURCES;\r | |
53 | }\r | |
54 | \r | |
55 | mExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r | |
56 | if (mExtractDecodeHandlerTable == NULL) {\r | |
57 | return RETURN_OUT_OF_RESOURCES;\r | |
58 | }\r | |
59 | \r | |
60 | mExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *) AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r | |
61 | if (mExtractGetInfoHandlerTable == NULL) {\r | |
62 | return RETURN_OUT_OF_RESOURCES;\r | |
63 | }\r | |
64 | \r | |
65 | //\r | |
66 | // the initialized number is Zero.\r | |
67 | //\r | |
68 | mNumberOfExtractHandler = 0;\r | |
69 | \r | |
70 | return RETURN_SUCCESS;\r | |
71 | }\r | |
72 | \r | |
73 | /** | |
74 | Get the supported exract guided section Handler guid list.\r | |
75 | If ExtractHandlerGuidTable = NULL, then ASSERT.\r | |
76 | \r | |
77 | @param[in, out] ExtractHandlerGuidTable The extract Handler guid pointer list. | |
78 | \r | |
79 | @retval return the number of the supported extract guided Handler. | |
80 | **/\r | |
81 | UINTN\r | |
82 | EFIAPI\r | |
83 | ExtractGuidedSectionGetGuidList (\r | |
84 | IN OUT GUID **ExtractHandlerGuidTable\r | |
85 | )\r | |
86 | {\r | |
87 | ASSERT (ExtractHandlerGuidTable != NULL);\r | |
88 | \r | |
89 | *ExtractHandlerGuidTable = mExtractHandlerGuidTable;\r | |
90 | return mNumberOfExtractHandler;\r | |
91 | }\r | |
92 | \r | |
93 | /** | |
94 | Register Guided Section Extract and GetInfo handler.\r | |
95 | \r | |
96 | @param[in] SectionGuid The guid matches this Extraction function. | |
97 | @param[in] GetInfoHandler Function to get info from guided section.\r | |
98 | @param[in] DecodeHandler Function to extract guided section. | |
99 | ||
100 | @retval RETURN_SUCCESS Register Guided Section Extract function successfully. | |
101 | @retval RETURN_OUT_OF_RESOURCES Resource is not enough to register new function. \r | |
102 | @retval RETURN_INVALID_PARAMETER Input pointer to Guid value is not valid.\r | |
103 | **/\r | |
104 | RETURN_STATUS\r | |
105 | EFIAPI\r | |
106 | ExtractGuidedSectionRegisterHandlers (\r | |
107 | IN CONST GUID *SectionGuid,\r | |
108 | IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r | |
109 | IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r | |
110 | )\r | |
111 | {\r | |
112 | //\r | |
113 | // Check input paramter.\r | |
114 | //\r | |
115 | if (SectionGuid == NULL) {\r | |
116 | return RETURN_INVALID_PARAMETER;\r | |
117 | }\r | |
118 | //\r | |
119 | // Check the global table is enough to contain new Handler.\r | |
120 | //\r | |
121 | if (mNumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r | |
122 | return RETURN_OUT_OF_RESOURCES;\r | |
123 | }\r | |
124 | \r | |
125 | //\r | |
126 | // Register new Handler and guid value.\r | |
127 | //\r | |
128 | CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);\r | |
129 | mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;\r | |
130 | mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;\r | |
131 | \r | |
132 | return RETURN_SUCCESS;\r | |
133 | }\r | |
134 | \r | |
135 | /** | |
136 | Get information from the guided section. This function first gets the guid value\r | |
137 | from guided section header, then match this guid in the registered extract Handler list\r | |
138 | to its corresponding getinfo Handler. \r | |
139 | If not found, RETURN_UNSUPPORTED will be return. \r | |
140 | If found, it will call the getinfo Handler to get the required size and attribute.\r | |
141 | \r | |
142 | It will ASSERT () if the pointer to OutputBufferSize is NULL.\r | |
143 | It will ASSERT () if the pointer to ScratchBufferSize is NULL. | |
144 | It will ASSERT () if the pointer to SectionAttribute is NULL.\r | |
145 | \r | |
146 | @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r | |
147 | @param[out] OutputBufferSize The size of OutputBuffer.\r | |
148 | @param[out] ScratchBufferSize The size of ScratchBuffer. \r | |
149 | @param[out] SectionAttribute The attribute of the input guided section.\r | |
150 | ||
151 | @retval RETURN_SUCCESS Get the required information successfully.\r | |
152 | @retval RETURN_UNSUPPORTED Guided section data is not supported.\r | |
153 | @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly.\r | |
154 | \r | |
155 | **/\r | |
156 | RETURN_STATUS\r | |
157 | EFIAPI\r | |
158 | ExtractGuidedSectionGetInfo (\r | |
159 | IN CONST VOID *InputSection,\r | |
160 | OUT UINT32 *OutputBufferSize,\r | |
161 | OUT UINT32 *ScratchBufferSize,\r | |
162 | OUT UINT16 *SectionAttribute \r | |
163 | )\r | |
164 | {\r | |
165 | UINT32 Index;\r | |
166 | \r | |
167 | if (InputSection == NULL) {\r | |
168 | return RETURN_INVALID_PARAMETER;\r | |
169 | }\r | |
170 | \r | |
171 | ASSERT (OutputBufferSize != NULL);\r | |
172 | ASSERT (ScratchBufferSize != NULL);\r | |
173 | ASSERT (SectionAttribute != NULL);\r | |
174 | \r | |
175 | //\r | |
176 | // Search the match registered GetInfo handler for the input guided section.\r | |
177 | //\r | |
178 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
179 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
180 | break;\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
184 | //\r | |
185 | // Not found, the input guided section is not supported. \r | |
186 | //\r | |
187 | if (Index == mNumberOfExtractHandler) {\r | |
188 | return RETURN_UNSUPPORTED;\r | |
189 | }\r | |
190 | \r | |
191 | //\r | |
192 | // Call the match handler to getinfo for the input section data.\r | |
193 | //\r | |
194 | return mExtractGetInfoHandlerTable [Index] (\r | |
195 | InputSection,\r | |
196 | OutputBufferSize,\r | |
197 | ScratchBufferSize,\r | |
198 | SectionAttribute\r | |
199 | );\r | |
200 | }\r | |
201 | \r | |
202 | /** | |
203 | Extract data from the guided section. This function first gets the guid value\r | |
204 | from guided section header, then match this guid in the registered extract Handler list\r | |
205 | to its corresponding extract Handler. \r | |
206 | If not found, RETURN_UNSUPPORTED will be return. \r | |
207 | If found, it will call this extract Handler to get output data and AuthenticationStatus. | |
208 | \r | |
209 | It will ASSERT () if the pointer to OutputBuffer is NULL.\r | |
210 | It will ASSERT () if the pointer to AuthenticationStatus is NULL.\r | |
211 | \r | |
212 | @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r | |
213 | @param[out] OutputBuffer OutputBuffer to point the start of the section's contents \r | |
214 | if guided data is not required prcessing. Otherwise,\r | |
215 | OutputBuffer to contain the output data, which is \r | |
216 | allocated by the caller.\r | |
217 | @param[out] ScratchBuffer A pointer to a caller-allocated buffer for function internal use. \r | |
218 | @param[out] AuthenticationStatus \r | |
219 | A pointer to a caller-allocated UINT32 that indicates the\r | |
220 | authentication status of the output buffer. | |
221 | ||
222 | @retval RETURN_SUCCESS Get the output data, size and AuthenticationStatus successfully.\r | |
223 | @retval RETURN_UNSUPPORTED Guided section data is not supported to be decoded.\r | |
224 | @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly.\r | |
225 | ||
226 | **/\r | |
227 | RETURN_STATUS\r | |
228 | EFIAPI\r | |
229 | ExtractGuidedSectionDecode (\r | |
230 | IN CONST VOID *InputSection,\r | |
231 | OUT VOID **OutputBuffer,\r | |
232 | OUT VOID *ScratchBuffer, OPTIONAL\r | |
233 | OUT UINT32 *AuthenticationStatus \r | |
234 | )\r | |
235 | {\r | |
236 | UINT32 Index;\r | |
237 | \r | |
238 | if (InputSection == NULL) {\r | |
239 | return RETURN_INVALID_PARAMETER;\r | |
240 | }\r | |
241 | \r | |
242 | ASSERT (OutputBuffer != NULL);\r | |
243 | ASSERT (AuthenticationStatus != NULL);\r | |
244 | \r | |
245 | //\r | |
246 | // Search the match registered GetInfo handler for the input guided section.\r | |
247 | //\r | |
248 | for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r | |
249 | if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r | |
250 | break;\r | |
251 | }\r | |
252 | }\r | |
253 | \r | |
254 | //\r | |
255 | // Not found, the input guided section is not supported. \r | |
256 | //\r | |
257 | if (Index == mNumberOfExtractHandler) {\r | |
258 | return RETURN_UNSUPPORTED;\r | |
259 | }\r | |
260 | \r | |
261 | //\r | |
262 | // Call the match handler to getinfo for the input section data.\r | |
263 | //\r | |
264 | return mExtractDecodeHandlerTable [Index] (\r | |
265 | InputSection,\r | |
266 | OutputBuffer,\r | |
267 | ScratchBuffer,\r | |
268 | AuthenticationStatus\r | |
269 | );\r | |
270 | }\r |