]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c
203207bac2b202f568072b68e8cb25c5c258045f
[mirror_edk2.git] / DynamicTablesPkg / Library / Common / TableHelperLib / TableHelper.c
1 /** @file
2 Table Helper
3
4 Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13
14 #include <Protocol/AcpiTable.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/BaseMemoryLib.h>
18
19 // Module specific include files.
20 #include <AcpiTableGenerator.h>
21 #include <ConfigurationManagerObject.h>
22 #include <Protocol/ConfigurationManagerProtocol.h>
23
24 /** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO
25 object from the Configuration Manager.
26
27 @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol
28 interface.
29 @param [out] CfgMfrInfo Pointer to the Configuration Manager Info
30 object structure.
31
32 @retval EFI_SUCCESS The object is returned.
33 @retval EFI_INVALID_PARAMETER The Object ID is invalid.
34 @retval EFI_NOT_FOUND The requested Object is not found.
35 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
36 Manager is less than the Object size.
37 **/
38 EFI_STATUS
39 EFIAPI
40 GetCgfMgrInfo (
41 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
42 OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo
43 )
44 {
45 EFI_STATUS Status;
46 CM_OBJ_DESCRIPTOR CmObjectDesc;
47
48 ASSERT (CfgMgrProtocol != NULL);
49 ASSERT (CfgMfrInfo != NULL);
50
51 *CfgMfrInfo = NULL;
52 Status = CfgMgrProtocol->GetObject (
53 CfgMgrProtocol,
54 CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo),
55 CM_NULL_TOKEN,
56 &CmObjectDesc
57 );
58 if (EFI_ERROR (Status)) {
59 DEBUG ((
60 DEBUG_ERROR,
61 "ERROR: Failed to Get Configuration Manager Info. Status = %r\n",
62 Status
63 ));
64 return Status;
65 }
66
67 if (CmObjectDesc.ObjectId != CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo)) {
68 DEBUG ((
69 DEBUG_ERROR,
70 "ERROR: EStdObjCfgMgrInfo: Invalid ObjectId = 0x%x, expected Id = 0x%x\n",
71 CmObjectDesc.ObjectId,
72 CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo)
73 ));
74 ASSERT (FALSE);
75 return EFI_INVALID_PARAMETER;
76 }
77
78 if (CmObjectDesc.Size <
79 (sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO) * CmObjectDesc.Count)) {
80 DEBUG ((
81 DEBUG_ERROR,
82 "ERROR: EStdObjCfgMgrInfo: Buffer too small, size = 0x%x\n",
83 CmObjectDesc.Size
84 ));
85 ASSERT (FALSE);
86 return EFI_BAD_BUFFER_SIZE;
87 }
88
89 *CfgMfrInfo = (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO*)CmObjectDesc.Data;
90 return Status;
91 }
92
93 /** The AddAcpiHeader function updates the ACPI header structure pointed by
94 the AcpiHeader. It utilizes the ACPI table Generator and the Configuration
95 Manager protocol to obtain any information required for constructing the
96 header.
97
98 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
99 protocol interface.
100 @param [in] Generator Pointer to the ACPI table Generator.
101 @param [in,out] AcpiHeader Pointer to the ACPI table header to be
102 updated.
103 @param [in] AcpiTableInfo Pointer to the ACPI table info structure.
104 @param [in] Length Length of the ACPI table.
105
106 @retval EFI_SUCCESS The ACPI table is updated successfully.
107 @retval EFI_INVALID_PARAMETER A parameter is invalid.
108 @retval EFI_NOT_FOUND The required object information is not found.
109 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
110 Manager is less than the Object size for the
111 requested object.
112 **/
113 EFI_STATUS
114 EFIAPI
115 AddAcpiHeader (
116 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
117 IN CONST ACPI_TABLE_GENERATOR * CONST Generator,
118 IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader,
119 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,
120 IN CONST UINT32 Length
121 )
122 {
123 EFI_STATUS Status;
124 CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMfrInfo;
125
126 ASSERT (CfgMgrProtocol != NULL);
127 ASSERT (Generator != NULL);
128 ASSERT (AcpiHeader != NULL);
129 ASSERT (Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));
130
131 if ((CfgMgrProtocol == NULL) ||
132 (Generator == NULL) ||
133 (AcpiHeader == NULL) ||
134 (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER))
135 ) {
136 return EFI_INVALID_PARAMETER;
137 }
138
139 Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
140 if (EFI_ERROR (Status)) {
141 DEBUG ((
142 DEBUG_ERROR,
143 "ERROR: Failed to get Configuration Manager info. Status = %r\n",
144 Status
145 ));
146 goto error_handler;
147 }
148
149 // UINT32 Signature
150 AcpiHeader->Signature = Generator->AcpiTableSignature;
151 // UINT32 Length
152 AcpiHeader->Length = Length;
153 // UINT8 Revision
154 AcpiHeader->Revision = AcpiTableInfo->AcpiTableRevision;
155 // UINT8 Checksum
156 AcpiHeader->Checksum = 0;
157
158 // UINT8 OemId[6]
159 CopyMem (AcpiHeader->OemId, CfgMfrInfo->OemId, sizeof (AcpiHeader->OemId));
160
161 // UINT64 OemTableId
162 if (AcpiTableInfo->OemTableId != 0) {
163 AcpiHeader->OemTableId = AcpiTableInfo->OemTableId;
164 } else {
165 AcpiHeader->OemTableId = SIGNATURE_32 (
166 CfgMfrInfo->OemId[0],
167 CfgMfrInfo->OemId[1],
168 CfgMfrInfo->OemId[2],
169 CfgMfrInfo->OemId[3]
170 ) |
171 ((UINT64)Generator->AcpiTableSignature << 32);
172 }
173
174 // UINT32 OemRevision
175 if (AcpiTableInfo->OemRevision != 0) {
176 AcpiHeader->OemRevision = AcpiTableInfo->OemRevision;
177 } else {
178 AcpiHeader->OemRevision = CfgMfrInfo->Revision;
179 }
180
181 // UINT32 CreatorId
182 AcpiHeader->CreatorId = Generator->CreatorId;
183 // UINT32 CreatorRevision
184 AcpiHeader->CreatorRevision = Generator->CreatorRevision;
185
186 error_handler:
187 return Status;
188 }