]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/Locate.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / Locate.c
index 3420170b0de8172c84498b695721ced19745bdab..2d553625801bf4d64b65150c15485805c648869e 100644 (file)
@@ -2,13 +2,7 @@
   Locate handle functions\r
 \r
   Copyright (c) 2009 - 2018, 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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 //\r
 // ProtocolRequest - Last LocateHandle request ID\r
 //\r
-UINTN mEfiLocateHandleRequest = 0;\r
+UINTN  mEfiLocateHandleRequest = 0;\r
 \r
 //\r
 // Internal prototypes\r
 //\r
 \r
 typedef struct {\r
-  EFI_GUID        *Protocol;\r
-  VOID            *SearchKey;\r
-  LIST_ENTRY      *Position;\r
-  PROTOCOL_ENTRY  *ProtEntry;\r
+  EFI_GUID          *Protocol;\r
+  VOID              *SearchKey;\r
+  LIST_ENTRY        *Position;\r
+  PROTOCOL_ENTRY    *ProtEntry;\r
 } LOCATE_POSITION;\r
 \r
 typedef\r
 IHANDLE *\r
-(* CORE_GET_NEXT) (\r
-  IN OUT LOCATE_POSITION    *Position,\r
-  OUT VOID                  **Interface\r
+(*CORE_GET_NEXT) (\r
+  IN OUT LOCATE_POSITION  *Position,\r
+  OUT VOID                **Interface\r
   );\r
 \r
 /**\r
   Routine to get the next Handle, when you are searching for all handles.\r
 \r
-  @param  Position               Information about which Handle to seach for.\r
+  @param  Position               Information about which Handle to search for.\r
   @param  Interface              Return the interface structure for the matching\r
                                  protocol.\r
 \r
@@ -54,7 +48,7 @@ SmmGetNextLocateAllHandles (
   OUT    VOID             **Interface\r
   )\r
 {\r
-  IHANDLE     *Handle;\r
+  IHANDLE  *Handle;\r
 \r
   //\r
   // Next handle\r
@@ -64,11 +58,12 @@ SmmGetNextLocateAllHandles (
   //\r
   // If not at the end of the list, get the handle\r
   //\r
-  Handle      = NULL;\r
-  *Interface  = NULL;\r
+  Handle     = NULL;\r
+  *Interface = NULL;\r
   if (Position->Position != &gHandleList) {\r
     Handle = CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);\r
   }\r
+\r
   return Handle;\r
 }\r
 \r
@@ -76,7 +71,7 @@ SmmGetNextLocateAllHandles (
   Routine to get the next Handle, when you are searching for register protocol\r
   notifies.\r
 \r
-  @param  Position               Information about which Handle to seach for.\r
+  @param  Position               Information about which Handle to search for.\r
   @param  Interface              Return the interface structure for the matching\r
                                  protocol.\r
 \r
@@ -95,15 +90,15 @@ SmmGetNextLocateByRegisterNotify (
   PROTOCOL_INTERFACE  *Prot;\r
   LIST_ENTRY          *Link;\r
 \r
-  Handle      = NULL;\r
-  *Interface  = NULL;\r
+  Handle     = NULL;\r
+  *Interface = NULL;\r
   ProtNotify = Position->SearchKey;\r
 \r
   //\r
   // If this is the first request, get the next handle\r
   //\r
   if (ProtNotify != NULL) {\r
-    ASSERT(ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);\r
+    ASSERT (ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);\r
     Position->SearchKey = NULL;\r
 \r
     //\r
@@ -111,18 +106,19 @@ SmmGetNextLocateByRegisterNotify (
     //\r
     Link = ProtNotify->Position->ForwardLink;\r
     if (Link != &ProtNotify->Protocol->Protocols) {\r
-      Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);\r
-      Handle = Prot->Handle;\r
+      Prot       = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);\r
+      Handle     = Prot->Handle;\r
       *Interface = Prot->Interface;\r
     }\r
   }\r
+\r
   return Handle;\r
 }\r
 \r
 /**\r
   Routine to get the next Handle, when you are searching for a given protocol.\r
 \r
-  @param  Position               Information about which Handle to seach for.\r
+  @param  Position               Information about which Handle to search for.\r
   @param  Interface              Return the interface structure for the matching\r
                                  protocol.\r
 \r
@@ -140,13 +136,13 @@ SmmGetNextLocateByProtocol (
   LIST_ENTRY          *Link;\r
   PROTOCOL_INTERFACE  *Prot;\r
 \r
-  Handle      = NULL;\r
-  *Interface  = NULL;\r
-  for (; ;) {\r
+  Handle     = NULL;\r
+  *Interface = NULL;\r
+  for ( ; ;) {\r
     //\r
     // Next entry\r
     //\r
-    Link = Position->Position->ForwardLink;\r
+    Link               = Position->Position->ForwardLink;\r
     Position->Position = Link;\r
 \r
     //\r
@@ -160,8 +156,8 @@ SmmGetNextLocateByProtocol (
     //\r
     // Get the handle\r
     //\r
-    Prot = CR(Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);\r
-    Handle = Prot->Handle;\r
+    Prot       = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE);\r
+    Handle     = Prot->Handle;\r
     *Interface = Prot->Interface;\r
 \r
     //\r
@@ -173,13 +169,14 @@ SmmGetNextLocateByProtocol (
       break;\r
     }\r
   }\r
+\r
   return Handle;\r
 }\r
 \r
 /**\r
   Return the first Protocol Interface that matches the Protocol GUID. If\r
   Registration is pasased in return a Protocol Instance that was just add\r
-  to the system. If Retistration is NULL return the first Protocol Interface\r
+  to the system. If Registration is NULL return the first Protocol Interface\r
   you find.\r
 \r
   @param  Protocol               The protocol to search for\r
@@ -200,17 +197,17 @@ SmmLocateProtocol (
   OUT VOID      **Interface\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
-  LOCATE_POSITION         Position;\r
-  PROTOCOL_NOTIFY         *ProtNotify;\r
-  IHANDLE                 *Handle;\r
+  EFI_STATUS       Status;\r
+  LOCATE_POSITION  Position;\r
+  PROTOCOL_NOTIFY  *ProtNotify;\r
+  IHANDLE          *Handle;\r
 \r
   if ((Interface == NULL) || (Protocol == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   *Interface = NULL;\r
-  Status = EFI_SUCCESS;\r
+  Status     = EFI_SUCCESS;\r
 \r
   //\r
   // Set initial position\r
@@ -229,6 +226,7 @@ SmmLocateProtocol (
     if (Position.ProtEntry == NULL) {\r
       return EFI_NOT_FOUND;\r
     }\r
+\r
     Position.Position = &Position.ProtEntry->Protocols;\r
 \r
     Handle = SmmGetNextLocateByProtocol (&Position, Interface);\r
@@ -243,7 +241,7 @@ SmmLocateProtocol (
     // If this is a search by register notify and a handle was\r
     // returned, update the register notification position\r
     //\r
-    ProtNotify = Registration;\r
+    ProtNotify           = Registration;\r
     ProtNotify->Position = ProtNotify->Position->ForwardLink;\r
   }\r
 \r
@@ -304,51 +302,54 @@ SmmLocateHandle (
   Position.SearchKey = SearchKey;\r
   Position.Position  = &gHandleList;\r
 \r
-  ResultSize = 0;\r
-  ResultBuffer = (IHANDLE **) Buffer;\r
-  Status = EFI_SUCCESS;\r
+  ResultSize   = 0;\r
+  ResultBuffer = (IHANDLE **)Buffer;\r
+  Status       = EFI_SUCCESS;\r
 \r
   //\r
   // Get the search function based on type\r
   //\r
   switch (SearchType) {\r
-  case AllHandles:\r
-    GetNext = SmmGetNextLocateAllHandles;\r
-    break;\r
+    case AllHandles:\r
+      GetNext = SmmGetNextLocateAllHandles;\r
+      break;\r
 \r
-  case ByRegisterNotify:\r
-    GetNext = SmmGetNextLocateByRegisterNotify;\r
-    //\r
-    // Must have SearchKey for locate ByRegisterNotify\r
-    //\r
-    if (SearchKey == NULL) {\r
-      Status = EFI_INVALID_PARAMETER;\r
-    }\r
-    break;\r
+    case ByRegisterNotify:\r
+      GetNext = SmmGetNextLocateByRegisterNotify;\r
+      //\r
+      // Must have SearchKey for locate ByRegisterNotify\r
+      //\r
+      if (SearchKey == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
 \r
-  case ByProtocol:\r
-    GetNext = SmmGetNextLocateByProtocol;\r
-    if (Protocol == NULL) {\r
-      Status = EFI_INVALID_PARAMETER;\r
       break;\r
-    }\r
-    //\r
-    // Look up the protocol entry and set the head pointer\r
-    //\r
-    Position.ProtEntry = SmmFindProtocolEntry (Protocol, FALSE);\r
-    if (Position.ProtEntry == NULL) {\r
-      Status = EFI_NOT_FOUND;\r
+\r
+    case ByProtocol:\r
+      GetNext = SmmGetNextLocateByProtocol;\r
+      if (Protocol == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+        break;\r
+      }\r
+\r
+      //\r
+      // Look up the protocol entry and set the head pointer\r
+      //\r
+      Position.ProtEntry = SmmFindProtocolEntry (Protocol, FALSE);\r
+      if (Position.ProtEntry == NULL) {\r
+        Status = EFI_NOT_FOUND;\r
+        break;\r
+      }\r
+\r
+      Position.Position = &Position.ProtEntry->Protocols;\r
       break;\r
-    }\r
-    Position.Position = &Position.ProtEntry->Protocols;\r
-    break;\r
 \r
-  default:\r
-    Status = EFI_INVALID_PARAMETER;\r
-    break;\r
+    default:\r
+      Status = EFI_INVALID_PARAMETER;\r
+      break;\r
   }\r
 \r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
@@ -356,7 +357,7 @@ SmmLocateHandle (
   // Enumerate out the matching handles\r
   //\r
   mEfiLocateHandleRequest += 1;\r
-  for (; ;) {\r
+  for ( ; ;) {\r
     //\r
     // Get the next handle.  If no more handles, stop\r
     //\r
@@ -369,10 +370,10 @@ SmmLocateHandle (
     // Increase the resulting buffer size, and if this handle\r
     // fits return it\r
     //\r
-    ResultSize += sizeof(Handle);\r
+    ResultSize += sizeof (Handle);\r
     if (ResultSize <= *BufferSize) {\r
-        *ResultBuffer = Handle;\r
-        ResultBuffer += 1;\r
+      *ResultBuffer = Handle;\r
+      ResultBuffer += 1;\r
     }\r
   }\r
 \r
@@ -393,13 +394,13 @@ SmmLocateHandle (
 \r
     *BufferSize = ResultSize;\r
 \r
-    if (SearchType == ByRegisterNotify && !EFI_ERROR(Status)) {\r
+    if ((SearchType == ByRegisterNotify) && !EFI_ERROR (Status)) {\r
       ASSERT (SearchKey != NULL);\r
       //\r
       // If this is a search by register notify and a handle was\r
       // returned, update the register notification position\r
       //\r
-      ProtNotify = SearchKey;\r
+      ProtNotify           = SearchKey;\r
       ProtNotify->Position = ProtNotify->Position->ForwardLink;\r
     }\r
   }\r
@@ -450,26 +451,27 @@ SmmLocateHandleBuffer (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  BufferSize = 0;\r
+  BufferSize     = 0;\r
   *NumberHandles = 0;\r
-  *Buffer = NULL;\r
-  Status = SmmLocateHandle (\r
-             SearchType,\r
-             Protocol,\r
-             SearchKey,\r
-             &BufferSize,\r
-             *Buffer\r
-             );\r
+  *Buffer        = NULL;\r
+  Status         = SmmLocateHandle (\r
+                     SearchType,\r
+                     Protocol,\r
+                     SearchKey,\r
+                     &BufferSize,\r
+                     *Buffer\r
+                     );\r
   //\r
   // LocateHandleBuffer() returns incorrect status code if SearchType is\r
   // invalid.\r
   //\r
   // Add code to correctly handle expected errors from SmmLocateHandle().\r
   //\r
-  if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {\r
+  if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
     if (Status != EFI_INVALID_PARAMETER) {\r
       Status = EFI_NOT_FOUND;\r
     }\r
+\r
     return Status;\r
   }\r
 \r
@@ -486,8 +488,8 @@ SmmLocateHandleBuffer (
              *Buffer\r
              );\r
 \r
-  *NumberHandles = BufferSize / sizeof(EFI_HANDLE);\r
-  if (EFI_ERROR(Status)) {\r
+  *NumberHandles = BufferSize / sizeof (EFI_HANDLE);\r
+  if (EFI_ERROR (Status)) {\r
     *NumberHandles = 0;\r
   }\r
 \r