]>
Commit | Line | Data |
---|---|---|
1d112229 RN |
1 | /** @file |
2 | Library functions which contain all the code to connect console device. | |
3 | ||
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 | |
9 | ||
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. | |
12 | ||
13 | **/ | |
14 | ||
15 | #include "InternalBm.h" | |
16 | ||
17 | CHAR16 *mConVarName[] = { | |
18 | L"ConIn", | |
19 | L"ConOut", | |
20 | L"ErrOut", | |
21 | L"ConInDev", | |
22 | L"ConOutDev", | |
23 | L"ErrOutDev" | |
24 | }; | |
25 | ||
26 | /** | |
27 | Search out the video controller. | |
28 | ||
29 | @return PCI device path of the video controller. | |
30 | **/ | |
31 | EFI_HANDLE | |
32 | BmGetVideoController ( | |
33 | VOID | |
34 | ) | |
35 | { | |
36 | EFI_STATUS Status; | |
37 | UINTN RootBridgeHandleCount; | |
38 | EFI_HANDLE *RootBridgeHandleBuffer; | |
39 | UINTN HandleCount; | |
40 | EFI_HANDLE *HandleBuffer; | |
41 | UINTN RootBridgeIndex; | |
42 | UINTN Index; | |
43 | EFI_HANDLE VideoController; | |
44 | EFI_PCI_IO_PROTOCOL *PciIo; | |
45 | PCI_TYPE00 Pci; | |
46 | ||
47 | // | |
48 | // Make all the PCI_IO protocols show up | |
49 | // | |
50 | Status = gBS->LocateHandleBuffer ( | |
51 | ByProtocol, | |
52 | &gEfiPciRootBridgeIoProtocolGuid, | |
53 | NULL, | |
54 | &RootBridgeHandleCount, | |
55 | &RootBridgeHandleBuffer | |
56 | ); | |
57 | if (EFI_ERROR (Status) || (RootBridgeHandleCount == 0)) { | |
58 | return NULL; | |
59 | } | |
60 | ||
61 | VideoController = NULL; | |
62 | for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) { | |
63 | gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, FALSE); | |
64 | ||
65 | // | |
66 | // Start to check all the pci io to find the first video controller | |
67 | // | |
68 | Status = gBS->LocateHandleBuffer ( | |
69 | ByProtocol, | |
70 | &gEfiPciIoProtocolGuid, | |
71 | NULL, | |
72 | &HandleCount, | |
73 | &HandleBuffer | |
74 | ); | |
75 | if (EFI_ERROR (Status)) { | |
76 | continue; | |
77 | } | |
78 | ||
79 | for (Index = 0; Index < HandleCount; Index++) { | |
80 | Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID **) &PciIo); | |
81 | if (!EFI_ERROR (Status)) { | |
82 | // | |
83 | // Check for all video controller | |
84 | // | |
85 | Status = PciIo->Pci.Read ( | |
86 | PciIo, | |
87 | EfiPciIoWidthUint32, | |
88 | 0, | |
89 | sizeof (Pci) / sizeof (UINT32), | |
90 | &Pci | |
91 | ); | |
92 | if (!EFI_ERROR (Status) && IS_PCI_VGA (&Pci)) { | |
93 | // TODO: use IS_PCI_DISPLAY?? | |
94 | VideoController = HandleBuffer[Index]; | |
95 | break; | |
96 | } | |
97 | } | |
98 | } | |
99 | FreePool (HandleBuffer); | |
100 | ||
101 | if (VideoController != NULL) { | |
102 | break; | |
103 | } | |
104 | } | |
105 | FreePool (RootBridgeHandleBuffer); | |
106 | ||
107 | return VideoController; | |
108 | } | |
109 | ||
110 | /** | |
111 | Query all the children of VideoController and return the device paths of all the | |
112 | children that support GraphicsOutput protocol. | |
113 | ||
114 | @param VideoController PCI handle of video controller. | |
115 | ||
116 | @return Device paths of all the children that support GraphicsOutput protocol. | |
117 | **/ | |
118 | EFI_DEVICE_PATH_PROTOCOL * | |
119 | EFIAPI | |
120 | EfiBootManagerGetGopDevicePath ( | |
121 | IN EFI_HANDLE VideoController | |
122 | ) | |
123 | { | |
124 | UINTN Index; | |
125 | EFI_STATUS Status; | |
126 | EFI_GUID **ProtocolBuffer; | |
127 | UINTN ProtocolBufferCount; | |
128 | UINTN ProtocolIndex; | |
129 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; | |
130 | UINTN EntryCount; | |
131 | EFI_DEVICE_PATH_PROTOCOL *DevicePath; | |
132 | EFI_DEVICE_PATH_PROTOCOL *Next; | |
133 | EFI_DEVICE_PATH_PROTOCOL *Previous; | |
134 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; | |
135 | EFI_DEVICE_PATH_PROTOCOL *GopPool; | |
136 | EFI_DEVICE_PATH_PROTOCOL *ReturnDevicePath; | |
137 | ||
138 | ||
139 | Status = gBS->ProtocolsPerHandle ( | |
140 | VideoController, | |
141 | &ProtocolBuffer, | |
142 | &ProtocolBufferCount | |
143 | ); | |
144 | if (EFI_ERROR (Status)) { | |
145 | return NULL; | |
146 | } | |
147 | ||
148 | GopPool = NULL; | |
149 | ||
150 | for (ProtocolIndex = 0; ProtocolIndex < ProtocolBufferCount; ProtocolIndex++) { | |
151 | Status = gBS->OpenProtocolInformation ( | |
152 | VideoController, | |
153 | ProtocolBuffer[ProtocolIndex], | |
154 | &OpenInfoBuffer, | |
155 | &EntryCount | |
156 | ); | |
157 | if (EFI_ERROR (Status)) { | |
158 | continue; | |
159 | } | |
160 | ||
161 | for (Index = 0; Index < EntryCount; Index++) { | |
162 | // | |
163 | // Query all the children | |
164 | // | |
165 | if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { | |
166 | Status = gBS->OpenProtocol ( | |
167 | OpenInfoBuffer[Index].ControllerHandle, | |
168 | &gEfiDevicePathProtocolGuid, | |
169 | (VOID **) &DevicePath, | |
170 | NULL, | |
171 | NULL, | |
172 | EFI_OPEN_PROTOCOL_GET_PROTOCOL | |
173 | ); | |
174 | if (EFI_ERROR (Status)) { | |
175 | continue; | |
176 | } | |
177 | ||
178 | Previous = NULL; | |
179 | for (Next = DevicePath; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) { | |
180 | Previous = Next; | |
181 | } | |
182 | ASSERT (Previous != NULL); | |
183 | ||
184 | if (DevicePathType (Previous) == ACPI_DEVICE_PATH && DevicePathSubType (Previous) == ACPI_ADR_DP) { | |
185 | Status = gBS->OpenProtocol ( | |
186 | OpenInfoBuffer[Index].ControllerHandle, | |
187 | &gEfiGraphicsOutputProtocolGuid, | |
188 | NULL, | |
189 | NULL, | |
190 | NULL, | |
191 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL | |
192 | ); | |
193 | if (!EFI_ERROR (Status)) { | |
194 | // | |
195 | // Append the device path to GOP pool when there is GOP protocol installed. | |
196 | // | |
197 | TempDevicePath = GopPool; | |
198 | GopPool = AppendDevicePathInstance (GopPool, DevicePath); | |
199 | gBS->FreePool (TempDevicePath); | |
200 | } | |
201 | } | |
202 | ||
203 | if (DevicePathType (Previous) == HARDWARE_DEVICE_PATH && DevicePathSubType (Previous) == HW_CONTROLLER_DP) { | |
204 | // | |
205 | // Recursively look for GOP child in this frame buffer handle | |
206 | // | |
207 | DEBUG ((EFI_D_INFO, "[Bds] Looking for GOP child deeper ... \n")); | |
208 | TempDevicePath = GopPool; | |
209 | ReturnDevicePath = EfiBootManagerGetGopDevicePath (OpenInfoBuffer[Index].ControllerHandle); | |
210 | GopPool = AppendDevicePathInstance (GopPool, ReturnDevicePath); | |
211 | gBS->FreePool (ReturnDevicePath); | |
212 | gBS->FreePool (TempDevicePath); | |
213 | } | |
214 | } | |
215 | } | |
216 | ||
217 | FreePool (OpenInfoBuffer); | |
218 | } | |
219 | ||
220 | FreePool (ProtocolBuffer); | |
221 | ||
222 | return GopPool; | |
223 | } | |
224 | ||
225 | /** | |
226 | Connect the platform active active video controller. | |
227 | ||
228 | @param VideoController PCI handle of video controller. | |
229 | ||
230 | @retval EFI_NOT_FOUND There is no active video controller. | |
231 | @retval EFI_SUCCESS The video controller is connected. | |
232 | **/ | |
233 | EFI_STATUS | |
234 | EFIAPI | |
235 | EfiBootManagerConnectVideoController ( | |
236 | EFI_HANDLE VideoController OPTIONAL | |
237 | ) | |
238 | { | |
239 | EFI_DEVICE_PATH_PROTOCOL *Gop; | |
240 | ||
241 | if (VideoController == NULL) { | |
242 | // | |
243 | // Get the platform vga device | |
244 | // | |
245 | VideoController = BmGetVideoController (); | |
246 | } | |
247 | ||
248 | if (VideoController == NULL) { | |
249 | return EFI_NOT_FOUND; | |
250 | } | |
251 | ||
252 | // | |
253 | // Try to connect the PCI device path, so that GOP dirver could start on this | |
254 | // device and create child handles with GraphicsOutput Protocol installed | |
255 | // on them, then we get device paths of these child handles and select | |
256 | // them as possible console device. | |
257 | // | |
258 | gBS->ConnectController (VideoController, NULL, NULL, FALSE); | |
259 | ||
260 | Gop = EfiBootManagerGetGopDevicePath (VideoController); | |
261 | if (Gop == NULL) { | |
262 | return EFI_NOT_FOUND; | |
263 | } | |
264 | ||
265 | EfiBootManagerUpdateConsoleVariable (ConOut, Gop, NULL); | |
266 | FreePool (Gop); | |
267 | ||
268 | // | |
269 | // Necessary for ConPlatform and ConSplitter driver to start up again after ConOut is updated. | |
270 | // | |
271 | return gBS->ConnectController (VideoController, NULL, NULL, TRUE); | |
272 | } | |
273 | ||
274 | /** | |
275 | Fill console handle in System Table if there are no valid console handle in. | |
276 | ||
277 | Firstly, check the validation of console handle in System Table. If it is invalid, | |
278 | update it by the first console device handle from EFI console variable. | |
279 | ||
280 | @param VarName The name of the EFI console variable. | |
281 | @param ConsoleGuid Specified Console protocol GUID. | |
282 | @param ConsoleHandle On IN, console handle in System Table to be checked. | |
283 | On OUT, new console handle in system table. | |
284 | @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked. | |
285 | On OUT, new console protocol on new console handle in system table. | |
286 | ||
287 | @retval TRUE System Table has been updated. | |
288 | @retval FALSE System Table hasn't been updated. | |
289 | ||
290 | **/ | |
291 | BOOLEAN | |
292 | BmUpdateSystemTableConsole ( | |
293 | IN CHAR16 *VarName, | |
294 | IN EFI_GUID *ConsoleGuid, | |
295 | IN OUT EFI_HANDLE *ConsoleHandle, | |
296 | IN OUT VOID **ProtocolInterface | |
297 | ) | |
298 | { | |
299 | EFI_STATUS Status; | |
300 | UINTN DevicePathSize; | |
301 | EFI_DEVICE_PATH_PROTOCOL *FullDevicePath; | |
302 | EFI_DEVICE_PATH_PROTOCOL *VarConsole; | |
303 | EFI_DEVICE_PATH_PROTOCOL *Instance; | |
304 | VOID *Interface; | |
305 | EFI_HANDLE NewHandle; | |
306 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut; | |
307 | ||
308 | ASSERT (VarName != NULL); | |
309 | ASSERT (ConsoleHandle != NULL); | |
310 | ASSERT (ConsoleGuid != NULL); | |
311 | ASSERT (ProtocolInterface != NULL); | |
312 | ||
313 | if (*ConsoleHandle != NULL) { | |
314 | Status = gBS->HandleProtocol ( | |
315 | *ConsoleHandle, | |
316 | ConsoleGuid, | |
317 | &Interface | |
318 | ); | |
319 | if (Status == EFI_SUCCESS && Interface == *ProtocolInterface) { | |
320 | // | |
321 | // If ConsoleHandle is valid and console protocol on this handle also | |
322 | // also matched, just return. | |
323 | // | |
324 | return FALSE; | |
325 | } | |
326 | } | |
327 | ||
328 | // | |
329 | // Get all possible consoles device path from EFI variable | |
330 | // | |
331 | GetEfiGlobalVariable2 (VarName, (VOID **) &VarConsole, NULL); | |
332 | if (VarConsole == NULL) { | |
333 | // | |
334 | // If there is no any console device, just return. | |
335 | // | |
336 | return FALSE; | |
337 | } | |
338 | ||
339 | FullDevicePath = VarConsole; | |
340 | ||
341 | do { | |
342 | // | |
343 | // Check every instance of the console variable | |
344 | // | |
345 | Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize); | |
346 | if (Instance == NULL) { | |
347 | DEBUG ((EFI_D_ERROR, "[Bds] No valid console instance is found for %s!\n", VarName)); | |
348 | // We should not ASSERT when all the console devices are removed. | |
349 | // ASSERT_EFI_ERROR (EFI_NOT_FOUND); | |
350 | FreePool (FullDevicePath); | |
351 | return FALSE; | |
352 | } | |
353 | ||
354 | // | |
355 | // Find console device handle by device path instance | |
356 | // | |
357 | Status = gBS->LocateDevicePath ( | |
358 | ConsoleGuid, | |
359 | &Instance, | |
360 | &NewHandle | |
361 | ); | |
362 | if (!EFI_ERROR (Status)) { | |
363 | // | |
364 | // Get the console protocol on this console device handle | |
365 | // | |
366 | Status = gBS->HandleProtocol ( | |
367 | NewHandle, | |
368 | ConsoleGuid, | |
369 | &Interface | |
370 | ); | |
371 | if (!EFI_ERROR (Status)) { | |
372 | // | |
373 | // Update new console handle in System Table. | |
374 | // | |
375 | *ConsoleHandle = NewHandle; | |
376 | *ProtocolInterface = Interface; | |
377 | if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) { | |
378 | // | |
379 | // If it is console out device, set console mode 80x25 if current mode is invalid. | |
380 | // | |
381 | TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface; | |
382 | if (TextOut->Mode->Mode == -1) { | |
383 | TextOut->SetMode (TextOut, 0); | |
384 | } | |
385 | } | |
386 | return TRUE; | |
387 | } | |
388 | } | |
389 | ||
390 | } while (Instance != NULL); | |
391 | ||
392 | // | |
393 | // No any available console devcie found. | |
394 | // | |
395 | return FALSE; | |
396 | } | |
397 | ||
398 | /** | |
399 | This function updates the console variable based on ConVarName. It can | |
400 | add or remove one specific console device path from the variable | |
401 | ||
402 | @param ConsoleType ConIn, ConOut, ErrOut, ConInDev, ConOutDev or ErrOutDev. | |
403 | @param CustomizedConDevicePath The console device path to be added to | |
404 | the console variable. Cannot be multi-instance. | |
405 | @param ExclusiveDevicePath The console device path to be removed | |
406 | from the console variable. Cannot be multi-instance. | |
407 | ||
408 | @retval EFI_UNSUPPORTED The added device path is the same as a removed one. | |
409 | @retval EFI_SUCCESS Successfully added or removed the device path from the | |
410 | console variable. | |
411 | @retval others Return status of RT->SetVariable(). | |
412 | ||
413 | **/ | |
414 | EFI_STATUS | |
415 | EFIAPI | |
416 | EfiBootManagerUpdateConsoleVariable ( | |
417 | IN CONSOLE_TYPE ConsoleType, | |
418 | IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath, | |
419 | IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath | |
420 | ) | |
421 | { | |
422 | EFI_STATUS Status; | |
423 | EFI_DEVICE_PATH_PROTOCOL *VarConsole; | |
424 | EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; | |
425 | EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; | |
426 | ||
427 | if (ConsoleType >= sizeof (mConVarName) / sizeof (mConVarName[0])) { | |
428 | return EFI_INVALID_PARAMETER; | |
429 | } | |
430 | ||
431 | // | |
432 | // Notes: check the device path point, here should check | |
433 | // with compare memory | |
434 | // | |
435 | if (CustomizedConDevicePath == ExclusiveDevicePath) { | |
436 | return EFI_UNSUPPORTED; | |
437 | } | |
438 | // | |
439 | // Delete the ExclusiveDevicePath from current default console | |
440 | // | |
441 | GetEfiGlobalVariable2 (mConVarName[ConsoleType], (VOID **) &VarConsole, NULL); | |
442 | // | |
443 | // Initialize NewDevicePath | |
444 | // | |
445 | NewDevicePath = VarConsole; | |
446 | ||
447 | // | |
448 | // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it. | |
449 | // In the end, NewDevicePath is the final device path. | |
450 | // | |
451 | if (ExclusiveDevicePath != NULL && VarConsole != NULL) { | |
452 | NewDevicePath = BmDelPartMatchInstance (VarConsole, ExclusiveDevicePath); | |
453 | } | |
454 | // | |
455 | // Try to append customized device path to NewDevicePath. | |
456 | // | |
457 | if (CustomizedConDevicePath != NULL) { | |
458 | if (!BmMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) { | |
459 | // | |
460 | // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it. | |
461 | // | |
462 | NewDevicePath = BmDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath); | |
463 | // | |
464 | // In the first check, the default console variable will be _ModuleEntryPoint, | |
465 | // just append current customized device path | |
466 | // | |
467 | TempNewDevicePath = NewDevicePath; | |
468 | NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); | |
469 | if (TempNewDevicePath != NULL) { | |
470 | FreePool(TempNewDevicePath); | |
471 | } | |
472 | } | |
473 | } | |
474 | ||
475 | // | |
476 | // Finally, Update the variable of the default console by NewDevicePath | |
477 | // | |
478 | Status = gRT->SetVariable ( | |
479 | mConVarName[ConsoleType], | |
480 | &gEfiGlobalVariableGuid, | |
481 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | |
482 | | ((ConsoleType < ConInDev) ? EFI_VARIABLE_NON_VOLATILE : 0), | |
483 | GetDevicePathSize (NewDevicePath), | |
484 | NewDevicePath | |
485 | ); | |
486 | ||
487 | if (VarConsole == NewDevicePath) { | |
488 | if (VarConsole != NULL) { | |
489 | FreePool(VarConsole); | |
490 | } | |
491 | } else { | |
492 | if (VarConsole != NULL) { | |
493 | FreePool(VarConsole); | |
494 | } | |
495 | if (NewDevicePath != NULL) { | |
496 | FreePool(NewDevicePath); | |
497 | } | |
498 | } | |
499 | ||
500 | return Status; | |
501 | } | |
502 | ||
503 | ||
504 | /** | |
505 | Connect the console device base on the variable ConsoleType. | |
506 | ||
507 | @param ConsoleType ConIn, ConOut or ErrOut. | |
508 | ||
509 | @retval EFI_NOT_FOUND There is not any console devices connected | |
510 | success | |
511 | @retval EFI_SUCCESS Success connect any one instance of the console | |
512 | device path base on the variable ConVarName. | |
513 | ||
514 | **/ | |
515 | EFI_STATUS | |
516 | EFIAPI | |
517 | EfiBootManagerConnectConsoleVariable ( | |
518 | IN CONSOLE_TYPE ConsoleType | |
519 | ) | |
520 | { | |
521 | EFI_STATUS Status; | |
522 | EFI_DEVICE_PATH_PROTOCOL *StartDevicePath; | |
523 | EFI_DEVICE_PATH_PROTOCOL *Instance; | |
524 | EFI_DEVICE_PATH_PROTOCOL *Next; | |
525 | EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath; | |
526 | UINTN Size; | |
527 | BOOLEAN DeviceExist; | |
528 | EFI_HANDLE Handle; | |
529 | ||
530 | if ((ConsoleType != ConIn) && (ConsoleType != ConOut) && (ConsoleType != ErrOut)) { | |
531 | return EFI_INVALID_PARAMETER; | |
532 | } | |
533 | ||
534 | Status = EFI_SUCCESS; | |
535 | DeviceExist = FALSE; | |
536 | Handle = NULL; | |
537 | ||
538 | // | |
539 | // Check if the console variable exist | |
540 | // | |
541 | GetEfiGlobalVariable2 (mConVarName[ConsoleType], (VOID **) &StartDevicePath, NULL); | |
542 | if (StartDevicePath == NULL) { | |
543 | return EFI_UNSUPPORTED; | |
544 | } | |
545 | ||
546 | CopyOfDevicePath = StartDevicePath; | |
547 | do { | |
548 | // | |
549 | // Check every instance of the console variable | |
550 | // | |
551 | Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size); | |
552 | if (Instance == NULL) { | |
553 | FreePool (StartDevicePath); | |
554 | return EFI_UNSUPPORTED; | |
555 | } | |
556 | ||
557 | Next = Instance; | |
558 | while (!IsDevicePathEndType (Next)) { | |
559 | Next = NextDevicePathNode (Next); | |
560 | } | |
561 | ||
562 | SetDevicePathEndNode (Next); | |
563 | // | |
564 | // Connect the USB console | |
565 | // USB console device path is a short-form device path that | |
566 | // starts with the first element being a USB WWID | |
567 | // or a USB Class device path | |
568 | // | |
569 | if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) && | |
570 | ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP) || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)) | |
571 | ) { | |
572 | Status = BmConnectUsbShortFormDevicePath (Instance); | |
573 | if (!EFI_ERROR (Status)) { | |
574 | DeviceExist = TRUE; | |
575 | } | |
576 | } else { | |
577 | for (Next = Instance; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) { | |
578 | if (DevicePathType (Next) == ACPI_DEVICE_PATH && DevicePathSubType (Next) == ACPI_ADR_DP) { | |
579 | break; | |
580 | } else if (DevicePathType (Next) == HARDWARE_DEVICE_PATH && | |
581 | DevicePathSubType (Next) == HW_CONTROLLER_DP && | |
582 | DevicePathType (NextDevicePathNode (Next)) == ACPI_DEVICE_PATH && | |
583 | DevicePathSubType (NextDevicePathNode (Next)) == ACPI_ADR_DP | |
584 | ) { | |
585 | break; | |
586 | } | |
587 | } | |
588 | if (!IsDevicePathEnd (Next)) { | |
589 | // | |
590 | // For GOP device path, start the video driver with NULL remaining device path | |
591 | // | |
592 | SetDevicePathEndNode (Next); | |
593 | Status = EfiBootManagerConnectDevicePath (Instance, &Handle); | |
594 | if (!EFI_ERROR (Status)) { | |
595 | gBS->ConnectController (Handle, NULL, NULL, TRUE); | |
596 | } | |
597 | } else { | |
598 | Status = EfiBootManagerConnectDevicePath (Instance, NULL); | |
599 | } | |
600 | if (EFI_ERROR (Status)) { | |
601 | // | |
602 | // Delete the instance from the console varialbe | |
603 | // | |
604 | EfiBootManagerUpdateConsoleVariable (ConsoleType, NULL, Instance); | |
605 | } else { | |
606 | DeviceExist = TRUE; | |
607 | } | |
608 | } | |
609 | FreePool(Instance); | |
610 | } while (CopyOfDevicePath != NULL); | |
611 | ||
612 | FreePool (StartDevicePath); | |
613 | ||
614 | if (!DeviceExist) { | |
615 | return EFI_NOT_FOUND; | |
616 | } | |
617 | ||
618 | return EFI_SUCCESS; | |
619 | } | |
620 | ||
621 | ||
622 | /** | |
623 | This function will search every input/output device in current system, | |
624 | and make every input/output device as potential console device. | |
625 | **/ | |
626 | VOID | |
627 | EFIAPI | |
628 | EfiBootManagerConnectAllConsoles ( | |
629 | VOID | |
630 | ) | |
631 | { | |
632 | UINTN Index; | |
633 | EFI_DEVICE_PATH_PROTOCOL *ConDevicePath; | |
634 | UINTN HandleCount; | |
635 | EFI_HANDLE *HandleBuffer; | |
636 | ||
637 | Index = 0; | |
638 | HandleCount = 0; | |
639 | HandleBuffer = NULL; | |
640 | ConDevicePath = NULL; | |
641 | ||
642 | // | |
643 | // Update all the console variables | |
644 | // | |
645 | gBS->LocateHandleBuffer ( | |
646 | ByProtocol, | |
647 | &gEfiSimpleTextInProtocolGuid, | |
648 | NULL, | |
649 | &HandleCount, | |
650 | &HandleBuffer | |
651 | ); | |
652 | ||
653 | for (Index = 0; Index < HandleCount; Index++) { | |
654 | gBS->HandleProtocol ( | |
655 | HandleBuffer[Index], | |
656 | &gEfiDevicePathProtocolGuid, | |
657 | (VOID **) &ConDevicePath | |
658 | ); | |
659 | EfiBootManagerUpdateConsoleVariable (ConIn, ConDevicePath, NULL); | |
660 | } | |
661 | ||
662 | if (HandleBuffer != NULL) { | |
663 | FreePool(HandleBuffer); | |
664 | HandleBuffer = NULL; | |
665 | } | |
666 | ||
667 | gBS->LocateHandleBuffer ( | |
668 | ByProtocol, | |
669 | &gEfiSimpleTextOutProtocolGuid, | |
670 | NULL, | |
671 | &HandleCount, | |
672 | &HandleBuffer | |
673 | ); | |
674 | for (Index = 0; Index < HandleCount; Index++) { | |
675 | gBS->HandleProtocol ( | |
676 | HandleBuffer[Index], | |
677 | &gEfiDevicePathProtocolGuid, | |
678 | (VOID **) &ConDevicePath | |
679 | ); | |
680 | EfiBootManagerUpdateConsoleVariable (ConOut, ConDevicePath, NULL); | |
681 | EfiBootManagerUpdateConsoleVariable (ErrOut, ConDevicePath, NULL); | |
682 | } | |
683 | ||
684 | if (HandleBuffer != NULL) { | |
685 | FreePool(HandleBuffer); | |
686 | } | |
687 | ||
688 | // | |
689 | // Connect all console variables | |
690 | // | |
691 | EfiBootManagerConnectAllDefaultConsoles (); | |
692 | } | |
693 | ||
694 | ||
695 | /** | |
696 | This function will connect all the console devices base on the console | |
697 | device variable ConIn, ConOut and ErrOut. | |
698 | **/ | |
699 | VOID | |
700 | EFIAPI | |
701 | EfiBootManagerConnectAllDefaultConsoles ( | |
702 | VOID | |
703 | ) | |
704 | { | |
705 | BOOLEAN SystemTableUpdated; | |
706 | ||
707 | EfiBootManagerConnectConsoleVariable (ConOut); | |
708 | PERF_START (NULL, "ConOutReady", "BDS", 1); | |
709 | PERF_END (NULL, "ConOutReady", "BDS", 0); | |
710 | ||
711 | ||
712 | EfiBootManagerConnectConsoleVariable (ConIn); | |
713 | PERF_START (NULL, "ConInReady", "BDS", 1); | |
714 | PERF_END (NULL, "ConInReady", "BDS", 0); | |
715 | ||
716 | // | |
717 | // The _ModuleEntryPoint err out var is legal. | |
718 | // | |
719 | EfiBootManagerConnectConsoleVariable (ErrOut); | |
720 | PERF_START (NULL, "ErrOutReady", "BDS", 1); | |
721 | PERF_END (NULL, "ErrOutReady", "BDS", 0); | |
722 | ||
723 | SystemTableUpdated = FALSE; | |
724 | // | |
725 | // Fill console handles in System Table if no console device assignd. | |
726 | // | |
727 | if (BmUpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn)) { | |
728 | SystemTableUpdated = TRUE; | |
729 | } | |
730 | if (BmUpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) { | |
731 | SystemTableUpdated = TRUE; | |
732 | } | |
733 | if (BmUpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) { | |
734 | SystemTableUpdated = TRUE; | |
735 | } | |
736 | ||
737 | if (SystemTableUpdated) { | |
738 | // | |
739 | // Update the CRC32 in the EFI System Table header | |
740 | // | |
741 | gST->Hdr.CRC32 = 0; | |
742 | gBS->CalculateCrc32 ( | |
743 | (UINT8 *) &gST->Hdr, | |
744 | gST->Hdr.HeaderSize, | |
745 | &gST->Hdr.CRC32 | |
746 | ); | |
747 | } | |
748 | } |