From nobody Sat May 18 23:15:00 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+105475+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+105475+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1685501298; cv=none; d=zohomail.com; s=zohoarc; b=gK0gxPzZI8L2j3p3c9k0a78i7Yq9VFxGnh+37WFImXxursgBhkXiNSmBXOBvS0Ioa43Q5SKSUZ3iEyZQxRHo1p+PJdpudmCSODRZxCvh/LmcNh1Witvh81yWBe8A3z668Yt527HIgsEIpF6ud0brUE/OQcuOrVovEwWRbRUJs0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685501298; 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=alybDz+czxpyQdNcf1STjFCKr2SDZqHM8kJv4pVBsNA=; b=KgeQWgWWi8j41HxZ/QXW51IKelKNZrJTbdg481JwHTgM1j2oliDRXx2ERKiPt+5TNeMmRTa4YqvoEzfRZrRGFkrCMuZE4r/vwilVT3xDcyn31omgNJnqKmY2K9uPU7LH+jwYtwmo3mj+KSd5SqCjNu5V7FnhcJ8SQY8Ms0wndOw= 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+105475+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 1685501298139323.460289316484; Tue, 30 May 2023 19:48:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HrhvYY1788612xBwRft9YDNd; Tue, 30 May 2023 19:48:17 -0700 X-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 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" X-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" X-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: [edk2-devel] [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> 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: rP5tFuWOw6ZRjLjGCLyUZEMBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685501297; bh=iYKGiSXyUHBSJ2AQwbsKwnP2ljDLh9u57ZIw3B0PncE=; h=Cc:Date:From:Reply-To:Subject:To; b=YVVgVEq7RtDmNkNjclT+EzL5mnyGpL8CD9ur7qBG7qLYIy2e77OJJAI60GIUuI9iO16 4/fLRmEl0H+yaiFr6B3H9Zcuw9iIO/Uaw83cbBc8ICGwsVGot3uwXA5CrAhwZfubOAXvE GaYm0Z2qi5M0QZzgMbWRJK1cdu1XhSd1fsQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685501299890100003 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 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 Reviewed-by: Ray Ni --- 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 ( } =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. + Function prototype for GetAcpiTableCount/CalculateAcpiTableCrc. + + @param[in] Table The pointer to ACPI table. + @param[in] TableIndex The ACPI table index. + @param[in] Context The pointer to UINTN for GetAcpiTableCount. + The pointer to UINT32 array for CalculateAcpiTab= leCrc. **/ +typedef VOID -IsHardwareChange ( - VOID +(EFIAPI *ACPI_TABLE_CALLBACK)( + IN EFI_ACPI_COMMON_HEADER *Table, + IN UINTN TableIndex, + IN VOID *Context + ); + +/** + Enumerate all ACPI tables in RSDT/XSDT. + + @param[in] Sdt ACPI XSDT/RSDT. + @param[in] TablePointerSize Size of table pointer: + 4(RSDT) or 8(XSDT). + @param[in] CallbackFunction The pointer to GetAcpiTableCount/Calculate= AcpiTableCrc. + @param[in] Context The pointer to UINTN for GetAcpiTableCount. + The pointer to UINT32 array for CalculateA= cpiTableCrc. +**/ +VOID +EnumerateAllAcpiTables ( + IN EFI_ACPI_DESCRIPTION_HEADER *Sdt, + IN UINTN TablePointerSize, + IN ACPI_TABLE_CALLBACK CallbackFunction, + IN VOID *Context ) { - 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! + UINTN Index; + UINTN TableIndex; + UINTN EntryCount; + UINT64 EntryPtr; + UINTN BasePtr; + EFI_ACPI_COMMON_HEADER *Table; + EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr; + + Index =3D 0; + TableIndex =3D 0; + EntryCount =3D (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Ta= blePointerSize; + EntryPtr =3D 0; + BasePtr =3D (UINTN)(Sdt + 1); + Table =3D NULL; + FadtPtr =3D NULL; + + if (Sdt =3D=3D NULL) { + ASSERT (Sdt !=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); + for (Index =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) { + CallbackFunction (Table, TableIndex++, Context); + } + + 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->Header.Revision < EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_T= ABLE_REVISION) { + // + // Locate FACS/DSDT in FADT + // + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Firmwa= reCtrl, TableIndex++, Context); + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt, = TableIndex++, Context); + } else { + // + // Locate FACS in FADT + // + if (FadtPtr->XFirmwareCtrl !=3D 0) { + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XFir= mwareCtrl, TableIndex++, Context); + } else { + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Firm= wareCtrl, TableIndex++, Context); + } + + // + // Locate DSDT in FADT + // + if (FadtPtr->XDsdt !=3D 0) { + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XDsd= t, TableIndex++, Context); + } else { + CallbackFunction ((EFI_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt= , TableIndex++, Context); + } + } + } + } +} + +/** + Count the number of ACPI tables. + + @param[in] Table The pointer to ACPI table. + @param[in] TableIndex The ACPI table index. + @param[in] Context The pointer to UINTN. +**/ +VOID +EFIAPI +GetAcpiTableCount ( + IN EFI_ACPI_COMMON_HEADER *Table, + IN UINTN TableIndex, + IN VOID *Context + ) +{ + UINTN *TableCount; + + TableCount =3D (UINTN *)Context; + + if (Table =3D=3D NULL) { + ASSERT (Table !=3D NULL); + return; + } + + (*TableCount)++; +} =20 - if (HWChange =3D=3D NULL) return; +/** + Calculate CRC based on each offset in the ACPI table. + + @param[in] Table The pointer to ACPI table. + @param[in] TableIndex The ACPI table index. + @param[in] Context The pointer to UINT32 array. +**/ +VOID +EFIAPI +CalculateAcpiTableCrc ( + IN EFI_ACPI_COMMON_HEADER *Table, + IN UINTN TableIndex, + IN VOID *Context + ) +{ + UINT32 *TableCrcRecord; + + TableCrcRecord =3D (UINT32 *)Context; + + if (Table =3D=3D NULL) { + ASSERT (Table !=3D NULL); + return; + } =20 // - // add HWChange inputs: PCI devices + // Calculate CRC value. // - 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 (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; + } + + gBS->CalculateCrc32 ((UINT8 *)Table, (UINTN)Table->Length, &TableCrcReco= rd[TableIndex]); +} + +/** + This function calculates CRC based on each ACPI table. + It also calculates CRC and provides as HardwareSignature field in FACS. +**/ +VOID +IsAcpiTableChange ( + VOID + ) +{ + EFI_STATUS Status; + BOOLEAN IsRsdt; + UINTN AcpiTableCount; + UINT32 *TableCrcRecord; + 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; + + IsRsdt =3D FALSE; + AcpiTableCount =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 =3D=3D NULL) { + if (Rsdt !=3D NULL) { + IsRsdt =3D TRUE; + } else { + return; } } =20 + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)EfiLocateFir= stAcpiTable (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE); + if (FacsPtr =3D=3D NULL) { + return; + } + // - // Locate FACP Table + // Count the ACPI tables found by RSDT/XSDT and FADT. // - 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 + if (IsRsdt) { + EnumerateAllAcpiTables (Rsdt, sizeof (UINT32), GetAcpiTableCount, (VOI= D *)&AcpiTableCount); + } else { + EnumerateAllAcpiTables (Xsdt, sizeof (UINT64), GetAcpiTableCount, (VOI= D *)&AcpiTableCount); } =20 // - // add HWChange inputs: others + // Allocate memory for founded ACPI tables. // - HWChange[Index++] =3D (UINT32)pFADT->XDsdt; + TableCrcRecord =3D AllocateZeroPool (sizeof (UINT32) * AcpiTableCount); + if (TableCrcRecord =3D=3D NULL) { + return; + } =20 // - // Calculate CRC value with HWChange data. + // Calculate CRC for each ACPI table and set record. // - Status =3D gBS->CalculateCrc32(HWChange, HWChangeSize, &CRC); - DEBUG ((DEBUG_INFO, "CRC =3D %x and Status =3D %r\n", CRC, Status)); + if (IsRsdt) { + EnumerateAllAcpiTables (Rsdt, sizeof (UINT32), CalculateAcpiTableCrc, = (VOID *)TableCrcRecord); + } else { + EnumerateAllAcpiTables (Xsdt, sizeof (UINT64), CalculateAcpiTableCrc, = (VOID *)TableCrcRecord); + } =20 // - // Set HardwareSignature value based on CRC value. + // Calculate and set HardwareSignature data. // - FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN) pFAD= T->FirmwareCtrl; - FacsPtr->HardwareSignature =3D CRC; - FreePool (HWChange); + Status =3D gBS->CalculateCrc32 ((UINT8 *)TableCrcRecord, AcpiTableCount,= &(FacsPtr->HardwareSignature)); + DEBUG ((DEBUG_INFO, "HardwareSignature =3D %x and Status =3D %r\n", Facs= Ptr->HardwareSignature, Status)); + + FreePool (TableCrcRecord); + DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__)); } =20 VOID @@ -1329,7 +1477,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 (#105475): https://edk2.groups.io/g/devel/message/105475 Mute This Topic: https://groups.io/mt/99234717/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-