]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.c
Make GuidedSection library instance to follow the value of GuidedSectionExtraction...
[mirror_edk2.git] / MdePkg / Library / DxeExtractGuidedSectionLib / DxeExtractGuidedSectionLib.c
CommitLineData
0fa00159
LG
1/*++\r
2\r
3Copyright (c) 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 DxeExtractGuidedSectionLib.c\r
15\r
16Abstract:\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
30STATIC GUID *mExtractHandlerGuidTable;\r
31STATIC UINT32 mNumberOfExtractHandler;\r
32\r
33STATIC EXTRACT_GUIDED_SECTION_DECODE_HANDLER *mExtractDecodeHandlerTable;\r
34STATIC 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
45RETURN_STATUS\r
46EFIAPI\r
47DxeExtractGuidedSectionLibConstructor (\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
86UINTN\r
87EFIAPI\r
88ExtractGuidedSectionGetGuidList (\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
109RETURN_STATUS\r
110EFIAPI\r
111ExtractGuidedSectionRegisterHandlers (\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
117 //\r
118 // Check input paramter.\r
119 //\r
120 if (SectionGuid == NULL) {\r
121 return RETURN_INVALID_PARAMETER;\r
122 }\r
123 //\r
124 // Check the global table is enough to contain new Handler.\r
125 //\r
126 if (mNumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r
127 return RETURN_OUT_OF_RESOURCES;\r
128 }\r
129 \r
130 //\r
131 // Register new Handler and guid value.\r
132 //\r
133 CopyGuid (&mExtractHandlerGuidTable [mNumberOfExtractHandler], SectionGuid);\r
134 mExtractDecodeHandlerTable [mNumberOfExtractHandler] = DecodeHandler;\r
135 mExtractGetInfoHandlerTable [mNumberOfExtractHandler++] = GetInfoHandler;\r
136 \r
137 return RETURN_SUCCESS;\r
138}\r
139\r
140/**
141 Get information from the guided section. This function first gets the guid value\r
142 from guided section header, then match this guid in the registered extract Handler list\r
143 to its corresponding getinfo Handler. \r
e6c560aa 144 If not found, RETURN_INVALID_PARAMETER will be return. \r
0fa00159
LG
145 If found, it will call the getinfo Handler to get the required size and attribute.\r
146\r
147 It will ASSERT () if the pointer to OutputBufferSize is NULL.\r
148 It will ASSERT () if the pointer to ScratchBufferSize is NULL.
149 It will ASSERT () if the pointer to SectionAttribute is NULL.\r
150\r
151 @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r
152 @param[out] OutputBufferSize The size of OutputBuffer.\r
153 @param[out] ScratchBufferSize The size of ScratchBuffer. \r
154 @param[out] SectionAttribute The attribute of the input guided section.\r
155
156 @retval RETURN_SUCCESS Get the required information successfully.\r
e6c560aa
LG
157 @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly. \r
158 The GUID in InputSection does not match any registered guid list.\r
0fa00159
LG
159\r
160**/\r
161RETURN_STATUS\r
162EFIAPI\r
163ExtractGuidedSectionGetInfo (\r
164 IN CONST VOID *InputSection,\r
165 OUT UINT32 *OutputBufferSize,\r
166 OUT UINT32 *ScratchBufferSize,\r
167 OUT UINT16 *SectionAttribute \r
168 )\r
169{\r
170 UINT32 Index;\r
171 \r
172 if (InputSection == NULL) {\r
173 return RETURN_INVALID_PARAMETER;\r
174 }\r
175 \r
176 ASSERT (OutputBufferSize != NULL);\r
177 ASSERT (ScratchBufferSize != NULL);\r
178 ASSERT (SectionAttribute != NULL);\r
179 \r
180 //\r
181 // Search the match registered GetInfo handler for the input guided section.\r
182 //\r
183 for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
184 if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
185 break;\r
186 }\r
187 }\r
188\r
189 //\r
190 // Not found, the input guided section is not supported. \r
191 //\r
192 if (Index == mNumberOfExtractHandler) {\r
e6c560aa 193 return RETURN_INVALID_PARAMETER;\r
0fa00159
LG
194 }\r
195\r
196 //\r
197 // Call the match handler to getinfo for the input section data.\r
198 //\r
199 return mExtractGetInfoHandlerTable [Index] (\r
200 InputSection,\r
201 OutputBufferSize,\r
202 ScratchBufferSize,\r
203 SectionAttribute\r
204 );\r
205}\r
206\r
207/**
208 Extract data from the guided section. This function first gets the guid value\r
209 from guided section header, then match this guid in the registered extract Handler list\r
210 to its corresponding extract Handler. \r
e6c560aa 211 If not found, RETURN_INVALID_PARAMETER will be return. \r
0fa00159
LG
212 If found, it will call this extract Handler to get output data and AuthenticationStatus.
213\r
214 It will ASSERT () if the pointer to OutputBuffer is NULL.\r
215 It will ASSERT () if the pointer to AuthenticationStatus is NULL.\r
216\r
217 @param[in] InputSection Buffer containing the input GUIDed section to be processed. \r
218 @param[out] OutputBuffer OutputBuffer to point the start of the section's contents \r
219 if guided data is not required prcessing. Otherwise,\r
220 OutputBuffer to contain the output data, which is \r
221 allocated by the caller.\r
222 @param[out] ScratchBuffer A pointer to a caller-allocated buffer for function internal use. \r
223 @param[out] AuthenticationStatus \r
224 A pointer to a caller-allocated UINT32 that indicates the\r
225 authentication status of the output buffer.
226
227 @retval RETURN_SUCCESS Get the output data, size and AuthenticationStatus successfully.\r
e6c560aa
LG
228 @retval RETURN_INVALID_PARAMETER The input data can't be parsed correctly. \r
229 The GUID in InputSection does not match any registered guid.\r
0fa00159
LG
230
231**/\r
232RETURN_STATUS\r
233EFIAPI\r
234ExtractGuidedSectionDecode (\r
235 IN CONST VOID *InputSection,\r
236 OUT VOID **OutputBuffer,\r
237 OUT VOID *ScratchBuffer, OPTIONAL\r
238 OUT UINT32 *AuthenticationStatus \r
239 )\r
240{\r
241 UINT32 Index;\r
242 \r
243 if (InputSection == NULL) {\r
244 return RETURN_INVALID_PARAMETER;\r
245 }\r
246 \r
247 ASSERT (OutputBuffer != NULL);\r
248 ASSERT (AuthenticationStatus != NULL);\r
249\r
250 //\r
251 // Search the match registered GetInfo handler for the input guided section.\r
252 //\r
253 for (Index = 0; Index < mNumberOfExtractHandler; Index ++) {\r
254 if (CompareGuid (&mExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
255 break;\r
256 }\r
257 }\r
258\r
259 //\r
260 // Not found, the input guided section is not supported. \r
261 //\r
262 if (Index == mNumberOfExtractHandler) {\r
e6c560aa 263 return RETURN_INVALID_PARAMETER;\r
0fa00159
LG
264 }\r
265\r
266 //\r
267 // Call the match handler to getinfo for the input section data.\r
268 //\r
269 return mExtractDecodeHandlerTable [Index] (\r
270 InputSection,\r
271 OutputBuffer,\r
272 ScratchBuffer,\r
273 AuthenticationStatus\r
274 );\r
275}\r