From nobody Sat May 4 05:56:18 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+103877+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+103877+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1683081602; cv=none; d=zohomail.com; s=zohoarc; b=Dr7TQRLVt37tpuZFGhnbFIs5+NZX+ydEfnViA3b8hOvS9ju6gihUuWRMF1oJVQAm2IuIWvStU6nixp1ImeK4XOT0U9mW9oWgHqNM28wx0wbnuw0dJ2v9Q4lLFfSYFtJR2Gc9qga5KMk3eMOKFH0qweU8tJ0hyS+pUhxULQwqyww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683081602; 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=/BVNebdVzgCzCRyvzjjEkdQQOUuzJdcHMGiNwyEe4n4=; b=ErFKPKYwCqANlfaFJyOnn9aWUQWQ2MJRaJ5o0R4cXDlo9HcjDbGPZjuE3qhzbw7UsaiuMtG3Tqq2ISKhCGnzqL6Pl4jSsoK1s5duHMnmkFwli++f3BildCAF75UFV/NvZwLo4PvQI5Zz7LmRiGrFn0grsZDydup0bNyJIt/xlS4= 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+103877+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 1683081602927373.6512471630116; Tue, 2 May 2023 19:40:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hx0EYY1788612xPOYrAVn2EC; Tue, 02 May 2023 19:40:02 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.10145.1683081601329645854 for ; Tue, 02 May 2023 19:40:01 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10698"; a="337687644" X-IronPort-AV: E=Sophos;i="5.99,246,1677571200"; d="scan'208";a="337687644" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 May 2023 19:40:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10698"; a="870776697" X-IronPort-AV: E=Sophos;i="5.99,246,1677571200"; d="scan'208";a="870776697" X-Received: from kxinfux-desk.gar.corp.intel.com ([10.227.107.32]) by orsmga005.jf.intel.com with ESMTP; 02 May 2023 19:39:59 -0700 From: "VincentX Ke" To: devel@edk2.groups.io Cc: VincentX Ke , Chasel Chiu , Nate DeSimone , Isaac Oram , Liming Gao , Eric Dong Subject: [edk2-devel] [PATCH v5] MinPlatformPkg: Update HWSignature filed in FACS Date: Wed, 3 May 2023 10:39:54 +0800 Message-Id: <20230503023954.119-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: AAI85zxvpO9ssnPsgSVzk4hZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683081602; bh=VYQZF/c+++UabucTjHI/ThiF4U5IbLCHWNEqN83qP5k=; h=Cc:Date:From:Reply-To:Subject:To; b=MDQBuH2qoEz4olGavgmc4GJO5ZtT6C6rb72F+vNsnQehQE44P9bIO27iptnv/hZ2NSD t4+GgMCaLiCGZR2/hr/05+BdK8gK6yJctV0xueRBLFJ49p9Jsxi04XBUojYGrnkQDcScD BjukO1mBfrog9GtD+nOrKcP5JRx1CeS3dVc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683081604995100002 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 Signed-off-by: VincentX Ke --- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 182 +++++= ++++++++------- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 1 + 2 files changed, 118 insertions(+), 65 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b= /Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index e967031a3b..a940424ced 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -1191,98 +1191,150 @@ 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 pointer to ACPI table that + required to calculate CRC. + + @retval CRC A pointer to allocate UINT32 that + contains the CRC32 data. +**/ +UINT32 +AcpiTableCrcCalculator ( + IN VOID *Table + ) +{ + UINT32 CRC; + + CRC =3D 0; + + // + // Calculate CRC value. + // + if (((EFI_ACPI_6_5_COMMON_HEADER *)(UINTN)Table)->Signature =3D=3D EFI_A= CPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) { + // + // Zero HardwareSignature field before Calculating FACS CRC + // + do { + ((EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Table)->Hard= wareSignature =3D 0; + } while (((EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Table= )->HardwareSignature); + + gBS->CalculateCrc32 ((UINT8 *)Table, (UINTN)((EFI_ACPI_6_5_FIRMWARE_AC= PI_CONTROL_STRUCTURE *)(UINTN)Table)->Length, &CRC); + } else { + gBS->CalculateCrc32 ((UINT8 *)Table, (UINTN)((EFI_ACPI_DESCRIPTION_HEA= DER *)(UINTN)Table)->Length, &CRC); + } + + return CRC; +} + +/** + 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_3_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr; - EFI_ACPI_6_3_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; + UINTN Index; + UINTN AcpiTableCount; + UINT32 Table; + UINT32 HWSignature; + UINT32 *AcpiTableCrc; + 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 =3D 0; + AcpiTableCrc =3D NULL; + Rsdp =3D NULL; + Rsdt =3D NULL; + Xsdt =3D NULL; + FacsPtr =3D NULL; + pFADT =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 + // ACPI table count starts with 2 as RSDT and XSDT are already located. + // Then add ACPI tables found by XSDT and FADT. // - HWChangeSize =3D HandleCount + 1; - HWChange =3D AllocateZeroPool (sizeof(UINT32) * HWChangeSize); - ASSERT(HWChange !=3D NULL); + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddr= ess; + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddr= ess; + AcpiTableCount +=3D 2; + AcpiTableCount =3D AcpiTableCount + (Xsdt->Length - sizeof (EFI_ACPI_DE= SCRIPTION_HEADER))/sizeof (UINT64); =20 - if (HWChange =3D=3D NULL) return; + for (Index =3D sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < (Xsdt->Leng= th); Index =3D Index + sizeof (UINT64)) { + Table =3D *((UINT32 *)((UINT8 *)Xsdt + Index)); + if (((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Table)->Signature =3D=3D EF= I_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) { + pFADT =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)Table; + if (pFADT->FirmwareCtrl) { + AcpiTableCount++; + } =20 - // - // add HWChange inputs: PCI devices - // - 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; + if ((pFADT->XDsdt) || (pFADT->Dsdt)) { + AcpiTableCount++; } - HWChange[Index++] =3D PciId; } } =20 // - // Locate FACP Table + // Allocate memory for founded ACPI tables. // - Handle =3D 0; - Status =3D LocateAcpiTableBySignature ( - EFI_ACPI_6_3_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 + AcpiTableCrc =3D AllocateZeroPool (sizeof (UINT32) * AcpiTableCount); + if (AcpiTableCrc =3D=3D NULL) { + return; + } + + AcpiTableCount =3D 0; + AcpiTableCrc[AcpiTableCount++] =3D AcpiTableCrcCalculator ((VOID *)(UINT= N)Rsdt); + AcpiTableCrc[AcpiTableCount++] =3D AcpiTableCrcCalculator ((VOID *)(UINT= N)Xsdt); + + for (Index =3D sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < (Xsdt->Leng= th); Index =3D Index + sizeof (UINT64)) { + Table =3D *((UINT32 *)((UINT8 *)Xsdt + Index)= ); + AcpiTableCrc[AcpiTableCount++] =3D AcpiTableCrcCalculator ((VOID *)(UI= NTN)Table); + if (((EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Table)->Signature =3D=3D EF= I_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) { + pFADT =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)(UINTN)Table; + if (pFADT->FirmwareCtrl) { + AcpiTableCrc[AcpiTableCount++] =3D AcpiTableCrcCalculator ((VOID *= )(UINTN)pFADT->FirmwareCtrl); + } + + if (pFADT->XDsdt) { + AcpiTableCrc[AcpiTableCount++] =3D AcpiTableCrcCalculator ((VOID *= )(UINTN)pFADT->XDsdt); + } else { + AcpiTableCrc[AcpiTableCount++] =3D AcpiTableCrcCalculator ((VOID *= )(UINTN)pFADT->Dsdt); + } + } } =20 // - // add HWChange inputs: others + // pFADT table not found. // - HWChange[Index++] =3D (UINT32)pFADT->XDsdt; + if (pFADT =3D=3D NULL) { + 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 (AcpiTableCrc, AcpiTableCount, &HWSignatu= re); + 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_3_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)pFADT= ->FirmwareCtrl; - FacsPtr->HardwareSignature =3D CRC; - FreePool (HWChange); + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUC= TURE *)(UINTN)pFADT->FirmwareCtrl; + FacsPtr->HardwareSignature =3D HWSignature; + FreePool (AcpiTableCrc); + DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__)); } =20 VOID @@ -1329,7 +1381,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 (#103877): https://edk2.groups.io/g/devel/message/103877 Mute This Topic: https://groups.io/mt/98654282/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-