VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/DynamicTablesPkg/Library/FdtHwInfoParserLib/CmObjectDescUtility.c

最後變更 在這個檔案是 99404,由 vboxsync 提交於 2 年 前

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

  • 屬性 svn:eol-style 設為 native
檔案大小: 9.0 KB
 
1/** @file
2 Configuration manager Object Descriptor Utility.
3
4 Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6**/
7
8#include <FdtHwInfoParserInclude.h>
9#include <ConfigurationManagerObject.h>
10
11#include "CmObjectDescUtility.h"
12
13/** Create a CM_OBJ_DESCRIPTOR.
14
15 @param [in] ObjectId CM_OBJECT_ID of the node.
16 @param [in] Count Number of CmObj stored in the
17 data field.
18 @param [in] Data Pointer to one or more CmObj objects.
19 The content of this Data buffer is copied.
20 @param [in] Size Size of the Data buffer.
21 @param [out] NewCmObjDesc The created CM_OBJ_DESCRIPTOR.
22
23 @retval EFI_SUCCESS The function completed successfully.
24 @retval EFI_INVALID_PARAMETER Invalid parameter.
25 @retval EFI_OUT_OF_RESOURCES An allocation has failed.
26**/
27EFI_STATUS
28EFIAPI
29CreateCmObjDesc (
30 IN CM_OBJECT_ID ObjectId,
31 IN UINT32 Count,
32 IN VOID *Data,
33 IN UINT32 Size,
34 OUT CM_OBJ_DESCRIPTOR **NewCmObjDesc
35 )
36{
37 CM_OBJ_DESCRIPTOR *CmObjDesc;
38 VOID *DataBuffer;
39
40 if ((Count == 0) ||
41 (Data == NULL) ||
42 (Size == 0) ||
43 (NewCmObjDesc == NULL))
44 {
45 ASSERT (0);
46 return EFI_INVALID_PARAMETER;
47 }
48
49 CmObjDesc = AllocateZeroPool (sizeof (CM_OBJ_DESCRIPTOR));
50 if (CmObjDesc == NULL) {
51 ASSERT (0);
52 return EFI_OUT_OF_RESOURCES;
53 }
54
55 DataBuffer = AllocateCopyPool (Size, Data);
56 if (DataBuffer == NULL) {
57 FreePool (CmObjDesc);
58 ASSERT (0);
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 CmObjDesc->ObjectId = ObjectId;
63 CmObjDesc->Count = Count;
64 CmObjDesc->Data = DataBuffer;
65 CmObjDesc->Size = Size;
66
67 *NewCmObjDesc = CmObjDesc;
68
69 return EFI_SUCCESS;
70}
71
72/** Free resources allocated for the CM_OBJ_DESCRIPTOR.
73
74 @param [in] CmObjDesc Pointer to the CM_OBJ_DESCRIPTOR.
75
76 @retval EFI_SUCCESS The function completed successfully.
77 @retval EFI_INVALID_PARAMETER Invalid parameter.
78**/
79EFI_STATUS
80EFIAPI
81FreeCmObjDesc (
82 IN CM_OBJ_DESCRIPTOR *CmObjDesc
83 )
84{
85 if (CmObjDesc == NULL) {
86 ASSERT (0);
87 return EFI_INVALID_PARAMETER;
88 }
89
90 if (CmObjDesc->Data != NULL) {
91 FreePool (CmObjDesc->Data);
92 }
93
94 FreePool (CmObjDesc);
95 return EFI_SUCCESS;
96}
97
98/** Add a single CmObj to the Configuration Manager.
99
100 @param [in] FdtParserHandle A handle to the parser instance.
101 @param [in] ObjectId CmObj ObjectId.
102 @param [in] Data CmObj Data.
103 @param [in] Size CmObj Size.
104 @param [out] Token If provided and success,
105 token generated for this CmObj.
106
107 @retval EFI_SUCCESS The function completed successfully.
108 @retval EFI_INVALID_PARAMETER Invalid parameter.
109**/
110EFI_STATUS
111EFIAPI
112AddSingleCmObj (
113 IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
114 IN CM_OBJECT_ID ObjectId,
115 IN VOID *Data,
116 IN UINT32 Size,
117 OUT CM_OBJECT_TOKEN *Token OPTIONAL
118 )
119{
120 EFI_STATUS Status;
121 CM_OBJ_DESCRIPTOR CmObjDesc;
122
123 if ((FdtParserHandle == NULL) ||
124 (FdtParserHandle->HwInfoAdd == NULL) ||
125 (Data == NULL) ||
126 (Size == 0))
127 {
128 ASSERT (0);
129 return EFI_INVALID_PARAMETER;
130 }
131
132 CmObjDesc.ObjectId = ObjectId;
133 CmObjDesc.Count = 1;
134 CmObjDesc.Data = Data;
135 CmObjDesc.Size = Size;
136
137 // Add the CmObj.
138 // Don't ask for a token.
139 Status = FdtParserHandle->HwInfoAdd (
140 FdtParserHandle,
141 FdtParserHandle->Context,
142 &CmObjDesc,
143 Token
144 );
145 ASSERT_EFI_ERROR (Status);
146 return Status;
147}
148
149/** Add multiple CmObj to the Configuration Manager.
150
151 @param [in] FdtParserHandle A handle to the parser instance.
152 @param [in] CmObjDesc CmObjDesc containing multiple CmObj
153 to add.
154 @param [in] TokenCount If provided, count of entries in the
155 TokenTable.
156 @param [out] TokenTable If provided and success,
157 token generated for these CmObj.
158 Address of an array of CM_OBJECT_TOKEN
159 with the same number of elements as the
160 CmObjDesc.
161
162 @retval EFI_SUCCESS The function completed successfully.
163 @retval EFI_INVALID_PARAMETER Invalid parameter.
164**/
165EFI_STATUS
166EFIAPI
167AddMultipleCmObj (
168 IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
169 IN CONST CM_OBJ_DESCRIPTOR *CmObjDesc,
170 IN UINT32 TokenCount, OPTIONAL
171 OUT CM_OBJECT_TOKEN *TokenTable OPTIONAL
172 )
173{
174 EFI_STATUS Status;
175 UINT32 Index;
176 UINT32 Count;
177 UINT8 *Data;
178 UINT32 Size;
179 CM_OBJ_DESCRIPTOR SingleCmObjDesc;
180
181 if ((FdtParserHandle == NULL) ||
182 (FdtParserHandle->HwInfoAdd == NULL) ||
183 (CmObjDesc == NULL) ||
184 (CmObjDesc->Count == 0) ||
185 (CmObjDesc->Data == NULL) ||
186 (CmObjDesc->Size == 0))
187 {
188 ASSERT (0);
189 return EFI_INVALID_PARAMETER;
190 }
191
192 Count = CmObjDesc->Count;
193 Data = CmObjDesc->Data;
194 Size = CmObjDesc->Size / Count;
195
196 SingleCmObjDesc.ObjectId = CmObjDesc->ObjectId;
197 SingleCmObjDesc.Count = 1;
198 SingleCmObjDesc.Size = Size;
199
200 for (Index = 0; Index < Count; Index++) {
201 SingleCmObjDesc.Data = (VOID *)&Data[Index * Size];
202 // Add the CmObj.
203 Status = FdtParserHandle->HwInfoAdd (
204 FdtParserHandle,
205 FdtParserHandle->Context,
206 &SingleCmObjDesc,
207 (TokenTable != NULL) ?
208 &TokenTable[Index] :
209 NULL
210 );
211 if (EFI_ERROR (Status)) {
212 ASSERT (0);
213 return Status;
214 }
215 } // for
216
217 return Status;
218}
219
220/** Add multiple CmObj to the Configuration Manager.
221
222 Get one token referencing a EArmObjCmRef CmObj itself referencing
223 the input CmObj. In the table below, RefToken is returned.
224
225 Token referencing an Array of tokens Array of CmObj
226 array of EArmObjCmRef referencing each from the input:
227 CmObj: CmObj from the input:
228
229 RefToken ---> CmObjToken[0] ---> CmObj[0]
230 CmObjToken[1] ---> CmObj[1]
231 CmObjToken[2] ---> CmObj[2]
232
233 @param [in] FdtParserHandle A handle to the parser instance.
234 @param [in] CmObjDesc CmObjDesc containing multiple CmObj
235 to add.
236 @param [out] Token If success, token referencing an array
237 of EArmObjCmRef CmObj, themselves
238 referencing the input CmObjs.
239
240 @retval EFI_SUCCESS The function completed successfully.
241 @retval EFI_INVALID_PARAMETER Invalid parameter.
242 @retval EFI_OUT_OF_RESOURCES An allocation has failed.
243**/
244EFI_STATUS
245EFIAPI
246AddMultipleCmObjWithCmObjRef (
247 IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
248 IN CM_OBJ_DESCRIPTOR *CmObjDesc,
249 OUT CM_OBJECT_TOKEN *Token
250 )
251{
252 EFI_STATUS Status;
253 CM_OBJ_DESCRIPTOR CmObjRef;
254 CM_OBJECT_TOKEN *TokenTable;
255 INT32 TokenTableSize;
256
257 if ((FdtParserHandle == NULL) ||
258 (FdtParserHandle->HwInfoAdd == NULL) ||
259 (CmObjDesc == NULL) ||
260 (CmObjDesc->Count == 0) ||
261 (CmObjDesc->Data == NULL) ||
262 (CmObjDesc->Size == 0) ||
263 (Token == NULL))
264 {
265 ASSERT (0);
266 return EFI_INVALID_PARAMETER;
267 }
268
269 // Allocate a buffer to store the tokens.
270 TokenTableSize = CmObjDesc->Count * sizeof (CM_OBJECT_TOKEN);
271 TokenTable = AllocateZeroPool (TokenTableSize);
272 if (TokenTable == NULL) {
273 ASSERT (0);
274 return EFI_OUT_OF_RESOURCES;
275 }
276
277 // Add the input CmObjs.
278 Status = AddMultipleCmObj (
279 FdtParserHandle,
280 CmObjDesc,
281 CmObjDesc->Count,
282 TokenTable
283 );
284 if (EFI_ERROR (Status)) {
285 ASSERT (0);
286 goto exit_handler;
287 }
288
289 CmObjRef.ObjectId = CREATE_CM_ARM_OBJECT_ID (EArmObjCmRef);
290 CmObjRef.Data = TokenTable;
291 CmObjRef.Count = CmObjDesc->Count;
292 CmObjRef.Size = TokenTableSize;
293
294 // Add the array of EArmObjCmRef CmObjs.
295 Status = FdtParserHandle->HwInfoAdd (
296 FdtParserHandle,
297 FdtParserHandle->Context,
298 &CmObjRef,
299 Token
300 );
301 ASSERT_EFI_ERROR (Status);
302
303exit_handler:
304 FreePool (TokenTable);
305 return Status;
306}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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