]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Hand/Handle.c
Remove DEBUG_LOAD for InstallProtocolInterface() to align with PPI installation debug...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Hand / Handle.c
index d95cef76dfe7ac44e31e3486f5118997c8c5600d..deae9d62513f7fa982154c9292b408107040eec6 100644 (file)
@@ -1,19 +1,19 @@
-/** @file \r
-\r
+/** @file\r
   UEFI handle & protocol handling.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
-All rights reserved. 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
-                                                                                          \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) 2006 - 2010, Intel Corporation. <BR>\r
+All rights reserved. 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
+\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
 \r
 **/\r
 \r
-#include <DxeMain.h>\r
+#include "DxeMain.h"\r
+#include "Handle.h"\r
 \r
 \r
 //\r
@@ -22,10 +22,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 // gProtocolDatabaseLock - Lock to protect the mProtocolDatabase\r
 // gHandleDatabaseKey    -  The Key to show that the handle has been created/modified\r
 //\r
-static 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      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
 \r
 \r
 \r
@@ -60,9 +60,9 @@ CoreReleaseProtocolLock (
 /**\r
   Check whether a handle is a valid EFI_HANDLE\r
 \r
-  @param  UserHandle             The handle to check \r
+  @param  UserHandle             The handle to check\r
 \r
-  @retval EFI_INVALID_PARAMETER  The handle is NULL or not a valid EFI_HANDLE. \r
+  @retval EFI_INVALID_PARAMETER  The handle is NULL or not a valid EFI_HANDLE.\r
   @retval EFI_SUCCESS            The handle is valid EFI_HANDLE.\r
 \r
 **/\r
@@ -89,8 +89,8 @@ CoreValidateHandle (
   Finds the protocol entry for the requested protocol.\r
   The gProtocolDatabaseLock must be owned\r
 \r
-  @param  Protocol               The ID of the protocol \r
-  @param  Create                 Create a new entry if not found \r
+  @param  Protocol               The ID of the protocol\r
+  @param  Create                 Create a new entry if not found\r
 \r
   @return Protocol entry\r
 \r
@@ -112,8 +112,8 @@ CoreFindProtocolEntry (
   //\r
 \r
   ProtEntry = NULL;\r
-  for (Link = mProtocolDatabase.ForwardLink; \r
-       Link != &mProtocolDatabase; \r
+  for (Link = mProtocolDatabase.ForwardLink;\r
+       Link != &mProtocolDatabase;\r
        Link = Link->ForwardLink) {\r
 \r
     Item = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);\r
@@ -129,18 +129,18 @@ CoreFindProtocolEntry (
   }\r
 \r
   //\r
-  // If the protocol entry was not found and Create is TRUE, then \r
+  // If the protocol entry was not found and Create is TRUE, then\r
   // allocate a new entry\r
-  //     \r
+  //\r
   if ((ProtEntry == NULL) && Create) {\r
-    ProtEntry = CoreAllocateBootServicesPool (sizeof(PROTOCOL_ENTRY));\r
-    \r
+    ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY));\r
+\r
     if (ProtEntry != NULL) {\r
       //\r
       // Initialize new protocol entry structure\r
       //\r
       ProtEntry->Signature = PROTOCOL_ENTRY_SIGNATURE;\r
-      CopyMem ((VOID *)&ProtEntry->ProtocolID, Protocol, sizeof (EFI_GUID));\r
+      CopyGuid ((VOID *)&ProtEntry->ProtocolID, Protocol);\r
       InitializeListHead (&ProtEntry->Protocols);\r
       InitializeListHead (&ProtEntry->Notify);\r
 \r
@@ -161,9 +161,9 @@ CoreFindProtocolEntry (
   Note: This function doesn't do parameters checking, it's caller's responsibility\r
   to pass in valid parameters.\r
 \r
-  @param  Handle                 The handle to search the protocol on \r
-  @param  Protocol               GUID of the protocol \r
-  @param  Interface              The interface for the protocol being searched \r
+  @param  Handle                 The handle to search the protocol on\r
+  @param  Protocol               GUID of the protocol\r
+  @param  Interface              The interface for the protocol being searched\r
 \r
   @return Protocol instance (NULL: Not found)\r
 \r
@@ -213,14 +213,13 @@ CoreFindProtocolInterface (
 /**\r
   Removes an event from a register protocol notify list on a protocol.\r
 \r
-  @param  Event                  The event to search for in the protocol \r
-                                 database. \r
+  @param  Event                  The event to search for in the protocol\r
+                                 database.\r
 \r
   @return EFI_SUCCESS   if the event was found and removed.\r
   @return EFI_NOT_FOUND if the event was not found in the protocl database.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 CoreUnregisterProtocolNotifyEvent (\r
   IN EFI_EVENT      Event\r
@@ -233,14 +232,14 @@ CoreUnregisterProtocolNotifyEvent (
 \r
   CoreAcquireProtocolLock ();\r
 \r
-  for ( Link =  mProtocolDatabase.ForwardLink; \r
-        Link != &mProtocolDatabase; \r
+  for ( Link =  mProtocolDatabase.ForwardLink;\r
+        Link != &mProtocolDatabase;\r
         Link =  Link->ForwardLink) {\r
 \r
     ProtEntry = CR(Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);\r
 \r
-    for ( NotifyLink =  ProtEntry->Notify.ForwardLink; \r
-          NotifyLink != &ProtEntry->Notify; \r
+    for ( NotifyLink =  ProtEntry->Notify.ForwardLink;\r
+          NotifyLink != &ProtEntry->Notify;\r
           NotifyLink =  NotifyLink->ForwardLink) {\r
 \r
       ProtNotify = CR(NotifyLink, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE);\r
@@ -263,8 +262,8 @@ CoreUnregisterProtocolNotifyEvent (
 /**\r
   Removes all the events in the protocol database that match Event.\r
 \r
-  @param  Event                  The event to search for in the protocol \r
-                                 database. \r
+  @param  Event                  The event to search for in the protocol\r
+                                 database.\r
 \r
   @return EFI_SUCCESS when done searching the entire database.\r
 \r
@@ -290,12 +289,12 @@ CoreUnregisterProtocolNotify (
   Wrapper function to CoreInstallProtocolInterfaceNotify.  This is the public API which\r
   Calls the private one which contains a BOOLEAN parameter for notifications\r
 \r
-  @param  UserHandle             The handle to install the protocol handler on, \r
-                                 or NULL if a new handle is to be allocated \r
-  @param  Protocol               The protocol to add to the handle \r
-  @param  InterfaceType          Indicates whether Interface is supplied in \r
-                                 native form. \r
-  @param  Interface              The interface for the protocol being added \r
+  @param  UserHandle             The handle to install the protocol handler on,\r
+                                 or NULL if a new handle is to be allocated\r
+  @param  Protocol               The protocol to add to the handle\r
+  @param  InterfaceType          Indicates whether Interface is supplied in\r
+                                 native form.\r
+  @param  Interface              The interface for the protocol being added\r
 \r
   @return Status code\r
 \r
@@ -310,10 +309,10 @@ CoreInstallProtocolInterface (
   )\r
 {\r
   return CoreInstallProtocolInterfaceNotify (\r
-            UserHandle, \r
-            Protocol, \r
-            InterfaceType, \r
-            Interface, \r
+            UserHandle,\r
+            Protocol,\r
+            InterfaceType,\r
+            Interface,\r
             TRUE\r
             );\r
 }\r
@@ -322,17 +321,17 @@ CoreInstallProtocolInterface (
 /**\r
   Installs a protocol interface into the boot services environment.\r
 \r
-  @param  UserHandle             The handle to install the protocol handler on, \r
-                                 or NULL if a new handle is to be allocated \r
-  @param  Protocol               The protocol to add to the handle \r
-  @param  InterfaceType          Indicates whether Interface is supplied in \r
-                                 native form. \r
-  @param  Interface              The interface for the protocol being added \r
-  @param  Notify                 indicates whether notify the notification list  \r
-                                 for this protocol \r
-\r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter \r
-  @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate \r
+  @param  UserHandle             The handle to install the protocol handler on,\r
+                                 or NULL if a new handle is to be allocated\r
+  @param  Protocol               The protocol to add to the handle\r
+  @param  InterfaceType          Indicates whether Interface is supplied in\r
+                                 native form.\r
+  @param  Interface              The interface for the protocol being added\r
+  @param  Notify                 indicates whether notify the notification list\r
+                                 for this protocol\r
+\r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
+  @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate\r
   @retval EFI_SUCCESS            Protocol interface successfully installed\r
 \r
 **/\r
@@ -366,15 +365,13 @@ CoreInstallProtocolInterfaceNotify (
   //\r
   // Print debug message\r
   //\r
-  DEBUG((DEBUG_ERROR | 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
   Handle = NULL;\r
 \r
-  ASSERT (NULL != gDxeCoreBS);\r
-\r
-  if (*UserHandle != NULL_HANDLE) {\r
+  if (*UserHandle != NULL) {\r
     Status = CoreHandleProtocol (*UserHandle, Protocol, (VOID **)&ExistingInterface);\r
     if (!EFI_ERROR (Status)) {\r
       return EFI_INVALID_PARAMETER;\r
@@ -382,7 +379,7 @@ CoreInstallProtocolInterfaceNotify (
   }\r
 \r
   //\r
-  // Lock the protocol database \r
+  // Lock the protocol database\r
   //\r
   CoreAcquireProtocolLock ();\r
 \r
@@ -397,7 +394,7 @@ CoreInstallProtocolInterfaceNotify (
   //\r
   // Allocate a new protocol interface structure\r
   //\r
-  Prot = CoreAllocateZeroBootServicesPool (sizeof(PROTOCOL_INTERFACE));\r
+  Prot = AllocateZeroPool (sizeof(PROTOCOL_INTERFACE));\r
   if (Prot == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -408,7 +405,7 @@ CoreInstallProtocolInterfaceNotify (
   //\r
   Handle = (IHANDLE *)*UserHandle;\r
   if (Handle == NULL) {\r
-    Handle = CoreAllocateZeroBootServicesPool (sizeof(IHANDLE));\r
+    Handle = AllocateZeroPool (sizeof(IHANDLE));\r
     if (Handle == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -431,7 +428,7 @@ CoreInstallProtocolInterfaceNotify (
     // in the system\r
     //\r
     InsertTailList (&gHandleList, &Handle->AllHandles);\r
-  } \r
+  }\r
 \r
   Status = CoreValidateHandle (Handle);\r
   if (EFI_ERROR (Status)) {\r
@@ -458,19 +455,19 @@ CoreInstallProtocolInterfaceNotify (
   Prot->OpenListCount = 0;\r
 \r
   //\r
-  // Add this protocol interface to the head of the supported \r
+  // Add this protocol interface to the head of the supported\r
   // protocol list for this handle\r
   //\r
   InsertHeadList (&Handle->Protocols, &Prot->Link);\r
 \r
   //\r
-  // Add this protocol interface to the tail of the \r
+  // Add this protocol interface to the tail of the\r
   // protocol entry\r
-  // \r
+  //\r
   InsertTailList (&ProtEntry->Protocols, &Prot->ByProtocol);\r
 \r
   //\r
-  // Notify the notification list for this protocol \r
+  // Notify the notification list for this protocol\r
   //\r
   if (Notify) {\r
     CoreNotifyProtocolEntry (ProtEntry);\r
@@ -508,14 +505,14 @@ 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  ...                    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
+  @param  Handle                 The handle to install the protocol handlers on,\r
+                                 or NULL 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_INVALID_PARAMETER  Handle is NULL. \r
+  @retval EFI_INVALID_PARAMETER  Handle is NULL.\r
   @retval EFI_SUCCESS            Protocol interfaces successfully installed.\r
 \r
 **/\r
@@ -535,14 +532,14 @@ CoreInstallMultipleProtocolInterfaces (
   EFI_HANDLE                OldHandle;\r
   EFI_HANDLE                DeviceHandle;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  \r
+\r
   if (Handle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  //\r
+  // Syncronize with notifcations.\r
   //\r
-  // Syncronize with notifcations. \r
-  // \r
   OldTpl = CoreRaiseTpl (TPL_NOTIFY);\r
   OldHandle = *Handle;\r
 \r
@@ -568,18 +565,19 @@ CoreInstallMultipleProtocolInterfaces (
       DeviceHandle = NULL;\r
       DevicePath   = Interface;\r
       Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle);\r
-      if (!EFI_ERROR (Status) && (DeviceHandle != NULL_HANDLE) && IsDevicePathEnd(DevicePath)) {\r
+      if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(DevicePath)) {\r
         Status = EFI_ALREADY_STARTED;\r
         continue;\r
       }\r
     }\r
-  \r
+\r
     //\r
     // Install it\r
     //\r
     Status = CoreInstallProtocolInterface (Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);\r
   }\r
-  \r
+  VA_END (Args);\r
+\r
   //\r
   // If there was an error, remove all the interfaces that were installed without any errors\r
   //\r
@@ -592,7 +590,9 @@ CoreInstallMultipleProtocolInterfaces (
       Protocol = VA_ARG (Args, EFI_GUID *);\r
       Interface = VA_ARG (Args, VOID *);\r
       CoreUninstallProtocolInterface (*Handle, Protocol, Interface);\r
-    }        \r
+    }\r
+    VA_END (Args);\r
+    \r
     *Handle = OldHandle;\r
   }\r
 \r
@@ -610,11 +610,11 @@ CoreInstallMultipleProtocolInterfaces (
   Note: This function doesn't do parameters checking, it's caller's responsibility\r
   to pass in valid parameters.\r
 \r
-  @param  UserHandle             The handle on which the protocol is installed \r
-  @param  Prot                   The protocol to disconnect drivers from \r
+  @param  UserHandle             The handle on which the protocol is installed\r
+  @param  Prot                   The protocol to disconnect drivers from\r
 \r
-  @retval EFI_SUCCESS            Drivers using the protocol interface are all \r
-                                 disconnected \r
+  @retval EFI_SUCCESS            Drivers using the protocol interface are all\r
+                                 disconnected\r
   @retval EFI_ACCESS_DENIED      Failed to disconnect one or all of the drivers\r
 \r
 **/\r
@@ -630,7 +630,7 @@ CoreDisconnectControllersUsingProtocolInterface (
   OPEN_PROTOCOL_DATA    *OpenData;\r
 \r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   //\r
   // Attempt to disconnect all drivers from this protocol interface\r
   //\r
@@ -640,7 +640,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
@@ -663,10 +663,10 @@ 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
+          RemoveEntryList (&OpenData->Link);\r
           Prot->OpenListCount--;\r
           CoreFreePool (OpenData);\r
         }\r
@@ -694,11 +694,11 @@ CoreDisconnectControllersUsingProtocolInterface (
   If the last protocol interface is remove from the handle, the\r
   handle is freed.\r
 \r
-  @param  UserHandle             The handle to remove the protocol handler from \r
-  @param  Protocol               The protocol, of protocol:interface, to remove \r
-  @param  Interface              The interface, of protocol:interface, to remove \r
+  @param  UserHandle             The handle to remove the protocol handler from\r
+  @param  Protocol               The protocol, of protocol:interface, to remove\r
+  @param  Interface              The interface, of protocol:interface, to remove\r
 \r
-  @retval EFI_INVALID_PARAMETER  Protocol is NULL. \r
+  @retval EFI_INVALID_PARAMETER  Protocol is NULL.\r
   @retval EFI_SUCCESS            Protocol interface successfully uninstalled.\r
 \r
 **/\r
@@ -770,7 +770,7 @@ CoreUninstallProtocolInterface (
     //\r
     gHandleDatabaseKey++;\r
     Handle->Key = gHandleDatabaseKey;\r
-    \r
+\r
     //\r
     // Remove the protocol interface from the handle\r
     //\r
@@ -793,7 +793,7 @@ CoreUninstallProtocolInterface (
     CoreFreePool (Handle);\r
   }\r
 \r
-Done:  \r
+Done:\r
   //\r
   // Done, unlock the database and return\r
   //\r
@@ -809,11 +809,11 @@ Done:
   This function calls UnisatllProtocolInterface() in a loop. This is\r
   basically a lib function to save space.\r
 \r
-  @param  Handle                 The handle to uninstall the protocol \r
-  @param  ...                    EFI_GUID followed by protocol instance. A NULL \r
-                                 terminates the  list. The pairs are the \r
-                                 arguments to UninstallProtocolInterface(). All \r
-                                 the protocols are added to Handle. \r
+  @param  Handle                 The handle to uninstall the protocol\r
+  @param  ...                    EFI_GUID followed by protocol instance. A NULL\r
+                                 terminates the  list. The pairs are the\r
+                                 arguments to UninstallProtocolInterface(). All\r
+                                 the protocols are added to Handle.\r
 \r
   @return Status code\r
 \r
@@ -848,6 +848,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
@@ -862,23 +863,23 @@ CoreUninstallMultipleProtocolInterfaces (
       Protocol = VA_ARG(Args, EFI_GUID *);\r
       Interface = VA_ARG(Args, VOID *);\r
       CoreInstallProtocolInterface (&Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);\r
-    }        \r
+    }\r
+    VA_END (Args);\r
   }\r
 \r
   return Status;\r
-}    \r
+}\r
 \r
 \r
 /**\r
   Locate a certain GUID protocol interface in a Handle's protocols.\r
 \r
-  @param  UserHandle             The handle to obtain the protocol interface on \r
-  @param  Protocol               The GUID of the protocol \r
+  @param  UserHandle             The handle to obtain the protocol interface on\r
+  @param  Protocol               The GUID of the protocol\r
 \r
   @return The requested protocol interface for the handle\r
 \r
 **/\r
-STATIC\r
 PROTOCOL_INTERFACE  *\r
 CoreGetProtocolInterface (\r
   IN  EFI_HANDLE                UserHandle,\r
@@ -895,7 +896,7 @@ CoreGetProtocolInterface (
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
-  \r
+\r
   Handle = (IHANDLE *)UserHandle;\r
 \r
   //\r
@@ -916,12 +917,16 @@ CoreGetProtocolInterface (
 /**\r
   Queries a handle to determine if it supports a specified protocol.\r
 \r
-  @param  UserHandle             The handle being queried. \r
-  @param  Protocol               The published unique identifier of the protocol. \r
-  @param  Interface              Supplies the address where a pointer to the \r
-                                 corresponding Protocol Interface is returned. \r
+  @param  UserHandle             The handle being queried.\r
+  @param  Protocol               The published unique identifier of the protocol.\r
+  @param  Interface              Supplies the address where a pointer to the\r
+                                 corresponding Protocol Interface is returned.\r
 \r
-  @return The requested protocol interface for the handle\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  Protocol is NULL.\r
+  @retval EFI_INVALID_PARAMETER  Interface is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -933,11 +938,11 @@ CoreHandleProtocol (
   )\r
 {\r
   return CoreOpenProtocol (\r
-          UserHandle,     \r
-          Protocol, \r
-          Interface, \r
-          gDxeCoreImageHandle, \r
-          NULL,     \r
+          UserHandle,\r
+          Protocol,\r
+          Interface,\r
+          gDxeCoreImageHandle,\r
+          NULL,\r
           EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL\r
           );\r
 }\r
@@ -949,18 +954,18 @@ CoreHandleProtocol (
   invokes it to obtain the protocol interface. Usage information\r
   is registered in the protocol data base.\r
 \r
-  @param  UserHandle             The handle to obtain the protocol interface on \r
-  @param  Protocol               The ID of the protocol \r
-  @param  Interface              The location to return the protocol interface \r
-  @param  ImageHandle            The handle of the Image that is opening the \r
-                                 protocol interface specified by Protocol and \r
-                                 Interface. \r
-  @param  ControllerHandle       The controller handle that is requiring this \r
-                                 interface. \r
-  @param  Attributes             The open mode of the protocol interface \r
-                                 specified by Handle and Protocol. \r
-\r
-  @retval EFI_INVALID_PARAMETER  Protocol is NULL. \r
+  @param  UserHandle             The handle to obtain the protocol interface on\r
+  @param  Protocol               The ID of the protocol\r
+  @param  Interface              The location to return the protocol interface\r
+  @param  ImageHandle            The handle of the Image that is opening the\r
+                                 protocol interface specified by Protocol and\r
+                                 Interface.\r
+  @param  ControllerHandle       The controller handle that is requiring this\r
+                                 interface.\r
+  @param  Attributes             The open mode of the protocol interface\r
+                                 specified by Handle and Protocol.\r
+\r
+  @retval EFI_INVALID_PARAMETER  Protocol is NULL.\r
   @retval EFI_SUCCESS            Get the protocol interface.\r
 \r
 **/\r
@@ -1001,7 +1006,7 @@ CoreOpenProtocol (
       *Interface = NULL;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Check for invalid UserHandle\r
   //\r
@@ -1068,7 +1073,7 @@ CoreOpenProtocol (
 \r
   //\r
   // This is the protocol interface entry for this protocol\r
-  //    \r
+  //\r
   if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {\r
     *Interface = Prot->Interface;\r
   }\r
@@ -1078,17 +1083,17 @@ CoreOpenProtocol (
   Exclusive       = FALSE;\r
   for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {\r
     OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r
-    ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) && \r
+    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
@@ -1122,7 +1127,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
@@ -1134,7 +1139,7 @@ CoreOpenProtocol (
           }\r
         }\r
       } while (Disconnect);\r
-    } \r
+    }\r
     break;\r
   case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER :\r
   case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL :\r
@@ -1150,7 +1155,7 @@ CoreOpenProtocol (
   //\r
   // Create new entry\r
   //\r
-  OpenData = CoreAllocateBootServicesPool (sizeof(OPEN_PROTOCOL_DATA));\r
+  OpenData = AllocatePool (sizeof(OPEN_PROTOCOL_DATA));\r
   if (OpenData == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
   } else {\r
@@ -1177,25 +1182,25 @@ Done:
 /**\r
   Closes a protocol on a handle that was opened using OpenProtocol().\r
 \r
-  @param  UserHandle             The handle for the protocol interface that was \r
-                                 previously opened with OpenProtocol(), and is \r
-                                 now being closed. \r
-  @param  Protocol               The published unique identifier of the protocol. \r
-                                 It is the caller's responsibility to pass in a \r
-                                 valid GUID. \r
-  @param  AgentHandle            The handle of the agent that is closing the \r
-                                 protocol interface. \r
-  @param  ControllerHandle       If the agent that opened a protocol is a driver \r
-                                 that follows the EFI Driver Model, then this \r
-                                 parameter is the controller handle that required \r
-                                 the protocol interface. If the agent does not \r
-                                 follow the EFI Driver Model, then this parameter \r
-                                 is optional and may be NULL. \r
-\r
-  @retval EFI_SUCCESS            The protocol instance was closed. \r
-  @retval EFI_INVALID_PARAMETER  Handle, AgentHandle or ControllerHandle is not a \r
-                                 valid EFI_HANDLE. \r
-  @retval EFI_NOT_FOUND          Can not find the specified protocol or \r
+  @param  UserHandle             The handle for the protocol interface that was\r
+                                 previously opened with OpenProtocol(), and is\r
+                                 now being closed.\r
+  @param  Protocol               The published unique identifier of the protocol.\r
+                                 It is the caller's responsibility to pass in a\r
+                                 valid GUID.\r
+  @param  AgentHandle            The handle of the agent that is closing the\r
+                                 protocol interface.\r
+  @param  ControllerHandle       If the agent that opened a protocol is a driver\r
+                                 that follows the EFI Driver Model, then this\r
+                                 parameter is the controller handle that required\r
+                                 the protocol interface. If the agent does not\r
+                                 follow the EFI Driver Model, then this parameter\r
+                                 is optional and may be NULL.\r
+\r
+  @retval EFI_SUCCESS            The protocol instance was closed.\r
+  @retval EFI_INVALID_PARAMETER  Handle, AgentHandle or ControllerHandle is not a\r
+                                 valid EFI_HANDLE.\r
+  @retval EFI_NOT_FOUND          Can not find the specified protocol or\r
                                  AgentHandle.\r
 \r
 **/\r
@@ -1205,7 +1210,7 @@ CoreCloseProtocol (
   IN  EFI_HANDLE                UserHandle,\r
   IN  EFI_GUID                  *Protocol,\r
   IN  EFI_HANDLE                AgentHandle,\r
-  IN  EFI_HANDLE                ControllerHandle  \r
+  IN  EFI_HANDLE                ControllerHandle\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -1224,7 +1229,7 @@ CoreCloseProtocol (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  if (ControllerHandle != NULL_HANDLE) {\r
+  if (ControllerHandle != NULL) {\r
     Status = CoreValidateHandle (ControllerHandle);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -1256,7 +1261,7 @@ CoreCloseProtocol (
     OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r
     Link = Link->ForwardLink;\r
     if ((OpenData->AgentHandle == AgentHandle) && (OpenData->ControllerHandle == ControllerHandle)) {\r
-        RemoveEntryList (&OpenData->Link);  \r
+        RemoveEntryList (&OpenData->Link);\r
         ProtocolInterface->OpenListCount--;\r
         CoreFreePool (OpenData);\r
         Status = EFI_SUCCESS;\r
@@ -1277,13 +1282,17 @@ Done:
 /**\r
   Return information about Opened protocols in the system\r
 \r
-  @param  UserHandle             The handle to close the protocol interface on \r
-  @param  Protocol               The ID of the protocol \r
-  @param  EntryBuffer            A pointer to a buffer of open protocol \r
-                                 information in the form of \r
-                                 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY structures. \r
+  @param  UserHandle             The handle to close the protocol interface on\r
+  @param  Protocol               The ID of the protocol\r
+  @param  EntryBuffer            A pointer to a buffer of open protocol information in the\r
+                                 form of EFI_OPEN_PROTOCOL_INFORMATION_ENTRY structures.\r
   @param  EntryCount             Number of EntryBuffer entries\r
 \r
+  @retval EFI_SUCCESS            The open protocol information was returned in EntryBuffer, \r
+                                 and the number of entries was returned EntryCount.\r
+  @retval EFI_NOT_FOUND          Handle does not support the protocol specified by Protocol.\r
+  @retval EFI_OUT_OF_RESOURCES   There are not enough resources available to allocate EntryBuffer.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1322,11 +1331,11 @@ CoreOpenProtocolInformation (
   //\r
   // Count the number of Open Entries\r
   //\r
-  for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0; \r
+  for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0;\r
         (Link != &ProtocolInterface->OpenList) ;\r
         Link = Link->ForwardLink  ) {\r
     Count++;\r
-  } \r
+  }\r
 \r
   ASSERT (Count == ProtocolInterface->OpenListCount);\r
 \r
@@ -1336,14 +1345,14 @@ CoreOpenProtocolInformation (
     Size = Count * sizeof(EFI_OPEN_PROTOCOL_INFORMATION_ENTRY);\r
   }\r
 \r
-  Buffer = CoreAllocateBootServicesPool (Size);\r
+  Buffer = AllocatePool (Size);\r
   if (Buffer == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
   Status = EFI_SUCCESS;\r
-  for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0; \r
+  for ( Link = ProtocolInterface->OpenList.ForwardLink, Count = 0;\r
         (Link != &ProtocolInterface->OpenList);\r
         Link = Link->ForwardLink, Count++  ) {\r
     OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);\r
@@ -1352,14 +1361,14 @@ CoreOpenProtocolInformation (
     Buffer[Count].ControllerHandle = OpenData->ControllerHandle;\r
     Buffer[Count].Attributes       = OpenData->Attributes;\r
     Buffer[Count].OpenCount        = OpenData->OpenCount;\r
-  } \r
+  }\r
 \r
   *EntryBuffer = Buffer;\r
   *EntryCount = Count;\r
-        \r
+\r
 Done:\r
   //\r
-  // Done. Release the database lock are return\r
+  // Done. Release the database lock.\r
   //\r
   CoreReleaseProtocolLock ();\r
   return Status;\r
@@ -1372,22 +1381,22 @@ Done:
   Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated\r
   from pool.\r
 \r
-  @param  UserHandle             The handle from which to retrieve the list of \r
-                                 protocol interface GUIDs. \r
-  @param  ProtocolBuffer         A pointer to the list of protocol interface GUID \r
-                                 pointers that are installed on Handle. \r
-  @param  ProtocolBufferCount    A pointer to the number of GUID pointers present \r
-                                 in ProtocolBuffer. \r
-\r
-  @retval EFI_SUCCESS            The list of protocol interface GUIDs installed \r
-                                 on Handle was returned in ProtocolBuffer. The \r
-                                 number of protocol interface GUIDs was returned \r
-                                 in ProtocolBufferCount. \r
-  @retval EFI_INVALID_PARAMETER  Handle is NULL. \r
-  @retval EFI_INVALID_PARAMETER  Handle is not a valid EFI_HANDLE. \r
-  @retval EFI_INVALID_PARAMETER  ProtocolBuffer is NULL. \r
-  @retval EFI_INVALID_PARAMETER  ProtocolBufferCount is NULL. \r
-  @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the \r
+  @param  UserHandle             The handle from which to retrieve the list of\r
+                                 protocol interface GUIDs.\r
+  @param  ProtocolBuffer         A pointer to the list of protocol interface GUID\r
+                                 pointers that are installed on Handle.\r
+  @param  ProtocolBufferCount    A pointer to the number of GUID pointers present\r
+                                 in ProtocolBuffer.\r
+\r
+  @retval EFI_SUCCESS            The list of protocol interface GUIDs installed\r
+                                 on Handle was returned in ProtocolBuffer. The\r
+                                 number of protocol interface GUIDs was returned\r
+                                 in ProtocolBufferCount.\r
+  @retval EFI_INVALID_PARAMETER  Handle is NULL.\r
+  @retval EFI_INVALID_PARAMETER  Handle is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER  ProtocolBuffer is NULL.\r
+  @retval EFI_INVALID_PARAMETER  ProtocolBufferCount is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the\r
                                  results.\r
 \r
 **/\r
@@ -1426,7 +1435,7 @@ CoreProtocolsPerHandle (
   ProtocolCount = 0;\r
 \r
   CoreAcquireProtocolLock ();\r
-  \r
+\r
   for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {\r
     ProtocolCount++;\r
   }\r
@@ -1439,7 +1448,7 @@ CoreProtocolsPerHandle (
     goto Done;\r
   }\r
 \r
-  Buffer = CoreAllocateBootServicesPool (sizeof (EFI_GUID *) * ProtocolCount);\r
+  Buffer = AllocatePool (sizeof (EFI_GUID *) * ProtocolCount);\r
   if (Buffer == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -1449,7 +1458,7 @@ CoreProtocolsPerHandle (
   *ProtocolBufferCount = ProtocolCount;\r
 \r
   for ( Link = Handle->Protocols.ForwardLink, ProtocolCount = 0;\r
-        Link != &Handle->Protocols; \r
+        Link != &Handle->Protocols;\r
         Link = Link->ForwardLink, ProtocolCount++) {\r
     Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE);\r
     Buffer[ProtocolCount] = &(Prot->Protocol->ProtocolID);\r
@@ -1483,7 +1492,7 @@ CoreGetHandleDatabaseKey (
 /**\r
   Go connect any handles that were created or modified while a image executed.\r
 \r
-  @param  Key                    The Key to show that the handle has been \r
+  @param  Key                    The Key to show that the handle has been\r
                                  created/modified\r
 \r
 **/\r
@@ -1510,12 +1519,12 @@ CoreConnectHandlesByKey (
     }\r
   }\r
 \r
-  HandleBuffer = CoreAllocateBootServicesPool (Count * sizeof (EFI_HANDLE));\r
+  HandleBuffer = AllocatePool (Count * sizeof (EFI_HANDLE));\r
   if (HandleBuffer == NULL) {\r
     CoreReleaseProtocolLock ();\r
     return;\r
   }\r
-  \r
+\r
   for (Link = gHandleList.ForwardLink, Count = 0; Link != &gHandleList; Link = Link->ForwardLink) {\r
     Handle = CR (Link, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE);\r
     if (Handle->Key > Key) {\r
@@ -1534,6 +1543,6 @@ CoreConnectHandlesByKey (
   for (Index = 0; Index < Count; Index++) {\r
     CoreConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
   }\r
-  \r
+\r
   CoreFreePool(HandleBuffer);\r
 }\r