60 UINTN ChildHandleCount;
62 UINTN HandleFilePathSize;
63 UINTN RemainingDevicePathSize;
77 if (EFI_ERROR (Status)) {
81 if (gSecurity2 !=
NULL) {
85 Status =
CoreHandleProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);
86 if (!EFI_ERROR (Status)) {
87 ASSERT (HandleFilePath !=
NULL);
88 FilePath = HandleFilePath;
90 if ((RemainingDevicePath !=
NULL) && !Recursive) {
93 TempFilePath =
AllocateZeroPool (HandleFilePathSize + RemainingDevicePathSize);
94 ASSERT (TempFilePath !=
NULL);
95 CopyMem (TempFilePath, HandleFilePath, HandleFilePathSize);
96 CopyMem ((UINT8 *)TempFilePath + HandleFilePathSize, RemainingDevicePath, RemainingDevicePathSize);
97 FilePath = TempFilePath;
100 Status = gSecurity2->FileAuthentication (
107 if (TempFilePath !=
NULL) {
111 if (EFI_ERROR (Status)) {
117 Handle = ControllerHandle;
122 AlignedRemainingDevicePath =
NULL;
123 if (RemainingDevicePath !=
NULL) {
126 if (AlignedRemainingDevicePath ==
NULL) {
127 return EFI_OUT_OF_RESOURCES;
141 AlignedRemainingDevicePath
143 }
while (ReturnStatus == EFI_NOT_READY);
148 if (AlignedRemainingDevicePath !=
NULL) {
165 if (EFI_ERROR (Status)) {
177 for (Link = Handle->
Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
179 for (ProtLink = Prot->
OpenList.ForwardLink;
181 ProtLink = ProtLink->ForwardLink)
184 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
194 if (ChildHandleBuffer ==
NULL) {
196 return EFI_OUT_OF_RESOURCES;
202 for (Link = Handle->
Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
204 for (ProtLink = Prot->
OpenList.ForwardLink;
206 ProtLink = ProtLink->ForwardLink)
209 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
210 ChildHandleBuffer[ChildHandleCount] = OpenData->ControllerHandle;
224 for (Index = 0; Index < ChildHandleCount; Index++) {
226 ChildHandleBuffer[Index],
264 IN OUT UINTN *NumberOfSortedDriverBindingProtocols,
266 IN UINTN DriverBindingHandleCount,
268 IN BOOLEAN IsImageHandle
284 if (EFI_ERROR (Status)) {
296 for (Index = 0; Index < DriverBindingHandleCount; Index++) {
301 DriverBindingHandleBuffer[Index],
302 &gEfiDriverBindingProtocolGuid,
303 (VOID **)&DriverBinding
305 if (EFI_ERROR (Status) || (DriverBinding ==
NULL)) {
313 if (DriverBinding->ImageHandle == DriverBindingHandle) {
315 DriverBindingHandleBuffer[Index],
316 NumberOfSortedDriverBindingProtocols,
317 SortedDriverBindingProtocols,
318 DriverBindingHandleCount,
319 DriverBindingHandleBuffer,
333 &gEfiDriverBindingProtocolGuid,
334 (VOID **)&DriverBinding
339 if (EFI_ERROR (Status) || (DriverBinding ==
NULL)) {
346 for (Index = 0; Index < *NumberOfSortedDriverBindingProtocols && Index < DriverBindingHandleCount; Index++) {
347 if (DriverBinding == SortedDriverBindingProtocols[Index]) {
355 if (*NumberOfSortedDriverBindingProtocols < DriverBindingHandleCount) {
356 SortedDriverBindingProtocols[*NumberOfSortedDriverBindingProtocols] = DriverBinding;
359 *NumberOfSortedDriverBindingProtocols = *NumberOfSortedDriverBindingProtocols + 1;
364 for (Index = 0; Index < DriverBindingHandleCount; Index++) {
365 if (DriverBindingHandleBuffer[Index] == DriverBindingHandle) {
366 DriverBindingHandleBuffer[Index] =
NULL;
404 UINTN DriverBindingHandleCount;
406 UINTN NewDriverBindingHandleCount;
410 UINTN NumberOfSortedDriverBindingProtocols;
412 UINT32 DriverFamilyOverrideVersion;
413 UINT32 HighestVersion;
422 DriverBindingHandleCount = 0;
423 DriverBindingHandleBuffer =
NULL;
424 NumberOfSortedDriverBindingProtocols = 0;
425 SortedDriverBindingProtocols =
NULL;
426 PlatformDriverOverride =
NULL;
427 NewDriverBindingHandleBuffer =
NULL;
434 &gEfiDriverBindingProtocolGuid,
436 &DriverBindingHandleCount,
437 &DriverBindingHandleBuffer
439 if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) {
440 return EFI_NOT_FOUND;
446 SortedDriverBindingProtocols =
AllocatePool (
sizeof (VOID *) * DriverBindingHandleCount);
447 if (SortedDriverBindingProtocols ==
NULL) {
449 return EFI_OUT_OF_RESOURCES;
455 if (ContextDriverImageHandles !=
NULL) {
456 for (Index = 0; ContextDriverImageHandles[Index] !=
NULL; Index++) {
458 ContextDriverImageHandles[Index],
459 &NumberOfSortedDriverBindingProtocols,
460 SortedDriverBindingProtocols,
461 DriverBindingHandleCount,
462 DriverBindingHandleBuffer,
472 &gEfiPlatformDriverOverrideProtocolGuid,
474 (VOID **)&PlatformDriverOverride
476 if (!EFI_ERROR (Status) && (PlatformDriverOverride !=
NULL)) {
477 DriverImageHandle =
NULL;
479 Status = PlatformDriverOverride->GetDriver (
480 PlatformDriverOverride,
484 if (!EFI_ERROR (Status)) {
487 &NumberOfSortedDriverBindingProtocols,
488 SortedDriverBindingProtocols,
489 DriverBindingHandleCount,
490 DriverBindingHandleBuffer,
494 }
while (!EFI_ERROR (Status));
501 &gEfiDriverFamilyOverrideProtocolGuid,
503 (VOID **)&DriverFamilyOverride
505 while (!EFI_ERROR (Status) && (DriverFamilyOverride !=
NULL)) {
506 HighestIndex = DriverBindingHandleCount;
508 for (Index = 0; Index < DriverBindingHandleCount; Index++) {
510 DriverBindingHandleBuffer[Index],
511 &gEfiDriverFamilyOverrideProtocolGuid,
512 (VOID **)&DriverFamilyOverride
514 if (!EFI_ERROR (Status) && (DriverFamilyOverride !=
NULL)) {
515 DriverFamilyOverrideVersion = DriverFamilyOverride->GetVersion (DriverFamilyOverride);
516 if ((HighestIndex == DriverBindingHandleCount) || (DriverFamilyOverrideVersion > HighestVersion)) {
517 HighestVersion = DriverFamilyOverrideVersion;
518 HighestIndex = Index;
523 if (HighestIndex == DriverBindingHandleCount) {
528 DriverBindingHandleBuffer[HighestIndex],
529 &NumberOfSortedDriverBindingProtocols,
530 SortedDriverBindingProtocols,
531 DriverBindingHandleCount,
532 DriverBindingHandleBuffer,
542 &gEfiBusSpecificDriverOverrideProtocolGuid,
543 (VOID **)&BusSpecificDriverOverride
545 if (!EFI_ERROR (Status) && (BusSpecificDriverOverride !=
NULL)) {
546 DriverImageHandle =
NULL;
548 Status = BusSpecificDriverOverride->GetDriver (
549 BusSpecificDriverOverride,
552 if (!EFI_ERROR (Status)) {
555 &NumberOfSortedDriverBindingProtocols,
556 SortedDriverBindingProtocols,
557 DriverBindingHandleCount,
558 DriverBindingHandleBuffer,
562 }
while (!EFI_ERROR (Status));
568 SortIndex = NumberOfSortedDriverBindingProtocols;
569 for (Index = 0; Index < DriverBindingHandleCount; Index++) {
571 DriverBindingHandleBuffer[Index],
572 &NumberOfSortedDriverBindingProtocols,
573 SortedDriverBindingProtocols,
574 DriverBindingHandleCount,
575 DriverBindingHandleBuffer,
591 &gEfiDriverBindingProtocolGuid,
593 &NewDriverBindingHandleCount,
594 &NewDriverBindingHandleBuffer
597 if (NewDriverBindingHandleCount > DriverBindingHandleCount) {
603 return EFI_NOT_READY;
610 for ( ; SortIndex < NumberOfSortedDriverBindingProtocols; SortIndex++) {
611 HighestVersion = SortedDriverBindingProtocols[SortIndex]->
Version;
612 HighestIndex = SortIndex;
613 for (Index = SortIndex + 1; Index < NumberOfSortedDriverBindingProtocols; Index++) {
614 if (SortedDriverBindingProtocols[Index]->Version > HighestVersion) {
615 HighestVersion = SortedDriverBindingProtocols[Index]->
Version;
616 HighestIndex = Index;
620 if (SortIndex != HighestIndex) {
621 DriverBinding = SortedDriverBindingProtocols[SortIndex];
622 SortedDriverBindingProtocols[SortIndex] = SortedDriverBindingProtocols[HighestIndex];
623 SortedDriverBindingProtocols[HighestIndex] = DriverBinding;
637 DriverBinding =
NULL;
639 for (Index = 0; (Index < NumberOfSortedDriverBindingProtocols) && !DriverFound; Index++) {
640 if (SortedDriverBindingProtocols[Index] !=
NULL) {
641 DriverBinding = SortedDriverBindingProtocols[Index];
643 Status = DriverBinding->Supported (
649 if (!EFI_ERROR (Status)) {
650 SortedDriverBindingProtocols[Index] =
NULL;
658 Status = DriverBinding->Start (
665 if (!EFI_ERROR (Status)) {
674 }
while (DriverFound);
691 if (RemainingDevicePath !=
NULL) {
700 return EFI_NOT_FOUND;
749 UINTN DriverImageHandleCount;
750 UINTN ChildrenToStop;
751 UINTN ChildBufferCount;
754 BOOLEAN ChildHandleValid;
755 BOOLEAN DriverImageHandleValid;
768 if (EFI_ERROR (Status)) {
776 if (ChildHandle !=
NULL) {
778 if (EFI_ERROR (Status)) {
786 Handle = ControllerHandle;
791 DriverImageHandleBuffer =
NULL;
792 DriverImageHandleCount = 1;
794 if (DriverImageHandle ==
NULL) {
798 DriverImageHandleCount = 0;
801 for (Link = Handle->
Protocols.ForwardLink; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
803 for (ProtLink = Prot->
OpenList.ForwardLink;
805 ProtLink = ProtLink->ForwardLink)
808 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
809 DriverImageHandleCount++;
819 if (DriverImageHandleCount == 0) {
825 if (DriverImageHandleBuffer ==
NULL) {
826 Status = EFI_OUT_OF_RESOURCES;
830 DriverImageHandleCount = 0;
833 for (Link = Handle->
Protocols.ForwardLink; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
835 for (ProtLink = Prot->
OpenList.ForwardLink;
837 ProtLink = ProtLink->ForwardLink)
840 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
842 for (Index = 0; Index < DriverImageHandleCount; Index++) {
843 if (DriverImageHandleBuffer[Index] == OpenData->AgentHandle) {
850 DriverImageHandleBuffer[DriverImageHandleCount] = OpenData->AgentHandle;
851 DriverImageHandleCount++;
861 for (HandleIndex = 0; HandleIndex < DriverImageHandleCount; HandleIndex++) {
862 if (DriverImageHandleBuffer !=
NULL) {
863 DriverImageHandle = DriverImageHandleBuffer[HandleIndex];
871 &gEfiDriverBindingProtocolGuid,
872 (VOID **)&DriverBinding
874 if (EFI_ERROR (Status) || (DriverBinding ==
NULL)) {
875 Status = EFI_INVALID_PARAMETER;
882 DriverImageHandleValid =
FALSE;
883 ChildBufferCount = 0;
886 for (Link = Handle->
Protocols.ForwardLink; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
888 for (ProtLink = Prot->
OpenList.ForwardLink;
890 ProtLink = ProtLink->ForwardLink)
893 if (OpenData->AgentHandle == DriverImageHandle) {
894 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
898 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
899 DriverImageHandleValid =
TRUE;
907 if (DriverImageHandleValid) {
908 ChildHandleValid =
FALSE;
910 if (ChildBufferCount != 0) {
912 if (ChildBuffer ==
NULL) {
913 Status = EFI_OUT_OF_RESOURCES;
917 ChildBufferCount = 0;
920 for (Link = Handle->
Protocols.ForwardLink; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
922 for (ProtLink = Prot->
OpenList.ForwardLink;
924 ProtLink = ProtLink->ForwardLink)
927 if ((OpenData->AgentHandle == DriverImageHandle) &&
928 ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0))
931 for (Index = 0; Index < ChildBufferCount; Index++) {
932 if (ChildBuffer[Index] == OpenData->ControllerHandle) {
939 ChildBuffer[ChildBufferCount] = OpenData->ControllerHandle;
940 if (ChildHandle == ChildBuffer[ChildBufferCount]) {
941 ChildHandleValid =
TRUE;
953 if ((ChildHandle ==
NULL) || ChildHandleValid) {
956 if (ChildBufferCount > 0) {
957 if (ChildHandle !=
NULL) {
959 Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, &ChildHandle);
961 ChildrenToStop = ChildBufferCount;
962 Status = DriverBinding->Stop (DriverBinding, ControllerHandle, ChildrenToStop, ChildBuffer);
966 if (!EFI_ERROR (Status) && ((ChildHandle ==
NULL) || (ChildBufferCount == ChildrenToStop))) {
967 Status = DriverBinding->Stop (DriverBinding, ControllerHandle, 0,
NULL);
970 if (!EFI_ERROR (Status)) {
975 if (ChildBuffer !=
NULL) {
984 Status = EFI_NOT_FOUND;
989 if (DriverImageHandleBuffer !=
NULL) {
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DuplicateDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_STATUS CoreConnectSingleController(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE *ContextDriverImageHandles OPTIONAL, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL)
EFI_STATUS EFIAPI CoreDisconnectController(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE DriverImageHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL)
VOID AddSortedDriverBindingProtocol(IN EFI_HANDLE DriverBindingHandle, IN OUT UINTN *NumberOfSortedDriverBindingProtocols, IN OUT EFI_DRIVER_BINDING_PROTOCOL **SortedDriverBindingProtocols, IN UINTN DriverBindingHandleCount, IN OUT EFI_HANDLE *DriverBindingHandleBuffer, IN BOOLEAN IsImageHandle)
EFI_STATUS EFIAPI CoreConnectController(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE *DriverImageHandle OPTIONAL, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, IN BOOLEAN Recursive)
EFI_STATUS EFIAPI CoreHandleProtocol(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, OUT VOID **Interface)
EFI_STATUS EFIAPI CoreLocateProtocol(IN EFI_GUID *Protocol, IN VOID *Registration OPTIONAL, OUT VOID **Interface)
EFI_STATUS EFIAPI CoreLocateHandleBuffer(IN EFI_LOCATE_SEARCH_TYPE SearchType, IN EFI_GUID *Protocol OPTIONAL, IN VOID *SearchKey OPTIONAL, IN OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
EFI_STATUS EFIAPI CoreFreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID CoreReleaseProtocolLock(VOID)
EFI_STATUS CoreValidateHandle(IN EFI_HANDLE UserHandle)
VOID CoreAcquireProtocolLock(VOID)
#define CR(Record, TYPE, Field, TestSignature)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_HANDLE DriverBindingHandle
LIST_ENTRY Protocols
List of PROTOCOL_INTERFACE's for this handle.
LIST_ENTRY OpenList
OPEN_PROTOCOL_DATA list.