2 Library functions which relate with connecting the device.
4 Copyright (c) 2011 - 2015, 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.
15 #include "InternalBm.h"
18 Connect all the drivers to all the controllers.
20 This function makes sure all the current system drivers manage the correspoinding
21 controllers if have. And at the same time, makes sure all the system controllers
22 have driver to manage it if have.
25 BmConnectAllDriversToAllControllers (
31 EFI_HANDLE
*HandleBuffer
;
36 // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
38 gBS
->LocateHandleBuffer (
46 for (Index
= 0; Index
< HandleCount
; Index
++) {
47 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
50 if (HandleBuffer
!= NULL
) {
51 FreePool (HandleBuffer
);
55 // Check to see if it's possible to dispatch an more DXE drivers.
56 // The above code may have made new DXE drivers show up.
57 // If any new driver is dispatched (Status == EFI_SUCCESS) and we will try
60 Status
= gDS
->Dispatch ();
62 } while (!EFI_ERROR (Status
));
66 This function will connect all the system driver to controller
67 first, and then special connect the default console, this make
68 sure all the system controller available and the platform default
74 EfiBootManagerConnectAll (
79 // Connect the platform console first
81 EfiBootManagerConnectAllDefaultConsoles ();
84 // Generic way to connect all the drivers
86 BmConnectAllDriversToAllControllers ();
89 // Here we have the assumption that we have already had
90 // platform default console
92 EfiBootManagerConnectAllDefaultConsoles ();
96 This function will create all handles associate with every device
97 path node. If the handle associate with one device path node can not
98 be created successfully, then still give chance to do the dispatch,
99 which load the missing drivers if possible.
101 @param DevicePathToConnect The device path which will be connected, it can be
102 a multi-instance device path
103 @param MatchingHandle Return the controller handle closest to the DevicePathToConnect
105 @retval EFI_SUCCESS All handles associate with every device path node
107 @retval EFI_OUT_OF_RESOURCES There is no resource to create new handles
108 @retval EFI_NOT_FOUND Create the handle associate with one device path
114 EfiBootManagerConnectDevicePath (
115 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
,
116 OUT EFI_HANDLE
*MatchingHandle OPTIONAL
120 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
122 EFI_HANDLE PreviousHandle
;
125 if (DevicePathToConnect
== NULL
) {
126 return EFI_INVALID_PARAMETER
;
129 CurrentTpl
= EfiGetCurrentTpl ();
131 // Start the real work of connect with RemainingDevicePath
133 PreviousHandle
= NULL
;
136 // Find the handle that best matches the Device Path. If it is only a
137 // partial match the remaining part of the device path is returned in
138 // RemainingDevicePath.
140 RemainingDevicePath
= DevicePathToConnect
;
141 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &Handle
);
142 if (!EFI_ERROR (Status
)) {
143 if (Handle
== PreviousHandle
) {
145 // If no forward progress is made try invoking the Dispatcher.
146 // A new FV may have been added to the system an new drivers
148 // Status == EFI_SUCCESS means a driver was dispatched
149 // Status == EFI_NOT_FOUND means no new drivers were dispatched
151 if (CurrentTpl
== TPL_APPLICATION
) {
152 Status
= gDS
->Dispatch ();
155 // Always return EFI_NOT_FOUND here
156 // to prevent dead loop when control handle is found but connection failded case
158 Status
= EFI_NOT_FOUND
;
163 if (!EFI_ERROR (Status
)) {
164 PreviousHandle
= Handle
;
166 // Connect all drivers that apply to Handle and RemainingDevicePath,
167 // the Recursive flag is FALSE so only one level will be expanded.
169 // Do not check the connect status here, if the connect controller fail,
170 // then still give the chance to do dispatch, because partial
171 // RemainingDevicepath may be in the new FV
173 // 1. If the connect fail, RemainingDevicepath and handle will not
174 // change, so next time will do the dispatch, then dispatch's status
176 // 2. If the connect success, the RemainingDevicepath and handle will
177 // change, then avoid the dispatch, we have chance to continue the
180 gBS
->ConnectController (Handle
, NULL
, RemainingDevicePath
, FALSE
);
181 if (MatchingHandle
!= NULL
) {
182 *MatchingHandle
= Handle
;
187 // Loop until RemainingDevicePath is an empty device path
189 } while (!EFI_ERROR (Status
) && !IsDevicePathEnd (RemainingDevicePath
));
191 ASSERT (EFI_ERROR (Status
) || IsDevicePathEnd (RemainingDevicePath
));
197 This function will disconnect all current system handles.
199 gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
200 If handle is a bus type handle, all childrens also are disconnected recursively by
201 gBS->DisconnectController().
205 EfiBootManagerDisconnectAll (
210 EFI_HANDLE
*HandleBuffer
;
216 gBS
->LocateHandleBuffer (
223 for (Index
= 0; Index
< HandleCount
; Index
++) {
224 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
227 if (HandleBuffer
!= NULL
) {
228 FreePool (HandleBuffer
);
233 Connect the specific Usb device which match the short form device path,
234 and whose bus is determined by Host Controller (Uhci or Ehci).
236 @param DevicePath A short-form device path that starts with the first
237 element being a USB WWID or a USB Class device
240 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
241 DevicePath is not a USB device path.
243 @return EFI_SUCCESS Success to connect USB device
244 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
248 BmConnectUsbShortFormDevicePath (
249 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
256 EFI_PCI_IO_PROTOCOL
*PciIo
;
258 BOOLEAN AtLeastOneConnected
;
261 // Check the passed in parameters
263 if (DevicePath
== NULL
) {
264 return EFI_INVALID_PARAMETER
;
267 if ((DevicePathType (DevicePath
) != MESSAGING_DEVICE_PATH
) ||
268 ((DevicePathSubType (DevicePath
) != MSG_USB_CLASS_DP
) && (DevicePathSubType (DevicePath
) != MSG_USB_WWID_DP
))
270 return EFI_INVALID_PARAMETER
;
274 // Find the usb host controller firstly, then connect with the remaining device path
276 AtLeastOneConnected
= FALSE
;
277 Status
= gBS
->LocateHandleBuffer (
279 &gEfiPciIoProtocolGuid
,
284 if (!EFI_ERROR (Status
)) {
285 for (Index
= 0; Index
< HandleCount
; Index
++) {
286 Status
= gBS
->HandleProtocol (
288 &gEfiPciIoProtocolGuid
,
291 if (!EFI_ERROR (Status
)) {
293 // Check whether the Pci device is the wanted usb host controller
295 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint8
, 0x09, 3, &Class
);
296 if (!EFI_ERROR (Status
) &&
297 ((PCI_CLASS_SERIAL
== Class
[2]) && (PCI_CLASS_SERIAL_USB
== Class
[1]))
299 Status
= gBS
->ConnectController (
305 if (!EFI_ERROR(Status
)) {
306 AtLeastOneConnected
= TRUE
;
312 if (Handles
!= NULL
) {
317 return AtLeastOneConnected
? EFI_SUCCESS
: EFI_NOT_FOUND
;