]>
Commit | Line | Data |
---|---|---|
067ed98a RN |
1 | /** @file\r |
2 | Library functions which contain all the code to connect console device.\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
fad21b7c | 5 | (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
067ed98a RN |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include "InternalBm.h"\r | |
11 | \r | |
12 | CHAR16 *mConVarName[] = {\r | |
13 | L"ConIn",\r | |
14 | L"ConOut",\r | |
15 | L"ErrOut",\r | |
16 | L"ConInDev",\r | |
17 | L"ConOutDev",\r | |
18 | L"ErrOutDev"\r | |
19 | };\r | |
20 | \r | |
21 | /**\r | |
22 | Search out the video controller.\r | |
23 | \r | |
24 | @return PCI device path of the video controller.\r | |
25 | **/\r | |
26 | EFI_HANDLE\r | |
27 | BmGetVideoController (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | EFI_STATUS Status;\r | |
32 | UINTN RootBridgeHandleCount;\r | |
33 | EFI_HANDLE *RootBridgeHandleBuffer;\r | |
34 | UINTN HandleCount;\r | |
35 | EFI_HANDLE *HandleBuffer;\r | |
36 | UINTN RootBridgeIndex;\r | |
37 | UINTN Index;\r | |
38 | EFI_HANDLE VideoController;\r | |
39 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
40 | PCI_TYPE00 Pci;\r | |
41 | \r | |
42 | //\r | |
43 | // Make all the PCI_IO protocols show up\r | |
44 | //\r | |
45 | Status = gBS->LocateHandleBuffer (\r | |
46 | ByProtocol,\r | |
47 | &gEfiPciRootBridgeIoProtocolGuid,\r | |
48 | NULL,\r | |
49 | &RootBridgeHandleCount,\r | |
50 | &RootBridgeHandleBuffer\r | |
51 | );\r | |
52 | if (EFI_ERROR (Status) || (RootBridgeHandleCount == 0)) {\r | |
53 | return NULL;\r | |
54 | }\r | |
55 | \r | |
56 | VideoController = NULL;\r | |
57 | for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) {\r | |
58 | gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, FALSE);\r | |
59 | \r | |
60 | //\r | |
61 | // Start to check all the pci io to find the first video controller\r | |
62 | //\r | |
63 | Status = gBS->LocateHandleBuffer (\r | |
64 | ByProtocol,\r | |
65 | &gEfiPciIoProtocolGuid,\r | |
66 | NULL,\r | |
67 | &HandleCount,\r | |
68 | &HandleBuffer\r | |
69 | );\r | |
70 | if (EFI_ERROR (Status)) {\r | |
71 | continue;\r | |
72 | }\r | |
73 | \r | |
74 | for (Index = 0; Index < HandleCount; Index++) {\r | |
75 | Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID **) &PciIo);\r | |
76 | if (!EFI_ERROR (Status)) {\r | |
77 | //\r | |
78 | // Check for all video controller\r | |
79 | //\r | |
80 | Status = PciIo->Pci.Read (\r | |
81 | PciIo,\r | |
82 | EfiPciIoWidthUint32,\r | |
83 | 0,\r | |
84 | sizeof (Pci) / sizeof (UINT32),\r | |
85 | &Pci\r | |
86 | );\r | |
87 | if (!EFI_ERROR (Status) && IS_PCI_VGA (&Pci)) {\r | |
88 | // TODO: use IS_PCI_DISPLAY??\r | |
89 | VideoController = HandleBuffer[Index];\r | |
90 | break;\r | |
91 | }\r | |
92 | }\r | |
93 | }\r | |
94 | FreePool (HandleBuffer);\r | |
95 | \r | |
96 | if (VideoController != NULL) {\r | |
97 | break;\r | |
98 | }\r | |
99 | }\r | |
100 | FreePool (RootBridgeHandleBuffer);\r | |
d1102dba | 101 | \r |
067ed98a RN |
102 | return VideoController;\r |
103 | }\r | |
104 | \r | |
105 | /**\r | |
d1102dba | 106 | Query all the children of VideoController and return the device paths of all the\r |
067ed98a RN |
107 | children that support GraphicsOutput protocol.\r |
108 | \r | |
109 | @param VideoController PCI handle of video controller.\r | |
110 | \r | |
111 | @return Device paths of all the children that support GraphicsOutput protocol.\r | |
112 | **/\r | |
113 | EFI_DEVICE_PATH_PROTOCOL *\r | |
114 | EFIAPI\r | |
115 | EfiBootManagerGetGopDevicePath (\r | |
116 | IN EFI_HANDLE VideoController\r | |
117 | )\r | |
118 | {\r | |
119 | UINTN Index;\r | |
120 | EFI_STATUS Status;\r | |
121 | EFI_GUID **ProtocolBuffer;\r | |
122 | UINTN ProtocolBufferCount;\r | |
123 | UINTN ProtocolIndex;\r | |
124 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
125 | UINTN EntryCount;\r | |
126 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
127 | EFI_DEVICE_PATH_PROTOCOL *Next;\r | |
128 | EFI_DEVICE_PATH_PROTOCOL *Previous;\r | |
129 | EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r | |
130 | EFI_DEVICE_PATH_PROTOCOL *GopPool;\r | |
131 | EFI_DEVICE_PATH_PROTOCOL *ReturnDevicePath;\r | |
132 | \r | |
133 | \r | |
134 | Status = gBS->ProtocolsPerHandle (\r | |
135 | VideoController,\r | |
136 | &ProtocolBuffer,\r | |
137 | &ProtocolBufferCount\r | |
138 | );\r | |
139 | if (EFI_ERROR (Status)) {\r | |
140 | return NULL;\r | |
141 | }\r | |
142 | \r | |
143 | GopPool = NULL;\r | |
144 | \r | |
145 | for (ProtocolIndex = 0; ProtocolIndex < ProtocolBufferCount; ProtocolIndex++) {\r | |
146 | Status = gBS->OpenProtocolInformation (\r | |
147 | VideoController,\r | |
148 | ProtocolBuffer[ProtocolIndex],\r | |
149 | &OpenInfoBuffer,\r | |
150 | &EntryCount\r | |
151 | );\r | |
152 | if (EFI_ERROR (Status)) {\r | |
153 | continue;\r | |
154 | }\r | |
155 | \r | |
156 | for (Index = 0; Index < EntryCount; Index++) {\r | |
157 | //\r | |
158 | // Query all the children\r | |
159 | //\r | |
160 | if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r | |
161 | Status = gBS->OpenProtocol (\r | |
162 | OpenInfoBuffer[Index].ControllerHandle,\r | |
163 | &gEfiDevicePathProtocolGuid,\r | |
164 | (VOID **) &DevicePath,\r | |
165 | NULL,\r | |
166 | NULL,\r | |
167 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
168 | );\r | |
169 | if (EFI_ERROR (Status)) {\r | |
170 | continue;\r | |
171 | }\r | |
172 | \r | |
173 | Previous = NULL;\r | |
174 | for (Next = DevicePath; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) {\r | |
175 | Previous = Next;\r | |
176 | }\r | |
177 | ASSERT (Previous != NULL);\r | |
178 | \r | |
179 | if (DevicePathType (Previous) == ACPI_DEVICE_PATH && DevicePathSubType (Previous) == ACPI_ADR_DP) {\r | |
180 | Status = gBS->OpenProtocol (\r | |
181 | OpenInfoBuffer[Index].ControllerHandle,\r | |
182 | &gEfiGraphicsOutputProtocolGuid,\r | |
183 | NULL,\r | |
184 | NULL,\r | |
185 | NULL,\r | |
186 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
187 | );\r | |
188 | if (!EFI_ERROR (Status)) {\r | |
189 | //\r | |
190 | // Append the device path to GOP pool when there is GOP protocol installed.\r | |
191 | //\r | |
192 | TempDevicePath = GopPool;\r | |
193 | GopPool = AppendDevicePathInstance (GopPool, DevicePath);\r | |
194 | gBS->FreePool (TempDevicePath);\r | |
195 | }\r | |
196 | }\r | |
197 | \r | |
198 | if (DevicePathType (Previous) == HARDWARE_DEVICE_PATH && DevicePathSubType (Previous) == HW_CONTROLLER_DP) {\r | |
199 | //\r | |
200 | // Recursively look for GOP child in this frame buffer handle\r | |
201 | //\r | |
87000d77 | 202 | DEBUG ((DEBUG_INFO, "[Bds] Looking for GOP child deeper ... \n"));\r |
067ed98a RN |
203 | TempDevicePath = GopPool;\r |
204 | ReturnDevicePath = EfiBootManagerGetGopDevicePath (OpenInfoBuffer[Index].ControllerHandle);\r | |
205 | GopPool = AppendDevicePathInstance (GopPool, ReturnDevicePath);\r | |
206 | gBS->FreePool (ReturnDevicePath);\r | |
207 | gBS->FreePool (TempDevicePath);\r | |
208 | }\r | |
209 | }\r | |
210 | }\r | |
211 | \r | |
212 | FreePool (OpenInfoBuffer);\r | |
213 | }\r | |
214 | \r | |
215 | FreePool (ProtocolBuffer);\r | |
216 | \r | |
217 | return GopPool;\r | |
218 | }\r | |
219 | \r | |
220 | /**\r | |
221 | Connect the platform active active video controller.\r | |
222 | \r | |
223 | @param VideoController PCI handle of video controller.\r | |
224 | \r | |
225 | @retval EFI_NOT_FOUND There is no active video controller.\r | |
226 | @retval EFI_SUCCESS The video controller is connected.\r | |
227 | **/\r | |
228 | EFI_STATUS\r | |
229 | EFIAPI\r | |
230 | EfiBootManagerConnectVideoController (\r | |
231 | EFI_HANDLE VideoController OPTIONAL\r | |
232 | )\r | |
233 | {\r | |
234 | EFI_DEVICE_PATH_PROTOCOL *Gop;\r | |
d1102dba | 235 | \r |
067ed98a RN |
236 | if (VideoController == NULL) {\r |
237 | //\r | |
238 | // Get the platform vga device\r | |
239 | //\r | |
240 | VideoController = BmGetVideoController ();\r | |
241 | }\r | |
d1102dba | 242 | \r |
067ed98a RN |
243 | if (VideoController == NULL) {\r |
244 | return EFI_NOT_FOUND;\r | |
245 | }\r | |
246 | \r | |
247 | //\r | |
3b28e744 | 248 | // Try to connect the PCI device path, so that GOP driver could start on this\r |
067ed98a | 249 | // device and create child handles with GraphicsOutput Protocol installed\r |
d1102dba | 250 | // on them, then we get device paths of these child handles and select\r |
067ed98a RN |
251 | // them as possible console device.\r |
252 | //\r | |
253 | gBS->ConnectController (VideoController, NULL, NULL, FALSE);\r | |
254 | \r | |
255 | Gop = EfiBootManagerGetGopDevicePath (VideoController);\r | |
256 | if (Gop == NULL) {\r | |
257 | return EFI_NOT_FOUND;\r | |
258 | }\r | |
259 | \r | |
260 | EfiBootManagerUpdateConsoleVariable (ConOut, Gop, NULL);\r | |
261 | FreePool (Gop);\r | |
262 | \r | |
263 | //\r | |
264 | // Necessary for ConPlatform and ConSplitter driver to start up again after ConOut is updated.\r | |
265 | //\r | |
266 | return gBS->ConnectController (VideoController, NULL, NULL, TRUE);\r | |
267 | }\r | |
268 | \r | |
269 | /**\r | |
270 | Fill console handle in System Table if there are no valid console handle in.\r | |
271 | \r | |
272 | Firstly, check the validation of console handle in System Table. If it is invalid,\r | |
d1102dba | 273 | update it by the first console device handle from EFI console variable.\r |
067ed98a RN |
274 | \r |
275 | @param VarName The name of the EFI console variable.\r | |
276 | @param ConsoleGuid Specified Console protocol GUID.\r | |
d1102dba | 277 | @param ConsoleHandle On IN, console handle in System Table to be checked.\r |
067ed98a | 278 | On OUT, new console handle in system table.\r |
d1102dba | 279 | @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked.\r |
067ed98a RN |
280 | On OUT, new console protocol on new console handle in system table.\r |
281 | \r | |
282 | @retval TRUE System Table has been updated.\r | |
283 | @retval FALSE System Table hasn't been updated.\r | |
284 | \r | |
285 | **/\r | |
d1102dba | 286 | BOOLEAN\r |
067ed98a RN |
287 | BmUpdateSystemTableConsole (\r |
288 | IN CHAR16 *VarName,\r | |
289 | IN EFI_GUID *ConsoleGuid,\r | |
290 | IN OUT EFI_HANDLE *ConsoleHandle,\r | |
291 | IN OUT VOID **ProtocolInterface\r | |
292 | )\r | |
293 | {\r | |
294 | EFI_STATUS Status;\r | |
295 | UINTN DevicePathSize;\r | |
296 | EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;\r | |
297 | EFI_DEVICE_PATH_PROTOCOL *VarConsole;\r | |
298 | EFI_DEVICE_PATH_PROTOCOL *Instance;\r | |
fad21b7c | 299 | EFI_DEVICE_PATH_PROTOCOL *FullInstance;\r |
067ed98a RN |
300 | VOID *Interface;\r |
301 | EFI_HANDLE NewHandle;\r | |
302 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r | |
303 | \r | |
304 | ASSERT (VarName != NULL);\r | |
305 | ASSERT (ConsoleHandle != NULL);\r | |
306 | ASSERT (ConsoleGuid != NULL);\r | |
307 | ASSERT (ProtocolInterface != NULL);\r | |
308 | \r | |
309 | if (*ConsoleHandle != NULL) {\r | |
310 | Status = gBS->HandleProtocol (\r | |
311 | *ConsoleHandle,\r | |
312 | ConsoleGuid,\r | |
313 | &Interface\r | |
314 | );\r | |
315 | if (Status == EFI_SUCCESS && Interface == *ProtocolInterface) {\r | |
316 | //\r | |
317 | // If ConsoleHandle is valid and console protocol on this handle also\r | |
318 | // also matched, just return.\r | |
319 | //\r | |
320 | return FALSE;\r | |
321 | }\r | |
322 | }\r | |
d1102dba | 323 | \r |
067ed98a RN |
324 | //\r |
325 | // Get all possible consoles device path from EFI variable\r | |
326 | //\r | |
327 | GetEfiGlobalVariable2 (VarName, (VOID **) &VarConsole, NULL);\r | |
328 | if (VarConsole == NULL) {\r | |
329 | //\r | |
330 | // If there is no any console device, just return.\r | |
331 | //\r | |
332 | return FALSE;\r | |
333 | }\r | |
334 | \r | |
335 | FullDevicePath = VarConsole;\r | |
336 | \r | |
337 | do {\r | |
338 | //\r | |
339 | // Check every instance of the console variable\r | |
340 | //\r | |
341 | Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize);\r | |
342 | if (Instance == NULL) {\r | |
87000d77 | 343 | DEBUG ((DEBUG_ERROR, "[Bds] No valid console instance is found for %s!\n", VarName));\r |
067ed98a RN |
344 | // We should not ASSERT when all the console devices are removed.\r |
345 | // ASSERT_EFI_ERROR (EFI_NOT_FOUND);\r | |
346 | FreePool (FullDevicePath);\r | |
347 | return FALSE;\r | |
348 | }\r | |
d1102dba | 349 | \r |
067ed98a RN |
350 | //\r |
351 | // Find console device handle by device path instance\r | |
352 | //\r | |
fad21b7c | 353 | FullInstance = Instance;\r |
067ed98a RN |
354 | Status = gBS->LocateDevicePath (\r |
355 | ConsoleGuid,\r | |
356 | &Instance,\r | |
357 | &NewHandle\r | |
358 | );\r | |
fad21b7c | 359 | FreePool (FullInstance);\r |
067ed98a RN |
360 | if (!EFI_ERROR (Status)) {\r |
361 | //\r | |
362 | // Get the console protocol on this console device handle\r | |
363 | //\r | |
364 | Status = gBS->HandleProtocol (\r | |
365 | NewHandle,\r | |
366 | ConsoleGuid,\r | |
367 | &Interface\r | |
368 | );\r | |
369 | if (!EFI_ERROR (Status)) {\r | |
370 | //\r | |
371 | // Update new console handle in System Table.\r | |
372 | //\r | |
373 | *ConsoleHandle = NewHandle;\r | |
374 | *ProtocolInterface = Interface;\r | |
375 | if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) {\r | |
376 | //\r | |
377 | // If it is console out device, set console mode 80x25 if current mode is invalid.\r | |
378 | //\r | |
379 | TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface;\r | |
380 | if (TextOut->Mode->Mode == -1) {\r | |
381 | TextOut->SetMode (TextOut, 0);\r | |
382 | }\r | |
383 | }\r | |
fad21b7c | 384 | FreePool (FullDevicePath);\r |
067ed98a RN |
385 | return TRUE;\r |
386 | }\r | |
387 | }\r | |
388 | \r | |
389 | } while (Instance != NULL);\r | |
390 | \r | |
391 | //\r | |
392 | // No any available console devcie found.\r | |
393 | //\r | |
fad21b7c | 394 | FreePool (FullDevicePath);\r |
067ed98a RN |
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 | |
f0209935 | 427 | if (ConsoleType >= ARRAY_SIZE (mConVarName)) {\r |
067ed98a RN |
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 | |
d1102dba | 556 | \r |
067ed98a RN |
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 | |
d1102dba | 565 | // USB console device path is a short-form device path that\r |
067ed98a RN |
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 | |
d1102dba | 580 | } else if (DevicePathType (Next) == HARDWARE_DEVICE_PATH &&\r |
067ed98a RN |
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 | |
67e9ab84 | 719 | PERF_EVENT ("ConOutReady");\r |
067ed98a | 720 | \r |
d1102dba | 721 | \r |
067ed98a RN |
722 | Status = EfiBootManagerConnectConsoleVariable (ConIn);\r |
723 | if (!EFI_ERROR (Status)) {\r | |
724 | OneConnected = TRUE;\r | |
725 | }\r | |
67e9ab84 | 726 | PERF_EVENT ("ConInReady");\r |
067ed98a RN |
727 | \r |
728 | Status = EfiBootManagerConnectConsoleVariable (ErrOut);\r | |
729 | if (!EFI_ERROR (Status)) {\r | |
730 | OneConnected = TRUE;\r | |
731 | }\r | |
67e9ab84 | 732 | PERF_EVENT ("ErrOutReady");\r |
067ed98a RN |
733 | \r |
734 | SystemTableUpdated = FALSE;\r | |
735 | //\r | |
736 | // Fill console handles in System Table if no console device assignd.\r | |
737 | //\r | |
738 | if (BmUpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn)) {\r | |
739 | SystemTableUpdated = TRUE;\r | |
740 | }\r | |
741 | if (BmUpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {\r | |
742 | SystemTableUpdated = TRUE;\r | |
743 | }\r | |
744 | if (BmUpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {\r | |
745 | SystemTableUpdated = TRUE;\r | |
746 | }\r | |
747 | \r | |
748 | if (SystemTableUpdated) {\r | |
749 | //\r | |
750 | // Update the CRC32 in the EFI System Table header\r | |
751 | //\r | |
752 | gST->Hdr.CRC32 = 0;\r | |
753 | gBS->CalculateCrc32 (\r | |
754 | (UINT8 *) &gST->Hdr,\r | |
755 | gST->Hdr.HeaderSize,\r | |
756 | &gST->Hdr.CRC32\r | |
757 | );\r | |
758 | }\r | |
759 | \r | |
760 | return OneConnected ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r | |
761 | }\r |