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