EmbeddedPkg: Fix typos in comments
[mirror_edk2.git] / EmbeddedPkg / Library / PrePiExtractGuidedSectionLib / PrePiExtractGuidedSectionLib.c
CommitLineData
2ef2b01e
A
1/** @file\r
2\r
60274cca 3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
3402aac7 4\r
60274cca 5 This program and the accompanying materials\r
2ef2b01e
A
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
9\r
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
12\r
13**/\r
14\r
15#include <PiPei.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/ExtractGuidedSectionLib.h>\r
19#include <Library/PcdLib.h>\r
20#include <Library/PrePiLib.h>\r
21\r
22#define PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID { 0x385A982C, 0x2F49, 0x4043, { 0xA5, 0x1E, 0x49, 0x01, 0x02, 0x5C, 0x8B, 0x6B }}\r
23\r
24typedef struct {\r
25 UINT32 NumberOfExtractHandler;\r
26 GUID *ExtractHandlerGuidTable;\r
27 EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;\r
28 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;\r
29} PRE_PI_EXTRACT_GUIDED_SECTION_DATA;\r
30\r
31PRE_PI_EXTRACT_GUIDED_SECTION_DATA *\r
32GetSavedData (\r
33 VOID\r
34 )\r
35{\r
36 EFI_HOB_GUID_TYPE *GuidHob;\r
37 GUID SavedDataGuid = PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID;\r
38\r
39 GuidHob = GetFirstGuidHob(&SavedDataGuid);\r
40 GuidHob++;\r
3402aac7 41\r
2ef2b01e
A
42 return (PRE_PI_EXTRACT_GUIDED_SECTION_DATA *)GuidHob;\r
43}\r
44\r
45RETURN_STATUS\r
46EFIAPI\r
47ExtractGuidedSectionRegisterHandlers (\r
48 IN CONST GUID *SectionGuid,\r
49 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,\r
50 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler\r
51 )\r
52{\r
53 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;\r
54 UINT32 Index;\r
55 //\r
4f0624e8 56 // Check input parameter.\r
2ef2b01e
A
57 //\r
58 if (SectionGuid == NULL) {\r
59 return RETURN_INVALID_PARAMETER;\r
60 }\r
61\r
62 SavedData = GetSavedData();\r
63\r
64 //\r
65 // Search the match registered GetInfo handler for the input guided section.\r
66 //\r
67 for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index ++) {\r
68 if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], SectionGuid)) {\r
69 break;\r
70 }\r
71 }\r
72\r
73 //\r
74 // If the guided handler has been registered before, only update its handler.\r
75 //\r
76 if (Index < SavedData->NumberOfExtractHandler) {\r
77 SavedData->ExtractDecodeHandlerTable [Index] = DecodeHandler;\r
78 SavedData->ExtractGetInfoHandlerTable [Index] = GetInfoHandler;\r
79 return RETURN_SUCCESS;\r
80 }\r
3402aac7 81\r
2ef2b01e
A
82 //\r
83 // Check the global table is enough to contain new Handler.\r
84 //\r
85 if (SavedData->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {\r
86 return RETURN_OUT_OF_RESOURCES;\r
87 }\r
3402aac7 88\r
2ef2b01e
A
89 //\r
90 // Register new Handler and guid value.\r
91 //\r
92 CopyGuid (&SavedData->ExtractHandlerGuidTable [SavedData->NumberOfExtractHandler], SectionGuid);\r
93 SavedData->ExtractDecodeHandlerTable [SavedData->NumberOfExtractHandler] = DecodeHandler;\r
94 SavedData->ExtractGetInfoHandlerTable [SavedData->NumberOfExtractHandler++] = GetInfoHandler;\r
3402aac7 95\r
2ef2b01e
A
96 return RETURN_SUCCESS;\r
97}\r
98\r
99UINTN\r
100EFIAPI\r
101ExtractGuidedSectionGetGuidList (\r
102 IN OUT GUID **ExtractHandlerGuidTable\r
103 )\r
104{\r
105 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;\r
106\r
107 ASSERT(ExtractHandlerGuidTable != NULL);\r
3402aac7 108\r
2ef2b01e 109 SavedData = GetSavedData();\r
3402aac7 110\r
2ef2b01e
A
111 *ExtractHandlerGuidTable = SavedData->ExtractHandlerGuidTable;\r
112 return SavedData->NumberOfExtractHandler;\r
113}\r
114\r
115RETURN_STATUS\r
116EFIAPI\r
117ExtractGuidedSectionGetInfo (\r
118 IN CONST VOID *InputSection,\r
119 OUT UINT32 *OutputBufferSize,\r
120 OUT UINT32 *ScratchBufferSize,\r
3402aac7 121 OUT UINT16 *SectionAttribute\r
2ef2b01e
A
122 )\r
123{\r
124 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;\r
125 UINT32 Index;\r
3402aac7 126\r
2ef2b01e
A
127 if (InputSection == NULL) {\r
128 return RETURN_INVALID_PARAMETER;\r
129 }\r
3402aac7 130\r
2ef2b01e
A
131 ASSERT (OutputBufferSize != NULL);\r
132 ASSERT (ScratchBufferSize != NULL);\r
133 ASSERT (SectionAttribute != NULL);\r
3402aac7 134\r
2ef2b01e
A
135 SavedData = GetSavedData();\r
136\r
137 //\r
138 // Search the match registered GetInfo handler for the input guided section.\r
139 //\r
140 for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index ++) {\r
141 if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
142 break;\r
143 }\r
144 }\r
145\r
146 //\r
3402aac7 147 // Not found, the input guided section is not supported.\r
2ef2b01e
A
148 //\r
149 if (Index == SavedData->NumberOfExtractHandler) {\r
150 return RETURN_INVALID_PARAMETER;\r
151 }\r
152\r
153 //\r
154 // Call the match handler to getinfo for the input section data.\r
155 //\r
156 return SavedData->ExtractGetInfoHandlerTable [Index] (\r
157 InputSection,\r
158 OutputBufferSize,\r
159 ScratchBufferSize,\r
160 SectionAttribute\r
161 );\r
162}\r
163\r
164RETURN_STATUS\r
165EFIAPI\r
166ExtractGuidedSectionDecode (\r
167 IN CONST VOID *InputSection,\r
168 OUT VOID **OutputBuffer,\r
169 OUT VOID *ScratchBuffer, OPTIONAL\r
3402aac7 170 OUT UINT32 *AuthenticationStatus\r
2ef2b01e
A
171 )\r
172{\r
173 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;\r
174 UINT32 Index;\r
3402aac7 175\r
2ef2b01e
A
176 if (InputSection == NULL) {\r
177 return RETURN_INVALID_PARAMETER;\r
178 }\r
3402aac7 179\r
2ef2b01e
A
180 ASSERT (OutputBuffer != NULL);\r
181 ASSERT (AuthenticationStatus != NULL);\r
182\r
183 SavedData = GetSavedData();\r
184\r
185 //\r
186 // Search the match registered GetInfo handler for the input guided section.\r
187 //\r
188 for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index ++) {\r
189 if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
190 break;\r
191 }\r
192 }\r
193\r
194 //\r
3402aac7 195 // Not found, the input guided section is not supported.\r
2ef2b01e
A
196 //\r
197 if (Index == SavedData->NumberOfExtractHandler) {\r
198 return RETURN_INVALID_PARAMETER;\r
199 }\r
200\r
201 //\r
202 // Call the match handler to getinfo for the input section data.\r
203 //\r
204 return SavedData->ExtractDecodeHandlerTable [Index] (\r
205 InputSection,\r
206 OutputBuffer,\r
207 ScratchBuffer,\r
208 AuthenticationStatus\r
209 );\r
210}\r
211\r
212RETURN_STATUS\r
213EFIAPI\r
214ExtractGuidedSectionLibConstructor (\r
215 VOID\r
216 )\r
217{\r
218 PRE_PI_EXTRACT_GUIDED_SECTION_DATA SavedData;\r
219 GUID HobGuid = PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID;\r
220\r
221 //\r
222 // Allocate global pool space to store the registered handler and its guid value.\r
223 //\r
224 SavedData.ExtractHandlerGuidTable = (GUID *)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler) * sizeof(GUID));\r
225 if (SavedData.ExtractHandlerGuidTable == NULL) {\r
226 return RETURN_OUT_OF_RESOURCES;\r
227 }\r
3402aac7 228\r
2ef2b01e
A
229 SavedData.ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler) * sizeof(EXTRACT_GUIDED_SECTION_DECODE_HANDLER));\r
230 if (SavedData.ExtractDecodeHandlerTable == NULL) {\r
231 return RETURN_OUT_OF_RESOURCES;\r
232 }\r
233\r
234 SavedData.ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)AllocatePool(PcdGet32(PcdMaximumGuidedExtractHandler) * sizeof(EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));\r
235 if (SavedData.ExtractGetInfoHandlerTable == NULL) {\r
236 return RETURN_OUT_OF_RESOURCES;\r
237 }\r
3402aac7 238\r
2ef2b01e
A
239 //\r
240 // the initialized number is Zero.\r
241 //\r
242 SavedData.NumberOfExtractHandler = 0;\r
3402aac7 243\r
2ef2b01e 244 BuildGuidDataHob(&HobGuid, &SavedData, sizeof(SavedData));\r
3402aac7 245\r
2ef2b01e
A
246 return RETURN_SUCCESS;\r
247}\r