From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web09.19750.1621840398051670996 for ; Mon, 24 May 2021 00:13:18 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: zhiguang.liu@intel.com) IronPort-SDR: gHLDxnb/7y30NKxJ1+SV8J/skQG7lmV9u6KcYAj8i2e2UcOvRXlQoG19eRH8L8Ulyq2Q5nzNcG cWMp8ve84Y5w== X-IronPort-AV: E=McAfee;i="6200,9189,9993"; a="265769897" X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="265769897" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2021 00:13:13 -0700 IronPort-SDR: smsCtyetZZ7APJXZ6r4U395ITeWFNmtrog1jZYrJ/FpXcIWXQ+Th7ZvLeVAHLJMuVHZkUweeHt 6UwWsmBphJZg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="413477827" Received: from fieedk002.ccr.corp.intel.com ([10.239.158.144]) by orsmga002.jf.intel.com with ESMTP; 24 May 2021 00:13:10 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Dandan Bi , Liming Gao , Ray Ni Subject: [PATCH 8/9] MdeModulePkg/ACPI: Install ACPI table from HOB. Date: Mon, 24 May 2021 15:12:33 +0800 Message-Id: <20210524071234.1056-9-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: <20210524071234.1056-1-zhiguang.liu@intel.com> References: <20210524071234.1056-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable If HOB contains APCI table information, entry point of AcpiTableDxe.inf should parse the APCI table from HOB, and install these tables. We assume the whole ACPI table (starting with EFI_ACPI_2_0_ROOT_SYSTEM_DESC= RIPTION_POINTER) is contained by a single gEfiAcpiTableGuid HOB. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Cc: Ray Ni Signed-off-by: Zhiguang Liu --- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h | 4 +++- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf | 4 +++- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 144 +++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 142 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h b/MdeModu= lePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h index 9d7cf7ccfc..7fd393aab3 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h @@ -1,7 +1,7 @@ /** @file=0D ACPI Table Protocol Driver=0D =0D - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -24,6 +24,8 @@ #include =0D #include =0D #include =0D +#include =0D +#include =0D =0D //=0D // Statements that include other files=0D diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf b/Md= eModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf index d341df439e..df80c4db35 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf @@ -4,7 +4,7 @@ # This driver initializes ACPI tables (Rsdp, Rsdt and Xsdt) and produces = UEFI/PI=0D # services to install/uninstall/manage ACPI tables.=0D #=0D -# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
= =0D # Copyright (c) 2016, Linaro Ltd. All rights reserved.
=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -51,10 +51,12 @@ DebugLib=0D BaseLib=0D PcdLib=0D + HobLib=0D =0D [Guids]=0D gEfiAcpi10TableGuid ## PRODUCES ## SystemTable= =0D gEfiAcpiTableGuid ## PRODUCES ## SystemTable= =0D + gPldAcpiTableGuid=0D =0D [FeaturePcd]=0D gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol ## CONSUMES=0D diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b= /MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index 5a2afdff27..24962843a1 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -1,7 +1,7 @@ /** @file=0D ACPI Table Protocol Implementation=0D =0D - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
=0D Copyright (c) 2016, Linaro Ltd. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -30,6 +30,7 @@ STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType; @param Table Table to add.=0D @param Checksum Does the table require checksumming.=0D @param Version The version of the list to add the tab= le to.=0D + @param IsFromHob True, if add Apci Table from Hob List.= =0D @param Handle Pointer for returning the handle.=0D =0D @return EFI_SUCCESS The function completed successfully.=0D @@ -44,6 +45,7 @@ AddTableToList ( IN VOID *Table,=0D IN BOOLEAN Checksum,=0D IN EFI_ACPI_TABLE_VERSION Version,=0D + IN BOOLEAN IsFromHob,=0D OUT UINTN *Handle=0D );=0D =0D @@ -238,6 +240,7 @@ InstallAcpiTable ( AcpiTableBufferConst,=0D TRUE,=0D Version,=0D + FALSE,=0D TableKey=0D );=0D if (!EFI_ERROR (Status)) {=0D @@ -472,6 +475,7 @@ FreeTableMemory ( @param Table Table to add.=0D @param Checksum Does the table require checksumming.=0D @param Version The version of the list to add the tab= le to.=0D + @param IsFromHob True, if add Apci Table from Hob List.= =0D @param Handle Pointer for returning the handle.=0D =0D @return EFI_SUCCESS The function completed successfully.=0D @@ -487,6 +491,7 @@ AddTableToList ( IN VOID *Table,=0D IN BOOLEAN Checksum,=0D IN EFI_ACPI_TABLE_VERSION Version,=0D + IN BOOLEAN IsFromHob,=0D OUT UINTN *Handle=0D )=0D {=0D @@ -552,13 +557,16 @@ AddTableToList ( // could be updated by OS present agent. For example, BufferPtrAddress= in=0D // SMM communication ACPI table.=0D //=0D - ASSERT ((EFI_PAGE_SIZE % 64) =3D=3D 0);=0D - Status =3D gBS->AllocatePages (=0D - AllocateMaxAddress,=0D - EfiACPIMemoryNVS,=0D - EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),=0D - &AllocPhysAddress=0D - );=0D + if (IsFromHob){=0D + AllocPhysAddress =3D (UINTN)Table;=0D + } else {=0D + Status =3D gBS->AllocatePages (=0D + AllocateMaxAddress,=0D + EfiACPIMemoryNVS,=0D + EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),=0D + &AllocPhysAddress=0D + );=0D + }=0D } else if (mAcpiTableAllocType =3D=3D AllocateAnyPages) {=0D //=0D // If there is no allocation limit, there is also no need to use page= =0D @@ -1689,6 +1697,124 @@ ChecksumCommonTables ( return EFI_SUCCESS;=0D }=0D =0D +/**=0D + This function will find gPldAcpiTableGuid Guid Hob, and install Acpi tab= le from it.=0D +=0D + @param AcpiTableInstance Protocol instance private data.=0D +=0D + @return EFI_SUCCESS The function completed successfully.=0D + @return EFI_NOT_FOUND The function doesn't find the gEfiAcpiTableGu= id Guid Hob.=0D + @return EFI_ABORTED The function could not complete successfully.= =0D +=0D +**/=0D +EFI_STATUS=0D +InstallAcpiTableFromHob (=0D + EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance=0D + )=0D +{=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + EFI_ACPI_TABLE_VERSION Version;=0D + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;=0D + EFI_ACPI_DESCRIPTION_HEADER *Rsdt;=0D + EFI_ACPI_DESCRIPTION_HEADER *ChildTable;=0D + UINT64 ChildTableAddress;=0D + UINTN Count;=0D + UINTN Index;=0D + UINTN TableKey;=0D + EFI_STATUS Status;=0D + UINTN EntrySize;=0D + PLD_ACPI_TABLE *AcpiTableAdress;=0D + VOID *TableToInstall;=0D + PLD_GENERIC_HEADER *GenericHeader;=0D +=0D + TableKey =3D 0;=0D + Version =3D PcdGet32 (PcdAcpiExposedTableVersions);=0D +=0D + //=0D + // HOB only contains the ACPI table in 2.0+ format.=0D + //=0D + GuidHob =3D GetFirstGuidHob (&gPldAcpiTableGuid);=0D + if (GuidHob =3D=3D NULL) {=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + GenericHeader =3D (PLD_GENERIC_HEADER *) GET_GUID_HOB_DATA (GuidHob);=0D + if ((sizeof (PLD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || = (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {=0D + return EFI_NOT_FOUND;=0D + }=0D + if (GenericHeader->Revision =3D=3D PLD_ACPI_TABLE_REVISION) {=0D + //=0D + // PLD_ACPI_TABLE structure is used when Revision equals to PLD_ACPI_T= ABLE_REVISION=0D + //=0D + AcpiTableAdress =3D (PLD_ACPI_TABLE *) GET_GUID_HOB_DATA (GuidHob);=0D + if (GenericHeader->Length < PLD_SIZEOF_THROUGH_FIELD (PLD_ACPI_TABLE, = Rsdp)) {=0D + //=0D + // Retrun if can't find the ACPI Info Hob with enough length=0D + //=0D + return EFI_NOT_FOUND;=0D + }=0D + Rsdp =3D (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) (UINTN) (Acp= iTableAdress->Rsdp);=0D +=0D + //=0D + // An ACPI-compatible OS must use the XSDT if present.=0D + // It shouldn't happen that XsdtAddress points beyond 4G range in 32-b= it environment.=0D + //=0D + ASSERT ((UINTN) Rsdp->XsdtAddress =3D=3D Rsdp->XsdtAddress);=0D +=0D + EntrySize =3D sizeof (UINT64);=0D + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->XsdtAddress;=0D + if (Rsdt =3D=3D NULL) {=0D + //=0D + // XsdtAddress is zero, then we use Rsdt which has 32 bit entry=0D + //=0D + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress;= =0D + EntrySize =3D sizeof (UINT32);=0D + }=0D + Count =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / Entr= ySize;=0D +=0D + for (Index =3D 0; Index < Count; Index++){=0D + ChildTableAddress =3D 0;=0D + CopyMem (&ChildTableAddress, (UINT8 *) (Rsdt + 1) + EntrySize * Inde= x, EntrySize);=0D + //=0D + // If the address is of UINT64 while this module runs at 32 bits,=0D + // make sure the upper bits are all-zeros.=0D + //=0D + ASSERT (ChildTableAddress =3D=3D (UINTN) ChildTableAddress);=0D +=0D + ChildTable =3D (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) ChildTableAdd= ress;=0D + Status =3D AddTableToList (AcpiTableInstance, ChildTable, TRUE, Vers= ion, TRUE, &TableKey);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI ta= ble at 0x%p\n", ChildTable));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + if (ChildTable->Signature =3D=3D EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION= _TABLE_SIGNATURE){=0D + //=0D + // Add the FACS and DSDT tables if it is not NULL.=0D + //=0D + if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *) ChildTable)->Fi= rmwareCtrl !=3D 0) {=0D + TableToInstall =3D (VOID *) (UINTN) ((EFI_ACPI_3_0_FIXED_ACPI_DE= SCRIPTION_TABLE *) ChildTable)->FirmwareCtrl;=0D + Status =3D AddTableToList (AcpiTableInstance, TableToInstall, TR= UE, Version, TRUE, &TableKey);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACP= I table FACS\n"));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + }=0D +=0D + if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *) ChildTable)->Ds= dt !=3D 0) {=0D + TableToInstall =3D (VOID *) (UINTN) ((EFI_ACPI_3_0_FIXED_ACPI_DE= SCRIPTION_TABLE *) ChildTable)->Dsdt;=0D + Status =3D AddTableToList (AcpiTableInstance, TableToInstall, TR= UE, Version, TRUE, &TableKey);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACP= I table DSDT\n"));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + }=0D + }=0D + }=0D + }=0D + Status =3D PublishTables (AcpiTableInstance, Version);=0D + ASSERT_EFI_ERROR (Status);=0D + return Status;=0D +}=0D =0D /**=0D Constructor for the ACPI table protocol. Initializes instance=0D @@ -1918,6 +2044,8 @@ AcpiTableAcpiTableConstructor ( =0D ChecksumCommonTables (AcpiTableInstance);=0D =0D + InstallAcpiTableFromHob (AcpiTableInstance);=0D +=0D //=0D // Completed successfully=0D //=0D --=20 2.30.0.windows.2