4 Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - PCI Firmware Specification - Revision 3.2, January 26, 2015.
12 #include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
13 #include <Library/AcpiLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Protocol/AcpiTable.h>
18 // Module specific include files.
19 #include <AcpiTableGenerator.h>
20 #include <ConfigurationManagerObject.h>
21 #include <ConfigurationManagerHelper.h>
22 #include <Library/TableHelperLib.h>
23 #include <Protocol/ConfigurationManagerProtocol.h>
25 /** ARM standard MCFG Generator
28 The following Configuration Manager Object(s) are required by
30 - EArmObjPciConfigSpaceInfo
35 /** This typedef is used to shorten the name of the MCFG Table
39 EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_BASE_ADDRESS_TABLE_HEADER
42 /** This typedef is used to shorten the name of the Enhanced
43 Configuration Space address structure.
46 EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE
51 /** Retrieve the PCI Configuration Space Information.
55 EArmObjPciConfigSpaceInfo
,
56 CM_ARM_PCI_CONFIG_SPACE_INFO
59 /** Add the PCI Enhanced Configuration Space Information to the MCFG Table.
61 @param [in] Mcfg Pointer to MCFG Table.
62 @param [in] PciCfgSpaceOffset Offset for the PCI Configuration Space
63 Info structure in the MCFG Table.
64 @param [in] PciCfgSpaceInfoList Pointer to the PCI Configuration Space
66 @param [in] PciCfgSpaceCount Count of PCI Configuration Space Info.
70 AddPciConfigurationSpaceList (
71 IN MCFG_TABLE
* CONST Mcfg
,
72 IN CONST UINT32 PciCfgSpaceOffset
,
73 IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO
* PciCfgSpaceInfoList
,
74 IN UINT32 PciCfgSpaceCount
77 MCFG_CFG_SPACE_ADDR
* PciCfgSpace
;
79 ASSERT (Mcfg
!= NULL
);
80 ASSERT (PciCfgSpaceInfoList
!= NULL
);
82 PciCfgSpace
= (MCFG_CFG_SPACE_ADDR
*)((UINT8
*)Mcfg
+ PciCfgSpaceOffset
);
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
;
93 PciCfgSpaceInfoList
++;
97 /** Construct the MCFG ACPI table.
99 This function invokes the Configuration Manager protocol interface
100 to get the required hardware information for generating the ACPI
103 If this function allocates any resources then they must be freed
104 in the FreeXXXXTableResources function.
106 @param [in] This Pointer to the table generator.
107 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
108 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
110 @param [out] Table Pointer to the constructed ACPI Table.
112 @retval EFI_SUCCESS Table generated successfully.
113 @retval EFI_INVALID_PARAMETER A parameter is invalid.
114 @retval EFI_NOT_FOUND The required object was not found.
115 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
116 Manager is less than the Object size for the
123 IN CONST ACPI_TABLE_GENERATOR
* CONST This
,
124 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO
* CONST AcpiTableInfo
,
125 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
126 OUT EFI_ACPI_DESCRIPTION_HEADER
** CONST Table
131 UINT32 ConfigurationSpaceCount
;
132 CM_ARM_PCI_CONFIG_SPACE_INFO
* PciConfigSpaceInfoList
;
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
);
142 if ((AcpiTableInfo
->AcpiTableRevision
< This
->MinAcpiTableRevision
) ||
143 (AcpiTableInfo
->AcpiTableRevision
> This
->AcpiTableRevision
)) {
146 "ERROR: MCFG: Requested table revision = %d, is not supported."
147 "Supported table revision: Minimum = %d, Maximum = %d\n",
148 AcpiTableInfo
->AcpiTableRevision
,
149 This
->MinAcpiTableRevision
,
150 This
->AcpiTableRevision
152 return EFI_INVALID_PARAMETER
;
156 Status
= GetEArmObjPciConfigSpaceInfo (
159 &PciConfigSpaceInfoList
,
160 &ConfigurationSpaceCount
162 if (EFI_ERROR (Status
)) {
164 "ERROR: MCFG: Failed to get PCI Configuration Space Information." \
171 if (ConfigurationSpaceCount
== 0) {
174 "ERROR: MCFG: Configuration Space Count = %d\n",
175 ConfigurationSpaceCount
177 Status
= EFI_INVALID_PARAMETER
;
178 ASSERT (ConfigurationSpaceCount
!= 0);
184 "MCFG: Configuration Space Count = %d\n",
185 ConfigurationSpaceCount
188 // Calculate the MCFG Table Size
189 TableSize
= sizeof (MCFG_TABLE
) +
190 ((sizeof (MCFG_CFG_SPACE_ADDR
) * ConfigurationSpaceCount
));
192 *Table
= (EFI_ACPI_DESCRIPTION_HEADER
*)AllocateZeroPool (TableSize
);
193 if (*Table
== NULL
) {
194 Status
= EFI_OUT_OF_RESOURCES
;
197 "ERROR: MCFG: Failed to allocate memory for MCFG Table, Size = %d," \
205 Mcfg
= (MCFG_TABLE
*)*Table
;
208 "MCFG: Mcfg = 0x%p TableSize = 0x%x\n",
213 Status
= AddAcpiHeader (
220 if (EFI_ERROR (Status
)) {
223 "ERROR: MCFG: Failed to add ACPI header. Status = %r\n",
229 Mcfg
->Reserved
= EFI_ACPI_RESERVED_QWORD
;
231 AddPciConfigurationSpaceList (
234 PciConfigSpaceInfoList
,
235 ConfigurationSpaceCount
241 if (*Table
!= NULL
) {
248 /** Free any resources allocated for constructing the MCFG
250 @param [in] This Pointer to the table generator.
251 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
252 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
254 @param [in, out] Table Pointer to the ACPI Table.
256 @retval EFI_SUCCESS The resources were freed successfully.
257 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
261 FreeMcfgTableResources (
262 IN CONST ACPI_TABLE_GENERATOR
* CONST This
,
263 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO
* CONST AcpiTableInfo
,
264 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
265 IN OUT EFI_ACPI_DESCRIPTION_HEADER
** CONST Table
268 ASSERT (This
!= NULL
);
269 ASSERT (AcpiTableInfo
!= NULL
);
270 ASSERT (CfgMgrProtocol
!= NULL
);
271 ASSERT (AcpiTableInfo
->TableGeneratorId
== This
->GeneratorID
);
272 ASSERT (AcpiTableInfo
->AcpiTableSignature
== This
->AcpiTableSignature
);
274 if ((Table
== NULL
) || (*Table
== NULL
)) {
275 DEBUG ((DEBUG_ERROR
, "ERROR: MCFG: Invalid Table Pointer\n"));
276 ASSERT ((Table
!= NULL
) && (*Table
!= NULL
));
277 return EFI_INVALID_PARAMETER
;
285 /** This macro defines the MCFG Table Generator revision.
287 #define MCFG_GENERATOR_REVISION CREATE_REVISION (1, 0)
289 /** The interface for the MCFG Table Generator.
293 ACPI_TABLE_GENERATOR McfgGenerator
= {
295 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdMcfg
),
296 // Generator Description
297 L
"ACPI.STD.MCFG.GENERATOR",
298 // ACPI Table Signature
299 EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
,
300 // ACPI Table Revision supported by this Generator
301 EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
,
302 // Minimum supported ACPI Table Revision
303 EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
,
305 TABLE_GENERATOR_CREATOR_ID_ARM
,
307 MCFG_GENERATOR_REVISION
,
308 // Build Table function
310 // Free Resource function
311 FreeMcfgTableResources
,
312 // Extended build function not needed
314 // Extended build function not implemented by the generator.
315 // Hence extended free resource function is not required.
319 /** Register the Generator with the ACPI Table Factory.
321 @param [in] ImageHandle The handle to the image.
322 @param [in] SystemTable Pointer to the System Table.
324 @retval EFI_SUCCESS The Generator is registered.
325 @retval EFI_INVALID_PARAMETER A parameter is invalid.
326 @retval EFI_ALREADY_STARTED The Generator for the Table ID
327 is already registered.
331 AcpiMcfgLibConstructor (
332 IN CONST EFI_HANDLE ImageHandle
,
333 IN EFI_SYSTEM_TABLE
* CONST SystemTable
337 Status
= RegisterAcpiTableGenerator (&McfgGenerator
);
338 DEBUG ((DEBUG_INFO
, "MCFG: Register Generator. Status = %r\n", Status
));
339 ASSERT_EFI_ERROR (Status
);
343 /** Deregister the Generator from the ACPI Table Factory.
345 @param [in] ImageHandle The handle to the image.
346 @param [in] SystemTable Pointer to the System Table.
348 @retval EFI_SUCCESS The Generator is deregistered.
349 @retval EFI_INVALID_PARAMETER A parameter is invalid.
350 @retval EFI_NOT_FOUND The Generator is not registered.
354 AcpiMcfgLibDestructor (
355 IN CONST EFI_HANDLE ImageHandle
,
356 IN EFI_SYSTEM_TABLE
* CONST SystemTable
360 Status
= DeregisterAcpiTableGenerator (&McfgGenerator
);
361 DEBUG ((DEBUG_INFO
, "MCFG: Deregister Generator. Status = %r\n", Status
));
362 ASSERT_EFI_ERROR (Status
);