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=192.55.52.88; helo=mga01.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 699C0202E5452 for ; Fri, 31 Aug 2018 04:59:54 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Aug 2018 04:59:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,311,1531810800"; d="scan'208";a="86536521" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga001.jf.intel.com with ESMTP; 31 Aug 2018 04:59:51 -0700 Received: from fmsmsx120.amr.corp.intel.com (10.18.124.208) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 31 Aug 2018 04:59:26 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx120.amr.corp.intel.com (10.18.124.208) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 31 Aug 2018 04:59:25 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.143]) with mapi id 14.03.0319.002; Fri, 31 Aug 2018 19:57:51 +0800 From: "Yao, Jiewen" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , Younas khan , "Gao, Liming" , "Zeng, Star" Thread-Topic: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new EfiFindAcpiTableBySignature() API Thread-Index: AQHUQR3kbmX/4SF0a0WlIck0i0cfdKTZwFyg Date: Fri, 31 Aug 2018 11:57:50 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AD36A49@shsmsx102.ccr.corp.intel.com> References: <1535714959-73472-1-git-send-email-star.zeng@intel.com> <1535714959-73472-2-git-send-email-star.zeng@intel.com> In-Reply-To: <1535714959-73472-2-git-send-email-star.zeng@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWNiYjAwYWYtZTE1Ni00YTBmLThiM2YtZGViMmIzMmZiOGUzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiT2g2Q3hmbWFjbjJlWjcyRWJWTkswcVNQRUE3MmlXZ1d4bUFJT091Q0VqR01HbnFJZ3ZhcFAyUDMzS0w4alRvMyJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 1/6] MdePkg UefiLib: Add new EfiFindAcpiTableBySignature() API 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:59:54 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Good enhancement. I have 2 additional thought: 1) How to handle DSDT? We have special code to handle FACS, but no DSDT. 2) How to handle SSDT or other multiple ACPI tables? We may have multiple SSDT. Usually, it is identified as OEMID. Do we want to provide similar function for them? Anyway, just *additional* thought. :-) Current implementation is good enough for check in. Reviewed-by: Jiewen.yao@intel.com Thank you Yao Jiewen > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of St= ar > Zeng > Sent: Friday, August 31, 2018 7:29 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Younas khan > ; Yao, Jiewen ; Gao, > Liming ; Zeng, Star > Subject: [edk2] [PATCH 1/6] MdePkg UefiLib: Add new > EfiFindAcpiTableBySignature() API >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D967 > Request to add a library function for GetAcpiTable() in order > to get ACPI table using signature as input. >=20 > After evaluation, we found there are many duplicated code to > find ACPI table by signature in different modules. >=20 > This patch adds new EfiFindAcpiTableBySignature() API in UefiLib > for the request and also the following patch to remove the > duplicated code. >=20 > Cc: Younas khan > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Jiewen Yao > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Star Zeng > --- > MdePkg/Include/Library/UefiLib.h | 17 +++ > MdePkg/Library/UefiLib/Acpi.c | 226 > +++++++++++++++++++++++++++++++++++++ > MdePkg/Library/UefiLib/UefiLib.inf | 3 + > 3 files changed, 246 insertions(+) > create mode 100644 MdePkg/Library/UefiLib/Acpi.c >=20 > diff --git a/MdePkg/Include/Library/UefiLib.h > b/MdePkg/Include/Library/UefiLib.h > index f80067f11103..8dd25f324fd2 100644 > --- a/MdePkg/Include/Library/UefiLib.h > +++ b/MdePkg/Include/Library/UefiLib.h > @@ -1595,4 +1595,21 @@ EfiOpenFileByDevicePath ( > IN UINT64 OpenMode, > IN UINT64 Attributes > ); > + > +/** > + This function finds ACPI table by signature. > + It will find the table in gEfiAcpi20TableGuid system configuration tab= le first, > + and then gEfiAcpi10TableGuid system configuration table. > + > + @param Signature ACPI table signature. > + > + @return ACPI table or NULL if not found. > + > +**/ > +VOID * > +EFIAPI > +EfiFindAcpiTableBySignature ( > + IN UINT32 Signature > + ); > + > #endif > diff --git a/MdePkg/Library/UefiLib/Acpi.c b/MdePkg/Library/UefiLib/Acpi.= c > new file mode 100644 > index 000000000000..5cb93966b59f > --- /dev/null > +++ b/MdePkg/Library/UefiLib/Acpi.c > @@ -0,0 +1,226 @@ > +/** @file > + This module provides help function for finding ACPI table. > + > + Copyright (c) 2018, Intel Corporation. All rights reserved.
> + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the = BSD > License > + which accompanies this distribution. The full text of the license may= be > found at > + http://opensource.org/licenses/bsd-license.php. > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include "UefiLibInternal.h" > +#include > +#include > + > +/** > + This function scans ACPI table in RSDT. > + > + @param Rsdt ACPI RSDT > + @param Signature ACPI table signature > + > + @return ACPI table or NULL if not found. > + > +**/ > +VOID * > +ScanTableInRSDT ( > + IN EFI_ACPI_DESCRIPTION_HEADER *Rsdt, > + IN UINT32 Signature > + ) > +{ > + UINTN Index; > + UINT32 EntryCount; > + UINT32 *EntryPtr; > + EFI_ACPI_DESCRIPTION_HEADER *Table; > + > + if (Rsdt =3D=3D NULL) { > + return NULL; > + } > + > + EntryCount =3D (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / > sizeof(UINT32); > + > + EntryPtr =3D (UINT32 *)(Rsdt + 1); > + for (Index =3D 0; Index < EntryCount; Index ++, EntryPtr ++) { > + Table =3D (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)(*EntryPtr)); > + if (Table->Signature =3D=3D Signature) { > + return Table; > + } > + } > + > + return NULL; > +} > + > +/** > + This function scans ACPI table in XSDT. > + > + @param Xsdt ACPI XSDT > + @param Signature ACPI table signature > + > + @return ACPI table or NULL if not found. > + > +**/ > +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 =3D=3D NULL) { > + return NULL; > + } > + > + EntryCount =3D (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / > sizeof(UINT64); > + > + BasePtr =3D (UINTN)(Xsdt + 1); > + for (Index =3D 0; Index < EntryCount; Index ++) { > + CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * sizeof(UINT64)), > sizeof(UINT64)); > + Table =3D (EFI_ACPI_DESCRIPTION_HEADER *)((UINTN)(EntryPtr)); > + if (Table->Signature =3D=3D Signature) { > + return Table; > + } > + } > + > + return NULL; > +} > + > +/** > + To find Facs in FADT. > + > + @param Fadt FADT table pointer > + > + @return Facs table pointer or NULL if not found. > + > +**/ > +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 =3D=3D NULL) { > + return NULL; > + } > + > + if (Fadt->Header.Revision < > EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) { > + Facs =3D (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE > *)(UINTN)Fadt->FirmwareCtrl; > + } else { > + CopyMem (&Data64, &Fadt->XFirmwareCtrl, sizeof(UINT64)); > + if (Data64 !=3D 0) { > + Facs =3D (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE > *)(UINTN)Data64; > + } else { > + Facs =3D (EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE > *)(UINTN)Fadt->FirmwareCtrl; > + } > + } > + return Facs; > +} > + > +/** > + To find ACPI table in ACPI ConfigurationTable. > + > + @param AcpiTableGuid The guid used to find ACPI ConfigurationTable. > + @param Signature ACPI table signature. > + > + @return ACPI table or NULL if not found. > + > +**/ > +VOID * > +FindAcpiTableInAcpiConfigurationTable ( > + IN EFI_GUID *AcpiGuid, > + IN UINT32 Signature > + > + ) > +{ > + EFI_STATUS Status; > + VOID *Table; > + 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; > + > + Rsdp =3D NULL; > + // > + // Find ACPI ConfigurationTable (RSD_PTR) > + // > + Status =3D EfiGetSystemConfigurationTable(AcpiGuid, (VOID **)&Rsdp); > + if (EFI_ERROR (Status) || (Rsdp =3D=3D NULL)) { > + return NULL; > + } > + > + Table =3D NULL; > + > + // > + // Search XSDT > + // > + if (Rsdp->Revision >=3D > EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION) { > + Xsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->XsdtAddress; > + if (Signature =3D=3D > EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) { > + // > + // It is to find FACS ACPI table, > + // need find FADT first. > + // > + Fadt =3D ScanTableInXSDT (Xsdt, > EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE); > + Table =3D FindAcpiFacsFromFadt (Fadt); > + } else { > + Table =3D ScanTableInXSDT (Xsdt, Signature); > + } > + } > + > + if (Table !=3D NULL) { > + return Table; > + } > + > + // > + // Search RSDT > + // > + Rsdt =3D (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN) Rsdp->RsdtAddress; > + if (Signature =3D=3D > EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) { > + // > + // It is to find FACS ACPI table, > + // need find FADT first. > + // > + Fadt =3D ScanTableInRSDT (Rsdt, > EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE); > + Table =3D FindAcpiFacsFromFadt (Fadt); > + } else { > + Table =3D ScanTableInRSDT (Rsdt, Signature); > + } > + > + return Table; > +} > + > +/** > + This function finds ACPI table by signature. > + It will find the table in gEfiAcpi20TableGuid system configuration tab= le first, > + and then gEfiAcpi10TableGuid system configuration table. > + > + @param Signature ACPI table signature. > + > + @return ACPI table or NULL if not found. > + > +**/ > +VOID * > +EFIAPI > +EfiFindAcpiTableBySignature ( > + IN UINT32 Signature > + ) > +{ > + VOID *Table; > + > + Table =3D FindAcpiTableInAcpiConfigurationTable (&gEfiAcpi20TableGuid, > Signature); > + if (Table !=3D NULL) { > + return Table; > + } > + > + return FindAcpiTableInAcpiConfigurationTable (&gEfiAcpi10TableGuid, > Signature); > +} > + > diff --git a/MdePkg/Library/UefiLib/UefiLib.inf > b/MdePkg/Library/UefiLib/UefiLib.inf > index a6c739ef3d6d..aea20fe67153 100644 > --- a/MdePkg/Library/UefiLib/UefiLib.inf > +++ b/MdePkg/Library/UefiLib/UefiLib.inf > @@ -41,6 +41,7 @@ [Sources] > Console.c > UefiLib.c > UefiLibInternal.h > + Acpi.c >=20 >=20 > [Packages] > @@ -62,6 +63,8 @@ [Guids] > gEfiEventReadyToBootGuid ## > SOMETIMES_CONSUMES ## Event > gEfiEventLegacyBootGuid ## > SOMETIMES_CONSUMES ## Event > gEfiGlobalVariableGuid ## > SOMETIMES_CONSUMES ## Variable > + gEfiAcpi20TableGuid ## > SOMETIMES_CONSUMES ## SystemTable > + gEfiAcpi10TableGuid ## > SOMETIMES_CONSUMES ## SystemTable >=20 > [Protocols] > gEfiDriverBindingProtocolGuid ## > SOMETIMES_PRODUCES > -- > 2.7.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel