* [PATCH 0/3] Add Memory32Fixed and AmlCodeGenMethodRetInteger functions @ 2022-01-08 21:57 Rebecca Cran 2022-01-08 21:57 ` [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function Rebecca Cran ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Rebecca Cran @ 2022-01-08 21:57 UTC (permalink / raw) To: devel, Sami Mujawar, Alexei Fedorov, Leif Lindholm; +Cc: Rebecca Cran Add functions to generate code for the Memory32Fixed ASL macro and a method returning an Integer. Remove a redundant cast from AmlCodeGenReturn. Rebecca Cran (3): DynamicTablesPkg: Add Memory32Fixed function DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 80 ++++++++++ DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 158 +++++++++++++++++++- DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c | 59 ++++++++ 3 files changed, 296 insertions(+), 1 deletion(-) -- 2.31.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function 2022-01-08 21:57 [PATCH 0/3] Add Memory32Fixed and AmlCodeGenMethodRetInteger functions Rebecca Cran @ 2022-01-08 21:57 ` Rebecca Cran 2022-01-11 11:34 ` [edk2-devel] " PierreGondois 2022-01-08 21:57 ` [PATCH 2/3] DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn Rebecca Cran 2022-01-08 21:57 ` [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function Rebecca Cran 2 siblings, 1 reply; 8+ messages in thread From: Rebecca Cran @ 2022-01-08 21:57 UTC (permalink / raw) To: devel, Sami Mujawar, Alexei Fedorov, Leif Lindholm; +Cc: Rebecca Cran Add a Memory32Fixed function to generate code for the corresponding Memory32Fixed macro in AML. Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> --- DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 33 +++++++++++ DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c | 59 ++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index af18bf8e4871..8b3e80b61466 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -592,6 +592,39 @@ AmlCodeGenRdDWordMemory ( OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL ); +/** Code generation for the "Memory32Fixed ()" ASL macro. + + The Resource Data effectively created is a 32-bit Memory Resource + Data. Cf ACPI 6.4: + - s19.6.83 "Memory Resource Descriptor Macro". + - s19.2.8 "Memory32FixedTerm". + + See ACPI 6.4 spec, s19.2.8 for more. + + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] Address AddressBase parameter. + @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] NewMemNode 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 +AmlCodeGenMemory32Fixed ( + BOOLEAN IsReadWrite, + UINT32 Address, + UINT32 RangeLength, + AML_OBJECT_NODE_HANDLE NameOpNode, + AML_DATA_NODE_HANDLE *NewMemNode + ); + /** Code generation for the "WordBusNumber ()" ASL function. The Resource Data effectively created is a Word Address Space Resource diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c index 40d8c2b07ae3..b9e8429cc6ca 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c @@ -609,6 +609,65 @@ AmlCodeGenRdDWordMemory ( ); } +/** Code generation for the "Memory32Fixed ()" ASL macro. + + The Resource Data effectively created is a 32-bit Memory Resource + Data. Cf ACPI 6.4: + - s19.6.83 "Memory Resource Descriptor Macro". + - s19.2.8 "Memory32FixedTerm". + + See ACPI 6.4 spec, s19.2.8 for more. + + @param [in] IsReadWrite ReadAndWrite parameter. + @param [in] Addres AddressBase parameter. + @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] NewMemNode 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 +AmlCodeGenMemory32Fixed ( + BOOLEAN IsReadWrite, + UINT32 Address, + UINT32 RangeLength, + AML_OBJECT_NODE_HANDLE NameOpNode, + AML_DATA_NODE_HANDLE *NewMemNode + ) +{ + EFI_STATUS Status; + AML_DATA_NODE *MemNode; + UINT8 Data[12]; + + Data[0] = 0x86; + Data[1] = 0x09; + Data[2] = 0x00; + Data[3] = IsReadWrite; + Data[4] = Address & 0xFF; + Data[5] = (Address & 0xFF00) >> 8; + Data[6] = (Address & 0xFF0000) >> 16; + Data[7] = (Address & 0xFF000000) >> 24; + Data[8] = RangeLength & 0xFF; + Data[9] = (RangeLength & 0xFF00) >> 8; + Data[10] = (RangeLength & 0xFF0000) >> 16; + Data[11] = (RangeLength & 0xFF000000) >> 24; + + Status = AmlCreateDataNode (EAmlNodeDataTypeResourceData, Data, sizeof (Data), &MemNode); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + return LinkRdNode (MemNode, NameOpNode, NewMemNode); +} + /** Code generation for the "WordSpace ()" ASL function. The Resource Data effectively created is a Word Address Space Resource -- 2.31.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function 2022-01-08 21:57 ` [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function Rebecca Cran @ 2022-01-11 11:34 ` PierreGondois 2022-01-11 17:37 ` Rebecca Cran 0 siblings, 1 reply; 8+ messages in thread From: PierreGondois @ 2022-01-11 11:34 UTC (permalink / raw) To: devel, quic_rcran, Sami Mujawar, Alexei Fedorov, Leif Lindholm Hello Rebecca, On 1/8/22 10:57 PM, Rebecca Cran via groups.io wrote: > Add a Memory32Fixed function to generate code for the corresponding > Memory32Fixed macro in AML. > > Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> > --- > DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 33 +++++++++++ > DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c | 59 ++++++++++++++++++++ > 2 files changed, 92 insertions(+) > > diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > index af18bf8e4871..8b3e80b61466 100644 > --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > @@ -592,6 +592,39 @@ AmlCodeGenRdDWordMemory ( > OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL > ); > > +/** Code generation for the "Memory32Fixed ()" ASL macro. > + > + The Resource Data effectively created is a 32-bit Memory Resource > + Data. Cf ACPI 6.4: > + - s19.6.83 "Memory Resource Descriptor Macro". > + - s19.2.8 "Memory32FixedTerm". > + > + See ACPI 6.4 spec, s19.2.8 for more. > + > + @param [in] IsReadWrite ReadAndWrite parameter. > + @param [in] Address AddressBase parameter. > + @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] NewMemNode 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 > +AmlCodeGenMemory32Fixed ( > + BOOLEAN IsReadWrite, > + UINT32 Address, > + UINT32 RangeLength, > + AML_OBJECT_NODE_HANDLE NameOpNode, > + AML_DATA_NODE_HANDLE *NewMemNode > + ); > + > /** Code generation for the "WordBusNumber ()" ASL function. > > The Resource Data effectively created is a Word Address Space Resource > diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c > index 40d8c2b07ae3..b9e8429cc6ca 100644 > --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c > +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c > @@ -609,6 +609,65 @@ AmlCodeGenRdDWordMemory ( > ); > } > > +/** Code generation for the "Memory32Fixed ()" ASL macro. > + > + The Resource Data effectively created is a 32-bit Memory Resource I think there are 2 spaces for the indentation (instead of 1 above). > + Data. Cf ACPI 6.4: > + - s19.6.83 "Memory Resource Descriptor Macro". > + - s19.2.8 "Memory32FixedTerm". > + > + See ACPI 6.4 spec, s19.2.8 for more. > + > + @param [in] IsReadWrite ReadAndWrite parameter. > + @param [in] Addres AddressBase parameter. > + @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] NewMemNode 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 > +AmlCodeGenMemory32Fixed ( > + BOOLEAN IsReadWrite, > + UINT32 Address, > + UINT32 RangeLength, > + AML_OBJECT_NODE_HANDLE NameOpNode, > + AML_DATA_NODE_HANDLE *NewMemNode > + ) > +{ > + EFI_STATUS Status; > + AML_DATA_NODE *MemNode; > + UINT8 Data[12]; > + > + Data[0] = 0x86; > + Data[1] = 0x09; > + Data[2] = 0x00; > + Data[3] = IsReadWrite; Is it possible to use BITx instead as this is a bit field, as: = IsReadWrite ? BIT0 : 0; > + Data[4] = Address & 0xFF; > + Data[5] = (Address & 0xFF00) >> 8; > + Data[6] = (Address & 0xFF0000) >> 16; > + Data[7] = (Address & 0xFF000000) >> 24; > + Data[8] = RangeLength & 0xFF; > + Data[9] = (RangeLength & 0xFF00) >> 8; > + Data[10] = (RangeLength & 0xFF0000) >> 16; > + Data[11] = (RangeLength & 0xFF000000) >> 24; Is it possible to use a EFI_ACPI_32_BIT_MEMORY_RANGE_DESCRIPTOR structure instead of a raw buffer ? > + > + Status = AmlCreateDataNode (EAmlNodeDataTypeResourceData, Data, sizeof (Data), &MemNode); > + if (EFI_ERROR (Status)) { > + ASSERT (0); > + return Status; > + } > + > + return LinkRdNode (MemNode, NameOpNode, NewMemNode); > +} > + > /** Code generation for the "WordSpace ()" ASL function. > > The Resource Data effectively created is a Word Address Space Resource Thanks for the patch, Regards, Pierre ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function 2022-01-11 11:34 ` [edk2-devel] " PierreGondois @ 2022-01-11 17:37 ` Rebecca Cran 0 siblings, 0 replies; 8+ messages in thread From: Rebecca Cran @ 2022-01-11 17:37 UTC (permalink / raw) To: Pierre Gondois, devel, Sami Mujawar, Alexei Fedorov, Leif Lindholm Thanks. I've fixed these issues in the v2 patch which I'll send out soon. -- Rebecca Cran On 1/11/22 04:34, Pierre Gondois wrote: > Hello Rebecca, > > On 1/8/22 10:57 PM, Rebecca Cran via groups.io wrote: >> Add a Memory32Fixed function to generate code for the corresponding >> Memory32Fixed macro in AML. >> >> Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> >> --- >> DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 33 +++++++++++ >> DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c | 59 ++++++++++++++++++++ >> 2 files changed, 92 insertions(+) >> >> diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h >> index af18bf8e4871..8b3e80b61466 100644 >> --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h >> +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h >> @@ -592,6 +592,39 @@ AmlCodeGenRdDWordMemory ( >> OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL >> ); >> >> +/** Code generation for the "Memory32Fixed ()" ASL macro. >> + >> + The Resource Data effectively created is a 32-bit Memory Resource >> + Data. Cf ACPI 6.4: >> + - s19.6.83 "Memory Resource Descriptor Macro". >> + - s19.2.8 "Memory32FixedTerm". >> + >> + See ACPI 6.4 spec, s19.2.8 for more. >> + >> + @param [in] IsReadWrite ReadAndWrite parameter. >> + @param [in] Address AddressBase parameter. >> + @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] NewMemNode 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 >> +AmlCodeGenMemory32Fixed ( >> + BOOLEAN IsReadWrite, >> + UINT32 Address, >> + UINT32 RangeLength, >> + AML_OBJECT_NODE_HANDLE NameOpNode, >> + AML_DATA_NODE_HANDLE *NewMemNode >> + ); >> + >> /** Code generation for the "WordBusNumber ()" ASL function. >> >> The Resource Data effectively created is a Word Address Space Resource >> diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c >> index 40d8c2b07ae3..b9e8429cc6ca 100644 >> --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c >> +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c >> @@ -609,6 +609,65 @@ AmlCodeGenRdDWordMemory ( >> ); >> } >> >> +/** Code generation for the "Memory32Fixed ()" ASL macro. >> + >> + The Resource Data effectively created is a 32-bit Memory Resource > I think there are 2 spaces for the indentation (instead of 1 above). >> + Data. Cf ACPI 6.4: >> + - s19.6.83 "Memory Resource Descriptor Macro". >> + - s19.2.8 "Memory32FixedTerm". >> + >> + See ACPI 6.4 spec, s19.2.8 for more. >> + >> + @param [in] IsReadWrite ReadAndWrite parameter. >> + @param [in] Addres AddressBase parameter. >> + @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] NewMemNode 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 >> +AmlCodeGenMemory32Fixed ( >> + BOOLEAN IsReadWrite, >> + UINT32 Address, >> + UINT32 RangeLength, >> + AML_OBJECT_NODE_HANDLE NameOpNode, >> + AML_DATA_NODE_HANDLE *NewMemNode >> + ) >> +{ >> + EFI_STATUS Status; >> + AML_DATA_NODE *MemNode; >> + UINT8 Data[12]; >> + >> + Data[0] = 0x86; >> + Data[1] = 0x09; >> + Data[2] = 0x00; >> + Data[3] = IsReadWrite; > Is it possible to use BITx instead as this is a bit field, as: > > = IsReadWrite ? BIT0 : 0; > >> + Data[4] = Address & 0xFF; >> + Data[5] = (Address & 0xFF00) >> 8; >> + Data[6] = (Address & 0xFF0000) >> 16; >> + Data[7] = (Address & 0xFF000000) >> 24; >> + Data[8] = RangeLength & 0xFF; >> + Data[9] = (RangeLength & 0xFF00) >> 8; >> + Data[10] = (RangeLength & 0xFF0000) >> 16; >> + Data[11] = (RangeLength & 0xFF000000) >> 24; > Is it possible to use a EFI_ACPI_32_BIT_MEMORY_RANGE_DESCRIPTOR structure instead of a raw buffer ? >> + >> + Status = AmlCreateDataNode (EAmlNodeDataTypeResourceData, Data, sizeof (Data), &MemNode); >> + if (EFI_ERROR (Status)) { >> + ASSERT (0); >> + return Status; >> + } >> + >> + return LinkRdNode (MemNode, NameOpNode, NewMemNode); >> +} >> + >> /** Code generation for the "WordSpace ()" ASL function. >> >> The Resource Data effectively created is a Word Address Space Resource > Thanks for the patch, > > Regards, > > Pierre > ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn 2022-01-08 21:57 [PATCH 0/3] Add Memory32Fixed and AmlCodeGenMethodRetInteger functions Rebecca Cran 2022-01-08 21:57 ` [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function Rebecca Cran @ 2022-01-08 21:57 ` Rebecca Cran 2022-01-11 11:35 ` [edk2-devel] " PierreGondois 2022-01-08 21:57 ` [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function Rebecca Cran 2 siblings, 1 reply; 8+ messages in thread From: Rebecca Cran @ 2022-01-08 21:57 UTC (permalink / raw) To: devel, Sami Mujawar, Alexei Fedorov, Leif Lindholm; +Cc: Rebecca Cran In AmlCodeGenReturn, the cast to AML_NODE_HEADER* in the call to AmlSetFixedArgument is redundant because ReturnNode is already a AML_NODE_HEADER* . Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> --- DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index d245848ce3fa..838a892c6b58 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1564,7 +1564,7 @@ AmlCodeGenReturn ( Status = AmlSetFixedArgument ( ObjectNode, EAmlParseIndexTerm0, - (AML_NODE_HEADER *)ReturnNode + ReturnNode ); if (EFI_ERROR (Status)) { ASSERT (0); -- 2.31.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH 2/3] DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn 2022-01-08 21:57 ` [PATCH 2/3] DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn Rebecca Cran @ 2022-01-11 11:35 ` PierreGondois 0 siblings, 0 replies; 8+ messages in thread From: PierreGondois @ 2022-01-11 11:35 UTC (permalink / raw) To: devel, quic_rcran, Sami Mujawar, Alexei Fedorov, Leif Lindholm Hello Rebecca, The patch looks good to me, Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> On 1/8/22 10:57 PM, Rebecca Cran via groups.io wrote: > In AmlCodeGenReturn, the cast to AML_NODE_HEADER* in the call to > AmlSetFixedArgument is redundant because ReturnNode is already a > AML_NODE_HEADER* . > > Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> > --- > DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c > index d245848ce3fa..838a892c6b58 100644 > --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c > +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c > @@ -1564,7 +1564,7 @@ AmlCodeGenReturn ( > Status = AmlSetFixedArgument ( > ObjectNode, > EAmlParseIndexTerm0, > - (AML_NODE_HEADER *)ReturnNode > + ReturnNode > ); > if (EFI_ERROR (Status)) { > ASSERT (0); ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function 2022-01-08 21:57 [PATCH 0/3] Add Memory32Fixed and AmlCodeGenMethodRetInteger functions Rebecca Cran 2022-01-08 21:57 ` [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function Rebecca Cran 2022-01-08 21:57 ` [PATCH 2/3] DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn Rebecca Cran @ 2022-01-08 21:57 ` Rebecca Cran 2022-01-11 11:38 ` [edk2-devel] " PierreGondois 2 siblings, 1 reply; 8+ messages in thread From: Rebecca Cran @ 2022-01-08 21:57 UTC (permalink / raw) To: devel, Sami Mujawar, Alexei Fedorov, Leif Lindholm; +Cc: Rebecca Cran Add AmlCodeGenMethodRetInteger function to generate AML code for a Method returning an Integer. Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> --- DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 47 ++++++ DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 156 ++++++++++++++++++++ 2 files changed, 203 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h index 8b3e80b61466..e47cf99eaa37 100644 --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h @@ -1118,6 +1118,53 @@ AmlCodeGenMethodRetNameString ( OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL ); +/** AML code generation for a method returning an Integer. + + AmlCodeGenMethodRetInteger ( + "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(_CBA, 1, Serialized, 3) { + Return (0) + } + + The ASL parameters "ReturnType" and "ParameterTypes" are not asked + in this function. They are optional parameters in ASL. + + @param [in] MethodNameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedInteger The value of the integer returned by the + method. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 15. + Default is 0 in ASL. + @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 +AmlCodeGenMethodRetInteger ( + IN CONST CHAR8 *MethodNameString, + IN UINT64 ReturnedInteger, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ); + /** Create a _LPI name. AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index 838a892c6b58..07822ead5b70 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1685,6 +1685,61 @@ exit_handler: return Status; } +/** AML code generation for a Return object node, + returning an Integer. + + AmlCodeGenReturn (0), ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Return (0) + + The ACPI 6.3 specification, 20.2.8 "Statement Opcodes Encoding" states: + DefReturn := ReturnOp ArgObject + ReturnOp := 0xA4 + ArgObject := TermArg => DataRefObject + + Thus, the ReturnNode must be evaluated as a DataRefObject. + + The ReturnNode must be generated inside a Method body scope. + + @param [in] Integer The integer is returned by the Return + ASL statement. + @param [in] ParentNode If provided, set ParentNode as the parent + of the node created. + Must be a MethodOp node. + @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. +**/ +STATIC +EFI_STATUS +EFIAPI +AmlCodeGenReturnInteger ( + IN UINT64 Integer, + IN AML_NODE_HEADER *ParentNode OPTIONAL, + OUT AML_OBJECT_NODE **NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE *IntNode; + + IntNode = NULL; + + Status = AmlCodeGenInteger (Integer, &IntNode); + ASSERT_EFI_ERROR (Status); + + // AmlCodeGenReturn() deletes DataNode if error. + Status = AmlCodeGenReturn ( + (AML_NODE_HEADER *)IntNode, + ParentNode, + NewObjectNode + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + /** AML code generation for a method returning a NameString. AmlCodeGenMethodRetNameString ( @@ -1793,6 +1848,107 @@ error_handler: return Status; } +/** AML code generation for a method returning an Integer. + + AmlCodeGenMethodRetInteger ( + "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode + ); + is equivalent of the following ASL code: + Method(_CBA, 1, Serialized, 3) { + Return (0) + } + + The ASL parameters "ReturnType" and "ParameterTypes" are not asked + in this function. They are optional parameters in ASL. + + @param [in] MethodNameString The new Method's name. + Must be a NULL-terminated ASL NameString + e.g.: "MET0", "_SB.MET0", etc. + The input string is copied. + @param [in] ReturnedInteger The value of the integer returned by the + method. + @param [in] NumArgs Number of arguments. + Must be 0 <= NumArgs <= 6. + @param [in] IsSerialized TRUE is equivalent to Serialized. + FALSE is equivalent to NotSerialized. + Default is NotSerialized in ASL spec. + @param [in] SyncLevel Synchronization level for the method. + Must be 0 <= SyncLevel <= 15. + Default is 0 in ASL. + @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 +AmlCodeGenMethodRetInteger ( + IN CONST CHAR8 *MethodNameString, + IN UINT64 ReturnedInteger, + IN UINT8 NumArgs, + IN BOOLEAN IsSerialized, + IN UINT8 SyncLevel, + IN AML_NODE_HANDLE ParentNode OPTIONAL, + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL + ) +{ + EFI_STATUS Status; + AML_OBJECT_NODE_HANDLE MethodNode; + + if ((MethodNameString == NULL) || + ((ParentNode == NULL) && (NewObjectNode == NULL))) + { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + // Create a Method named MethodNameString. + Status = AmlCodeGenMethod ( + MethodNameString, + NumArgs, + IsSerialized, + SyncLevel, + NULL, + &MethodNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + return Status; + } + + Status = AmlCodeGenReturnInteger ( + ReturnedInteger, + (AML_NODE_HANDLE)MethodNode, + NULL + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + Status = LinkNode ( + MethodNode, + ParentNode, + NewObjectNode + ); + if (EFI_ERROR (Status)) { + ASSERT (0); + goto error_handler; + } + + return Status; + +error_handler: + if (MethodNode != NULL) { + AmlDeleteTree ((AML_NODE_HANDLE)MethodNode); + } + + return Status; +} + /** Create a _LPI name. AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is -- 2.31.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function 2022-01-08 21:57 ` [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function Rebecca Cran @ 2022-01-11 11:38 ` PierreGondois 0 siblings, 0 replies; 8+ messages in thread From: PierreGondois @ 2022-01-11 11:38 UTC (permalink / raw) To: devel, quic_rcran, Sami Mujawar, Alexei Fedorov, Leif Lindholm Hello Rebecca, This patch looks good to me: Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> On 1/8/22 10:57 PM, Rebecca Cran via groups.io wrote: > Add AmlCodeGenMethodRetInteger function to generate AML code for > a Method returning an Integer. > > Signed-off-by: Rebecca Cran <quic_rcran@quicinc.com> > --- > DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h | 47 ++++++ > DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c | 156 ++++++++++++++++++++ > 2 files changed, 203 insertions(+) > > diff --git a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > index 8b3e80b61466..e47cf99eaa37 100644 > --- a/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > +++ b/DynamicTablesPkg/Include/Library/AmlLib/AmlLib.h > @@ -1118,6 +1118,53 @@ AmlCodeGenMethodRetNameString ( > OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL > ); > > +/** AML code generation for a method returning an Integer. > + > + AmlCodeGenMethodRetInteger ( > + "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode > + ); > + is equivalent of the following ASL code: > + Method(_CBA, 1, Serialized, 3) { > + Return (0) > + } > + > + The ASL parameters "ReturnType" and "ParameterTypes" are not asked > + in this function. They are optional parameters in ASL. > + > + @param [in] MethodNameString The new Method's name. > + Must be a NULL-terminated ASL NameString > + e.g.: "MET0", "_SB.MET0", etc. > + The input string is copied. > + @param [in] ReturnedInteger The value of the integer returned by the > + method. > + @param [in] NumArgs Number of arguments. > + Must be 0 <= NumArgs <= 6. > + @param [in] IsSerialized TRUE is equivalent to Serialized. > + FALSE is equivalent to NotSerialized. > + Default is NotSerialized in ASL spec. > + @param [in] SyncLevel Synchronization level for the method. > + Must be 0 <= SyncLevel <= 15. > + Default is 0 in ASL. > + @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 > +AmlCodeGenMethodRetInteger ( > + IN CONST CHAR8 *MethodNameString, > + IN UINT64 ReturnedInteger, > + IN UINT8 NumArgs, > + IN BOOLEAN IsSerialized, > + IN UINT8 SyncLevel, > + IN AML_NODE_HANDLE ParentNode OPTIONAL, > + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL > + ); > + > /** Create a _LPI name. > > AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is diff --git a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c index 838a892c6b58..07822ead5b70 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlCodeGen.c @@ -1685,6 +1685,61 @@ exit_handler: return Status; } +/** AML code generation for a Return object node, + returning an Integer. + + AmlCodeGenReturn (0), ParentNode, NewObjectNode) is + equivalent of the following ASL code: + Return (0) + + The ACPI 6.3 specification, 20.2.8 "Statement Opcodes Encoding" states: > + DefReturn := ReturnOp ArgObject > + ReturnOp := 0xA4 > + ArgObject := TermArg => DataRefObject > + > + Thus, the ReturnNode must be evaluated as a DataRefObject. > + > + The ReturnNode must be generated inside a Method body scope. > + > + @param [in] Integer The integer is returned by the Return > + ASL statement. > + @param [in] ParentNode If provided, set ParentNode as the parent > + of the node created. > + Must be a MethodOp node. > + @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. > +**/ > +STATIC > +EFI_STATUS > +EFIAPI > +AmlCodeGenReturnInteger ( > + IN UINT64 Integer, > + IN AML_NODE_HEADER *ParentNode OPTIONAL, > + OUT AML_OBJECT_NODE **NewObjectNode OPTIONAL > + ) > +{ > + EFI_STATUS Status; > + AML_OBJECT_NODE *IntNode; > + > + IntNode = NULL; > + > + Status = AmlCodeGenInteger (Integer, &IntNode); > + ASSERT_EFI_ERROR (Status); > + > + // AmlCodeGenReturn() deletes DataNode if error. > + Status = AmlCodeGenReturn ( > + (AML_NODE_HEADER *)IntNode, > + ParentNode, > + NewObjectNode > + ); > + ASSERT_EFI_ERROR (Status); > + > + return Status; > +} > + > /** AML code generation for a method returning a NameString. > > AmlCodeGenMethodRetNameString ( > @@ -1793,6 +1848,107 @@ error_handler: > return Status; > } > > +/** AML code generation for a method returning an Integer. > + > + AmlCodeGenMethodRetInteger ( > + "_CBA", 0, 1, TRUE, 3, ParentNode, NewObjectNode > + ); > + is equivalent of the following ASL code: > + Method(_CBA, 1, Serialized, 3) { > + Return (0) > + } > + > + The ASL parameters "ReturnType" and "ParameterTypes" are not asked > + in this function. They are optional parameters in ASL. > + > + @param [in] MethodNameString The new Method's name. > + Must be a NULL-terminated ASL NameString > + e.g.: "MET0", "_SB.MET0", etc. > + The input string is copied. > + @param [in] ReturnedInteger The value of the integer returned by the > + method. > + @param [in] NumArgs Number of arguments. > + Must be 0 <= NumArgs <= 6. > + @param [in] IsSerialized TRUE is equivalent to Serialized. > + FALSE is equivalent to NotSerialized. > + Default is NotSerialized in ASL spec. > + @param [in] SyncLevel Synchronization level for the method. > + Must be 0 <= SyncLevel <= 15. > + Default is 0 in ASL. > + @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 > +AmlCodeGenMethodRetInteger ( > + IN CONST CHAR8 *MethodNameString, > + IN UINT64 ReturnedInteger, > + IN UINT8 NumArgs, > + IN BOOLEAN IsSerialized, > + IN UINT8 SyncLevel, > + IN AML_NODE_HANDLE ParentNode OPTIONAL, > + OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL > + ) > +{ > + EFI_STATUS Status; > + AML_OBJECT_NODE_HANDLE MethodNode; > + > + if ((MethodNameString == NULL) || > + ((ParentNode == NULL) && (NewObjectNode == NULL))) > + { > + ASSERT (0); > + return EFI_INVALID_PARAMETER; > + } > + > + // Create a Method named MethodNameString. > + Status = AmlCodeGenMethod ( > + MethodNameString, > + NumArgs, > + IsSerialized, > + SyncLevel, > + NULL, > + &MethodNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT (0); > + return Status; > + } > + > + Status = AmlCodeGenReturnInteger ( > + ReturnedInteger, > + (AML_NODE_HANDLE)MethodNode, > + NULL > + ); > + if (EFI_ERROR (Status)) { > + ASSERT (0); > + goto error_handler; > + } > + > + Status = LinkNode ( > + MethodNode, > + ParentNode, > + NewObjectNode > + ); > + if (EFI_ERROR (Status)) { > + ASSERT (0); > + goto error_handler; > + } > + > + return Status; > + > +error_handler: > + if (MethodNode != NULL) { > + AmlDeleteTree ((AML_NODE_HANDLE)MethodNode); > + } > + > + return Status; > +} > + > /** Create a _LPI name. > > AmlCreateLpiNode ("_LPI", 0, 1, ParentNode, &LpiNode) is ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-01-11 17:37 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-01-08 21:57 [PATCH 0/3] Add Memory32Fixed and AmlCodeGenMethodRetInteger functions Rebecca Cran 2022-01-08 21:57 ` [PATCH 1/3] DynamicTablesPkg: Add Memory32Fixed function Rebecca Cran 2022-01-11 11:34 ` [edk2-devel] " PierreGondois 2022-01-11 17:37 ` Rebecca Cran 2022-01-08 21:57 ` [PATCH 2/3] DynamicTablesPkg: Remove redundant cast in AmlCodeGenReturn Rebecca Cran 2022-01-11 11:35 ` [edk2-devel] " PierreGondois 2022-01-08 21:57 ` [PATCH 3/3] DynamicTablesPkg: Add AmlCodeGenMethodRetInteger function Rebecca Cran 2022-01-11 11:38 ` [edk2-devel] " PierreGondois
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox