3 Copyright (c) 2006, 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
30 This function will connect all the system driver to controller
31 first, and then special connect the default console, this make
32 sure all the system controller avialbe and the platform default
46 // Connect the platform console first
48 BdsLibConnectAllDefaultConsoles ();
51 // Generic way to connect all the drivers
53 BdsLibConnectAllDriversToAllControllers ();
56 // Here we have the assumption that we have already had
57 // platform default console
59 BdsLibConnectAllDefaultConsoles ();
63 BdsLibGenericConnectAll (
70 This function will connect all the system drivers to all controllers
71 first, and then connect all the console devices the system current
72 have. After this we should get all the device work and console avariable
73 if the system have console device.
86 // Most generic way to connect all the drivers
88 BdsLibConnectAllDriversToAllControllers ();
89 BdsLibConnectAllConsoles ();
93 BdsLibConnectDevicePath (
94 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
99 This function will create all handles associate with every device
100 path node. If the handle associate with one device path node can not
101 be created success, then still give one chance to do the dispatch,
102 which load the missing drivers if possible.
106 DevicePathToConnect - The device path which will be connected, it can
107 be a multi-instance device path
111 EFI_SUCCESS - All handles associate with every device path
112 node have been created
114 EFI_OUT_OF_RESOURCES - There is no resource to create new handles
116 EFI_NOT_FOUND - Create the handle associate with one device
122 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
123 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
124 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
125 EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
;
126 EFI_DEVICE_PATH_PROTOCOL
*Next
;
128 EFI_HANDLE PreviousHandle
;
131 if (DevicePathToConnect
== NULL
) {
135 DevicePath
= DuplicateDevicePath (DevicePathToConnect
);
136 CopyOfDevicePath
= DevicePath
;
137 if (DevicePath
== NULL
) {
138 return EFI_OUT_OF_RESOURCES
;
143 // The outer loop handles multi instance device paths.
144 // Only console variables contain multiple instance device paths.
146 // After this call DevicePath points to the next Instance
148 Instance
= GetNextDevicePathInstance (&DevicePath
, &Size
);
150 while (!IsDevicePathEndType (Next
)) {
151 Next
= NextDevicePathNode (Next
);
154 SetDevicePathEndNode (Next
);
157 // Start the real work of connect with RemainingDevicePath
159 PreviousHandle
= NULL
;
162 // Find the handle that best matches the Device Path. If it is only a
163 // partial match the remaining part of the device path is returned in
164 // RemainingDevicePath.
166 RemainingDevicePath
= Instance
;
167 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &RemainingDevicePath
, &Handle
);
169 if (!EFI_ERROR (Status
)) {
170 if (Handle
== PreviousHandle
) {
172 // If no forward progress is made try invoking the Dispatcher.
173 // A new FV may have been added to the system an new drivers
175 // Status == EFI_SUCCESS means a driver was dispatched
176 // Status == EFI_NOT_FOUND means no new drivers were dispatched
178 Status
= gDS
->Dispatch ();
181 if (!EFI_ERROR (Status
)) {
182 PreviousHandle
= Handle
;
184 // Connect all drivers that apply to Handle and RemainingDevicePath,
185 // the Recursive flag is FALSE so only one level will be expanded.
187 // Do not check the connect status here, if the connect controller fail,
188 // then still give the chance to do dispatch, because partial
189 // RemainingDevicepath may be in the new FV
191 // 1. If the connect fail, RemainingDevicepath and handle will not
192 // change, so next time will do the dispatch, then dispatch's status
194 // 2. If the connect success, the RemainingDevicepath and handle will
195 // change, then avoid the dispatch, we have chance to continue the
198 gBS
->ConnectController (Handle
, NULL
, RemainingDevicePath
, FALSE
);
202 // Loop until RemainingDevicePath is an empty device path
204 } while (!EFI_ERROR (Status
) && !IsDevicePathEnd (RemainingDevicePath
));
206 } while (DevicePath
!= NULL
);
208 if (CopyOfDevicePath
!= NULL
) {
209 gBS
->FreePool (CopyOfDevicePath
);
212 // All handle with DevicePath exists in the handle database
218 BdsLibConnectAllEfi (
225 This function will connect all current system handles recursively. The
226 connection will finish until every handle's child handle created if it have.
234 EFI_SUCCESS - All handles and it's child handle have been connected
236 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
242 EFI_HANDLE
*HandleBuffer
;
245 Status
= gBS
->LocateHandleBuffer (
252 if (EFI_ERROR (Status
)) {
256 for (Index
= 0; Index
< HandleCount
; Index
++) {
257 Status
= gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
260 gBS
->FreePool (HandleBuffer
);
266 BdsLibDisconnectAllEfi (
273 This function will disconnect all current system handles. The disconnection
274 will finish until every handle have been disconnected.
282 EFI_SUCCESS - All handles have been disconnected
284 EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
290 EFI_HANDLE
*HandleBuffer
;
296 Status
= gBS
->LocateHandleBuffer (
303 if (EFI_ERROR (Status
)) {
307 for (Index
= 0; Index
< HandleCount
; Index
++) {
308 Status
= gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
311 gBS
->FreePool (HandleBuffer
);
317 BdsLibConnectAllDriversToAllControllers (
324 Connects all drivers to all controllers.
325 This function make sure all the current system driver will manage
326 the correspoinding controllers if have. And at the same time, make
327 sure all the system controllers have driver to manage it if have.
343 // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
345 BdsLibConnectAllEfi ();
348 // Check to see if it's possible to dispatch an more DXE drivers.
349 // The BdsLibConnectAllEfi () may have made new DXE drivers show up.
350 // If anything is Dispatched Status == EFI_SUCCESS and we will try
351 // the connect again.
353 Status
= gDS
->Dispatch ();
355 } while (!EFI_ERROR (Status
));