From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (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 3DAD32239365A for ; Wed, 31 Jan 2018 18:15:01 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 18:20:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,442,1511856000"; d="scan'208";a="27901014" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 31 Jan 2018 18:20:37 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 31 Jan 2018 18:20:29 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.116]) with mapi id 14.03.0319.002; Thu, 1 Feb 2018 10:20:27 +0800 From: "Zeng, Star" To: "Kinney, Michael D" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Gao, Liming" , "Zeng, Star" Thread-Topic: [edk2] [Patch 1/1] MdePkg/UefiLib: Add EfiLocateProtocolBuffer() Thread-Index: AQHTmuvtB7Z0+ubmC0a1IKcu/CjdbaOOwfEw//+ErgCAAIcIMA== Date: Thu, 1 Feb 2018 02:20:26 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BA1DE15@shsmsx102.ccr.corp.intel.com> References: <20180131233324.7492-1-michael.d.kinney@intel.com> <20180131233324.7492-2-michael.d.kinney@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483103BA1DD67@shsmsx102.ccr.corp.intel.com> In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch 1/1] MdePkg/UefiLib: Add EfiLocateProtocolBuffer() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 02:15:01 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Mike, Depend on whether the allocated buffer will be returned to caller or not, a= nd whether the implementation is matched with the function comments. Some cases seem ok. 1. There are paired interfaces, for example AddUnicodeString and FreeUnicod= eStringTable, etc. 2. There are clear comments, and implementation matches with comments, for = example GetVariable2, etc. " The returned buffer is allocated using AllocatePool(). The caller is res= ponsible for freeing this buffer with FreePool(). " More evaluation are needed for all the interfaces. Thanks, Star -----Original Message----- From: Kinney, Michael D=20 Sent: Thursday, February 1, 2018 10:07 AM To: Zeng, Star ; edk2-devel@lists.01.org; Kinney, Mich= ael D Cc: Yao, Jiewen ; Gao, Liming Subject: RE: [edk2] [Patch 1/1] MdePkg/UefiLib: Add EfiLocateProtocolBuffer= () Star, I agree with your observation. And the API specifically says that EFI_BOOT= _SERVICES.AllocatePool() is used, so I agree with your suggested change. However, there are other APIs in the UefiLib implementation that use the Me= moryAllocationLib services. Should those be updated too? Mike > -----Original Message----- > From: Zeng, Star > Sent: Wednesday, January 31, 2018 5:32 PM > To: Kinney, Michael D ; edk2-=20 > devel@lists.01.org > Cc: Kinney, Michael D ; Yao, Jiewen=20 > ; Gao, Liming ; Zeng, Star=20 > > Subject: RE: [edk2] [Patch 1/1] MdePkg/UefiLib: Add > EfiLocateProtocolBuffer() >=20 > Hi Mike, >=20 > UefiLib is capable to be used by SMM Core or SMM driver before=20 > SmmReadyToLock. >=20 > And the new interface has the comment below. >=20 > + The returned buffer is > allocated using > + > EFI_BOOT_SERVICES.AllocatePool(). The caller is > + responsible for freeing this > buffer with > + > EFI_BOOT_SERVICES.FreePool(). >=20 > But the implementation is using AllocateZeroPool() like below, that=20 > will direct to gSmst->AllocatePool for SMM Core or SMM driver. >=20 > + // > + // Allocate array of protocol instances // *Buffer =3D=20 > + AllocateZeroPool (NoHandles * sizeof (VOID > *)); > + if (*Buffer =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } >=20 > Should the implementation use gBS->AllocatePool() + > ZeroMem() instead of AllocateZeroPool()? >=20 >=20 > Thanks, > Star > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] > On Behalf Of Kinney, Michael D > Sent: Thursday, February 1, 2018 7:33 AM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Yao, Jiewen=20 > ; Gao, Liming > Subject: [edk2] [Patch 1/1] MdePkg/UefiLib: Add > EfiLocateProtocolBuffer() >=20 > From: Michael D Kinney >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D838 >=20 > Add new API to the UefiLib that locates and returns an array of=20 > protocols instances that match a given protocol. >=20 > Cc: Sean Brogan > Cc: Jiewen Yao > Cc: Liming Gao > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Michael D Kinney > > --- > MdePkg/Include/Library/UefiLib.h | 32 +++++++++++- =20 > MdePkg/Library/UefiLib/UefiLib.c | 107 > ++++++++++++++++++++++++++++++++++++++- > 2 files changed, 137 insertions(+), 2 deletions(-) >=20 > diff --git a/MdePkg/Include/Library/UefiLib.h > b/MdePkg/Include/Library/UefiLib.h > index 0b14792a0a..54bc2cc5a3 100644 > --- a/MdePkg/Include/Library/UefiLib.h > +++ b/MdePkg/Include/Library/UefiLib.h > @@ -12,7 +12,7 @@ > of size reduction when compiler optimization is disabled. If=20 > MDEPKG_NDEBUG is > defined, then debug and assert related macros wrapped by it are the=20 > NULL implementations. >=20 > -Copyright (c) 2006 - 2017, Intel Corporation. All rights=20 > reserved.
> +Copyright (c) 2006 - 2018, Intel Corporation. All rights > reserved.
> This program and the accompanying materials are licensed and made=20 > available under the terms and conditions of the BSD License that=20 > accompanies this distribution. > The full text of the license may be found at @@ -1490,4 +1490,34 @@=20 > CatSPrint ( > ... > ); >=20 > +/** > + Returns an array of protocol instance that matches the > given protocol. > + > + @param[in] Protocol Provides the protocol to > search for. > + @param[out] NoProtocols The number of protocols > returned in Buffer. > + @param[out] Buffer A pointer to the buffer to > return the requested > + array of protocol instances > that match Protocol. > + The returned buffer is > allocated using > + > EFI_BOOT_SERVICES.AllocatePool(). The caller is > + responsible for freeing this > buffer with > + > EFI_BOOT_SERVICES.FreePool(). > + > + @retval EFI_SUCCESS The array of protocols > was returned in Buffer, > + and the number of > protocols in Buffer was > + returned in > NoProtocols. > + @retval EFI_NOT_FOUND No protocols found. > + @retval EFI_OUT_OF_RESOURCES There is not enough > pool memory to store the > + matching results. > + @retval EFI_INVALID_PARAMETER Protocol is NULL. > + @retval EFI_INVALID_PARAMETER NoProtocols is NULL. > + @retval EFI_INVALID_PARAMETER Buffer is NULL. > + > +**/ > +EFI_STATUS > +EFIAPI > +EfiLocateProtocolBuffer ( > + IN EFI_GUID *Protocol, > + OUT UINTN *NoProtocols, > + OUT VOID ***Buffer > + ); > #endif > diff --git a/MdePkg/Library/UefiLib/UefiLib.c > b/MdePkg/Library/UefiLib/UefiLib.c > index a7eee01240..d86db4bd67 100644 > --- a/MdePkg/Library/UefiLib/UefiLib.c > +++ b/MdePkg/Library/UefiLib/UefiLib.c > @@ -5,7 +5,7 @@ > EFI Driver Model related protocols, manage Unicode string tables=20 > for UEFI Drivers, > and print messages on the console output and standard error=20 > devices. >=20 > - Copyright (c) 2006 - 2017, Intel Corporation. All rights=20 > reserved.
> + Copyright (c) 2006 - 2018, Intel Corporation. All > rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of=20 > the BSD License > which accompanies this distribution. The full text of the license=20 > may be found at @@ -1605,3 +1605,108 @@ GetBestLanguage ( > // > return NULL; > } > + > +/** > + Returns an array of protocol instance that matches the > given protocol. > + > + @param[in] Protocol Provides the protocol to > search for. > + @param[out] NoProtocols The number of protocols > returned in Buffer. > + @param[out] Buffer A pointer to the buffer to > return the requested > + array of protocol instances > that match Protocol. > + The returned buffer is > allocated using > + > EFI_BOOT_SERVICES.AllocatePool(). The caller is > + responsible for freeing this > buffer with > + > EFI_BOOT_SERVICES.FreePool(). > + > + @retval EFI_SUCCESS The array of protocols > was returned in Buffer, > + and the number of > protocols in Buffer was > + returned in > NoProtocols. > + @retval EFI_NOT_FOUND No protocols found. > + @retval EFI_OUT_OF_RESOURCES There is not enough > pool memory to store the > + matching results. > + @retval EFI_INVALID_PARAMETER Protocol is NULL. > + @retval EFI_INVALID_PARAMETER NoProtocols is NULL. > + @retval EFI_INVALID_PARAMETER Buffer is NULL. > + > +**/ > +EFI_STATUS > +EFIAPI > +EfiLocateProtocolBuffer ( > + IN EFI_GUID *Protocol, > + OUT UINTN *NoProtocols, > + OUT VOID ***Buffer > + ) > +{ > + EFI_STATUS Status; > + UINTN NoHandles; > + EFI_HANDLE *HandleBuffer; > + UINTN Index; > + > + // > + // Check input parameters > + // > + if (Protocol =3D=3D NULL || NoProtocols =3D=3D NULL || Buffer > =3D=3D NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // Initialze output parameters > + // > + *NoProtocols =3D 0; > + *Buffer =3D NULL; > + > + // > + // Retrieve the array of handles that support Protocol // Status=20 > + =3D gBS->LocateHandleBuffer ( > + ByProtocol, > + Protocol, > + NULL, > + &NoHandles, > + &HandleBuffer > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // Allocate array of protocol instances // *Buffer =3D=20 > + AllocateZeroPool (NoHandles * sizeof (VOID > *)); > + if (*Buffer =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + // > + // Lookup Protocol on each handle in HandleBuffer to > fill in the array of > + // protocol instances. Handle case where protocol > instance was present when > + // LocateHandleBuffer() was called, but is not present > when HandleProtocol() > + // is called. > + // > + for (Index =3D 0, *NoProtocols =3D 0; Index < NoHandles; > Index++) { > + Status =3D gBS->HandleProtocol ( > + HandleBuffer[Index], > + Protocol, > + &((*Buffer)[*NoProtocols]) > + ); > + if (!EFI_ERROR (Status)) { > + (*NoProtocols)++; > + } > + } > + > + // > + // Free the handle buffer > + // > + FreePool (HandleBuffer); > + > + // > + // Make sure at least one protocol instance was found // if=20 > + (*NoProtocols =3D=3D 0) { > + FreePool (*Buffer); > + *Buffer =3D NULL; > + return EFI_NOT_FOUND; > + } > + > + return EFI_SUCCESS; > +} > -- > 2.14.2.windows.3 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel