]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StandaloneMmPkg/Core/Locate.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / StandaloneMmPkg / Core / Locate.c
index 95c40ca7be0445765bd76553c547d59490f49a20..0cf04b9c8d0cda0d15c1f6cdaf6f6cd5b58125d3 100644 (file)
 //\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
@@ -49,7 +49,7 @@ MmGetNextLocateAllHandles (
   OUT    VOID             **Interface\r
   )\r
 {\r
-  IHANDLE     *Handle;\r
+  IHANDLE  *Handle;\r
 \r
   //\r
   // Next handle\r
@@ -59,11 +59,12 @@ MmGetNextLocateAllHandles (
   //\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
@@ -90,8 +91,8 @@ MmGetNextLocateByRegisterNotify (
   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
@@ -106,11 +107,12 @@ MmGetNextLocateByRegisterNotify (
     //\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
@@ -135,13 +137,13 @@ MmGetNextLocateByProtocol (
   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
@@ -155,8 +157,8 @@ MmGetNextLocateByProtocol (
     //\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
@@ -168,6 +170,7 @@ MmGetNextLocateByProtocol (
       break;\r
     }\r
   }\r
+\r
   return Handle;\r
 }\r
 \r
@@ -195,17 +198,17 @@ MmLocateProtocol (
   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
@@ -224,6 +227,7 @@ MmLocateProtocol (
     if (Position.ProtEntry == NULL) {\r
       return EFI_NOT_FOUND;\r
     }\r
+\r
     Position.Position = &Position.ProtEntry->Protocols;\r
 \r
     Handle = MmGetNextLocateByProtocol (&Position, Interface);\r
@@ -238,7 +242,7 @@ MmLocateProtocol (
     // 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
@@ -299,48 +303,51 @@ MmLocateHandle (
   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 = MmGetNextLocateAllHandles;\r
-    break;\r
+    case AllHandles:\r
+      GetNext = MmGetNextLocateAllHandles;\r
+      break;\r
 \r
-  case ByRegisterNotify:\r
-    GetNext = MmGetNextLocateByRegisterNotify;\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 = MmGetNextLocateByRegisterNotify;\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 = MmGetNextLocateByProtocol;\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 = MmFindProtocolEntry (Protocol, FALSE);\r
-    if (Position.ProtEntry == NULL) {\r
-      Status = EFI_NOT_FOUND;\r
+\r
+    case ByProtocol:\r
+      GetNext = MmGetNextLocateByProtocol;\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 = MmFindProtocolEntry (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
@@ -351,7 +358,7 @@ MmLocateHandle (
   // 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
@@ -366,8 +373,8 @@ MmLocateHandle (
     //\r
     ResultSize += sizeof (Handle);\r
     if (ResultSize <= *BufferSize) {\r
-        *ResultBuffer = Handle;\r
-        ResultBuffer += 1;\r
+      *ResultBuffer = Handle;\r
+      ResultBuffer += 1;\r
     }\r
   }\r
 \r
@@ -388,13 +395,13 @@ MmLocateHandle (
 \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
@@ -445,26 +452,27 @@ MmLocateHandleBuffer (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  BufferSize = 0;\r
+  BufferSize     = 0;\r
   *NumberHandles = 0;\r
-  *Buffer = NULL;\r
-  Status = MmLocateHandle (\r
-             SearchType,\r
-             Protocol,\r
-             SearchKey,\r
-             &BufferSize,\r
-             *Buffer\r
-             );\r
+  *Buffer        = NULL;\r
+  Status         = MmLocateHandle (\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 MmLocateHandle().\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
@@ -481,7 +489,7 @@ MmLocateHandleBuffer (
              *Buffer\r
              );\r
 \r
-  *NumberHandles = BufferSize / sizeof(EFI_HANDLE);\r
+  *NumberHandles = BufferSize / sizeof (EFI_HANDLE);\r
   if (EFI_ERROR (Status)) {\r
     *NumberHandles = 0;\r
   }\r