TianoCore EDK2 master
Loading...
Searching...
No Matches
BmConnect.c
Go to the documentation of this file.
1
9#include "InternalBm.h"
10
18VOID
20 VOID
21 )
22{
23 EFI_STATUS Status;
24 UINTN HandleCount;
25 EFI_HANDLE *HandleBuffer;
26 UINTN Index;
27
28 do {
29 //
30 // Connect All EFI 1.10 drivers following EFI 1.10 algorithm
31 //
32 gBS->LocateHandleBuffer (
34 NULL,
35 NULL,
36 &HandleCount,
37 &HandleBuffer
38 );
39
40 for (Index = 0; Index < HandleCount; Index++) {
41 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
42 }
43
44 if (HandleBuffer != NULL) {
45 FreePool (HandleBuffer);
46 }
47
48 //
49 // Check to see if it's possible to dispatch an more DXE drivers.
50 // The above code may have made new DXE drivers show up.
51 // If any new driver is dispatched (Status == EFI_SUCCESS) and we will try
52 // the connect again.
53 //
54 Status = gDS->Dispatch ();
55 } while (!EFI_ERROR (Status));
56}
57
65VOID
66EFIAPI
68 VOID
69 )
70{
71 //
72 // Connect the platform console first
73 //
75
76 //
77 // Generic way to connect all the drivers
78 //
80
81 //
82 // Here we have the assumption that we have already had
83 // platform default console
84 //
86}
87
107EFIAPI
109 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect,
110 OUT EFI_HANDLE *MatchingHandle OPTIONAL
111 )
112{
113 EFI_STATUS Status;
114 EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
115 EFI_HANDLE Handle;
116 EFI_HANDLE PreviousHandle;
117 EFI_TPL CurrentTpl;
118
119 if (DevicePathToConnect == NULL) {
120 return EFI_INVALID_PARAMETER;
121 }
122
123 CurrentTpl = EfiGetCurrentTpl ();
124 //
125 // Start the real work of connect with RemainingDevicePath
126 //
127 PreviousHandle = NULL;
128 do {
129 //
130 // Find the handle that best matches the Device Path. If it is only a
131 // partial match the remaining part of the device path is returned in
132 // RemainingDevicePath.
133 //
134 RemainingDevicePath = DevicePathToConnect;
135 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
136 if (!EFI_ERROR (Status)) {
137 if (Handle == PreviousHandle) {
138 //
139 // If no forward progress is made try invoking the Dispatcher.
140 // A new FV may have been added to the system an new drivers
141 // may now be found.
142 // Status == EFI_SUCCESS means a driver was dispatched
143 // Status == EFI_NOT_FOUND means no new drivers were dispatched
144 //
145 if (CurrentTpl == TPL_APPLICATION) {
146 Status = gDS->Dispatch ();
147 } else {
148 //
149 // Always return EFI_NOT_FOUND here
150 // to prevent dead loop when control handle is found but connection failded case
151 //
152 Status = EFI_NOT_FOUND;
153 }
154 }
155
156 if (!EFI_ERROR (Status)) {
157 PreviousHandle = Handle;
158 //
159 // Connect all drivers that apply to Handle and RemainingDevicePath,
160 // the Recursive flag is FALSE so only one level will be expanded.
161 //
162 // If ConnectController fails to find a driver, then still give the chance to
163 // do dispatch, because partial RemainingDevicePath may be in the new FV
164 //
165 // 1. If the connect fail, RemainingDevicepath and handle will not
166 // change, so next time will do the dispatch, then dispatch's status
167 // will take effect
168 // 2. If the connect success, the RemainingDevicepath and handle will
169 // change, then avoid the dispatch, we have chance to continue the
170 // next connection
171 //
172 Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
173 if (Status == EFI_NOT_FOUND) {
174 Status = EFI_SUCCESS;
175 }
176
177 if (MatchingHandle != NULL) {
178 *MatchingHandle = Handle;
179 }
180 }
181 }
182
183 //
184 // Loop until RemainingDevicePath is an empty device path
185 //
186 } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));
187
188 ASSERT (EFI_ERROR (Status) || IsDevicePathEnd (RemainingDevicePath));
189
190 return Status;
191}
192
200VOID
201EFIAPI
203 VOID
204 )
205{
206 UINTN HandleCount;
207 EFI_HANDLE *HandleBuffer;
208 UINTN Index;
209
210 //
211 // Disconnect all
212 //
213 gBS->LocateHandleBuffer (
215 NULL,
216 NULL,
217 &HandleCount,
218 &HandleBuffer
219 );
220 for (Index = 0; Index < HandleCount; Index++) {
221 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
222 }
223
224 if (HandleBuffer != NULL) {
225 FreePool (HandleBuffer);
226 }
227}
228
246 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
247 )
248{
249 EFI_STATUS Status;
250 EFI_HANDLE *Handles;
251 UINTN HandleCount;
252 UINTN Index;
253 EFI_PCI_IO_PROTOCOL *PciIo;
254 UINT8 Class[3];
255 BOOLEAN AtLeastOneConnected;
256
257 //
258 // Check the passed in parameters
259 //
260 if (DevicePath == NULL) {
261 return EFI_INVALID_PARAMETER;
262 }
263
264 if ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) ||
265 ((DevicePathSubType (DevicePath) != MSG_USB_CLASS_DP) && (DevicePathSubType (DevicePath) != MSG_USB_WWID_DP))
266 )
267 {
268 return EFI_INVALID_PARAMETER;
269 }
270
271 //
272 // Find the usb host controller firstly, then connect with the remaining device path
273 //
274 AtLeastOneConnected = FALSE;
275 Status = gBS->LocateHandleBuffer (
277 &gEfiPciIoProtocolGuid,
278 NULL,
279 &HandleCount,
280 &Handles
281 );
282 if (!EFI_ERROR (Status)) {
283 for (Index = 0; Index < HandleCount; Index++) {
284 Status = gBS->HandleProtocol (
285 Handles[Index],
286 &gEfiPciIoProtocolGuid,
287 (VOID **)&PciIo
288 );
289 if (!EFI_ERROR (Status)) {
290 //
291 // Check whether the Pci device is the wanted usb host controller
292 //
293 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
294 if (!EFI_ERROR (Status) &&
295 ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1]))
296 )
297 {
298 Status = gBS->ConnectController (
299 Handles[Index],
300 NULL,
301 DevicePath,
302 FALSE
303 );
304 if (!EFI_ERROR (Status)) {
305 AtLeastOneConnected = TRUE;
306 }
307 }
308 }
309 }
310
311 if (Handles != NULL) {
312 FreePool (Handles);
313 }
314 }
315
316 return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND;
317}
UINT64 UINTN
EFI_STATUS BmConnectUsbShortFormDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmConnect.c:245
EFI_STATUS EFIAPI EfiBootManagerConnectDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect, OUT EFI_HANDLE *MatchingHandle OPTIONAL)
Definition: BmConnect.c:108
VOID EFIAPI EfiBootManagerConnectAll(VOID)
Definition: BmConnect.c:67
VOID EFIAPI EfiBootManagerDisconnectAll(VOID)
Definition: BmConnect.c:202
VOID BmConnectAllDriversToAllControllers(VOID)
Definition: BmConnect.c:19
#define MSG_USB_WWID_DP
Definition: DevicePath.h:467
#define MSG_USB_CLASS_DP
Definition: DevicePath.h:434
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DXE_SERVICES * gDS
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI EfiBootManagerConnectAllDefaultConsoles(VOID)
Definition: BmConsole.c:712
EFI_BOOT_SERVICES * gBS
EFI_TPL EFIAPI EfiGetCurrentTpl(VOID)
Definition: UefiLib.c:375
@ ByProtocol
Definition: UefiSpec.h:1518
@ AllHandles
Definition: UefiSpec.h:1509