From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.9252.1639041923168244890 for ; Thu, 09 Dec 2021 01:25:23 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 644191474; Thu, 9 Dec 2021 01:25:16 -0800 (PST) Received: from e126645.nice.arm.com (unknown [10.34.129.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 54CF73F73B; Thu, 9 Dec 2021 01:25:15 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov Subject: [PATCH v4 1/8] DynamicTablesPkg: AML Code generation for memory ranges Date: Thu, 9 Dec 2021 10:24:58 +0100 Message-Id: <20211209092505.1248326-2-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211209092505.1248326-1-Pierre.Gondois@arm.com> References: <20211209092505.1248326-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pierre Gondois Add helper functions to generate AML Resource Data describing memory ranges. Memory ranges can be one, double or four words long. They can be of 'normal', IO or bus number memory type. The following APIs are exposed: - AmlCodeGenRdDWordIo () - AmlCodeGenRdDWordMemory () - AmlCodeGenRdWordBusNumber () - AmlCodeGenRdQWordMemory () To: Sami Mujawar To: Alexei Fedorov Signed-off-by: Pierre Gondois --- Notes: v2: - Correct typos/reformulate descriptions. [Sami] - Add brief description about the parameter in addition to the specification reference. [Sami] .../Include/Library/AmlLib/AmlLib.h | 272 +++++ .../AmlLib/CodeGen/AmlResourceDataCodeGen.c | 951 ++++++++++++++++++ 2 files changed, 1223 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTa= blesPkg/Include/Library/AmlLib/AmlLib.h index 094a8f32c6ff..385d2459d273 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -418,6 +418,278 @@ AmlUpdateRdQWord ( IN UINT64 BaseAddressLength ); =20 +/** Code generation for the "DWordIO ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.34 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] IsaRanges Possible values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] IsDenseTranslation TranslationDensity parameter. + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordIo ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT8 IsaRanges, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN BOOLEAN IsDenseTranslation, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + +/** Code generation for the "DWordMemory ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.35 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and suppor= ts + write combining + 3-The memory is cacheable and prefet= chable + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordMemory ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + +/** Code generation for the "WordBusNumber ()" ASL function. + + The Resource Data effectively created is a Word Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.3 "Word Address Space Descriptor". + - s19.6.149 "WordBusNumber". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.149 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdWordBusNumber ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + +/** Code generation for the "QWordMemory ()" ASL function. + + The Resource Data effectively created is a QWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.110 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and suppor= ts + write combining + 3-The memory is cacheable and prefet= chable + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Not supported. Must be 0. + @param [in] ResourceSource Resource Source. + Not supported. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + 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 Resourc= e diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDa= taCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceD= ataCodeGen.c index 29854634bf41..40d8c2b07ae3 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeG= en.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeG= en.c @@ -101,6 +101,957 @@ error_handler: return Status; } =20 +/** Construct the TypeSpecificFlags field for IO ranges. + + See ACPI 6.4 spec, s19.6.34 for more. + + @param [in] IsaRanges Possible values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + See ACPI 6.4 spec, s19.6.34 for more= . + @param [in] IsDenseTranslation TranslationDensity parameter. + @param [in] IsTypeStatic TranslationType parameter. + + @return A type specific flags value. + MAX_UINT8 if error. +**/ +STATIC +UINT8 +EFIAPI +RdIoRangeSpecificFlags ( + IN UINT8 IsaRanges, + IN BOOLEAN IsDenseTranslation, + IN BOOLEAN IsTypeStatic + ) +{ + // Only check type specific parameters. + if (IsaRanges > 3) { + ASSERT (0); + return MAX_UINT8; + } + + // Construct TypeSpecificFlags and call the generic function. + // Cf ACPI 6.4 specification, Table 6.50: + // "Table 6.50: I/O Resource Flag (Resource Type =3D 1) Definitions" + return IsaRanges | + (IsTypeStatic ? 0 : BIT4) | + (IsDenseTranslation ? 0 : BIT5); +} + +/** Construct the TypeSpecificFlags field for Memory ranges. + + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and suppor= ts + write combining + 3-The memory is cacheable and prefet= chable + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + See ACPI 6.4 spec, s19.6.35 for more= . + @param [in] IsTypeStatic TranslationType parameter. + + @return A type specific flags value. + MAX_UINT8 if error. +**/ +STATIC +UINT8 +EFIAPI +MemoryRangeSpecificFlags ( + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic + ) +{ + // Only check type specific parameters. + if ((Cacheable > 3) || + (MemoryRangeType > 3)) + { + ASSERT (0); + return MAX_UINT8; + } + + // Construct TypeSpecificFlags and call the generic function. + // Cf ACPI 6.4 specification, Table 6.49: + // "Memory Resource Flag (Resource Type =3D 0) Definitions" + return (IsReadWrite ? BIT0 : 0) | + (Cacheable << 1) | + (MemoryRangeType << 3) | + (IsTypeStatic ? 0 : BIT5); +} + +/** Construct the GeneralFlags field of any Address Space Resource Descr= iptors. + + E.g.: + ACPI 6.4 specification, s6.4.3.5.1 "QWord Address Space Descriptor" + for QWord + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + + @return A type specific flags value. +**/ +STATIC +UINT8 +EFIAPI +AddressSpaceGeneralFlags ( + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed + ) +{ + return (IsPosDecode ? 0 : BIT1) | + (IsMinFixed ? BIT2 : 0) | + (IsMaxFixed ? BIT3 : 0); +} + +/** Check Address Space Descriptor Fields. + + Cf. ACPI 6.4 Table 6.44: + "Valid Combination of Address Space Descriptor Fields" + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +STATIC +EFI_STATUS +EFIAPI +CheckAddressSpaceFields ( + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength + ) +{ + if ((AddressMinimum > AddressMaximum) || + (RangeLength > (AddressMaximum - AddressMinimum + 1)) || + ((AddressGranularity !=3D 0) && + (((AddressGranularity + 1) & AddressGranularity) !=3D 0))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + if (RangeLength !=3D 0) { + if (IsMinFixed ^ IsMaxFixed) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMinFixed && + IsMaxFixed && + (AddressGranularity !=3D 0) && + ((AddressMaximum - AddressMinimum + 1) !=3D RangeLength)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } else { + if (IsMinFixed && IsMaxFixed) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMinFixed && + ((AddressMinimum & AddressGranularity) !=3D 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } else if (IsMaxFixed && + (((AddressMaximum + 1) & AddressGranularity) !=3D 0)) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +/** Code generation for the "DWordSpace ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.36 for more. + + @param [in] ResourceType Resource type. + Possible values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + See ACPI 6.4 spec, s6.4.3.5.2 for mo= re. + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] TypeSpecificFlags Type specific flags. + See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordSpace ( + IN UINT8 ResourceType, + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 TypeSpecificFlags, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE *RdNode; + EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR RdDWord; + + // ResourceSource and ResourceSourceIndex are unused. + if ((TypeSpecificFlags =3D=3D MAX_UINT8) || + (ResourceSourceIndex !=3D 0) || + (ResourceSource !=3D NULL) || + ((NameOpNode =3D=3D NULL) && (NewRdNode =3D=3D NULL))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D CheckAddressSpaceFields ( + IsMinFixed, + IsMaxFixed, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Header + RdDWord.Header.Header.Bits.Name =3D + ACPI_LARGE_DWORD_ADDRESS_SPACE_DESCRIPTOR_NAME; + RdDWord.Header.Header.Bits.Type =3D ACPI_LARGE_ITEM_FLAG; + RdDWord.Header.Length =3D sizeof (EFI_ACPI_DWORD_ADDRESS_SPA= CE_DESCRIPTOR) - + sizeof (ACPI_LARGE_RESOURCE_HEADER); + + // Body + RdDWord.ResType =3D ResourceType; + RdDWord.GenFlag =3D AddressSpaceGeneralFlags ( + IsPosDecode, + IsMinFixed, + IsMaxFixed + ); + RdDWord.SpecificFlag =3D TypeSpecificFlags; + RdDWord.AddrSpaceGranularity =3D AddressGranularity; + RdDWord.AddrRangeMin =3D AddressMinimum; + RdDWord.AddrRangeMax =3D AddressMaximum; + RdDWord.AddrTranslationOffset =3D AddressTranslation; + RdDWord.AddrLen =3D RangeLength; + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8 *)&RdDWord, + sizeof (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR), + &RdNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (RdNode, NameOpNode, NewRdNode); +} + +/** Code generation for the "DWordIO ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.34 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] IsaRanges Possible values are: + 0-Reserved + 1-NonISAOnly + 2-ISAOnly + 3-EntireRange + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] IsDenseTranslation TranslationDensity parameter. + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordIo ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT8 IsaRanges, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN BOOLEAN IsDenseTranslation, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + return AmlCodeGenRdDWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_IO, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + RdIoRangeSpecificFlags ( + IsaRanges, + IsDenseTranslation, + IsTypeStatic + ), + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + +/** Code generation for the "DWordMemory ()" ASL function. + + The Resource Data effectively created is a DWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.35 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and suppor= ts + write combining + 3-The memory is cacheable and prefet= chable + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdDWordMemory ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 Cacheable, + IN BOOLEAN IsReadWrite, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN UINT8 MemoryRangeType, + IN BOOLEAN IsTypeStatic, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + return AmlCodeGenRdDWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_MEM, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + MemoryRangeSpecificFlags ( + Cacheable, + IsReadWrite, + MemoryRangeType, + IsTypeStatic + ), + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + +/** Code generation for the "WordSpace ()" ASL function. + + The Resource Data effectively created is a Word Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.3 "Word Address Space Descriptor". + - s19.6.151 "WordSpace". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.151 for more. + + @param [in] ResourceType Resource type. + Possible values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + See ACPI 6.4 spec, s6.4.3.5.3 for mo= re. + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] TypeSpecificFlags Type specific flags. + See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenRdWordSpace ( + IN UINT8 ResourceType, + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 TypeSpecificFlags, + IN UINT16 AddressGranularity, + IN UINT16 AddressMinimum, + IN UINT16 AddressMaximum, + IN UINT16 AddressTranslation, + IN UINT16 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE *RdNode; + EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR Rdword; + + // ResourceSource and ResourceSourceIndex are unused. + if ((TypeSpecificFlags =3D=3D MAX_UINT8) || + (ResourceSourceIndex !=3D 0) || + (ResourceSource !=3D NULL) || + ((NameOpNode =3D=3D NULL) && (NewRdNode =3D=3D NULL))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D CheckAddressSpaceFields ( + IsMinFixed, + IsMaxFixed, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Header + Rdword.Header.Header.Bits.Name =3D + ACPI_LARGE_WORD_ADDRESS_SPACE_DESCRIPTOR_NAME; + Rdword.Header.Header.Bits.Type =3D ACPI_LARGE_ITEM_FLAG; + Rdword.Header.Length =3D sizeof (EFI_ACPI_WORD_ADDRESS_SPACE= _DESCRIPTOR) - + sizeof (ACPI_LARGE_RESOURCE_HEADER); + + // Body + Rdword.ResType =3D ResourceType; + Rdword.GenFlag =3D AddressSpaceGeneralFlags ( + IsPosDecode, + IsMinFixed, + IsMaxFixed + ); + Rdword.SpecificFlag =3D TypeSpecificFlags; + Rdword.AddrSpaceGranularity =3D AddressGranularity; + Rdword.AddrRangeMin =3D AddressMinimum; + Rdword.AddrRangeMax =3D AddressMaximum; + Rdword.AddrTranslationOffset =3D AddressTranslation; + Rdword.AddrLen =3D RangeLength; + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8 *)&Rdword, + sizeof (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR), + &RdNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (RdNode, NameOpNode, NewRdNode); +} + +/** Code generation for the "WordBusNumber ()" ASL function. + + The Resource Data effectively created is a Word Address Space Resource + Data. Cf ACPI 6.4: + - s6.4.3.5.3 "Word Address Space Descriptor". + - s19.6.149 "WordBusNumber". + + The created resource data node can be: + - appended to the list of resource data elements of the NameOpNode. + In such case NameOpNode must be defined by a the "Name ()" ASL stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.149 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] IsPosDecode Decode parameter + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdWordBusNumber ( + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN BOOLEAN IsPosDecode, + IN UINT32 AddressGranularity, + IN UINT32 AddressMinimum, + IN UINT32 AddressMaximum, + IN UINT32 AddressTranslation, + IN UINT32 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + // There is no Type Specific Flags for buses. + return AmlCodeGenRdWordSpace ( + ACPI_ADDRESS_SPACE_TYPE_BUS, + IsResourceConsumer, + IsPosDecode, + IsMinFixed, + IsMaxFixed, + 0, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength, + ResourceSourceIndex, + ResourceSource, + NameOpNode, + NewRdNode + ); +} + +/** Code generation for the "QWordSpace ()" ASL function. + + The Resource Data effectively created is a QWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.111 for more. + + @param [in] ResourceType Resource type. + Possible values are: + 0: Memory range + 1: I/O range + 2: Bus number range + 3-191: Reserved + 192-255: Hardware Vendor Defined + See ACPI 6.4 spec, s6.4.3.5.1 for mo= re. + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] TypeSpecificFlags Type specific flags. + See ACPI 6.4 spec, s6.4.3.5.5 + "Resource Type Specific Flags". + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + of this node. + @param [out] NewRdNode If provided and success, + contain the created node. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenRdQWordSpace ( + IN UINT8 ResourceType, + IN BOOLEAN IsResourceConsumer, + IN BOOLEAN IsPosDecode, + IN BOOLEAN IsMinFixed, + IN BOOLEAN IsMaxFixed, + IN UINT8 TypeSpecificFlags, + IN UINT64 AddressGranularity, + IN UINT64 AddressMinimum, + IN UINT64 AddressMaximum, + IN UINT64 AddressTranslation, + IN UINT64 RangeLength, + IN UINT8 ResourceSourceIndex, + IN CONST CHAR8 *ResourceSource, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_DATA_NODE *RdNode; + EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR RdQword; + + // ResourceSource and ResourceSourceIndex are unused. + if ((TypeSpecificFlags =3D=3D MAX_UINT8) || + (ResourceSourceIndex !=3D 0) || + (ResourceSource !=3D NULL) || + ((NameOpNode =3D=3D NULL) && (NewRdNode =3D=3D NULL))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + Status =3D CheckAddressSpaceFields ( + IsMinFixed, + IsMaxFixed, + AddressGranularity, + AddressMinimum, + AddressMaximum, + AddressTranslation, + RangeLength + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + // Header + RdQword.Header.Header.Bits.Name =3D + ACPI_LARGE_QWORD_ADDRESS_SPACE_DESCRIPTOR_NAME; + RdQword.Header.Header.Bits.Type =3D ACPI_LARGE_ITEM_FLAG; + RdQword.Header.Length =3D sizeof (EFI_ACPI_QWORD_ADDRESS_SPA= CE_DESCRIPTOR) - + sizeof (ACPI_LARGE_RESOURCE_HEADER); + + // Body + RdQword.ResType =3D ResourceType; + RdQword.GenFlag =3D AddressSpaceGeneralFlags ( + IsPosDecode, + IsMinFixed, + IsMaxFixed + ); + RdQword.SpecificFlag =3D TypeSpecificFlags; + RdQword.AddrSpaceGranularity =3D AddressGranularity; + RdQword.AddrRangeMin =3D AddressMinimum; + RdQword.AddrRangeMax =3D AddressMaximum; + RdQword.AddrTranslationOffset =3D AddressTranslation; + RdQword.AddrLen =3D RangeLength; + + Status =3D AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8 *)&RdQword, + sizeof (EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR), + &RdNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (RdNode, NameOpNode, NewRdNode); +} + +/** Code generation for the "QWordMemory ()" ASL function. + + The Resource Data effectively created is a QWord Address Space Resourc= e + 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 stat= ement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + See ACPI 6.4 spec, s19.6.110 for more. + + @param [in] IsResourceConsumer ResourceUsage parameter. + @param [in] IsPosDecode Decode parameter. + @param [in] IsMinFixed Minimum address is fixed. + @param [in] IsMaxFixed Maximum address is fixed. + @param [in] Cacheable Possible values are: + 0-The memory is non-cacheable + 1-The memory is cacheable + 2-The memory is cacheable and suppor= ts + write combining + 3-The memory is cacheable and prefet= chable + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] AddressGranularity Address granularity. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] AddressTranslation Address translation. + @param [in] RangeLength Range length. + @param [in] ResourceSourceIndex Resource Source index. + Unused. Must be 0. + @param [in] ResourceSource Resource Source. + Unused. Must be NULL. + @param [in] MemoryRangeType Possible values are: + 0-AddressRangeMemory + 1-AddressRangeReserved + 2-AddressRangeACPI + 3-AddressRangeNVS + @param [in] IsTypeStatic TranslationType parameter. + @param [in] NameOpNode NameOp object node defining a named = object. + If provided, append the new resource= data + node to the list of resource data el= ements + 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 Resourc= e --=20 2.25.1