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