From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: Two or more type TXT spf records found.) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 675A72110BD48 for ; Fri, 31 Aug 2018 04:29:28 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Aug 2018 04:29:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,311,1531810800"; d="scan'208";a="253450311" Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by orsmga005.jf.intel.com with ESMTP; 31 Aug 2018 04:29:27 -0700 From: Star Zeng To: edk2-devel@lists.01.org Cc: Star Zeng , Younas khan , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Date: Fri, 31 Aug 2018 19:29:16 +0800 Message-Id: <1535714959-73472-4-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1535714959-73472-1-git-send-email-star.zeng@intel.com> References: <1535714959-73472-1-git-send-email-star.zeng@intel.com> Subject: [PATCH 3/6] MdeModulePkg S3SaveStateDxe: Use new EfiFindAcpiTableBySignature() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Aug 2018 11:29:28 -0000 https://bugzilla.tianocore.org/show_bug.cgi?id=967 Request to add a library function for GetAcpiTable() in order to get ACPI table using signature as input. After evaluation, we found there are many duplicated code to find ACPI table by signature in different modules. This patch updates S3SaveStateDxe to use new EfiFindAcpiTableBySignature() and remove the duplicated code. Cc: Younas khan Cc: Michael D Kinney Cc: Liming Gao Cc: Jiewen Yao Cc: Jian J Wang Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- .../Acpi/S3SaveStateDxe/AcpiS3ContextSave.c | 208 +-------------------- .../Acpi/S3SaveStateDxe/S3SaveStateDxe.inf | 3 +- 2 files changed, 5 insertions(+), 206 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c index 3f99023f110f..11f1890b5494 100644 --- a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c +++ b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c @@ -22,8 +22,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include -#include #include #include @@ -76,208 +76,6 @@ AllocateMemoryBelow4G ( } /** - - This function scan ACPI table in RSDT. - - @param Rsdt ACPI RSDT - @param Signature ACPI table signature - - @return ACPI table - -**/ -VOID * -ScanTableInRSDT ( - IN EFI_ACPI_DESCRIPTION_HEADER *Rsdt, - IN UINT32 Signature - ) -{ - UINTN Index; - UINT32 EntryCount; - UINT32 *EntryPtr; - EFI_ACPI_DESCRIPTION_HEADER *Table; - - if (Rsdt == NULL) { - return NULL; - } - - EntryCount = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT32); - - EntryPtr = (UINT32 *)(Rsdt + 1); - for (Index = 0; Index < EntryCount; Index ++, EntryPtr ++) { - Table = (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)(*EntryPtr)); - if (Table->Signature == Signature) { - return Table; - } - } - - return NULL; -} - -/** - - This function scan ACPI table in XSDT. - - @param Xsdt ACPI XSDT - @param Signature ACPI table signature - - @return ACPI table - -**/ -VOID * -ScanTableInXSDT ( - IN EFI_ACPI_DESCRIPTION_HEADER *Xsdt, - IN UINT32 Signature - ) -{ - UINTN Index; - UINT32 EntryCount; - UINT64 EntryPtr; - UINTN BasePtr; - EFI_ACPI_DESCRIPTION_HEADER *Table; - - if (Xsdt == NULL) { - return NULL; - } - - EntryCount = (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof(UINT64); - - BasePtr = (UINTN)(Xsdt + 1); - for (Index = 0; Index < EntryCount; Index ++) { - CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * sizeof(UINT64)), sizeof(UINT64)); - Table = (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)(EntryPtr)); - if (Table->Signature == Signature) { - return Table; - } - } - - return NULL; -} - -/** - To find Facs in FADT. - - @param Fadt FADT table pointer - - @return Facs table pointer. -**/ -EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * -FindAcpiFacsFromFadt ( - IN EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt - ) -{ - EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs; - UINT64 Data64; - - if (Fadt == NULL) { - return NULL; - } - - if (Fadt->Header.Revision < EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { - Facs = (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Fadt->FirmwareCtrl; - } else { - if (Fadt->FirmwareCtrl != 0) { - Facs = (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Fadt->FirmwareCtrl; - } else { - CopyMem (&Data64, &Fadt->XFirmwareCtrl, sizeof(UINT64)); - Facs = (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)(UINTN)Data64; - } - } - return Facs; -} - -/** - To find Facs in Acpi tables. - - To find Firmware ACPI control strutcure in Acpi Tables since the S3 waking vector is stored - in the table. - - @param AcpiTableGuid The guid used to find ACPI table in UEFI ConfigurationTable. - - @return Facs table pointer. -**/ -EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * -FindAcpiFacsTableByAcpiGuid ( - IN EFI_GUID *AcpiTableGuid - ) -{ - EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; - EFI_ACPI_DESCRIPTION_HEADER *Rsdt; - EFI_ACPI_DESCRIPTION_HEADER *Xsdt; - EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt; - EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs; - UINTN Index; - - Rsdp = NULL; - // - // found ACPI table RSD_PTR from system table - // - for (Index = 0; Index < gST->NumberOfTableEntries; Index++) { - if (CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), AcpiTableGuid)) { - // - // A match was found. - // - Rsdp = gST->ConfigurationTable[Index].VendorTable; - break; - } - } - - if (Rsdp == NULL) { - return NULL; - } - - // - // Search XSDT - // - if (Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { - Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->XsdtAddress; - Fadt = ScanTableInXSDT (Xsdt, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE); - if (Fadt != NULL) { - Facs = FindAcpiFacsFromFadt (Fadt); - if (Facs != NULL) { - return Facs; - } - } - } - - // - // Search RSDT - // - Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->RsdtAddress; - Fadt = ScanTableInRSDT (Rsdt, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE); - if (Fadt != NULL) { - Facs = FindAcpiFacsFromFadt (Fadt); - if (Facs != NULL) { - return Facs; - } - } - - return NULL; -} - -/** - To find Facs in Acpi tables. - - To find Firmware ACPI control strutcure in Acpi Tables since the S3 waking vector is stored - in the table. - - @return Facs table pointer. -**/ -EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE * -FindAcpiFacsTable ( - VOID - ) -{ - EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs; - - Facs = FindAcpiFacsTableByAcpiGuid (&gEfiAcpi20TableGuid); - if (Facs != NULL) { - return Facs; - } - - return FindAcpiFacsTableByAcpiGuid (&gEfiAcpi10TableGuid); -} - -/** The function will check if long mode waking vector is supported. @param[in] Facs Pointer to FACS table. @@ -460,7 +258,9 @@ AcpiS3ContextSaveOnEndOfDxe ( // // Get ACPI Table because we will save its position to variable // - Facs = (EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) FindAcpiFacsTable (); + Facs = (EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) EfiFindAcpiTableBySignature ( + EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE + ); AcpiS3Context->AcpiFacsTable = (EFI_PHYSICAL_ADDRESS) (UINTN) Facs; ASSERT (AcpiS3Context->AcpiFacsTable != 0); diff --git a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf index 36ed80cc7995..2c01f4959933 100644 --- a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf +++ b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf @@ -49,12 +49,11 @@ [LibraryClasses] PcdLib HobLib LockBoxLib + UefiLib [Guids] gEfiAcpiVariableGuid ## PRODUCES ## UNDEFINED # LockBox Save Data. gEfiAcpiS3ContextGuid ## PRODUCES ## UNDEFINED # LockBox Save Data. - gEfiAcpi20TableGuid ## SOMETIMES_CONSUMES ## SystemTable - gEfiAcpi10TableGuid ## SOMETIMES_CONSUMES ## SystemTable gEfiEndOfDxeEventGroupGuid ## CONSUMES ## Event [Protocols] -- 2.7.0.windows.1