From: "VincentX Ke" <vincentx.ke@intel.com>
To: devel@edk2.groups.io
Cc: VincentX Ke <vincentx.ke@intel.com>,
Chasel Chiu <chasel.chiu@intel.com>,
Nate DeSimone <nathaniel.l.desimone@intel.com>,
Isaac Oram <isaac.w.oram@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Eric Dong <eric.dong@intel.com>
Subject: [PATCH v3] MinPlatformPkg: Update HWSignature filed in FADT
Date: Fri, 28 Apr 2023 10:56:59 +0800 [thread overview]
Message-ID: <20230428025659.692-1-vincentx.ke@intel.com> (raw)
From: VincentX Ke <vincentx.ke@intel.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4428
Calculating CRC based on checksum from all ACPI tables.
Update HWSignature filed in FADT based on CRC while ACPI table changed.
Signed-off-by: VincentX Ke <vincentx.ke@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 110 +++++++++++++++++++-
Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 1 +
2 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index e967031a3b..d84c1d4f6d 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -1285,6 +1285,108 @@ IsHardwareChange (
FreePool (HWChange);
}
+/**
+ This function calculates RCR based on Checksum from all ACPI tables.
+ It also calculates CRC and provides as HWSignature filed in FADT table.
+**/
+VOID
+IsAcpiTableChange (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ UINTN AcpiTableCount;
+ UINT32 Table;
+ UINT32 CRC;
+ UINT32 *AcpiTable;
+ EFI_ACPI_6_5_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
+ EFI_ACPI_DESCRIPTION_HEADER *Rsdt;
+ EFI_ACPI_DESCRIPTION_HEADER *Xsdt;
+ EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr;
+ EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *pFADT;
+
+ AcpiTableCount = 0;
+ AcpiTable = NULL;
+ Rsdp = NULL;
+ Rsdt = NULL;
+ Xsdt = NULL;
+ FacsPtr = NULL;
+ pFADT = NULL;
+
+ DEBUG ((DEBUG_INFO, "%a() - Start\n", __FUNCTION__));
+
+ Status = EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)&Rsdp);
+ if (EFI_ERROR (Status) || (Rsdp == NULL)) {
+ return;
+ }
+
+ //
+ // ACPI table count starts with 2 as RSDT and XSDT are already located.
+ // Then add ACPI tables found by XSDT and FADT.
+ //
+ Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;
+ Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;
+ AcpiTableCount = AcpiTableCount + 2;
+ AcpiTableCount = AcpiTableCount + (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER))/sizeof (UINT64);
+
+ for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < (Xsdt->Length); Index = Index + sizeof (UINT64)) {
+ Table = *((UINT32 *)((UINT8 *)Xsdt + Index));
+ if (((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Table)->Signature == EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
+ pFADT = (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)Table;
+ if ((pFADT->XDsdt != 0) || (pFADT->Dsdt != 0)) {
+ AcpiTableCount = AcpiTableCount + 1;
+ }
+ }
+ }
+
+ //
+ // Allocate memory for founded ACPI tables.
+ //
+ AcpiTable = AllocateZeroPool (sizeof (UINT32) * AcpiTableCount);
+ if (AcpiTable == NULL) {
+ return;
+ }
+
+ AcpiTableCount = 0;
+ AcpiTable[AcpiTableCount++] = Rsdt->Checksum;
+ AcpiTable[AcpiTableCount++] = Xsdt->Checksum;
+
+ for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < (Xsdt->Length); Index = Index + sizeof (UINT64)) {
+ Table = *((UINT32 *)((UINT8 *)Xsdt + Index));
+ AcpiTable[AcpiTableCount++] = ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Table)->Checksum;
+ if (((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Table)->Signature == EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
+ pFADT = (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)Table;
+ if (pFADT->XDsdt != 0) {
+ AcpiTable[AcpiTableCount++] = ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)pFADT->XDsdt)->Checksum;
+ } else {
+ AcpiTable[AcpiTableCount++] = ((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)pFADT->Dsdt)->Checksum;
+ }
+ }
+ }
+
+ //
+ // pFADT table not found.
+ //
+ if (pFADT == NULL) {
+ return;
+ }
+
+ //
+ // Calculate CRC value.
+ //
+ Status = gBS->CalculateCrc32 (AcpiTable, AcpiTableCount, &CRC);
+ DEBUG ((DEBUG_INFO, "CRC = %x and Status = %r\n", CRC, Status));
+
+ //
+ // Set HardwareSignature value based on CRC value.
+ //
+ FacsPtr = (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)pFADT->FirmwareCtrl;
+ FacsPtr->HardwareSignature = CRC;
+ FreePool (AcpiTable);
+ DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__));
+}
+
VOID
UpdateLocalTable (
VOID
@@ -1329,7 +1431,13 @@ AcpiEndOfDxeEvent (
//
// Calculate Hardware Signature value based on current platform configurations
//
- IsHardwareChange ();
+ if ((PcdGet8 (PcdFadtMajorVersion) <= EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) &&
+ (PcdGet8 (PcdFadtMinorVersion) <= EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION))
+ {
+ IsHardwareChange ();
+ } else {
+ IsAcpiTableChange ();
+ }
}
/**
diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf
index 694492112b..f47cc3908d 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf
@@ -128,6 +128,7 @@
gEfiGlobalVariableGuid ## CONSUMES
gEfiHobListGuid ## CONSUMES
gEfiEndOfDxeEventGroupGuid ## CONSUMES
+ gEfiAcpiTableGuid ## CONSUMES
[Depex]
gEfiAcpiTableProtocolGuid AND
--
2.39.2.windows.1
next reply other threads:[~2023-04-28 2:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-28 2:56 VincentX Ke [this message]
2023-04-28 3:08 ` [edk2-devel] [PATCH v3] MinPlatformPkg: Update HWSignature filed in FADT Ni, Ray
2023-04-28 3:30 ` VincentX Ke
2023-04-28 3:46 ` VincentX Ke
2023-04-28 3:54 ` Ni, Ray
2023-05-03 2:44 ` VincentX Ke
[not found] ` <1759FCFBF7AAA148.29517@groups.io>
2023-04-28 5:02 ` Ni, Ray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230428025659.692-1-vincentx.ke@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox