3 Copyright (c) 2006 - 2007, 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 BDS Lib functions which relate with connect the device
22 #include <EdkGenericBdsLibInternal.h>
32 This function will connect all the system driver to controller
33 first, and then special connect the default console, this make
34 sure all the system controller avialbe and the platform default
48 // Connect the platform console first
50 BdsLibConnectAllDefaultConsoles ();
53 // Generic way to connect all the drivers
55 BdsLibConnectAllDriversToAllControllers ();
58 // Here we have the assumption that we have already had
59 // platform default console
61 BdsLibConnectAllDefaultConsoles ();
65 BdsLibGenericConnectAll (
72 This function will connect all the system drivers to all controllers
73 first, and then connect all the console devices the system current
74 have. After this we should get all the device work and console avariable
75 if the system have console device.
88 // Most generic way to connect all the drivers
90 BdsLibConnectAllDriversToAllControllers ();
91 BdsLibConnectAllConsoles ();
95 BdsLibConnectDevicePath (
96 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
101 This function will create all handles associate with every device
102 path node. If the handle associate with one device path node can not
103 be created success, then still give one chance to do the dispatch,
104 which load the missing drivers if possible.
108 DevicePathToConnect - The device path which will be connected, it can
109 be a multi-instance device path
113 EFI_SUCCESS - All handles associate with every device path
114 node have been created
116 EFI_OUT_OF_RESOURCES - There is no resource to create new handles
118 EFI_NOT_FOUND - Create the handle associate with one device
124 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
125 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
126 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
127 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
128 EFI_DEVICE_PATH_PROTOCOL
*Next
;
130 EFI_HANDLE PreviousHandle
;
133 if (DevicePathToConnect
== NULL
) {
137 DevicePath
= DuplicateDevicePath (DevicePathToConnect
);
138 CopyOfDevicePath
= DevicePath
;
139 if (DevicePath
== NULL
) {
140 return EFI_OUT_OF_RESOURCES
;
145 // The outer loop handles multi instance device paths.
146 // Only console variables contain multiple instance device paths.
148 // After this call DevicePath points to the next Instance
150 Instance
= GetNextDevicePathInstance (&DevicePath
, &Size
);
152 while (!IsDevicePathEndType (Next
)) {
153 Next
= NextDevicePathNode (Next
);
156 SetDevicePathEndNode (Next
);
159 // Start the real work of connect with RemainingDevicePath
161 PreviousHandle
= NULL
;
164 // Find the handle that best matches the Device Path. If it is only a
165 // partial match the remaining part of the device path is returned in
166 // RemainingDevicePath.
168 RemainingDevicePath
= Instance
;
169 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &Handle
);
171 if (!EFI_ERROR (Status
)) {
172 if (Handle
== PreviousHandle
) {
174 // If no forward progress is made try invoking the Dispatcher.
175 // A new FV may have been added to the system an new drivers
177 // Status == EFI_SUCCESS means a driver was dispatched
178 // Status == EFI_NOT_FOUND means no new drivers were dispatched
180 Status
= gDS
->Dispatch ();
183 if (!EFI_ERROR (Status
)) {
184 PreviousHandle
= Handle
;
186 // Connect all drivers that apply to Handle and RemainingDevicePath,
187 // the Recursive flag is FALSE so only one level will be expanded.
189 // Do not check the connect status here, if the connect controller fail,
190 // then still give the chance to do dispatch, because partial
191 // RemainingDevicepath may be in the new FV
193 // 1. If the connect fail, RemainingDevicepath and handle will not
194 // change, so next time will do the dispatch, then dispatch's status
196 // 2. If the connect success, the RemainingDevicepath and handle will
197 // change, then avoid the dispatch, we have chance to continue the
200 gBS
->ConnectController (Handle
, NULL
, RemainingDevicePath
, FALSE
);
204 // Loop until RemainingDevicePath is an empty device path
206 } while (!EFI_ERROR (Status
) && !IsDevicePathEnd (RemainingDevicePath
));
208 } while (DevicePath
!= NULL
);
210 if (CopyOfDevicePath
!= NULL
) {
211 FreePool (CopyOfDevicePath
);
214 // All handle with DevicePath exists in the handle database
220 BdsLibConnectAllEfi (
227 This function will connect all current system handles recursively. The
228 connection will finish until every handle's child handle created if it have.
236 EFI_SUCCESS - All handles and it's child handle have been connected
238 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
244 EFI_HANDLE
*HandleBuffer
;
247 Status
= gBS
->LocateHandleBuffer (
254 if (EFI_ERROR (Status
)) {
258 for (Index
= 0; Index
< HandleCount
; Index
++) {
259 Status
= gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
262 FreePool (HandleBuffer
);
268 BdsLibDisconnectAllEfi (
275 This function will disconnect all current system handles. The disconnection
276 will finish until every handle have been disconnected.
284 EFI_SUCCESS - All handles have been disconnected
286 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
292 EFI_HANDLE
*HandleBuffer
;
298 Status
= gBS
->LocateHandleBuffer (
305 if (EFI_ERROR (Status
)) {
309 for (Index
= 0; Index
< HandleCount
; Index
++) {
310 Status
= gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
313 FreePool (HandleBuffer
);
319 BdsLibConnectAllDriversToAllControllers (
326 Connects all drivers to all controllers.
327 This function make sure all the current system driver will manage
328 the correspoinding controllers if have. And at the same time, make
329 sure all the system controllers have driver to manage it if have.
345 // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
347 BdsLibConnectAllEfi ();
350 // Check to see if it's possible to dispatch an more DXE drivers.
351 // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
352 // If anything is Dispatched Status == EFI_SUCCESS and we will try
353 // the connect again.
355 Status
= gDS
->Dispatch ();
357 } while (!EFI_ERROR (Status
));