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