From nobody Tue May 7 23:42:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489131312081146.9300903830631; Thu, 9 Mar 2017 23:35:12 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 04B47803AD; Thu, 9 Mar 2017 23:35:11 -0800 (PST) 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 CFF5E803AA for ; Thu, 9 Mar 2017 23:35:08 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 23:35:08 -0800 Received: from jyao1-mobl.ccr.corp.intel.com ([10.239.192.59]) by fmsmga004.fm.intel.com with ESMTP; 09 Mar 2017 23:35:07 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,139,1486454400"; d="scan'208";a="234483243" From: Jiewen Yao To: edk2-devel@lists.01.org Date: Fri, 10 Mar 2017 15:35:01 +0800 Message-Id: <1489131303-3732-2-git-send-email-jiewen.yao@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1489131303-3732-1-git-send-email-jiewen.yao@intel.com> References: <1489131303-3732-1-git-send-email-jiewen.yao@intel.com> Subject: [edk2] [PATCH 1/3] MdePkg/SmiHandlerProfile: Add Context support in Unregister X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Jeff Fan , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The reason is that we observe that a platform may use same Handler for different context. In order to support Unregister such handler, we have to input context information as well. Cc: Jeff Fan Cc: Liming Gao Cc: Michael D Kinney Cc: Bret Barkelew Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao Reviewed-by: Feng Tian Reviewed-by: Jeff Fan --- MdePkg/Include/Library/SmiHandlerProfileLib.h | 8 +++= ++++- MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c | 8 +++= ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/MdePkg/Include/Library/SmiHandlerProfileLib.h b/MdePkg/Include= /Library/SmiHandlerProfileLib.h index 10b7323..77d19f9 100644 --- a/MdePkg/Include/Library/SmiHandlerProfileLib.h +++ b/MdePkg/Include/Library/SmiHandlerProfileLib.h @@ -66,6 +66,10 @@ SmiHandlerProfileRegisterHandler ( For the SmmChildDispatch protocol, the HandlerGuid must be the GUID of SmmChildDispatch protocol. @param Handler The SMI handler. + @param Context The context of the SMI handler. + If it is NOT NULL, it will be used to check what = is registered. + @param ContextSize The size of the context in bytes. + If Context is NOT NULL, it will be used to check = what is registered. =20 @retval EFI_SUCCESS The original record is removed. @retval EFI_UNSUPPORTED The feature is unsupported. @@ -75,7 +79,9 @@ EFI_STATUS EFIAPI SmiHandlerProfileUnregisterHandler ( IN EFI_GUID *HandlerGuid, - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler + IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, + IN VOID *Context, OPTIONAL + IN UINTN ContextSize OPTIONAL ); =20 #endif diff --git a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNu= ll.c b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c index 6ae4718..7f4855b 100644 --- a/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c +++ b/MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.c @@ -56,6 +56,10 @@ SmiHandlerProfileRegisterHandler ( For the SmmChildDispatch protocol, the HandlerGuid must be the GUID of SmmChildDispatch protocol. @param Handler The SMI handler. + @param Context The context of the SMI handler. + If it is NOT NULL, it will be used to check what = is registered. + @param ContextSize The size of the context in bytes. + If Context is NOT NULL, it will be used to check = what is registered. =20 @retval EFI_SUCCESS The original record is removed. @retval EFI_UNSUPPORTED The feature is unsupported. @@ -65,7 +69,9 @@ EFI_STATUS EFIAPI SmiHandlerProfileUnregisterHandler ( IN EFI_GUID *HandlerGuid, - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler + IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, + IN VOID *Context, OPTIONAL + IN UINTN ContextSize OPTIONAL ) { return EFI_UNSUPPORTED; --=20 2.7.4.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue May 7 23:42:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489131314584493.7530211105808; Thu, 9 Mar 2017 23:35:14 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3E6C2803B1; Thu, 9 Mar 2017 23:35:12 -0800 (PST) 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 5E5E7803AD for ; Thu, 9 Mar 2017 23:35:10 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 23:35:10 -0800 Received: from jyao1-mobl.ccr.corp.intel.com ([10.239.192.59]) by fmsmga004.fm.intel.com with ESMTP; 09 Mar 2017 23:35:08 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,139,1486454400"; d="scan'208";a="234483253" From: Jiewen Yao To: edk2-devel@lists.01.org Date: Fri, 10 Mar 2017 15:35:02 +0800 Message-Id: <1489131303-3732-3-git-send-email-jiewen.yao@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1489131303-3732-1-git-send-email-jiewen.yao@intel.com> References: <1489131303-3732-1-git-send-email-jiewen.yao@intel.com> Subject: [edk2] [PATCH 2/3] MdeModulePkg/SmiHandlerProfile: Add Context support in Unregister X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Feng Tian , Jeff Fan , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The reason is that we observe that a platform may use same Handler for different context. In order to support Unregister such handler, we have to input context information as well. Cc: Jeff Fan Cc: Feng Tian Cc: Star Zeng Cc: Bret Barkelew Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao Reviewed-by: Feng Tian Reviewed-by: Jeff Fan --- MdeModulePkg/Include/Guid/SmiHandlerProfile.h | 4= 1 +++++++++++++++++++- MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c | 1= 0 ++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Include/Guid/SmiHandlerProfile.h b/MdeModulePkg/I= nclude/Guid/SmiHandlerProfile.h index b81631d..c5d29e8 100644 --- a/MdeModulePkg/Include/Guid/SmiHandlerProfile.h +++ b/MdeModulePkg/Include/Guid/SmiHandlerProfile.h @@ -150,6 +150,26 @@ extern EFI_GUID gSmiHandlerProfileGuid; =20 typedef struct _SMI_HANDLER_PROFILE_PROTOCOL SMI_HANDLER_PROFILE_PROTOCOL; =20 +/** + This function is called by SmmChildDispatcher module to report + a new SMI handler is registered, to SmmCore. + + @param This The protocol instance + @param HandlerGuid The GUID to identify the type of the handler. + For the SmmChildDispatch protocol, the HandlerGuid + must be the GUID of SmmChildDispatch protocol. + @param Handler The SMI handler. + @param CallerAddress The address of the module who registers the SMI h= andler. + @param Context The context of the SMI handler. + For the SmmChildDispatch protocol, the Context + must match the one defined for SmmChildDispatch p= rotocol. + @param ContextSize The size of the context in bytes. + For the SmmChildDispatch protocol, the Context + must match the one defined for SmmChildDispatch p= rotocol. + + @retval EFI_SUCCESS The information is recorded. + @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the = information. +**/ typedef EFI_STATUS (EFIAPI *SMI_HANDLER_PROFILE_REGISTER_HANDLER) ( @@ -161,12 +181,31 @@ EFI_STATUS IN UINTN ContextSize OPTIONAL ); =20 +/** + This function is called by SmmChildDispatcher module to report + an existing SMI handler is unregistered, to SmmCore. + + @param This The protocol instance + @param HandlerGuid The GUID to identify the type of the handler. + For the SmmChildDispatch protocol, the HandlerGuid + must be the GUID of SmmChildDispatch protocol. + @param Handler The SMI handler. + @param Context The context of the SMI handler. + If it is NOT NULL, it will be used to check what = is registered. + @param ContextSize The size of the context in bytes. + If Context is NOT NULL, it will be used to check = what is registered. + + @retval EFI_SUCCESS The original record is removed. + @retval EFI_NOT_FOUND There is no record for the HandlerGuid and= handler. +**/ typedef EFI_STATUS (EFIAPI *SMI_HANDLER_PROFILE_UNREGISTER_HANDLER) ( IN SMI_HANDLER_PROFILE_PROTOCOL *This, IN EFI_GUID *HandlerGuid, - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler + IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, + IN VOID *Context, OPTIONAL + IN UINTN ContextSize OPTIONAL ); =20 struct _SMI_HANDLER_PROFILE_PROTOCOL { diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProf= ileLib.c b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfil= eLib.c index 2edc71b..2911619 100644 --- a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c +++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c @@ -63,6 +63,10 @@ SmiHandlerProfileRegisterHandler ( For the SmmChildDispatch protocol, the HandlerGuid must be the GUID of SmmChildDispatch protocol. @param Handler The SMI handler. + @param Context The context of the SMI handler. + If it is NOT NULL, it will be used to check what = is registered. + @param ContextSize The size of the context in bytes. + If Context is NOT NULL, it will be used to check = what is registered. =20 @retval EFI_SUCCESS The original record is removed. @retval EFI_UNSUPPORTED The feature is unsupported. @@ -72,11 +76,13 @@ EFI_STATUS EFIAPI SmiHandlerProfileUnregisterHandler ( IN EFI_GUID *HandlerGuid, - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler + IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, + IN VOID *Context, OPTIONAL + IN UINTN ContextSize OPTIONAL ) { if (mSmiHandlerProfile !=3D NULL) { - return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, Hand= lerGuid, Handler); + return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, Hand= lerGuid, Handler, Context, ContextSize); } return EFI_UNSUPPORTED; } --=20 2.7.4.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue May 7 23:42:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489131317098427.2304332141798; Thu, 9 Mar 2017 23:35:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 793BC803B0; Thu, 9 Mar 2017 23:35:14 -0800 (PST) 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 BBDA0803B0 for ; Thu, 9 Mar 2017 23:35:11 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 23:35:11 -0800 Received: from jyao1-mobl.ccr.corp.intel.com ([10.239.192.59]) by fmsmga004.fm.intel.com with ESMTP; 09 Mar 2017 23:35:10 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,139,1486454400"; d="scan'208";a="234483259" From: Jiewen Yao To: edk2-devel@lists.01.org Date: Fri, 10 Mar 2017 15:35:03 +0800 Message-Id: <1489131303-3732-4-git-send-email-jiewen.yao@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1489131303-3732-1-git-send-email-jiewen.yao@intel.com> References: <1489131303-3732-1-git-send-email-jiewen.yao@intel.com> Subject: [edk2] [PATCH 3/3] MdeModulePkg/SmmCore: Add Context in SmiHandlerProfileUnregister. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Feng Tian , Jeff Fan , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The reason is that we observe that a platform may use same Handler for different context. In order to support Unregister such handler, we have to input context information as well. Cc: Jeff Fan Cc: Feng Tian Cc: Star Zeng Cc: Bret Barkelew Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao Reviewed-by: Feng Tian Reviewed-by: Jeff Fan --- MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 8 +- MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c | 103 ++++++++++++++++---- 2 files changed, 89 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/Pi= SmmCore/PiSmmCore.h index 45b9d97..c12805a 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h @@ -1139,6 +1139,10 @@ SmiHandlerProfileRegisterHandler ( For the SmmChildDispatch protocol, the HandlerGuid must be the GUID of SmmChildDispatch protocol. @param Handler The SMI handler. + @param Context The context of the SMI handler. + If it is NOT NULL, it will be used to check what = is registered. + @param ContextSize The size of the context in bytes. + If Context is NOT NULL, it will be used to check = what is registered. =20 @retval EFI_SUCCESS The original record is removed. @retval EFI_NOT_FOUND There is no record for the HandlerGuid and= handler. @@ -1148,7 +1152,9 @@ EFIAPI SmiHandlerProfileUnregisterHandler ( IN SMI_HANDLER_PROFILE_PROTOCOL *This, IN EFI_GUID *HandlerGuid, - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler + IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, + IN VOID *Context, OPTIONAL + IN UINTN ContextSize OPTIONAL ); =20 extern UINTN mFullSmramRangeCount; diff --git a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c b/MdeModulePkg= /Core/PiSmmCore/SmiHandlerProfile.c index f85c0f0..1e36039 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c +++ b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c @@ -1089,6 +1089,40 @@ SmmCoreFindHardwareSmiEntry ( } =20 /** + Convert EFI_SMM_USB_REGISTER_CONTEXT to SMI_HANDLER_PROFILE_USB_REGISTER= _CONTEXT. + + @param UsbContext A pointer to EFI_SMM_USB_REGISTER_CO= NTEXT + @param UsbContextSize The size of EFI_SMM_USB_REGISTER_CON= TEXT in bytes + @param SmiHandlerUsbContextSize The size of SMI_HANDLER_PROFILE_USB_= REGISTER_CONTEXT in bytes + + @return SmiHandlerUsbContext A pointer to SMI_HANDLER_PROFILE_USB_REGIS= TER_CONTEXT +**/ +SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT * +ConvertSmiHandlerUsbContext ( + IN EFI_SMM_USB_REGISTER_CONTEXT *UsbContext, + IN UINTN UsbContextSize, + OUT UINTN *SmiHandlerUsbContextSize + ) +{ + UINTN DevicePathSize; + SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *SmiHandlerUsbContext; + + ASSERT (UsbContextSize =3D=3D sizeof(EFI_SMM_USB_REGISTER_CONTEXT)); + + DevicePathSize =3D GetDevicePathSize (UsbContext->Device); + SmiHandlerUsbContext =3D AllocatePool (sizeof (SMI_HANDLER_PROFILE_USB_R= EGISTER_CONTEXT) + DevicePathSize); + if (SmiHandlerUsbContext =3D=3D NULL) { + *SmiHandlerUsbContextSize =3D 0; + return NULL; + } + SmiHandlerUsbContext->Type =3D UsbContext->Type; + SmiHandlerUsbContext->DevicePathSize =3D (UINT32)DevicePathSize; + CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathSize); + *SmiHandlerUsbContextSize =3D sizeof (SMI_HANDLER_PROFILE_USB_REGISTER_C= ONTEXT) + DevicePathSize; + return SmiHandlerUsbContext; +} + +/** This function is called by SmmChildDispatcher module to report a new SMI handler is registered, to SmmCore. =20 @@ -1123,6 +1157,11 @@ SmiHandlerProfileRegisterHandler ( SMI_ENTRY *SmiEntry; LIST_ENTRY *List; =20 + if (((ContextSize =3D=3D 0) && (Context !=3D NULL)) || + ((ContextSize !=3D 0) && (Context =3D=3D NULL))) { + return EFI_INVALID_PARAMETER; + } + SmiHandler =3D AllocateZeroPool (sizeof (SMI_HANDLER)); if (SmiHandler =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -1131,33 +1170,24 @@ SmiHandlerProfileRegisterHandler ( SmiHandler->Signature =3D SMI_HANDLER_SIGNATURE; SmiHandler->Handler =3D Handler; SmiHandler->CallerAddr =3D (UINTN)CallerAddress; - if (ContextSize !=3D 0 && Context !=3D NULL) { + SmiHandler->Context =3D Context; + SmiHandler->ContextSize =3D ContextSize; + + if (Context !=3D NULL) { if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) { - EFI_SMM_USB_REGISTER_CONTEXT *UsbContext; - UINTN DevicePathSize; - SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT *SmiHandlerUsbContext; - - ASSERT (ContextSize =3D=3D sizeof(EFI_SMM_USB_REGISTER_CONTEXT)); - - UsbContext =3D (EFI_SMM_USB_REGISTER_CONTEXT *)Context; - DevicePathSize =3D GetDevicePathSize (UsbContext->Device); - SmiHandlerUsbContext =3D AllocatePool (sizeof (SMI_HANDLER_PROFILE_U= SB_REGISTER_CONTEXT) + DevicePathSize); - if (SmiHandlerUsbContext !=3D NULL) { - SmiHandlerUsbContext->Type =3D UsbContext->Type; - SmiHandlerUsbContext->DevicePathSize =3D (UINT32)DevicePathSize; - CopyMem (SmiHandlerUsbContext + 1, UsbContext->Device, DevicePathS= ize); - SmiHandler->Context =3D SmiHandlerUsbContext; - } + SmiHandler->Context =3D ConvertSmiHandlerUsbContext (Context, Contex= tSize, &SmiHandler->ContextSize); } else { SmiHandler->Context =3D AllocateCopyPool (ContextSize, Context); } } - if (SmiHandler->Context !=3D NULL) { - SmiHandler->ContextSize =3D ContextSize; + if (SmiHandler->Context =3D=3D NULL) { + SmiHandler->ContextSize =3D 0; } =20 SmiEntry =3D SmmCoreFindHardwareSmiEntry (HandlerGuid, TRUE); if (SmiEntry =3D=3D NULL) { + FreePool (SmiHandler->Context); + FreePool (SmiHandler); return EFI_OUT_OF_RESOURCES; } =20 @@ -1178,6 +1208,10 @@ SmiHandlerProfileRegisterHandler ( For the SmmChildDispatch protocol, the HandlerGuid must be the GUID of SmmChildDispatch protocol. @param Handler The SMI handler. + @param Context The context of the SMI handler. + If it is NOT NULL, it will be used to check what = is registered. + @param ContextSize The size of the context in bytes. + If Context is NOT NULL, it will be used to check = what is registered. =20 @retval EFI_SUCCESS The original record is removed. @retval EFI_NOT_FOUND There is no record for the HandlerGuid and= handler. @@ -1187,7 +1221,9 @@ EFIAPI SmiHandlerProfileUnregisterHandler ( IN SMI_HANDLER_PROFILE_PROTOCOL *This, IN EFI_GUID *HandlerGuid, - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler + IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, + IN VOID *Context, OPTIONAL + IN UINTN ContextSize OPTIONAL ) { LIST_ENTRY *Link; @@ -1195,21 +1231,46 @@ SmiHandlerProfileUnregisterHandler ( SMI_HANDLER *SmiHandler; SMI_ENTRY *SmiEntry; SMI_HANDLER *TargetSmiHandler; + VOID *SearchContext; + UINTN SearchContextSize; + + if (((ContextSize =3D=3D 0) && (Context !=3D NULL)) || + ((ContextSize !=3D 0) && (Context =3D=3D NULL))) { + return EFI_INVALID_PARAMETER; + } =20 SmiEntry =3D SmmCoreFindHardwareSmiEntry (HandlerGuid, FALSE); if (SmiEntry =3D=3D NULL) { return EFI_NOT_FOUND; } =20 + SearchContext =3D Context; + SearchContextSize =3D ContextSize; + if (Context !=3D NULL) { + if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) { + SearchContext =3D ConvertSmiHandlerUsbContext (Context, ContextSize,= &SearchContextSize); + } + } + TargetSmiHandler =3D NULL; Head =3D &SmiEntry->SmiHandlers; for (Link =3D Head->ForwardLink; Link !=3D Head; Link =3D Link->ForwardL= ink) { SmiHandler =3D CR (Link, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE); if (SmiHandler->Handler =3D=3D Handler) { - TargetSmiHandler =3D SmiHandler; - break; + if ((SearchContext =3D=3D NULL) || + ((SearchContextSize =3D=3D SmiHandler->ContextSize) && (CompareM= em (SearchContext, SmiHandler->Context, SearchContextSize) =3D=3D 0))) { + TargetSmiHandler =3D SmiHandler; + break; + } + } + } + + if (SearchContext !=3D NULL) { + if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) { + FreePool (SearchContext); } } + if (TargetSmiHandler =3D=3D NULL) { return EFI_NOT_FOUND; } --=20 2.7.4.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel