TianoCore EDK2 master
Loading...
Searching...
No Matches
McfgGenerator.c
Go to the documentation of this file.
1
13#include <Library/AcpiLib.h>
14#include <Library/DebugLib.h>
16#include <Protocol/AcpiTable.h>
17
18// Module specific include files.
19#include <AcpiTableGenerator.h>
24
33#pragma pack(1)
34
38typedef
41
45typedef
48
49#pragma pack()
50
57 );
58
69VOID
71 IN MCFG_TABLE *CONST Mcfg,
72 IN CONST UINT32 PciCfgSpaceOffset,
74 IN UINT32 PciCfgSpaceCount
75 )
76{
77 MCFG_CFG_SPACE_ADDR *PciCfgSpace;
78
79 ASSERT (Mcfg != NULL);
80 ASSERT (PciCfgSpaceInfoList != NULL);
81
82 PciCfgSpace = (MCFG_CFG_SPACE_ADDR *)((UINT8 *)Mcfg + PciCfgSpaceOffset);
83
84 while (PciCfgSpaceCount-- != 0) {
85 // Add PCI Configuration Space entry
86 PciCfgSpace->BaseAddress = PciCfgSpaceInfoList->BaseAddress;
87 PciCfgSpace->PciSegmentGroupNumber =
88 PciCfgSpaceInfoList->PciSegmentGroupNumber;
89 PciCfgSpace->StartBusNumber = PciCfgSpaceInfoList->StartBusNumber;
90 PciCfgSpace->EndBusNumber = PciCfgSpaceInfoList->EndBusNumber;
91 PciCfgSpace->Reserved = EFI_ACPI_RESERVED_DWORD;
92 PciCfgSpace++;
93 PciCfgSpaceInfoList++;
94 }
95}
96
119STATIC
121EFIAPI
127 )
128{
129 EFI_STATUS Status;
130 UINT32 TableSize;
131 UINT32 ConfigurationSpaceCount;
132 CM_ARCH_COMMON_PCI_CONFIG_SPACE_INFO *PciConfigSpaceInfoList;
133 MCFG_TABLE *Mcfg;
134
135 ASSERT (This != NULL);
136 ASSERT (AcpiTableInfo != NULL);
137 ASSERT (CfgMgrProtocol != NULL);
138 ASSERT (Table != NULL);
139 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
140 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
141
142 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
143 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision))
144 {
145 DEBUG ((
146 DEBUG_ERROR,
147 "ERROR: MCFG: Requested table revision = %d, is not supported."
148 "Supported table revision: Minimum = %d, Maximum = %d\n",
149 AcpiTableInfo->AcpiTableRevision,
150 This->MinAcpiTableRevision,
151 This->AcpiTableRevision
152 ));
153 return EFI_INVALID_PARAMETER;
154 }
155
156 *Table = NULL;
157 Status = GetEArchCommonObjPciConfigSpaceInfo (
158 CfgMgrProtocol,
160 &PciConfigSpaceInfoList,
161 &ConfigurationSpaceCount
162 );
163 if (EFI_ERROR (Status)) {
164 DEBUG ((
165 DEBUG_ERROR,
166 "ERROR: MCFG: Failed to get PCI Configuration Space Information." \
167 " Status = %r\n",
168 Status
169 ));
170 goto error_handler;
171 }
172
173 if (ConfigurationSpaceCount == 0) {
174 DEBUG ((
175 DEBUG_ERROR,
176 "ERROR: MCFG: Configuration Space Count = %d\n",
177 ConfigurationSpaceCount
178 ));
179 Status = EFI_INVALID_PARAMETER;
180 ASSERT (ConfigurationSpaceCount != 0);
181 goto error_handler;
182 }
183
184 DEBUG ((
185 DEBUG_INFO,
186 "MCFG: Configuration Space Count = %d\n",
187 ConfigurationSpaceCount
188 ));
189
190 // Calculate the MCFG Table Size
191 TableSize = sizeof (MCFG_TABLE) +
192 ((sizeof (MCFG_CFG_SPACE_ADDR) * ConfigurationSpaceCount));
193
194 *Table = (EFI_ACPI_DESCRIPTION_HEADER *)AllocateZeroPool (TableSize);
195 if (*Table == NULL) {
196 Status = EFI_OUT_OF_RESOURCES;
197 DEBUG ((
198 DEBUG_ERROR,
199 "ERROR: MCFG: Failed to allocate memory for MCFG Table, Size = %d," \
200 " Status = %r\n",
201 TableSize,
202 Status
203 ));
204 goto error_handler;
205 }
206
207 Mcfg = (MCFG_TABLE *)*Table;
208 DEBUG ((
209 DEBUG_INFO,
210 "MCFG: Mcfg = 0x%p TableSize = 0x%x\n",
211 Mcfg,
212 TableSize
213 ));
214
215 Status = AddAcpiHeader (
216 CfgMgrProtocol,
217 This,
218 &Mcfg->Header,
219 AcpiTableInfo,
220 TableSize
221 );
222 if (EFI_ERROR (Status)) {
223 DEBUG ((
224 DEBUG_ERROR,
225 "ERROR: MCFG: Failed to add ACPI header. Status = %r\n",
226 Status
227 ));
228 goto error_handler;
229 }
230
231 Mcfg->Reserved = EFI_ACPI_RESERVED_QWORD;
232
234 Mcfg,
235 sizeof (MCFG_TABLE),
236 PciConfigSpaceInfoList,
237 ConfigurationSpaceCount
238 );
239
240 return EFI_SUCCESS;
241
242error_handler:
243 if (*Table != NULL) {
244 FreePool (*Table);
245 *Table = NULL;
246 }
247
248 return Status;
249}
250
262STATIC
264EFIAPI
270 )
271{
272 ASSERT (This != NULL);
273 ASSERT (AcpiTableInfo != NULL);
274 ASSERT (CfgMgrProtocol != NULL);
275 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
276 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
277
278 if ((Table == NULL) || (*Table == NULL)) {
279 DEBUG ((DEBUG_ERROR, "ERROR: MCFG: Invalid Table Pointer\n"));
280 ASSERT ((Table != NULL) && (*Table != NULL));
281 return EFI_INVALID_PARAMETER;
282 }
283
284 FreePool (*Table);
285 *Table = NULL;
286 return EFI_SUCCESS;
287}
288
291#define MCFG_GENERATOR_REVISION CREATE_REVISION (1, 0)
292
295STATIC
296CONST
298 // Generator ID
300 // Generator Description
301 L"ACPI.STD.MCFG.GENERATOR",
302 // ACPI Table Signature
304 // ACPI Table Revision supported by this Generator
306 // Minimum supported ACPI Table Revision
308 // Creator ID
310 // Creator Revision
312 // Build Table function
314 // Free Resource function
316 // Extended build function not needed
317 NULL,
318 // Extended build function not implemented by the generator.
319 // Hence extended free resource function is not required.
320 NULL
321};
322
334EFIAPI
336 IN EFI_HANDLE ImageHandle,
337 IN EFI_SYSTEM_TABLE *SystemTable
338 )
339{
340 EFI_STATUS Status;
341
343 DEBUG ((DEBUG_INFO, "MCFG: Register Generator. Status = %r\n", Status));
344 ASSERT_EFI_ERROR (Status);
345 return Status;
346}
347
358EFIAPI
360 IN EFI_HANDLE ImageHandle,
361 IN EFI_SYSTEM_TABLE *SystemTable
362 )
363{
364 EFI_STATUS Status;
365
367 DEBUG ((DEBUG_INFO, "MCFG: Deregister Generator. Status = %r\n", Status));
368 ASSERT_EFI_ERROR (Status);
369 return Status;
370}
#define EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
Definition: Acpi62.h:2906
EFI_STATUS EFIAPI RegisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
EFI_STATUS EFIAPI DeregisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
#define CREATE_STD_ACPI_TABLE_GEN_ID(TableId)
#define TABLE_GENERATOR_CREATOR_ID
@ EStdAcpiTableIdMcfg
MCFG Generator.
@ EArchCommonObjPciConfigSpaceInfo
8 - PCI Configuration Space Info
#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type)
@ EObjNameSpaceArchCommon
Arch Common Objects Namespace.
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
STATIC VOID AddPciConfigurationSpaceList(IN MCFG_TABLE *CONST Mcfg, IN CONST UINT32 PciCfgSpaceOffset, IN CONST CM_ARCH_COMMON_PCI_CONFIG_SPACE_INFO *PciCfgSpaceInfoList, IN UINT32 PciCfgSpaceCount)
Definition: McfgGenerator.c:70
STATIC CONST ACPI_TABLE_GENERATOR McfgGenerator
STATIC EFI_STATUS EFIAPI BuildMcfgTable(IN CONST ACPI_TABLE_GENERATOR *CONST This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table)
EFI_STATUS EFIAPI AcpiMcfgLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
#define MCFG_GENERATOR_REVISION
EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE MCFG_CFG_SPACE_ADDR
Definition: McfgGenerator.c:47
EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER MCFG_TABLE
Definition: McfgGenerator.c:40
EFI_STATUS EFIAPI AcpiMcfgLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC EFI_STATUS EFIAPI FreeMcfgTableResources(IN CONST ACPI_TABLE_GENERATOR *CONST This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
#define CM_NULL_TOKEN
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
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112