3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI Driver Support Protocol
30 GetHandleFromDriverBinding (
31 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingNeed
,
32 OUT EFI_HANDLE
*Handle
37 // Driver Support Function Prototypes
41 CoreConnectSingleController (
42 IN EFI_HANDLE ControllerHandle
,
43 IN EFI_HANDLE
*DriverImageHandle OPTIONAL
,
44 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
48 // Driver Support Functions
54 CoreConnectController (
55 IN EFI_HANDLE ControllerHandle
,
56 IN EFI_HANDLE
*DriverImageHandle OPTIONAL
,
57 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
,
64 Connects one or more drivers to a controller.
68 ControllerHandle - Handle of the controller to be connected.
70 DriverImageHandle - DriverImageHandle A pointer to an ordered list of driver image handles.
72 RemainingDevicePath - RemainingDevicePath A pointer to the device path that specifies a child of the
73 controller specified by ControllerHandle.
75 Recursive - Whether the function would be called recursively or not.
84 EFI_STATUS ReturnStatus
;
86 PROTOCOL_INTERFACE
*Prot
;
89 OPEN_PROTOCOL_DATA
*OpenData
;
90 EFI_DEVICE_PATH_PROTOCOL
*AlignedRemainingDevicePath
;
93 // Make sure ControllerHandle is valid
95 Status
= CoreValidateHandle (ControllerHandle
);
96 if (EFI_ERROR (Status
)) {
100 Handle
= ControllerHandle
;
103 // Connect all drivers to ControllerHandle
105 AlignedRemainingDevicePath
= NULL
;
106 if (RemainingDevicePath
!= NULL
) {
107 AlignedRemainingDevicePath
= CoreDuplicateDevicePath (RemainingDevicePath
);
109 ReturnStatus
= CoreConnectSingleController (
112 AlignedRemainingDevicePath
114 if (AlignedRemainingDevicePath
!= NULL
) {
115 CoreFreePool (AlignedRemainingDevicePath
);
119 // If not recursive, then just return after connecting drivers to ControllerHandle
126 // If recursive, then connect all drivers to all of ControllerHandle's children
128 CoreAcquireProtocolLock ();
129 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
130 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
131 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
132 ProtLink
!= &Prot
->OpenList
;
133 ProtLink
= ProtLink
->ForwardLink
) {
134 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
135 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
136 CoreReleaseProtocolLock ();
137 Status
= CoreConnectController (
138 OpenData
->ControllerHandle
,
143 CoreAcquireProtocolLock ();
147 CoreReleaseProtocolLock ();
153 AddSortedDriverBindingProtocol (
154 IN EFI_HANDLE DriverBindingHandle
,
155 IN OUT UINTN
*NumberOfSortedDriverBindingProtocols
,
156 IN OUT EFI_DRIVER_BINDING_PROTOCOL
**SortedDriverBindingProtocols
,
157 IN UINTN DriverBindingHandleCount
,
158 IN OUT EFI_HANDLE
*DriverBindingHandleBuffer
164 Add Driver Binding Protocols from Context Driver Image Handles to sorted
165 Driver Binding Protocol list.
169 DriverBindingHandle - Handle of the driver binding protocol.
171 NumberOfSortedDriverBindingProtocols - Number Of sorted driver binding protocols
173 SortedDriverBindingProtocols - The sorted protocol list.
175 DriverBindingHandleCount - Driver Binding Handle Count.
177 DriverBindingHandleBuffer - The buffer of driver binding protocol to be modified.
186 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
190 // Make sure the DriverBindingHandle is valid
192 Status
= CoreValidateHandle (DriverBindingHandle
);
193 if (EFI_ERROR (Status
)) {
198 // Retrieve the Driver Binding Protocol from DriverBindingHandle
200 Status
= CoreHandleProtocol(
202 &gEfiDriverBindingProtocolGuid
,
203 (VOID
**)&DriverBinding
206 // If DriverBindingHandle does not support the Driver Binding Protocol then return
208 if (EFI_ERROR (Status
) || DriverBinding
== NULL
) {
213 // See if DriverBinding is already in the sorted list
215 for (Index
= 0; Index
< *NumberOfSortedDriverBindingProtocols
; Index
++) {
216 if (DriverBinding
== SortedDriverBindingProtocols
[Index
]) {
222 // Add DriverBinding to the end of the list
224 SortedDriverBindingProtocols
[*NumberOfSortedDriverBindingProtocols
] = DriverBinding
;
225 *NumberOfSortedDriverBindingProtocols
= *NumberOfSortedDriverBindingProtocols
+ 1;
228 // Mark the cooresponding handle in DriverBindingHandleBuffer as used
230 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
231 if (DriverBindingHandleBuffer
[Index
] == DriverBindingHandle
) {
232 DriverBindingHandleBuffer
[Index
] = NULL
;
239 CoreConnectSingleController (
240 IN EFI_HANDLE ControllerHandle
,
241 IN EFI_HANDLE
*ContextDriverImageHandles OPTIONAL
,
242 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
248 Connects a controller to a driver.
252 ControllerHandle - Handle of the controller to be connected.
253 ContextDriverImageHandles - DriverImageHandle A pointer to an ordered list of driver image handles.
254 RemainingDevicePath - RemainingDevicePath A pointer to the device path that specifies a child
255 of the controller specified by ControllerHandle.
259 EFI_SUCCESS - One or more drivers were connected to ControllerHandle.
260 EFI_OUT_OF_RESOURCES - No enough system resources to complete the request.
261 EFI_NOT_FOUND - No drivers were connected to ControllerHandle.
267 EFI_HANDLE DriverImageHandle
;
268 UINTN PlatformDriverOverrideHandleCount
;
269 EFI_HANDLE
*PlatformDriverOverrideHandleBuffer
;
270 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*PlatformDriverOverride
;
271 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
272 UINTN DriverBindingHandleCount
;
273 EFI_HANDLE
*DriverBindingHandleBuffer
;
274 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
275 UINTN NumberOfSortedDriverBindingProtocols
;
276 EFI_DRIVER_BINDING_PROTOCOL
**SortedDriverBindingProtocols
;
277 UINT32 HighestVersion
;
282 EFI_HANDLE DriverBindingHandle
;
285 // DriverBindingHandle is used for performance measurement, initialize it here just in case.
287 DriverBindingHandle
= NULL
;
289 // Initialize local variables
291 DriverBindingHandleCount
= 0;
292 DriverBindingHandleBuffer
= NULL
;
293 PlatformDriverOverrideHandleCount
= 0;
294 PlatformDriverOverrideHandleBuffer
= NULL
;
295 NumberOfSortedDriverBindingProtocols
= 0;
296 SortedDriverBindingProtocols
= NULL
;
299 // Get list of all Driver Binding Protocol Instances
301 Status
= CoreLocateHandleBuffer (
303 &gEfiDriverBindingProtocolGuid
,
305 &DriverBindingHandleCount
,
306 &DriverBindingHandleBuffer
308 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
309 return EFI_NOT_FOUND
;
313 // Allocate a duplicate array for the sorted Driver Binding Protocol Instances
315 SortedDriverBindingProtocols
= CoreAllocateBootServicesPool (sizeof (VOID
*) * DriverBindingHandleCount
);
316 if (SortedDriverBindingProtocols
== NULL
) {
317 CoreFreePool (DriverBindingHandleBuffer
);
318 return EFI_OUT_OF_RESOURCES
;
322 // Add Driver Binding Protocols from Context Driver Image Handles first
324 if (ContextDriverImageHandles
!= NULL
) {
325 for (Index
= 0; ContextDriverImageHandles
[Index
] != NULL
; Index
++) {
326 AddSortedDriverBindingProtocol (
327 ContextDriverImageHandles
[Index
],
328 &NumberOfSortedDriverBindingProtocols
,
329 SortedDriverBindingProtocols
,
330 DriverBindingHandleCount
,
331 DriverBindingHandleBuffer
337 // Add the Platform Driver Override Protocol drivers for ControllerHandle next
339 Status
= CoreLocateProtocol (
340 &gEfiPlatformDriverOverrideProtocolGuid
,
342 (VOID
**)&PlatformDriverOverride
344 if (!EFI_ERROR (Status
) && (PlatformDriverOverride
!= NULL
)) {
345 DriverImageHandle
= NULL
;
347 Status
= PlatformDriverOverride
->GetDriver (
348 PlatformDriverOverride
,
352 if (!EFI_ERROR (Status
)) {
353 AddSortedDriverBindingProtocol (
355 &NumberOfSortedDriverBindingProtocols
,
356 SortedDriverBindingProtocols
,
357 DriverBindingHandleCount
,
358 DriverBindingHandleBuffer
361 } while (!EFI_ERROR (Status
));
365 // Get the Bus Specific Driver Override Protocol instance on the Controller Handle
367 Status
= CoreHandleProtocol(
369 &gEfiBusSpecificDriverOverrideProtocolGuid
,
370 (VOID
**)&BusSpecificDriverOverride
372 if (!EFI_ERROR (Status
) && (BusSpecificDriverOverride
!= NULL
)) {
373 DriverImageHandle
= NULL
;
375 Status
= BusSpecificDriverOverride
->GetDriver (
376 BusSpecificDriverOverride
,
379 if (!EFI_ERROR (Status
)) {
380 AddSortedDriverBindingProtocol (
382 &NumberOfSortedDriverBindingProtocols
,
383 SortedDriverBindingProtocols
,
384 DriverBindingHandleCount
,
385 DriverBindingHandleBuffer
388 } while (!EFI_ERROR (Status
));
392 // Then add all the remaining Driver Binding Protocols
394 SortIndex
= NumberOfSortedDriverBindingProtocols
;
395 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
396 AddSortedDriverBindingProtocol (
397 DriverBindingHandleBuffer
[Index
],
398 &NumberOfSortedDriverBindingProtocols
,
399 SortedDriverBindingProtocols
,
400 DriverBindingHandleCount
,
401 DriverBindingHandleBuffer
406 // Free the Driver Binding Handle Buffer
408 CoreFreePool (DriverBindingHandleBuffer
);
411 // Sort the remaining DriverBinding Protocol based on their Version field from
412 // highest to lowest.
414 for ( ; SortIndex
< DriverBindingHandleCount
; SortIndex
++) {
415 HighestVersion
= SortedDriverBindingProtocols
[SortIndex
]->Version
;
416 HighestIndex
= SortIndex
;
417 for (Index
= SortIndex
+ 1; Index
< DriverBindingHandleCount
; Index
++) {
418 if (SortedDriverBindingProtocols
[Index
]->Version
> HighestVersion
) {
419 HighestVersion
= SortedDriverBindingProtocols
[Index
]->Version
;
420 HighestIndex
= Index
;
423 if (SortIndex
!= HighestIndex
) {
424 DriverBinding
= SortedDriverBindingProtocols
[SortIndex
];
425 SortedDriverBindingProtocols
[SortIndex
] = SortedDriverBindingProtocols
[HighestIndex
];
426 SortedDriverBindingProtocols
[HighestIndex
] = DriverBinding
;
431 // Loop until no more drivers can be started on ControllerHandle
437 // Loop through the sorted Driver Binding Protocol Instances in order, and see if
438 // any of the Driver Binding Protocols support the controller specified by
441 DriverBinding
= NULL
;
443 for (Index
= 0; (Index
< NumberOfSortedDriverBindingProtocols
) && !DriverFound
; Index
++) {
444 if (SortedDriverBindingProtocols
[Index
] != NULL
) {
445 DriverBinding
= SortedDriverBindingProtocols
[Index
];
446 Status
= DriverBinding
->Supported(
451 if (!EFI_ERROR (Status
)) {
452 SortedDriverBindingProtocols
[Index
] = NULL
;
456 // A driver was found that supports ControllerHandle, so attempt to start the driver
457 // on ControllerHandle.
460 GetHandleFromDriverBinding (DriverBinding
, &DriverBindingHandle
);
463 PERF_START (DriverBindingHandle
, DRIVERBINDING_START_TOK
, NULL
, 0);
464 Status
= DriverBinding
->Start (
469 PERF_END (DriverBindingHandle
, DRIVERBINDING_START_TOK
, NULL
, 0);
471 if (!EFI_ERROR (Status
)) {
473 // The driver was successfully started on ControllerHandle, so set a flag
480 } while (DriverFound
);
483 // Free any buffers that were allocated with AllocatePool()
485 CoreFreePool (SortedDriverBindingProtocols
);
488 // If at least one driver was started on ControllerHandle, then return EFI_SUCCESS.
495 // If no drivers started and RemainingDevicePath is an End Device Path Node, then return EFI_SUCCESS
497 if (RemainingDevicePath
!= NULL
) {
498 if (IsDevicePathEnd (RemainingDevicePath
)) {
504 // Otherwise, no drivers were started on ControllerHandle, so return EFI_NOT_FOUND
506 return EFI_NOT_FOUND
;
512 CoreDisconnectController (
513 IN EFI_HANDLE ControllerHandle
,
514 IN EFI_HANDLE DriverImageHandle OPTIONAL
,
515 IN EFI_HANDLE ChildHandle OPTIONAL
521 Disonnects a controller from a driver
525 ControllerHandle - ControllerHandle The handle of the controller from which driver(s)
526 are to be disconnected.
527 DriverImageHandle - DriverImageHandle The driver to disconnect from ControllerHandle.
528 ChildHandle - ChildHandle The handle of the child to destroy.
532 EFI_SUCCESS - One or more drivers were disconnected from the controller.
533 EFI_SUCCESS - On entry, no drivers are managing ControllerHandle.
534 EFI_SUCCESS - DriverImageHandle is not NULL, and on entry DriverImageHandle is not managing ControllerHandle.
535 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
536 EFI_INVALID_PARAMETER - DriverImageHandle is not NULL, and it is not a valid EFI_HANDLE.
537 EFI_INVALID_PARAMETER - ChildHandle is not NULL, and it is not a valid EFI_HANDLE.
538 EFI_OUT_OF_RESOURCES - There are not enough resources available to disconnect any drivers from ControllerHandle.
539 EFI_DEVICE_ERROR - The controller could not be disconnected because of a device error.
545 EFI_HANDLE
*DriverImageHandleBuffer
;
546 EFI_HANDLE
*ChildBuffer
;
549 UINTN DriverImageHandleCount
;
550 UINTN ChildrenToStop
;
551 UINTN ChildBufferCount
;
554 BOOLEAN ChildHandleValid
;
555 BOOLEAN DriverImageHandleValid
;
557 LIST_ENTRY
*ProtLink
;
558 OPEN_PROTOCOL_DATA
*OpenData
;
559 PROTOCOL_INTERFACE
*Prot
;
560 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
563 // Make sure ControllerHandle is valid
565 Status
= CoreValidateHandle (ControllerHandle
);
566 if (EFI_ERROR (Status
)) {
571 // Make sure ChildHandle is valid if it is not NULL
573 if (ChildHandle
!= NULL
) {
574 Status
= CoreValidateHandle (ChildHandle
);
575 if (EFI_ERROR (Status
)) {
580 Handle
= ControllerHandle
;
583 // Get list of drivers that are currently managing ControllerHandle
585 DriverImageHandleBuffer
= NULL
;
586 DriverImageHandleCount
= 1;
588 if (DriverImageHandle
== NULL
) {
590 // Look at each protocol interface for a match
592 DriverImageHandleCount
= 0;
594 CoreAcquireProtocolLock ();
595 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
596 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
597 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
598 ProtLink
!= &Prot
->OpenList
;
599 ProtLink
= ProtLink
->ForwardLink
) {
600 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
601 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
602 DriverImageHandleCount
++;
606 CoreReleaseProtocolLock ();
609 // If there are no drivers managing this controller, then return EFI_SUCCESS
611 if (DriverImageHandleCount
== 0) {
612 Status
= EFI_SUCCESS
;
616 DriverImageHandleBuffer
= CoreAllocateBootServicesPool (sizeof (EFI_HANDLE
) * DriverImageHandleCount
);
617 if (DriverImageHandleBuffer
== NULL
) {
618 Status
= EFI_OUT_OF_RESOURCES
;
622 DriverImageHandleCount
= 0;
624 CoreAcquireProtocolLock ();
625 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
626 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
627 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
628 ProtLink
!= &Prot
->OpenList
;
629 ProtLink
= ProtLink
->ForwardLink
) {
630 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
631 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
633 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
634 if (DriverImageHandleBuffer
[Index
] == OpenData
->AgentHandle
) {
640 DriverImageHandleBuffer
[DriverImageHandleCount
] = OpenData
->AgentHandle
;
641 DriverImageHandleCount
++;
646 CoreReleaseProtocolLock ();
650 for (HandleIndex
= 0; HandleIndex
< DriverImageHandleCount
; HandleIndex
++) {
652 if (DriverImageHandleBuffer
!= NULL
) {
653 DriverImageHandle
= DriverImageHandleBuffer
[HandleIndex
];
657 // Get the Driver Binding Protocol of the driver that is managing this controller
659 Status
= CoreHandleProtocol (
661 &gEfiDriverBindingProtocolGuid
,
662 (VOID
**)&DriverBinding
664 if (EFI_ERROR (Status
)) {
665 Status
= EFI_INVALID_PARAMETER
;
670 // Look at each protocol interface for a match
672 DriverImageHandleValid
= FALSE
;
673 ChildBufferCount
= 0;
675 CoreAcquireProtocolLock ();
676 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
677 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
678 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
679 ProtLink
!= &Prot
->OpenList
;
680 ProtLink
= ProtLink
->ForwardLink
) {
681 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
682 if (OpenData
->AgentHandle
== DriverImageHandle
) {
683 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
686 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
687 DriverImageHandleValid
= TRUE
;
692 CoreReleaseProtocolLock ();
694 if (DriverImageHandleValid
) {
695 ChildHandleValid
= FALSE
;
697 if (ChildBufferCount
!= 0) {
698 ChildBuffer
= CoreAllocateBootServicesPool (sizeof (EFI_HANDLE
) * ChildBufferCount
);
699 if (ChildBuffer
== NULL
) {
700 Status
= EFI_OUT_OF_RESOURCES
;
704 ChildBufferCount
= 0;
706 CoreAcquireProtocolLock ();
707 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
708 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
709 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
710 ProtLink
!= &Prot
->OpenList
;
711 ProtLink
= ProtLink
->ForwardLink
) {
712 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
713 if ((OpenData
->AgentHandle
== DriverImageHandle
) &&
714 ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0)) {
716 for (Index
= 0; Index
< ChildBufferCount
; Index
++) {
717 if (ChildBuffer
[Index
] == OpenData
->ControllerHandle
) {
723 ChildBuffer
[ChildBufferCount
] = OpenData
->ControllerHandle
;
724 if (ChildHandle
== ChildBuffer
[ChildBufferCount
]) {
725 ChildHandleValid
= TRUE
;
732 CoreReleaseProtocolLock ();
735 if (ChildHandle
== NULL
|| ChildHandleValid
) {
737 Status
= EFI_SUCCESS
;
738 if (ChildBufferCount
> 0) {
739 if (ChildHandle
!= NULL
) {
741 Status
= DriverBinding
->Stop (DriverBinding
, ControllerHandle
, ChildrenToStop
, &ChildHandle
);
743 ChildrenToStop
= ChildBufferCount
;
744 Status
= DriverBinding
->Stop (DriverBinding
, ControllerHandle
, ChildrenToStop
, ChildBuffer
);
747 if (!EFI_ERROR (Status
) && ((ChildHandle
== NULL
) || (ChildBufferCount
== ChildrenToStop
))) {
748 Status
= DriverBinding
->Stop (DriverBinding
, ControllerHandle
, 0, NULL
);
750 if (!EFI_ERROR (Status
)) {
755 if (ChildBuffer
!= NULL
) {
756 CoreFreePool (ChildBuffer
);
762 Status
= EFI_SUCCESS
;
764 Status
= EFI_NOT_FOUND
;
769 if (DriverImageHandleBuffer
!= NULL
) {
770 CoreFreePool (DriverImageHandleBuffer
);
780 GetHandleFromDriverBinding (
781 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingNeed
,
782 OUT EFI_HANDLE
*Handle
788 Locate the driver binding handle which a specified driver binding protocol installed on.
792 DriverBindingNeed - The specified driver binding protocol.
794 Handle - The driver binding handle which the protocol installed on.
799 EFI_NOT_FOUND - Could not find the handle.
801 EFI_SUCCESS - Successfully find the associated driver binding handle.
806 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
807 UINTN DriverBindingHandleCount
;
808 EFI_HANDLE
*DriverBindingHandleBuffer
;
811 DriverBindingHandleCount
= 0;
812 DriverBindingHandleBuffer
= NULL
;
813 *Handle
= NULL_HANDLE
;
814 Status
= CoreLocateHandleBuffer (
816 &gEfiDriverBindingProtocolGuid
,
818 &DriverBindingHandleCount
,
819 &DriverBindingHandleBuffer
821 if (EFI_ERROR (Status
) || DriverBindingHandleCount
== 0) {
822 return EFI_NOT_FOUND
;
825 for (Index
= 0 ; Index
< DriverBindingHandleCount
; Index
++ ) {
826 Status
= CoreOpenProtocol(
827 DriverBindingHandleBuffer
[Index
],
828 &gEfiDriverBindingProtocolGuid
,
829 (VOID
**)&DriverBinding
,
832 EFI_OPEN_PROTOCOL_GET_PROTOCOL
835 if (!EFI_ERROR (Status
) && DriverBinding
!= NULL
) {
837 if ( DriverBinding
== DriverBindingNeed
) {
838 *Handle
= DriverBindingHandleBuffer
[Index
];
839 CoreFreePool (DriverBindingHandleBuffer
);
845 CoreFreePool (DriverBindingHandleBuffer
);
846 return EFI_NOT_FOUND
;