]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/PlatformBdsDxe/Generic/BootMaint/ConsoleOption.c
add in PlatformBds.inf
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / BootMaint / ConsoleOption.c
1 /*++
2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module Name:
12
13 ConsoleOption.c
14
15 Abstract:
16
17 handles console redirection from boot manager
18
19
20 Revision History
21
22 --*/
23
24 //
25 // Include common header file for this module.
26 //
27 #include "CommonHeader.h"
28
29 #include "BootMaint.h"
30
31 EFI_DEVICE_PATH_PROTOCOL *
32 DevicePathInstanceDup (
33 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
34 );
35
36 EFI_STATUS
37 UpdateComAttributeFromVariable (
38 EFI_DEVICE_PATH_PROTOCOL *DevicePath
39 );
40
41 EFI_STATUS
42 ChangeTerminalDevicePath (
43 EFI_DEVICE_PATH_PROTOCOL *DevicePath,
44 BOOLEAN ChangeTerminal
45 )
46 {
47 EFI_DEVICE_PATH_PROTOCOL *Node;
48 EFI_DEVICE_PATH_PROTOCOL *Node1;
49 ACPI_HID_DEVICE_PATH *Acpi;
50 UART_DEVICE_PATH *Uart;
51 UART_DEVICE_PATH *Uart1;
52 UINTN Com;
53 UINT32 Match;
54 BM_TERMINAL_CONTEXT *NewTerminalContext;
55 BM_MENU_ENTRY *NewMenuEntry;
56
57 Match = EISA_PNP_ID (0x0501);
58 Node = DevicePath;
59 Node = NextDevicePathNode (Node);
60 Com = 0;
61 while (!IsDevicePathEnd (Node)) {
62 if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {
63 Acpi = (ACPI_HID_DEVICE_PATH *) Node;
64 if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
65 CopyMem (&Com, &Acpi->UID, sizeof (UINT32));
66 }
67 }
68
69 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com);
70 if (NULL == NewMenuEntry) {
71 return EFI_NOT_FOUND;
72 }
73
74 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
75 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
76 Uart = (UART_DEVICE_PATH *) Node;
77 CopyMem (
78 &Uart->BaudRate,
79 &NewTerminalContext->BaudRate,
80 sizeof (UINT64)
81 );
82
83 CopyMem (
84 &Uart->DataBits,
85 &NewTerminalContext->DataBits,
86 sizeof (UINT8)
87 );
88
89 CopyMem (
90 &Uart->Parity,
91 &NewTerminalContext->Parity,
92 sizeof (UINT8)
93 );
94
95 CopyMem (
96 &Uart->StopBits,
97 &NewTerminalContext->StopBits,
98 sizeof (UINT8)
99 );
100 //
101 // Change the device path in the ComPort
102 //
103 if (ChangeTerminal) {
104 Node1 = NewTerminalContext->DevicePath;
105 Node1 = NextDevicePathNode (Node1);
106 while (!IsDevicePathEnd (Node1)) {
107 if ((DevicePathType (Node1) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node1) == MSG_UART_DP)) {
108 Uart1 = (UART_DEVICE_PATH *) Node1;
109 CopyMem (
110 &Uart1->BaudRate,
111 &NewTerminalContext->BaudRate,
112 sizeof (UINT64)
113 );
114
115 CopyMem (
116 &Uart1->DataBits,
117 &NewTerminalContext->DataBits,
118 sizeof (UINT8)
119 );
120
121 CopyMem (
122 &Uart1->Parity,
123 &NewTerminalContext->Parity,
124 sizeof (UINT8)
125 );
126
127 CopyMem (
128 &Uart1->StopBits,
129 &NewTerminalContext->StopBits,
130 sizeof (UINT8)
131 );
132 break;
133 }
134 //
135 // end if
136 //
137 Node1 = NextDevicePathNode (Node1);
138 }
139 //
140 // end while
141 //
142 break;
143 }
144 }
145
146 Node = NextDevicePathNode (Node);
147 }
148
149 return EFI_SUCCESS;
150
151 }
152
153 VOID
154 ChangeVariableDevicePath (
155 EFI_DEVICE_PATH_PROTOCOL *DevicePath
156 )
157 {
158 EFI_DEVICE_PATH_PROTOCOL *Node;
159 ACPI_HID_DEVICE_PATH *Acpi;
160 UART_DEVICE_PATH *Uart;
161 UINTN Com;
162 UINT32 Match;
163 BM_TERMINAL_CONTEXT *NewTerminalContext;
164 BM_MENU_ENTRY *NewMenuEntry;
165
166 Match = EISA_PNP_ID (0x0501);
167 Node = DevicePath;
168 Node = NextDevicePathNode (Node);
169 Com = 0;
170 while (!IsDevicePathEnd (Node)) {
171 if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {
172 Acpi = (ACPI_HID_DEVICE_PATH *) Node;
173 if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
174 CopyMem (&Com, &Acpi->UID, sizeof (UINT32));
175 }
176 }
177
178 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
179 NewMenuEntry = BOpt_GetMenuEntry (
180 &TerminalMenu,
181 Com
182 );
183 ASSERT (NewMenuEntry != NULL);
184 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
185 Uart = (UART_DEVICE_PATH *) Node;
186 CopyMem (
187 &Uart->BaudRate,
188 &NewTerminalContext->BaudRate,
189 sizeof (UINT64)
190 );
191
192 CopyMem (
193 &Uart->DataBits,
194 &NewTerminalContext->DataBits,
195 sizeof (UINT8)
196 );
197
198 CopyMem (
199 &Uart->Parity,
200 &NewTerminalContext->Parity,
201 sizeof (UINT8)
202 );
203
204 CopyMem (
205 &Uart->StopBits,
206 &NewTerminalContext->StopBits,
207 sizeof (UINT8)
208 );
209 }
210
211 Node = NextDevicePathNode (Node);
212 }
213
214 return ;
215 }
216
217 BOOLEAN
218 IsTerminalDevicePath (
219 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
220 OUT TYPE_OF_TERMINAL *Termi,
221 OUT UINTN *Com
222 );
223
224 EFI_STATUS
225 LocateSerialIo (
226 VOID
227 )
228 /*++
229
230 Routine Description:
231 Build a list containing all serial devices
232
233 Arguments:
234
235 Returns:
236
237 --*/
238 {
239 UINT8 *Ptr;
240 UINTN Index;
241 UINTN Index2;
242 UINTN NoHandles;
243 EFI_HANDLE *Handles;
244 EFI_STATUS Status;
245 ACPI_HID_DEVICE_PATH *Acpi;
246 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
247 UINT32 Match;
248 EFI_SERIAL_IO_PROTOCOL *SerialIo;
249 EFI_DEVICE_PATH_PROTOCOL *OutDevicePath;
250 EFI_DEVICE_PATH_PROTOCOL *InpDevicePath;
251 EFI_DEVICE_PATH_PROTOCOL *ErrDevicePath;
252 BM_MENU_ENTRY *NewMenuEntry;
253 BM_TERMINAL_CONTEXT *NewTerminalContext;
254 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
255 VENDOR_DEVICE_PATH Vendor;
256 //
257 // Get all handles that have SerialIo protocol installed
258 //
259 InitializeListHead (&TerminalMenu.Head);
260 TerminalMenu.MenuNumber = 0;
261 Status = gBS->LocateHandleBuffer (
262 ByProtocol,
263 &gEfiSerialIoProtocolGuid,
264 NULL,
265 &NoHandles,
266 &Handles
267 );
268 if (EFI_ERROR (Status)) {
269 //
270 // No serial ports present
271 //
272 return EFI_UNSUPPORTED;
273 }
274
275 for (Index = 0; Index < NoHandles; Index++) {
276 //
277 // Check to see whether the handle has DevicePath Protocol installed
278 //
279 gBS->HandleProtocol (
280 Handles[Index],
281 &gEfiDevicePathProtocolGuid,
282 &DevicePath
283 );
284 Ptr = (UINT8 *) DevicePath;
285 while (*Ptr != END_DEVICE_PATH_TYPE) {
286 Ptr++;
287 }
288
289 Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);
290 Acpi = (ACPI_HID_DEVICE_PATH *) Ptr;
291 Match = EISA_PNP_ID (0x0501);
292
293 if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
294 NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);
295 if (!NewMenuEntry) {
296 return EFI_OUT_OF_RESOURCES;
297 }
298
299 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
300 CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));
301 NewTerminalContext->DevicePath = DevicePathInstanceDup (DevicePath);
302 //
303 // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!
304 // coz' the misc data for each platform is not correct, actually it's the device path stored in
305 // datahub which is not completed, so a searching for end of device path will enter a
306 // dead-loop.
307 //
308 NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath);
309 if (NULL == NewMenuEntry->DisplayString) {
310 NewMenuEntry->DisplayString = DevicePathToStr (DevicePath);
311 }
312
313 NewMenuEntry->HelpString = NULL;
314
315 gBS->HandleProtocol (
316 Handles[Index],
317 &gEfiSerialIoProtocolGuid,
318 &SerialIo
319 );
320
321 CopyMem (
322 &NewTerminalContext->BaudRate,
323 &SerialIo->Mode->BaudRate,
324 sizeof (UINT64)
325 );
326
327 CopyMem (
328 &NewTerminalContext->DataBits,
329 &SerialIo->Mode->DataBits,
330 sizeof (UINT8)
331 );
332
333 CopyMem (
334 &NewTerminalContext->Parity,
335 &SerialIo->Mode->Parity,
336 sizeof (UINT8)
337 );
338
339 CopyMem (
340 &NewTerminalContext->StopBits,
341 &SerialIo->Mode->StopBits,
342 sizeof (UINT8)
343 );
344 InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);
345 TerminalMenu.MenuNumber++;
346 }
347 }
348 //
349 // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
350 //
351 OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid);
352 InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid);
353 ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid);
354 if (OutDevicePath) {
355 UpdateComAttributeFromVariable (OutDevicePath);
356 }
357
358 if (InpDevicePath) {
359 UpdateComAttributeFromVariable (InpDevicePath);
360 }
361
362 if (ErrDevicePath) {
363 UpdateComAttributeFromVariable (ErrDevicePath);
364 }
365
366 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
367 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
368 if (NULL == NewMenuEntry) {
369 return EFI_NOT_FOUND;
370 }
371
372 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
373
374 NewTerminalContext->TerminalType = 0;
375 NewTerminalContext->IsConIn = FALSE;
376 NewTerminalContext->IsConOut = FALSE;
377 NewTerminalContext->IsStdErr = FALSE;
378
379 Vendor.Header.Type = MESSAGING_DEVICE_PATH;
380 Vendor.Header.SubType = MSG_VENDOR_DP;
381
382 for (Index2 = 0; Index2 < 4; Index2++) {
383 CopyMem (&Vendor.Guid, &Guid[Index2], sizeof (EFI_GUID));
384 SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
385 NewDevicePath = AppendDevicePathNode (
386 NewTerminalContext->DevicePath,
387 (EFI_DEVICE_PATH_PROTOCOL *) &Vendor
388 );
389 SafeFreePool (NewMenuEntry->HelpString);
390 //
391 // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);
392 // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
393 //
394 NewMenuEntry->HelpString = NULL;
395
396 if (BdsLibMatchDevicePaths (OutDevicePath, NewDevicePath)) {
397 NewTerminalContext->IsConOut = TRUE;
398 NewTerminalContext->TerminalType = (UINT8) Index2;
399 }
400
401 if (BdsLibMatchDevicePaths (InpDevicePath, NewDevicePath)) {
402 NewTerminalContext->IsConIn = TRUE;
403 NewTerminalContext->TerminalType = (UINT8) Index2;
404 }
405
406 if (BdsLibMatchDevicePaths (ErrDevicePath, NewDevicePath)) {
407 NewTerminalContext->IsStdErr = TRUE;
408 NewTerminalContext->TerminalType = (UINT8) Index2;
409 }
410 }
411 }
412
413 return EFI_SUCCESS;
414 }
415
416 EFI_STATUS
417 UpdateComAttributeFromVariable (
418 EFI_DEVICE_PATH_PROTOCOL *DevicePath
419 )
420 /*++
421
422 Routine Description:
423 Update Com Ports attributes from DevicePath
424
425 Arguments:
426 DevicePath - DevicePath that contains Com ports
427
428 Returns:
429
430 --*/
431 {
432 EFI_DEVICE_PATH_PROTOCOL *Node;
433 EFI_DEVICE_PATH_PROTOCOL *SerialNode;
434 ACPI_HID_DEVICE_PATH *Acpi;
435 UART_DEVICE_PATH *Uart;
436 UART_DEVICE_PATH *Uart1;
437 UINT32 Match;
438 UINTN TerminalNumber;
439 BM_MENU_ENTRY *NewMenuEntry;
440 BM_TERMINAL_CONTEXT *NewTerminalContext;
441 UINTN Index;
442
443 Match = EISA_PNP_ID (0x0501);
444 Node = DevicePath;
445 Node = NextDevicePathNode (Node);
446 TerminalNumber = 0;
447 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
448 while (!IsDevicePathEnd (Node)) {
449 if ((DevicePathType (Node) == ACPI_DEVICE_PATH) && (DevicePathSubType (Node) == ACPI_DP)) {
450 Acpi = (ACPI_HID_DEVICE_PATH *) Node;
451 if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
452 CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32));
453 }
454 }
455
456 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
457 Uart = (UART_DEVICE_PATH *) Node;
458 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, TerminalNumber);
459 if (NULL == NewMenuEntry) {
460 return EFI_NOT_FOUND;
461 }
462
463 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
464 CopyMem (
465 &NewTerminalContext->BaudRate,
466 &Uart->BaudRate,
467 sizeof (UINT64)
468 );
469
470 CopyMem (
471 &NewTerminalContext->DataBits,
472 &Uart->DataBits,
473 sizeof (UINT8)
474 );
475
476 CopyMem (
477 &NewTerminalContext->Parity,
478 &Uart->Parity,
479 sizeof (UINT8)
480 );
481
482 CopyMem (
483 &NewTerminalContext->StopBits,
484 &Uart->StopBits,
485 sizeof (UINT8)
486 );
487
488 SerialNode = NewTerminalContext->DevicePath;
489 SerialNode = NextDevicePathNode (SerialNode);
490 while (!IsDevicePathEnd (SerialNode)) {
491 if ((DevicePathType (SerialNode) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (SerialNode) == MSG_UART_DP)) {
492 //
493 // Update following device paths according to
494 // previous acquired uart attributes
495 //
496 Uart1 = (UART_DEVICE_PATH *) SerialNode;
497 CopyMem (
498 &Uart1->BaudRate,
499 &NewTerminalContext->BaudRate,
500 sizeof (UINT64)
501 );
502
503 CopyMem (
504 &Uart1->DataBits,
505 &NewTerminalContext->DataBits,
506 sizeof (UINT8)
507 );
508 CopyMem (
509 &Uart1->Parity,
510 &NewTerminalContext->Parity,
511 sizeof (UINT8)
512 );
513 CopyMem (
514 &Uart1->StopBits,
515 &NewTerminalContext->StopBits,
516 sizeof (UINT8)
517 );
518
519 break;
520 }
521
522 SerialNode = NextDevicePathNode (SerialNode);
523 }
524 //
525 // end while
526 //
527 }
528
529 Node = NextDevicePathNode (Node);
530 }
531 //
532 // end while
533 //
534 }
535
536 return EFI_SUCCESS;
537 }
538
539 EFI_DEVICE_PATH_PROTOCOL *
540 DevicePathInstanceDup (
541 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
542 )
543 /*++
544
545 Routine Description:
546 Function creates a device path data structure that identically matches the
547 device path passed in.
548
549 Arguments:
550 DevPath - A pointer to a device path data structure.
551
552 Returns:
553
554 The new copy of DevPath is created to identically match the input.
555 Otherwise, NULL is returned.
556
557 --*/
558 {
559 EFI_DEVICE_PATH_PROTOCOL *NewDevPath;
560 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
561 EFI_DEVICE_PATH_PROTOCOL *Temp;
562 UINT8 *Ptr;
563 UINTN Size;
564
565 //
566 // get the size of an instance from the input
567 //
568 Temp = DevPath;
569 DevicePathInst = GetNextDevicePathInstance (&Temp, &Size);
570
571 //
572 // Make a copy and set proper end type
573 //
574 NewDevPath = NULL;
575 if (Size) {
576 NewDevPath = AllocateZeroPool (Size);
577 ASSERT (NewDevPath != NULL);
578 }
579
580 if (NewDevPath) {
581 CopyMem (NewDevPath, DevicePathInst, Size);
582 Ptr = (UINT8 *) NewDevPath;
583 Ptr += Size - sizeof (EFI_DEVICE_PATH_PROTOCOL);
584 Temp = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
585 SetDevicePathEndNode (Temp);
586 }
587
588 return NewDevPath;
589 }
590
591 EFI_STATUS
592 GetConsoleMenu (
593 IN UINTN ConsoleMenuType
594 )
595 {
596 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
597 EFI_DEVICE_PATH_PROTOCOL *AllDevicePath;
598 EFI_DEVICE_PATH_PROTOCOL *MultiDevicePath;
599 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
600 UINTN Size;
601 UINTN AllCount;
602 UINTN Index;
603 UINTN Index2;
604 BM_MENU_ENTRY *NewMenuEntry;
605 BM_CONSOLE_CONTEXT *NewConsoleContext;
606 BM_TERMINAL_CONTEXT *NewTerminalContext;
607 TYPE_OF_TERMINAL Terminal;
608 BM_MENU_ENTRY *NewTerminalMenuEntry;
609 UINTN Com;
610 BM_MENU_OPTION *ConsoleMenu;
611
612 DevicePath = NULL;
613 AllDevicePath = NULL;
614 AllCount = 0;
615 switch (ConsoleMenuType) {
616 case BM_CONSOLE_IN_CONTEXT_SELECT:
617 ConsoleMenu = &ConsoleInpMenu;
618 DevicePath = EfiLibGetVariable (
619 L"ConIn",
620 &gEfiGlobalVariableGuid
621 );
622
623 AllDevicePath = EfiLibGetVariable (
624 L"ConInDev",
625 &gEfiGlobalVariableGuid
626 );
627 break;
628
629 case BM_CONSOLE_OUT_CONTEXT_SELECT:
630 ConsoleMenu = &ConsoleOutMenu;
631 DevicePath = EfiLibGetVariable (
632 L"ConOut",
633 &gEfiGlobalVariableGuid
634 );
635
636 AllDevicePath = EfiLibGetVariable (
637 L"ConOutDev",
638 &gEfiGlobalVariableGuid
639 );
640 break;
641
642 case BM_CONSOLE_ERR_CONTEXT_SELECT:
643 ConsoleMenu = &ConsoleErrMenu;
644 DevicePath = EfiLibGetVariable (
645 L"ErrOut",
646 &gEfiGlobalVariableGuid
647 );
648
649 AllDevicePath = EfiLibGetVariable (
650 L"ErrOutDev",
651 &gEfiGlobalVariableGuid
652 );
653 break;
654
655 default:
656 return EFI_UNSUPPORTED;
657 }
658
659 if (NULL == AllDevicePath) {
660 return EFI_NOT_FOUND;
661 }
662
663 InitializeListHead (&ConsoleMenu->Head);
664
665 AllCount = EfiDevicePathInstanceCount (AllDevicePath);
666 ConsoleMenu->MenuNumber = 0;
667 //
668 // Following is menu building up for Console Out Devices
669 //
670 MultiDevicePath = AllDevicePath;
671 Index2 = 0;
672 for (Index = 0; Index < AllCount; Index++) {
673 DevicePathInst = GetNextDevicePathInstance (&MultiDevicePath, &Size);
674
675 NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT);
676 if (NULL == NewMenuEntry) {
677 return EFI_OUT_OF_RESOURCES;
678 }
679
680 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;
681 NewMenuEntry->OptionNumber = Index2;
682
683 NewConsoleContext->DevicePath = DevicePathInstanceDup (DevicePathInst);
684 NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);
685 if (NULL == NewMenuEntry->DisplayString) {
686 NewMenuEntry->DisplayString = DevicePathToStr (NewConsoleContext->DevicePath);
687 }
688
689 NewConsoleContext->IsTerminal = IsTerminalDevicePath (
690 NewConsoleContext->DevicePath,
691 &Terminal,
692 &Com
693 );
694
695 NewConsoleContext->IsActive = BdsLibMatchDevicePaths (
696 DevicePath,
697 NewConsoleContext->DevicePath
698 );
699 NewTerminalMenuEntry = NULL;
700 NewTerminalContext = NULL;
701
702 if (NewConsoleContext->IsTerminal) {
703 BOpt_DestroyMenuEntry (NewMenuEntry);
704 } else {
705 Index2++;
706 ConsoleMenu->MenuNumber++;
707 InsertTailList (&ConsoleMenu->Head, &NewMenuEntry->Link);
708 }
709 }
710
711 return EFI_SUCCESS;
712 }
713
714 EFI_STATUS
715 GetAllConsoles (
716 VOID
717 )
718 /*++
719
720 Routine Description:
721 Build up ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu
722
723 Arguments:
724
725 Returns:
726 EFI_SUCCESS
727 Others
728
729 --*/
730 {
731 GetConsoleMenu (BM_CONSOLE_IN_CONTEXT_SELECT);
732 GetConsoleMenu (BM_CONSOLE_OUT_CONTEXT_SELECT);
733 GetConsoleMenu (BM_CONSOLE_ERR_CONTEXT_SELECT);
734 return EFI_SUCCESS;
735 }
736
737 EFI_STATUS
738 FreeAllConsoles (
739 VOID
740 )
741 /*++
742
743 Routine Description:
744 Free ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu
745
746 Arguments:
747
748 Returns:
749 EFI_SUCCESS
750 Others
751
752 --*/
753 {
754 BOpt_FreeMenu (&ConsoleOutMenu);
755 BOpt_FreeMenu (&ConsoleInpMenu);
756 BOpt_FreeMenu (&ConsoleErrMenu);
757 BOpt_FreeMenu (&TerminalMenu);
758 return EFI_SUCCESS;
759 }
760
761 BOOLEAN
762 IsTerminalDevicePath (
763 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
764 OUT TYPE_OF_TERMINAL *Termi,
765 OUT UINTN *Com
766 )
767 /*++
768
769 Routine Description:
770 Test whether DevicePath is a valid Terminal
771
772 Arguments:
773 DevicePath - DevicePath to be checked
774 Termi - If is terminal, give its type
775 Com - If is Com Port, give its type
776
777 Returns:
778 TRUE - If DevicePath point to a Terminal
779 FALSE
780
781 --*/
782 {
783 UINT8 *Ptr;
784 BOOLEAN IsTerminal;
785 VENDOR_DEVICE_PATH *Vendor;
786 ACPI_HID_DEVICE_PATH *Acpi;
787 UINT32 Match;
788 EFI_GUID TempGuid;
789
790 IsTerminal = FALSE;
791
792 //
793 // Parse the Device Path, should be change later!!!
794 //
795 Ptr = (UINT8 *) DevicePath;
796 while (*Ptr != END_DEVICE_PATH_TYPE) {
797 Ptr++;
798 }
799
800 Ptr = Ptr - sizeof (VENDOR_DEVICE_PATH);
801 Vendor = (VENDOR_DEVICE_PATH *) Ptr;
802
803 //
804 // There are four kinds of Terminal types
805 // check to see whether this devicepath
806 // is one of that type
807 //
808 CopyMem (&TempGuid, &Vendor->Guid, sizeof (EFI_GUID));
809
810 if (CompareGuid (&TempGuid, &Guid[0])) {
811 *Termi = PC_ANSI;
812 IsTerminal = TRUE;
813 } else {
814 if (CompareGuid (&TempGuid, &Guid[1])) {
815 *Termi = VT_100;
816 IsTerminal = TRUE;
817 } else {
818 if (CompareGuid (&TempGuid, &Guid[2])) {
819 *Termi = VT_100_PLUS;
820 IsTerminal = TRUE;
821 } else {
822 if (CompareGuid (&TempGuid, &Guid[3])) {
823 *Termi = VT_UTF8;
824 IsTerminal = TRUE;
825 } else {
826 IsTerminal = FALSE;
827 }
828 }
829 }
830 }
831
832 if (!IsTerminal) {
833 return FALSE;
834 }
835
836 Ptr = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);
837 Acpi = (ACPI_HID_DEVICE_PATH *) Ptr;
838 Match = EISA_PNP_ID (0x0501);
839 if (CompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
840 CopyMem (Com, &Acpi->UID, sizeof (UINT32));
841 } else {
842 return FALSE;
843 }
844
845 return TRUE;
846 }