From nobody Thu Apr 25 22:56:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105073+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105073+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1684492203; cv=none; d=zohomail.com; s=zohoarc; b=dv2GbHNqXd1TQzjpCVeNDUrz5gsHqgl2/sfS7Qvb/gzrQeEYVYYmSN4gqRl7U6EqP1vGrEPlAmS3n7RKQXPL4tt0LFb0myRq/Fj+FyC0+QhY6e4SgplGOG8Uoii5TFXST24ubRf/Z+swnFsLDtMuY/3w+JG2U39Q/lTbb+87A78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684492203; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=XPsGk1+tcmDOB85oNrWFLoAhWScdDnfUOzWIzLJG7gI=; b=Qf2BCEN0Q8LSuzDoytSKHTVEBx57YiGSvvl8H7Elw5u2DhZ0/aRQIXTlCswFFeK5vQXYViXxfREwR1M/fggIvt8c+YUmrI/ShaR+BdvGmW5uXGqSOPezfN9MQhxIGnGwFD0mlzwQEWZexCahuLonMk8cJLXpdqpAW8ELty2w8UI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105073+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1684492203637492.4696758286557; Fri, 19 May 2023 03:30:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PqiLYY1788612xnTZuvtko1k; Fri, 19 May 2023 03:30:03 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.22344.1684492201591804214 for ; Fri, 19 May 2023 03:30:01 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="355565306" X-IronPort-AV: E=Sophos;i="6.00,176,1681196400"; d="scan'208";a="355565306" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2023 03:29:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="876802722" X-IronPort-AV: E=Sophos;i="6.00,176,1681196400"; d="scan'208";a="876802722" X-Received: from kxinfux-desk.gar.corp.intel.com ([10.227.107.32]) by orsmga005.jf.intel.com with ESMTP; 19 May 2023 03:29:53 -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: [edk2-devel] [PATCH v8] MinPlatformPkg: Update HWSignature filed in FACS Date: Fri, 19 May 2023 18:29:28 +0800 Message-Id: <20230519102928.155-1-vincentx.ke@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,vincentx.ke@intel.com X-Gm-Message-State: Z3ER4Ssijx0RXjTzG2X9zrxHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1684492203; bh=u7tgGK+1nnAyNBz2FNYMumJOaRdSUAe8j9RELJo/P/U=; h=Cc:Date:From:Reply-To:Subject:To; b=DPeN1FOkLM3Z8jO9+3PX0KCliOz0lo8bzqjqEIrzREl45FltcMXYVU6IPfWMshrPN7k 9quE23VhNnpFxmFlZXLXRRooXAeyk2xd+JHjvwisYzuScK6SDyuePay5YeuQcHweeYTyz P66EUOsJ5x2/scAcJVwP49qdWgJ3X3z54a8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1684492205968100003 Content-Type: text/plain; charset="utf-8" From: VincentX Ke REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4428 Calculating CRC based on each ACPI table. Update HWSignature filed 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 | 299 +++++= ++++++++++----- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 1 + 2 files changed, 233 insertions(+), 67 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b= /Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index 2f2c96f907..5005d1a524 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -1191,98 +1191,263 @@ PlatformUpdateTables ( } =20 /** - This function calculates RCR based on PCI Device ID and Vendor ID from t= he devices - available on the platform. - It also includes other instances of BIOS change to calculate CRC and pro= vides as - HWSignature filed in FADT table. + This function calculates CRC based on each offset in the ACPI table. + + @param[in] Table The ACPI table required to calculate CRC. + + @retval CRC A pointer to allocate UINT32 that + contains the CRC32 data. +**/ +UINT32 +AcpiTableCrcCalculator ( + IN EFI_ACPI_COMMON_HEADER *Table + ) +{ + EFI_STATUS Status; + UINT32 CRC; + + Status =3D EFI_SUCCESS; + CRC =3D 0; + + // + // Calculate CRC value. + // + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE= _SIGNATURE) { + // + // Zero HardwareSignature field before Calculating FACS CRC + // + ((EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)Table)->HardwareSigna= ture =3D 0; + } + + Status =3D gBS->CalculateCrc32 ((UINT8 *)Table, (UINTN)Table->Length, &C= RC); + return CRC; +} + +/** + This function count ACPI tables in RSDT/XSDT and return the result. + + @param[in] Sdt ACPI XSDT/RSDT. + @param[in] TablePointerSize Size of table pointer: + 4(RSDT) or 8(XSDT). + + @retval TableCount The total number of ACPI tables in + RSDT or XSDT. +**/ +UINTN +CountTableInSDT ( + IN EFI_ACPI_DESCRIPTION_HEADER *Sdt, + IN UINTN TablePointerSize + ) +{ + UINTN Index; + UINTN TableCount; + UINTN EntryCount; + UINT64 EntryPtr; + UINTN BasePtr; + EFI_ACPI_COMMON_HEADER *Table; + EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr; + + EntryCount =3D (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Ta= blePointerSize; + BasePtr =3D (UINTN)(Sdt + 1); + FadtPtr =3D NULL; + + for (Index =3D 0, TableCount =3D 0; Index < EntryCount; Index++) { + EntryPtr =3D 0; + Table =3D NULL; + CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * TablePointerSize), Tabl= ePointerSize); + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr)); + if (Table !=3D NULL) { + TableCount++; + } + + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_= SIGNATURE) { + FadtPtr =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table; + if (FadtPtr->FirmwareCtrl || FadtPtr->XFirmwareCtrl) { + TableCount++; + } + + if (FadtPtr->Dsdt || FadtPtr->XDsdt) { + TableCount++; + } + } + } + + return TableCount; +} + +/** + This function calculates CRC based on each ACPI table. + It also calculates CRC and provides as HWSignature filed in FACS. **/ VOID -IsHardwareChange ( +IsAcpiTableChange ( VOID ) { - EFI_STATUS Status; - UINTN Index; - UINTN HandleCount; - EFI_HANDLE *HandleBuffer; - EFI_PCI_IO_PROTOCOL *PciIo; - UINT32 CRC; - UINT32 *HWChange; - UINTN HWChangeSize; - UINT32 PciId; - UINTN Handle; - EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr; - EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *pFADT; - - HandleCount =3D 0; - HandleBuffer =3D NULL; - - Status =3D gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return; // PciIO protocol not installed yet! + EFI_STATUS Status; + BOOLEAN IsRsdt; + UINTN Index; + UINTN AcpiTableCount; + UINTN EntryCount; + UINTN BasePtr; + UINT64 EntryPtr; + UINT32 *TableCrcRecord; + UINT32 HWSignature; + EFI_ACPI_COMMON_HEADER *Table; + EFI_ACPI_6_5_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; + EFI_ACPI_DESCRIPTION_HEADER *Rsdt; + EFI_ACPI_DESCRIPTION_HEADER *Xsdt; + EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr; + EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr; + + IsRsdt =3D FALSE; + Index =3D 0; + AcpiTableCount =3D 0; + EntryCount =3D 0; + BasePtr =3D 0; + EntryPtr =3D 0; + HWSignature =3D 0; + TableCrcRecord =3D NULL; + Rsdp =3D NULL; + Rsdt =3D NULL; + Xsdt =3D NULL; + FadtPtr =3D NULL; + FacsPtr =3D NULL; + + DEBUG ((DEBUG_INFO, "%a() - Start\n", __FUNCTION__)); + + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)= &Rsdp); + if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) { + return; } =20 - // - // Allocate memory for HWChange and add additional entrie for - // pFADT->XDsdt - // - HWChangeSize =3D HandleCount + 1; - HWChange =3D AllocateZeroPool (sizeof(UINT32) * HWChangeSize); - ASSERT(HWChange !=3D NULL); + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress; + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress; =20 - if (HWChange =3D=3D NULL) return; + if (Xsdt->Signature !=3D EFI_ACPI_6_5_EXTENDED_SYSTEM_DESCRIPTION_TABLE_= SIGNATURE) { + if (Rsdt->Signature =3D=3D EFI_ACPI_6_5_ROOT_SYSTEM_DESCRIPTION_TABLE_= SIGNATURE) { + IsRsdt =3D TRUE; + } else { + return; + } + } =20 // - // add HWChange inputs: PCI devices + // Count the ACPI tables found by RSDT/XSDT and FADT. // - for (Index =3D 0; HandleCount > 0; HandleCount--) { - PciId =3D 0; - Status =3D gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtoco= lGuid, (VOID **) &PciIo); - if (!EFI_ERROR (Status)) { - Status =3D PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &PciId= ); - if (EFI_ERROR (Status)) { - continue; - } - HWChange[Index++] =3D PciId; - } + if (IsRsdt =3D=3D TRUE) { + AcpiTableCount =3D CountTableInSDT (Rsdt, sizeof (UINT32)); + } else { + AcpiTableCount =3D CountTableInSDT (Xsdt, sizeof (UINT64)); } =20 // - // Locate FACP Table + // Allocate memory for founded ACPI tables. // - Handle =3D 0; - Status =3D LocateAcpiTableBySignature ( - EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, - (EFI_ACPI_DESCRIPTION_HEADER **) &pFADT, - &Handle - ); - if (EFI_ERROR (Status) || (pFADT =3D=3D NULL)) { - return; //Table not found or out of memory resource for pFADT table + TableCrcRecord =3D AllocateZeroPool (sizeof (UINT32) * AcpiTableCount); + if (TableCrcRecord =3D=3D NULL) { + return; + } + + if (IsRsdt =3D=3D TRUE) { + // + // Search RSDT + // + AcpiTableCount =3D 0; + EntryCount =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER= )) / sizeof (UINT32); + BasePtr =3D (UINTN)(Rsdt + 1); + for (Index =3D 0; Index < EntryCount; Index++) { + EntryPtr =3D 0; + Table =3D NULL; + CopyMem ((VOID *)&EntryPtr, (VOID *)(BasePtr + Index * sizeof (UINT3= 2)), sizeof (UINT32)); + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr)); + if (Table !=3D NULL) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator (Table= ); + } + + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABL= E_SIGNATURE) { + FadtPtr =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table; + // + // Locate FACS in FADT + // + if (FadtPtr->FirmwareCtrl) { + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)FadtPtr->FirmwareCtrl; + + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->FirmwareCtrl); + } + + // + // Locate DSDT in FADT + // + if (FadtPtr->Dsdt) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt); + } + } + } + } else { + // + // Search XSDT + // + AcpiTableCount =3D 0; + EntryCount =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER= )) / sizeof (UINT64); + BasePtr =3D (UINTN)(Xsdt + 1); + for (Index =3D 0; Index < EntryCount; Index++) { + EntryPtr =3D 0; + Table =3D NULL; + CopyMem ((VOID *)&EntryPtr, (VOID *)(BasePtr + Index * sizeof (UINT6= 4)), sizeof (UINT64)); + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr)); + if (Table !=3D NULL) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator (Table= ); + } + + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABL= E_SIGNATURE) { + FadtPtr =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table; + // + // Locate FACS in FADT + // + CopyMem ((VOID *)&EntryPtr, (VOID *)FadtPtr->XFirmwareCtrl, sizeof= (UINT64)); + if (EntryPtr !=3D 0) { + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)FadtPtr->XFirmwareCtrl; + + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XFirmwareCtrl); + } else { + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)FadtPtr->FirmwareCtrl; + + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->FirmwareCtrl); + } + + // + // Locate DSDT in FADT + // + CopyMem ((VOID *)&EntryPtr, (VOID *)FadtPtr->XDsdt, sizeof (UINT64= )); + if (EntryPtr !=3D 0) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XDsdt); + } else { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt); + } + } + } } =20 // - // add HWChange inputs: others + // FACS not found // - HWChange[Index++] =3D (UINT32)pFADT->XDsdt; + if (FacsPtr->Signature !=3D EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE= _SIGNATURE) { + return; + } =20 // - // Calculate CRC value with HWChange data. + // Calculate HWSignature data. // - Status =3D gBS->CalculateCrc32(HWChange, HWChangeSize, &CRC); - DEBUG ((DEBUG_INFO, "CRC =3D %x and Status =3D %r\n", CRC, Status)); + Status =3D gBS->CalculateCrc32 (TableCrcRecord, AcpiTableCount, &HWSigna= ture); + DEBUG ((DEBUG_INFO, "HardwareSignature =3D %x and Status =3D %r\n", HWSi= gnature, Status)); =20 // // Set HardwareSignature value based on CRC value. // - FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN) pFAD= T->FirmwareCtrl; - FacsPtr->HardwareSignature =3D CRC; - FreePool (HWChange); + FacsPtr->HardwareSignature =3D HWSignature; + FreePool (TableCrcRecord); + DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__)); } =20 VOID @@ -1329,7 +1494,7 @@ AcpiEndOfDxeEvent ( // // Calculate Hardware Signature value based on current platform configur= ations // - IsHardwareChange (); + IsAcpiTableChange (); } =20 /** 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 =20 [Depex] gEfiAcpiTableProtocolGuid AND --=20 2.39.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105073): https://edk2.groups.io/g/devel/message/105073 Mute This Topic: https://groups.io/mt/99009355/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-