VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c@ 105381

Last change on this file since 105381 was 99404, checked in by vboxsync, 20 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1/** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <PiPei.h>
10#include <Library/BaseMemoryLib.h>
11#include <Library/DebugLib.h>
12#include <Library/ExtractGuidedSectionLib.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;
23} PRE_PI_EXTRACT_GUIDED_SECTION_DATA;
24
25PRE_PI_EXTRACT_GUIDED_SECTION_DATA *
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
41ExtractGuidedSectionRegisterHandlers (
42 IN CONST GUID *SectionGuid,
43 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER GetInfoHandler,
44 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER DecodeHandler
45 )
46{
47 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;
48 UINT32 Index;
49
50 //
51 // Check input parameter.
52 //
53 if (SectionGuid == NULL) {
54 return RETURN_INVALID_PARAMETER;
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)) {
81 return RETURN_OUT_OF_RESOURCES;
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
94UINTN
95EFIAPI
96ExtractGuidedSectionGetGuidList (
97 IN OUT GUID **ExtractHandlerGuidTable
98 )
99{
100 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;
101
102 ASSERT (ExtractHandlerGuidTable != NULL);
103
104 SavedData = GetSavedData ();
105
106 *ExtractHandlerGuidTable = SavedData->ExtractHandlerGuidTable;
107 return SavedData->NumberOfExtractHandler;
108}
109
110RETURN_STATUS
111EFIAPI
112ExtractGuidedSectionGetInfo (
113 IN CONST VOID *InputSection,
114 OUT UINT32 *OutputBufferSize,
115 OUT UINT32 *ScratchBufferSize,
116 OUT UINT16 *SectionAttribute
117 )
118{
119 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;
120 UINT32 Index;
121 EFI_GUID *SectionDefinitionGuid;
122
123 if (InputSection == NULL) {
124 return RETURN_INVALID_PARAMETER;
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) {
152 return RETURN_INVALID_PARAMETER;
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{
175 PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;
176 UINT32 Index;
177 EFI_GUID *SectionDefinitionGuid;
178
179 if (InputSection == NULL) {
180 return RETURN_INVALID_PARAMETER;
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) {
207 return RETURN_INVALID_PARAMETER;
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{
227 PRE_PI_EXTRACT_GUIDED_SECTION_DATA SavedData;
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) {
235 return RETURN_OUT_OF_RESOURCES;
236 }
237
238 SavedData.ExtractDecodeHandlerTable = (EXTRACT_GUIDED_SECTION_DECODE_HANDLER *)AllocatePool (PcdGet32 (PcdMaximumGuidedExtractHandler) * sizeof (EXTRACT_GUIDED_SECTION_DECODE_HANDLER));
239 if (SavedData.ExtractDecodeHandlerTable == NULL) {
240 return RETURN_OUT_OF_RESOURCES;
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) {
245 return RETURN_OUT_OF_RESOURCES;
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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette