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 ();
154 AddSortedDriverBindingProtocol (
155 IN EFI_HANDLE DriverBindingHandle
,
156 IN OUT UINTN
*NumberOfSortedDriverBindingProtocols
,
157 IN OUT EFI_DRIVER_BINDING_PROTOCOL
**SortedDriverBindingProtocols
,
158 IN UINTN DriverBindingHandleCount
,
159 IN OUT EFI_HANDLE
*DriverBindingHandleBuffer
165 Add Driver Binding Protocols from Context Driver Image Handles to sorted
166 Driver Binding Protocol list.
170 DriverBindingHandle - Handle of the driver binding protocol.
172 NumberOfSortedDriverBindingProtocols - Number Of sorted driver binding protocols
174 SortedDriverBindingProtocols - The sorted protocol list.
176 DriverBindingHandleCount - Driver Binding Handle Count.
178 DriverBindingHandleBuffer - The buffer of driver binding protocol to be modified.
187 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
191 // Make sure the DriverBindingHandle is valid
193 Status
= CoreValidateHandle (DriverBindingHandle
);
194 if (EFI_ERROR (Status
)) {
199 // Retrieve the Driver Binding Protocol from DriverBindingHandle
201 Status
= CoreHandleProtocol(
203 &gEfiDriverBindingProtocolGuid
,
204 (VOID
**)&DriverBinding
207 // If DriverBindingHandle does not support the Driver Binding Protocol then return
209 if (EFI_ERROR (Status
) || DriverBinding
== NULL
) {
214 // See if DriverBinding is already in the sorted list
216 for (Index
= 0; Index
< *NumberOfSortedDriverBindingProtocols
; Index
++) {
217 if (DriverBinding
== SortedDriverBindingProtocols
[Index
]) {
223 // Add DriverBinding to the end of the list
225 SortedDriverBindingProtocols
[*NumberOfSortedDriverBindingProtocols
] = DriverBinding
;
226 *NumberOfSortedDriverBindingProtocols
= *NumberOfSortedDriverBindingProtocols
+ 1;
229 // Mark the cooresponding handle in DriverBindingHandleBuffer as used
231 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
232 if (DriverBindingHandleBuffer
[Index
] == DriverBindingHandle
) {
233 DriverBindingHandleBuffer
[Index
] = NULL
;
240 CoreConnectSingleController (
241 IN EFI_HANDLE ControllerHandle
,
242 IN EFI_HANDLE
*ContextDriverImageHandles OPTIONAL
,
243 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
249 Connects a controller to a driver.
253 ControllerHandle - Handle of the controller to be connected.
254 ContextDriverImageHandles - DriverImageHandle A pointer to an ordered list of driver image handles.
255 RemainingDevicePath - RemainingDevicePath A pointer to the device path that specifies a child
256 of the controller specified by ControllerHandle.
260 EFI_SUCCESS - One or more drivers were connected to ControllerHandle.
261 EFI_OUT_OF_RESOURCES - No enough system resources to complete the request.
262 EFI_NOT_FOUND - No drivers were connected to ControllerHandle.
268 EFI_HANDLE DriverImageHandle
;
269 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL
*PlatformDriverOverride
;
270 EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*BusSpecificDriverOverride
;
271 UINTN DriverBindingHandleCount
;
272 EFI_HANDLE
*DriverBindingHandleBuffer
;
273 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
274 UINTN NumberOfSortedDriverBindingProtocols
;
275 EFI_DRIVER_BINDING_PROTOCOL
**SortedDriverBindingProtocols
;
276 UINT32 HighestVersion
;
281 EFI_HANDLE DriverBindingHandle
;
284 // DriverBindingHandle is used for performance measurement, initialize it here just in case.
286 DriverBindingHandle
= NULL
;
288 // Initialize local variables
290 DriverBindingHandleCount
= 0;
291 DriverBindingHandleBuffer
= NULL
;
292 NumberOfSortedDriverBindingProtocols
= 0;
293 SortedDriverBindingProtocols
= NULL
;
296 // Get list of all Driver Binding Protocol Instances
298 Status
= CoreLocateHandleBuffer (
300 &gEfiDriverBindingProtocolGuid
,
302 &DriverBindingHandleCount
,
303 &DriverBindingHandleBuffer
305 if (EFI_ERROR (Status
) || (DriverBindingHandleCount
== 0)) {
306 return EFI_NOT_FOUND
;
310 // Allocate a duplicate array for the sorted Driver Binding Protocol Instances
312 SortedDriverBindingProtocols
= CoreAllocateBootServicesPool (sizeof (VOID
*) * DriverBindingHandleCount
);
313 if (SortedDriverBindingProtocols
== NULL
) {
314 CoreFreePool (DriverBindingHandleBuffer
);
315 return EFI_OUT_OF_RESOURCES
;
319 // Add Driver Binding Protocols from Context Driver Image Handles first
321 if (ContextDriverImageHandles
!= NULL
) {
322 for (Index
= 0; ContextDriverImageHandles
[Index
] != NULL
; Index
++) {
323 AddSortedDriverBindingProtocol (
324 ContextDriverImageHandles
[Index
],
325 &NumberOfSortedDriverBindingProtocols
,
326 SortedDriverBindingProtocols
,
327 DriverBindingHandleCount
,
328 DriverBindingHandleBuffer
334 // Add the Platform Driver Override Protocol drivers for ControllerHandle next
336 Status
= CoreLocateProtocol (
337 &gEfiPlatformDriverOverrideProtocolGuid
,
339 (VOID
**)&PlatformDriverOverride
341 if (!EFI_ERROR (Status
) && (PlatformDriverOverride
!= NULL
)) {
342 DriverImageHandle
= NULL
;
344 Status
= PlatformDriverOverride
->GetDriver (
345 PlatformDriverOverride
,
349 if (!EFI_ERROR (Status
)) {
350 AddSortedDriverBindingProtocol (
352 &NumberOfSortedDriverBindingProtocols
,
353 SortedDriverBindingProtocols
,
354 DriverBindingHandleCount
,
355 DriverBindingHandleBuffer
358 } while (!EFI_ERROR (Status
));
362 // Get the Bus Specific Driver Override Protocol instance on the Controller Handle
364 Status
= CoreHandleProtocol(
366 &gEfiBusSpecificDriverOverrideProtocolGuid
,
367 (VOID
**)&BusSpecificDriverOverride
369 if (!EFI_ERROR (Status
) && (BusSpecificDriverOverride
!= NULL
)) {
370 DriverImageHandle
= NULL
;
372 Status
= BusSpecificDriverOverride
->GetDriver (
373 BusSpecificDriverOverride
,
376 if (!EFI_ERROR (Status
)) {
377 AddSortedDriverBindingProtocol (
379 &NumberOfSortedDriverBindingProtocols
,
380 SortedDriverBindingProtocols
,
381 DriverBindingHandleCount
,
382 DriverBindingHandleBuffer
385 } while (!EFI_ERROR (Status
));
389 // Then add all the remaining Driver Binding Protocols
391 SortIndex
= NumberOfSortedDriverBindingProtocols
;
392 for (Index
= 0; Index
< DriverBindingHandleCount
; Index
++) {
393 AddSortedDriverBindingProtocol (
394 DriverBindingHandleBuffer
[Index
],
395 &NumberOfSortedDriverBindingProtocols
,
396 SortedDriverBindingProtocols
,
397 DriverBindingHandleCount
,
398 DriverBindingHandleBuffer
403 // Free the Driver Binding Handle Buffer
405 CoreFreePool (DriverBindingHandleBuffer
);
408 // Sort the remaining DriverBinding Protocol based on their Version field from
409 // highest to lowest.
411 for ( ; SortIndex
< NumberOfSortedDriverBindingProtocols
; SortIndex
++) {
412 HighestVersion
= SortedDriverBindingProtocols
[SortIndex
]->Version
;
413 HighestIndex
= SortIndex
;
414 for (Index
= SortIndex
+ 1; Index
< NumberOfSortedDriverBindingProtocols
; Index
++) {
415 if (SortedDriverBindingProtocols
[Index
]->Version
> HighestVersion
) {
416 HighestVersion
= SortedDriverBindingProtocols
[Index
]->Version
;
417 HighestIndex
= Index
;
420 if (SortIndex
!= HighestIndex
) {
421 DriverBinding
= SortedDriverBindingProtocols
[SortIndex
];
422 SortedDriverBindingProtocols
[SortIndex
] = SortedDriverBindingProtocols
[HighestIndex
];
423 SortedDriverBindingProtocols
[HighestIndex
] = DriverBinding
;
428 // Loop until no more drivers can be started on ControllerHandle
434 // Loop through the sorted Driver Binding Protocol Instances in order, and see if
435 // any of the Driver Binding Protocols support the controller specified by
438 DriverBinding
= NULL
;
440 for (Index
= 0; (Index
< NumberOfSortedDriverBindingProtocols
) && !DriverFound
; Index
++) {
441 if (SortedDriverBindingProtocols
[Index
] != NULL
) {
442 DriverBinding
= SortedDriverBindingProtocols
[Index
];
443 Status
= DriverBinding
->Supported(
448 if (!EFI_ERROR (Status
)) {
449 SortedDriverBindingProtocols
[Index
] = NULL
;
453 // A driver was found that supports ControllerHandle, so attempt to start the driver
454 // on ControllerHandle.
457 GetHandleFromDriverBinding (DriverBinding
, &DriverBindingHandle
);
460 PERF_START (DriverBindingHandle
, DRIVERBINDING_START_TOK
, NULL
, 0);
461 Status
= DriverBinding
->Start (
466 PERF_END (DriverBindingHandle
, DRIVERBINDING_START_TOK
, NULL
, 0);
468 if (!EFI_ERROR (Status
)) {
470 // The driver was successfully started on ControllerHandle, so set a flag
477 } while (DriverFound
);
480 // Free any buffers that were allocated with AllocatePool()
482 CoreFreePool (SortedDriverBindingProtocols
);
485 // If at least one driver was started on ControllerHandle, then return EFI_SUCCESS.
492 // If no drivers started and RemainingDevicePath is an End Device Path Node, then return EFI_SUCCESS
494 if (RemainingDevicePath
!= NULL
) {
495 if (IsDevicePathEnd (RemainingDevicePath
)) {
501 // Otherwise, no drivers were started on ControllerHandle, so return EFI_NOT_FOUND
503 return EFI_NOT_FOUND
;
509 CoreDisconnectController (
510 IN EFI_HANDLE ControllerHandle
,
511 IN EFI_HANDLE DriverImageHandle OPTIONAL
,
512 IN EFI_HANDLE ChildHandle OPTIONAL
518 Disonnects a controller from a driver
522 ControllerHandle - ControllerHandle The handle of the controller from which driver(s)
523 are to be disconnected.
524 DriverImageHandle - DriverImageHandle The driver to disconnect from ControllerHandle.
525 ChildHandle - ChildHandle The handle of the child to destroy.
529 EFI_SUCCESS - One or more drivers were disconnected from the controller.
530 EFI_SUCCESS - On entry, no drivers are managing ControllerHandle.
531 EFI_SUCCESS - DriverImageHandle is not NULL, and on entry DriverImageHandle is not managing ControllerHandle.
532 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
533 EFI_INVALID_PARAMETER - DriverImageHandle is not NULL, and it is not a valid EFI_HANDLE.
534 EFI_INVALID_PARAMETER - ChildHandle is not NULL, and it is not a valid EFI_HANDLE.
535 EFI_OUT_OF_RESOURCES - There are not enough resources available to disconnect any drivers from ControllerHandle.
536 EFI_DEVICE_ERROR - The controller could not be disconnected because of a device error.
542 EFI_HANDLE
*DriverImageHandleBuffer
;
543 EFI_HANDLE
*ChildBuffer
;
546 UINTN DriverImageHandleCount
;
547 UINTN ChildrenToStop
;
548 UINTN ChildBufferCount
;
551 BOOLEAN ChildHandleValid
;
552 BOOLEAN DriverImageHandleValid
;
554 LIST_ENTRY
*ProtLink
;
555 OPEN_PROTOCOL_DATA
*OpenData
;
556 PROTOCOL_INTERFACE
*Prot
;
557 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
560 // Make sure ControllerHandle is valid
562 Status
= CoreValidateHandle (ControllerHandle
);
563 if (EFI_ERROR (Status
)) {
568 // Make sure ChildHandle is valid if it is not NULL
570 if (ChildHandle
!= NULL
) {
571 Status
= CoreValidateHandle (ChildHandle
);
572 if (EFI_ERROR (Status
)) {
577 Handle
= ControllerHandle
;
580 // Get list of drivers that are currently managing ControllerHandle
582 DriverImageHandleBuffer
= NULL
;
583 DriverImageHandleCount
= 1;
585 if (DriverImageHandle
== NULL
) {
587 // Look at each protocol interface for a match
589 DriverImageHandleCount
= 0;
591 CoreAcquireProtocolLock ();
592 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
593 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
594 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
595 ProtLink
!= &Prot
->OpenList
;
596 ProtLink
= ProtLink
->ForwardLink
) {
597 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
598 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
599 DriverImageHandleCount
++;
603 CoreReleaseProtocolLock ();
606 // If there are no drivers managing this controller, then return EFI_SUCCESS
608 if (DriverImageHandleCount
== 0) {
609 Status
= EFI_SUCCESS
;
613 DriverImageHandleBuffer
= CoreAllocateBootServicesPool (sizeof (EFI_HANDLE
) * DriverImageHandleCount
);
614 if (DriverImageHandleBuffer
== NULL
) {
615 Status
= EFI_OUT_OF_RESOURCES
;
619 DriverImageHandleCount
= 0;
621 CoreAcquireProtocolLock ();
622 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
623 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
624 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
625 ProtLink
!= &Prot
->OpenList
;
626 ProtLink
= ProtLink
->ForwardLink
) {
627 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
628 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
630 for (Index
= 0; Index
< DriverImageHandleCount
; Index
++) {
631 if (DriverImageHandleBuffer
[Index
] == OpenData
->AgentHandle
) {
637 DriverImageHandleBuffer
[DriverImageHandleCount
] = OpenData
->AgentHandle
;
638 DriverImageHandleCount
++;
643 CoreReleaseProtocolLock ();
647 for (HandleIndex
= 0; HandleIndex
< DriverImageHandleCount
; HandleIndex
++) {
649 if (DriverImageHandleBuffer
!= NULL
) {
650 DriverImageHandle
= DriverImageHandleBuffer
[HandleIndex
];
654 // Get the Driver Binding Protocol of the driver that is managing this controller
656 Status
= CoreHandleProtocol (
658 &gEfiDriverBindingProtocolGuid
,
659 (VOID
**)&DriverBinding
661 if (EFI_ERROR (Status
)) {
662 Status
= EFI_INVALID_PARAMETER
;
667 // Look at each protocol interface for a match
669 DriverImageHandleValid
= FALSE
;
670 ChildBufferCount
= 0;
672 CoreAcquireProtocolLock ();
673 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
674 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
675 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
676 ProtLink
!= &Prot
->OpenList
;
677 ProtLink
= ProtLink
->ForwardLink
) {
678 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
679 if (OpenData
->AgentHandle
== DriverImageHandle
) {
680 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
683 if ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
684 DriverImageHandleValid
= TRUE
;
689 CoreReleaseProtocolLock ();
691 if (DriverImageHandleValid
) {
692 ChildHandleValid
= FALSE
;
694 if (ChildBufferCount
!= 0) {
695 ChildBuffer
= CoreAllocateBootServicesPool (sizeof (EFI_HANDLE
) * ChildBufferCount
);
696 if (ChildBuffer
== NULL
) {
697 Status
= EFI_OUT_OF_RESOURCES
;
701 ChildBufferCount
= 0;
703 CoreAcquireProtocolLock ();
704 for (Link
= Handle
->Protocols
.ForwardLink
; Link
!= &Handle
->Protocols
; Link
= Link
->ForwardLink
) {
705 Prot
= CR(Link
, PROTOCOL_INTERFACE
, Link
, PROTOCOL_INTERFACE_SIGNATURE
);
706 for (ProtLink
= Prot
->OpenList
.ForwardLink
;
707 ProtLink
!= &Prot
->OpenList
;
708 ProtLink
= ProtLink
->ForwardLink
) {
709 OpenData
= CR (ProtLink
, OPEN_PROTOCOL_DATA
, Link
, OPEN_PROTOCOL_DATA_SIGNATURE
);
710 if ((OpenData
->AgentHandle
== DriverImageHandle
) &&
711 ((OpenData
->Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0)) {
713 for (Index
= 0; Index
< ChildBufferCount
; Index
++) {
714 if (ChildBuffer
[Index
] == OpenData
->ControllerHandle
) {
720 ChildBuffer
[ChildBufferCount
] = OpenData
->ControllerHandle
;
721 if (ChildHandle
== ChildBuffer
[ChildBufferCount
]) {
722 ChildHandleValid
= TRUE
;
729 CoreReleaseProtocolLock ();
732 if (ChildHandle
== NULL
|| ChildHandleValid
) {
734 Status
= EFI_SUCCESS
;
735 if (ChildBufferCount
> 0) {
736 if (ChildHandle
!= NULL
) {
738 Status
= DriverBinding
->Stop (DriverBinding
, ControllerHandle
, ChildrenToStop
, &ChildHandle
);
740 ChildrenToStop
= ChildBufferCount
;
741 Status
= DriverBinding
->Stop (DriverBinding
, ControllerHandle
, ChildrenToStop
, ChildBuffer
);
744 if (!EFI_ERROR (Status
) && ((ChildHandle
== NULL
) || (ChildBufferCount
== ChildrenToStop
))) {
745 Status
= DriverBinding
->Stop (DriverBinding
, ControllerHandle
, 0, NULL
);
747 if (!EFI_ERROR (Status
)) {
752 if (ChildBuffer
!= NULL
) {
753 CoreFreePool (ChildBuffer
);
759 Status
= EFI_SUCCESS
;
761 Status
= EFI_NOT_FOUND
;
766 if (DriverImageHandleBuffer
!= NULL
) {
767 CoreFreePool (DriverImageHandleBuffer
);
777 GetHandleFromDriverBinding (
778 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBindingNeed
,
779 OUT EFI_HANDLE
*Handle
785 Locate the driver binding handle which a specified driver binding protocol installed on.
789 DriverBindingNeed - The specified driver binding protocol.
791 Handle - The driver binding handle which the protocol installed on.
796 EFI_NOT_FOUND - Could not find the handle.
798 EFI_SUCCESS - Successfully find the associated driver binding handle.
803 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
804 UINTN DriverBindingHandleCount
;
805 EFI_HANDLE
*DriverBindingHandleBuffer
;
808 DriverBindingHandleCount
= 0;
809 DriverBindingHandleBuffer
= NULL
;
810 *Handle
= NULL_HANDLE
;
811 Status
= CoreLocateHandleBuffer (
813 &gEfiDriverBindingProtocolGuid
,
815 &DriverBindingHandleCount
,
816 &DriverBindingHandleBuffer
818 if (EFI_ERROR (Status
) || DriverBindingHandleCount
== 0) {
819 return EFI_NOT_FOUND
;
822 for (Index
= 0 ; Index
< DriverBindingHandleCount
; Index
++ ) {
823 Status
= CoreOpenProtocol(
824 DriverBindingHandleBuffer
[Index
],
825 &gEfiDriverBindingProtocolGuid
,
826 (VOID
**)&DriverBinding
,
829 EFI_OPEN_PROTOCOL_GET_PROTOCOL
832 if (!EFI_ERROR (Status
) && DriverBinding
!= NULL
) {
834 if ( DriverBinding
== DriverBindingNeed
) {
835 *Handle
= DriverBindingHandleBuffer
[Index
];
836 CoreFreePool (DriverBindingHandleBuffer
);
842 CoreFreePool (DriverBindingHandleBuffer
);
843 return EFI_NOT_FOUND
;