[PATCH v2 5/6] DynamicTablesPkg: AcpiSsdtPcieLibArm: Added function to reserve ECAM space


Kun Qin
 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3998

Certain OSes will complain if the ECAM config space is not reserved in
the ACPI namespace.

This change adds a function to reserve PNP motherboard resources for a
given PCI node.

Co-authored-by: Joe Lopez <joelopez@...>
Signed-off-by: Kun Qin <kuqin12@...>
---

Notes:
v2:
- Only create RES0 after config space checking [Pierre]

DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerator.c |=
169 ++++++++++++++++++++
1 file changed, 169 insertions(+)

diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG=
enerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG=
enerator.c
index ceffe2838c03..c03550baabf2 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato=
r.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato=
r.c
@@ -616,6 +616,167 @@ GeneratePciCrs (
return Status;=0D
}=0D
=0D
+/** Generate a Pci Resource Template to hold Address Space Info=0D
+=0D
+ @param [in] PciNode RootNode of the AML tree.=0D
+ @param [in, out] CrsNode CRS node of the AML tree to populate.=0D
+=0D
+ @retval EFI_SUCCESS The function completed successfully.=0D
+ @retval EFI_INVALID_PARAMETER Invalid input parameter.=0D
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.=0D
+**/=0D
+STATIC=0D
+EFI_STATUS=0D
+EFIAPI=0D
+PopulateBasicPciResObjects (=0D
+ IN AML_OBJECT_NODE_HANDLE PciNode,=0D
+ IN OUT AML_OBJECT_NODE_HANDLE *CrsNode=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ UINT32 EisaId;=0D
+ AML_OBJECT_NODE_HANDLE ResNode;=0D
+=0D
+ if (CrsNode =3D=3D NULL) {=0D
+ ASSERT (0);=0D
+ return EFI_INVALID_PARAMETER;=0D
+ }=0D
+=0D
+ // ASL: Device (PCIx) {}=0D
+ Status =3D AmlCodeGenDevice ("RES0", PciNode, &ResNode);=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
+ // ASL: Name (_HID, EISAID ("PNP0C02"))=0D
+ Status =3D AmlGetEisaIdFromString ("PNP0C02", &EisaId); /* PNP Motherboa=
rd Resources */=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
+ Status =3D AmlCodeGenNameInteger ("_HID", EisaId, ResNode, NULL);=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
+ // ASL: Name (_CRS, ResourceTemplate () {})=0D
+ Status =3D AmlCodeGenNameResourceTemplate ("_CRS", ResNode, CrsNode);=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
+ return Status;=0D
+}=0D
+=0D
+/** Generate a Pci Resource Template to hold Address Space Info=0D
+=0D
+ @param [in] Generator The SSDT Pci generator.=0D
+ @param [in] CfgMgrProtocol Pointer to the Configuration Manager=0D
+ Protocol interface.=0D
+ @param [in] PciInfo Pci device information.=0D
+ @param [in, out] PciNode RootNode of the AML tree to populate.=
=0D
+=0D
+ @retval EFI_SUCCESS The function completed successfully.=0D
+ @retval EFI_INVALID_PARAMETER Invalid parameter.=0D
+ @retval EFI_OUT_OF_RESOURCES Could not allocate memory.=0D
+**/=0D
+STATIC=0D
+EFI_STATUS=0D
+EFIAPI=0D
+GeneratePciRes (=0D
+ IN ACPI_PCI_GENERATOR *Generator,=
=0D
+ IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtoc=
ol,=0D
+ IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO *PciInfo,=0D
+ IN OUT AML_OBJECT_NODE_HANDLE PciNode=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ AML_OBJECT_NODE_HANDLE CrsNode;=0D
+ BOOLEAN Translation;=0D
+ UINT32 Index;=0D
+ CM_ARM_OBJ_REF *RefInfo;=0D
+ UINT32 RefCount;=0D
+ CM_ARM_PCI_ADDRESS_MAP_INFO *AddrMapInfo;=0D
+ BOOLEAN IsPosDecode;=0D
+=0D
+ // Get the array of CM_ARM_OBJ_REF referencing the=0D
+ // CM_ARM_PCI_ADDRESS_MAP_INFO objects.=0D
+ Status =3D GetEArmObjCmRef (=0D
+ CfgMgrProtocol,=0D
+ PciInfo->AddressMapToken,=0D
+ &RefInfo,=0D
+ &RefCount=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
+ for (Index =3D 0; Index < RefCount; Index++) {=0D
+ // Get CM_ARM_PCI_ADDRESS_MAP_INFO structures one by one.=0D
+ Status =3D GetEArmObjPciAddressMapInfo (=0D
+ CfgMgrProtocol,=0D
+ RefInfo[Index].ReferenceToken,=0D
+ &AddrMapInfo,=0D
+ NULL=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
+ Translation =3D (AddrMapInfo->CpuAddress !=3D AddrMapInfo->PciAddress)=
;=0D
+ if (AddrMapInfo->CpuAddress >=3D AddrMapInfo->PciAddress) {=0D
+ IsPosDecode =3D TRUE;=0D
+ } else {=0D
+ IsPosDecode =3D FALSE;=0D
+ }=0D
+=0D
+ switch (AddrMapInfo->SpaceCode) {=0D
+ case PCI_SS_CONFIG:=0D
+ Status =3D PopulateBasicPciResObjects (PciNode, &CrsNode);=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ break;=0D
+ }=0D
+=0D
+ Status =3D AmlCodeGenRdQWordMemory (=0D
+ FALSE,=0D
+ IsPosDecode,=0D
+ TRUE,=0D
+ TRUE,=0D
+ FALSE, // non-cacheable=0D
+ TRUE,=0D
+ 0,=0D
+ AddrMapInfo->PciAddress,=0D
+ AddrMapInfo->PciAddress + AddrMapInfo->AddressSize - 1,=
=0D
+ Translation ? AddrMapInfo->CpuAddress - AddrMapInfo->Pc=
iAddress : 0,=0D
+ AddrMapInfo->AddressSize,=0D
+ 0,=0D
+ NULL,=0D
+ 0,=0D
+ TRUE,=0D
+ CrsNode,=0D
+ NULL=0D
+ );=0D
+ break;=0D
+ default:=0D
+ break;=0D
+ } // switch=0D
+=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+ }=0D
+=0D
+ return Status;=0D
+}=0D
+=0D
/** Generate a Pci device.=0D
=0D
@param [in] Generator The SSDT Pci generator.=0D
@@ -702,9 +863,17 @@ GeneratePciDevice (
return Status;=0D
}=0D
=0D
+ // Add the PNP Motherboard Resources Device to reserve ECAM space=0D
+ Status =3D GeneratePciRes (Generator, CfgMgrProtocol, PciInfo, PciNode);=
=0D
+ if (EFI_ERROR (Status)) {=0D
+ ASSERT (0);=0D
+ return Status;=0D
+ }=0D
+=0D
// Add the template _OSC method.=0D
Status =3D AddOscMethod (PciInfo, PciNode);=0D
ASSERT_EFI_ERROR (Status);=0D
+=0D
return Status;=0D
}=0D
=0D
--=20
2.37.1.windows.1

Join {devel@edk2.groups.io to automatically receive all group messages.