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
))
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
153 return EFI_INVALID_PARAMETER
;
157 Status
= GetEArmObjPciConfigSpaceInfo (
160 &PciConfigSpaceInfoList
,
161 &ConfigurationSpaceCount
163 if (EFI_ERROR (Status
)) {
166 "ERROR: MCFG: Failed to get PCI Configuration Space Information." \
173 if (ConfigurationSpaceCount
== 0) {
176 "ERROR: MCFG: Configuration Space Count = %d\n",
177 ConfigurationSpaceCount
179 Status
= EFI_INVALID_PARAMETER
;
180 ASSERT (ConfigurationSpaceCount
!= 0);
186 "MCFG: Configuration Space Count = %d\n",
187 ConfigurationSpaceCount
190 // Calculate the MCFG Table Size
191 TableSize
= sizeof (MCFG_TABLE
) +
192 ((sizeof (MCFG_CFG_SPACE_ADDR
) * ConfigurationSpaceCount
));
194 *Table
= (EFI_ACPI_DESCRIPTION_HEADER
*)AllocateZeroPool (TableSize
);
195 if (*Table
== NULL
) {
196 Status
= EFI_OUT_OF_RESOURCES
;
199 "ERROR: MCFG: Failed to allocate memory for MCFG Table, Size = %d," \
207 Mcfg
= (MCFG_TABLE
*)*Table
;
210 "MCFG: Mcfg = 0x%p TableSize = 0x%x\n",
215 Status
= AddAcpiHeader (
222 if (EFI_ERROR (Status
)) {
225 "ERROR: MCFG: Failed to add ACPI header. Status = %r\n",
231 Mcfg
->Reserved
= EFI_ACPI_RESERVED_QWORD
;
233 AddPciConfigurationSpaceList (
236 PciConfigSpaceInfoList
,
237 ConfigurationSpaceCount
243 if (*Table
!= NULL
) {
251 /** Free any resources allocated for constructing the MCFG
253 @param [in] This Pointer to the table generator.
254 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
255 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
257 @param [in, out] Table Pointer to the ACPI Table.
259 @retval EFI_SUCCESS The resources were freed successfully.
260 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
264 FreeMcfgTableResources (
265 IN CONST ACPI_TABLE_GENERATOR
*CONST This
,
266 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO
*CONST AcpiTableInfo
,
267 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
*CONST CfgMgrProtocol
,
268 IN OUT EFI_ACPI_DESCRIPTION_HEADER
**CONST Table
271 ASSERT (This
!= NULL
);
272 ASSERT (AcpiTableInfo
!= NULL
);
273 ASSERT (CfgMgrProtocol
!= NULL
);
274 ASSERT (AcpiTableInfo
->TableGeneratorId
== This
->GeneratorID
);
275 ASSERT (AcpiTableInfo
->AcpiTableSignature
== This
->AcpiTableSignature
);
277 if ((Table
== NULL
) || (*Table
== NULL
)) {
278 DEBUG ((DEBUG_ERROR
, "ERROR: MCFG: Invalid Table Pointer\n"));
279 ASSERT ((Table
!= NULL
) && (*Table
!= NULL
));
280 return EFI_INVALID_PARAMETER
;
288 /** This macro defines the MCFG Table Generator revision.
290 #define MCFG_GENERATOR_REVISION CREATE_REVISION (1, 0)
292 /** The interface for the MCFG Table Generator.
296 ACPI_TABLE_GENERATOR McfgGenerator
= {
298 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdMcfg
),
299 // Generator Description
300 L
"ACPI.STD.MCFG.GENERATOR",
301 // ACPI Table Signature
302 EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
,
303 // ACPI Table Revision supported by this Generator
304 EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
,
305 // Minimum supported ACPI Table Revision
306 EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION
,
308 TABLE_GENERATOR_CREATOR_ID_ARM
,
310 MCFG_GENERATOR_REVISION
,
311 // Build Table function
313 // Free Resource function
314 FreeMcfgTableResources
,
315 // Extended build function not needed
317 // Extended build function not implemented by the generator.
318 // Hence extended free resource function is not required.
322 /** Register the Generator with the ACPI Table Factory.
324 @param [in] ImageHandle The handle to the image.
325 @param [in] SystemTable Pointer to the System Table.
327 @retval EFI_SUCCESS The Generator is registered.
328 @retval EFI_INVALID_PARAMETER A parameter is invalid.
329 @retval EFI_ALREADY_STARTED The Generator for the Table ID
330 is already registered.
334 AcpiMcfgLibConstructor (
335 IN EFI_HANDLE ImageHandle
,
336 IN EFI_SYSTEM_TABLE
*SystemTable
341 Status
= RegisterAcpiTableGenerator (&McfgGenerator
);
342 DEBUG ((DEBUG_INFO
, "MCFG: Register Generator. Status = %r\n", Status
));
343 ASSERT_EFI_ERROR (Status
);
347 /** Deregister the Generator from the ACPI Table Factory.
349 @param [in] ImageHandle The handle to the image.
350 @param [in] SystemTable Pointer to the System Table.
352 @retval EFI_SUCCESS The Generator is deregistered.
353 @retval EFI_INVALID_PARAMETER A parameter is invalid.
354 @retval EFI_NOT_FOUND The Generator is not registered.
358 AcpiMcfgLibDestructor (
359 IN EFI_HANDLE ImageHandle
,
360 IN EFI_SYSTEM_TABLE
*SystemTable
365 Status
= DeregisterAcpiTableGenerator (&McfgGenerator
);
366 DEBUG ((DEBUG_INFO
, "MCFG: Deregister Generator. Status = %r\n", Status
));
367 ASSERT_EFI_ERROR (Status
);