From nobody Sat May 18 07:31:22 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+76959+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+76959+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449544; cv=none; d=zohomail.com; s=zohoarc; b=gCEEtVXCdwWIqviaGQeRTwgBo2jcjr0ddDigL5jM5QAL5nv5qppfafe7jnzIKBSBfCpSem/+lQ/efcUwSaayshLSjjotLusTbSn1bS3cFLAEt25L9AXQLWjNmzjLlKYrjH/Ggi8JoXlrZdqm2xtdviIr8FRbxEIXNf2GnshEZs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449544; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=qdvDq94+9P4KJf8NldLtfL16A0d9FGX2o2Pz+9fDeQo=; b=TCX/ZgPwhJXpGRaKyASO+pBd+4ugdzSsxinCTn3khZN/vMSP3tPQ/+jmmQq7uoUaFHbIFOaOy6S/82XT3KF9SF3xoVFkOawAQ0M9jg+CBKEUImRHCPu0amyuHy0U9E9Rvex/T7a9tnHZ1zdHIjrKCWjHQecRkIjn44Gl6+Nfi8U= 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+76959+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 162444954453020.02974684058927; Wed, 23 Jun 2021 04:59:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qT4nYY1788612xBODhaEQH9K; Wed, 23 Jun 2021 04:59:04 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6478.1624449543438618835 for ; Wed, 23 Jun 2021 04:59:03 -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 0DF491063; Wed, 23 Jun 2021 04:59:03 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4E5DE3F718; Wed, 23 Jun 2021 04:59:01 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 1/7] DynamicTablesPkg: AML Code generation for memory ranges Date: Wed, 23 Jun 2021 12:58:28 +0100 Message-Id: <20210623115834.907-2-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: spLXUOwZjUpLQsORpqsfFQPdx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449544; bh=JlUNihmACl6pxo/F9UwZyd2J+QhEFKLi8UkD6qosetY=; h=Cc:Date:From:Reply-To:Subject:To; b=cCpH2ESxmZqc3T7oL0bHiAKRPdGyamIIsObdTzt1NXgUFN9Fg8tTbF7CA+8S/GcwlX7 xg1iMQgyXsSm6Q0HmgZtbzrs26N0rj7G37fsrP0iosa7bf5WWXEUZ7Tju15v26XXgLA78 nPRv836m4VqFDgrUtq3jqdL4dB474NcSKn8= X-ZohoMail-DKIM: pass (identity @groups.io) 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 () Signed-off-by: Pierre Gondois --- .../Include/Library/AmlLib/AmlLib.h | 289 ++++++ .../AmlLib/CodeGen/AmlResourceDataCodeGen.c | 945 ++++++++++++++++++ 2 files changed, 1234 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTabl= esPkg/Include/Library/AmlLib/AmlLib.h index 4932f6fd9c8b..cbbbb7a478f7 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -418,6 +418,295 @@ AmlUpdateRdQWord ( IN UINT64 BaseAddressLength ); =20 +/** Code generation for the "DWordIO ()" ASL function. + + The Resource Data effectively created is an Extended Interrupt 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. + + @ingroup CodeGenApis + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsaRanges Available values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.34 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.34 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.34 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.34 for more. + Not supported. + @param [in] IsDenseTranslation TranslationDensity parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsTypeStatic TranslationType parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @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 an Extended Interrupt 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. + + @ingroup CodeGenApis + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.35 for more. + @param [in] Cacheable Available 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, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.35 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.35 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.35 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.35 for more. + Not supported. + @param [in] MemoryRangeType Available 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, + See ACPI 6.4 spec, s19.6.35 for more. + @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 an Extended Interrupt 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. + + @ingroup CodeGenApis + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.149 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.149 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.149 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.149 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.149 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.149 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.149 for more. + Not supported. + @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 an Extended Interrupt 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. + + @ingroup CodeGenApis + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.110 for more. + @param [in] Cacheable Available 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, + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.110 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.110 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.110 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.110 for more. + Not supported. + @param [in] MemoryRangeType Available values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsTypeStatic TranslationType parameter, + See ACPI 6.4 spec, s19.6.110 for more. + @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 78910cc5d4b4..3ab78d4fce22 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen= .c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen= .c @@ -94,6 +94,951 @@ error_handler: return Status; } =20 +/** Populate the TypeSpecificFlags field for IO ranges. + + @param [in] IsaRanges Available 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, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsTypeStatic TranslationType parameter, + See ACPI 6.4 spec, s19.6.34 for more. + + @return A TypeSpecificFlagsvalue. + 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; + } + + // Populate 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); +} + +/** Populate the TypeSpecificFlags field for Memory ranges. + + @param [in] Cacheable Available 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, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] MemoryRangeType Available 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, + See ACPI 6.4 spec, s19.6.35 for more. + + @return A TypeSpecificFlagsvalue. + 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; + } + + // Populate 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); +} + +/** Populate the GeneralFlags field of any Address Space Resource Descript= ors. + + E.g.: + ACPI 6.4 specification, s6.4.3.5.1 "QWord Address Space Descriptor" + for QWord + + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.36 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.36 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.36 for more. + + @return A TypeSpecificFlagsvalue. +**/ +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" + + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.36 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.36 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.36 for more. + + @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 an Extended Interrupt 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. + + @param [in] ResourceType See ACPI 6.4 spec, s6.4.3.5.2 for more. + Available values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.36 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.36 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.36 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.36 for more. + @param [in] TypeSpecificFlags See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.36 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.36 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.36 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.36 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.36 for more. + Not supported. + @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 not supported. + 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 an Extended Interrupt 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. + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsaRanges Available values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.34 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.34 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.34 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.34 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.34 for more. + Not supported. + @param [in] IsDenseTranslation TranslationDensity parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @param [in] IsTypeStatic TranslationType parameter, + See ACPI 6.4 spec, s19.6.34 for more. + @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 an Extended Interrupt 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. + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.35 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.35 for more. + @param [in] Cacheable Available 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, + See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.35 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.35 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.35 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.35 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.35 for more. + Not supported. + @param [in] MemoryRangeType Available 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, + See ACPI 6.4 spec, s19.6.35 for more. + @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 an Extended Interrupt 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. + + @param [in] ResourceType See ACPI 6.4 spec, s6.4.3.5.3 for more. + Available values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.151 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.151 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.151 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.151 for more. + @param [in] TypeSpecificFlags See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.151 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.151 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.151 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.151 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.151 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.151 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.151 for more. + Not supported. + @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 not supported. + 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 an Extended Interrupt 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. + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.149 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.149 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.149 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.149 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.149 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.149 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.149 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.149 for more. + Not supported. + @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 an Extended Interrupt 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. + + @param [in] ResourceType See ACPI 6.4 spec, s6.4.3.5.1 for more. + Available values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.111 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.111 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.111 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.111 for more. + @param [in] TypeSpecificFlags See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.111 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.111 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.111 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.111 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.111 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.111 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.111 for more. + Not supported. + @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 not supported. + 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 an Extended Interrupt 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. + + @param [in] IsResourceConsumer ResourceUsage parameter, + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsPosDecode Decode parameter, + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsMinFixed See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsMaxFixed See ACPI 6.4 spec, s19.6.110 for more. + @param [in] Cacheable Available 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, + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressGranularity See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressMinimum See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressMaximum See ACPI 6.4 spec, s19.6.110 for more. + @param [in] AddressTranslation See ACPI 6.4 spec, s19.6.110 for more. + @param [in] RangeLength See ACPI 6.4 spec, s19.6.110 for more. + @param [in] ResourceSourceIndex See ACPI 6.4 spec, s19.6.110 for more. + Not supported. + @param [in] ResourceSource See ACPI 6.4 spec, s19.6.110 for more. + Not supported. + @param [in] MemoryRangeType Available values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + See ACPI 6.4 spec, s19.6.110 for more. + @param [in] IsTypeStatic TranslationType parameter, + See ACPI 6.4 spec, s19.6.110 for more. + @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 (#76959): https://edk2.groups.io/g/devel/message/76959 Mute This Topic: https://groups.io/mt/83735871/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 Sat May 18 07:31:22 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+76960+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+76960+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449551; cv=none; d=zohomail.com; s=zohoarc; b=Ep5zUtohZ8zJU2oNCjm3DbVzyfhHK28bYQTz4aV9PspIA1wEbnTZ41bmAb0Oi1knWPFQXppOIJs58AdZlqOrXpsyqGBUp0kv4VqPMDXdZwRtr51bDaLCI8bpKgmt/6we1wNIh0Sq0QrUpDIpZTet7NQZuKmkejCfM4p3Dn1BPvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449551; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=2BvZMZ2oXSOF4fNWfFn7WEyeG7MKfn7Ov+X/LBJ+oP0=; b=LqZ3u/ZdyZKU/LUgREFbwuSIZGUVuHdZ/SqX8ji94LmweJG7j4FRMeENrA2BjEZkGwfMS+W6mPjqnrxCJf8vykihHiUOssfaLPuC6t4ExhllC7H4p2CBSWrIGxhyKyLNQ1iDAQAYL/k7Itaue/EsJ/4V2waZ0qKKbrRV0A/qHqc= 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+76960+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 1624449551116498.65320077727756; Wed, 23 Jun 2021 04:59:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KkuPYY1788612xpkeqwZleMs; Wed, 23 Jun 2021 04:59:10 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6479.1624449545128652426 for ; Wed, 23 Jun 2021 04:59:05 -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 B07D7ED1; Wed, 23 Jun 2021 04:59:04 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4E5F03F718; Wed, 23 Jun 2021 04:59:03 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 2/7] DynamicTablesPkg: AML Code generation to create a named Package() Date: Wed, 23 Jun 2021 12:58:29 +0100 Message-Id: <20210623115834.907-3-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: 1OCeeK9heMophtor3iuaM4JOx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449550; bh=c9gK7UmDH15X9LPo4Qy0Xh5CW/sqFQb7aL8GYP4qo1M=; h=Cc:Date:From:Reply-To:Subject:To; b=JWpJ+Emn+rbgKerGZFnKG9STbpUYN84UDDdxDbsS+Rf28ABUvtttClOPiwA3pqH0CzW N3hyUWcjJC7/1v2OWf/EcdWCiGKH/TxK1aMR63yrK3m1xBs4MpnD6j8N1G2K0/2NVMCA+ NQxLoeUWd55h+Tml/49imYEjyk1pKLNzQHw= X-ZohoMail-DKIM: pass (identity @groups.io) 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 () {}) Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../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 cbbbb7a478f7..412db886e1f2 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -852,6 +852,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 f0861040191f..f9175c623622 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -747,6 +747,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 (#76960): https://edk2.groups.io/g/devel/message/76960 Mute This Topic: https://groups.io/mt/83735872/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 Sat May 18 07:31:22 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+76961+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+76961+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449553; cv=none; d=zohomail.com; s=zohoarc; b=fCsbldcWjMjXneMvHyk4Gv5D1BIhOwWv9bs9lp0zN5OyqMqfFvB7x6T1o91wy9FsMHA9A7yAXXQWM8UKWQ++bB2hRNguBsffXEmjPod2aYyZSTav170Tst4Rb4kgZkZYyJ5XTtWltSogiXPmng7pGmJwTizR0fTPCcYO4hC3d1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449553; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=11RxDYBoSYOwE7J5RNwB4uhiTxFErQn//5/20BxN+tk=; b=H3EXKdmsLpYh5c1hVZ/stCfmZw8Ds3mfDCs4GpSbr64UmjJw9W6LsMtpgCwpJIsk+Ya9btHZnQ4qI1mC16iBB9eOmAvGD2iaLuUQYAz3xndGNkb3tEmMza9PJcwCi9QMQRze7x7SjdVwQC+Qwhvhw5pUHB7ng5Q+By0t4O8AUyE= 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+76961+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 1624449553430421.6209212541877; Wed, 23 Jun 2021 04:59:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id iHgyYY1788612x1GOYqiJYgD; Wed, 23 Jun 2021 04:59:13 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6480.1624449546879975367 for ; Wed, 23 Jun 2021 04:59:07 -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 7103FED1; Wed, 23 Jun 2021 04:59:06 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B5543F718; Wed, 23 Jun 2021 04:59:04 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 3/7] DynamicTablesPkg: AML Code generation to create a named ResourceTemplate() Date: Wed, 23 Jun 2021 12:58:30 +0100 Message-Id: <20210623115834.907-4-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: Q5LO7IbmPi92nulSM373y2aKx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449553; bh=r5yjdGHE1MboTJNuhZRITFQBFOGExNQ5ENnM04pKIps=; h=Cc:Date:From:Reply-To:Subject:To; b=Fg0Mnl79L8qrmjxQQer7iwFfC5T/hoXV/StAuTYQac+z3XiNR37MRK+02bFyc0NN0Ki N3FA0xuydamkSax06z90bo0byDUK9C0N5zY2EfJIrPi1CvbNqmkaVldEj9/+MbbHiSVLJ WLyvN960p3LqnnyRccNo/BBlLF+RraBA+sk= X-ZohoMail-DKIM: pass (identity @groups.io) 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 () {}) Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../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 412db886e1f2..544bc670c455 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -880,6 +880,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 f9175c623622..eaa49a5834c2 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -802,6 +802,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 (#76961): https://edk2.groups.io/g/devel/message/76961 Mute This Topic: https://groups.io/mt/83735874/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 Sat May 18 07:31:22 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+76962+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+76962+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449549; cv=none; d=zohomail.com; s=zohoarc; b=PVlOPvvf0hSw8Rhdf8ETXnQbXBP1lF08pCdGwGdJhU6v1Ae/Wm6l9TpNOJlvxQHZu8izKCQ/OwSlniW5Tp4xEWLhwb2m15OqXVegJO0A1eZt6frFZqoATNxsVsd9FfygTqQHxu/z6IAUSh4rMJv7Q0w1Glj2eSei6pjBdonNJoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449549; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=e6Je/n8Fqb4ZQwxg3/G9jSgNMLVL2OL6Ru6n4XdjLaU=; b=mnv5Sw97MMivrL7Ww47xSqsyLM71BAYpJ9oe3B+kxr7vVG6kzracp+PPz452fT1ef+muLScQ8sQG2NOiOszqK9ra9k1qMekoIdOxIhokLWY//+0jw5C4ASOqAd7zJ1BgJi8sbwYQ3YLiSrEo3VHz0hSGKrfeg9IMoToBML2axro= 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+76962+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 16244495496421012.5376018750491; Wed, 23 Jun 2021 04:59:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 09jrYY1788612xNqjZBUc8Ha; Wed, 23 Jun 2021 04:59:09 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.6606.1624449548714605248 for ; Wed, 23 Jun 2021 04:59:08 -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 4B21EED1; Wed, 23 Jun 2021 04:59:08 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D05123F718; Wed, 23 Jun 2021 04:59:06 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 4/7] DynamicTablesPkg: AML Code generation to add _PRT entries Date: Wed, 23 Jun 2021 12:58:31 +0100 Message-Id: <20210623115834.907-5-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: tIV4vCwxaArfzraYt6cRlSPax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449549; bh=auArnIbfMxzJeFjsi/JH3d2MCnQowPLGAMjmexBp1Hc=; h=Cc:Date:From:Reply-To:Subject:To; b=f1kjqTBWzPSbaYJpQzoOEtYn76kbOsSiXil4pRL3x4eKByRnV/9Imz1TioIHOhkyVcS /AjBtSM1fF6fB/ujImQPy609NoGOpyvX7moaHElkeVta0Eqg9SNUSAZ1SME2YtbZhhZfU ZIK3VAV71an5dmCKC2DOwJsAhdBaB5qG5mw= X-ZohoMail-DKIM: pass (identity @groups.io) 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. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../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 544bc670c455..4a10da8cd7bb 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -908,6 +908,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 eaa49a5834c2..9bf4e110d05c 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -857,6 +857,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 (#76962): https://edk2.groups.io/g/devel/message/76962 Mute This Topic: https://groups.io/mt/83735875/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 Sat May 18 07:31:22 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+76963+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+76963+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449551; cv=none; d=zohomail.com; s=zohoarc; b=V5ge1q+kYUl8032ihqxSlLCjIEarUejffMuOy/wulC0OVNxSevW12y+Zt/wV60Is7HsvqivuJxQefycwzn5+aUJZLScLN0QpSCZnJ9Qn0KcOEXdoGWxjYzl/tqs1Q86KLI6Otb9pG8+r+C5+nUJFB86BE8OouZ+0YDXyzVhKW0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449551; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=11lnZvwet+ysZealc1hhi0tpPeui28F8K1OxM5QTCDs=; b=ZQdxoO8pVq7H+mGFe90zz/j12e1rT5wLjehhUMhBNbngOo7jzlHP/BrikkLQnA1XjKhk/MNkohhSEsTe5JIgIdBduUuJ8q/gSKpKdGf9k6HsG2UqigkDCaAk1xPeohVaC9Tkqu9vawitBDNqH8Yl7atwlgunGufPGP7XW/qpMHk= 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+76963+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 1624449551459811.8605687178426; Wed, 23 Jun 2021 04:59:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id o3j5YY1788612x9DuEmC2HNb; Wed, 23 Jun 2021 04:59:11 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.6607.1624449550270732627 for ; Wed, 23 Jun 2021 04:59:10 -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 DFABDED1; Wed, 23 Jun 2021 04:59:09 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9FEED3F718; Wed, 23 Jun 2021 04:59:08 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 5/7] DynamicTablesPkg: Add AmlAttachNode() Date: Wed, 23 Jun 2021 12:58:32 +0100 Message-Id: <20210623115834.907-6-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: UJMt8iQH8qAr1rVBG5pkjrUrx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449551; bh=Tc1jtgZ2PUc0a9EyZa7kN+4NnFz4uMrRje9Ql8KChZQ=; h=Cc:Date:From:Reply-To:Subject:To; b=ZV0wyoU8n6QTCp9p+h6Pb9QcUBE/ENn5RW2CgqyoWmBGtEGrwdOtS0f0tnwcpLTS+mX eLVi5ObipxStVL8UHF0LRXRF4i1Y5dyafSk/S8YzoQOiPTaumw+8XBPtTQG0buozeNlGD w63guuUGNp8mNMjZjAiFIw6HpWK90bHY11w= X-ZohoMail-DKIM: pass (identity @groups.io) 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) } Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../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 4a10da8cd7bb..b4766726e84d 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 (#76963): https://edk2.groups.io/g/devel/message/76963 Mute This Topic: https://groups.io/mt/83735876/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 Sat May 18 07:31:22 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+76964+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+76964+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449553; cv=none; d=zohomail.com; s=zohoarc; b=NggFeNlalYZqQ5Ebvca/Fztvwdcc2hlDOg/viQifxjBBJv42aAaAnfGv5YlEFaJ93ZhSn8gInhiFaxy45R4W3jUUciN7AbHL2qTOYCDnCXMRBR9mDa4fiU+9QxL1cBlEUeAUPJoxrhln2l5MHagSSZjdTmtUK2Ow9g2xyAFceU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449553; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Y62/uO4th4jDs4sWbbyx98vmd5uBfGQhvb2CXjPJmMY=; b=ADT/TO6phi+LtJXfOkS5/G98SvcX6SW2xCP7nbIrPkm5bXx5lFqSK6af5NhaY2dpprmIebSVZUJU9/GaK7/S86NZs4YTY5YHxO6cDJ/X8Vw6WmM3QoOSWeEbq1Nb9x6ZNyNKrB3WwrjhUykF21raZrPsPWoViB1dOmvX4hMhiVs= 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+76964+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 1624449553029654.4787968388908; Wed, 23 Jun 2021 04:59:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UoPTYY1788612xkVWk8udZAh; Wed, 23 Jun 2021 04:59:12 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.6611.1624449552018557736 for ; Wed, 23 Jun 2021 04:59:12 -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 8E4B1ED1; Wed, 23 Jun 2021 04:59:11 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2AC3F3F718; Wed, 23 Jun 2021 04:59:10 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 6/7] DynamicTablesPkg: Add Pci related objects Date: Wed, 23 Jun 2021 12:58:33 +0100 Message-Id: <20210623115834.907-7-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: sr62Rw0EoY2oPH1sLU9KAopPx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449552; bh=0veuqK3cBvPoAUKeECtVsoHqFinPgJw4s8IkVHyMkFA=; h=Cc:Date:From:Reply-To:Subject:To; b=S44ZmagvL9Fy1gGrub4E74UF6tYrZRrbJLfi5r3+03yocy/era/QmXmDCFbUL55jN+z /0J+nC55Qjn9vrCtByIMqruE/XDgh5OwTg4iikip+nZDGGrBkpydCSmGzgB4nrwx+d1+0 d18FXC1wHrSLqgEUEEtFhyMuFVizegq/DaI= X-ZohoMail-DKIM: pass (identity @groups.io) 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. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../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 9c49091def59..b3779f828c17 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 da5f5846edd9..0ba4e6e5faff 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 (#76964): https://edk2.groups.io/g/devel/message/76964 Mute This Topic: https://groups.io/mt/83735880/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 Sat May 18 07:31:22 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+76965+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+76965+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1624449555; cv=none; d=zohomail.com; s=zohoarc; b=dBnTueVkfgrOAKcSWJSAbL+QW6ClPSgyw44X12hzywwMeumJLe9v0cGyjCUINmLk0Ht8J4NBk5u0syS5RTsI49jBcAA8m2cazO9o0OaBwHlVsTjijpzfmAz3angBEN7y4q0xghwdo3CuKoHa/OQv9FcTbuRt2hIKddIUp2LtunE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624449555; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=R8h92WQbrC/zMofoWuUNAGJag2o1Mic1wiKSWEWFdNg=; b=OR9F54NgirKCMi1ONDAFjN84FQXVE2tF7oF+13YfAJnzBD7VeKRLKomh58qnpF45lQzXpWCJR9FB8BBmrTU79Py5T5H0yhvLv1+Z+zz92UFEsDZQQB12ttpzHq+26yCjq7tpS1cJSz2N0+O17dK57feqJ8XOicv5V6ifd5BSKQ8= 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+76965+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 1624449555501670.4455683132422; Wed, 23 Jun 2021 04:59:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id cPfiYY1788612xwUrKg3VHwM; Wed, 23 Jun 2021 04:59:15 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6398.1624449554142739647 for ; Wed, 23 Jun 2021 04:59:14 -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 C5CE9ED1; Wed, 23 Jun 2021 04:59:13 -0700 (PDT) X-Received: from e120189.arm.com (unknown [10.57.78.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 278553F718; Wed, 23 Jun 2021 04:59:11 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei Fedorov Cc: Akanksha Jain , Alexandru Elisei Subject: [edk2-devel] [PATCH v1 7/7] DynamicTablesPkg: SSDT Pci express generator Date: Wed, 23 Jun 2021 12:58:34 +0100 Message-Id: <20210623115834.907-8-Pierre.Gondois@arm.com> In-Reply-To: <20210623115834.907-1-Pierre.Gondois@arm.com> References: <20210623115834.907-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: pQbTiDGUJ4VIZE0ghzY1gMZix1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624449555; bh=KxocmEMYj8KK9ArtCmHRnmsSM2amW6u4NqgARzdrnQ0=; h=Cc:Date:From:Reply-To:Subject:To; b=lPOSv2kbZgEVoJJxbp9XC9jWlHA4WlcOZC44eJJ6NYsA/D0Jl8xMV4ITZqPyRaAywgf VxS3JtJ3PWyUG9FmDdHNl26+TsWIoCccw/m6gAcbAO160ySXhTezTMkFdEgFeQKx3zM94 wLRzy7hfQfS+sm/ohexMh2QFzeBrkuhX9IM= X-ZohoMail-DKIM: pass (identity @groups.io) 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 Signed-off-by: Pierre Gondois --- DynamicTablesPkg/DynamicTables.dsc.inc | 2 + DynamicTablesPkg/Include/AcpiTableGenerator.h | 5 + .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.c | 1417 +++++++++++++++++ .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.h | 134 ++ .../Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf | 32 + .../SsdtPcieOscTemplate.asl | 80 + 6 files changed, 1670 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..478bc60ef6f3 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.c @@ -0,0 +1,1417 @@ +/** @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 +**/ + +#include +#include +#include +#include +#include +#include +#include + +// Module specific include files. +#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 < MAX_PCI_LEGACY_INTERRUPT); + 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]) // 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]) // PCI Segment Group number + Name (_BBN, [Bus number]) // 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, [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, [Pci segment group]) + Status =3D AmlCodeGenNameInteger ( + "_SEG", + PciInfo->PciSegmentGroupNumber, + PciNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Name (_BBN, [Bus number]) + 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 ([Link Name]) { + Name (_UID, [Uid]]) + Name (_HID, EISAID ("PNP0C0F")) + Name (_PRS, ResourceTemplate () { + Interrupt (ResourceProducer, Level, ActiveHigh, Exclusive) { [Irq]] } + }) + Method (_CRS, 0) { Return (_PRS) } + Method (_SRS, 1) { } + 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" + + @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; + } + + // The LNKx devices must be defined before being referenced. + // Thus add it to the head of the Pci list of variable arguments. + Status =3D AmlAttachNode (PciNode, LinkNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + // Failed to add. + AmlDeleteTree ((AML_NODE_HANDLE)LinkNode); + return Status; + } + + // ASL: Name (_UID, [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 (_PRS, ResourceTemplate () { + // Interrupt (ResourceProducer, Level, ActiveHigh, Exclusive) { [Irq] } + // }) + Status =3D AmlCodeGenNameResourceTemplate ("_PRS", 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 (_PRS) + // } + Status =3D AmlCodeGenMethodRetNameString ( + "_CRS", + "_PRS", + 0, + FALSE, + 0, + LinkNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // ASL: Method (_SRS, 1) {} + // Not possible to set interrupts. + Status =3D AmlCodeGenMethodRetNameString ( + "_SRS", + NULL, + 1, + 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. + ASSERT (LastIndex < 32); + + 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, [address value]) + // } + 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); + + // 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_handler; + } + + // ASL: Name (_PRT, Package () {}) + Status =3D AmlCodeGenNamePackage ("_PRT", PciNode, &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 + ); + 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); + return EFI_INVALID_PARAMETER; + } + + // Add the device to the DeviceTable. + MappingTableAdd (&Generator->DeviceTable, IrqMapInfo->PciDevice); + + /* Add a _PRT entry. + ASL + Name (_PRT, Package () { + [OldPrtEntries], + [NewPrtEntry] + }) + + 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. + // To look nicer, do it in reverse order since LNKx are added to the hea= d. + for (Index =3D Generator->IrqTable.LastIndex - 1; Index >=3D 0; Index--)= { + Status =3D GenerateLinkDevice ( + Generator->IrqTable.Table[Index], + IrqFlags, + Index, + PciNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto exit_handler; + } + } // for + + // 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->IrqTable); + MappingTableFree (&Generator->DeviceTable); + + 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 + // [Start], // AddressMinimum - Minimum Bus Number + // [End], // AddressMaximum - Maximum Bus Number + // 0, // AddressTranslation - Set to 0 + // [End] - [Start] + 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 RootNode; + AML_OBJECT_NODE_HANDLE OscNode; + + ASSERT (PciNode !=3D NULL); + + // Parse the Ssdt Pci Osc Template. + SsdtPcieOscTemplate =3D (EFI_ACPI_DESCRIPTION_HEADER*) + ssdtpcieosctemplate_aml_code; + + RootNode =3D NULL; + Status =3D AmlParseDefinitionBlock ( + SsdtPcieOscTemplate, + &RootNode + ); + 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 (RootNode, "\\_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)) { + goto error_handler; + } + +error_handler: + // Cleanup + Status1 =3D AmlDeleteTree (RootNode); + 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] 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_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; + CHAR8 OemTableId[9]; + + ASSERT (Generator !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (PciInfo !=3D NULL); + ASSERT (Table !=3D NULL); + + CopyMem (OemTableId, "SSDTPCIx", sizeof (OemTableId) + 1); + OemTableId[7] =3D AsciiFromHex(Uid); + + // Create a new Ssdt table. + Status =3D AmlCodeGenDefinitionBlock ( + "SSDT", + "ARMLTD", + OemTableId, + 1, + &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, + &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..2b7f40447d87 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerato= r.h @@ -0,0 +1,134 @@ +/** @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 +**/ + +#ifndef SSDT_PCIE_GENERATOR_H_ +#define SSDT_PCIE_GENERATOR_H_ + +/** Pci address attributes. +*/ +#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 address mapping, referencing + CM_ARM_PCI_INTERRUPT_MAP_INFO structures. + + Example (for the interrupt mapping): + (Pci0) + CM_ARM_PCI_CONFIG_SPACE_INFO + | + v + (List of references to address mappings) + CM_ARM_OBJ_REF + | + +---------------------------------------- + | | + v v + (A first interrupt mapping) (A second interrupt mapping) + CM_ARM_PCI_INTERRUPT_MAP_INFO[0] CM_ARM_PCI_INTERRUPT_MAP_INF= O[1] + + 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 (#76965): https://edk2.groups.io/g/devel/message/76965 Mute This Topic: https://groups.io/mt/83735882/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-