]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: AML Code generation for Resource data EndTag
authorPierre Gondois <Pierre.Gondois@arm.com>
Fri, 8 Oct 2021 14:46:22 +0000 (15:46 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 8 Oct 2021 15:39:42 +0000 (15:39 +0000)
Add a helper function AmlCodeGenEndTag() to generate AML Resource Data
EndTag. The EndTag resource data is automatically generated by the ASL
compiler at the end of a list of resource data elements. Therefore, an
equivalent function is not present in ASL.

However, AmlCodeGenEndTag() is useful when generating AML code for the
ResourceTemplate() macro.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c
DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.h

index 20b745f27a2b855281fb198757fb440fe1a0cab4..0bdb6c24c5bb8161e163b60ee7a0558b55510086 100644 (file)
@@ -280,6 +280,119 @@ AmlCodeGenRdRegister (
   return LinkRdNode (RdNode, NameOpNode, NewRdNode);\r
 }\r
 \r
+/** Code generation for the EndTag resource data.\r
+\r
+  The EndTag resource data is automatically generated by the ASL compiler\r
+  at the end of a list of resource data elements. Thus, it doesn't have\r
+  a corresponding ASL function.\r
+\r
+  This function allocates memory to create a data node. It is the caller's\r
+  responsibility to either:\r
+   - attach this node to an AML tree;\r
+   - delete this node.\r
+\r
+  ACPI 6.4, s6.4.2.9 "End Tag":\r
+  "This checksum is generated such that adding it to the sum of all the data\r
+  bytes will produce a zero sum."\r
+  "If the checksum field is zero, the resource data is treated as if the\r
+  checksum operation succeeded. Configuration proceeds normally."\r
+\r
+  To avoid re-computing checksums, if a new resource data elements is\r
+  added/removed/modified in a list of resource data elements, the AmlLib\r
+  resets the checksum to 0.\r
+\r
+  @param [in]  CheckSum        CheckSum to store in the EndTag.\r
+                               To ignore/avoid computing the checksum,\r
+                               give 0.\r
+  @param [in]  ParentNode      If not NULL, add the generated node\r
+                               to the end of the variable list of\r
+                               argument of the ParentNode.\r
+                               The ParentNode must not initially contain\r
+                               an EndTag resource data element.\r
+  @param  [out] NewRdNode      If success, contains the generated node.\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
+  @retval EFI_OUT_OF_RESOURCES    Could not allocate memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AmlCodeGenEndTag (\r
+  IN  UINT8               CheckSum,   OPTIONAL\r
+  IN  AML_OBJECT_NODE   * ParentNode, OPTIONAL\r
+  OUT AML_DATA_NODE    ** NewRdNode   OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  AML_DATA_NODE                 * RdNode;\r
+  EFI_ACPI_END_TAG_DESCRIPTOR     EndTag;\r
+  ACPI_SMALL_RESOURCE_HEADER      SmallResHdr;\r
+\r
+  if ((ParentNode == NULL) && (NewRdNode == NULL)) {\r
+    ASSERT (0);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  RdNode = NULL;\r
+\r
+  // Header\r
+  SmallResHdr.Bits.Length = sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) -\r
+                              sizeof (ACPI_SMALL_RESOURCE_HEADER);\r
+  SmallResHdr.Bits.Name = ACPI_SMALL_END_TAG_DESCRIPTOR_NAME;\r
+  SmallResHdr.Bits.Type = ACPI_SMALL_ITEM_FLAG;\r
+\r
+  // Body\r
+  EndTag.Desc = SmallResHdr.Byte;\r
+  EndTag.Checksum = CheckSum;\r
+\r
+  Status = AmlCreateDataNode (\r
+             EAmlNodeDataTypeResourceData,\r
+             (UINT8*)&EndTag,\r
+             sizeof (EFI_ACPI_END_TAG_DESCRIPTOR),\r
+             &RdNode\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    ASSERT (0);\r
+    return Status;\r
+  }\r
+\r
+  if (NewRdNode != NULL) {\r
+    *NewRdNode = RdNode;\r
+  }\r
+\r
+  if (ParentNode != NULL) {\r
+    // Check the BufferOp doesn't contain any resource data yet.\r
+    // This is a hard check: do not allow to add an EndTag if the BufferNode\r
+    // already has resource data elements attached. Indeed, the EndTag should\r
+    // have already been added.\r
+    if (AmlGetNextVariableArgument ((AML_NODE_HEADER*)ParentNode, NULL) !=\r
+          NULL) {\r
+      ASSERT (0);\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto error_handler;\r
+    }\r
+\r
+    // Add the EndTag RdNode. Indeed, the AmlAppendRdNode function\r
+    // is looking for an EndTag, which we are adding here.\r
+    Status = AmlVarListAddTail (\r
+               (AML_NODE_HEADER*)ParentNode,\r
+               (AML_NODE_HEADER*)RdNode\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      ASSERT (0);\r
+      goto error_handler;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+\r
+error_handler:\r
+  if (RdNode != NULL) {\r
+    AmlDeleteTree ((AML_NODE_HEADER*)RdNode);\r
+  }\r
+  return Status;\r
+}\r
+\r
 // DEPRECATED APIS\r
 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
index 831d6a7462ae872b84ab8e960b100a42a93133ae..10234049593387253b65fad56dbd7b41470beaf4 100644 (file)
@@ -104,4 +104,47 @@ AmlCodeGenRdRegister (
   OUT AML_DATA_NODE_HANDLE    *NewRdNode  OPTIONAL\r
   );\r
 \r
+/** Code generation for the EndTag resource data.\r
+\r
+  The EndTag resource data is automatically generated by the ASL compiler\r
+  at the end of a list of resource data elements. Thus, it doesn't have\r
+  a corresponding ASL function.\r
+\r
+  This function allocates memory to create a data node. It is the caller's\r
+  responsibility to either:\r
+   - attach this node to an AML tree;\r
+   - delete this node.\r
+\r
+  ACPI 6.4, s6.4.2.9 "End Tag":\r
+  "This checksum is generated such that adding it to the sum of all the data\r
+  bytes will produce a zero sum."\r
+  "If the checksum field is zero, the resource data is treated as if the\r
+  checksum operation succeeded. Configuration proceeds normally."\r
+\r
+  To avoid re-computing checksums, if a new resource data elements is\r
+  added/removed/modified in a list of resource data elements, the AmlLib\r
+  resets the checksum to 0.\r
+\r
+  @param [in]  CheckSum        CheckSum to store in the EndTag.\r
+                               To ignore/avoid computing the checksum,\r
+                               give 0.\r
+  @param [in]  ParentNode      If not NULL, add the generated node\r
+                               to the end of the variable list of\r
+                               argument of the ParentNode.\r
+                               The ParentNode must not initially contain\r
+                               an EndTag resource data element.\r
+  @param  [out] NewRdNode      If success, contains the generated node.\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
+  @retval EFI_OUT_OF_RESOURCES    Could not allocate memory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AmlCodeGenEndTag (\r
+  IN  UINT8               CheckSum,   OPTIONAL\r
+  IN  AML_OBJECT_NODE   * ParentNode, OPTIONAL\r
+  OUT AML_DATA_NODE    ** NewRdNode   OPTIONAL\r
+  );\r
+\r
 #endif // AML_RESOURCE_DATA_CODE_GEN_H_\r