From 28b2df475fb214d11ee50f5a924cedee671f0ba1 Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Fri, 8 Oct 2021 15:46:15 +0100 Subject: [PATCH] DynamicTablesPkg: Add AmlRdSetEndTagChecksum() Add AmlRdSetEndTagChecksum(), setting the CheckSum value contained in a Resource Data element. ACPI 6.4, s6.4.2.9 "End Tag": "This checksum is generated such that adding it to the sum of all the data bytes will produce a zero sum." "If the checksum field is zero, the resource data is treated as if the checksum operation succeeded. Configuration proceeds normally." Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../AmlLib/ResourceData/AmlResourceData.c | 33 +++++++++++++++++++ .../AmlLib/ResourceData/AmlResourceData.h | 21 ++++++++++++ 2 files changed, 54 insertions(+) diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c index 8b46c7232d..41cf0bc453 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c +++ b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c @@ -101,3 +101,36 @@ AmlRdGetSize ( return ((ACPI_SMALL_RESOURCE_HEADER*)Header)->Bits.Length + sizeof (ACPI_SMALL_RESOURCE_HEADER); } + +/** Set the Checksum of an EndTag resource data. + + ACPI 6.4, s6.4.2.9 "End Tag": + "This checksum is generated such that adding it to the sum of all the data + bytes will produce a zero sum." + "If the checksum field is zero, the resource data is treated as if the + checksum operation succeeded. Configuration proceeds normally." + + @param [in] Header Pointer to the first byte of a resource data. + @param [in] CheckSum Checksum value to set. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AmlRdSetEndTagChecksum ( + IN CONST AML_RD_HEADER * Header, + IN UINT8 CheckSum + ) +{ + if ((Header == NULL) || + !AmlRdCompareDescId ( + Header, + AML_RD_BUILD_SMALL_DESC_ID (ACPI_SMALL_END_TAG_DESCRIPTOR_NAME))) { + ASSERT (0); + return EFI_INVALID_PARAMETER; + } + + ((EFI_ACPI_END_TAG_DESCRIPTOR*)Header)->Checksum = CheckSum; + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h index 48e4e2aadd..e478107dff 100644 --- a/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h +++ b/DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.h @@ -171,4 +171,25 @@ AmlRdGetSize ( IN CONST AML_RD_HEADER * Header ); +/** Set the Checksum of an EndTag resource data. + + ACPI 6.4, s6.4.2.9 "End Tag": + "This checksum is generated such that adding it to the sum of all the data + bytes will produce a zero sum." + "If the checksum field is zero, the resource data is treated as if the + checksum operation succeeded. Configuration proceeds normally." + + @param [in] Header Pointer to the first byte of a resource data. + @param [in] CheckSum Checksum value to set. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +AmlRdSetEndTagChecksum ( + IN CONST AML_RD_HEADER * Header, + IN UINT8 CheckSum + ); + #endif // AML_RESOURCE_DATA_H_