]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/Notify.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / Notify.c
index 8654f6e459df1085f30b64f665625fb95070fafc..7d5bff2576de72959a178f82ede190883349a0df 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Support functions for UEFI protocol notification infrastructure.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation.  All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available \r
-  under the terms and conditions of the BSD License which accompanies this \r
-  distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -30,8 +24,8 @@ SmmNotifyProtocol (
   LIST_ENTRY       *Link;\r
 \r
   ProtEntry = Prot->Protocol;\r
-  for (Link=ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {\r
-    ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
+  for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {\r
+    ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
     ProtNotify->Function (&ProtEntry->ProtocolID, Prot->Interface, Prot->Handle);\r
   }\r
 }\r
@@ -60,14 +54,13 @@ SmmRemoveInterfaceFromProtocol (
 \r
   Prot = SmmFindProtocolInterface (Handle, Protocol, Interface);\r
   if (Prot != NULL) {\r
-\r
     ProtEntry = Prot->Protocol;\r
 \r
     //\r
     // If there's a protocol notify location pointing to this entry, back it up one\r
     //\r
-    for(Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) {\r
-      ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
+    for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {\r
+      ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
 \r
       if (ProtNotify->Position == &Prot->ByProtocol) {\r
         ProtNotify->Position = Prot->ByProtocol.BackLink;\r
@@ -91,9 +84,11 @@ SmmRemoveInterfaceFromProtocol (
   @param  Function               Points to the notification function\r
   @param  Registration           Returns the registration record\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
   @retval EFI_SUCCESS            Successfully returned the registration record\r
-                                 that has been added\r
+                                 that has been added or unhooked\r
+  @retval EFI_INVALID_PARAMETER  Protocol is NULL or Registration is NULL\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough memory resource to finish the request\r
+  @retval EFI_NOT_FOUND          If the registration is not found when Function == NULL\r
 \r
 **/\r
 EFI_STATUS\r
@@ -109,28 +104,60 @@ SmmRegisterProtocolNotify (
   LIST_ENTRY       *Link;\r
   EFI_STATUS       Status;\r
 \r
-  if ((Protocol == NULL) || (Function == NULL) || (Registration == NULL))  {\r
+  if ((Protocol == NULL) || (Registration == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (Function == NULL) {\r
+    //\r
+    // Get the protocol entry per Protocol\r
+    //\r
+    ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, FALSE);\r
+    if (ProtEntry != NULL) {\r
+      ProtNotify = (PROTOCOL_NOTIFY *)*Registration;\r
+      for (Link = ProtEntry->Notify.ForwardLink;\r
+           Link != &ProtEntry->Notify;\r
+           Link = Link->ForwardLink)\r
+      {\r
+        //\r
+        // Compare the notification record\r
+        //\r
+        if (ProtNotify == (CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE))) {\r
+          //\r
+          // If Registration is an existing registration, then unhook it\r
+          //\r
+          ProtNotify->Signature = 0;\r
+          RemoveEntryList (&ProtNotify->Link);\r
+          FreePool (ProtNotify);\r
+          return EFI_SUCCESS;\r
+        }\r
+      }\r
+    }\r
+\r
+    //\r
+    // If the registration is not found\r
+    //\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   ProtNotify = NULL;\r
 \r
   //\r
   // Get the protocol entry to add the notification too\r
   //\r
-  ProtEntry = SmmFindProtocolEntry ((EFI_GUID *) Protocol, TRUE);\r
+  ProtEntry = SmmFindProtocolEntry ((EFI_GUID *)Protocol, TRUE);\r
   if (ProtEntry != NULL) {\r
     //\r
     // Find whether notification already exist\r
     //\r
     for (Link = ProtEntry->Notify.ForwardLink;\r
          Link != &ProtEntry->Notify;\r
-         Link = Link->ForwardLink) {\r
-\r
-      ProtNotify = CR(Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
+         Link = Link->ForwardLink)\r
+    {\r
+      ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
       if (CompareGuid (&ProtNotify->Protocol->ProtocolID, Protocol) &&\r
-          (ProtNotify->Function == Function)) {\r
-\r
+          (ProtNotify->Function == Function))\r
+      {\r
         //\r
         // Notification already exist\r
         //\r
@@ -143,11 +170,11 @@ SmmRegisterProtocolNotify (
     //\r
     // Allocate a new notification record\r
     //\r
-    ProtNotify = AllocatePool (sizeof(PROTOCOL_NOTIFY));\r
+    ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY));\r
     if (ProtNotify != NULL) {\r
       ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE;\r
-      ProtNotify->Protocol = ProtEntry;\r
-      ProtNotify->Function = Function;\r
+      ProtNotify->Protocol  = ProtEntry;\r
+      ProtNotify->Function  = Function;\r
       //\r
       // Start at the ending\r
       //\r
@@ -164,7 +191,8 @@ SmmRegisterProtocolNotify (
   Status = EFI_OUT_OF_RESOURCES;\r
   if (ProtNotify != NULL) {\r
     *Registration = ProtNotify;\r
-    Status = EFI_SUCCESS;\r
+    Status        = EFI_SUCCESS;\r
   }\r
+\r
   return Status;\r
 }\r