From nobody Sun May 19 05:50:48 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+104685+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+104685+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1683799228; cv=none; d=zohomail.com; s=zohoarc; b=H2OawNrC6oXdmU23q7TqHDj35iXAdOXAnOglv/DrUDZStEV2khmV8DwCVHVcgzJKOKedxgZ4M+jTSYCPs1i3tix+ZAF+LjKh0ngVMLfwG+sHzauWHSTbwAM9bktKDq2+wAJ7s1rSyc+fL4kr6Pi9kQETHEAI7Y11tAv+oWUQ3Wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683799228; 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=m+p0uTN8KdhJKmjrFdH0U49nndaCzAjrQWzPjrfpDCY=; b=l95YO3l7WGhUEGk2ZRc2K3asqyHmdeXoX5Omhf7qUixdzzAhiY++Yl8GDsTxKhwcgNikL/MWzX4Us8fzKiIPvkL1CEQ6MmVYkse95sDHrxKHVDI0pU85lDXIbbqgIXMYSDawMQAE1pP01L64L2Y+ZHEASd8d5IITcXX+VYaM1oU= 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+104685+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 1683799228356830.6603626986583; Thu, 11 May 2023 03:00:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id acASYY1788612xFXJYF9E4V3; Thu, 11 May 2023 03:00:28 -0700 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web10.55313.1683799227211201216 for ; Thu, 11 May 2023 03:00:27 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="436786308" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="436786308" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 03:00:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="764678483" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="764678483" X-Received: from kxinfux-desk.gar.corp.intel.com ([10.227.107.32]) by fmsmga008.fm.intel.com with ESMTP; 11 May 2023 03:00:08 -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 v7] MinPlatformPkg: Update HWSignature filed in FACS Date: Thu, 11 May 2023 17:59:59 +0800 Message-Id: <20230511095959.562-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: s51gXRqQb6XPAh0DarV64kgyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683799228; bh=YTVxQAZCGcl6WYoYvxcyQMml0aSGMJins97/s57MCMw=; h=Cc:Date:From:Reply-To:Subject:To; b=LlCWC4fimT33oEVm66KE9BABWnrknz9Hr4mH+tHLP/JujNlcA81Kus/HN/CZx5yw7+m sbAJbOlqPx80w6u+UwrFn6CC+ajAJTgLB397ce0LoXCC3X1rrzOEAuZcUgcJEM3nC4EI9 UmvjAlRYD4ftVOlHzXUmLio1wHddWg5ikHU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683799229521100001 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 Reviewed-by: Ankit Sinha --- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c | 287 +++++= ++++++++++----- Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.inf | 1 + 2 files changed, 223 insertions(+), 65 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b= /Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c index e967031a3b..3dca6f99f7 100644 --- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c @@ -1191,98 +1191,255 @@ 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; + + EntryCount =3D (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Ta= blePointerSize; + BasePtr =3D (UINTN)(Sdt + 1); + + 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) { + TableCount++; + } + + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_= SIGNATURE) { + CopyMem ((VOID *)&Fadt, (VOID *)Table, sizeof (EFI_ACPI_6_5_FIXED_AC= PI_DESCRIPTION_TABLE)); + if (Fadt.FirmwareCtrl || Fadt.XFirmwareCtrl) { + TableCount++; + } + + if (Fadt.Dsdt || Fadt.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_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; + 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_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr; + + 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; + 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; + } + + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress; + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress; + + if (Xsdt->Signature !=3D EFI_ACPI_6_5_EXTENDED_SYSTEM_DESCRIPTION_TABLE_= SIGNATURE) { + if (Rsdt->Signature !=3D EFI_ACPI_6_5_ROOT_SYSTEM_DESCRIPTION_TABLE_SI= GNATURE) { + return; + } } =20 // - // Allocate memory for HWChange and add additional entrie for - // pFADT->XDsdt + // ACPI table count starts with 0. + // Then add ACPI tables found by RSDT/XSDT and FADT. // - HWChangeSize =3D HandleCount + 1; - HWChange =3D AllocateZeroPool (sizeof(UINT32) * HWChangeSize); - ASSERT(HWChange !=3D NULL); + AcpiTableCount =3D CountTableInSDT (Xsdt, sizeof (UINT64)); + if (AcpiTableCount =3D=3D 0) { + AcpiTableCount =3D CountTableInSDT (Rsdt, sizeof (UINT32)); + } =20 - if (HWChange =3D=3D NULL) return; + // + // Allocate memory for founded ACPI tables. + // + TableCrcRecord =3D AllocateZeroPool (sizeof (UINT32) * AcpiTableCount); + if (TableCrcRecord =3D=3D NULL) { + return; + } =20 // - // add HWChange inputs: PCI devices + // Search XSDT // - 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; + 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 (UINT64)= ), sizeof (UINT64)); + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr)); + if (Table) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator (Table); + } + + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_= SIGNATURE) { + CopyMem ((VOID *)&Fadt, (VOID *)Table, sizeof (EFI_ACPI_6_5_FIXED_AC= PI_DESCRIPTION_TABLE)); + // + // Locate FACS in FADT + // + CopyMem ((VOID *)&EntryPtr, (VOID *)&Fadt.XFirmwareCtrl, sizeof (UIN= T64)); + if (EntryPtr !=3D 0) { + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN= )((EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table)->XFirmwareCtrl; + + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EFI_= ACPI_COMMON_HEADER *)(UINTN)EntryPtr); + } else { + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN= )((EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table)->FirmwareCtrl; + + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EFI_= ACPI_COMMON_HEADER *)(UINTN)Fadt.FirmwareCtrl); + } + + // + // Locate DSDT in FADT + // + CopyMem ((VOID *)&EntryPtr, (VOID *)&Fadt.XDsdt, sizeof (UINT64)); + if (EntryPtr !=3D 0) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EFI_= ACPI_COMMON_HEADER *)(UINTN)EntryPtr); + } else { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EFI_= ACPI_COMMON_HEADER *)(UINTN)Fadt.Dsdt); } - HWChange[Index++] =3D PciId; } } =20 - // - // Locate FACP Table - // - 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 + if (FacsPtr->Signature !=3D EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE= _SIGNATURE) { + // + // 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) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator (Table= ); + } + + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABL= E_SIGNATURE) { + CopyMem ((VOID *)&Fadt, (VOID *)Table, sizeof (EFI_ACPI_6_5_FIXED_= ACPI_DESCRIPTION_TABLE)); + // + // Locate FACS in FADT + // + if (Fadt.FirmwareCtrl) { + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)((EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table)->FirmwareCtrl; + + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)Fadt.FirmwareCtrl); + } + + // + // Locate DSDT in FADT + // + if (Fadt.Dsdt) { + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)Fadt.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_3_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)pFADT= ->FirmwareCtrl; - FacsPtr->HardwareSignature =3D CRC; - FreePool (HWChange); + FacsPtr->HardwareSignature =3D HWSignature; + FreePool (TableCrcRecord); + DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__)); } =20 VOID @@ -1329,7 +1486,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 (#104685): https://edk2.groups.io/g/devel/message/104685 Mute This Topic: https://groups.io/mt/98824282/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-