]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.c
Revert back the change. For now, ECP only support build mode with EFI_SPECIFICATION_V...
[mirror_edk2.git] / MdePkg / Library / DxeExtractGuidedSectionLib / DxeExtractGuidedSectionLib.c
CommitLineData
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
23STATIC GUID *mExtractHandlerGuidTable;\r
b911d09f 24STATIC UINT32 mNumberOfExtractHandler = 0;\r
0fa00159
LG
25\r
26STATIC EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable;\r
27STATIC EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *mExtractGetInfoHandlerTable;\r
28\r
29/**
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
33 @param SystemTable A pointer to the EFI System Table.
34\r
35 @retval RETURN_SUCCESS Allocate the global memory space to store guid and funciton tables.\r
36 @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.
37**/\r
38RETURN_STATUS\r
39EFIAPI\r
40DxeExtractGuidedSectionLibConstructor (\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
69/**
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
eceb3a4c 75 @param[out] ExtractHandlerGuidTable The extract Handler guid pointer list.
0fa00159 76\r
eceb3a4c 77 @return the number of the supported extract guided Handler.
0fa00159
LG
78**/\r
79UINTN\r
80EFIAPI\r
81ExtractGuidedSectionGetGuidList (\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
91/**
92 Register Guided Section Extract and GetInfo handler.\r
93\r
94 @param[in] SectionGuid The guid matches this Extraction function.
95 @param[in] GetInfoHandler Function to get info from guided section.\r
96 @param[in] DecodeHandler Function to extract guided section.
97
98 @retval RETURN_SUCCESS Register Guided Section Extract function successfully.
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
102RETURN_STATUS\r
103EFIAPI\r
104ExtractGuidedSectionRegisterHandlers (\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
149/**
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
157 It will ASSERT () if the pointer to ScratchBufferSize is NULL.
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
164
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
170RETURN_STATUS\r
171EFIAPI\r
172ExtractGuidedSectionGetInfo (\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
212/**
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
0fa00159
LG
217 If found, it will call this extract Handler to get output data and AuthenticationStatus.
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
230 authentication status of the output buffer.
231
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
234 @retval RETURN_INVALID_PARAMETER The input data is not the valid guided section.
0fa00159
LG
235
236**/\r
237RETURN_STATUS\r
238EFIAPI\r
239ExtractGuidedSectionDecode (\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