From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.4943.1685501296784865639 for ; Tue, 30 May 2023 19:48:17 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=MG7wC4JL; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: vincentx.ke@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685501296; x=1717037296; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=jh7iJYc3M6KJJDpmhsb7mXuBTAOWselrQ4XTdnPzuXU=; b=MG7wC4JL15SPKSDWID+XAPZbWq3sVFsfXITvocthD8PuiIDn3E6o8r2l wb+YE1VFPoUZ7XKnzMly3ksN3MeZzktC1fo/2fbriOO1YWmxSIRUfkWYZ CcvcoCjMsBc0F5JkW+fUcQsh82o9K8Oy9NXB1dC/cVxjDnnkYwMTPrHwL k0+LZw/8J17FYjmB1XrDiHJUxz0vf5+21Sa+Ez4ZpWtzzT03PdEIB9vYK ZmxyDfrglZa6SyqkiOC0kbRprzEsgWfwlmpxqVJDF4xIpFaZr+Srl0d8I LWadPTp4TjHDPk/449Hc+sZtJGFFqkLkHs9rBAyttMGlqnkWFCMs86LPi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="335462871" X-IronPort-AV: E=Sophos;i="6.00,205,1681196400"; d="scan'208";a="335462871" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 19:48:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="796511104" X-IronPort-AV: E=Sophos;i="6.00,205,1681196400"; d="scan'208";a="796511104" Received: from kxinfux-desk.gar.corp.intel.com ([10.227.107.32]) by FMSMGA003.fm.intel.com with ESMTP; 30 May 2023 19:48:10 -0700 From: "VincentX Ke" To: devel@edk2.groups.io Cc: VincentX Ke , Chasel Chiu , Nate DeSimone , Isaac Oram , Liming Gao , Eric Dong , Ankit Sinha Subject: [PATCH v10] MinPlatformPkg: Update HWSignature field in FACS Date: Wed, 31 May 2023 10:48:06 +0800 Message-Id: <20230531024806.374-1-vincentx.ke@intel.com> X-Mailer: git-send-email 2.39.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: VincentX Ke REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4428 Calculating CRC based on each ACPI table. Update HWSignature field in FACS based on CRC while ACPI table changed. Change-Id: Ic0ca66ff10cda0fbcd0683020fab1bc9aea9b78c Signed-off-by: VincentX Ke Cc: Chasel Chiu Cc: Nate DeSimone Cc: Isaac Oram Cc: Liming Gao Cc: Eric Dong Cc: Ankit Sinha Signed-off-by: VincentX Ke --- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 284 +++++= ++++++++++----- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 1 + 2 files changed, 217 insertions(+), 68 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b= /Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index 2f2c96f907..2a833ec99c 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -1191,98 +1191,246 @@ PlatformUpdateTables ( }=0D =0D /**=0D - This function calculates RCR based on PCI Device ID and Vendor ID from t= he devices=0D - available on the platform.=0D - It also includes other instances of BIOS change to calculate CRC and pro= vides as=0D - HWSignature filed in FADT table.=0D + Function prototype for GetAcpiTableCount/CalculateAcpiTableCrc.=0D +=0D + @param[in] Table The pointer to ACPI table.=0D + @param[in] TableIndex The ACPI table index.=0D + @param[in] Context The pointer to UINTN for GetAcpiTableCount.=0D + The pointer to UINT32 array for CalculateAcpiTab= leCrc.=0D **/=0D +typedef=0D VOID=0D -IsHardwareChange (=0D - VOID=0D +(EFIAPI *ACPI_TABLE_CALLBACK)(=0D + IN EFI_ACPI_COMMON_HEADER *Table,=0D + IN UINTN TableIndex,=0D + IN VOID *Context=0D + );=0D +=0D +/**=0D + Enumerate all ACPI tables in RSDT/XSDT.=0D +=0D + @param[in] Sdt ACPI XSDT/RSDT.=0D + @param[in] TablePointerSize Size of table pointer:=0D + 4(RSDT) or 8(XSDT).=0D + @param[in] CallbackFunction The pointer to GetAcpiTableCount/Calculate= AcpiTableCrc.=0D + @param[in] Context The pointer to UINTN for GetAcpiTableCount= .=0D + The pointer to UINT32 array for CalculateA= cpiTableCrc.=0D +**/=0D +VOID=0D +EnumerateAllAcpiTables (=0D + IN EFI_ACPI_DESCRIPTION_HEADER *Sdt,=0D + IN UINTN TablePointerSize,=0D + IN ACPI_TABLE_CALLBACK CallbackFunction,=0D + IN VOID *Context=0D )=0D {=0D - EFI_STATUS Status;=0D - UINTN Index;=0D - UINTN HandleCount;=0D - EFI_HANDLE *HandleBuffer;=0D - EFI_PCI_IO_PROTOCOL *PciIo;=0D - UINT32 CRC;=0D - UINT32 *HWChange;=0D - UINTN HWChangeSize;=0D - UINT32 PciId;=0D - UINTN Handle;=0D - EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr;=0D - EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *pFADT;=0D -=0D - HandleCount =3D 0;=0D - HandleBuffer =3D NULL;=0D -=0D - Status =3D gBS->LocateHandleBuffer (=0D - ByProtocol,=0D - &gEfiPciIoProtocolGuid,=0D - NULL,=0D - &HandleCount,=0D - &HandleBuffer=0D - );=0D - if (EFI_ERROR (Status)) {=0D - return; // PciIO protocol not installed yet!=0D + UINTN Index;=0D + UINTN TableIndex;=0D + UINTN EntryCount;=0D + UINT64 EntryPtr;=0D + UINTN BasePtr;=0D + EFI_ACPI_COMMON_HEADER *Table;=0D + EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr;=0D +=0D + Index =3D 0;=0D + TableIndex =3D 0;=0D + EntryCount =3D (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Ta= blePointerSize;=0D + EntryPtr =3D 0;=0D + BasePtr =3D (UINTN)(Sdt + 1);=0D + Table =3D NULL;=0D + FadtPtr =3D NULL;=0D +=0D + if (Sdt =3D=3D NULL) {=0D + ASSERT (Sdt !=3D NULL);=0D + return;=0D }=0D =0D - //=0D - // Allocate memory for HWChange and add additional entrie for=0D - // pFADT->XDsdt=0D - //=0D - HWChangeSize =3D HandleCount + 1;=0D - HWChange =3D AllocateZeroPool (sizeof(UINT32) * HWChangeSize);=0D - ASSERT(HWChange !=3D NULL);=0D + for (Index =3D 0; Index < EntryCount; Index++) {=0D + EntryPtr =3D 0;=0D + Table =3D NULL;=0D + CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * TablePointerSize), Tabl= ePointerSize);=0D + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr));=0D + if (Table !=3D NULL) {=0D + CallbackFunction (Table, TableIndex++, Context);=0D + }=0D +=0D + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_= SIGNATURE) {=0D + FadtPtr =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table;=0D + if (FadtPtr->Header.Revision < EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_T= ABLE_REVISION) {=0D + //=0D + // Locate FACS/DSDT in FADT=0D + //=0D + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Firmwa= reCtrl, TableIndex++, Context);=0D + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt, = TableIndex++, Context);=0D + } else {=0D + //=0D + // Locate FACS in FADT=0D + //=0D + if (FadtPtr->XFirmwareCtrl !=3D 0) {=0D + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XFir= mwareCtrl, TableIndex++, Context);=0D + } else {=0D + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Firm= wareCtrl, TableIndex++, Context);=0D + }=0D +=0D + //=0D + // Locate DSDT in FADT=0D + //=0D + if (FadtPtr->XDsdt !=3D 0) {=0D + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XDsd= t, TableIndex++, Context);=0D + } else {=0D + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt= , TableIndex++, Context);=0D + }=0D + }=0D + }=0D + }=0D +}=0D +=0D +/**=0D + Count the number of ACPI tables.=0D +=0D + @param[in] Table The pointer to ACPI table.=0D + @param[in] TableIndex The ACPI table index.=0D + @param[in] Context The pointer to UINTN.=0D +**/=0D +VOID=0D +EFIAPI=0D +GetAcpiTableCount (=0D + IN EFI_ACPI_COMMON_HEADER *Table,=0D + IN UINTN TableIndex,=0D + IN VOID *Context=0D + )=0D +{=0D + UINTN *TableCount;=0D +=0D + TableCount =3D (UINTN *)Context;=0D +=0D + if (Table =3D=3D NULL) {=0D + ASSERT (Table !=3D NULL);=0D + return;=0D + }=0D +=0D + (*TableCount)++;=0D +}=0D =0D - if (HWChange =3D=3D NULL) return;=0D +/**=0D + Calculate CRC based on each offset in the ACPI table.=0D +=0D + @param[in] Table The pointer to ACPI table.=0D + @param[in] TableIndex The ACPI table index.=0D + @param[in] Context The pointer to UINT32 array.=0D +**/=0D +VOID=0D +EFIAPI=0D +CalculateAcpiTableCrc (=0D + IN EFI_ACPI_COMMON_HEADER *Table,=0D + IN UINTN TableIndex,=0D + IN VOID *Context=0D + )=0D +{=0D + UINT32 *TableCrcRecord;=0D +=0D + TableCrcRecord =3D (UINT32 *)Context;=0D +=0D + if (Table =3D=3D NULL) {=0D + ASSERT (Table !=3D NULL);=0D + return;=0D + }=0D =0D //=0D - // add HWChange inputs: PCI devices=0D + // Calculate CRC value.=0D //=0D - for (Index =3D 0; HandleCount > 0; HandleCount--) {=0D - PciId =3D 0;=0D - Status =3D gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtoco= lGuid, (VOID **) &PciIo);=0D - if (!EFI_ERROR (Status)) {=0D - Status =3D PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &PciId= );=0D - if (EFI_ERROR (Status)) {=0D - continue;=0D - }=0D - HWChange[Index++] =3D PciId;=0D + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE= _SIGNATURE) {=0D + //=0D + // Zero HardwareSignature field before Calculating FACS CRC=0D + //=0D + ((EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)Table)->HardwareSigna= ture =3D 0;=0D + }=0D +=0D + gBS->CalculateCrc32 ((UINT8 *)Table, (UINTN)Table->Length, &TableCrcReco= rd[TableIndex]);=0D +}=0D +=0D +/**=0D + This function calculates CRC based on each ACPI table.=0D + It also calculates CRC and provides as HardwareSignature field in FACS.= =0D +**/=0D +VOID=0D +IsAcpiTableChange (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + BOOLEAN IsRsdt;=0D + UINTN AcpiTableCount;=0D + UINT32 *TableCrcRecord;=0D + EFI_ACPI_6_5_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;=0D + EFI_ACPI_DESCRIPTION_HEADER *Rsdt;=0D + EFI_ACPI_DESCRIPTION_HEADER *Xsdt;=0D + EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr;=0D +=0D + IsRsdt =3D FALSE;=0D + AcpiTableCount =3D 0;=0D + TableCrcRecord =3D NULL;=0D + Rsdp =3D NULL;=0D + Rsdt =3D NULL;=0D + Xsdt =3D NULL;=0D + FacsPtr =3D NULL;=0D +=0D + DEBUG ((DEBUG_INFO, "%a() - Start\n", __FUNCTION__));=0D +=0D + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)= &Rsdp);=0D + if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) {=0D + return;=0D + }=0D +=0D + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;=0D + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;=0D + if (Xsdt =3D=3D NULL) {=0D + if (Rsdt !=3D NULL) {=0D + IsRsdt =3D TRUE;=0D + } else {=0D + return;=0D }=0D }=0D =0D + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)EfiLocateFir= stAcpiTable (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE);=0D + if (FacsPtr =3D=3D NULL) {=0D + return;=0D + }=0D +=0D //=0D - // Locate FACP Table=0D + // Count the ACPI tables found by RSDT/XSDT and FADT.=0D //=0D - Handle =3D 0;=0D - Status =3D LocateAcpiTableBySignature (=0D - EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE,=0D - (EFI_ACPI_DESCRIPTION_HEADER **) &pFADT,=0D - &Handle=0D - );=0D - if (EFI_ERROR (Status) || (pFADT =3D=3D NULL)) {=0D - return; //Table not found or out of memory resource for pFADT table=0D + if (IsRsdt) {=0D + EnumerateAllAcpiTables (Rsdt, sizeof (UINT32), GetAcpiTableCount, (VOI= D *)&AcpiTableCount);=0D + } else {=0D + EnumerateAllAcpiTables (Xsdt, sizeof (UINT64), GetAcpiTableCount, (VOI= D *)&AcpiTableCount);=0D }=0D =0D //=0D - // add HWChange inputs: others=0D + // Allocate memory for founded ACPI tables.=0D //=0D - HWChange[Index++] =3D (UINT32)pFADT->XDsdt;=0D + TableCrcRecord =3D AllocateZeroPool (sizeof (UINT32) * AcpiTableCount);= =0D + if (TableCrcRecord =3D=3D NULL) {=0D + return;=0D + }=0D =0D //=0D - // Calculate CRC value with HWChange data.=0D + // Calculate CRC for each ACPI table and set record.=0D //=0D - Status =3D gBS->CalculateCrc32(HWChange, HWChangeSize, &CRC);=0D - DEBUG ((DEBUG_INFO, "CRC =3D %x and Status =3D %r\n", CRC, Status));=0D + if (IsRsdt) {=0D + EnumerateAllAcpiTables (Rsdt, sizeof (UINT32), CalculateAcpiTableCrc, = (VOID *)TableCrcRecord);=0D + } else {=0D + EnumerateAllAcpiTables (Xsdt, sizeof (UINT64), CalculateAcpiTableCrc, = (VOID *)TableCrcRecord);=0D + }=0D =0D //=0D - // Set HardwareSignature value based on CRC value.=0D + // Calculate and set HardwareSignature data.=0D //=0D - FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN) pFAD= T->FirmwareCtrl;=0D - FacsPtr->HardwareSignature =3D CRC;=0D - FreePool (HWChange);=0D + Status =3D gBS->CalculateCrc32 ((UINT8 *)TableCrcRecord, AcpiTableCount,= &(FacsPtr->HardwareSignature));=0D + DEBUG ((DEBUG_INFO, "HardwareSignature =3D %x and Status =3D %r\n", Facs= Ptr->HardwareSignature, Status));=0D +=0D + FreePool (TableCrcRecord);=0D + DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__));=0D }=0D =0D VOID=0D @@ -1329,7 +1477,7 @@ AcpiEndOfDxeEvent ( //=0D // Calculate Hardware Signature value based on current platform configur= ations=0D //=0D - IsHardwareChange ();=0D + IsAcpiTableChange ();=0D }=0D =0D /**=0D 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=0D gEfiHobListGuid ## CONSUMES=0D gEfiEndOfDxeEventGroupGuid ## CONSUMES=0D + gEfiAcpiTableGuid ## CONSUMES=0D =0D [Depex]=0D gEfiAcpiTableProtocolGuid AND=0D --=20 2.39.2.windows.1