]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Hand/Handle.c
MdeModulePkg: Enhance the debug message for InstallProtocolInterface
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / Handle.c
index cda7d66d502cef18dde6d89b102778396d0dfd18..59b89148c8f0c51d6adb2ba7c615ffe8f4bf98b5 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   UEFI handle & protocol handling.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "DxeMain.h"\r
+#include "Handle.h"\r
 \r
 \r
 //\r
@@ -22,9 +23,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 // gHandleDatabaseKey    -  The Key to show that the handle has been created/modified\r
 //\r
 LIST_ENTRY      mProtocolDatabase     = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase);\r
-LIST_ENTRY             gHandleList           = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);\r
-EFI_LOCK               gProtocolDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r
-UINT64                 gHandleDatabaseKey    = 0;\r
+LIST_ENTRY      gHandleList           = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList);\r
+EFI_LOCK        gProtocolDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r
+UINT64          gHandleDatabaseKey    = 0;\r
 \r
 \r
 \r
@@ -364,7 +365,7 @@ CoreInstallProtocolInterfaceNotify (
   //\r
   // Print debug message\r
   //\r
-  DEBUG((DEBUG_LOAD | DEBUG_INFO, "InstallProtocolInterface: %g %p\n", Protocol, Interface));\r
+  DEBUG((DEBUG_INFO, "InstallProtocolInterface: %g %p\n", Protocol, Interface));\r
 \r
   Status = EFI_OUT_OF_RESOURCES;\r
   Prot = NULL;\r
@@ -427,11 +428,12 @@ CoreInstallProtocolInterfaceNotify (
     // in the system\r
     //\r
     InsertTailList (&gHandleList, &Handle->AllHandles);\r
-  }\r
-\r
-  Status = CoreValidateHandle (Handle);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Done;\r
+  } else {\r
+    Status = CoreValidateHandle (Handle);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG((DEBUG_ERROR, "InstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));\r
+      goto Done;\r
+    }\r
   }\r
 \r
   //\r
@@ -490,6 +492,7 @@ Done:
     if (Prot != NULL) {\r
       CoreFreePool (Prot);\r
     }\r
+    DEBUG((DEBUG_ERROR, "InstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));\r
   }\r
 \r
   return Status;\r
@@ -504,15 +507,20 @@ Done:
   occures all the protocols added by this function are removed. This is\r
   basically a lib function to save space.\r
 \r
-  @param  Handle                 The handle to install the protocol handlers on,\r
-                                 or NULL if a new handle is to be allocated\r
+  @param  Handle                 The pointer to a handle to install the new\r
+                                 protocol interfaces on, or a pointer to NULL\r
+                                 if a new handle is to be allocated.\r
   @param  ...                    EFI_GUID followed by protocol instance. A NULL\r
                                  terminates the  list. The pairs are the\r
                                  arguments to InstallProtocolInterface(). All the\r
                                  protocols are added to Handle.\r
 \r
+  @retval EFI_SUCCESS            All the protocol interface was installed.\r
+  @retval EFI_OUT_OF_RESOURCES   There was not enough memory in pool to install all the protocols.\r
+  @retval EFI_ALREADY_STARTED    A Device Path Protocol instance was passed in that is already present in\r
+                                 the handle database.\r
   @retval EFI_INVALID_PARAMETER  Handle is NULL.\r
-  @retval EFI_SUCCESS            Protocol interfaces successfully installed.\r
+  @retval EFI_INVALID_PARAMETER  Protocol is already installed on the handle specified by Handle.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -575,6 +583,7 @@ CoreInstallMultipleProtocolInterfaces (
     //\r
     Status = CoreInstallProtocolInterface (Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);\r
   }\r
+  VA_END (Args);\r
 \r
   //\r
   // If there was an error, remove all the interfaces that were installed without any errors\r
@@ -589,6 +598,8 @@ CoreInstallMultipleProtocolInterfaces (
       Interface = VA_ARG (Args, VOID *);\r
       CoreUninstallProtocolInterface (*Handle, Protocol, Interface);\r
     }\r
+    VA_END (Args);\r
+    \r
     *Handle = OldHandle;\r
   }\r
 \r
@@ -636,7 +647,7 @@ CoreDisconnectControllersUsingProtocolInterface (
           (Link != &Prot->OpenList) && !ItemFound;\r
           Link = Link->ForwardLink ) {\r
       OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r
-      if (OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) {\r
+      if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
         ItemFound = TRUE;\r
         CoreReleaseProtocolLock ();\r
         Status = CoreDisconnectController (UserHandle, OpenData->AgentHandle, NULL);\r
@@ -659,8 +670,8 @@ CoreDisconnectControllersUsingProtocolInterface (
             (Link != &Prot->OpenList) && !ItemFound;\r
             Link = Link->ForwardLink ) {\r
         OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r
-        if (OpenData->Attributes &\r
-            (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_PROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {\r
+        if ((OpenData->Attributes &\r
+            (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_PROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) != 0) {\r
           ItemFound = TRUE;\r
           RemoveEntryList (&OpenData->Link);\r
           Prot->OpenListCount--;\r
@@ -844,6 +855,7 @@ CoreUninstallMultipleProtocolInterfaces (
     //\r
     Status = CoreUninstallProtocolInterface (Handle, Protocol, Interface);\r
   }\r
+  VA_END (Args);\r
 \r
   //\r
   // If there was an error, add all the interfaces that were\r
@@ -859,6 +871,7 @@ CoreUninstallMultipleProtocolInterfaces (
       Interface = VA_ARG(Args, VOID *);\r
       CoreInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);\r
     }\r
+    VA_END (Args);\r
   }\r
 \r
   return Status;\r
@@ -918,7 +931,7 @@ CoreGetProtocolInterface (
 \r
   @retval EFI_SUCCESS            The interface information for the specified protocol was returned.\r
   @retval EFI_UNSUPPORTED        The device does not support the specified protocol.\r
-  @retval EFI_INVALID_PARAMETER  Handle is not a valid EFI_HANDLE..\r
+  @retval EFI_INVALID_PARAMETER  Handle is NULL..\r
   @retval EFI_INVALID_PARAMETER  Protocol is NULL.\r
   @retval EFI_INVALID_PARAMETER  Interface is NULL.\r
 \r
@@ -1080,14 +1093,14 @@ CoreOpenProtocol (
     ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&\r
                             (OpenData->Attributes == Attributes)  &&\r
                             (OpenData->ControllerHandle == ControllerHandle));\r
-    if (OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) {\r
+    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
       ByDriver = TRUE;\r
       if (ExactMatch) {\r
         Status = EFI_ALREADY_STARTED;\r
         goto Done;\r
       }\r
     }\r
-    if (OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) {\r
+    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {\r
       Exclusive = TRUE;\r
     } else if (ExactMatch) {\r
       OpenData->OpenCount++;\r
@@ -1121,7 +1134,7 @@ CoreOpenProtocol (
         Disconnect = FALSE;\r
         for ( Link = Prot->OpenList.ForwardLink; (Link != &Prot->OpenList) && (!Disconnect); Link = Link->ForwardLink) {\r
           OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r
-          if (OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) {\r
+          if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
             Disconnect = TRUE;\r
             CoreReleaseProtocolLock ();\r
             Status = CoreDisconnectController (UserHandle, OpenData->AgentHandle, NULL);\r