diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-01-18 11:15:26 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-01-18 11:15:26 +0000 |
commit | ca21f1a216d218fb3ff61940ce9a5605984350a1 (patch) | |
tree | c5f1addaa215a901152452ec299453c2b48d9ca1 /MdePkg/Library/UefiLib | |
parent | 76dbeb3b910133575ad03583f79dcd9443af06f5 (diff) | |
download | edk2-ca21f1a216d218fb3ff61940ce9a5605984350a1.tar.gz edk2-ca21f1a216d218fb3ff61940ce9a5605984350a1.tar.bz2 edk2-ca21f1a216d218fb3ff61940ce9a5605984350a1.zip |
Add two useful functions in UefiLib for the implementation of Component Name, Driver Config, and Driver Diag protocols.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2267 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/UefiLib')
-rw-r--r-- | MdePkg/Library/UefiLib/UefiLib.c | 126 |
1 files changed, 125 insertions, 1 deletions
diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c index e8883b49f8..1140854303 100644 --- a/MdePkg/Library/UefiLib/UefiLib.c +++ b/MdePkg/Library/UefiLib/UefiLib.c @@ -1,7 +1,7 @@ /** @file
Mde UEFI library functions.
- Copyright (c) 2006, Intel Corporation<BR>
+ Copyright (c) 2006 - 2007, Intel Corporation<BR>
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -347,6 +347,130 @@ EfiReleaseLock ( gBS->RestoreTPL (Tpl);
}
+/** + Tests whether a controller is managed by a specific driver. + + This function tests whether a specific driver manages ControllerHandle by
+ opening on DriverBindingHandle a protocol specified by ProtocolGuid with
+ attribute EFI_OPEN_PROTOCOL_BY_DRIVER. 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 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. + +**/
+EFI_STATUS
+EFIAPI
+EfiTestManagedDevice (
+ IN CONST EFI_HANDLE ControllerHandle,
+ IN CONST EFI_HANDLE DriverBindingHandle,
+ IN CONST EFI_GUID *ProtocolGuid
+ )
+{
+ EFI_STATUS Status;
+ VOID *ManagedInterface;
+
+ ASSERT (ProtocolGuid != NULL);
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ (EFI_GUID *) ProtocolGuid,
+ &ManagedInterface,
+ DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ (EFI_GUID *) ProtocolGuid,
+ DriverBindingHandle,
+ ControllerHandle
+ );
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status != EFI_ALREADY_STARTED) {
+ return EFI_UNSUPPORTED;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** + 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. + +**/
+EFI_STATUS
+EFIAPI
+EfiTestChildHandle (
+ IN CONST EFI_HANDLE ControllerHandle,
+ IN CONST EFI_HANDLE ChildHandle,
+ IN CONST EFI_GUID *ProtocolGuid
+ )
+{
+ EFI_STATUS Status;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
+ UINTN EntryCount;
+ UINTN Index;
+
+ ASSERT (ProtocolGuid != NULL);
+
+ //
+ // Retrieve the list of agents that are consuming the specific protocol
+ // on ControllerHandle.
+ //
+ Status = gBS->OpenProtocolInformation (
+ ControllerHandle,
+ (EFI_GUID *) ProtocolGuid,
+ &OpenInfoBuffer,
+ &EntryCount
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Inspect if ChildHandle is one of the agents.
+ //
+ Status = EFI_UNSUPPORTED;
+ for (Index = 0; Index < EntryCount; Index++) {
+ if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&
+ (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
+ Status = EFI_SUCCESS;
+ break;
+ }
+ }
+
+ FreePool (OpenInfoBuffer);
+ return Status;
+}
+
/**
This function looks up a Unicode string in UnicodeStringTable. If Language is
a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable
|