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
23 // Include common header file for this module.
25 #include "CommonHeader.h"
35 This function will connect all the system driver to controller
36 first, and then special connect the default console, this make
37 sure all the system controller avialbe and the platform default
51 // Connect the platform console first
53 BdsLibConnectAllDefaultConsoles ();
56 // Generic way to connect all the drivers
58 BdsLibConnectAllDriversToAllControllers ();
61 // Here we have the assumption that we have already had
62 // platform default console
64 BdsLibConnectAllDefaultConsoles ();
68 BdsLibGenericConnectAll (
75 This function will connect all the system drivers to all controllers
76 first, and then connect all the console devices the system current
77 have. After this we should get all the device work and console avariable
78 if the system have console device.
91 // Most generic way to connect all the drivers
93 BdsLibConnectAllDriversToAllControllers ();
94 BdsLibConnectAllConsoles ();
98 BdsLibConnectDevicePath (
99 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
104 This function will create all handles associate with every device
105 path node. If the handle associate with one device path node can not
106 be created success, then still give one chance to do the dispatch,
107 which load the missing drivers if possible.
111 DevicePathToConnect - The device path which will be connected, it can
112 be a multi-instance device path
116 EFI_SUCCESS - All handles associate with every device path
117 node have been created
119 EFI_OUT_OF_RESOURCES - There is no resource to create new handles
121 EFI_NOT_FOUND - Create the handle associate with one device
127 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
128 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
129 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
130 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
131 EFI_DEVICE_PATH_PROTOCOL
*Next
;
133 EFI_HANDLE PreviousHandle
;
136 if (DevicePathToConnect
== NULL
) {
140 DevicePath
= DuplicateDevicePath (DevicePathToConnect
);
141 CopyOfDevicePath
= DevicePath
;
142 if (DevicePath
== NULL
) {
143 return EFI_OUT_OF_RESOURCES
;
148 // The outer loop handles multi instance device paths.
149 // Only console variables contain multiple instance device paths.
151 // After this call DevicePath points to the next Instance
153 Instance
= GetNextDevicePathInstance (&DevicePath
, &Size
);
155 while (!IsDevicePathEndType (Next
)) {
156 Next
= NextDevicePathNode (Next
);
159 SetDevicePathEndNode (Next
);
162 // Start the real work of connect with RemainingDevicePath
164 PreviousHandle
= NULL
;
167 // Find the handle that best matches the Device Path. If it is only a
168 // partial match the remaining part of the device path is returned in
169 // RemainingDevicePath.
171 RemainingDevicePath
= Instance
;
172 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &Handle
);
174 if (!EFI_ERROR (Status
)) {
175 if (Handle
== PreviousHandle
) {
177 // If no forward progress is made try invoking the Dispatcher.
178 // A new FV may have been added to the system an new drivers
180 // Status == EFI_SUCCESS means a driver was dispatched
181 // Status == EFI_NOT_FOUND means no new drivers were dispatched
183 Status
= gDS
->Dispatch ();
186 if (!EFI_ERROR (Status
)) {
187 PreviousHandle
= Handle
;
189 // Connect all drivers that apply to Handle and RemainingDevicePath,
190 // the Recursive flag is FALSE so only one level will be expanded.
192 // Do not check the connect status here, if the connect controller fail,
193 // then still give the chance to do dispatch, because partial
194 // RemainingDevicepath may be in the new FV
196 // 1. If the connect fail, RemainingDevicepath and handle will not
197 // change, so next time will do the dispatch, then dispatch's status
199 // 2. If the connect success, the RemainingDevicepath and handle will
200 // change, then avoid the dispatch, we have chance to continue the
203 gBS
->ConnectController (Handle
, NULL
, RemainingDevicePath
, FALSE
);
207 // Loop until RemainingDevicePath is an empty device path
209 } while (!EFI_ERROR (Status
) && !IsDevicePathEnd (RemainingDevicePath
));
211 } while (DevicePath
!= NULL
);
213 if (CopyOfDevicePath
!= NULL
) {
214 FreePool (CopyOfDevicePath
);
217 // All handle with DevicePath exists in the handle database
223 BdsLibConnectAllEfi (
230 This function will connect all current system handles recursively. The
231 connection will finish until every handle's child handle created if it have.
239 EFI_SUCCESS - All handles and it's child handle have been connected
241 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
247 EFI_HANDLE
*HandleBuffer
;
250 Status
= gBS
->LocateHandleBuffer (
257 if (EFI_ERROR (Status
)) {
261 for (Index
= 0; Index
< HandleCount
; Index
++) {
262 Status
= gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
265 FreePool (HandleBuffer
);
271 BdsLibDisconnectAllEfi (
278 This function will disconnect all current system handles. The disconnection
279 will finish until every handle have been disconnected.
287 EFI_SUCCESS - All handles have been disconnected
289 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
295 EFI_HANDLE
*HandleBuffer
;
301 Status
= gBS
->LocateHandleBuffer (
308 if (EFI_ERROR (Status
)) {
312 for (Index
= 0; Index
< HandleCount
; Index
++) {
313 Status
= gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
316 FreePool (HandleBuffer
);
322 BdsLibConnectAllDriversToAllControllers (
329 Connects all drivers to all controllers.
330 This function make sure all the current system driver will manage
331 the correspoinding controllers if have. And at the same time, make
332 sure all the system controllers have driver to manage it if have.
348 // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
350 BdsLibConnectAllEfi ();
353 // Check to see if it's possible to dispatch an more DXE drivers.
354 // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
355 // If anything is Dispatched Status == EFI_SUCCESS and we will try
356 // the connect again.
358 Status
= gDS
->Dispatch ();
360 } while (!EFI_ERROR (Status
));