TianoCore EDK2 master
Loading...
Searching...
No Matches
PrePiExtractGuidedSectionLib.c
Go to the documentation of this file.
1
9#include <PiPei.h>
11#include <Library/DebugLib.h>
13#include <Library/PcdLib.h>
14#include <Library/PrePiLib.h>
15
16#define PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID { 0x385A982C, 0x2F49, 0x4043, { 0xA5, 0x1E, 0x49, 0x01, 0x02, 0x5C, 0x8B, 0x6B }}
17
18typedef struct {
19 UINT32 NumberOfExtractHandler;
20 GUID *ExtractHandlerGuidTable;
21 EXTRACT_GUIDED_SECTION_DECODE_HANDLER *ExtractDecodeHandlerTable;
22 EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *ExtractGetInfoHandlerTable;
24
26GetSavedData (
27 VOID
28 )
29{
30 EFI_HOB_GUID_TYPE *GuidHob;
31 GUID SavedDataGuid = PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID;
32
33 GuidHob = GetFirstGuidHob (&SavedDataGuid);
34 GuidHob++;
35
36 return (PRE_PI_EXTRACT_GUIDED_SECTION_DATA *)GuidHob;
37}
38
39RETURN_STATUS
40EFIAPI
42 IN CONST GUID *SectionGuid,
45 )
46{
48 UINT32 Index;
49
50 //
51 // Check input parameter.
52 //
53 if (SectionGuid == NULL) {
55 }
56
57 SavedData = GetSavedData ();
58
59 //
60 // Search the match registered GetInfo handler for the input guided section.
61 //
62 for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index++) {
63 if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], SectionGuid)) {
64 break;
65 }
66 }
67
68 //
69 // If the guided handler has been registered before, only update its handler.
70 //
71 if (Index < SavedData->NumberOfExtractHandler) {
72 SavedData->ExtractDecodeHandlerTable[Index] = DecodeHandler;
73 SavedData->ExtractGetInfoHandlerTable[Index] = GetInfoHandler;
74 return RETURN_SUCCESS;
75 }
76
77 //
78 // Check the global table is enough to contain new Handler.
79 //
80 if (SavedData->NumberOfExtractHandler >= PcdGet32 (PcdMaximumGuidedExtractHandler)) {
82 }
83
84 //
85 // Register new Handler and guid value.
86 //
87 CopyGuid (&SavedData->ExtractHandlerGuidTable[SavedData->NumberOfExtractHandler], SectionGuid);
88 SavedData->ExtractDecodeHandlerTable[SavedData->NumberOfExtractHandler] = DecodeHandler;
89 SavedData->ExtractGetInfoHandlerTable[SavedData->NumberOfExtractHandler++] = GetInfoHandler;
90
91 return RETURN_SUCCESS;
92}
93
95EFIAPI
96ExtractGuidedSectionGetGuidList (
97 IN OUT GUID **ExtractHandlerGuidTable
98 )
99{
101
102 ASSERT (ExtractHandlerGuidTable != NULL);
103
104 SavedData = GetSavedData ();
105
106 *ExtractHandlerGuidTable = SavedData->ExtractHandlerGuidTable;
107 return SavedData->NumberOfExtractHandler;
108}
109
110RETURN_STATUS
111EFIAPI
113 IN CONST VOID *InputSection,
114 OUT UINT32 *OutputBufferSize,
115 OUT UINT32 *ScratchBufferSize,
116 OUT UINT16 *SectionAttribute
117 )
118{
120 UINT32 Index;
121 EFI_GUID *SectionDefinitionGuid;
122
123 if (InputSection == NULL) {
125 }
126
127 ASSERT (OutputBufferSize != NULL);
128 ASSERT (ScratchBufferSize != NULL);
129 ASSERT (SectionAttribute != NULL);
130
131 SavedData = GetSavedData ();
132
133 if (IS_SECTION2 (InputSection)) {
134 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
135 } else {
136 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
137 }
138
139 //
140 // Search the match registered GetInfo handler for the input guided section.
141 //
142 for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index++) {
143 if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], SectionDefinitionGuid)) {
144 break;
145 }
146 }
147
148 //
149 // Not found, the input guided section is not supported.
150 //
151 if (Index == SavedData->NumberOfExtractHandler) {
153 }
154
155 //
156 // Call the match handler to getinfo for the input section data.
157 //
158 return SavedData->ExtractGetInfoHandlerTable[Index](
159 InputSection,
160 OutputBufferSize,
161 ScratchBufferSize,
162 SectionAttribute
163 );
164}
165
166RETURN_STATUS
167EFIAPI
168ExtractGuidedSectionDecode (
169 IN CONST VOID *InputSection,
170 OUT VOID **OutputBuffer,
171 OUT VOID *ScratchBuffer OPTIONAL,
172 OUT UINT32 *AuthenticationStatus
173 )
174{
176 UINT32 Index;
177 EFI_GUID *SectionDefinitionGuid;
178
179 if (InputSection == NULL) {
181 }
182
183 ASSERT (OutputBuffer != NULL);
184 ASSERT (AuthenticationStatus != NULL);
185
186 SavedData = GetSavedData ();
187
188 if (IS_SECTION2 (InputSection)) {
189 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION2 *)InputSection)->SectionDefinitionGuid);
190 } else {
191 SectionDefinitionGuid = &(((EFI_GUID_DEFINED_SECTION *)InputSection)->SectionDefinitionGuid);
192 }
193
194 //
195 // Search the match registered GetInfo handler for the input guided section.
196 //
197 for (Index = 0; Index < SavedData->NumberOfExtractHandler; Index++) {
198 if (CompareGuid (&SavedData->ExtractHandlerGuidTable[Index], SectionDefinitionGuid)) {
199 break;
200 }
201 }
202
203 //
204 // Not found, the input guided section is not supported.
205 //
206 if (Index == SavedData->NumberOfExtractHandler) {
208 }
209
210 //
211 // Call the match handler to getinfo for the input section data.
212 //
213 return SavedData->ExtractDecodeHandlerTable[Index](
214 InputSection,
215 OutputBuffer,
216 ScratchBuffer,
217 AuthenticationStatus
218 );
219}
220
221RETURN_STATUS
222EFIAPI
223ExtractGuidedSectionLibConstructor (
224 VOID
225 )
226{
228 GUID HobGuid = PRE_PI_EXTRACT_GUIDED_SECTION_DATA_GUID;
229
230 //
231 // Allocate global pool space to store the registered handler and its guid value.
232 //
233 SavedData.ExtractHandlerGuidTable = (GUID *)AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (GUID));
234 if (SavedData.ExtractHandlerGuidTable == NULL) {
236 }
237
238 SavedData.ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));
239 if (SavedData.ExtractDecodeHandlerTable == NULL) {
241 }
242
243 SavedData.ExtractGetInfoHandlerTable = (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER *)AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER));
244 if (SavedData.ExtractGetInfoHandlerTable == NULL) {
246 }
247
248 //
249 // the initialized number is Zero.
250 //
251 SavedData.NumberOfExtractHandler = 0;
252
253 BuildGuidDataHob (&HobGuid, &SavedData, sizeof (SavedData));
254
255 return RETURN_SUCCESS;
256}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
RETURN_STATUS(EFIAPI * EXTRACT_GUIDED_SECTION_DECODE_HANDLER)(IN CONST VOID *InputSection, OUT VOID **OutputBuffer, IN VOID *ScratchBuffer OPTIONAL, OUT UINT32 *AuthenticationStatus)
RETURN_STATUS(EFIAPI * EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER)(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_OUT_OF_RESOURCES
Definition: Base.h:1114
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
RETURN_STATUS EFIAPI ExtractGuidedSectionGetInfo(IN CONST VOID *InputSection, OUT UINT32 *OutputBufferSize, OUT UINT32 *ScratchBufferSize, OUT UINT16 *SectionAttribute)
RETURN_STATUS EFIAPI ExtractGuidedSectionRegisterHandlers(IN CONST GUID *SectionGuid, IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler, IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
Definition: Base.h:213