TianoCore EDK2 master
Loading...
Searching...
No Matches
TableHelper.c
Go to the documentation of this file.
1
10#include <Protocol/AcpiTable.h>
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
14
15// Module specific include files.
16#include <AcpiTableGenerator.h>
21
37EFIAPI
41 )
42{
43 EFI_STATUS Status;
44 CM_OBJ_DESCRIPTOR CmObjectDesc;
45
46 ASSERT (CfgMgrProtocol != NULL);
47 ASSERT (CfgMfrInfo != NULL);
48
49 *CfgMfrInfo = NULL;
50 Status = CfgMgrProtocol->GetObject (
51 CfgMgrProtocol,
54 &CmObjectDesc
55 );
56 if (EFI_ERROR (Status)) {
57 DEBUG ((
58 DEBUG_ERROR,
59 "ERROR: Failed to Get Configuration Manager Info. Status = %r\n",
60 Status
61 ));
62 return Status;
63 }
64
66 DEBUG ((
67 DEBUG_ERROR,
68 "ERROR: EStdObjCfgMgrInfo: Invalid ObjectId = 0x%x, expected Id = 0x%x\n",
69 CmObjectDesc.ObjectId,
71 ));
72 ASSERT (FALSE);
73 return EFI_INVALID_PARAMETER;
74 }
75
76 if (CmObjectDesc.Size <
77 (sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO) * CmObjectDesc.Count))
78 {
79 DEBUG ((
80 DEBUG_ERROR,
81 "ERROR: EStdObjCfgMgrInfo: Buffer too small, size = 0x%x\n",
82 CmObjectDesc.Size
83 ));
84 ASSERT (FALSE);
85 return EFI_BAD_BUFFER_SIZE;
86 }
87
88 *CfgMfrInfo = (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO *)CmObjectDesc.Data;
89 return Status;
90}
91
113EFIAPI
119 IN CONST UINT32 Length
120 )
121{
122 EFI_STATUS Status;
124
125 ASSERT (CfgMgrProtocol != NULL);
126 ASSERT (Generator != NULL);
127 ASSERT (AcpiHeader != NULL);
128 ASSERT (AcpiTableInfo != NULL);
129 ASSERT (Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));
130
131 if ((CfgMgrProtocol == NULL) ||
132 (Generator == NULL) ||
133 (AcpiHeader == NULL) ||
134 (AcpiTableInfo == NULL) ||
135 (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER))
136 )
137 {
138 return EFI_INVALID_PARAMETER;
139 }
140
141 Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
142 if (EFI_ERROR (Status)) {
143 DEBUG ((
144 DEBUG_ERROR,
145 "ERROR: Failed to get Configuration Manager info. Status = %r\n",
146 Status
147 ));
148 goto error_handler;
149 }
150
151 // UINT32 Signature
152 AcpiHeader->Signature = Generator->AcpiTableSignature;
153 // UINT32 Length
154 AcpiHeader->Length = Length;
155 // UINT8 Revision
156 AcpiHeader->Revision = AcpiTableInfo->AcpiTableRevision;
157 // UINT8 Checksum
158 AcpiHeader->Checksum = 0;
159
160 // UINT8 OemId[6]
161 CopyMem (AcpiHeader->OemId, CfgMfrInfo->OemId, sizeof (AcpiHeader->OemId));
162
163 // UINT64 OemTableId
164 if (AcpiTableInfo->OemTableId != 0) {
165 AcpiHeader->OemTableId = AcpiTableInfo->OemTableId;
166 } else {
167 AcpiHeader->OemTableId = SIGNATURE_32 (
168 CfgMfrInfo->OemId[0],
169 CfgMfrInfo->OemId[1],
170 CfgMfrInfo->OemId[2],
171 CfgMfrInfo->OemId[3]
172 ) |
173 LShiftU64 (
174 (UINT64)Generator->AcpiTableSignature,
175 32
176 );
177 }
178
179 // UINT32 OemRevision
180 if (AcpiTableInfo->OemRevision != 0) {
181 AcpiHeader->OemRevision = AcpiTableInfo->OemRevision;
182 } else {
183 AcpiHeader->OemRevision = CfgMfrInfo->Revision;
184 }
185
186 // UINT32 CreatorId
187 AcpiHeader->CreatorId = Generator->CreatorId;
188 // UINT32 CreatorRevision
189 AcpiHeader->CreatorRevision = Generator->CreatorRevision;
190
191error_handler:
192 return Status;
193}
194
220EFIAPI
225 OUT AML_ROOT_NODE_HANDLE *RootNode
226 )
227{
228 EFI_STATUS Status;
229 UINT64 OemTableId;
230 UINT32 OemRevision;
232
233 ASSERT (CfgMgrProtocol != NULL);
234 ASSERT (Generator != NULL);
235 ASSERT (AcpiTableInfo != NULL);
236
237 if ((CfgMgrProtocol == NULL) ||
238 (Generator == NULL) ||
239 (AcpiTableInfo == NULL))
240 {
241 return EFI_INVALID_PARAMETER;
242 }
243
244 Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
245 if (EFI_ERROR (Status)) {
246 DEBUG ((
247 DEBUG_ERROR,
248 "ERROR: Failed to get Configuration Manager info. Status = %r\n",
249 Status
250 ));
251 return Status;
252 }
253
254 if (AcpiTableInfo->OemTableId != 0) {
255 OemTableId = AcpiTableInfo->OemTableId;
256 } else {
257 OemTableId = SIGNATURE_32 (
258 CfgMfrInfo->OemId[0],
259 CfgMfrInfo->OemId[1],
260 CfgMfrInfo->OemId[2],
261 CfgMfrInfo->OemId[3]
262 ) |
263 LShiftU64 ((UINT64)Generator->AcpiTableSignature, 32);
264 }
265
266 if (AcpiTableInfo->OemRevision != 0) {
267 OemRevision = AcpiTableInfo->OemRevision;
268 } else {
269 OemRevision = CfgMfrInfo->Revision;
270 }
271
273 "SSDT",
274 (CONST CHAR8 *)&CfgMfrInfo->OemId,
275 (CONST CHAR8 *)&OemTableId,
276 OemRevision,
277 RootNode
278 );
279 ASSERT_EFI_ERROR (Status);
280 return Status;
281}
282
297BOOLEAN
298EFIAPI
300 IN CONST VOID *Array,
301 IN CONST UINTN Count,
302 IN CONST UINTN ElementSize,
303 IN PFN_IS_EQUAL EqualTestFunction
304 )
305{
306 UINTN Index1;
307 UINTN Index2;
308 UINT8 *Element1;
309 UINT8 *Element2;
310
311 if (Array == NULL) {
312 DEBUG ((DEBUG_ERROR, "ERROR: FindDuplicateValues: Array is NULL.\n"));
313 return TRUE;
314 }
315
316 if (ElementSize == 0) {
317 DEBUG ((DEBUG_ERROR, "ERROR: FindDuplicateValues: ElementSize is 0.\n"));
318 return TRUE;
319 }
320
321 if (EqualTestFunction == NULL) {
322 DEBUG ((
323 DEBUG_ERROR,
324 "ERROR: FindDuplicateValues: EqualTestFunction is NULL.\n"
325 ));
326 return TRUE;
327 }
328
329 if (Count < 2) {
330 return FALSE;
331 }
332
333 for (Index1 = 0; Index1 < Count - 1; Index1++) {
334 for (Index2 = Index1 + 1; Index2 < Count; Index2++) {
335 Element1 = (UINT8 *)Array + (Index1 * ElementSize);
336 Element2 = (UINT8 *)Array + (Index2 * ElementSize);
337
338 if (EqualTestFunction (Element1, Element2, Index1, Index2)) {
339 return TRUE;
340 }
341 }
342 }
343
344 return FALSE;
345}
UINT64 UINTN
void * AML_ROOT_NODE_HANDLE
Definition: AmlLib.h:51
EFI_STATUS EFIAPI AmlCodeGenDefinitionBlock(IN CONST CHAR8 *TableSignature, IN CONST CHAR8 *OemId, IN CONST CHAR8 *OemTableId, IN UINT32 OemRevision, OUT AML_ROOT_NODE_HANDLE *NewRootNode)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define CREATE_CM_STD_OBJECT_ID(ObjectId)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define SIGNATURE_32(A, B, C, D)
Definition: Base.h:1310
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
@ EStdObjCfgMgrInfo
0 - Configuration Manager Info
#define CM_NULL_TOKEN
EFI_STATUS EFIAPI AddSsdtAcpiHeader(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR *CONST Generator, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, OUT AML_ROOT_NODE_HANDLE *RootNode)
Definition: TableHelper.c:221
EFI_STATUS EFIAPI AddAcpiHeader(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR *CONST Generator, IN OUT EFI_ACPI_DESCRIPTION_HEADER *CONST AcpiHeader, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST UINT32 Length)
Definition: TableHelper.c:114
BOOLEAN EFIAPI FindDuplicateValue(IN CONST VOID *Array, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN PFN_IS_EQUAL EqualTestFunction)
Definition: TableHelper.c:299
EFI_STATUS EFIAPI GetCgfMgrInfo(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO **CfgMfrInfo)
Definition: TableHelper.c:38
BOOLEAN(EFIAPI * PFN_IS_EQUAL)(IN CONST VOID *Object1, IN CONST VOID *Object2, IN UINTN Index1 OPTIONAL, IN UINTN Index2 OPTIONAL)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
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.
UINT32 Revision
The Configuration Manager Revision.