TianoCore EDK2 master
Loading...
Searching...
No Matches
CmObjectDescUtility.c
Go to the documentation of this file.
1
10
11#include "CmObjectDescUtility.h"
12
28EFIAPI
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
80EFIAPI
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
111EFIAPI
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
166EFIAPI
168 IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
169 IN CONST CM_OBJ_DESCRIPTOR *CmObjDesc,
170 IN UINT32 TokenCount, 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
245EFIAPI
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;
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,
283 );
284 if (EFI_ERROR (Status)) {
285 ASSERT (0);
286 goto exit_handler;
287 }
288
290 CmObjRef.Data = TokenTable;
291 CmObjRef.Count = CmObjDesc->Count;
292 CmObjRef.Size = TokenTableSize;
293
294 // Add the array of EArchCommonObjCmRef CmObjs.
295 Status = FdtParserHandle->HwInfoAdd (
296 FdtParserHandle,
297 FdtParserHandle->Context,
298 &CmObjRef,
299 Token
300 );
301 ASSERT_EFI_ERROR (Status);
302
303exit_handler:
305 return Status;
306}
@ EArchCommonObjCmRef
7 - CM Object Reference
EFI_STATUS EFIAPI AddMultipleCmObjWithCmObjRef(IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, IN CM_OBJ_DESCRIPTOR *CmObjDesc, OUT CM_OBJECT_TOKEN *Token)
EFI_STATUS EFIAPI FreeCmObjDesc(IN CM_OBJ_DESCRIPTOR *CmObjDesc)
EFI_STATUS EFIAPI AddMultipleCmObj(IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, IN CONST CM_OBJ_DESCRIPTOR *CmObjDesc, IN UINT32 TokenCount, OPTIONAL OUT CM_OBJECT_TOKEN *TokenTable OPTIONAL)
EFI_STATUS EFIAPI AddSingleCmObj(IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle, IN CM_OBJECT_ID ObjectId, IN VOID *Data, IN UINT32 Size, OUT CM_OBJECT_TOKEN *Token OPTIONAL)
EFI_STATUS EFIAPI CreateCmObjDesc(IN CM_OBJECT_ID ObjectId, IN UINT32 Count, IN VOID *Data, IN UINT32 Size, OUT CM_OBJ_DESCRIPTOR **NewCmObjDesc)
UINT32 CM_OBJECT_ID
#define CREATE_CM_ARCH_COMMON_OBJECT_ID(ObjectId)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
UINTN CM_OBJECT_TOKEN
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID * Data
Pointer to the described Object or Object List.
UINT32 Size
Size of the described Object or Object List.
UINT32 Count
Count of objects in the list.
CM_OBJECT_ID ObjectId
Object Id.