]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Library / BootMaintenanceManagerUiLib / ConsoleOption.c
CommitLineData
4af04335
DB
1/** @file\r
2handles console redirection from boot manager\r
3\r
d1102dba 4Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
4af04335
DB
6\r
7**/\r
8\r
9#include "BootMaintenanceManager.h"\r
10\r
11/**\r
12 Function compares a device path data structure to that of all the nodes of a\r
13 second device path instance.\r
14\r
15 @param Multi A pointer to a multi-instance device path data\r
16 structure.\r
17 @param Single A pointer to a single-instance device path data\r
18 structure.\r
19\r
20 @retval TRUE If the Single device path is contained within Multi device path.\r
21 @retval FALSE The Single device path is not match within Multi device path.\r
22\r
23**/\r
24BOOLEAN\r
25MatchDevicePaths (\r
26 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
27 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
28 )\r
29{\r
30 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
31 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
32 UINTN Size;\r
33\r
1436aea4 34 if ((Multi == NULL) || (Single == NULL)) {\r
4af04335
DB
35 return FALSE;\r
36 }\r
37\r
38 DevicePath = Multi;\r
39 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
40\r
41 //\r
42 // Search for the match of 'Single' in 'Multi'\r
43 //\r
44 while (DevicePathInst != NULL) {\r
45 //\r
46 // If the single device path is found in multiple device paths,\r
47 // return success\r
48 //\r
49 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
50 FreePool (DevicePathInst);\r
51 return TRUE;\r
52 }\r
53\r
54 FreePool (DevicePathInst);\r
55 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
56 }\r
57\r
58 return FALSE;\r
59}\r
60\r
61/**\r
62 Check whether the device path node is ISA Serial Node.\r
63\r
64 @param Acpi Device path node to be checked\r
65\r
66 @retval TRUE It's ISA Serial Node.\r
67 @retval FALSE It's NOT ISA Serial Node.\r
68\r
69**/\r
70BOOLEAN\r
71IsIsaSerialNode (\r
1436aea4 72 IN ACPI_HID_DEVICE_PATH *Acpi\r
4af04335
DB
73 )\r
74{\r
1436aea4
MK
75 return (BOOLEAN)(\r
76 (DevicePathType (Acpi) == ACPI_DEVICE_PATH) &&\r
77 (DevicePathSubType (Acpi) == ACPI_DP) &&\r
78 (ReadUnaligned32 (&Acpi->HID) == EISA_PNP_ID (0x0501))\r
79 );\r
4af04335
DB
80}\r
81\r
82/**\r
83 Update Com Ports attributes from DevicePath\r
84\r
85 @param DevicePath DevicePath that contains Com ports\r
86\r
87 @retval EFI_SUCCESS The update is successful.\r
88\r
89**/\r
90EFI_STATUS\r
91UpdateComAttributeFromVariable (\r
92 EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
93 );\r
94\r
95/**\r
96 Update the multi-instance device path of Terminal Device based on\r
d1102dba 97 the global TerminalMenu. If ChangeTernimal is TRUE, the terminal\r
4af04335
DB
98 device path in the Terminal Device in TerminalMenu is also updated.\r
99\r
100 @param DevicePath The multi-instance device path.\r
d1102dba 101 @param ChangeTerminal TRUE, then device path in the Terminal Device\r
4af04335
DB
102 in TerminalMenu is also updated; FALSE, no update.\r
103\r
104 @return EFI_SUCCESS The function completes successfully.\r
105\r
106**/\r
107EFI_STATUS\r
108ChangeTerminalDevicePath (\r
109 IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
110 IN BOOLEAN ChangeTerminal\r
111 )\r
112{\r
113 EFI_DEVICE_PATH_PROTOCOL *Node;\r
114 EFI_DEVICE_PATH_PROTOCOL *Node1;\r
115 ACPI_HID_DEVICE_PATH *Acpi;\r
116 UART_DEVICE_PATH *Uart;\r
117 UART_DEVICE_PATH *Uart1;\r
118 UINTN Com;\r
119 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
120 BM_MENU_ENTRY *NewMenuEntry;\r
121\r
1436aea4
MK
122 Node = DevicePath;\r
123 Node = NextDevicePathNode (Node);\r
124 Com = 0;\r
4af04335 125 while (!IsDevicePathEnd (Node)) {\r
1436aea4 126 Acpi = (ACPI_HID_DEVICE_PATH *)Node;\r
4af04335
DB
127 if (IsIsaSerialNode (Acpi)) {\r
128 CopyMem (&Com, &Acpi->UID, sizeof (UINT32));\r
129 }\r
130\r
131 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com);\r
132\r
1436aea4 133 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335 134 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
1436aea4 135 Uart = (UART_DEVICE_PATH *)Node;\r
4af04335
DB
136 CopyMem (\r
137 &Uart->BaudRate,\r
138 &NewTerminalContext->BaudRate,\r
139 sizeof (UINT64)\r
140 );\r
141\r
142 CopyMem (\r
143 &Uart->DataBits,\r
144 &NewTerminalContext->DataBits,\r
145 sizeof (UINT8)\r
146 );\r
147\r
148 CopyMem (\r
149 &Uart->Parity,\r
150 &NewTerminalContext->Parity,\r
151 sizeof (UINT8)\r
152 );\r
153\r
154 CopyMem (\r
155 &Uart->StopBits,\r
156 &NewTerminalContext->StopBits,\r
157 sizeof (UINT8)\r
158 );\r
159 //\r
160 // Change the device path in the ComPort\r
161 //\r
162 if (ChangeTerminal) {\r
163 Node1 = NewTerminalContext->DevicePath;\r
164 Node1 = NextDevicePathNode (Node1);\r
165 while (!IsDevicePathEnd (Node1)) {\r
166 if ((DevicePathType (Node1) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node1) == MSG_UART_DP)) {\r
1436aea4 167 Uart1 = (UART_DEVICE_PATH *)Node1;\r
4af04335
DB
168 CopyMem (\r
169 &Uart1->BaudRate,\r
170 &NewTerminalContext->BaudRate,\r
171 sizeof (UINT64)\r
172 );\r
173\r
174 CopyMem (\r
175 &Uart1->DataBits,\r
176 &NewTerminalContext->DataBits,\r
177 sizeof (UINT8)\r
178 );\r
179\r
180 CopyMem (\r
181 &Uart1->Parity,\r
182 &NewTerminalContext->Parity,\r
183 sizeof (UINT8)\r
184 );\r
185\r
186 CopyMem (\r
187 &Uart1->StopBits,\r
188 &NewTerminalContext->StopBits,\r
189 sizeof (UINT8)\r
190 );\r
191 break;\r
192 }\r
1436aea4 193\r
4af04335
DB
194 //\r
195 // end if\r
196 //\r
197 Node1 = NextDevicePathNode (Node1);\r
198 }\r
1436aea4 199\r
4af04335
DB
200 //\r
201 // end while\r
202 //\r
203 break;\r
204 }\r
205 }\r
206\r
207 Node = NextDevicePathNode (Node);\r
208 }\r
209\r
210 return EFI_SUCCESS;\r
4af04335
DB
211}\r
212\r
213/**\r
214 Update the device path that describing a terminal device\r
215 based on the new BaudRate, Data Bits, parity and Stop Bits\r
216 set.\r
217\r
218 @param DevicePath terminal device's path\r
219\r
220**/\r
221VOID\r
222ChangeVariableDevicePath (\r
223 IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
224 )\r
225{\r
226 EFI_DEVICE_PATH_PROTOCOL *Node;\r
227 ACPI_HID_DEVICE_PATH *Acpi;\r
228 UART_DEVICE_PATH *Uart;\r
229 UINTN Com;\r
230 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
231 BM_MENU_ENTRY *NewMenuEntry;\r
232\r
1436aea4
MK
233 Node = DevicePath;\r
234 Node = NextDevicePathNode (Node);\r
235 Com = 0;\r
4af04335 236 while (!IsDevicePathEnd (Node)) {\r
1436aea4 237 Acpi = (ACPI_HID_DEVICE_PATH *)Node;\r
4af04335
DB
238 if (IsIsaSerialNode (Acpi)) {\r
239 CopyMem (&Com, &Acpi->UID, sizeof (UINT32));\r
240 }\r
241\r
242 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
243 NewMenuEntry = BOpt_GetMenuEntry (\r
1436aea4
MK
244 &TerminalMenu,\r
245 Com\r
246 );\r
4af04335 247 ASSERT (NewMenuEntry != NULL);\r
1436aea4
MK
248 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
249 Uart = (UART_DEVICE_PATH *)Node;\r
4af04335
DB
250 CopyMem (\r
251 &Uart->BaudRate,\r
252 &NewTerminalContext->BaudRate,\r
253 sizeof (UINT64)\r
254 );\r
255\r
256 CopyMem (\r
257 &Uart->DataBits,\r
258 &NewTerminalContext->DataBits,\r
259 sizeof (UINT8)\r
260 );\r
261\r
262 CopyMem (\r
263 &Uart->Parity,\r
264 &NewTerminalContext->Parity,\r
265 sizeof (UINT8)\r
266 );\r
267\r
268 CopyMem (\r
269 &Uart->StopBits,\r
270 &NewTerminalContext->StopBits,\r
271 sizeof (UINT8)\r
272 );\r
273 }\r
274\r
275 Node = NextDevicePathNode (Node);\r
276 }\r
277}\r
278\r
279/**\r
280 Retrieve ACPI UID of UART from device path\r
281\r
282 @param Handle The handle for the UART device.\r
283 @param AcpiUid The ACPI UID on output.\r
284\r
285 @retval TRUE Find valid UID from device path\r
286 @retval FALSE Can't find\r
287\r
288**/\r
289BOOLEAN\r
290RetrieveUartUid (\r
1436aea4
MK
291 IN EFI_HANDLE Handle,\r
292 IN OUT UINT32 *AcpiUid\r
4af04335
DB
293 )\r
294{\r
295 EFI_STATUS Status;\r
296 ACPI_HID_DEVICE_PATH *Acpi;\r
297 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
298\r
299 Status = gBS->HandleProtocol (\r
300 Handle,\r
301 &gEfiDevicePathProtocolGuid,\r
1436aea4 302 (VOID **)&DevicePath\r
4af04335
DB
303 );\r
304 if (EFI_ERROR (Status)) {\r
305 return FALSE;\r
306 }\r
307\r
308 Acpi = NULL;\r
1436aea4 309 for ( ; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
4af04335
DB
310 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (DevicePath) == MSG_UART_DP)) {\r
311 break;\r
312 }\r
1436aea4 313\r
4af04335
DB
314 //\r
315 // Acpi points to the node before the Uart node\r
316 //\r
1436aea4 317 Acpi = (ACPI_HID_DEVICE_PATH *)DevicePath;\r
4af04335
DB
318 }\r
319\r
320 if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {\r
321 if (AcpiUid != NULL) {\r
322 CopyMem (AcpiUid, &Acpi->UID, sizeof (UINT32));\r
323 }\r
1436aea4 324\r
4af04335
DB
325 return TRUE;\r
326 } else {\r
327 return FALSE;\r
328 }\r
329}\r
330\r
331/**\r
332 Sort Uart handles array with Acpi->UID from low to high.\r
333\r
334 @param Handles EFI_SERIAL_IO_PROTOCOL handle buffer\r
335 @param NoHandles EFI_SERIAL_IO_PROTOCOL handle count\r
336**/\r
337VOID\r
338SortedUartHandle (\r
1436aea4
MK
339 IN EFI_HANDLE *Handles,\r
340 IN UINTN NoHandles\r
4af04335
DB
341 )\r
342{\r
343 UINTN Index1;\r
344 UINTN Index2;\r
345 UINTN Position;\r
346 UINT32 AcpiUid1;\r
347 UINT32 AcpiUid2;\r
348 UINT32 TempAcpiUid;\r
349 EFI_HANDLE TempHandle;\r
350\r
351 for (Index1 = 0; Index1 < NoHandles-1; Index1++) {\r
352 if (!RetrieveUartUid (Handles[Index1], &AcpiUid1)) {\r
353 continue;\r
354 }\r
1436aea4 355\r
4af04335
DB
356 TempHandle = Handles[Index1];\r
357 Position = Index1;\r
358 TempAcpiUid = AcpiUid1;\r
359\r
360 for (Index2 = Index1+1; Index2 < NoHandles; Index2++) {\r
361 if (!RetrieveUartUid (Handles[Index2], &AcpiUid2)) {\r
362 continue;\r
363 }\r
1436aea4 364\r
4af04335
DB
365 if (AcpiUid2 < TempAcpiUid) {\r
366 TempAcpiUid = AcpiUid2;\r
367 TempHandle = Handles[Index2];\r
368 Position = Index2;\r
369 }\r
370 }\r
1436aea4 371\r
4af04335
DB
372 Handles[Position] = Handles[Index1];\r
373 Handles[Index1] = TempHandle;\r
374 }\r
375}\r
376\r
377/**\r
378 Test whether DevicePath is a valid Terminal\r
379\r
380\r
381 @param DevicePath DevicePath to be checked\r
382 @param Termi If DevicePath is valid Terminal, terminal type is returned.\r
383 @param Com If DevicePath is valid Terminal, Com Port type is returned.\r
384\r
385 @retval TRUE If DevicePath point to a Terminal.\r
386 @retval FALSE If DevicePath does not point to a Terminal.\r
387\r
388**/\r
389BOOLEAN\r
390IsTerminalDevicePath (\r
1436aea4
MK
391 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
392 OUT TYPE_OF_TERMINAL *Termi,\r
393 OUT UINTN *Com\r
4af04335
DB
394 );\r
395\r
396/**\r
397 Build a list containing all serial devices.\r
398\r
399\r
400 @retval EFI_SUCCESS The function complete successfully.\r
401 @retval EFI_UNSUPPORTED No serial ports present.\r
402\r
403**/\r
404EFI_STATUS\r
405LocateSerialIo (\r
406 VOID\r
407 )\r
408{\r
409 UINTN Index;\r
410 UINTN Index2;\r
411 UINTN NoHandles;\r
412 EFI_HANDLE *Handles;\r
413 EFI_STATUS Status;\r
414 ACPI_HID_DEVICE_PATH *Acpi;\r
415 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
416 EFI_SERIAL_IO_PROTOCOL *SerialIo;\r
417 EFI_DEVICE_PATH_PROTOCOL *Node;\r
418 EFI_DEVICE_PATH_PROTOCOL *OutDevicePath;\r
419 EFI_DEVICE_PATH_PROTOCOL *InpDevicePath;\r
420 EFI_DEVICE_PATH_PROTOCOL *ErrDevicePath;\r
421 BM_MENU_ENTRY *NewMenuEntry;\r
422 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
423 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
424 VENDOR_DEVICE_PATH Vendor;\r
425\r
426 //\r
427 // Get all handles that have SerialIo protocol installed\r
428 //\r
429 InitializeListHead (&TerminalMenu.Head);\r
430 TerminalMenu.MenuNumber = 0;\r
1436aea4
MK
431 Status = gBS->LocateHandleBuffer (\r
432 ByProtocol,\r
433 &gEfiSerialIoProtocolGuid,\r
434 NULL,\r
435 &NoHandles,\r
436 &Handles\r
437 );\r
4af04335
DB
438 if (EFI_ERROR (Status)) {\r
439 //\r
440 // No serial ports present\r
441 //\r
442 return EFI_UNSUPPORTED;\r
443 }\r
444\r
445 //\r
446 // Sort Uart handles array with Acpi->UID from low to high\r
447 // then Terminal menu can be built from low Acpi->UID to high Acpi->UID\r
448 //\r
449 SortedUartHandle (Handles, NoHandles);\r
450\r
451 for (Index = 0; Index < NoHandles; Index++) {\r
452 //\r
453 // Check to see whether the handle has DevicePath Protocol installed\r
454 //\r
455 gBS->HandleProtocol (\r
1436aea4
MK
456 Handles[Index],\r
457 &gEfiDevicePathProtocolGuid,\r
458 (VOID **)&DevicePath\r
459 );\r
4af04335
DB
460\r
461 Acpi = NULL;\r
462 for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {\r
463 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
464 break;\r
465 }\r
1436aea4 466\r
4af04335
DB
467 //\r
468 // Acpi points to the node before Uart node\r
469 //\r
1436aea4 470 Acpi = (ACPI_HID_DEVICE_PATH *)Node;\r
4af04335
DB
471 }\r
472\r
473 if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {\r
474 NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);\r
475 if (NewMenuEntry == NULL) {\r
476 FreePool (Handles);\r
477 return EFI_OUT_OF_RESOURCES;\r
478 }\r
479\r
1436aea4 480 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335
DB
481 CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));\r
482 NewTerminalContext->DevicePath = DuplicateDevicePath (DevicePath);\r
483 //\r
484 // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!\r
485 // coz' the misc data for each platform is not correct, actually it's the device path stored in\r
486 // datahub which is not completed, so a searching for end of device path will enter a\r
487 // dead-loop.\r
488 //\r
489 NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath);\r
490 if (NULL == NewMenuEntry->DisplayString) {\r
491 NewMenuEntry->DisplayString = UiDevicePathToStr (DevicePath);\r
492 }\r
493\r
494 NewMenuEntry->HelpString = NULL;\r
495\r
496 NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);\r
497\r
498 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;\r
499\r
500 gBS->HandleProtocol (\r
1436aea4
MK
501 Handles[Index],\r
502 &gEfiSerialIoProtocolGuid,\r
503 (VOID **)&SerialIo\r
504 );\r
4af04335
DB
505\r
506 CopyMem (\r
507 &NewTerminalContext->BaudRate,\r
508 &SerialIo->Mode->BaudRate,\r
509 sizeof (UINT64)\r
510 );\r
511\r
512 CopyMem (\r
513 &NewTerminalContext->DataBits,\r
514 &SerialIo->Mode->DataBits,\r
515 sizeof (UINT8)\r
516 );\r
517\r
518 CopyMem (\r
519 &NewTerminalContext->Parity,\r
520 &SerialIo->Mode->Parity,\r
521 sizeof (UINT8)\r
522 );\r
523\r
524 CopyMem (\r
525 &NewTerminalContext->StopBits,\r
526 &SerialIo->Mode->StopBits,\r
527 sizeof (UINT8)\r
528 );\r
529 InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);\r
530 TerminalMenu.MenuNumber++;\r
531 }\r
532 }\r
1436aea4 533\r
4af04335
DB
534 if (Handles != NULL) {\r
535 FreePool (Handles);\r
536 }\r
537\r
538 //\r
539 // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var\r
540 //\r
1436aea4
MK
541 GetEfiGlobalVariable2 (L"ConOut", (VOID **)&OutDevicePath, NULL);\r
542 GetEfiGlobalVariable2 (L"ConIn", (VOID **)&InpDevicePath, NULL);\r
543 GetEfiGlobalVariable2 (L"ErrOut", (VOID **)&ErrDevicePath, NULL);\r
4af04335
DB
544 if (OutDevicePath != NULL) {\r
545 UpdateComAttributeFromVariable (OutDevicePath);\r
546 }\r
547\r
548 if (InpDevicePath != NULL) {\r
549 UpdateComAttributeFromVariable (InpDevicePath);\r
550 }\r
551\r
552 if (ErrDevicePath != NULL) {\r
553 UpdateComAttributeFromVariable (ErrDevicePath);\r
554 }\r
555\r
556 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
557 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
558 if (NULL == NewMenuEntry) {\r
559 return EFI_NOT_FOUND;\r
560 }\r
561\r
1436aea4 562 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335 563\r
1436aea4
MK
564 NewTerminalContext->TerminalType = 0;\r
565 NewTerminalContext->IsConIn = FALSE;\r
566 NewTerminalContext->IsConOut = FALSE;\r
567 NewTerminalContext->IsStdErr = FALSE;\r
4af04335 568\r
1436aea4
MK
569 Vendor.Header.Type = MESSAGING_DEVICE_PATH;\r
570 Vendor.Header.SubType = MSG_VENDOR_DP;\r
4af04335 571\r
6eeeb288 572 for (Index2 = 0; Index2 < (ARRAY_SIZE (TerminalTypeGuid)); Index2++) {\r
4af04335
DB
573 CopyMem (&Vendor.Guid, &TerminalTypeGuid[Index2], sizeof (EFI_GUID));\r
574 SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));\r
575 NewDevicePath = AppendDevicePathNode (\r
576 NewTerminalContext->DevicePath,\r
1436aea4 577 (EFI_DEVICE_PATH_PROTOCOL *)&Vendor\r
4af04335
DB
578 );\r
579 if (NewMenuEntry->HelpString != NULL) {\r
580 FreePool (NewMenuEntry->HelpString);\r
581 }\r
1436aea4 582\r
4af04335
DB
583 //\r
584 // NewMenuEntry->HelpString = UiDevicePathToStr (NewDevicePath);\r
585 // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;\r
586 //\r
587 NewMenuEntry->HelpString = NULL;\r
588\r
589 NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);\r
590\r
591 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;\r
592\r
593 if (MatchDevicePaths (OutDevicePath, NewDevicePath)) {\r
1436aea4
MK
594 NewTerminalContext->IsConOut = TRUE;\r
595 NewTerminalContext->TerminalType = (UINT8)Index2;\r
4af04335
DB
596 }\r
597\r
598 if (MatchDevicePaths (InpDevicePath, NewDevicePath)) {\r
1436aea4
MK
599 NewTerminalContext->IsConIn = TRUE;\r
600 NewTerminalContext->TerminalType = (UINT8)Index2;\r
4af04335
DB
601 }\r
602\r
603 if (MatchDevicePaths (ErrDevicePath, NewDevicePath)) {\r
1436aea4
MK
604 NewTerminalContext->IsStdErr = TRUE;\r
605 NewTerminalContext->TerminalType = (UINT8)Index2;\r
4af04335
DB
606 }\r
607 }\r
608 }\r
609\r
610 return EFI_SUCCESS;\r
611}\r
612\r
613/**\r
614 Update Com Ports attributes from DevicePath\r
615\r
616 @param DevicePath DevicePath that contains Com ports\r
617\r
618 @retval EFI_SUCCESS The update is successful.\r
619 @retval EFI_NOT_FOUND Can not find specific menu entry\r
620**/\r
621EFI_STATUS\r
622UpdateComAttributeFromVariable (\r
623 EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
624 )\r
625{\r
626 EFI_DEVICE_PATH_PROTOCOL *Node;\r
627 EFI_DEVICE_PATH_PROTOCOL *SerialNode;\r
628 ACPI_HID_DEVICE_PATH *Acpi;\r
629 UART_DEVICE_PATH *Uart;\r
630 UART_DEVICE_PATH *Uart1;\r
631 UINTN TerminalNumber;\r
632 BM_MENU_ENTRY *NewMenuEntry;\r
633 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
634 UINTN Index;\r
635\r
1436aea4
MK
636 Node = DevicePath;\r
637 Node = NextDevicePathNode (Node);\r
638 TerminalNumber = 0;\r
4af04335
DB
639 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
640 while (!IsDevicePathEnd (Node)) {\r
1436aea4 641 Acpi = (ACPI_HID_DEVICE_PATH *)Node;\r
4af04335
DB
642 if (IsIsaSerialNode (Acpi)) {\r
643 CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32));\r
644 }\r
645\r
646 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
1436aea4
MK
647 Uart = (UART_DEVICE_PATH *)Node;\r
648 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, TerminalNumber);\r
4af04335
DB
649 if (NULL == NewMenuEntry) {\r
650 return EFI_NOT_FOUND;\r
651 }\r
652\r
1436aea4 653 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335
DB
654 CopyMem (\r
655 &NewTerminalContext->BaudRate,\r
656 &Uart->BaudRate,\r
657 sizeof (UINT64)\r
658 );\r
659\r
660 CopyMem (\r
661 &NewTerminalContext->DataBits,\r
662 &Uart->DataBits,\r
663 sizeof (UINT8)\r
664 );\r
665\r
666 CopyMem (\r
667 &NewTerminalContext->Parity,\r
668 &Uart->Parity,\r
669 sizeof (UINT8)\r
670 );\r
671\r
672 CopyMem (\r
673 &NewTerminalContext->StopBits,\r
674 &Uart->StopBits,\r
675 sizeof (UINT8)\r
676 );\r
677\r
1436aea4
MK
678 SerialNode = NewTerminalContext->DevicePath;\r
679 SerialNode = NextDevicePathNode (SerialNode);\r
4af04335
DB
680 while (!IsDevicePathEnd (SerialNode)) {\r
681 if ((DevicePathType (SerialNode) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (SerialNode) == MSG_UART_DP)) {\r
682 //\r
683 // Update following device paths according to\r
684 // previous acquired uart attributes\r
685 //\r
1436aea4 686 Uart1 = (UART_DEVICE_PATH *)SerialNode;\r
4af04335
DB
687 CopyMem (\r
688 &Uart1->BaudRate,\r
689 &NewTerminalContext->BaudRate,\r
690 sizeof (UINT64)\r
691 );\r
692\r
693 CopyMem (\r
694 &Uart1->DataBits,\r
695 &NewTerminalContext->DataBits,\r
696 sizeof (UINT8)\r
697 );\r
698 CopyMem (\r
699 &Uart1->Parity,\r
700 &NewTerminalContext->Parity,\r
701 sizeof (UINT8)\r
702 );\r
703 CopyMem (\r
704 &Uart1->StopBits,\r
705 &NewTerminalContext->StopBits,\r
706 sizeof (UINT8)\r
707 );\r
708\r
709 break;\r
710 }\r
711\r
712 SerialNode = NextDevicePathNode (SerialNode);\r
713 }\r
1436aea4 714\r
4af04335
DB
715 //\r
716 // end while\r
717 //\r
718 }\r
719\r
720 Node = NextDevicePathNode (Node);\r
721 }\r
1436aea4 722\r
4af04335
DB
723 //\r
724 // end while\r
725 //\r
726 }\r
727\r
728 return EFI_SUCCESS;\r
729}\r
730\r
731/**\r
732 Build up Console Menu based on types passed in. The type can\r
733 be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT\r
734 and BM_CONSOLE_ERR_CONTEXT_SELECT.\r
735\r
736 @param ConsoleMenuType Can be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT\r
737 and BM_CONSOLE_ERR_CONTEXT_SELECT.\r
738\r
739 @retval EFI_UNSUPPORTED The type passed in is not in the 3 types defined.\r
d1102dba 740 @retval EFI_NOT_FOUND If the EFI Variable defined in UEFI spec with name "ConOutDev",\r
4af04335
DB
741 "ConInDev" or "ConErrDev" doesn't exists.\r
742 @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operations.\r
743 @retval EFI_SUCCESS Function completes successfully.\r
744\r
745**/\r
746EFI_STATUS\r
747GetConsoleMenu (\r
1436aea4 748 IN UINTN ConsoleMenuType\r
4af04335
DB
749 )\r
750{\r
751 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
752 EFI_DEVICE_PATH_PROTOCOL *AllDevicePath;\r
753 EFI_DEVICE_PATH_PROTOCOL *MultiDevicePath;\r
754 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
755 UINTN Size;\r
756 UINTN AllCount;\r
757 UINTN Index;\r
758 UINTN Index2;\r
759 BM_MENU_ENTRY *NewMenuEntry;\r
760 BM_CONSOLE_CONTEXT *NewConsoleContext;\r
761 TYPE_OF_TERMINAL Terminal;\r
762 UINTN Com;\r
763 BM_MENU_OPTION *ConsoleMenu;\r
764\r
765 DevicePath = NULL;\r
766 AllDevicePath = NULL;\r
767 AllCount = 0;\r
768 switch (ConsoleMenuType) {\r
1436aea4
MK
769 case BM_CONSOLE_IN_CONTEXT_SELECT:\r
770 ConsoleMenu = &ConsoleInpMenu;\r
771 GetEfiGlobalVariable2 (L"ConIn", (VOID **)&DevicePath, NULL);\r
772 GetEfiGlobalVariable2 (L"ConInDev", (VOID **)&AllDevicePath, NULL);\r
773 break;\r
774\r
775 case BM_CONSOLE_OUT_CONTEXT_SELECT:\r
776 ConsoleMenu = &ConsoleOutMenu;\r
777 GetEfiGlobalVariable2 (L"ConOut", (VOID **)&DevicePath, NULL);\r
778 GetEfiGlobalVariable2 (L"ConOutDev", (VOID **)&AllDevicePath, NULL);\r
779 break;\r
780\r
781 case BM_CONSOLE_ERR_CONTEXT_SELECT:\r
782 ConsoleMenu = &ConsoleErrMenu;\r
783 GetEfiGlobalVariable2 (L"ErrOut", (VOID **)&DevicePath, NULL);\r
784 GetEfiGlobalVariable2 (L"ErrOutDev", (VOID **)&AllDevicePath, NULL);\r
785 break;\r
786\r
787 default:\r
788 return EFI_UNSUPPORTED;\r
4af04335
DB
789 }\r
790\r
791 if (NULL == AllDevicePath) {\r
792 return EFI_NOT_FOUND;\r
793 }\r
794\r
795 InitializeListHead (&ConsoleMenu->Head);\r
796\r
797 AllCount = EfiDevicePathInstanceCount (AllDevicePath);\r
798 ConsoleMenu->MenuNumber = 0;\r
799 //\r
800 // Following is menu building up for Console Devices selected.\r
801 //\r
802 MultiDevicePath = AllDevicePath;\r
803 Index2 = 0;\r
804 for (Index = 0; Index < AllCount; Index++) {\r
1436aea4 805 DevicePathInst = GetNextDevicePathInstance (&MultiDevicePath, &Size);\r
4af04335 806\r
1436aea4 807 NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT);\r
4af04335
DB
808 if (NULL == NewMenuEntry) {\r
809 return EFI_OUT_OF_RESOURCES;\r
810 }\r
811\r
1436aea4
MK
812 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;\r
813 NewMenuEntry->OptionNumber = Index2;\r
4af04335
DB
814\r
815 NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst);\r
816 ASSERT (NewConsoleContext->DevicePath != NULL);\r
1436aea4 817 NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);\r
4af04335
DB
818 if (NULL == NewMenuEntry->DisplayString) {\r
819 NewMenuEntry->DisplayString = UiDevicePathToStr (NewConsoleContext->DevicePath);\r
820 }\r
821\r
822 NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);\r
823\r
824 if (NULL == NewMenuEntry->HelpString) {\r
825 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;\r
826 } else {\r
827 NewMenuEntry->HelpStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL);\r
828 }\r
829\r
830 NewConsoleContext->IsTerminal = IsTerminalDevicePath (\r
831 NewConsoleContext->DevicePath,\r
832 &Terminal,\r
833 &Com\r
834 );\r
835\r
836 NewConsoleContext->IsActive = MatchDevicePaths (\r
837 DevicePath,\r
838 NewConsoleContext->DevicePath\r
839 );\r
840\r
841 if (NewConsoleContext->IsTerminal) {\r
842 BOpt_DestroyMenuEntry (NewMenuEntry);\r
843 } else {\r
844 Index2++;\r
845 ConsoleMenu->MenuNumber++;\r
846 InsertTailList (&ConsoleMenu->Head, &NewMenuEntry->Link);\r
847 }\r
848 }\r
849\r
850 return EFI_SUCCESS;\r
851}\r
852\r
853/**\r
854 Build up ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu\r
855\r
856 @retval EFI_SUCCESS The function always complete successfully.\r
857\r
858**/\r
859EFI_STATUS\r
860GetAllConsoles (\r
861 VOID\r
862 )\r
863{\r
864 GetConsoleMenu (BM_CONSOLE_IN_CONTEXT_SELECT);\r
865 GetConsoleMenu (BM_CONSOLE_OUT_CONTEXT_SELECT);\r
866 GetConsoleMenu (BM_CONSOLE_ERR_CONTEXT_SELECT);\r
867 return EFI_SUCCESS;\r
868}\r
869\r
870/**\r
871 Free ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu\r
872\r
873 @retval EFI_SUCCESS The function always complete successfully.\r
874**/\r
875EFI_STATUS\r
876FreeAllConsoles (\r
877 VOID\r
878 )\r
879{\r
880 BOpt_FreeMenu (&ConsoleOutMenu);\r
881 BOpt_FreeMenu (&ConsoleInpMenu);\r
882 BOpt_FreeMenu (&ConsoleErrMenu);\r
883 BOpt_FreeMenu (&TerminalMenu);\r
884 return EFI_SUCCESS;\r
885}\r
886\r
887/**\r
888 Test whether DevicePath is a valid Terminal\r
889\r
890\r
891 @param DevicePath DevicePath to be checked\r
892 @param Termi If DevicePath is valid Terminal, terminal type is returned.\r
893 @param Com If DevicePath is valid Terminal, Com Port type is returned.\r
894\r
895 @retval TRUE If DevicePath point to a Terminal.\r
896 @retval FALSE If DevicePath does not point to a Terminal.\r
897\r
898**/\r
899BOOLEAN\r
900IsTerminalDevicePath (\r
1436aea4
MK
901 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
902 OUT TYPE_OF_TERMINAL *Termi,\r
903 OUT UINTN *Com\r
4af04335
DB
904 )\r
905{\r
906 BOOLEAN IsTerminal;\r
907 EFI_DEVICE_PATH_PROTOCOL *Node;\r
908 VENDOR_DEVICE_PATH *Vendor;\r
909 UART_DEVICE_PATH *Uart;\r
910 ACPI_HID_DEVICE_PATH *Acpi;\r
590c9d58 911 UINTN Index;\r
4af04335
DB
912\r
913 IsTerminal = FALSE;\r
914\r
915 Uart = NULL;\r
916 Vendor = NULL;\r
917 Acpi = NULL;\r
918 for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {\r
919 //\r
920 // Vendor points to the node before the End node\r
921 //\r
1436aea4 922 Vendor = (VENDOR_DEVICE_PATH *)Node;\r
4af04335
DB
923\r
924 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {\r
1436aea4 925 Uart = (UART_DEVICE_PATH *)Node;\r
4af04335
DB
926 }\r
927\r
928 if (Uart == NULL) {\r
929 //\r
930 // Acpi points to the node before the UART node\r
931 //\r
1436aea4 932 Acpi = (ACPI_HID_DEVICE_PATH *)Node;\r
4af04335
DB
933 }\r
934 }\r
935\r
1436aea4
MK
936 if ((Vendor == NULL) ||\r
937 (DevicePathType (Vendor) != MESSAGING_DEVICE_PATH) ||\r
938 (DevicePathSubType (Vendor) != MSG_VENDOR_DP) ||\r
939 (Uart == NULL))\r
940 {\r
4af04335
DB
941 return FALSE;\r
942 }\r
943\r
944 //\r
590c9d58 945 // There are 9 kinds of Terminal types\r
4af04335
DB
946 // check to see whether this devicepath\r
947 // is one of that type\r
948 //\r
590c9d58
ZG
949 for (Index = 0; Index < ARRAY_SIZE (TerminalTypeGuid); Index++) {\r
950 if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[Index])) {\r
1436aea4 951 *Termi = Index;\r
590c9d58
ZG
952 IsTerminal = TRUE;\r
953 break;\r
4af04335
DB
954 }\r
955 }\r
956\r
590c9d58
ZG
957 if (Index == ARRAY_SIZE (TerminalTypeGuid)) {\r
958 IsTerminal = FALSE;\r
959 }\r
960\r
4af04335
DB
961 if (!IsTerminal) {\r
962 return FALSE;\r
963 }\r
964\r
965 if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {\r
966 CopyMem (Com, &Acpi->UID, sizeof (UINT32));\r
967 } else {\r
968 return FALSE;\r
969 }\r
970\r
971 return TRUE;\r
972}\r
973\r
974/**\r
975 Get mode number according to column and row\r
976\r
977 @param CallbackData The BMM context data.\r
978**/\r
979VOID\r
980GetConsoleOutMode (\r
1436aea4 981 IN BMM_CALLBACK_DATA *CallbackData\r
4af04335
DB
982 )\r
983{\r
1436aea4
MK
984 UINTN Col;\r
985 UINTN Row;\r
986 UINTN CurrentCol;\r
987 UINTN CurrentRow;\r
988 UINTN Mode;\r
989 UINTN MaxMode;\r
990 EFI_STATUS Status;\r
4af04335
DB
991 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
992\r
1436aea4
MK
993 ConOut = gST->ConOut;\r
994 MaxMode = (UINTN)(ConOut->Mode->MaxMode);\r
4af04335
DB
995\r
996 CurrentCol = PcdGet32 (PcdSetupConOutColumn);\r
997 CurrentRow = PcdGet32 (PcdSetupConOutRow);\r
998 for (Mode = 0; Mode < MaxMode; Mode++) {\r
999 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);\r
1436aea4
MK
1000 if (!EFI_ERROR (Status)) {\r
1001 if ((CurrentCol == Col) && (CurrentRow == Row)) {\r
1002 CallbackData->BmmFakeNvData.ConsoleOutMode = (UINT16)Mode;\r
4af04335
DB
1003 break;\r
1004 }\r
1005 }\r
1006 }\r
1007}\r
1008\r
1009/**\r
1010\r
1011 Initialize console input device check box to ConsoleInCheck[MAX_MENU_NUMBER]\r
1012 in BMM_FAKE_NV_DATA structure.\r
1013\r
1014 @param CallbackData The BMM context data.\r
1015\r
d1102dba
LG
1016**/\r
1017VOID\r
4af04335 1018GetConsoleInCheck (\r
1436aea4 1019 IN BMM_CALLBACK_DATA *CallbackData\r
4af04335
DB
1020 )\r
1021{\r
1436aea4
MK
1022 UINT16 Index;\r
1023 BM_MENU_ENTRY *NewMenuEntry;\r
1024 UINT8 *ConInCheck;\r
1025 BM_CONSOLE_CONTEXT *NewConsoleContext;\r
1026 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
4af04335
DB
1027\r
1028 ASSERT (CallbackData != NULL);\r
1029\r
1030 ConInCheck = &CallbackData->BmmFakeNvData.ConsoleInCheck[0];\r
1031 for (Index = 0; ((Index < ConsoleInpMenu.MenuNumber) && \\r
1436aea4
MK
1032 (Index < MAX_MENU_NUMBER)); Index++)\r
1033 {\r
4af04335 1034 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleInpMenu, Index);\r
1436aea4 1035 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335
DB
1036 ConInCheck[Index] = NewConsoleContext->IsActive;\r
1037 }\r
d508fe87
DB
1038\r
1039 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
1436aea4
MK
1040 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
1041 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
d508fe87
DB
1042 ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER);\r
1043 ConInCheck[Index + ConsoleInpMenu.MenuNumber] = NewTerminalContext->IsConIn;\r
1044 }\r
4af04335
DB
1045}\r
1046\r
1047/**\r
1048\r
1049 Initialize console output device check box to ConsoleOutCheck[MAX_MENU_NUMBER]\r
1050 in BMM_FAKE_NV_DATA structure.\r
1051\r
1052 @param CallbackData The BMM context data.\r
1053\r
d1102dba
LG
1054**/\r
1055VOID\r
4af04335 1056GetConsoleOutCheck (\r
1436aea4 1057 IN BMM_CALLBACK_DATA *CallbackData\r
4af04335
DB
1058 )\r
1059{\r
1436aea4
MK
1060 UINT16 Index;\r
1061 BM_MENU_ENTRY *NewMenuEntry;\r
1062 UINT8 *ConOutCheck;\r
1063 BM_CONSOLE_CONTEXT *NewConsoleContext;\r
1064 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
d508fe87 1065\r
4af04335
DB
1066 ASSERT (CallbackData != NULL);\r
1067 ConOutCheck = &CallbackData->BmmFakeNvData.ConsoleOutCheck[0];\r
1068 for (Index = 0; ((Index < ConsoleOutMenu.MenuNumber) && \\r
1436aea4
MK
1069 (Index < MAX_MENU_NUMBER)); Index++)\r
1070 {\r
1071 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleOutMenu, Index);\r
1072 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335
DB
1073 ConOutCheck[Index] = NewConsoleContext->IsActive;\r
1074 }\r
d508fe87
DB
1075\r
1076 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
1436aea4
MK
1077 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
1078 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
d508fe87
DB
1079 ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER);\r
1080 ConOutCheck[Index + ConsoleOutMenu.MenuNumber] = NewTerminalContext->IsConOut;\r
1081 }\r
4af04335
DB
1082}\r
1083\r
1084/**\r
1085\r
1086 Initialize standard error output device check box to ConsoleErrCheck[MAX_MENU_NUMBER]\r
1087 in BMM_FAKE_NV_DATA structure.\r
1088\r
1089 @param CallbackData The BMM context data.\r
1090\r
d1102dba
LG
1091**/\r
1092VOID\r
4af04335 1093GetConsoleErrCheck (\r
1436aea4 1094 IN BMM_CALLBACK_DATA *CallbackData\r
4af04335
DB
1095 )\r
1096{\r
1436aea4
MK
1097 UINT16 Index;\r
1098 BM_MENU_ENTRY *NewMenuEntry;\r
1099 UINT8 *ConErrCheck;\r
1100 BM_CONSOLE_CONTEXT *NewConsoleContext;\r
1101 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
4af04335
DB
1102\r
1103 ASSERT (CallbackData != NULL);\r
1104 ConErrCheck = &CallbackData->BmmFakeNvData.ConsoleErrCheck[0];\r
1105 for (Index = 0; ((Index < ConsoleErrMenu.MenuNumber) && \\r
1436aea4
MK
1106 (Index < MAX_MENU_NUMBER)); Index++)\r
1107 {\r
1108 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleErrMenu, Index);\r
1109 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;\r
4af04335
DB
1110 ConErrCheck[Index] = NewConsoleContext->IsActive;\r
1111 }\r
d508fe87
DB
1112\r
1113 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
1436aea4
MK
1114 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
1115 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
d508fe87
DB
1116 ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER);\r
1117 ConErrCheck[Index + ConsoleErrMenu.MenuNumber] = NewTerminalContext->IsStdErr;\r
1118 }\r
4af04335
DB
1119}\r
1120\r
1121/**\r
1122\r
1123 Initialize terminal attributes (baudrate, data rate, stop bits, parity and terminal type)\r
1124 to BMM_FAKE_NV_DATA structure.\r
1125\r
1126 @param CallbackData The BMM context data.\r
1127\r
1128**/\r
d1102dba 1129VOID\r
4af04335 1130GetTerminalAttribute (\r
1436aea4 1131 IN BMM_CALLBACK_DATA *CallbackData\r
4af04335
DB
1132 )\r
1133{\r
1134 BMM_FAKE_NV_DATA *CurrentFakeNVMap;\r
1135 BM_MENU_ENTRY *NewMenuEntry;\r
d1102dba
LG
1136 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
1137 UINT16 TerminalIndex;\r
4af04335
DB
1138 UINT8 AttributeIndex;\r
1139\r
1140 ASSERT (CallbackData != NULL);\r
1141\r
d1102dba 1142 CurrentFakeNVMap = &CallbackData->BmmFakeNvData;\r
4af04335 1143 for (TerminalIndex = 0; ((TerminalIndex < TerminalMenu.MenuNumber) && \\r
1436aea4
MK
1144 (TerminalIndex < MAX_MENU_NUMBER)); TerminalIndex++)\r
1145 {\r
1146 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, TerminalIndex);\r
1147 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;\r
1148 for (AttributeIndex = 0; AttributeIndex < sizeof (BaudRateList) / sizeof (BaudRateList[0]); AttributeIndex++) {\r
1149 if (NewTerminalContext->BaudRate == (UINT64)(BaudRateList[AttributeIndex].Value)) {\r
4af04335
DB
1150 NewTerminalContext->BaudRateIndex = AttributeIndex;\r
1151 break;\r
1152 }\r
1153 }\r
1436aea4 1154\r
6eeeb288 1155 for (AttributeIndex = 0; AttributeIndex < ARRAY_SIZE (DataBitsList); AttributeIndex++) {\r
1436aea4 1156 if (NewTerminalContext->DataBits == (UINT64)(DataBitsList[AttributeIndex].Value)) {\r
4af04335
DB
1157 NewTerminalContext->DataBitsIndex = AttributeIndex;\r
1158 break;\r
1159 }\r
d1102dba 1160 }\r
4af04335 1161\r
6eeeb288 1162 for (AttributeIndex = 0; AttributeIndex < ARRAY_SIZE (ParityList); AttributeIndex++) {\r
1436aea4 1163 if (NewTerminalContext->Parity == (UINT64)(ParityList[AttributeIndex].Value)) {\r
4af04335
DB
1164 NewTerminalContext->ParityIndex = AttributeIndex;\r
1165 break;\r
1166 }\r
1167 }\r
1168\r
6eeeb288 1169 for (AttributeIndex = 0; AttributeIndex < ARRAY_SIZE (StopBitsList); AttributeIndex++) {\r
1436aea4 1170 if (NewTerminalContext->StopBits == (UINT64)(StopBitsList[AttributeIndex].Value)) {\r
4af04335
DB
1171 NewTerminalContext->StopBitsIndex = AttributeIndex;\r
1172 break;\r
1173 }\r
1174 }\r
1436aea4 1175\r
4af04335
DB
1176 CurrentFakeNVMap->COMBaudRate[TerminalIndex] = NewTerminalContext->BaudRateIndex;\r
1177 CurrentFakeNVMap->COMDataRate[TerminalIndex] = NewTerminalContext->DataBitsIndex;\r
1178 CurrentFakeNVMap->COMStopBits[TerminalIndex] = NewTerminalContext->StopBitsIndex;\r
d1102dba 1179 CurrentFakeNVMap->COMParity[TerminalIndex] = NewTerminalContext->ParityIndex;\r
4af04335
DB
1180 CurrentFakeNVMap->COMTerminalType[TerminalIndex] = NewTerminalContext->TerminalType;\r
1181 CurrentFakeNVMap->COMFlowControl[TerminalIndex] = NewTerminalContext->FlowControl;\r
1182 }\r
1183}\r