From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.9355.1639041923165221731 for ; Thu, 09 Dec 2021 01:25:23 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB4261480; Thu, 9 Dec 2021 01:25:19 -0800 (PST) Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 185983F73B; Thu, 9 Dec 2021 01:25:18 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [PATCH v4 4/8] DynamicTablesPkg: AML Code generation to add _PRT entries Date: Thu, 9 Dec 2021 10:25:01 +0100 Message-Id: <20211209092505.1248326-5-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211209092505.1248326-1-Pierre.Gondois@arm.com> References: <20211209092505.1248326-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pierre Gondois _PRT entries can describe interrupt mapping for Pci devices. The object is described in ACPI 6.4 s6.2.13 "_PRT (PCI Routing Table)". Add AmlCodeGenPrtEntry() helper function to add _PRT entries to an existing _PRT object. To: Sami Mujawar To: Alexei Fedorov Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../Include/Library/AmlLib/AmlLib.h | 52 +++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 214 ++++++++++++++++++ 2 files changed, 266 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTa= blesPkg/Include/Library/AmlLib/AmlLib.h index 8949cf4d932a..9ca34f61ba88 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -891,6 +891,58 @@ AmlCodeGenNameResourceTemplate ( OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ); =20 +/** Add a _PRT entry. + + AmlCodeGenPrtEntry (0x0FFFF, 0, "LNKA", 0, PrtNameNode) is + equivalent of the following ASL code: + Package (4) { + 0x0FFFF, // Address: Device address (([Device Id] << 16) | 0xFFFF)= . + 0, // Pin: PCI pin number of the device (0-INTA, ...). + LNKA // Source: Name of the device that allocates the interrup= t + // to which the above pin is connected. + 0 // Source Index: Source is assumed to only describe one + // interrupt, so let it to index 0. + } + + The package is added at the tail of the list of the input _PRT node + name: + Name (_PRT, Package () { + [Pre-existing _PRT entries], + [Newly created _PRT entry] + }) + + Cf. ACPI 6.4, s6.2.13 "_PRT (PCI Routing Table)" + + @ingroup CodeGenApis + + @param [in] Address Address. Cf ACPI 6.4 specification, Table = 6.2: + "ADR Object Address Encodings": + High word-Device #, Low word-Function #. (= for + example, device 3, function 2 is 0x0003000= 2). + To refer to all the functions on a device = #, + use a function number of FFFF). + @param [in] Pin PCI pin number of the device (0-INTA ... 3= -INTD). + Must be between 0-3. + @param [in] LinkName Link Name, i.e. device in the AML NameSpac= e + describing the interrupt used. + The input string is copied. + @param [in] SourceIndex Source index or GSIV. + @param [in] PrtNameNode Prt Named node to add the object to .... + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlAddPrtEntry ( + IN UINT32 Address, + IN UINT8 Pin, + IN CONST CHAR8 *LinkName, + IN UINT32 SourceIndex, + IN AML_OBJECT_NODE_HANDLE PrtNameNode + ); + /** AML code generation for a Device object node. =20 AmlCodeGenDevice ("COM0", ParentNode, NewObjectNode) is diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c = b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index 778e3c5ffaf0..d245848ce3fa 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -868,6 +868,220 @@ AmlCodeGenNameResourceTemplate ( return Status; } =20 +/** Add a _PRT entry. + + AmlCodeGenPrtEntry (0x0FFFF, 0, "LNKA", 0, PrtNameNode) is + equivalent of the following ASL code: + Package (4) { + 0x0FFFF, // Address: Device address (([Device Id] << 16) | 0xFFFF)= . + 0, // Pin: PCI pin number of the device (0-INTA, ...). + LNKA // Source: Name of the device that allocates the interrup= t + // to which the above pin is connected. + 0 // Source Index: Source is assumed to only describe one + // interrupt, so let it to index 0. + } + + The package is added at the tail of the list of the input _PRT node + name: + Name (_PRT, Package () { + [Pre-existing _PRT entries], + [Newly created _PRT entry] + }) + + Cf. ACPI 6.4 specification: + - s6.2.13 "_PRT (PCI Routing Table)" + - s6.1.1 "_ADR (Address)" + + @param [in] Address Address. Cf ACPI 6.4 specification, Table = 6.2: + "ADR Object Address Encodings": + High word-Device #, Low word-Function #. (= for + example, device 3, function 2 is 0x0003000= 2). + To refer to all the functions on a device = #, + use a function number of FFFF). + @param [in] Pin PCI pin number of the device (0-INTA ... 3= -INTD). + Must be between 0-3. + @param [in] LinkName Link Name, i.e. device in the AML NameSpac= e + describing the interrupt used. + The input string is copied. + @param [in] SourceIndex Source index or GSIV. + @param [in] PrtNameNode Prt Named node to add the object to .... + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlAddPrtEntry ( + IN UINT32 Address, + IN UINT8 Pin, + IN CONST CHAR8 *LinkName, + IN UINT32 SourceIndex, + IN AML_OBJECT_NODE_HANDLE PrtNameNode + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE *PrtEntryList; + AML_OBJECT_NODE *PackageNode; + AML_OBJECT_NODE *NewElementNode; + + CHAR8 *AmlNameString; + UINT32 AmlNameStringSize; + AML_DATA_NODE *DataNode; + + if ((Pin > 3) || + (LinkName =3D=3D NULL) || + (PrtNameNode =3D=3D NULL) || + (AmlGetNodeType ((AML_NODE_HANDLE)PrtNameNode) !=3D EAmlNodeObject= ) || + (!AmlNodeHasOpCode (PrtNameNode, AML_NAME_OP, 0)) = || + !AmlNameOpCompareName (PrtNameNode, "_PRT")) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + NewElementNode =3D NULL; + AmlNameString =3D NULL; + DataNode =3D NULL; + + // Get the Package object node of the _PRT node, + // which is the 2nd fixed argument (i.e. index 1). + PrtEntryList =3D (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument ( + PrtNameNode, + EAmlParseIndexTerm1 + ); + if ((PrtEntryList =3D=3D NULL) = || + (AmlGetNodeType ((AML_NODE_HANDLE)PrtEntryList) !=3D EAmlNodeObjec= t) || + (!AmlNodeHasOpCode (PrtEntryList, AML_PACKAGE_OP, 0))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // The new _PRT entry. + Status =3D AmlCodeGenPackage (&PackageNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D AmlCodeGenInteger (Address, &NewElementNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D AmlVarListAddTail ( + (AML_NODE_HANDLE)PackageNode, + (AML_NODE_HANDLE)NewElementNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + NewElementNode =3D NULL; + + Status =3D AmlCodeGenInteger (Pin, &NewElementNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D AmlVarListAddTail ( + (AML_NODE_HANDLE)PackageNode, + (AML_NODE_HANDLE)NewElementNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + NewElementNode =3D NULL; + + Status =3D ConvertAslNameToAmlName (LinkName, &AmlNameString); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D AmlGetNameStringSize (AmlNameString, &AmlNameStringSize); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeNameString, + (UINT8 *)AmlNameString, + AmlNameStringSize, + &DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // AmlNameString will be freed before returning. + + Status =3D AmlVarListAddTail ( + (AML_NODE_HANDLE)PackageNode, + (AML_NODE_HANDLE)DataNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + DataNode =3D NULL; + + Status =3D AmlCodeGenInteger (SourceIndex, &NewElementNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status =3D AmlVarListAddTail ( + (AML_NODE_HANDLE)PackageNode, + (AML_NODE_HANDLE)NewElementNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // Append to the the list of _PRT entries. + Status =3D AmlVarListAddTail ( + (AML_NODE_HANDLE)PrtEntryList, + (AML_NODE_HANDLE)PackageNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + // Free AmlNameString before returning as it is copied + // in the call to AmlCreateDataNode(). + goto exit_handler; + +error_handler: + AmlDeleteTree ((AML_NODE_HANDLE)PackageNode); + if (NewElementNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)NewElementNode); + } + + if (DataNode !=3D NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)DataNode); + } + +exit_handler: + if (AmlNameString !=3D NULL) { + FreePool (AmlNameString); + } + + return Status; +} + /** AML code generation for a Device object node. =20 AmlCodeGenDevice ("COM0", ParentNode, NewObjectNode) is --=20 2.25.1