From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=EFv7126R; spf=pass (domain: intel.com, ip: 134.134.136.65, 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=1684492201; x=1716028201; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=AwjP5Uw9//z3E+Wu9P49wlt/EL1I7xMlt+aQUh9BhzY=; b=EFv7126RUZ9Zb/nZy2P9tZ/3Z8LhAkQ2+Pbh+DAHzCGQopreYFmWdGoE CdvTZR8utXzgQ+z/HHmi2HM2HD3Kku0nN25ApjQeul4HUEc3841aPfFVJ UrtfMc66bCQw2JF7WAhW68b0WV0q3W53PmzCjicyak/AlKCRBCU+DTLO6 IDACKsCIX04XxEI0XQqT4m7g1o9c2VK8c0HDuVhm+VFBGlN7Kk7hITrhA FTFvgx4PwKfaIlf4pTa14Hw4FrcyONMfQ4a65emZXCsVsbz68GGXkXwB0 5vIjeMgBCJwSl5wMzPxw7u1JF4kigokV5K1zLaiA8l8vAUkho6+6N6hAQ Q==; 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" 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" 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: [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> 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 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 ( }=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 + This function calculates CRC based on each offset in the ACPI table.=0D +=0D + @param[in] Table The ACPI table required to calculate CRC.=0D +=0D + @retval CRC A pointer to allocate UINT32 that=0D + contains the CRC32 data.=0D +**/=0D +UINT32=0D +AcpiTableCrcCalculator (=0D + IN EFI_ACPI_COMMON_HEADER *Table=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 CRC;=0D +=0D + Status =3D EFI_SUCCESS;=0D + CRC =3D 0;=0D +=0D + //=0D + // Calculate CRC value.=0D + //=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 + Status =3D gBS->CalculateCrc32 ((UINT8 *)Table, (UINTN)Table->Length, &C= RC);=0D + return CRC;=0D +}=0D +=0D +/**=0D + This function count ACPI tables in RSDT/XSDT and return the result.=0D +=0D + @param[in] Sdt ACPI XSDT/RSDT.=0D + @param[in] TablePointerSize Size of table pointer:=0D + 4(RSDT) or 8(XSDT).=0D +=0D + @retval TableCount The total number of ACPI tables in=0D + RSDT or XSDT.=0D +**/=0D +UINTN=0D +CountTableInSDT (=0D + IN EFI_ACPI_DESCRIPTION_HEADER *Sdt,=0D + IN UINTN TablePointerSize=0D + )=0D +{=0D + UINTN Index;=0D + UINTN TableCount;=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 + EntryCount =3D (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Ta= blePointerSize;=0D + BasePtr =3D (UINTN)(Sdt + 1);=0D + FadtPtr =3D NULL;=0D +=0D + for (Index =3D 0, TableCount =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 + TableCount++;=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->FirmwareCtrl || FadtPtr->XFirmwareCtrl) {=0D + TableCount++;=0D + }=0D +=0D + if (FadtPtr->Dsdt || FadtPtr->XDsdt) {=0D + TableCount++;=0D + }=0D + }=0D + }=0D +=0D + return TableCount;=0D +}=0D +=0D +/**=0D + This function calculates CRC based on each ACPI table.=0D + It also calculates CRC and provides as HWSignature filed in FACS.=0D **/=0D VOID=0D -IsHardwareChange (=0D +IsAcpiTableChange (=0D VOID=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 + EFI_STATUS Status;=0D + BOOLEAN IsRsdt;=0D + UINTN Index;=0D + UINTN AcpiTableCount;=0D + UINTN EntryCount;=0D + UINTN BasePtr;=0D + UINT64 EntryPtr;=0D + UINT32 *TableCrcRecord;=0D + UINT32 HWSignature;=0D + EFI_ACPI_COMMON_HEADER *Table;=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_FIXED_ACPI_DESCRIPTION_TABLE *FadtPtr;=0D + EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *FacsPtr;=0D +=0D + IsRsdt =3D FALSE;=0D + Index =3D 0;=0D + AcpiTableCount =3D 0;=0D + EntryCount =3D 0;=0D + BasePtr =3D 0;=0D + EntryPtr =3D 0;=0D + HWSignature =3D 0;=0D + TableCrcRecord =3D NULL;=0D + Rsdp =3D NULL;=0D + Rsdt =3D NULL;=0D + Xsdt =3D NULL;=0D + FadtPtr =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 - //=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 + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;=0D + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;=0D =0D - if (HWChange =3D=3D NULL) return;=0D + if (Xsdt->Signature !=3D EFI_ACPI_6_5_EXTENDED_SYSTEM_DESCRIPTION_TABLE_= SIGNATURE) {=0D + if (Rsdt->Signature =3D=3D EFI_ACPI_6_5_ROOT_SYSTEM_DESCRIPTION_TABLE_= SIGNATURE) {=0D + IsRsdt =3D TRUE;=0D + } else {=0D + return;=0D + }=0D + }=0D =0D //=0D - // add HWChange inputs: PCI devices=0D + // Count the ACPI tables found by RSDT/XSDT and FADT.=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 - }=0D + if (IsRsdt =3D=3D TRUE) {=0D + AcpiTableCount =3D CountTableInSDT (Rsdt, sizeof (UINT32));=0D + } else {=0D + AcpiTableCount =3D CountTableInSDT (Xsdt, sizeof (UINT64));=0D }=0D =0D //=0D - // Locate FACP Table=0D + // Allocate memory for founded ACPI tables.=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 + TableCrcRecord =3D AllocateZeroPool (sizeof (UINT32) * AcpiTableCount);= =0D + if (TableCrcRecord =3D=3D NULL) {=0D + return;=0D + }=0D +=0D + if (IsRsdt =3D=3D TRUE) {=0D + //=0D + // Search RSDT=0D + //=0D + AcpiTableCount =3D 0;=0D + EntryCount =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER= )) / sizeof (UINT32);=0D + BasePtr =3D (UINTN)(Rsdt + 1);=0D + for (Index =3D 0; Index < EntryCount; Index++) {=0D + EntryPtr =3D 0;=0D + Table =3D NULL;=0D + CopyMem ((VOID *)&EntryPtr, (VOID *)(BasePtr + Index * sizeof (UINT3= 2)), sizeof (UINT32));=0D + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr));=0D + if (Table !=3D NULL) {=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator (Table= );=0D + }=0D +=0D + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABL= E_SIGNATURE) {=0D + FadtPtr =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table;=0D + //=0D + // Locate FACS in FADT=0D + //=0D + if (FadtPtr->FirmwareCtrl) {=0D + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)FadtPtr->FirmwareCtrl;=0D +=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->FirmwareCtrl);=0D + }=0D +=0D + //=0D + // Locate DSDT in FADT=0D + //=0D + if (FadtPtr->Dsdt) {=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt);=0D + }=0D + }=0D + }=0D + } else {=0D + //=0D + // Search XSDT=0D + //=0D + AcpiTableCount =3D 0;=0D + EntryCount =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER= )) / sizeof (UINT64);=0D + BasePtr =3D (UINTN)(Xsdt + 1);=0D + for (Index =3D 0; Index < EntryCount; Index++) {=0D + EntryPtr =3D 0;=0D + Table =3D NULL;=0D + CopyMem ((VOID *)&EntryPtr, (VOID *)(BasePtr + Index * sizeof (UINT6= 4)), sizeof (UINT64));=0D + Table =3D (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr));=0D + if (Table !=3D NULL) {=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator (Table= );=0D + }=0D +=0D + if (Table->Signature =3D=3D EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABL= E_SIGNATURE) {=0D + FadtPtr =3D (EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *)Table;=0D + //=0D + // Locate FACS in FADT=0D + //=0D + CopyMem ((VOID *)&EntryPtr, (VOID *)FadtPtr->XFirmwareCtrl, sizeof= (UINT64));=0D + if (EntryPtr !=3D 0) {=0D + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)FadtPtr->XFirmwareCtrl;=0D +=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XFirmwareCtrl);=0D + } else {=0D + FacsPtr =3D (EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UIN= TN)FadtPtr->FirmwareCtrl;=0D +=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->FirmwareCtrl);=0D + }=0D +=0D + //=0D + // Locate DSDT in FADT=0D + //=0D + CopyMem ((VOID *)&EntryPtr, (VOID *)FadtPtr->XDsdt, sizeof (UINT64= ));=0D + if (EntryPtr !=3D 0) {=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->XDsdt);=0D + } else {=0D + TableCrcRecord[AcpiTableCount++] =3D AcpiTableCrcCalculator ((EF= I_ACPI_COMMON_HEADER *)(UINTN)FadtPtr->Dsdt);=0D + }=0D + }=0D + }=0D }=0D =0D //=0D - // add HWChange inputs: others=0D + // FACS not found=0D //=0D - HWChange[Index++] =3D (UINT32)pFADT->XDsdt;=0D + if (FacsPtr->Signature !=3D EFI_ACPI_6_5_FIRMWARE_ACPI_CONTROL_STRUCTURE= _SIGNATURE) {=0D + return;=0D + }=0D =0D //=0D - // Calculate CRC value with HWChange data.=0D + // Calculate HWSignature data.=0D //=0D - Status =3D gBS->CalculateCrc32(HWChange, HWChangeSize, &CRC);=0D - DEBUG ((DEBUG_INFO, "CRC =3D %x and Status =3D %r\n", CRC, Status));=0D + Status =3D gBS->CalculateCrc32 (TableCrcRecord, AcpiTableCount, &HWSigna= ture);=0D + DEBUG ((DEBUG_INFO, "HardwareSignature =3D %x and Status =3D %r\n", HWSi= gnature, Status));=0D =0D //=0D // Set HardwareSignature value based on CRC value.=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 + FacsPtr->HardwareSignature =3D HWSignature;=0D + FreePool (TableCrcRecord);=0D + DEBUG ((DEBUG_INFO, "%a() - End\n", __FUNCTION__));=0D }=0D =0D VOID=0D @@ -1329,7 +1494,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