diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index 7c130736b4..13ce97c3dd 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -1028,6 +1028,48 @@ AmlCodeGenRdInterrupt ( OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL ); +/** Code generation for the "IO ()" ASL function. + + The Resource Data effectively created is a IO Resource + Data. Cf ACPI 6.5: + - s19.6.65 IO (IO Resource Descriptor Macro) + - s6.4.2.5 I/O Port Descriptor + + 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 statement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + @param [in] IsDecoder16 Decoder parameter. + TRUE if 16-bit decoder. + FALSE if 10-bit decoder. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] Alignment Alignment. + @param [in] RangeLength Range length. + @param [in] NameOpNode NameOp object node defining a named object. + If provided, append the new resource data + node to the list of resource data elements + 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. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdIo ( + IN BOOLEAN IsDecoder16, + IN UINT16 AddressMinimum, + IN UINT16 AddressMaximum, + IN UINT8 Alignment, + IN UINT8 RangeLength, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ); + /** AML code generation for DefinitionBlock. Create a Root Node handle. diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c index 46243f981c..3db536dddf 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c @@ -1475,6 +1475,89 @@ AmlCodeGenRdRegister ( return LinkRdNode (RdNode, NameOpNode, NewRdNode); } +/** Code generation for the "IO ()" ASL function. + + The Resource Data effectively created is a IO Resource + Data. Cf ACPI 6.5: + - s19.6.65 IO (IO Resource Descriptor Macro) + - s6.4.2.5 I/O Port Descriptor + + 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 statement + and initially contain a "ResourceTemplate ()". + - returned through the NewRdNode parameter. + + @param [in] IsDecoder16 Decoder parameter. + TRUE if 16-bit decoder. + FALSE if 10-bit decoder. + @param [in] AddressMinimum Minimum address. + @param [in] AddressMaximum Maximum address. + @param [in] Alignment Alignment. + @param [in] RangeLength Range length. + @param [in] NameOpNode NameOp object node defining a named object. + If provided, append the new resource data + node to the list of resource data elements + 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. +**/ +EFI_STATUS +EFIAPI +AmlCodeGenRdIo ( + IN BOOLEAN IsDecoder16, + IN UINT16 AddressMinimum, + IN UINT16 AddressMaximum, + IN UINT8 Alignment, + IN UINT8 RangeLength, + IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL + OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_ACPI_IO_PORT_DESCRIPTOR IoDesc; + AML_DATA_NODE *IoNode; + + if (AddressMinimum > AddressMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Alignment != 0) { + /// check the alignment + if ((AddressMinimum % Alignment) != 0) { + return EFI_INVALID_PARAMETER; + } + + if ((AddressMaximum % Alignment) != 0) { + return EFI_INVALID_PARAMETER; + } + } + + IoDesc.Header.Byte = ACPI_IO_PORT_DESCRIPTOR; + IoDesc.Information = IsDecoder16 ? BIT0 : 0; + + IoDesc.BaseAddressMin = AddressMinimum; + IoDesc.BaseAddressMax = AddressMaximum; + IoDesc.Alignment = Alignment; + IoDesc.Length = RangeLength; + + Status = AmlCreateDataNode ( + EAmlNodeDataTypeResourceData, + (UINT8 *)&IoDesc, + sizeof (IoDesc), + &IoNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (IoNode, NameOpNode, NewRdNode); +} + /** Code generation for the EndTag resource data. The EndTag resource data is automatically generated by the ASL compiler