From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81753+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81753+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970740; cv=none; d=zohomail.com; s=zohoarc; b=IWaCg6DZao+9eVJVxp4luK/nIqImSDmTO1pgUxKtd5k6JUqDWBFmGQSs5+QdJENaSgK0yj7GTcqW8pRsZWJKlMSiCkfpIr1q3O94fzCAAHNpMe1/UPtiVPObw6q6ZV/gGp5bL7jGf4RTWkCvc5tyas+t3e7Ax3qj8kWBqtI1kNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970740; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=L1k8qex93wymjG1Ep4uCkN0J+lCT6jDRuvEmUDG0+nA=; b=bgyB0cg733ralt9WB3NisQRlubRF+Stma2qk53FpgJETnIfOq5MTP4V2FbaqrLadP8NBNHpM18L5CkeHrmvpMWMfsH7EeAtpxujvgMHhudDgytteISf/7pHvYiQLndygh6K0oXvmV1RWunKSBBCmw99wo2tYzG//5QcnZKElY+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81753+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633970740950698.8425722230643; Mon, 11 Oct 2021 09:45:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SrI8YY1788612x9uXeGKmd07; Mon, 11 Oct 2021 09:45:40 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1048.1633970738603569889 for ; Mon, 11 Oct 2021 09:45:38 -0700 X-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 5413C1063; Mon, 11 Oct 2021 09:45:32 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CCD973F7D8; Mon, 11 Oct 2021 09:45:30 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 1/7] DynamicTablesPkg: AML Code generation for memory ranges Date: Mon, 11 Oct 2021 17:45:21 +0100 Message-Id: <20211011164527.18660-2-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: AOEShV9dfCgUFHts59yrjw8ux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970740; bh=6B9KlXSY1xmL4YF7+L67ug56xBJDR/7zY8xlrz8Kywk=; h=Date:From:Reply-To:Subject:To; b=uWbJoeth83M+YgbFUeMWnmiXTx/haRjcaaN9ksRLncY/EM9fWscMwwp94JiwkXUwC85 KOyi2WuHSR1ZcdoxXQpsYmeqOReihPI0EiiuPL0sQzpJPFqNJfV4DHAgrhoJ6FBFcnD9m 6y2wOrmHFNQklWxKdZqv6IkyWZTrWFd/bEE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970741939100013 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add helper functions to generate AML Resource Data describing memory ranges. Memory ranges can be one, double or four words long. They can be of 'normal', IO or bus number memory type. The following APIs are exposed: - AmlCodeGenRdDWordIo () - AmlCodeGenRdDWordMemory () - AmlCodeGenRdWordBusNumber () - AmlCodeGenRdQWordMemory () To: Sami Mujawar To: Alexei Fedorov Signed-off-by: Pierre Gondois --- Notes: v2: - Correct typos/reformulate descriptions. [Sami] - Add brief description about the parameter in addition to the specification reference. [Sami] .../Include/Library/AmlLib/AmlLib.h | 272 +++++ .../AmlLib/CodeGen/AmlResourceDataCodeGen.c | 943 ++++++++++++++++++ 2 files changed, 1215 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index 4932f6fd9c8b..59811379c597 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -418,6 +418,278 @@ AmlUpdateRdQWord ( IN UINT64 BaseAddressLength ); =20 +/** Code generation for the "DWordIO ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.2 "DWord Address Space Descriptor". + - s19.6.34 "DWordIO". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.34 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] IsaRanges Possible values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] IsDenseTranslation TranslationDensity parameter. + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordIo ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT8 IsaRanges, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN BOOLEAN IsDenseTranslation, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + +/** Code generation for the "DWordMemory ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.2 "DWord Address Space Descriptor". + - s19.6.35 "DWordMemory". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.35 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and supports + write combining + 3-The memory is cacheable and prefetch= able + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordMemory ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + +/** Code generation for the "WordBusNumber ()" ASL function. + + The Resource Data effectively created is a Word Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.3 "Word Address Space Descriptor". + - s19.6.149 "WordBusNumber". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.149 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdWordBusNumber ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + +/** Code generation for the "QWordMemory ()" ASL function. + + The Resource Data effectively created is a QWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.1 "QWord Address Space Descriptor". + - s19.6.110 "QWordMemory". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.110 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and supports + write combining + 3-The memory is cacheable and prefetch= able + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdQWordMemory ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + /** Code generation for the "Interrupt ()" ASL function. =20 The Resource Data effectively created is an Extended Interrupt Resource diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceData= CodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataC= odeGen.c index 0bdb6c24c5bb..c385ac2645a2 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen= .c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen= .c @@ -100,6 +100,949 @@ error_handler: return Status; } =20 +/** Construct the TypeSpecificFlags field for IO ranges. + + See ACPI 6.4 spec, s19.6.34 for more. + + @param [in] IsaRanges Possible values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsDenseTranslation TranslationDensity parameter. + @param [in] IsTypeStatic TranslationType parameter. + + @return A type specific flags value. + MAX_UINT8 if error. +**/ +STATIC +UINT8 +EFIAPI +RdIoRangeSpecificFlags ( + IN UINT8 IsaRanges, + IN BOOLEAN IsDenseTranslation, + IN BOOLEAN IsTypeStatic + ) +{ + // Only check type specific parameters. + if (IsaRanges > 3) { + ASSERT (0); + return MAX_UINT8; + } + + // Construct TypeSpecificFlags and call the generic function. + // Cf ACPI 6.4 specification, Table 6.50: + // "Table 6.50: I/O Resource Flag (Resource Type =3D 1) Definitions" + return IsaRanges | + (IsTypeStatic ? 0 : BIT4) | + (IsDenseTranslation ? 0 : BIT5); +} + +/** Construct the TypeSpecificFlags field for Memory ranges. + + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and supports + write combining + 3-The memory is cacheable and prefetch= able + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsTypeStatic TranslationType parameter. + + @return A type specific flags value. + MAX_UINT8 if error. +**/ +STATIC +UINT8 +EFIAPI +MemoryRangeSpecificFlags ( + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic + ) +{ + // Only check type specific parameters. + if ((Cacheable > 3) || + (MemoryRangeType > 3)) { + ASSERT (0); + return MAX_UINT8; + } + + // Construct TypeSpecificFlags and call the generic function. + // Cf ACPI 6.4 specification, Table 6.49: + // "Memory Resource Flag (Resource Type =3D 0) Definitions" + return (IsReadWrite ? BIT0 : 0) | + (Cacheable << 1) | + (MemoryRangeType << 3) | + (IsTypeStatic ? 0 : BIT5); +} + +/** Construct the GeneralFlags field of any Address Space Resource Descrip= tors. + + E.g.: + ACPI 6.4 specification, s6.4.3.5.1 "QWord Address Space Descriptor" + for QWord + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + + @return A type specific flags value. +**/ +STATIC +UINT8 +EFIAPI +AddressSpaceGeneralFlags ( + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed + ) +{ + return (IsPosDecode ? 0 : BIT1) | + (IsMinFixed ? BIT2 : 0) | + (IsMaxFixed ? BIT3 : 0); +} + +/** Check Address Space Descriptor Fields. + + Cf. ACPI 6.4 Table 6.44: + "Valid Combination of Address Space Descriptor Fields" + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +CheckAddressSpaceFields ( + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength + ) +{ + if ((AddressMinimum > AddressMaximum) || + (RangeLength > (AddressMaximum - AddressMinimum + 1)) || + ((AddressGranularity !=3D 0) && + ((AddressGranularity + 1) & AddressGranularity) !=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (RangeLength !=3D 0) { + if (IsMinFixed ^ IsMaxFixed) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMinFixed && + IsMaxFixed && + (AddressGranularity !=3D 0) && + ((AddressMaximum - AddressMinimum + 1) !=3D RangeLength)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } else { + if (IsMinFixed && IsMaxFixed) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMinFixed && + ((AddressMinimum & AddressGranularity) !=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMaxFixed && + (((AddressMaximum + 1) & AddressGranularity) !=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +/** Code generation for the "DWordSpace ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.2 "DWord Address Space Descriptor". + - s19.6.36 "DWordSpace". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] ResourceType Resource type. + Possible values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + See ACPI 6.4 spec, s6.4.3.5.2 for more. + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] TypeSpecificFlags Type specific flags. + See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordSpace ( + IN UINT8 ResourceType, + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 TypeSpecificFlags, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE * RdNode; + EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR RdDWord; + + // ResourceSource and ResourceSourceIndex are unused. + if ((TypeSpecificFlags =3D=3D MAX_UINT8) || + (ResourceSourceIndex !=3D 0) || + (ResourceSource !=3D NULL) || + ((NameOpNode =3D=3D NULL) && (NewRdNode =3D=3D NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D CheckAddressSpaceFields ( + IsMinFixed, + IsMaxFixed, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Header + RdDWord.Header.Header.Bits.Name =3D + ACPI_LARGE_DWORD_ADDRESS_SPACE_DESCRIPTOR_NAME; + RdDWord.Header.Header.Bits.Type =3D ACPI_LARGE_ITEM_FLAG; + RdDWord.Header.Length =3D sizeof (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTO= R) - + sizeof (ACPI_LARGE_RESOURCE_HEADER); + + // Body + RdDWord.ResType =3D ResourceType; + RdDWord.GenFlag =3D AddressSpaceGeneralFlags ( + IsPosDecode, + IsMinFixed, + IsMaxFixed + ); + RdDWord.SpecificFlag =3D TypeSpecificFlags; + RdDWord.AddrSpaceGranularity =3D AddressGranularity; + RdDWord.AddrRangeMin =3D AddressMinimum; + RdDWord.AddrRangeMax =3D AddressMaximum; + RdDWord.AddrTranslationOffset =3D AddressTranslation; + RdDWord.AddrLen =3D RangeLength; + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8*)&RdDWord, + sizeof (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR), + &RdNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (RdNode, NameOpNode, NewRdNode); +} + +/** Code generation for the "DWordIO ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.2 "DWord Address Space Descriptor". + - s19.6.34 "DWordIO". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.34 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] IsaRanges Possible values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] IsDenseTranslation TranslationDensity parameter. + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordIo ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT8 IsaRanges, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN BOOLEAN IsDenseTranslation, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + return AmlCodeGenRdDWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_IO, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + RdIoRangeSpecificFlags ( + IsaRanges, + IsDenseTranslation, + IsTypeStatic + ), + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + +/** Code generation for the "DWordMemory ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.2 "DWord Address Space Descriptor". + - s19.6.35 "DWordMemory". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.35 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and supports + write combining + 3-The memory is cacheable and prefetch= able + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordMemory ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + return AmlCodeGenRdDWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_MEM, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + MemoryRangeSpecificFlags ( + Cacheable, + IsReadWrite, + MemoryRangeType, + IsTypeStatic + ), + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + +/** Code generation for the "WordSpace ()" ASL function. + + The Resource Data effectively created is a Word Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.3 "Word Address Space Descriptor". + - s19.6.151 "WordSpace". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.151 for more. + + @param [in] ResourceType Resource type. + Possible values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + See ACPI 6.4 spec, s6.4.3.5.3 for more. + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] TypeSpecificFlags Type specific flags. + See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenRdWordSpace ( + IN UINT8 ResourceType, + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 TypeSpecificFlags, + IN UINT16 AddressGranularity, + IN UINT16 AddressMinimum, + IN UINT16 AddressMaximum, + IN UINT16 AddressTranslation, + IN UINT16 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE * RdNode; + EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR Rdword; + + // ResourceSource and ResourceSourceIndex are unused. + if ((TypeSpecificFlags =3D=3D MAX_UINT8) || + (ResourceSourceIndex !=3D 0) || + (ResourceSource !=3D NULL) || + ((NameOpNode =3D=3D NULL) && (NewRdNode =3D=3D NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D CheckAddressSpaceFields ( + IsMinFixed, + IsMaxFixed, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Header + Rdword.Header.Header.Bits.Name =3D + ACPI_LARGE_WORD_ADDRESS_SPACE_DESCRIPTOR_NAME; + Rdword.Header.Header.Bits.Type =3D ACPI_LARGE_ITEM_FLAG; + Rdword.Header.Length =3D sizeof (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR)= - + sizeof (ACPI_LARGE_RESOURCE_HEADER); + + // Body + Rdword.ResType =3D ResourceType; + Rdword.GenFlag =3D AddressSpaceGeneralFlags ( + IsPosDecode, + IsMinFixed, + IsMaxFixed + ); + Rdword.SpecificFlag =3D TypeSpecificFlags; + Rdword.AddrSpaceGranularity =3D AddressGranularity; + Rdword.AddrRangeMin =3D AddressMinimum; + Rdword.AddrRangeMax =3D AddressMaximum; + Rdword.AddrTranslationOffset =3D AddressTranslation; + Rdword.AddrLen =3D RangeLength; + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8*)&Rdword, + sizeof (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR), + &RdNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (RdNode, NameOpNode, NewRdNode); +} + +/** Code generation for the "WordBusNumber ()" ASL function. + + The Resource Data effectively created is a Word Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.3 "Word Address Space Descriptor". + - s19.6.149 "WordBusNumber". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.149 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdWordBusNumber ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + // There is no Type Specific Flags for buses. + return AmlCodeGenRdWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_BUS, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + 0, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + +/** Code generation for the "QWordSpace ()" ASL function. + + The Resource Data effectively created is a QWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.1 "QWord Address Space Descriptor". + - s19.6.111 "QWordSpace". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.111 for more. + + @param [in] ResourceType Resource type. + Possible values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + See ACPI 6.4 spec, s6.4.3.5.1 for more. + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] TypeSpecificFlags Type specific flags. + See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenRdQWordSpace ( + IN UINT8 ResourceType, + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 TypeSpecificFlags, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE * RdNode; + EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR RdQword; + + // ResourceSource and ResourceSourceIndex are unused. + if ((TypeSpecificFlags =3D=3D MAX_UINT8) || + (ResourceSourceIndex !=3D 0) || + (ResourceSource !=3D NULL) || + ((NameOpNode =3D=3D NULL) && (NewRdNode =3D=3D NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D CheckAddressSpaceFields ( + IsMinFixed, + IsMaxFixed, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Header + RdQword.Header.Header.Bits.Name =3D + ACPI_LARGE_QWORD_ADDRESS_SPACE_DESCRIPTOR_NAME; + RdQword.Header.Header.Bits.Type =3D ACPI_LARGE_ITEM_FLAG; + RdQword.Header.Length =3D sizeof (EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTO= R) - + sizeof (ACPI_LARGE_RESOURCE_HEADER); + + // Body + RdQword.ResType =3D ResourceType; + RdQword.GenFlag =3D AddressSpaceGeneralFlags ( + IsPosDecode, + IsMinFixed, + IsMaxFixed + ); + RdQword.SpecificFlag =3D TypeSpecificFlags; + RdQword.AddrSpaceGranularity =3D AddressGranularity; + RdQword.AddrRangeMin =3D AddressMinimum; + RdQword.AddrRangeMax =3D AddressMaximum; + RdQword.AddrTranslationOffset =3D AddressTranslation; + RdQword.AddrLen =3D RangeLength; + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8*)&RdQword, + sizeof (EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR), + &RdNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (RdNode, NameOpNode, NewRdNode); +} + +/** Code generation for the "QWordMemory ()" ASL function. + + The Resource Data effectively created is a QWord Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.1 "QWord Address Space Descriptor". + - s19.6.110 "QWordMemory". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL statem= ent + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.110 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and supports + write combining + 3-The memory is cacheable and prefetch= able + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named ob= ject. + If provided, append the new resource d= ata + node to the list of resource data elem= ents + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdQWordMemory ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + return AmlCodeGenRdQWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_MEM, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + MemoryRangeSpecificFlags ( + Cacheable, + IsReadWrite, + MemoryRangeType, + IsTypeStatic + ), + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + /** Code generation for the "Interrupt ()" ASL function. =20 The Resource Data effectively created is an Extended Interrupt Resource --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81753): https://edk2.groups.io/g/devel/message/81753 Mute This Topic: https://groups.io/mt/86241741/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81756+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81756+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970741; cv=none; d=zohomail.com; s=zohoarc; b=bZTfqKBidT8vfgwspOWDdwDKlYwdEr6GQVCpNq+LYU0kRS6lCt9szWU3rp6XqjmOxk24qlw7D88y1FGtqRsa9j2kt9y/EOPh85XlZyWxkSqtR9JibBkuwFoBpgMEQ6v+GL6xrmNc0nuyJ6VqJmhLVu9ReTDhLIlPDqJ1imbWI+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970741; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=7SJAMsvBohsV0+xMPh2PKydQjW3ZiJCt6RHPjX/nBuY=; b=A9AyndDzZh81ABVl0WiJOe0e4fOnKyajISadLDoWitQQN4MHz64GNZ0LVzRHxn0oUGw4yshtblb93Xd+M14NzGSuErppyi8r1oHnA+rAaKCrFds8IVKD7bSaVHAEF1zylusqMfARhoyCh4eopdvHZkHTy3YmpBgLcrfUYnQ0Eko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81756+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633970741261814.7559371556267; Mon, 11 Oct 2021 09:45:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BZFIYY1788612xrFlU2g3YEM; Mon, 11 Oct 2021 09:45:40 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.1051.1633970738600170732 for ; Mon, 11 Oct 2021 09:45:39 -0700 X-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 A7CC7106F; Mon, 11 Oct 2021 09:45:33 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9DBA33F66F; Mon, 11 Oct 2021 09:45:32 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 2/7] DynamicTablesPkg: AML Code generation to create a named Package() Date: Mon, 11 Oct 2021 17:45:22 +0100 Message-Id: <20211011164527.18660-3-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: a7Uq4CV7MVspFk21VXVGBhWlx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970740; bh=IOPSzoSt62LwoJKHmNErL8x9kfHy4UxRH68qa0htPfI=; h=Date:From:Reply-To:Subject:To; b=hZ1mC9z5YMVyHdmJ1ojM7B7mRdSszSdhRp81NfwnVQtXZ4rQsTDHD2HL2qCsN2e7w8R yHYLSS6ZYEofjTZmibjXFcB1nb957MYlpjwEji8EsgIJ4ZdYNHh6n/RwmTcJVuS6mfEvr VxEZVDzJtsdUhmRWE5cn0OSEx6BQxIX7F4o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970741876100009 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add AmlCodeGenNamePackage() to generate code for a Package(). AmlCodeGenNamePackage ("PACK", ParentNode, NewObjectNode) is equivalent of the following ASL code: Name(PACK, Package () {}) To: Sami Mujawar To: Alexei Fedorov Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../Include/Library/AmlLib/AmlLib.h | 28 ++++++++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 55 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index 59811379c597..d2e9cbe26d75 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -835,6 +835,34 @@ AmlCodeGenNameInteger ( OUT AML_OBJECT_NODE_HANDLE * NewObjectNode OPTIONAL ); =20 +/** AML code generation for a Name object node, containing a Package. + + AmlCodeGenNamePackage ("PKG0", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Name(PKG0, Package () {}) + + @ingroup CodeGenApis + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenNamePackage ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HANDLE ParentNode, OPTIONAL + OUT AML_OBJECT_NODE_HANDLE * NewObjectNode OPTIONAL + ); + /** 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 64064018aecb..1ba75fbd6f12 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -746,6 +746,61 @@ AmlCodeGenNameInteger ( return Status; } =20 +/** AML code generation for a Name object node, containing a Package. + + AmlCodeGenNamePackage ("PKG0", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Name(PKG0, Package () {}) + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenNamePackage ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * PackageNode; + + if ((NameString =3D=3D NULL) || + ((ParentNode =3D=3D NULL) && (NewObjectNode =3D=3D NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D AmlCodeGenPackage (&PackageNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D AmlCodeGenName ( + NameString, + PackageNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)PackageNode); + } + + return Status; +} + /** AML code generation for a Device object node. =20 AmlCodeGenDevice ("COM0", ParentNode, NewObjectNode) is --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81756): https://edk2.groups.io/g/devel/message/81756 Mute This Topic: https://groups.io/mt/86241744/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81754+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81754+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970739; cv=none; d=zohomail.com; s=zohoarc; b=ado6lX7LKHk0J7e83FXVNqpjsvbk8vu78neEsfWjoqBT/aLkbb45uYu0V6Ehat0lPtCQr48ipTVDo4Sz/9NeJwVH+1QKpKTu+XnBkjMmdm+3fVfGWVxeTvueLlO3aGSCBT2J6M84+z+qUMVGHXY3JoPC23RnBasnFLy7c+64RyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970739; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZzWlivjKvypLqVKFAGp3DmTwwIDl/dr4lQKhOHC9yIw=; b=nF+QL+5CqLWwUHaBxVh+1i/dJHx0snmIXZf9F79DxC+qz4Ik0za96r0nLpT9KlPWYNxL/qtEKUt/4C9IODXw1YdutvKubuw2HHExjt5XqoW7IKh7U6AVdd1xt06AL+vTrn19sMyu1AmXvBfqpiNE+6IbPHjWfqx5Vx+r7847MIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81754+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633970739916708.244159488151; Mon, 11 Oct 2021 09:45:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id R9yRYY1788612xasfF91zVyL; Mon, 11 Oct 2021 09:45:39 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.1011.1633970738600234337 for ; Mon, 11 Oct 2021 09:45:38 -0700 X-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 1D48C11D4; Mon, 11 Oct 2021 09:45:35 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 131B53F66F; Mon, 11 Oct 2021 09:45:33 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 3/7] DynamicTablesPkg: AML Code generation to create a named ResourceTemplate() Date: Mon, 11 Oct 2021 17:45:23 +0100 Message-Id: <20211011164527.18660-4-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: wa33TsFMMV8BWjkXTt9a8tqHx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970739; bh=5UWd316ALSY0m5OpWyO4ScS8LbCo/JynCmaqgKIHvIg=; h=Date:From:Reply-To:Subject:To; b=S+4Fg9EWTmZjrKVWCOGZTPvYB7f4wwEat1R27vkkl6ksoG0os7EEro2WZ4EJNnPtdqa Bh52UWD0io0qjpmlkZzPY4LLRgNWtRrwwT5w804t1oeH+tAX+1ntSgiQzscX1HOkP+CNm mDWIRKZNgqQlPOpmT+HM7ndTcIV5x++cHjI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970741621100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add AmlCodeGenNameResourceTemplate() to generate code for a ResourceTemplate(). AmlCodeGenNameResourceTemplate ("REST", ParentNode, NewObjectNode) is equivalent of the following ASL code: Name(REST, ResourceTemplate () {}) To: Sami Mujawar To: Alexei Fedorov Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../Include/Library/AmlLib/AmlLib.h | 28 ++++++++++ .../Common/AmlLib/CodeGen/AmlCodeGen.c | 55 +++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index d2e9cbe26d75..763e2ce7d268 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -863,6 +863,34 @@ AmlCodeGenNamePackage ( OUT AML_OBJECT_NODE_HANDLE * NewObjectNode OPTIONAL ); =20 +/** AML code generation for a Name object node, containing a ResourceTempl= ate. + + AmlCodeGenNameResourceTemplate ("PRS0", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Name(PRS0, ResourceTemplate () {}) + + @ingroup CodeGenApis + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenNameResourceTemplate ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HANDLE ParentNode, OPTIONAL + OUT AML_OBJECT_NODE_HANDLE * NewObjectNode OPTIONAL + ); + /** 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 1ba75fbd6f12..8f48f214648f 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -801,6 +801,61 @@ AmlCodeGenNamePackage ( return Status; } =20 +/** AML code generation for a Name object node, containing a ResourceTempl= ate. + + AmlCodeGenNameResourceTemplate ("PRS0", ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Name(PRS0, ResourceTemplate () {}) + + @param [in] NameString The new variable name. + Must be a NULL-terminated ASL NameString + e.g.: "DEV0", "DV15.DEV0", etc. + The input string is copied. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + @param [out] NewObjectNode If success, contains the created node. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenNameResourceTemplate ( + IN CONST CHAR8 * NameString, + IN AML_NODE_HEADER * ParentNode, OPTIONAL + OUT AML_OBJECT_NODE ** NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE * ResourceTemplateNode; + + if ((NameString =3D=3D NULL) || + ((ParentNode =3D=3D NULL) && (NewObjectNode =3D=3D NULL))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D AmlCodeGenResourceTemplate (&ResourceTemplateNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D AmlCodeGenName ( + NameString, + ResourceTemplateNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + AmlDeleteTree ((AML_NODE_HEADER*)ResourceTemplateNode); + } + + return Status; +} + /** AML code generation for a Device object node. =20 AmlCodeGenDevice ("COM0", ParentNode, NewObjectNode) is --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81754): https://edk2.groups.io/g/devel/message/81754 Mute This Topic: https://groups.io/mt/86241742/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81760+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81760+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970743; cv=none; d=zohomail.com; s=zohoarc; b=g939tZ3Kb2wtD0StsPa3VirMWxAdesrBSIx+TxZxw57bdWBvZt2tWWCVdgjBXuHHs9WTkoF836mssPpUw3UbQwzN2K3TRIBsSncwqc0IpVtOwkBu11mFUxs8X3yDeXYhcIZGTtV+vRmlhAQn8VlOpqQV+xoC3GS1PuxOhnYA7zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970743; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=xCy+LZKDzXc/7RyPHOEgaXI271pILd4EQ/dWwsz3C0Q=; b=aNNWvoGXtnZfc87/FnH7OGC4zwjYw8nSOsgUu8ENRu4f941AO6SyHlaoK9L7t62yn1tFONQxQ2/F4sM8SfWYisLUuTiUT18oT9uIwKK872+3AScXFmop7D9kVSR1ylGtG+mNxd2y2uWJ5LhAYVZ7SmjlgdVgTW+MmivpQa1FSu8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81760+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633970743322356.2929347012257; Mon, 11 Oct 2021 09:45:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id rJ5BYY1788612xR49Pae3MI8; Mon, 11 Oct 2021 09:45:43 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1049.1633970742032536247 for ; Mon, 11 Oct 2021 09:45:42 -0700 X-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 87C2911FB; Mon, 11 Oct 2021 09:45:36 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7D00E3F66F; Mon, 11 Oct 2021 09:45:35 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 4/7] DynamicTablesPkg: AML Code generation to add _PRT entries Date: Mon, 11 Oct 2021 17:45:24 +0100 Message-Id: <20211011164527.18660-5-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: VwheH5P8Ry1Cpp2w28rZO0Lxx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970743; bh=5F+GcGrAzcagWfZF8pWRIvK1vYxzEnSfpILnad4KZMw=; h=Date:From:Reply-To:Subject:To; b=juMTweHHrLboxV3CWO+bkL+EmAOBNeE/XdbtOXv6B9z4U6HIorYWJ5r4LJLo/X83iGu ZSeA2A+micplGZtmxZ/lbu8JmwSmBd+E5NSNiYnWv/ZAwjB9gcajEybDJPunQk6HfD+Is WjNO8Mf1FXebbRk+TUGofNEWKGoG3dNowDw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970744395100026 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 | 210 ++++++++++++++++++ 2 files changed, 262 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index 763e2ce7d268..aef5f55ce319 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 interrupt + // 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 0x00030002). + 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-I= NTD). + Must be between 0-3. + @param [in] LinkName Link Name, i.e. device in the AML NameSpace + 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 8f48f214648f..5f2b39305540 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -856,6 +856,216 @@ 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 interrupt + // 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 0x00030002). + 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-I= NTD). + Must be between 0-3. + @param [in] LinkName Link Name, i.e. device in the AML NameSpace + 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 EAmlNodeObject)= || + (!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.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81760): https://edk2.groups.io/g/devel/message/81760 Mute This Topic: https://groups.io/mt/86241749/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81758+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81758+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970742; cv=none; d=zohomail.com; s=zohoarc; b=K/ediqDv+jWU2dyNFPnBlbQv3f7fEd1D39nLeV766C5263iJgAVrFJzBAsRBqFwazycQS0pTVZVBHSEX2JtcNkQ4hu27/iS0zHSNM1DuXIshQF9nRUX36P5/pxaog8jxWV3Ij6xwKB9UyJr4m1z3aDbM7LMGlRA3k9thNJZL9rM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970742; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=vteON/Aw2Hkaf889jl0q7ckng3MwAcrEzALR2O1vPeU=; b=U6pojTON9l9E02wsCSkyKJZpRuyEB8skHwFat2Is5Ay3EH0mDHkBid7yt0bL5zC7pp0nWkD//0tJCGus3lnxEwIacHnXcEFZjQsOni8rwgo8PjUn5sT8isu7TyTOI9LgboHtTLAwO6reezGaqrTE8NCveTo4Jvc2fVgJDC6jf2g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81758+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163397074214241.72486085776973; Mon, 11 Oct 2021 09:45:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UijnYY1788612xlKICdf0mHq; Mon, 11 Oct 2021 09:45:41 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.988.1633970739811441904 for ; Mon, 11 Oct 2021 09:45:40 -0700 X-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 F0E141396; Mon, 11 Oct 2021 09:45:37 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DC39A3F66F; Mon, 11 Oct 2021 09:45:36 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 5/7] DynamicTablesPkg: Add AmlAttachNode() Date: Mon, 11 Oct 2021 17:45:25 +0100 Message-Id: <20211011164527.18660-6-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: hc2Zvej7FVWf0zXJ3D30UxIyx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970741; bh=Z/H4+QG4nADrR6OgCBmZlvqaRuayRh9cub96duWWEIA=; h=Date:From:Reply-To:Subject:To; b=vvRXXGc4nyUHJG6PKwsdLG0AGo438XR5M4J4Ls6pckKkIZ7fUF2RkRz+OlQX5w3C+1K W5KkN/74HI9OWxF0d2hgXMKG8E4SnlkEEFmlmSst2beaZYuWNzqWVHiAxE1KQN+6J5AWk G2ATLxkbV9bDt+6V/3gZg4na2yjwYOKYqNM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970744028100022 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois This function allows to add a node as the last node of a parent node in an AML tree. For instance, ASL code corresponding to NewNode: Name (_UID, 0) ASL code corresponding to ParentNode: Device (PCI0) { Name(_HID, EISAID("PNP0A08")) } "AmlAttachNode (ParentNode, NewNode)" will result in: ASL code: Device (PCI0) { Name(_HID, EISAID("PNP0A08")) Name (_UID, 0) } To: Sami Mujawar To: Alexei Fedorov Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../Include/Library/AmlLib/AmlLib.h | 33 +++++++++++++++++ .../Library/Common/AmlLib/Api/AmlApi.c | 36 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index aef5f55ce319..15517b5efac1 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -166,6 +166,39 @@ AmlDetachNode ( IN AML_NODE_HANDLE Node ); =20 +/** Attach a node in an AML tree. + + The node will be added as the last statement of the ParentNode. + E.g.: + ASL code corresponding to NewNode: + Name (_UID, 0) + + ASL code corresponding to ParentNode: + Device (PCI0) { + Name(_HID, EISAID("PNP0A08")) + } + + "AmlAttachNode (ParentNode, NewNode)" will result in: + ASL code: + Device (PCI0) { + Name(_HID, EISAID("PNP0A08")) + Name (_UID, 0) + } + + @param [in] ParentNode Pointer to the parent node. + Must be a root or an object node. + @param [in] NewNode Pointer to the node to add. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AmlAttachNode ( + IN AML_NODE_HANDLE ParentNode, + IN AML_NODE_HANDLE NewNode + ); + /** Find a node in the AML namespace, given an ASL path and a reference No= de. =20 - The AslPath can be an absolute path, or a relative path from the diff --git a/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlApi.c b/DynamicT= ablesPkg/Library/Common/AmlLib/Api/AmlApi.c index 6f9e3f6f2805..def581299f5c 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlApi.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/Api/AmlApi.c @@ -379,6 +379,42 @@ AmlNameOpGetNextRdNode ( return EFI_SUCCESS; } =20 +/** Attach a node in an AML tree. + + The node will be added as the last statement of the ParentNode. + E.g.: + ASL code corresponding to NewNode: + Name (_UID, 0) + + ASL code corresponding to ParentNode: + Device (PCI0) { + Name(_HID, EISAID("PNP0A08")) + } + + "AmlAttachNode (ParentNode, NewNode)" will result in: + ASL code: + Device (PCI0) { + Name(_HID, EISAID("PNP0A08")) + Name (_UID, 0) + } + + @param [in] ParentNode Pointer to the parent node. + Must be a root or an object node. + @param [in] NewNode Pointer to the node to add. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AmlAttachNode ( + IN AML_NODE_HANDLE ParentNode, + IN AML_NODE_HANDLE NewNode + ) +{ + return AmlVarListAddTail (ParentNode, NewNode); +} + // DEPRECATED APIS #ifndef DISABLE_NEW_DEPRECATED_INTERFACES =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81758): https://edk2.groups.io/g/devel/message/81758 Mute This Topic: https://groups.io/mt/86241747/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81757+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81757+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970741; cv=none; d=zohomail.com; s=zohoarc; b=JVG29ggifBw9x71BHQ70QAMugNZkuYBO6CZe1twMoV8UsI21Cy15hH1YTWREDh8m1VdK6o3RLaH+CPkHfVhzaSCSkTLhkuHADn58qpHS58QXLx3WzYn0alDX/FpMGv6HiDoUCXdH5HgVPyzZL+5zEoOQT4iwG0I+yzzCQZZZBM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970741; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=3e3f7W83pX41HyDjWQQj7N4RRbumTaGrBm0xMF9dAOk=; b=f121LHcK2mBx0FDEOUxpN/uRr7mlLBwTGPvhZRwY9BabO2523LKZBfQqZv91JsNDPInr1VJipjpIWafMp/mY8E827KqykHNJ70qSA8vhGkuOwBrmt2kC3Fy1GBMBteEQ30YkMYSEkMjBzPdhcX7556PDgVBRLhNqF1Oj5rczwCM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81757+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163397074166157.53068104381998; Mon, 11 Oct 2021 09:45:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MD22YY1788612xAXaHubT9cb; Mon, 11 Oct 2021 09:45:41 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.987.1633970739729041997 for ; Mon, 11 Oct 2021 09:45:39 -0700 X-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 66BBEED1; Mon, 11 Oct 2021 09:45:39 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5CCF13F66F; Mon, 11 Oct 2021 09:45:38 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 6/7] DynamicTablesPkg: Add Pci related objects Date: Mon, 11 Oct 2021 17:45:26 +0100 Message-Id: <20211011164527.18660-7-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: x9cwrnVM5ik9StJek7PE9lPgx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970741; bh=eBjVOWhBgJVq/Eq1i4HMSY52jIdC1ZfKLX5K3aRExoQ=; h=Date:From:Reply-To:Subject:To; b=GlGFK25H49L7H5xvU4VmxLdKS4PRsn2vSDcIZdohQyOptlJrONhKhpTJb6EzDq9j4VV f9QNf2/+8QVGi67WM62PbqdV6hY5TPfbz7UeAf8v/vk3wB5sVeDu0TLJMft/7tgIaV3Vz AT74zjceRQGfFvszTa6Q/jDZto4DUQbcJ7s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970743873100018 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Introduce the following CmObj in the ArmNameSpaceObjects: - CM_ARM_PCI_ADDRESS_MAP_INFO - CM_ARM_PCI_INTERRUPT_MAP_INFO These objects allow to describe address range mapping of Pci busses and interrupt mapping of Pci devices. To: Sami Mujawar To: Alexei Fedorov Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../Include/ArmNameSpaceObjects.h | 78 +++++++++++++++++++ .../ConfigurationManagerObjectParser.c | 28 ++++++- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Include/ArmNameSpaceObjects.h b/DynamicTables= Pkg/Include/ArmNameSpaceObjects.h index f19c9c706669..ac19fa1f6e6c 100644 --- a/DynamicTablesPkg/Include/ArmNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/ArmNameSpaceObjects.h @@ -59,6 +59,8 @@ typedef enum ArmObjectID { EArmObjSerialPortInfo, ///< 35 - Generic Serial Port Info EArmObjCmn600Info, ///< 36 - CMN-600 Info EArmObjLpiInfo, ///< 37 - Lpi Info + EArmObjPciAddressMapInfo, ///< 38 - Pci Address Map Info + EArmObjPciInterruptMapInfo, ///< 39 - Pci Interrupt Map Info EArmObjMax } EARM_OBJECT_ID; =20 @@ -433,6 +435,14 @@ typedef struct CmArmPciConfigSpaceInfo { =20 /// The end bus number UINT8 EndBusNumber; + + /// Optional field: Reference Token for address mapping. + /// Token identifying a CM_ARM_OBJ_REF structure. + CM_OBJECT_TOKEN AddressMapToken; + + /// Optional field: Reference Token for interrupt mapping. + /// Token identifying a CM_ARM_OBJ_REF structure. + CM_OBJECT_TOKEN InterruptMapToken; } CM_ARM_PCI_CONFIG_SPACE_INFO; =20 /** A structure that describes the @@ -666,6 +676,10 @@ typedef struct CmArmGenericInterrupt { UINT32 Interrupt; =20 /// Flags + /// BIT0: 0: Interrupt is Level triggered + /// 1: Interrupt is Edge triggered + /// BIT1: 0: Interrupt is Active high + /// 1: Interrupt is Active low UINT32 Flags; } CM_ARM_GENERIC_INTERRUPT; =20 @@ -946,6 +960,70 @@ typedef struct CmArmLpiInfo { CHAR8 StateName[16]; } CM_ARM_LPI_INFO; =20 +/** A structure that describes a PCI Address Map. + + The memory-ranges used by the PCI bus are described by this object. + + ID: EArmObjPciAddressMapInfo +*/ +typedef struct CmArmPciAddressMapInfo { + /** Pci address space code + + Available values are: + - 0: Configuration Space + - 1: I/O Space + - 2: 32-bit-address Memory Space + - 3: 64-bit-address Memory Space + */ + UINT8 SpaceCode; + + /// PCI address + UINT64 PciAddress; + + /// Cpu address + UINT64 CpuAddress; + + /// Address size + UINT64 AddressSize; +} CM_ARM_PCI_ADDRESS_MAP_INFO; + +/** A structure that describes a PCI Interrupt Map. + + The legacy PCI interrupts used by PCI devices are described by this obje= ct. + + Cf Devicetree Specification - Release v0.3 + s2.4.3 "Interrupt Nexus Properties" + + ID: EArmObjPciInterruptMapInfo +*/ +typedef struct CmArmPciInterruptMapInfo { + /// Pci Bus. + /// Value on 8 bits (max 255). + UINT8 PciBus; + + /// Pci Bus. + /// Value on 5 bits (max 31). + UINT8 PciDevice; + + /** PCI interrupt + + ACPI bindings are used: + Cf. ACPI 6.4, s6.2.13 _PRT (PCI Routing Table): + "0-INTA, 1-INTB, 2-INTC, 3-INTD" + + Device-tree bindings are shifted by 1: + "INTA=3D1, INTB=3D2, INTC=3D3, INTD=3D4" + */ + UINT8 PciInterrupt; + + /** Interrupt controller interrupt. + + Cf Devicetree Specification - Release v0.3 + s2.4.3 "Interrupt Nexus Properties": "parent interrupt specifier" + */ + CM_ARM_GENERIC_INTERRUPT IntcInterrupt; +} CM_ARM_PCI_INTERRUPT_MAP_INFO; + #pragma pack() =20 #endif // ARM_NAMESPACE_OBJECTS_H_ diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationMa= nagerObjectParser.c b/DynamicTablesPkg/Library/Common/TableHelperLib/Config= urationManagerObjectParser.c index 2337d47e3fb3..48ddc2c58c3d 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerOb= jectParser.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationManagerOb= jectParser.c @@ -152,7 +152,9 @@ STATIC CONST CM_OBJ_PARSER CmArmPciConfigSpaceInfoParse= r[] =3D { {"BaseAddress", 8, "0x%llx", NULL}, {"PciSegmentGroupNumber", 2, "0x%x", NULL}, {"StartBusNumber", 1, "0x%x", NULL}, - {"EndBusNumber", 1, "0x%x", NULL} + {"EndBusNumber", 1, "0x%x", NULL}, + {"AddressMapToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL}, + {"InterruptMapToken", sizeof (CM_OBJECT_TOKEN), "0x%p", NULL}, }; =20 /** A parser for EArmObjHypervisorVendorIdentity. @@ -401,6 +403,26 @@ STATIC CONST CM_OBJ_PARSER CmArmLpiInfoParser[] =3D { {"StateName", 16, "0x%a", NULL}, }; =20 +/** A parser for EArmObjPciAddressMapInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmArmPciAddressMapInfoParser[] =3D { + {"SpaceCode", 1, "%d", NULL}, + {"PciAddress", 8, "0x%llx", NULL}, + {"CpuAddress", 8, "0x%llx", NULL}, + {"AddressSize", 8, "0x%llx", NULL}, +}; + +/** A parser for EArmObjPciInterruptMapInfo. +*/ +STATIC CONST CM_OBJ_PARSER CmPciInterruptMapInfoParser[] =3D { + {"PciBus", 1, "0x%x", NULL}, + {"PciDevice", 1, "0x%x", NULL}, + {"PciInterrupt", 1, "0x%x", NULL}, + {"IntcInterrupt", sizeof (CM_ARM_GENERIC_INTERRUPT), + NULL, NULL, CmArmGenericInterruptParser, + ARRAY_SIZE (CmArmGenericInterruptParser)}, +}; + /** A parser for Arm namespace objects. */ STATIC CONST CM_OBJ_PARSER_ARRAY ArmNamespaceObjectParser[] =3D { @@ -475,6 +497,10 @@ STATIC CONST CM_OBJ_PARSER_ARRAY ArmNamespaceObjectPar= ser[] =3D { ARRAY_SIZE (CmArmCmn600InfoParser)}, {"EArmObjLpiInfo", CmArmLpiInfoParser, ARRAY_SIZE (CmArmLpiInfoParser)}, + {"EArmObjPciAddressMapInfo", CmArmPciAddressMapInfoParser, + ARRAY_SIZE (CmArmPciAddressMapInfoParser)}, + {"EArmObjPciInterruptMapInfo", CmPciInterruptMapInfoParser, + ARRAY_SIZE (CmPciInterruptMapInfoParser)}, {"EArmObjMax", NULL, 0}, }; =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81757): https://edk2.groups.io/g/devel/message/81757 Mute This Topic: https://groups.io/mt/86241746/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 23 10:00:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81759+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81759+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1633970742; cv=none; d=zohomail.com; s=zohoarc; b=R+etx0J7kXYMKUb0FO4bXh++F78GFKGGZP0xX7ZAGAC1utz8nvTaxUnhahYID6Qf3aCjlvgfNLiv6Kq4s7nC97oQawEO46h1+vkYwOxMIs/O7A/m3TMNAcKaRL1puygw7Wfjy2u4n0cRjJJmrVB8xMyVF4ELp+kop3lmKvbbTi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633970742; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=DHEJ9KFbRe3S5gPjWJ2usgpscwmsoErO0d4pJp6YsnE=; b=J1PXSQVnyuL2Q19uICa8pD9vveYs1/emTA1s0CEpT9cN3+mpNpcwmm5HLD6NrNtIhnzO/jwwTTK4Hacyj3bsnF0EO7gODhNYUgJFSB2H6K7zaDxlSrhzG7wZIhl9VP5d6jGEgzTLJP8MMdWkzzVXngqbdbgetVmrTthhXX/800Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81759+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1633970742505599.1938448027777; Mon, 11 Oct 2021 09:45:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id b7koYY1788612xUDw1jH8SVY; Mon, 11 Oct 2021 09:45:42 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.987.1633970739729041997 for ; Mon, 11 Oct 2021 09:45:41 -0700 X-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 CA745ED1; Mon, 11 Oct 2021 09:45:40 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.74.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C6D923F66F; Mon, 11 Oct 2021 09:45:39 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Subject: [edk2-devel] [PATCH v2 7/7] DynamicTablesPkg: SSDT Pci express generator Date: Mon, 11 Oct 2021 17:45:27 +0100 Message-Id: <20211011164527.18660-8-Pierre.Gondois@arm.com> In-Reply-To: <20211011164527.18660-1-Pierre.Gondois@arm.com> References: <20211011164527.18660-1-Pierre.Gondois@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: IaTSGYGF7AUYoAsDj2sKlJg4x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1633970742; bh=5UZYVY/U0l5boPwn/kFZIq6n57+RaRJBKxMjGpLiE8A=; h=Date:From:Reply-To:Subject:To; b=RikeIkJj7FVDRIox5DhqyMeD70PAg1tWLQvqUjLrdkxYM4f4k3A2c2bKxyCafNSwMVQ TWBjfAXDY6fTwNxGcy+66J/d9+GwMyACQH6hwC5mu1TT19NuYyE9kf6opt1nPTxMXV5+s pXl4HGDusNnrw+TD42AiNLssDMOp2nSxM5o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1633970744435100028 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois This generator allows to generate a SSDT table describing a Pci express Bus. It uses the following CmObj: - EArmObjCmRef - EArmObjPciConfigSpaceInfo - EArmObjPciAddressMapInfo - EArmObjPciInterruptMapInfo REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3682 To: Sami Mujawar To: Alexei Fedorov Signed-off-by: Pierre Gondois --- Notes: v2: - Various error handling/typo/comments modifications. [Sami] - Use the Oem information provided by the configuration manager. [Sami] - Remove generation of _SRS and _PRS objects. [Sami] - An explanation of the meaning of SS in PCI_SS_... is given, but this matchs bits in a specification and not hard accronym. [Sami] - Modify code generation to generate LNKx devices in increasing order and before the _PRT object. [Pierre] DynamicTablesPkg/DynamicTables.dsc.inc | 2 + DynamicTablesPkg/Include/AcpiTableGenerator.h | 5 + .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.c | 1448 +++++++++++++++++ .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.h | 138 ++ .../Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf | 32 + .../SsdtPcieOscTemplate.asl | 80 + 6 files changed, 1705 insertions(+) create mode 100644 DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/Ss= dtPcieGenerator.c create mode 100644 DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/Ss= dtPcieGenerator.h create mode 100644 DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/Ss= dtPcieLibArm.inf create mode 100644 DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/Ss= dtPcieOscTemplate.asl diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/Dyna= micTables.dsc.inc index 292215c39456..60bcf4b199e8 100644 --- a/DynamicTablesPkg/DynamicTables.dsc.inc +++ b/DynamicTablesPkg/DynamicTables.dsc.inc @@ -39,6 +39,7 @@ [Components.common] =20 # AML Codegen DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCpuTopologyLibArm/SsdtCpuTopol= ogyLibArm.inf + DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf =20 # # Dynamic Table Factory Dxe @@ -62,6 +63,7 @@ [Components.common] =20 # AML Codegen NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtCpuTopologyLibArm/Ssd= tCpuTopologyLibArm.inf + NULL|DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLi= bArm.inf } =20 # diff --git a/DynamicTablesPkg/Include/AcpiTableGenerator.h b/DynamicTablesP= kg/Include/AcpiTableGenerator.h index 45c808ba740d..58ec941f2a35 100644 --- a/DynamicTablesPkg/Include/AcpiTableGenerator.h +++ b/DynamicTablesPkg/Include/AcpiTableGenerator.h @@ -67,6 +67,10 @@ The Dynamic Tables Framework implements the following AC= PI table generators: The SSDT Cpu-Topology generator collates the cpu and LPI information from the Configuration Manager and generates a SSDT table describing the CPU hierarchy. + - SSDT Pci-Express: + The SSDT Pci Express generator collates the Pci Express + information from the Configuration Manager and generates a + SSDT table describing a Pci Express bus. */ =20 /** The ACPI_TABLE_GENERATOR_ID type describes ACPI table generator ID. @@ -93,6 +97,7 @@ typedef enum StdAcpiTableId { EStdAcpiTableIdSsdtSerialPort, ///< SSDT Serial-Port Gene= rator EStdAcpiTableIdSsdtCmn600, ///< SSDT Cmn-600 Generator EStdAcpiTableIdSsdtCpuTopology, ///< SSDT Cpu Topology + EStdAcpiTableIdSsdtPciExpress, ///< SSDT Pci Express Gene= rator EStdAcpiTableIdMax } ESTD_ACPI_TABLE_ID; =20 diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.c new file mode 100644 index 000000000000..3cbe78fc4335 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c @@ -0,0 +1,1448 @@ +/** @file + SSDT Pcie Table Generator. + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - PCI Firmware Specification - Revision 3.0 + - ACPI 6.4 specification: + - s6.2.13 "_PRT (PCI Routing Table)" + - s6.1.1 "_ADR (Address)" + - linux kernel code + - Arm Base Boot Requirements v1.0 +**/ + +#include +#include +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include +#include + +#include "SsdtPcieGenerator.h" + +/** ARM standard SSDT Pcie Table Generator. + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArmObjCmRef + - EArmObjPciConfigSpaceInfo + - EArmObjPciAddressMapInfo + - EArmObjPciInterruptMapInfo +*/ + +/** This macro expands to a function that retrieves the cross-CM-object- + reference information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjCmRef, + CM_ARM_OBJ_REF + ); + +/** This macro expands to a function that retrieves the Pci + Configuration Space Information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjPciConfigSpaceInfo, + CM_ARM_PCI_CONFIG_SPACE_INFO + ); + +/** This macro expands to a function that retrieves the Pci + Address Mapping Information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjPciAddressMapInfo, + CM_ARM_PCI_ADDRESS_MAP_INFO + ); + +/** This macro expands to a function that retrieves the Pci + Interrupt Mapping Information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjPciInterruptMapInfo, + CM_ARM_PCI_INTERRUPT_MAP_INFO + ); + +/** Initialize the MappingTable. + + @param [in] MappingTable The mapping table structure. + @param [in] Count Number of entries to allocate in the + MappingTable. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +MappingTableInitialize ( + IN MAPPING_TABLE * MappingTable, + IN UINT32 Count + ) +{ + UINT32 * Table; + + if ((MappingTable =3D=3D NULL) || + (Count =3D=3D 0)) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Table =3D AllocateZeroPool (sizeof (*Table) * Count); + if (Table =3D=3D NULL) { + ASSERT (0); + return EFI_OUT_OF_RESOURCES; + } + + MappingTable->Table =3D Table; + MappingTable->LastIndex =3D 0; + MappingTable->MaxIndex =3D Count; + + return EFI_SUCCESS; +} + +/** Free the MappingTable. + + @param [in, out] MappingTable The mapping table structure. +**/ +STATIC +VOID +EFIAPI +MappingTableFree ( + IN OUT MAPPING_TABLE * MappingTable + ) +{ + ASSERT (MappingTable !=3D NULL); + ASSERT (MappingTable->Table !=3D NULL); + + if (MappingTable->Table !=3D NULL) { + FreePool (MappingTable->Table); + } +} + +/** Add a new entry to the MappingTable and return its index. + + If an entry with [Integer] is already available in the table, + return its index without adding a new entry. + + @param [in] MappingTable The mapping table structure. + @param [in] Integer New Integer entry to add. + + @retval The index of the Integer entry in the MappingTable. +**/ +STATIC +UINT32 +EFIAPI +MappingTableAdd ( + IN MAPPING_TABLE * MappingTable, + IN UINT32 Integer + ) +{ + UINT32 * Table; + UINT32 Index; + UINT32 LastIndex; + + ASSERT (MappingTable !=3D NULL); + ASSERT (MappingTable->Table !=3D NULL); + + Table =3D MappingTable->Table; + LastIndex =3D MappingTable->LastIndex; + + // Search if there is already an entry with this Integer. + for (Index =3D 0; Index < LastIndex; Index++) { + if (Table[Index] =3D=3D Integer) { + return Index; + } + } + + ASSERT (LastIndex < MappingTable->MaxIndex); + + // If no, create a new entry. + Table[LastIndex] =3D Integer; + + return MappingTable->LastIndex++; +} + +/** Generate required Pci device information. + + ASL code: + Name (_UID, ) // Uid of the Pci device + Name (_HID, EISAID ("PNP0A08")) // PCI Express Root Bridge + Name (_CID, EISAID ("PNP0A03")) // Compatible PCI Root Bridge + Name (_SEG, ) // PCI Segment Group number + Name (_BBN, ) // PCI Base Bus Number + Name (_CCA, 1) // Initially mark the PCI coherent + + @param [in] PciInfo Pci device information. + @param [in] Uid Unique Id of the Pci device. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +GeneratePciDeviceInfo ( + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO * PciInfo, + IN UINT32 Uid, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + UINT32 EisaId; + + ASSERT (PciInfo !=3D NULL); + ASSERT (PciNode !=3D NULL); + + // ASL: Name (_UID, ) + Status =3D AmlCodeGenNameInteger ("_UID", Uid, PciNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_HID, EISAID ("PNP0A08")) + Status =3D AmlGetEisaIdFromString ("PNP0A08", &EisaId); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + Status =3D AmlCodeGenNameInteger ("_HID", EisaId, PciNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_CID, EISAID ("PNP0A03")) + Status =3D AmlGetEisaIdFromString ("PNP0A03", &EisaId); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + Status =3D AmlCodeGenNameInteger ("_CID", EisaId, PciNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_SEG, ) + Status =3D AmlCodeGenNameInteger ( + "_SEG", + PciInfo->PciSegmentGroupNumber, + PciNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_BBN, ) + Status =3D AmlCodeGenNameInteger ( + "_BBN", + PciInfo->StartBusNumber, + PciNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_CCA, 1) + // Must be aligned with the IORT CCA property in + // "Table 14 Memory access properties" + Status =3D AmlCodeGenNameInteger ("_CCA", 1, PciNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + } + return Status; +} + +/** Generate a Link device. + + The Link device is added at the beginning of the ASL Pci device definiti= on. + + Each Link device represents a Pci legacy interrupt (INTA-...-INTD). + + ASL code: + Device () { + Name (_UID, ]) + Name (_HID, EISAID ("PNP0C0F")) + Name (CRS0, ResourceTemplate () { + Interrupt (ResourceProducer, Level, ActiveHigh, Exclusive) { ] } + }) + Method (_CRS, 0) { + Return CRS0 + }) + Method (_DIS) { } + } + + The list of objects to define is available at: + PCI Firmware Specification - Revision 3.3, + s3.5. "Device State at Firmware/Operating System Handoff" + + The _CRS and _SRS are not supported, cf Arm Base Boot Requirements v1.0: + "The _PRS (Possible Resource Settings) and _SRS (Set Resource Settings) + are not supported." + + @param [in] Irq Interrupt controller interrupt. + @param [in] IrqFlags Interrupt flags. + @param [in] LinkIndex Legacy Pci interrupt index. + Must be between 0-INTA and 3-INTD. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +GenerateLinkDevice ( + IN UINT32 Irq, + IN UINT32 IrqFlags, + IN UINT32 LinkIndex, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + CHAR8 AslName[AML_NAME_SEG_SIZE + 1]; + AML_OBJECT_NODE_HANDLE LinkNode; + AML_OBJECT_NODE_HANDLE CrsNode; + UINT32 EisaId; + + ASSERT (LinkIndex < 4); + ASSERT (PciNode !=3D NULL); + + CopyMem (AslName, "LNKx", AML_NAME_SEG_SIZE + 1); + AslName[AML_NAME_SEG_SIZE - 1] =3D 'A' + LinkIndex; + + // ASL: Device (LNKx) {} + Status =3D AmlCodeGenDevice (AslName, NULL, &LinkNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D AmlAttachNode (PciNode, LinkNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + // Failed to add. + AmlDeleteTree ((AML_NODE_HANDLE)LinkNode); + return Status; + } + + // ASL: Name (_UID, ) + Status =3D AmlCodeGenNameInteger ("_UID", LinkIndex, LinkNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_HID, EISAID ("PNP0C0F")) + Status =3D AmlGetEisaIdFromString ("PNP0C0F", &EisaId); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + Status =3D AmlCodeGenNameInteger ("_HID", EisaId, LinkNode, NULL); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: + // Name (CRS0, ResourceTemplate () { + // Interrupt (ResourceProducer, Level, ActiveHigh, Exclusive) { } + // }) + Status =3D AmlCodeGenNameResourceTemplate ("CRS0", LinkNode, &CrsNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + Status =3D AmlCodeGenRdInterrupt ( + FALSE, + (IrqFlags & BIT0) !=3D 0, + (IrqFlags & BIT1) !=3D 0, + FALSE, + &Irq, + 1, + CrsNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: + // Method (_CRS, 0) { + // Return (CRS0) + // } + Status =3D AmlCodeGenMethodRetNameString ( + "_CRS", + "CRS0", + 0, + FALSE, + 0, + LinkNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL:Method (_DIS, 1) {} + // Not possible to disable interrupts. + Status =3D AmlCodeGenMethodRetNameString ( + "_DIS", + NULL, + 0, + FALSE, + 0, + LinkNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // _STA: + // ACPI 6.4, s6.3.7 "_STA (Device Status)": + // If a device object describes a device that is not on an enumerable bus + // and the device object does not have an _STA object, then OSPM assumes + // that the device is present, enabled, shown in the UI, and functioning. + + // _MAT: + // Not supported. Mainly used for processors. + + return Status; +} + +/** Generate Pci slots devices. + + PCI Firmware Specification - Revision 3.3, + s4.8 "Generic ACPI PCI Slot Description" requests to describe the PCI sl= ot + used. It should be possible to enumerate them, but this is additional + information. + + @param [in] MappingTable The mapping table structure. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +GeneratePciSlots ( + IN CONST MAPPING_TABLE * MappingTable, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + UINT32 Index; + UINT32 LastIndex; + UINT32 DeviceId; + CHAR8 AslName[AML_NAME_SEG_SIZE + 1]; + AML_OBJECT_NODE_HANDLE DeviceNode; + + ASSERT (MappingTable !=3D NULL); + ASSERT (PciNode !=3D NULL); + + // Generic device name is "Dxx". + CopyMem (AslName, "Dxx_", AML_NAME_SEG_SIZE + 1); + + LastIndex =3D MappingTable->LastIndex; + + // There are at most 32 devices on a Pci bus. + if (LastIndex >=3D 32) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < LastIndex; Index++) { + DeviceId =3D MappingTable->Table[Index]; + AslName[AML_NAME_SEG_SIZE - 3] =3D AsciiFromHex (DeviceId & 0xF); + AslName[AML_NAME_SEG_SIZE - 2] =3D AsciiFromHex ((DeviceId >> 4) & 0xF= ); + + // ASL: + // Device (Dxx) { + // Name (_ADR,
) + // } + Status =3D AmlCodeGenDevice (AslName, PciNode, &DeviceNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + /* ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings" + High word-Device #, Low word-Function #. (for example, device 3, + function 2 is 0x00030002). To refer to all the functions on a devic= e #, + use a function number of FFFF). + */ + Status =3D AmlCodeGenNameInteger ( + "_ADR", + (DeviceId << 16) | 0xFFFF, + DeviceNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // _SUN object is not generated as we don't know which slot will be us= ed. + } + + return Status; +} + +/** Generate a _PRT object (Pci Routing Table) for the Pci device. + + Cf. ACPI 6.4 specification, s6.2.13 "_PRT (PCI Routing Table)" + + @param [in] Generator The SSDT Pci generator. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] PciInfo Pci device information. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +GeneratePrt ( + IN ACPI_PCI_GENERATOR * Generator, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtoc= ol, + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO * PciInfo, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + INT32 Index; + UINT32 IrqTableIndex; + AML_OBJECT_NODE_HANDLE PrtNode; + CHAR8 AslName[AML_NAME_SEG_SIZE + 1]; + CM_ARM_OBJ_REF * RefInfo; + UINT32 RefCount; + CM_ARM_PCI_INTERRUPT_MAP_INFO * IrqMapInfo; + UINT32 IrqFlags; + UINT32 PrevIrqFlags; + + ASSERT (Generator !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (PciInfo !=3D NULL); + ASSERT (PciNode !=3D NULL); + + PrtNode =3D NULL; + + // Get the array of CM_ARM_OBJ_REF referencing the + // CM_ARM_PCI_INTERRUPT_MAP_INFO objects. + Status =3D GetEArmObjCmRef ( + CfgMgrProtocol, + PciInfo->InterruptMapToken, + &RefInfo, + &RefCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Initialized IrqTable. + Status =3D MappingTableInitialize (&Generator->IrqTable, RefCount); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Initialized DeviceTable. + Status =3D MappingTableInitialize (&Generator->DeviceTable, RefCount); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler0; + } + + // ASL: Name (_PRT, Package () {}) + Status =3D AmlCodeGenNamePackage ("_PRT", NULL, &PrtNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + CopyMem (AslName, "LNKx", AML_NAME_SEG_SIZE + 1); + + for (Index =3D 0; Index < RefCount; Index++) { + // Get CM_ARM_PCI_INTERRUPT_MAP_INFO structures one by one. + Status =3D GetEArmObjPciInterruptMapInfo ( + CfgMgrProtocol, + RefInfo[Index].ReferenceToken, + &IrqMapInfo, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + // Add the interrupt in the IrqTable and get the link name. + IrqTableIndex =3D MappingTableAdd ( + &Generator->IrqTable, + IrqMapInfo->IntcInterrupt.Interrupt + ); + if (IrqTableIndex >=3D MAX_PCI_LEGACY_INTERRUPT) { + ASSERT (0); + Status =3D EFI_INVALID_PARAMETER; + goto exit_handler; + } + + AslName[AML_NAME_SEG_SIZE - 1] =3D 'A' + IrqTableIndex; + + // Check that the interrupts flags are identical for all interrupts. + PrevIrqFlags =3D IrqFlags; + IrqFlags =3D IrqMapInfo->IntcInterrupt.Flags; + if ((Index > 0) && (PrevIrqFlags !=3D IrqFlags)) { + ASSERT (0); + Status =3D EFI_INVALID_PARAMETER; + goto exit_handler; + } + + // Add the device to the DeviceTable. + MappingTableAdd (&Generator->DeviceTable, IrqMapInfo->PciDevice); + + /* Add a _PRT entry. + ASL + Name (_PRT, Package () { + , + + }) + + Address is set as: + ACPI 6.4 specification, Table 6.2: "ADR Object Address Encodings" + High word-Device #, Low word-Function #. (for example, device 3, + function 2 is 0x00030002). To refer to all the functions on a devic= e #, + use a function number of FFFF). + */ + Status =3D AmlAddPrtEntry ( + (IrqMapInfo->PciDevice << 16) | 0xFFFF, + IrqMapInfo->PciInterrupt, + AslName, + 0, + PrtNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } // for + + // Generate the LNKx devices now that we know all the interrupts used. + for (Index =3D 0; Index < Generator->IrqTable.LastIndex; Index++) { + Status =3D GenerateLinkDevice ( + Generator->IrqTable.Table[Index], + IrqFlags, + Index, + PciNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } // for + + // Attach the _PRT entry now, after the LNKx devices. + Status =3D AmlAttachNode (PciNode, PrtNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + PrtNode =3D NULL; + + // Generate the Pci slots once all the device have been added. + Status =3D GeneratePciSlots (&Generator->DeviceTable, PciNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + +exit_handler: + MappingTableFree (&Generator->DeviceTable); +exit_handler0: + MappingTableFree (&Generator->IrqTable); + if (PrtNode !=3D NULL) { + AmlDeleteTree (PrtNode); + } + + return Status; +} + +/** Generate a _CRS method for the Pci device. + + @param [in] Generator The SSDT Pci generator. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] PciInfo Pci device information. + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +GeneratePciCrs ( + IN ACPI_PCI_GENERATOR * Generator, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtoc= ol, + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO * PciInfo, + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + BOOLEAN Translation; + UINT32 Index; + CM_ARM_OBJ_REF * RefInfo; + UINT32 RefCount; + CM_ARM_PCI_ADDRESS_MAP_INFO * AddrMapInfo; + AML_OBJECT_NODE_HANDLE CrsNode; + + ASSERT (Generator !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (PciInfo !=3D NULL); + ASSERT (PciNode !=3D NULL); + + // ASL: Name (_CRS, ResourceTemplate () {}) + Status =3D AmlCodeGenNameResourceTemplate ("_CRS", PciNode, &CrsNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: + // WordBusNumber ( // Bus numbers assigned to this root + // ResourceProducer, MinFixed, MaxFixed, PosDecode, + // 0, // AddressGranularity + // , // AddressMinimum - Minimum Bus Number + // , // AddressMaximum - Maximum Bus Number + // 0, // AddressTranslation - Set to 0 + // - + 1 // RangeLength - Number of Busses + // ) + Status =3D AmlCodeGenRdWordBusNumber ( + FALSE, + TRUE, + TRUE, + TRUE, + 0, + PciInfo->StartBusNumber, + PciInfo->EndBusNumber, + 0, + PciInfo->EndBusNumber - PciInfo->StartBusNumber + 1, + 0, + NULL, + CrsNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Get the array of CM_ARM_OBJ_REF referencing the + // CM_ARM_PCI_ADDRESS_MAP_INFO objects. + Status =3D GetEArmObjCmRef ( + CfgMgrProtocol, + PciInfo->AddressMapToken, + &RefInfo, + &RefCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + for (Index =3D 0; Index < RefCount; Index++) { + // Get CM_ARM_PCI_ADDRESS_MAP_INFO structures one by one. + Status =3D GetEArmObjPciAddressMapInfo ( + CfgMgrProtocol, + RefInfo[Index].ReferenceToken, + &AddrMapInfo, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Translation =3D (AddrMapInfo->CpuAddress !=3D AddrMapInfo->PciAddress); + + switch (AddrMapInfo->SpaceCode) { + case PCI_SS_IO: + Status =3D AmlCodeGenRdDWordIo ( + FALSE, + TRUE, + TRUE, + TRUE, + 3, + 0, + AddrMapInfo->PciAddress, + AddrMapInfo->PciAddress + AddrMapInfo->AddressSize - 1, + Translation ? AddrMapInfo->CpuAddress : 0, + AddrMapInfo->AddressSize, + 0, + NULL, + TRUE, + FALSE, + CrsNode, + NULL + ); + break; + + case PCI_SS_M32: + Status =3D AmlCodeGenRdDWordMemory ( + FALSE, + TRUE, + TRUE, + TRUE, + TRUE, + TRUE, + 0, + AddrMapInfo->PciAddress, + AddrMapInfo->PciAddress + AddrMapInfo->AddressSize - 1, + Translation ? AddrMapInfo->CpuAddress : 0, + AddrMapInfo->AddressSize, + 0, + NULL, + 0, + TRUE, + CrsNode, + NULL + ); + break; + + case PCI_SS_M64: + Status =3D AmlCodeGenRdQWordMemory ( + FALSE, + TRUE, + TRUE, + TRUE, + TRUE, + TRUE, + 0, + AddrMapInfo->PciAddress, + AddrMapInfo->PciAddress + AddrMapInfo->AddressSize - 1, + Translation ? AddrMapInfo->CpuAddress : 0, + AddrMapInfo->AddressSize, + 0, + NULL, + 0, + TRUE, + CrsNode, + NULL + ); + break; + + default: + Status =3D EFI_INVALID_PARAMETER; + } // switch + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } // for + return Status; +} + +/** Add an _OSC template method to the PciNode. + + The _OSC method is provided as an AML blob. The blob is + parsed and attached at the end of the PciNode list of variable elements. + + @param [in, out] PciNode Pci node to amend. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AddOscMethod ( + IN OUT AML_OBJECT_NODE_HANDLE PciNode + ) +{ + EFI_STATUS Status; + EFI_STATUS Status1; + EFI_ACPI_DESCRIPTION_HEADER * SsdtPcieOscTemplate; + AML_ROOT_NODE_HANDLE OscTemplateRoot; + AML_OBJECT_NODE_HANDLE OscNode; + + ASSERT (PciNode !=3D NULL); + + // Parse the Ssdt Pci Osc Template. + SsdtPcieOscTemplate =3D (EFI_ACPI_DESCRIPTION_HEADER*) + ssdtpcieosctemplate_aml_code; + + OscNode =3D NULL; + OscTemplateRoot =3D NULL; + Status =3D AmlParseDefinitionBlock ( + SsdtPcieOscTemplate, + &OscTemplateRoot + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI-OSC: Failed to parse SSDT PCI OSC Template." + " Status =3D %r\n", + Status + )); + return Status; + } + + Status =3D AmlFindNode (OscTemplateRoot, "\\_OSC", &OscNode); + if (EFI_ERROR (Status)) { + goto error_handler; + } + + Status =3D AmlDetachNode (OscNode); + if (EFI_ERROR (Status)) { + goto error_handler; + } + + Status =3D AmlAttachNode (PciNode, OscNode); + if (EFI_ERROR (Status)) { + // Free the detached node. + AmlDeleteTree (OscNode); + goto error_handler; + } + +error_handler: + // Cleanup + Status1 =3D AmlDeleteTree (OscTemplateRoot); + if (EFI_ERROR (Status1)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI-OSC: Failed to cleanup AML tree." + " Status =3D %r\n", + Status1 + )); + // If Status was success but we failed to delete the AML Tree + // return Status1 else return the original error code, i.e. Status. + if (!EFI_ERROR (Status)) { + return Status1; + } + } + + return Status; +} + +/** Generate a Pci device. + + @param [in] Generator The SSDT Pci generator. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] PciInfo Pci device information. + @param [in] Uid Unique Id of the Pci device. + @param [in, out] RootNode RootNode of the AML tree to populate. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +GeneratePciDevice ( + IN ACPI_PCI_GENERATOR * Generator, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtoc= ol, + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO * PciInfo, + IN UINT32 Uid, + IN OUT AML_ROOT_NODE_HANDLE * RootNode + ) +{ + EFI_STATUS Status; + + CHAR8 AslName[AML_NAME_SEG_SIZE + 1]; + AML_OBJECT_NODE_HANDLE ScopeNode; + AML_OBJECT_NODE_HANDLE PciNode; + + ASSERT (Generator !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (PciInfo !=3D NULL); + ASSERT (RootNode !=3D NULL); + + PciNode =3D NULL; + + // ASL: Scope (\_SB) {} + Status =3D AmlCodeGenScope (SB_SCOPE, RootNode, &ScopeNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Write the name of the PCI device. + CopyMem (AslName, "PCIx", AML_NAME_SEG_SIZE + 1); + AslName[AML_NAME_SEG_SIZE - 1] =3D AsciiFromHex (Uid); + + // ASL: Device (PCIx) {} + Status =3D AmlCodeGenDevice (AslName, ScopeNode, &PciNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Populate the PCIx node with some Id values. + Status =3D GeneratePciDeviceInfo (PciInfo, Uid, PciNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Generate the Pci Routing Table (_PRT). + if (PciInfo->InterruptMapToken !=3D CM_NULL_TOKEN) { + Status =3D GeneratePrt ( + Generator, + CfgMgrProtocol, + PciInfo, + PciNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + } + + // Generate the _CRS method. + Status =3D GeneratePciCrs (Generator, CfgMgrProtocol, PciInfo, PciNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Add the template _OSC method. + Status =3D AddOscMethod (PciNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + } + + return Status; +} + +/** Build an Ssdt table describing a Pci device. + + @param [in] Generator The SSDT Pci generator. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [in] AcpiTableInfo Pointer to the ACPI table information. + @param [in] PciInfo Pci device information. + @param [in] Uid Unique Id of the Pci device. + @param [out] Table If success, contains the created SSDT tabl= e. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildSsdtPciTable ( + IN ACPI_PCI_GENERATOR * Generator, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo, + IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO * PciInfo, + IN UINT32 Uid, + OUT EFI_ACPI_DESCRIPTION_HEADER ** Table + ) +{ + EFI_STATUS Status; + EFI_STATUS Status1; + AML_ROOT_NODE_HANDLE RootNode; + + ASSERT (Generator !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (PciInfo !=3D NULL); + ASSERT (Table !=3D NULL); + + // Create a new Ssdt table. + Status =3D AddSsdtAcpiHeader ( + CfgMgrProtocol, + &Generator->Header, + AcpiTableInfo, + &RootNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status =3D GeneratePciDevice ( + Generator, + CfgMgrProtocol, + PciInfo, + Uid, + RootNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + + // Serialize the tree. + Status =3D AmlSerializeDefinitionBlock ( + RootNode, + Table + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI: Failed to Serialize SSDT Table Data." + " Status =3D %r\n", + Status + )); + } + +exit_handler: + // Cleanup + Status1 =3D AmlDeleteTree (RootNode); + if (EFI_ERROR (Status1)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI: Failed to cleanup AML tree." + " Status =3D %r\n", + Status1 + )); + // If Status was success but we failed to delete the AML Tree + // return Status1 else return the original error code, i.e. Status. + if (!EFI_ERROR (Status)) { + return Status1; + } + } + + return Status; +} + +/** Construct SSDT tables describing Pci root complexes. + + This function invokes the Configuration Manager protocol interface + to get the required hardware information for generating the ACPI + table. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResourcesEx function. + + @param [in] This Pointer to the ACPI table generator. + @param [in] AcpiTableInfo Pointer to the ACPI table information. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + @param [out] Table Pointer to a list of generated ACPI table(s= ). + @param [out] TableCount Number of generated ACPI table(s). + + @retval EFI_SUCCESS Table generated successfully. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND Could not find information. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +EFIAPI +BuildSsdtPciTableEx ( + IN CONST ACPI_TABLE_GENERATOR * This, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, + OUT EFI_ACPI_DESCRIPTION_HEADER *** Table, + OUT UINTN * CONST TableCount + ) +{ + EFI_STATUS Status; + CM_ARM_PCI_CONFIG_SPACE_INFO * PciInfo; + UINT32 PciCount; + UINTN Index; + EFI_ACPI_DESCRIPTION_HEADER ** TableList; + ACPI_PCI_GENERATOR * Generator; + + ASSERT (This !=3D NULL); + ASSERT (AcpiTableInfo !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (Table !=3D NULL); + ASSERT (TableCount !=3D NULL); + ASSERT (AcpiTableInfo->TableGeneratorId =3D=3D This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature =3D=3D This->AcpiTableSignatur= e); + + *TableCount =3D 0; + Generator =3D (ACPI_PCI_GENERATOR*)This; + + Status =3D GetEArmObjPciConfigSpaceInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &PciInfo, + &PciCount + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + if (PciCount > MAX_PCI_ROOT_COMPLEXES_SUPPORTED) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI: Too many Pci root complexes: %d." + " Maximum Pci root complexes supported =3D %d.\n", + PciCount, + MAX_PCI_ROOT_COMPLEXES_SUPPORTED + )); + return EFI_INVALID_PARAMETER; + } + + // Allocate a table to store pointers to the SSDT tables. + TableList =3D (EFI_ACPI_DESCRIPTION_HEADER**) + AllocateZeroPool ( + (sizeof (EFI_ACPI_DESCRIPTION_HEADER*) * PciCount) + ); + if (TableList =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI: Failed to allocate memory for Table List." + " Status =3D %r\n", + Status + )); + return Status; + } + + // Setup the table list early so that appropriate cleanup + // can be done in case of failure. + *Table =3D TableList; + + for (Index =3D 0; Index < PciCount; Index++) { + // Build a SSDT table describing the Pci devices. + Status =3D BuildSsdtPciTable ( + Generator, + CfgMgrProtocol, + AcpiTableInfo, + &PciInfo[Index], + Index, + &TableList[Index] + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI: Failed to build associated SSDT table." + " Status =3D %r\n", + Status + )); + goto error_handler; + } + + *TableCount +=3D 1; + } // for + +error_handler: + // Note: Table list and Table count have been setup. The + // error handler does nothing here as the framework will invoke + // FreeSsdtPciTableEx () even on failure. + return Status; +} + +/** Free any resources allocated for constructing the tables. + + @param [in] This Pointer to the ACPI table generator. + @param [in] AcpiTableInfo Pointer to the ACPI Table Info. + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Table Pointer to an array of pointers + to ACPI Table(s). + @param [in] TableCount Number of ACPI table(s). + + @retval EFI_SUCCESS The resources were freed successfully. + @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid. +**/ +STATIC +EFI_STATUS +EFIAPI +FreeSsdtPciTableEx ( + IN CONST ACPI_TABLE_GENERATOR * CONST This, + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableIn= fo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProto= col, + IN OUT EFI_ACPI_DESCRIPTION_HEADER *** CONST Table, + IN CONST UINTN TableCount + ) +{ + EFI_ACPI_DESCRIPTION_HEADER ** TableList; + UINTN Index; + + ASSERT (This !=3D NULL); + ASSERT (AcpiTableInfo !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (AcpiTableInfo->TableGeneratorId =3D=3D This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature =3D=3D This->AcpiTableSignatur= e); + + if ((Table =3D=3D NULL) || + (*Table =3D=3D NULL) || + (TableCount =3D=3D 0)) { + DEBUG ((DEBUG_ERROR, "ERROR: SSDT-PCI: Invalid Table Pointer\n")); + return EFI_INVALID_PARAMETER; + } + + TableList =3D *Table; + for (Index =3D 0; Index < TableCount; Index++) { + if ((TableList[Index] !=3D NULL) && + (TableList[Index]->Signature =3D=3D + EFI_ACPI_6_3_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE)) { + FreePool (TableList[Index]); + } else { + DEBUG (( + DEBUG_ERROR, + "ERROR: SSDT-PCI: Could not free SSDT table at index %d.", + Index + )); + return EFI_INVALID_PARAMETER; + } + } //for + + // Free the table list. + FreePool (*Table); + + return EFI_SUCCESS; +} + +/** This macro defines the SSDT Pci Table Generator revision. +*/ +#define SSDT_PCI_GENERATOR_REVISION CREATE_REVISION (1, 0) + +/** The interface for the SSDT Pci Table Generator. +*/ +STATIC +ACPI_PCI_GENERATOR SsdtPcieGenerator =3D { + // ACPI table generator header + { + // Generator ID + CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdSsdtPciExpress), + // Generator Description + L"ACPI.STD.SSDT.PCI.GENERATOR", + // ACPI Table Signature + EFI_ACPI_6_3_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, + // ACPI Table Revision - Unused + 0, + // Minimum ACPI Table Revision - Unused + 0, + // Creator ID + TABLE_GENERATOR_CREATOR_ID_ARM, + // Creator Revision + SSDT_PCI_GENERATOR_REVISION, + // Build table function. Use the extended version instead. + NULL, + // Free table function. Use the extended version instead. + NULL, + // Extended Build table function. + BuildSsdtPciTableEx, + // Extended free function. + FreeSsdtPciTableEx + }, + + // Private fields are defined from here. + + // IrqTable + { + // Table + NULL, + // LastIndex + 0, + // MaxIndex + 0 + }, + // DeviceTable + { + // Table + NULL, + // LastIndex + 0, + // MaxIndex + 0 + }, +}; + +/** Register the Generator with the ACPI Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +AcpiSsdtPcieLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE * SystemTable + ) +{ + EFI_STATUS Status; + Status =3D RegisterAcpiTableGenerator (&SsdtPcieGenerator.Header); + DEBUG (( + DEBUG_INFO, + "SSDT-PCI: Register Generator. Status =3D %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the ACPI Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +AcpiSsdtPcieLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE * SystemTable + ) +{ + EFI_STATUS Status; + Status =3D DeregisterAcpiTableGenerator (&SsdtPcieGenerator.Header); + DEBUG (( + DEBUG_INFO, + "SSDT-PCI: Deregister Generator. Status =3D %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.h b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieG= enerator.h new file mode 100644 index 000000000000..d2300a6e4aa3 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.h @@ -0,0 +1,138 @@ +/** @file + SSDT Pcie Table Generator. + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - PCI Firmware Specification - Revision 3.0 + - ACPI 6.4 specification: + - s6.2.13 "_PRT (PCI Routing Table)" + - s6.1.1 "_ADR (Address)" + - linux kernel code + - Arm Base Boot Requirements v1.0 +**/ + +#ifndef SSDT_PCIE_GENERATOR_H_ +#define SSDT_PCIE_GENERATOR_H_ + +/** Pci address attributes. + + This can also be denoted as space code, address space or ss. +*/ +#define PCI_SS_CONFIG 0 +#define PCI_SS_IO 1 +#define PCI_SS_M32 2 +#define PCI_SS_M64 3 + +/** Maximum Pci root complexes supported by this generator. + + Note: This is not a hard limitation and can be extended if needed. + Corresponding changes would be needed to support the Name and + UID fields describing the Pci root complexes. +*/ +#define MAX_PCI_ROOT_COMPLEXES_SUPPORTED 16 + +/** Maximum number of Pci legacy interrupts. + + Currently 4 for INTA-INTB-INTC-INTD. +*/ +#define MAX_PCI_LEGACY_INTERRUPT 4 + +// _SB scope of the AML namespace. +#define SB_SCOPE "\\_SB_" + +/** C array containing the compiled AML template. + This symbol is defined in the auto generated C file + containing the AML bytecode array. +*/ +extern CHAR8 ssdtpcieosctemplate_aml_code[]; + +#pragma pack(1) + +/** Structure used to map integer to an index. +*/ +typedef struct MappingTable { + /// Mapping table. + /// Contains the Index <-> integer mapping + UINT32 * Table; + + /// Last used index of the Table. + /// Bound by MaxIndex. + UINT32 LastIndex; + + /// Number of entries in the Table. + UINT32 MaxIndex; +} MAPPING_TABLE; + +/** A structure holding the Pcie generator and additional private data. +*/ +typedef struct AcpiPcieGenerator { + /// ACPI Table generator header + ACPI_TABLE_GENERATOR Header; + + // Private fields are defined from here. + + /** A structure used to handle the Address and Interrupt Map referencing. + + A CM_ARM_PCI_CONFIG_SPACE_INFO structure references two CM_ARM_OBJ_REF: + - one for the address mapping, referencing + CM_ARM_PCI_ADDRESS_MAP_INFO structures. + - one for the interrupt mapping, referencing + CM_ARM_PCI_INTERRUPT_MAP_INFO structures. + + Example (for the interrupt mapping): + (Pci0) + CM_ARM_PCI_CONFIG_SPACE_INFO + | + +---------------------------------------- + | | + v v + CM_ARM_OBJ_REF CM_ARM_OBJ_REF + (List of references to (List of references to + address mappings) interrupt mappings) + | | + v v + CM_ARM_PCI_INTERRUPT_MAP_INFO[0..N] CM_ARM_PCI_INTERRUPT_MAP_INFO[0= ..M] + (A list of address mappings) (A list of interrupt mappings) + + The CM_ARM_PCI_INTERRUPT_MAP_INFO objects cannot be handled individual= ly. + Device's Pci legacy interrupts that are mapped to the same CPU interru= pt + are grouped under a Link device. + For instance, the following mapping: + - [INTA of device 0] mapped on [GIC irq 168] + - [INTB of device 1] mapped on [GIC irq 168] + will be represented in an SSDT table as: + - [INTA of device 0] mapped on [Link device A] + - [INTB of device 1] mapped on [Link device A] + - [Link device A] mapped on [GIC irq 168] + + Counting the number of Cpu interrupts used and grouping them in Link + devices is done through this IRQ_TABLE. + + ASL code: + Scope (_SB) { + Device (LNKA) { + [...] + Name (_PRS, ResourceTemplate () { + Interrupt (ResourceProducer, Level, ActiveHigh, Exclusive) { 168= } + }) + } + + Device (PCI0) { + Name (_PRT, Package () { + Package (0x0FFFF, 0, LNKA, 0) // INTA of device 0 <-> LNKA + Package (0x1FFFF, 1, LNKA, 0) // INTB of device 1 <-> LNKA + }) + } + } + */ + MAPPING_TABLE IrqTable; + + /// Table to map: Index <-> Pci device + MAPPING_TABLE DeviceTable; +} ACPI_PCI_GENERATOR; + +#pragma pack() + +#endif // SSDT_PCIE_GENERATOR_H_ diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieL= ibArm.inf b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLi= bArm.inf new file mode 100644 index 000000000000..283b5648017c --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.i= nf @@ -0,0 +1,32 @@ +## @file +# Ssdt Serial Port Table Generator +# +# Copyright (c) 2021, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D SsdtPcieLibArm + FILE_GUID =3D E431D7FD-26BF-4E3D-9064-5B13B0439057 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D NULL|DXE_DRIVER + CONSTRUCTOR =3D AcpiSsdtPcieLibConstructor + DESTRUCTOR =3D AcpiSsdtPcieLibDestructor + +[Sources] + SsdtPcieGenerator.c + SsdtPcieGenerator.h + SsdtPcieOscTemplate.asl + +[Packages] + DynamicTablesPkg/DynamicTablesPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + AcpiHelperLib + AmlLib + BaseLib diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieO= scTemplate.asl b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtP= cieOscTemplate.asl new file mode 100644 index 000000000000..feaf56b53384 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieOscTempl= ate.asl @@ -0,0 +1,80 @@ +/** @file + SSDT Pci Osc (Operating System Capabilities) + + Copyright (c) 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - PCI Firmware Specification - Revision 3.3 + - ACPI 6.4 specification: + - s6.2.13 "_PRT (PCI Routing Table)" + - s6.1.1 "_ADR (Address)" + - linux kernel code +**/ + +DefinitionBlock ("SsdtPciOsc.aml", "SSDT", 2, "ARMLTD", "PCI-OSC", 1) { + + // This table is just a template and is never installed as a table. + // Pci devices are dynamically created at runtime as: + // ASL: + // Device (PCIx) { + // ... + // } + // and the _OSC method available below is appended to the PCIx device as: + // ASL: + // Device (PCIx) { + // ... + // Method (_OSC, 4 { + // ... + // }) + // } + Method (_OSC, 4) { + // + // OS Control Handoff + // + Name (SUPP, Zero) // PCI _OSC Support Field value + Name (CTRL, Zero) // PCI _OSC Control Field value + + // Create DWord-addressable fields from the Capabilities Buffer + CreateDWordField (Arg3, 0, CDW1) + CreateDWordField (Arg3, 4, CDW2) + CreateDWordField (Arg3, 8, CDW3) + + // Check for proper UUID + If (LEqual (Arg0,ToUUID ("33DB4D5B-1FF7-401C-9657-7441C03DD766"))) { + + // Save Capabilities DWord2 & 3 + Store (CDW2, SUPP) + Store (CDW3, CTRL) + + // Only allow native hot plug control if OS supports: + // * ASPM + // * Clock PM + // * MSI/MSI-X + If (LNotEqual (And (SUPP, 0x16), 0x16)) { + And (CTRL, 0x1E, CTRL) // Mask bit 0 (and undefined bits) + } + + // Always allow native PME, AER (no dependencies) + + // Never allow SHPC (no SHPC controller in this system) + And (CTRL, 0x1D, CTRL) + + If (LNotEqual (Arg1, One)) { // Unknown revision + Or (CDW1, 0x08, CDW1) + } + + If (LNotEqual (CDW3, CTRL)) { // Capabilities bits were masked + Or (CDW1, 0x10, CDW1) + } + + // Update DWORD3 in the buffer + Store (CTRL,CDW3) + Return (Arg3) + } Else { + Or (CDW1, 4, CDW1) // Unrecognized UUID + Return (Arg3) + } // If + } // _OSC +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81759): https://edk2.groups.io/g/devel/message/81759 Mute This Topic: https://groups.io/mt/86241748/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-