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