]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add two useful functions in UefiLib for the implementation of Component Name, Driver...
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 18 Jan 2007 11:15:26 +0000 (11:15 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 18 Jan 2007 11:15:26 +0000 (11:15 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2267 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/Library/UefiLib.h
MdePkg/Library/UefiLib/UefiLib.c

index 9eed35ba1631f2301415ec4305df3dd975314283..1f0b52b06152c15a8eb06514d2a47605e9f6fcac 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   MDE UEFI library functions and macros\r
 \r
-  Copyright (c) 2006, Intel Corporation                                                         \r
+  Copyright (c) 2006 - 2007, 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
@@ -233,6 +233,63 @@ EfiReleaseLock (
   IN EFI_LOCK  *Lock\r
   );\r
 \r
+/**
+  Tests whether a controller is managed by a specific driver.
+
+  This function tests whether a specific driver manages ControllerHandle by\r
+  opening on DriverBindingHandle a protocol specified by ProtocolGuid with\r
+  attribute EFI_OPEN_PROTOCOL_BY_DRIVER.  This library function is used to\r
+  implement the Component Name Protocol for EFI Drivers.\r
+  If ProtocolGuid is NULL, then ASSERT().\r
+
+  @param  ControllerHandle     A handle for a controller to test.
+  @param  DriverBindingHandle  Specifies the driver binding handle for the
+                               driver.
+  @param  ProtocolGuid         Supplies GUID for the protocol opened by the
+                               driver on the controller. 
+
+  @retval EFI_SUCCESS          ControllerHandle is managed by the specific
+                               driver.
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the specific
+                               driver.
+
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiTestManagedDevice (\r
+  IN CONST EFI_HANDLE       ControllerHandle,\r
+  IN CONST EFI_HANDLE       DriverBindingHandle,\r
+  IN CONST EFI_GUID         *ProtocolGuid\r
+  );\r
+\r
+/**
+  Tests whether a child handle is a children device of the controller.
+
+  This function tests whether ChildHandle is one of the children of
+  ControllerHandle which are consuming a protocol specified by ProtocolGuid
+  with the attribute bit EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER set.  This
+  library function is used to implement the Component Name Protocol for EFI
+  Drivers.
+  If ProtocolGuid is NULL, then ASSERT().
+
+  @param  ControllerHandle     A handle for a (parent) controller to test. 
+  @param  ChildHandle          A child handle to test.
+  @param  ConsumsedGuid        Supplies GUID for the protocol consumed by
+                               children from controller. 
+
+  @retval EFI_SUCCESS          ChildHandle is a child of the ControllerHandle.
+  @retval EFI_UNSUPPORTED      ChildHandle is not a child of the
+                               ControllerHandle.
+
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiTestChildHandle (\r
+  IN CONST EFI_HANDLE       ControllerHandle,\r
+  IN CONST EFI_HANDLE       ChildHandle,\r
+  IN CONST EFI_GUID         *ProtocolGuid\r
+  );\r
+\r
 /**\r
   This function looks up a Unicode string in UnicodeStringTable.  If Language is \r
   a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable\r
index e8883b49f862b1414ca24f213a69bffc99298172..11408543030b1486b7015a892b989a52447cc16d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Mde UEFI library functions.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2007, 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
@@ -347,6 +347,130 @@ EfiReleaseLock (
   gBS->RestoreTPL (Tpl);\r
 }\r
 \r
+/**
+  Tests whether a controller is managed by a specific driver.
+
+  This function tests whether a specific driver manages ControllerHandle by\r
+  opening on DriverBindingHandle a protocol specified by ProtocolGuid with\r
+  attribute EFI_OPEN_PROTOCOL_BY_DRIVER.  This library function is used to\r
+  implement the Component Name Protocol for EFI Drivers.\r
+  If ProtocolGuid is NULL, then ASSERT().\r
+
+  @param  ControllerHandle     A handle for a controller to test.
+  @param  DriverBindingHandle  Specifies the driver binding handle for the
+                               driver.
+  @param  ProtocolGuid         Supplies GUID for the protocol opened by the
+                               driver on the controller. 
+
+  @retval EFI_SUCCESS          ControllerHandle is managed by the specific
+                               driver.
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the specific
+                               driver.
+
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiTestManagedDevice (\r
+  IN CONST EFI_HANDLE       ControllerHandle,\r
+  IN CONST EFI_HANDLE       DriverBindingHandle,\r
+  IN CONST EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**
+  Tests whether a child handle is a children device of the controller.
+
+  This function tests whether ChildHandle is one of the children of
+  ControllerHandle which are consuming a protocol specified by ProtocolGuid
+  with the attribute bit EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER set.  This
+  library function is used to implement the Component Name Protocol for EFI
+  Drivers.
+  If ProtocolGuid is NULL, then ASSERT().
+
+  @param  ControllerHandle     A handle for a (parent) controller to test. 
+  @param  ChildHandle          A child handle to test.
+  @param  ConsumsedGuid        Supplies GUID for the protocol consumed by
+                               children from controller. 
+
+  @retval EFI_SUCCESS          ChildHandle is a child of the ControllerHandle.
+  @retval EFI_UNSUPPORTED      ChildHandle is not a child of the
+                               ControllerHandle.
+
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiTestChildHandle (\r
+  IN CONST EFI_HANDLE       ControllerHandle,\r
+  IN CONST EFI_HANDLE       ChildHandle,\r
+  IN CONST EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY   *OpenInfoBuffer;\r
+  UINTN                                 EntryCount;\r
+  UINTN                                 Index;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  //\r
+  // Retrieve the list of agents that are consuming the specific protocol\r
+  // on ControllerHandle.\r
+  //\r
+  Status = gBS->OpenProtocolInformation (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &OpenInfoBuffer,\r
+                  &EntryCount\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Inspect if ChildHandle is one of the agents.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  for (Index = 0; Index < EntryCount; Index++) {\r
+    if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r
+        (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+  }\r
+  \r
+  FreePool (OpenInfoBuffer);\r
+  return Status;\r
+}\r
+\r
 /**\r
   This function looks up a Unicode string in UnicodeStringTable.  If Language is \r
   a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable\r