2 BDS Lib functions which relate with connect the device
4 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI_STATUS
ScanDeviceHandles(EFI_HANDLE ControllerHandle
,
20 EFI_HANDLE
**HandleBuffer
,
25 EFI_GUID
**ProtocolGuidArray
;
28 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
38 // Retrieve the list of all handles from the handle database
40 Status
= gBS
->LocateHandleBuffer (AllHandles
, NULL
, NULL
, HandleCount
, HandleBuffer
);
41 if (EFI_ERROR (Status
)) goto Error
;
43 *HandleType
= AllocatePool (*HandleCount
* sizeof (UINT32
));
44 if (*HandleType
== NULL
) goto Error
;
46 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
47 (*HandleType
)[HandleIndex
] = EFI_HANDLE_TYPE_UNKNOWN
;
49 // Retrieve the list of all the protocols on each handle
51 Status
= gBS
->ProtocolsPerHandle (
52 (*HandleBuffer
)[HandleIndex
],
56 if (!EFI_ERROR (Status
)) {
57 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++)
60 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
))
62 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_IMAGE_HANDLE
;
65 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
))
67 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_DRIVER_BINDING_HANDLE
;
70 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
))
72 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_DRIVER_CONFIGURATION_HANDLE
;
75 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
))
77 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_DRIVER_DIAGNOSTICS_HANDLE
;
80 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
))
82 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_COMPONENT_NAME_HANDLE
;
85 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) )
87 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_COMPONENT_NAME_HANDLE
;
90 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
))
92 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_DEVICE_HANDLE
;
96 // Retrieve the list of agents that have opened each protocol
98 Status
= gBS
->OpenProtocolInformation (
99 (*HandleBuffer
)[HandleIndex
],
100 ProtocolGuidArray
[ProtocolIndex
],
104 if (!EFI_ERROR (Status
)) {
106 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
108 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
)
110 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) == EFI_OPEN_PROTOCOL_BY_DRIVER
)
112 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++)
114 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].AgentHandle
)
116 (*HandleType
)[ChildIndex
] |= EFI_HANDLE_TYPE_DEVICE_DRIVER
;
121 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
)
123 (*HandleType
)[HandleIndex
] |= EFI_HANDLE_TYPE_PARENT_HANDLE
;
124 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++)
126 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].AgentHandle
)
128 (*HandleType
)[ChildIndex
] |= EFI_HANDLE_TYPE_BUS_DRIVER
;
139 FreePool (ProtocolGuidArray
);
146 if (*HandleType
!= NULL
) {
147 FreePool (*HandleType
);
150 if (*HandleBuffer
!= NULL
) {
151 FreePool (*HandleBuffer
);
155 *HandleBuffer
= NULL
;
163 EFI_STATUS
BdsLibConnectMostlyAllEfi()
166 UINTN AllHandleCount
;
167 EFI_HANDLE
*AllHandleBuffer
;
170 EFI_HANDLE
*HandleBuffer
;
175 EFI_PCI_IO_PROTOCOL
* PciIo
;
179 Status
= gBS
->LocateHandleBuffer (AllHandles
, NULL
, NULL
, &AllHandleCount
, &AllHandleBuffer
);
180 if (CheckError(Status
, L
"locating handle buffer"))
183 for (Index
= 0; Index
< AllHandleCount
; Index
++)
185 Status
= ScanDeviceHandles(AllHandleBuffer
[Index
], &HandleCount
, &HandleBuffer
, &HandleType
);
187 if (EFI_ERROR (Status
))
192 if (HandleType
[Index
] & EFI_HANDLE_TYPE_DRIVER_BINDING_HANDLE
)
194 if (HandleType
[Index
] & EFI_HANDLE_TYPE_IMAGE_HANDLE
)
200 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++)
202 if (HandleType
[HandleIndex
] & EFI_HANDLE_TYPE_PARENT_HANDLE
)
208 if (HandleType
[Index
] & EFI_HANDLE_TYPE_DEVICE_HANDLE
)
210 Status
= gBS
->HandleProtocol (AllHandleBuffer
[Index
], &gEfiPciIoProtocolGuid
, (VOID
*)&PciIo
);
211 if (!EFI_ERROR (Status
))
213 Status
= PciIo
->Pci
.Read (PciIo
,EfiPciIoWidthUint32
, 0, sizeof (Pci
) / sizeof (UINT32
), &Pci
);
214 if (!EFI_ERROR (Status
))
216 if(IS_PCI_VGA(&Pci
)==TRUE
)
218 gBS
->DisconnectController(AllHandleBuffer
[Index
], NULL
, NULL
);
222 Status
= gBS
->ConnectController(AllHandleBuffer
[Index
], NULL
, NULL
, TRUE
);
227 FreePool (HandleBuffer
);
228 FreePool (HandleType
);
232 FreePool (AllHandleBuffer
);
239 Connects all drivers to all controllers.
240 This function make sure all the current system driver will manage
241 the correspoinding controllers if have. And at the same time, make
242 sure all the system controllers have driver to manage it if have.
247 BdsLibConnectAllDriversToAllControllers (
255 // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
257 //BdsLibConnectAllEfi ();
258 BdsLibConnectMostlyAllEfi ();
261 // Check to see if it's possible to dispatch an more DXE drivers.
262 // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
263 // If anything is Dispatched Status == EFI_SUCCESS and we will try
264 // the connect again.
266 Status
= gDS
->Dispatch ();
268 } while (!EFI_ERROR (Status
));