summaryrefslogtreecommitdiff
path: root/Core/EM/Terminal/TerminalSetup.c
blob: 312c0f1620d0ac6a120cd0b5324a315536d0e1dd (plain)
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
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
//****************************************************************************
//****************************************************************************
//**                                                                        **
//**             (C)Copyright 1985-20014, American Megatrends, Inc.          **
//**                                                                        **
//**                          All Rights Reserved.                          **
//**                                                                        **
//**             5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093          **
//**                                                                        **
//**                          Phone (770)-246-8600                          **
//**                                                                        **
//****************************************************************************
//****************************************************************************
// $Header: /Alaska/BIN/Modules/Terminal/TerminalSetup.c 68    5/29/14 5:20a Deepthins $
//
// $Revision: 68 $
//
// $Date: 5/29/14 5:20a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Modules/Terminal/TerminalSetup.c $
// 
// 68    5/29/14 5:20a Deepthins
// [TAG]  		EIP166561
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	Runtime attribute set for the some of the variables used by
// terminal driver.
// [RootCause]  	Runtime attribute set for the some of the variables used
// by terminal driver.
// [Solution]  	Runtime attribute is removed
// [Files]  		TerminalSetup.c
// 
// 67    3/17/14 12:16a Anbuprakashp
// [TAG]  		EIP156273
// [Category]  	Improvement
// [Description]  	Avoid Build issue happened in Non english version of
// the OS with Serial Redirection label 4.6.3_Terminal_53
// [Files]  		Terminal.sd,TerminalSetup.c
// 
// 66    9/04/13 3:27a Anbuprakashp
// [TAG]  		EIP134648
// [Category]  	Bug Fix
// [Severity]  	Minor
// [Symptom]  	Build error occurs in Sharkbay platform if tokens
// "TOTAL_SIO_SERIAL_PORTS" and "TOTAL_PCI_SERIAL_PORTS" are set to 0
// [RootCause]  	TerminalSetup.c file Status Variable Initialization is
// missing.Terminal.sd file, Condition (TOTAL_SERIAL_PORTS > 0) need to be
// added to avoid build error.
// [Solution]  	Terminal.sd file, Condition (TOTAL_SERIAL_PORTS > 0) added
// to avoid build error.
// Status variable initialzed properly.
// [Files]  		Terminal.sd,TerminalSetup.c
// 
// 65    8/21/13 1:23a Anbuprakashp
// [TAG]  		EIP131785
// [Category]  	Bug Fix
// [Severity]  	Minor
// [Symptom]  	Serial Redirection PCI COM port function numbers are
// changing randomly for every reboot
// [RootCause]  	COM port number and its associated PCI Function numbers
// are
// changing due to the funtion (ValidatePciSerialNvram) in TerminalSetup.c
// file of the SerialRedirection module.Here, It fail to make particular
// PCI COM port function number to Zero.
// As it wrongly comparing device path for the PCI com port.
// 
// [Solution]  	PCI serial COM port's Device Path comparing condition
// commented.
// [Files]  		TerminalSetup.c
// 
// 64    5/27/13 6:34a Rameshr
// [TAG]  		EIP121329
// [Category]  	Improvement
// [Description]  	Serial Mouse Detection added based on the SDL token and
// by default kept disabled
// 
// [Files]  		SerialIo.c, TerminalSetup.c , Terminal.sdl
// 
// 63    5/02/13 9:27a Kapilporwal
// [TAG]  		EIP117486
// [Description]  	CppCheck error in Terminal label 4.6.3_Terminal_50
// [Files]  		SerialIo.c, Terminal.c, TerminalSetup.c,
// TerminalSimpleTextOut.c
// 
// 62    2/11/13 3:00a Rameshr
// [TAG]  		EIP113629
// [Category]  	New Feature
// [Description]  	Terminal driver support for ctrl+key(ASCII Control
// Char) combinations
// [Files]  		Terminal.sdl, TerminalSetup.c, TerminalSimpleTextIn.c
// 
// 61    6/29/12 5:29a Srilathasc
// [TAG]  		EIP93519 
// [Category]  	Improvement
// [Description]  	make hardware flow control maximum re-try count as SDL
// token.
// [Files]  		Terminal.sdl, TerminalSetup.c, SerialIo.c
// 
// 60    3/30/12 12:16a Rajeshms
// [TAG]  		EIP86477 
// [Category]  	Improvement
// [Description]  	PuttyKeyPad value is returned as non-zero(PUTTY_VT100)
// from GetSetupValuesForTerminal() if there is any error in that
// function.
// [Files]  		TerminalSetup.c
// 
// 59    3/29/12 11:58p Rajeshms
// [TAG]  		EIP84341
// [Category]  	Improvement
// [Description]  	Added Separate PCI_UART_INPUT_CLOCK token for setting
// the Clock for PCI Serial UART.
// [Files]  		Terminal.sdl, TerminalSetup.c, SerialIo.c, LegacySredir.c,
// LegacySredir_Setup.c
// 
// 58    12/12/11 6:53a Rajeshms
// [TAG]  		EIP71636
// [Category]  	New Feature
// [Description]  	Implement the AMI_SERIAL_PROTOCOL for non-generic PCI
// Serial Device.
// [Files]  		AmiSerial.c, AmiSerial.sdl, AmiSerial.mak, AmiSerial.chm,
// AmiSerial.dxs, AmiSerial.cif, Terminal.c, SerialIo.c, TerminalSetup.c,
// InitTerminalStrings.c, TerminalSetupVar.h, Terminal.cif,
// TerminalAmiSerial.h, LegacySredir_Setup.c
// 
// 57    11/03/11 4:47a Rameshr
// [TAG]  		EIP73026
// [Category]  	Improvement
// [Description]  	SetNvramVariable used on line 1039, conditionally not
// set
// [Files]  		TerminalSetup.c
// 
// 56    10/19/11 6:42a Rajeshms
// [TAG]  		EIP71973
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	ASCII Control characters that are used to display graphics
// characters are not  redirected to remote if Putty/teraterm application
// is used.
// [RootCause]  	Putty/Teraterm application does not use ASCII control
// characters as Printable characters. 
// [Solution]  	DONT_SEND_ASCII_CONTROL_PRINTABLE_CHARACTERS token has
// been created, if disabled it will not send the ASCII control
// characters.
// [Files]  		Terminal.sdl, TerminalSetup.c, TerminalSimpleTextOut.c
// 
// 55    9/20/11 3:05a Rajeshms
// [TAG]  		EIP70320
// [Category]  	Bug Fix
// [Severity]  	Critical
// [Symptom]  	SPCR table is not created with EFI_SPECIFICATION_VERSION
// 0x2000A
// [RootCause]  	Comport was returned as 0xff from
// GetAcpiSpcrTableValues() as the PORT number is zero indexed after
// EFI_SPECIFICATION_VERSION 0x2000A.
// [Solution]  	The comport number is not subtracted with 1 if
// EFI_SPECIFICATION_VERSION is equal to greater  than0x2000A
// [Files]  		Terminal.sd, TerminalSetup.c
// 
// 54    8/29/11 6:26a Rameshr
// [TAG] - EIP 55335
// [Category]- IMPROVEMENT
// [Description]- Add optional code to clear keyboard buffer at
// ReadyToBoot in Terminal driver
// [Files] - Terminal.c , Terminal.h, Terminal.sdl, TerminalSetup.c
// 
// 53    7/13/11 2:47a Rajeshms
// [TAG]- EIP 36616
// [Category]- New Feature
// [Description]- Add Setup option for Various Putty keyPad support in
// Terminal driver.
// [Files]- Terminal.c, Terminal.h, Terminal.sd, Terminal.sdl,
// Terminal.uni, TerminalBoard.h, TerminalSetup.c, TerminalSimpleTextIn.c
// 
// 52    5/19/11 1:58a Rameshr
// [TAG] - EIP 59741 
// [Category]- BUG FIX
// [Severity]- Minor
// [Symptom] - System hangs if the Serial port doesn't work 
// [RootCause]- Serial Port says valid, but when we try to write, Terminal
// Holding Register never gets Empty.
// [Solution] - Added Error Count when the maximum error count reached,
// SerialIoWrite has been stopped
// [Files] - SerialIo.c, Terminal.sdl , TerminalSetup.c
// 
// 51    4/29/11 5:04a Rameshr
// [TAG] - EIP 54870 
// [Category]- BUG FIX
// [Severity]- Major
// [Symptom] - Legacy Console Redirection doesn't work on 2nd PCI Serial
// Port 
// [RootCause]- Terminal creats the same Nvram variable name for all the
// PCI Serial devices 
// [Solution] - Created seperate Nvram Variable name for each PCI serial
// devices Ahci recovery driver shutdown code exectued only when the
// Recovery from Ahci driver started 
// [Files] - TerminalSetup.c
// 
// 50    4/12/11 4:31a Rameshr
// [TAG]- EIP 57688
// [Category]- New Feature
// [Description]- Add Setup option for Vt-UTF8 combo key support in
// terminal driver 
// [Files]- Terminal.c, Terminal.h, Terminal.sd, Terminal.sdl ,
// Terminal.uni, Terminalboard.h, TerminalSetup.c, TerminalSimpletextin.c
// 
// 49    3/02/11 3:14a Rameshr
// [TAG]- EIP 54313
// [Category]-IMPROVEMENT
// [Description]- Terminal driver Getvariable calls assumed to have valid
// values. Added code to return the error code when there is an failure in
// the getvariable call. 
// [Files]- TerminalSetup.c, InitTerminalString.c
// 
// 48    3/02/11 3:07a Rameshr
// [TAG]- EIP 54526
// [Category]-IMPROVEMENT
// [Description]- PCI serial MMIO device width support added through SDL
// token 
// [Files]- SerialIo.c , TerminalSetup.c , Terminal.sdl
// 
// 47    2/07/11 12:55a Rameshr
// [TAG] - EIP 53292
// [Category]- BUG FIX
// [Severity]- Minor
// [Symptom] - CPU Exception D in Terminal when enabling more than 1
// Serial Port.
// [RootCause]- ComPort value is not initilized , that returns junk value
// causing the invalid exection.
// [Solution] - Initilized to 0xFF
// [Files] - TerminalSetup.c
// 
// 46    1/20/11 1:16a Lavanyap
// [TAG] - EIP51898
// [Category] - BUG FIX
// [Severity] - Minor
// [Symptom] - SDL tokens are not working in Terminal driver when Terminal
// source module is not available in project.
// [RootCause] - Tokens are defined in Terminal binary module and are used
// in source module,so SDL token value changes cannot take effect when
// source module is not present in the project.
// [Solution] - Replaced SDL tokens used in source module with variables
// defined in binary module.
// [Files] - Terminal.c, TerminalSetup.c
// 
// 45    11/29/10 11:58p Rajeshms
// Build error resolved that caused because of previous Check-in.
// 
// 44    11/29/10 7:28a Rajeshms
// [TAG] - EIP 39842
// [Category]- BUG FIX
// [Severity]- Normal
// [Symptom] - PCI Serial Doesn't work when we change the PCI Serial
// device to different Slot(TOTAL_PCI_SERIAL_PORTS=1).
// [RootCause] - NVRAM variable was not set to Zero once device was
// removed from that slot so eventhough device(in another slot) is
// detected its not shown in Setup.  
// [Solution] - NVRAM variable which was set previously when device was
// present is set to ZERO if the device is not present in current slot.
// [Files] - TerminalSetup.c
// 
// 43    11/03/10 2:07a Rajeshms
// [TAG] - EIP 46234
// [Category]- BUG FIX
// [Severity]- Normal
// [Symptom] - If TOTAL_PCI_SERIAL_PORTS=1, the BIOS will hang in POST in
// non-debug mode.Was reproduced in CrownBay.
// [RootCause] - In non-debug mode terminal driver gets garbage value for
// UINT8 ComPort; in some cases so it hangs.  
// [Solution] - UINT8 Comport is initialised to zero.
// [Files] - TerminalSetup.c
// 
// 42    11/02/10 4:15a Lavanyap
// [TAG] - EIP42299
// [Category] - IMPROVEMENT
// [Description] - Console Redirection can support 10 COM Ports.
// [Files] - InitTerminalStrings.c, SerialIo.c, Terminal.sd, 
//           Terminal.sdl, Terminal.uni, TerminalSetup.c
// 
// 41    10/19/10 8:35a Rajeshms
// [TAG]- EIP 39562
// [Category]-IMPROVEMENT
// [Description]- Show entire PCI address of redirection device in Setup
// [Files]- Terminal.c, TerminalSetup.c, InitTerminalStrings.c
// 
// 40    6/01/10 12:32a Rameshr
// Support for Baud Rate 38400 in Terminal Driver
// EIP 38852
// 
// 39    5/03/10 1:14a Rameshr
// Issue:Need to handle different Base Hz values for SerialStatusCode,
// Terminal, and Legacy Serial Redirection.
// Solution: Moved Uart input clock into Core.sdl token and used in all
// the above modules.
// EIP: 37332
// 
// 38    5/03/10 12:22a Rameshr
// Issue:VT-UTF8 mode support for Console redirection with Debugger
// Solution: Serial Port attribute Setup questions added for the debugger
// console redirection port.
// EIP 37440
// 
// 37    4/19/10 1:44a Rameshr
// Build problem resolved because of removing
// DEFAULT_CONSOLE_REDIRECTION_ENABLE SDL token.
// 
// 36    3/31/10 12:30a Rameshr
// Recorder mode support Added.
// EIP 34388
// 
// 35    1/21/10 4:11p Artems
// 
// 34    12/16/09 6:35p Artems
// 
// 33    11/26/09 6:00a Rameshr
// SPCR table OEMID and OEMTABLEID configured through SDL tokens.
// EIP:26773
// 
// 32    10/26/09 9:48a Yul
// EIP 26401
// Console Redirection freezes when "CTRL + R" (refresh screen) is used
// 
// 31    10/21/09 11:28a Artems
// EIP 25955 - fixed switching mode mechanism
// 
// 30    10/08/09 6:02p Pats
// EIP 23731: Need to remove SIO serial port from Console Redirection
// Setup menu if TOTAL_SIO_SERIAL_PORTS is 0.
// Solution: In SetSerialPortsEnabledVar_Sio(), "#if (TOTAL_SERIAL_PORTS >
// 0)" changed to "#if (TOTAL_SIO_SERIAL_PORTS > 0)".
// 
// 29    9/28/09 4:08p Rameshr
// Terminal assumes UID to be started from 0. This assumption removed as
// UID should be unique and not be started from 0.
// EIP 17239
// 
// 28    9/21/09 11:38a Rameshr
// SerailIo driver to handle Pciserial device based on the SDL token
// settings.
// EIP 23764
// 
// 27    9/04/09 3:55p Krishnakumarg
// DEFAULT_DEBUGGER_CONSOLE_REDIRECTION_ENABLE token created for setting
// default option for debugger port.
// 
// 26    7/17/09 2:48p Rameshr
// ESC sequence information moved from Lib to Board module.
// Uart fifo size added as SDL token.
// EIP 23064
// 
// 25    7/02/09 5:01p Rameshr
// Coding Standard and File header updated.
// 
// 24    11/12/08 5:55p Ambikas
// 
// 23    9/08/08 4:52p Ambikas
// 
// 22    5/13/08 3:40p Rameshraju
// Terminal Resolution 100 x 31 support Added
// 
// 21    4/14/08 7:51p Ambikas
// 
// 20    4/14/08 7:42p Ambikas
// 
// 19    4/14/08 4:52p Ambikas
// 
// 18    4/14/08 4:46p Ambikas
// 
// 17    11/07/07 4:53p Ambikas
// We have reverted to the version of VfrCompile which uses 1 based
// arrays.  
// Array indeces have been changed accordingly.  
// 
// 16    10/11/07 7:42a Ambikas
// 
// 15    6/12/07 3:58p Ambikas
// 
// 14    6/11/07 11:36a Ambikas
// 
// 13    6/10/07 6:02p Ambikas
// 
// 12    6/06/07 7:52p Ambikas
// We now save the pci device path of pci serial port rather than segment
// and bus numbers.
// 
// 11    6/05/07 6:26p Ambikas
// 
// 10    6/05/07 11:55a Ambikas
// 
// 9     6/4/2007 7:34p Ambikas
// 
// 8     6/4/2007 7:30p Ambikas
// If TOTAL_SERIAL_PORTS is 0, then the setup data structures for the
// serial ports in Terminal.sd will not be defined.  So, we comment out
// code which references those data structures and just return default 
// values. 
// 
// 7     5/30/2007 12:18p Ambikas
// 
// 6     5/29/2007 8:35p Ambikas
// 
// 5     5/24/2007 2:33p Ambikas
// 
// 4     8/24/2006 7:07p Felixp
// x64 support (warnings/errors fixed)
// 
// 3     8/24/2006 3:34p Felixp
// x64 support (warnings/errors fixed)
// 
// 2     5/05/2006 5:35p Ambikas
//
// 1     11/11/2005 2:07p Ambikas
//
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: TerminalSetup.c
//
// Description: This file contains functions used by 
//              Terminal.lib/Terminalx64.lib to get Terminal/Serial 
//              related setup values.  
//
//<AMI_FHDR_END>
//**********************************************************************


#include <Protocol\SerialIo.h>  //for SERIAL_IO_MODE
#include <Token.h>              //for sdl tokens
#include <AmiDxeLib.h>          //for pRS
#include "TerminalBoard.h"

#include <Protocol\SerialIo.h>
#include <Setup.h>
#include "TerminalSetupVar.h"
#include <protocol\PciRootBridgeIo.h>
#include <Pci.h>

#define PCI_CFG_ADDRESS(bus,dev,func,reg) \
    ((UINT64)((((UINTN)bus) << 24) + (((UINTN)dev) << 16) + (((UINTN)func) << 8) + ((UINTN)reg)))& 0x00000000ffffffff

#define HARDWARE_LOOPBACK       1
#define SOFTWARE_LOOPBACK       2

#ifdef UART_INPUT_CLOCK
UINTN   SioUartInputClock = UART_INPUT_CLOCK;
#else
//
// Set the default value((24000000/13)MHz input clock) if the UART_INPUT_CLOCK SDL token is not present.
//
UINTN   SioUartInputClock=1843200;
#endif

UINTN   PciUartInputClock = PCI_UART_INPUT_CLOCK;

//for serial io defaults
UINT32 UartDefaultBaudRate              = UART_DEFAULT_BAUD_RATE;
EFI_PARITY_TYPE UartDefaultParity       = UART_DEFAULT_PARITY;
UINT8 UartDefaultDataBits               = UART_DEFAULT_DATA_BITS;
EFI_STOP_BITS_TYPE UartDefaultStopBits  = UART_DEFAULT_STOP_BITS;
UINT8 SerialIo_PciSerialSupport         = SERIALIO_PCI_SERIAL_SUPPORT;
BOOLEAN ValidateNvram                   = FALSE;

UINT32 TimeoutForDeterminingLoneEscChar = 
                                    TIMEOUT_FOR_DETERMINING_LONE_ESC_CHAR;

UINT32 EscSequenceCheckingIntervel = 
                                    (TIMEOUT_FOR_DETERMINING_LONE_ESC_CHAR/NUMBER_OF_TIME_FOR_ESC_SEQUENCE_CHECKING);

CHAR16 RefreshScreenKey     = REFRESH_SCREEN_KEY;
UINT8 SPCR_OEM_ID[6]     = CONVERT_TO_STRING(SPCR_ACPI_OEM_ID);		
UINT8 SPCR_OEM_TBL_ID[8] = CONVERT_TO_STRING(SPCR_ACPI_OEM_TBL_ID);	
UINT32 gTotalSioSerialPorts = TOTAL_SIO_SERIAL_PORTS;
UINT32 gTotalPciSerialPorts = TOTAL_PCI_SERIAL_PORTS;
UINTN  TotalTerminalDev=TOTAL_SERIAL_PORTS; 
UINT32 Uart_Fifo_Size=UART_FIFO_SIZE;
UINT8  PciComMmioWidth=PCI_SERIAL_MMIO_WIDTH;
UINT8  MaxFailuresAllowed = MAX_FAILURES_ALLOWED;
UINT32 MaximumSerialWriteErrorCount = MAXIMUM_SERIAL_WRITE_ERROR_COUNT; 
BOOLEAN SerialWriteErrorCheck= SERIAL_WRITE_ERROR_CHECK;
BOOLEAN ClearTerminalKBBufferReadyToBoot= CLEAR_TERMINAL_KB_BUFFER_AT_READYTOBOOT;
BOOLEAN ASCIIControlCodeSupport= ASCII_CONTROL_CODE_SUPPORT;
BOOLEAN SerialMouseDetection=SERIAL_MOUSE_DETECTION;


EFI_GUID gTerminalVarGuid   = TERMINAL_VAR_GUID;
EFI_GUID gSetupGuid         = SETUP_GUID; 
EFI_GUID gDebuggerTerminalVarGuid   = DEBUGGER_TERMINAL_VAR_GUID;
EFI_GUID  gEfiPciRootBridgeIoProtocolGuid = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;

UINT64 gAcpiSpcrTableComBaudRates[8] = 
                                {0, 0, 0, 9600, 19200, 38400, 57600, 115200};

CHAR16 *gPciSerialPortsDevicePathVarName[MAX_PCI_SERIAL_PORTS];

SETUP_DATA gSetupData;

//Terminal Driver global variables for SDL tokens.

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    Dont_Send_Ascii_Control_Printable_Characters
//
// Description:	Variable to replace DONT_SEND_ASCII_CONTROL_PRINTABLE_CHARACTERS.
//              token.
// Notes: BOOLEAN
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END>
BOOLEAN  Dont_Send_Ascii_Control_Printable_Characters =
#ifdef DONT_SEND_ASCII_CONTROL_PRINTABLE_CHARACTERS
    DONT_SEND_ASCII_CONTROL_PRINTABLE_CHARACTERS
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrInterfaceType
//
// Description:	Variable to replace spcr_interface_type token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END>
UINT8 SpcrInterfaceType = 
#ifdef spcr_interface_type
    spcr_interface_type
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrAddrSpcId
//
// Description:	Variable to replace spcr_addr_spc_id token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END>
UINT8 SpcrAddrSpcId = 
#ifdef spcr_addr_spc_id
    spcr_addr_spc_id
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrAddrBitWidth
//
// Description:	Variable to replace spcr_addr_bit_width token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrAddrBitWidth = 
#ifdef spcr_addr_bit_width
    spcr_addr_bit_width
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrAddrBitOffset
//
// Description:	Variable to replace spcr_addr_bit_offset token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrAddrBitOffset = 
#ifdef spcr_addr_bit_offset
    spcr_addr_bit_offset
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrAccessSize
//
// Description:	Variable to replace spcr_access_size token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrAccessSize = 
#ifdef spcr_access_size
    spcr_access_size
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrInterruptType
//
// Description:	Variable to replace spcr_interrupt_type token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrInterruptType = 
#ifdef spcr_interrupt_type
    spcr_interrupt_type
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrGlobalSystemInit
//
// Description:	Variable to replace spcr_global_system_int token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrGlobalSystemInit = 
#ifdef spcr_global_system_int
    spcr_global_system_int
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrParity
//
// Description:	Variable to replace spcr_parity token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrParity = 
#ifdef spcr_parity
    spcr_parity
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrStopBits
//
// Description:	Variable to replace spcr_stop_bits token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrStopBits = 
#ifdef spcr_stop_bits
    spcr_stop_bits
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciDeviceId
//
// Description:	Variable to replace spcr_pci_device_id token.
//
// Notes: UINT16
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT16 SpcrPciDeviceId = 
#ifdef spcr_pci_device_id
    spcr_pci_device_id
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciVendorId
//
// Description:	Variable to replace spcr_pci_vendor_id token.
//
// Notes: UINT16
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT16 SpcrPciVendorId = 
#ifdef spcr_pci_vendor_id
    spcr_pci_vendor_id
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciBusNumber
//
// Description:	Variable to replace spcr_pci_bus_number token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrPciBusNumber = 
#ifdef spcr_pci_bus_number
    spcr_pci_bus_number
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciDeviceNumber
//
// Description:	Variable to replace spcr_interface_type token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrPciDeviceNumber = 
#ifdef spcr_pci_device_number
    spcr_pci_device_number
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciFunctionNumber
//
// Description:	Variable to replace spcr_pci_function_number token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrPciFunctionNumber = 
#ifdef spcr_pci_function_number
    spcr_pci_function_number
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciFlags
//
// Description:	Variable to replace spcr_pci_flags token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END> 
UINT8 SpcrPciFlags = 
#ifdef spcr_pci_flags
    spcr_pci_flags
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    SpcrPciSegment
//
// Description:	Variable to replace spcr_pci_segment token.
//
// Notes: UINT8
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END>  
UINT8 SpcrPciSegment = 
#ifdef spcr_pci_segment
    spcr_pci_segment
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    AcpiOemRev
//
// Description:	Variable to replace ACPI_OEM_REV token.
//
// Notes: UINT64
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END>  
UINT64 AcpiOemRev = 
#ifdef ACPI_OEM_REV
    ACPI_OEM_REV
#else
    0
#endif
    ;

//<AMI_SHDR_START>
//----------------------------------------------------------------------------
// Name:    CoreRevision
//
// Description:	Variable to replace CORE_REVISION token.
//
// Notes: UINT64
//
//----------------------------------------------------------------------------
//<AMI_SHDR_END>  
UINT8 CoreRevision = 
#ifdef CORE_REVISION
    CORE_REVISION
#else
    0
#endif
    ;

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: InitSerialPortsEnabledVar
//
// Input: VOID
//
// Output: VOID
//
// Description: Initializes the variables SERIAL_PORTS_ENABLED_VAR and 
//              PCI_SERIAL_PORTS_LOCATION_VAR.  
//              SERIAL_PORTS_ENABLED_VAR keeps track of which serial ports
//              (both SuperIO and PCI) are enabled. 
//              PCI_SERIAL_PORTS_LOCATION_VAR keeps contains location 
//              information about the pci serial ports (device and function 
//              numbers).  
//                          
//<AMI_PHDR_END>
//**********************************************************************  
VOID InitSerialPortsEnabledVar(VOID)
{
    UINTN DebuggerSerialPortsEnabledVarSize = sizeof(DEBUGGER_SERIAL_PORTS_ENABLED_VAR); 
    DEBUGGER_SERIAL_PORTS_ENABLED_VAR DebuggerSerialPortsEnabledVar; 
    EFI_STATUS Status = EFI_SUCCESS;

#if (TOTAL_SERIAL_PORTS > 0)

    UINTN SerialPortsEnabledVarSize = sizeof(SERIAL_PORTS_ENABLED_VAR); 
    SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar; 

#if (TOTAL_PCI_SERIAL_PORTS > 0)
    UINTN PciSerialPortsLocationVarSize = 
                                    sizeof(PCI_SERIAL_PORTS_LOCATION_VAR);
    PCI_SERIAL_PORTS_LOCATION_VAR PciSerialPortsLocationVar; 
#endif
#if (TOTAL_SIO_SERIAL_PORTS > 0)
    UINTN SioSerialPortsLocationVarSize = 
                                    sizeof(SIO_SERIAL_PORTS_LOCATION_VAR);
    SIO_SERIAL_PORTS_LOCATION_VAR SioSerialPortsLocationVar; 
#endif

    pBS->SetMem(&SerialPortsEnabledVar, 
                sizeof(SERIAL_PORTS_ENABLED_VAR), 
                0);
    Status = pRS->SetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                EFI_VARIABLE_BOOTSERVICE_ACCESS,
                                SerialPortsEnabledVarSize,
                                &SerialPortsEnabledVar); 
    ASSERT_EFI_ERROR(Status);

#if (TOTAL_SIO_SERIAL_PORTS > 0)
    Status = pRS->GetVariable(SIO_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                NULL, 
                                &SioSerialPortsLocationVarSize, 
                                &SioSerialPortsLocationVar);
    if (EFI_ERROR(Status)) {
        pBS->SetMem(&SioSerialPortsLocationVar, 
                    sizeof(SIO_SERIAL_PORTS_LOCATION_VAR), 
                    0);
        Status = pRS->SetVariable(SIO_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                    &gTerminalVarGuid, 
                                    (EFI_VARIABLE_BOOTSERVICE_ACCESS | 
                                            EFI_VARIABLE_NON_VOLATILE),
                                    SioSerialPortsLocationVarSize, 
                                    &SioSerialPortsLocationVar); 
        ASSERT_EFI_ERROR(Status);
    }
#endif


#if (TOTAL_PCI_SERIAL_PORTS > 0)
    Status = pRS->GetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                NULL, 
                                &PciSerialPortsLocationVarSize, 
                                &PciSerialPortsLocationVar);
    if (EFI_ERROR(Status)) {
        pBS->SetMem(&PciSerialPortsLocationVar, 
                    sizeof(PCI_SERIAL_PORTS_LOCATION_VAR), 
                    0);
        Status = pRS->SetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                    &gTerminalVarGuid, 
                                    (EFI_VARIABLE_BOOTSERVICE_ACCESS | 
                                            EFI_VARIABLE_NON_VOLATILE),
                                    PciSerialPortsLocationVarSize, 
                                    &PciSerialPortsLocationVar); 
        ASSERT_EFI_ERROR(Status);
    }
#endif

#endif
    //
    // Initilize the Amidebugger Serial Port variables.
    //
    pBS->SetMem(&DebuggerSerialPortsEnabledVar, 
                sizeof(DEBUGGER_SERIAL_PORTS_ENABLED_VAR), 
                0);
    Status = pRS->SetVariable(DEBUGGER_SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gDebuggerTerminalVarGuid, 
                                EFI_VARIABLE_BOOTSERVICE_ACCESS,
                                DebuggerSerialPortsEnabledVarSize,
                                &DebuggerSerialPortsEnabledVar); 
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: SetSerialPortsEnabledVar_Sio
//
// Input: IN UINT8 Port
//
// Output: VOID
//
// Description: Sets SERIAL_PORTS_ENABLED_VAR[Port] to 1.
//
//<AMI_PHDR_END>
//**********************************************************************  
UINT8 SetSerialPortsEnabledVar_Sio(IN UINT8 Uid)
{
    UINTN DebuggerSerialPortsEnabledVarSize = sizeof(DEBUGGER_SERIAL_PORTS_ENABLED_VAR);
    UINT32 DebuggerSerialPortsEnabledVarAttributes=0;
    DEBUGGER_SERIAL_PORTS_ENABLED_VAR DebuggerSerialPortsEnabledVar;
    EFI_STATUS Status = EFI_SUCCESS;	

    if(Uid == 0xFF) {

        //
        // Handle the Serial Port that is coming from Ami debugger
        //
        Status = pRS->GetVariable(DEBUGGER_SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gDebuggerTerminalVarGuid, 
                                &DebuggerSerialPortsEnabledVarAttributes, 
                                &DebuggerSerialPortsEnabledVarSize, 
                                &DebuggerSerialPortsEnabledVar);
	ASSERT_EFI_ERROR(Status);

        //
        // Port Present Status.
        //
        DebuggerSerialPortsEnabledVar.PortEnabled=1;

        Status = pRS->SetVariable(DEBUGGER_SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gDebuggerTerminalVarGuid, 
                                EFI_VARIABLE_BOOTSERVICE_ACCESS,
                                DebuggerSerialPortsEnabledVarSize,
                                &DebuggerSerialPortsEnabledVar);
	ASSERT_EFI_ERROR(Status);
        //
        // Return 0xFF, so that it's known as this serial port is coming 
        // from AmiDebugger
        //
        return 0xFF; 
    }

#if (TOTAL_SIO_SERIAL_PORTS > 0)
{

    UINTN SerialPortsEnabledVarSize = sizeof(SERIAL_PORTS_ENABLED_VAR);
    UINT32 SerialPortsEnabledVarAttributes=0;
    SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar;

    UINTN SioSerialPortsLocationVarSize = 
                                    sizeof(SIO_SERIAL_PORTS_LOCATION_VAR);
    UINT32 SioSerialPortsLocationVarAttributes=0;
    SIO_SERIAL_PORTS_LOCATION_VAR SioSerialPortsLocationVar; 
    EFI_STATUS Status = EFI_SUCCESS;	
    UINT32 i = 0;
    UINT8 ComPort = 0xFF; 

    Status = pRS->GetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                &SerialPortsEnabledVarAttributes, 
                                &SerialPortsEnabledVarSize, 
                                &SerialPortsEnabledVar);
    ASSERT_EFI_ERROR(Status);

    if(EFI_ERROR(Status)) {
        return 0xFF;
    }

    Status = pRS->GetVariable(SIO_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                &SioSerialPortsLocationVarAttributes, 
                                &SioSerialPortsLocationVarSize, 
                                &SioSerialPortsLocationVar);
    ASSERT_EFI_ERROR(Status);

    if(EFI_ERROR(Status)) {
        return 0xFF;
    }

    for (i = 0; i < TOTAL_SIO_SERIAL_PORTS; i++) {
        if ((SioSerialPortsLocationVar.PortUid[i] == Uid ) && 
            (SioSerialPortsLocationVar.Valid[i] == 0xFF)) {
            SerialPortsEnabledVar.PortsEnabled[i] = 1;
            ComPort = i; 
            break;            
        }
    }

    if (i == TOTAL_SIO_SERIAL_PORTS) {
        for (i = 0; i < TOTAL_SIO_SERIAL_PORTS; i++) {
            if ((!SerialPortsEnabledVar.PortsEnabled[i]) &&
                (SioSerialPortsLocationVar.Valid[i] == 0)) {
                
                SerialPortsEnabledVar.PortsEnabled[i] = 1;
                ComPort = i; 
               
                SioSerialPortsLocationVar.PortUid[i] = Uid;
                SioSerialPortsLocationVar.Valid[i] = 0xFF;

                Status = pRS->SetVariable(
                                    SIO_SERIAL_PORTS_LOCATION_VAR_C_NAME,
                                    &gTerminalVarGuid, 
                                    (EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                            EFI_VARIABLE_NON_VOLATILE),
                                    SioSerialPortsLocationVarSize, 
                                    &SioSerialPortsLocationVar); 

                ASSERT_EFI_ERROR(Status);
                break;
            }
        }
    }

    Status = pRS->SetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                EFI_VARIABLE_BOOTSERVICE_ACCESS,
                                SerialPortsEnabledVarSize,
                                &SerialPortsEnabledVar); 
    ASSERT_EFI_ERROR(Status);

    return ComPort; 
}
#else 

    return 0xFF;

#endif
}

#if (TOTAL_PCI_SERIAL_PORTS > 0)
//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: ValidatePciSerialNvram
//
// Input:  IN SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar,
//         IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
//
// Output: EFI_STATUS
//
// Description: Checks for the Presence of PCI Serial device with values
//              present in the NVRAM Variable PciSerialPortsLocationVar.
//              If found donot change NVRAM variable.If not found delete
//              the NVRAM variable describing the device path  and make 
//              current PciSerialPortsLocationVar.Bus[i],Device[i] and
//              function[i] to zero.
//
//<AMI_PHDR_END>
//********************************************************************** 
EFI_STATUS ValidatePciSerialNvram(
    IN SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar,
	IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
{
    UINT64      PciAddress;
    UINT8       RevisionId[4];
    UINT8       SetNvramVariable=0;
    UINT8       i = 0;
    EFI_STATUS  Status;

    UINTN PciSerialPortsLocationVarSize = sizeof(PCI_SERIAL_PORTS_LOCATION_VAR);
    UINT32 PciSerialPortsLocationVarAttributes=0;
    PCI_SERIAL_PORTS_LOCATION_VAR PciSerialPortsLocationVar;
    
	UINTN PciSerialPortDevicePathVarSize = 0;
    UINT32 PciSerialPortDevicePathVarAttributes = 0;
    EFI_DEVICE_PATH_PROTOCOL *PciSerialPortDevicePathVar = NULL;

    EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL	*gPciRootBridgeIo=NULL;

    if (ValidateNvram == TRUE) {
        return EFI_SUCCESS;
    }           

    Status = pBS->LocateProtocol( &gEfiPciRootBridgeIoProtocolGuid,
                                  NULL,
                                  &gPciRootBridgeIo );

    ASSERT_EFI_ERROR(Status);
    if (EFI_ERROR(Status)) { 
        return Status;
    }

    ValidateNvram = TRUE;
    Status = pRS->GetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME,
                              &gTerminalVarGuid, 
                              &PciSerialPortsLocationVarAttributes,
                              &PciSerialPortsLocationVarSize, 
                              &PciSerialPortsLocationVar );
    if(EFI_ERROR(Status)) {
        return Status;
    }

    ASSERT_EFI_ERROR(Status);

    for (i = 0; i < TOTAL_PCI_SERIAL_PORTS; i++) {
        if (!SerialPortsEnabledVar.PortsEnabled[gTotalSioSerialPorts+i]) {
            if ((PciSerialPortsLocationVar.Bus[i] == 0) &&
                (PciSerialPortsLocationVar.Device[i] == 0) &&
                (PciSerialPortsLocationVar.Function[i] == 0)) {
                continue;
            }

            PciAddress = PCI_CFG_ADDRESS (PciSerialPortsLocationVar.Bus[i],
                                          PciSerialPortsLocationVar.Device[i],
                                          PciSerialPortsLocationVar.Function[i],
                                          PCI_REV_ID_OFFSET
                                          );
            //
            //Get the Class Code
            //
            Status = gPciRootBridgeIo->Pci.Read(
                                        gPciRootBridgeIo,
                                        EfiPciWidthUint32,
                                        PciAddress,
                                        1,
                                        &RevisionId);
            ASSERT_EFI_ERROR(Status);

            Status = GetEfiVariable(gPciSerialPortsDevicePathVarName[i],
                                    &gTerminalVarGuid, 
                                    &PciSerialPortDevicePathVarAttributes, 
                                    &PciSerialPortDevicePathVarSize, 
                                    &PciSerialPortDevicePathVar);
            if (EFI_ERROR(Status)) { 
                return Status;
            }

            //
            //Check for the presence of the PCI Serial device
            //
            if ((RevisionId[3] == PCI_CL_COMM) &&
                ((RevisionId[2] == PCI_CL_COMM_CSL_SERIAL) ||
                (RevisionId[2] == PCI_CL_COMM_CSL_OTHER)) ) {
                continue;
            }

            //
            //Its not PCI serial Device,So delete NVRAM variable describing device path of the device.
            //
            SetNvramVariable = 1;
            Status = pRS->SetVariable(gPciSerialPortsDevicePathVarName[i],
                                      &gTerminalVarGuid,
                                      (EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                      EFI_VARIABLE_NON_VOLATILE), 
                                      NULL,
                                      NULL);
            ASSERT_EFI_ERROR(Status);
            //
            //Initialise Bus,Dev,func. to Zero and set variable to represent that device is not present.
            //
            PciSerialPortsLocationVar.Bus[i] = 0;
            PciSerialPortsLocationVar.Device[i] = 0;
            PciSerialPortsLocationVar.Function[i] = 0;
        }
    }
    if (SetNvramVariable == 1) {
        Status = pRS->SetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME,
                                  &gTerminalVarGuid, 
                                  (EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                      EFI_VARIABLE_NON_VOLATILE), 
                                  PciSerialPortsLocationVarSize, 
                                  &PciSerialPortsLocationVar);
        ASSERT_EFI_ERROR(Status);
    }
    return EFI_SUCCESS;
}
#endif

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: SetSerialPortsEnabledVar_Pci
//
// Input: 
//      IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
//      IN UINT8 Device
//      IN UINT8 Function
//
// Output: the assigned com port number
//      UINT8 
//
// Description: Keeping track of which pci serial ports are enabled 
//              a bit complicated.
//              Unlike the SuperIO serial ports, pci serial ports do not 
//              have UIDs.  
//              We distinguish them by their locations.  
//              For each pci serial port, we store the entire device 
//              path under the variable names in 
//              gPciSerialPortsDevicePathVarName ("COM5," "COM6", etc).
//              We check the parameter "DevicePath" against our stored 
//              device paths.
//              If it matches, we return the com port number of that 
//              device path.
//              If it doesn't match, we use a new entry in 
//              SERIAL_PORTS_ENABLED_VAR for the pci serial port.  
//              We also use a new entry in PCI_SERIAL_PORTS_LOCATION_VAR 
//              and store the device and function numbers. 
//
//<AMI_PHDR_END>
//**********************************************************************  
UINT8 SetSerialPortsEnabledVar_Pci(
    IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
    IN UINT8 Bus,
    IN UINT8 Device, 
    IN UINT8 Function,
    IN UINT8 Port,
    IN BOOLEAN AmiPciSerialDetected)
{
#if (TOTAL_PCI_SERIAL_PORTS > 0)
    UINTN SerialPortsEnabledVarSize = sizeof(SERIAL_PORTS_ENABLED_VAR); 
    UINT32 SerialPortsEnabledVarAttributes=0;
    SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar; 

    UINTN PciSerialPortsLocationVarSize = 
                                    sizeof(PCI_SERIAL_PORTS_LOCATION_VAR);
    UINT32 PciSerialPortsLocationVarAttributes=0;
    PCI_SERIAL_PORTS_LOCATION_VAR PciSerialPortsLocationVar; 

    UINTN PciSerialPortDevicePathVarSize = 0;
    UINT32 PciSerialPortDevicePathVarAttributes = 0;
    EFI_DEVICE_PATH_PROTOCOL *PciSerialPortDevicePathVar = NULL; 

    EFI_STATUS Status = EFI_SUCCESS;	
    UINT32 i = 0;
    UINT8 ComPort=0xFF; 
    CHAR16 PciSerialPortName[TOTAL_PCI_SERIAL_PORTS][6];

    for ( i = 0; i < TOTAL_PCI_SERIAL_PORTS; i++) {
        Swprintf(PciSerialPortName[i], L"COM%x", gTotalSioSerialPorts+i);
        gPciSerialPortsDevicePathVarName[i] = PciSerialPortName[i];
    }

    Status = pRS->GetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gTerminalVarGuid,
                                &SerialPortsEnabledVarAttributes, 
                                &SerialPortsEnabledVarSize, 
                                &SerialPortsEnabledVar);
    ASSERT_EFI_ERROR(Status);

    if(EFI_ERROR(Status)) {
        return 0xFF;
    }

	Status = ValidatePciSerialNvram(SerialPortsEnabledVar,DevicePath);

    if (EFI_ERROR(Status)) {
        return 0xFF;
    }

    Status = pRS->GetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                &PciSerialPortsLocationVarAttributes, 
                                &PciSerialPortsLocationVarSize, 
                                &PciSerialPortsLocationVar);
    ASSERT_EFI_ERROR(Status);

    if(EFI_ERROR(Status)) {
        return 0xFF;
    }

    for (i = 0; i < TOTAL_PCI_SERIAL_PORTS; i++) {
        if ((PciSerialPortsLocationVar.Device[i] == Device) && 
            (PciSerialPortsLocationVar.Function[i] == Function)) {
            Status = GetEfiVariable(gPciSerialPortsDevicePathVarName[i],
                                    &gTerminalVarGuid, 
                                    &PciSerialPortDevicePathVarAttributes, 
                                    &PciSerialPortDevicePathVarSize, 
                                    &PciSerialPortDevicePathVar);
            if (!EFI_ERROR(Status)) {
                if (!DPCmp(DevicePath, PciSerialPortDevicePathVar)) {
                    SerialPortsEnabledVar.PortsEnabled[gTotalSioSerialPorts+i] = 1;
                    ComPort = gTotalSioSerialPorts+i; 
                    break;            
                }
            }
        }
    }

    if (i == TOTAL_PCI_SERIAL_PORTS) {
        for (i = 0; i < TOTAL_PCI_SERIAL_PORTS; i++) {
            if ((!SerialPortsEnabledVar.PortsEnabled[gTotalSioSerialPorts+i]) &&
                (PciSerialPortsLocationVar.Device[i] == 0) &&
                (PciSerialPortsLocationVar.Function[i] == 0)) {
                Status = GetEfiVariable(
                                    gPciSerialPortsDevicePathVarName[i],
                                    &gTerminalVarGuid, 
                                    &PciSerialPortDevicePathVarAttributes,
                                    &PciSerialPortDevicePathVarSize, 
                                    &PciSerialPortDevicePathVar);
                if (Status == EFI_NOT_FOUND) {
                    SerialPortsEnabledVar.PortsEnabled[gTotalSioSerialPorts+i] = 1;
                    ComPort = gTotalSioSerialPorts+i; 
               
                    PciSerialPortDevicePathVarSize = DPLength(DevicePath);
                    Status = pRS->SetVariable(
                                        gPciSerialPortsDevicePathVarName[i],
                                        &gTerminalVarGuid,
                                        (EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                            EFI_VARIABLE_NON_VOLATILE), 
                                        PciSerialPortDevicePathVarSize, 
                                        DevicePath);
                    ASSERT_EFI_ERROR(Status);

      			    PciSerialPortsLocationVar.Bus[i] = Bus;              
				    PciSerialPortsLocationVar.Device[i] = Device;
                    PciSerialPortsLocationVar.Function[i] = Function;
                    if(AmiPciSerialDetected) {
                        PciSerialPortsLocationVar.AmiPciSerialPresent[i] = TRUE;
                        PciSerialPortsLocationVar.Port[i] = Port;
                    }

                    Status = pRS->SetVariable(
                                    PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME,
                                    &gTerminalVarGuid, 
                                    (EFI_VARIABLE_BOOTSERVICE_ACCESS |
                                            EFI_VARIABLE_NON_VOLATILE),
                                    PciSerialPortsLocationVarSize, 
                                    &PciSerialPortsLocationVar); 
                    ASSERT_EFI_ERROR(Status);

                    break;
                }
            }
        }
    }

    Status = pRS->SetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME,
                                &gTerminalVarGuid,
                                EFI_VARIABLE_BOOTSERVICE_ACCESS,
                                SerialPortsEnabledVarSize, 
                                &SerialPortsEnabledVar); 
    ASSERT_EFI_ERROR(Status);

    return ComPort; 

#else 

    return 0xFF;

#endif
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: GetSetupValuesForSerialIoMode
//
// Input: 
//      IN UINT8 Port
//      IN OUT SERIAL_IO_MODE *SerialIoMode
//
// Output: VOID
//
// Description: Returns the user configured SERIAL_IO_MODE values.
//
//<AMI_PHDR_END>
//**********************************************************************  
VOID GetSetupValuesForSerialIoMode(
    IN UINT8 Port, 
    IN OUT SERIAL_IO_MODE *SerialIoMode)
{
    UINT32 SetupDataAttributes = 0;
    UINTN SetupDataVarSize = sizeof(SETUP_DATA); 

    UINT8 LoopbackEnable = 0;
    UINT8 FlowControl = 0;
    EFI_STATUS Status = EFI_SUCCESS;

#if (TOTAL_SERIAL_PORTS == 0)

    LoopbackEnable          = UART_DEFAULT_LOOPBACK_ENABLE;
    FlowControl             = UART_DEFAULT_FLOW_CONTROL;
    SerialIoMode->BaudRate  = 
                gAcpiSpcrTableComBaudRates[UART_DEFAULT_BAUD_RATE_INDEX];
    SerialIoMode->Parity    = UART_DEFAULT_PARITY;
    SerialIoMode->DataBits  = UART_DEFAULT_DATA_BITS;
    SerialIoMode->StopBits  = UART_DEFAULT_STOP_BITS;

#else

    Status = pRS->GetVariable(L"Setup", &gSetupGuid, &SetupDataAttributes,
                                &SetupDataVarSize, &gSetupData);

    if (EFI_ERROR(Status)) {
        LoopbackEnable          = UART_DEFAULT_LOOPBACK_ENABLE;
        FlowControl             = UART_DEFAULT_FLOW_CONTROL;
        SerialIoMode->BaudRate  = 
                gAcpiSpcrTableComBaudRates[UART_DEFAULT_BAUD_RATE_INDEX];
        SerialIoMode->Parity    = UART_DEFAULT_PARITY;
        SerialIoMode->DataBits  = UART_DEFAULT_DATA_BITS;
        SerialIoMode->StopBits  = UART_DEFAULT_STOP_BITS;
    } else {
        LoopbackEnable          = gSetupData.LoopbackEnable[Port];
        FlowControl             = gSetupData.FlowControl[Port];
        SerialIoMode->BaudRate  = 
                    gAcpiSpcrTableComBaudRates[gSetupData.BaudRate[Port]];
        SerialIoMode->Parity    = gSetupData.Parity[Port];
        SerialIoMode->DataBits  = gSetupData.DataBits[Port];
        SerialIoMode->StopBits  = gSetupData.StopBits[Port];
    }

#endif

    SerialIoMode->ControlMask = 0;
    if (FlowControl == HARDWARE_FLOW_CONTROL_SETUP_OPTION) 
        SerialIoMode->ControlMask |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
    else if (FlowControl == SOFTWARE_FLOW_CONTROL_SETUP_OPTION)
        SerialIoMode->ControlMask |= EFI_SERIAL_SOFTWARE_FLOW_CONTROL_ENABLE;
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: GetDefaultConsoleRedirectionStatus
//
// Description: Returns the default settings of the ConsoleRedirection
//              enable status 
//
// Input:  IN UINT8 Port
//
// Output: OUT UINT8 RedirectionStatus
//
//
//<AMI_PHDR_END>
//**********************************************************************  
UINT8 GetDefaultConsoleRedirectionStatus(
    IN UINT8 Port 
)
{
    switch (Port) {
#if (TOTAL_SIO_SERIAL_PORTS > 0)
        case 0:
                return COM0_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 1)
        case 1:
                return COM1_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 2)
        case 2:
                return COM2_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 3)
        case 3:
                return COM3_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 4)
        case 4:
                return COM4_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 5)
        case 5:
                return COM5_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 6)
        case 6:
                return COM6_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 7)
        case 7:
                return COM7_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 8)
        case 8:
                return COM8_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_SIO_SERIAL_PORTS > 9)
        case 9:
                return COM9_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_PCI_SERIAL_PORTS > 0)
        case (TOTAL_SIO_SERIAL_PORTS):
                return PCI0_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_PCI_SERIAL_PORTS > 1)
        case (TOTAL_SIO_SERIAL_PORTS+1):
                return PCI1_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_PCI_SERIAL_PORTS > 2)
        case (TOTAL_SIO_SERIAL_PORTS+2):
                return PCI2_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

#if (TOTAL_PCI_SERIAL_PORTS > 3)
        case (TOTAL_SIO_SERIAL_PORTS+3):
                return PCI3_DEFAULT_CONSOLE_REDIRECTION_ENABLE;
#endif

    }

    return 0;
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: GetSetupValuesForTerminal
//
// Input: 
//      IN UINT8 Port
//      IN OUT UINT8 *ConsoleRedirectionEnable
//      IN OUT UINT8 *TerminalType
//      IN OUT BOOLEAN *SupportExRes
//      IN OUT BOOLEAN *RecorderMode, 
//      IN OUT UINT8 *Disable_Terminal_For_SCT_Test
//
// Output: VOID
//
// Description: Returns the Setup setttings for the terminal 
//              (whether redirection is enabled and the terminal type).
//
//<AMI_PHDR_END>
//**********************************************************************  
VOID GetSetupValuesForTerminal(
    IN UINT8 Port, 
    IN OUT UINT8 *ConsoleRedirectionEnable, 
    IN OUT UINT8 *TerminalType,
    IN OUT BOOLEAN *SupportExRes, 
    IN OUT BOOLEAN *VtUtf8, 
    IN OUT BOOLEAN *RecorderMode, 
    IN OUT BOOLEAN *PuttyKeyPad,
    IN OUT UINT8 *Disable_Terminal_For_SCT_Test)
{
    UINT32 SetupDataAttributes = 0;
    UINTN SetupDataSize = sizeof(SETUP_DATA);     

    EFI_STATUS Status ;

    *Disable_Terminal_For_SCT_Test = DISABLE_TERMINAL_FOR_SCT_TEST;

    Status = pRS->GetVariable(L"Setup", &gSetupGuid, &SetupDataAttributes,
                                    &SetupDataSize, &gSetupData);
    
    if(Port == (UINT8)-1){
        //
        // If the redirection comes Via Ami debugger
        //
#ifdef CONSOLE_REDIRECTION_SUPPORT
#if CONSOLE_REDIRECTION_SUPPORT == 1
        if(EFI_ERROR(Status)) {
            //
            // If the Setup Variable is not Found Return the Default values
            //
            *ConsoleRedirectionEnable = DEFAULT_DEBUGGER_CONSOLE_REDIRECTION_ENABLE;
            *TerminalType = DEFAULT_TERMINAL_TYPE;
            *SupportExRes = FALSE;
            *VtUtf8 = VTUTF8_ENABLE;
            *RecorderMode = FALSE;
            *PuttyKeyPad = PUTTY_VT100;
        } else {
            //
            // Setup Values Found for the Debugger Serial port. 
            //
            *ConsoleRedirectionEnable=gSetupData.DebuggerConsoleRedirectionEnable;
            *TerminalType = gSetupData.DebuggerTerminalType;
            *SupportExRes = FALSE;
            *VtUtf8 = VTUTF8_ENABLE;
            *RecorderMode = FALSE;
            *PuttyKeyPad = PUTTY_VT100;
        }
#else
        //
        // CONSOLE_REDIRECTION_SUPPORT token is defined in Amidebugger module. 
        // But if this token is disabled, return the default values. 
        //
        *ConsoleRedirectionEnable = DEFAULT_DEBUGGER_CONSOLE_REDIRECTION_ENABLE;
        *TerminalType = DEFAULT_TERMINAL_TYPE;
        *SupportExRes = FALSE;
        *VtUtf8 = VTUTF8_ENABLE;
        *RecorderMode = FALSE;
        *PuttyKeyPad = PUTTY_VT100;
#endif
#else 
        //
        // CONSOLE_REDIRECTION_SUPPORT token is defined in Amidebugger module. 
        // If this token is not present, return the default values. 
        //
        *ConsoleRedirectionEnable = DEFAULT_DEBUGGER_CONSOLE_REDIRECTION_ENABLE;
        *TerminalType = DEFAULT_TERMINAL_TYPE;
        *SupportExRes = FALSE;
        *VtUtf8 = VTUTF8_ENABLE;
        *RecorderMode = FALSE;
        *PuttyKeyPad = PUTTY_VT100;

#endif

        return;
    } 

#if (TOTAL_SERIAL_PORTS == 0)

    *ConsoleRedirectionEnable = GetDefaultConsoleRedirectionStatus(Port);
    *TerminalType = DEFAULT_TERMINAL_TYPE;
    *SupportExRes = FALSE;
    *VtUtf8 = VTUTF8_ENABLE;
    *RecorderMode = FALSE;
    *PuttyKeyPad = PUTTY_VT100;

#else
    if (EFI_ERROR(Status)) {
        *ConsoleRedirectionEnable = GetDefaultConsoleRedirectionStatus(Port);
        *TerminalType = DEFAULT_TERMINAL_TYPE;
        *SupportExRes = FALSE;
        *VtUtf8 = VTUTF8_ENABLE;
        *RecorderMode = FALSE;
        *PuttyKeyPad = PUTTY_VT100;
    } else {
        *ConsoleRedirectionEnable = 
                                    gSetupData.ConsoleRedirectionEnable[Port];
        *TerminalType = gSetupData.TerminalType[Port];
        *SupportExRes = (gSetupData.Resolution[Port] == 0) ? FALSE : TRUE;
        *VtUtf8 = (gSetupData.VtUtf8[Port] == 0) ? FALSE : TRUE;
        *RecorderMode = (gSetupData.RecorderMode[Port] == 0) ? FALSE : TRUE;
        *PuttyKeyPad = gSetupData.PuttyFunctionKeyPad[Port];
    }
#endif
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure: GetAcpiSpcrTableValues
//
// Input: 
//      IN OUT UINT8 *AcpiSpcrTableComPort
//      IN OUT UINT8 *AcpiSpcrTableConsoleRedirectionEnable
//      IN OUT UINT8 *AcpiSpcrTableTerminalType
//      IN OUT UINT8 *AcpiSpcrTableBaudRate
//      IN OUT UINT8 *AcpiSpcrTableFlowControl
//
// Output: VOID
//
// Description: Returns the configurable aspects of the acpi spcr table 
//              com port (the com port number, whether the console 
//              redirection is enabled, the terminal type, baude rate, 
//              and flow control type used).  
//
//<AMI_PHDR_END>
//**********************************************************************  
VOID GetAcpiSpcrTableValues(
    IN OUT UINT8 *AcpiSpcrTableComPort, 
    IN OUT UINT8 *AcpiSpcrTableConsoleRedirectionEnable, 
    IN OUT UINT8 *AcpiSpcrTableTerminalType, 
    IN OUT UINT8 *AcpiSpcrTableBaudRate, 
    IN OUT UINT8 *AcpiSpcrTableFlowControl)
{
    UINT32 SetupDataAttributes = 0;
    UINTN SetupDataSize = sizeof(SETUP_DATA); 

    EFI_STATUS Status = EFI_SUCCESS ;

#if (TOTAL_SERIAL_PORTS == 0)

    *AcpiSpcrTableComPort = DEFAULT_ACPI_SPCR_COM_PORT;
    *AcpiSpcrTableConsoleRedirectionEnable = 
                            DEFAULT_ACPI_SPCR_CONSOLE_REDIRECTION_ENABLE;
    *AcpiSpcrTableTerminalType = DEFAULT_ACPI_SPCR_TABLE_TERMINAL_TYPE;
    *AcpiSpcrTableBaudRate = UART_DEFAULT_BAUD_RATE_INDEX;
    *AcpiSpcrTableFlowControl = UART_DEFAULT_FLOW_CONTROL;

#else

    Status = pRS->GetVariable(L"Setup", &gSetupGuid, &SetupDataAttributes,
                                &SetupDataSize, &gSetupData);

    if (EFI_ERROR(Status)) {
        *AcpiSpcrTableComPort = DEFAULT_ACPI_SPCR_COM_PORT;
        *AcpiSpcrTableConsoleRedirectionEnable = 
                            DEFAULT_ACPI_SPCR_CONSOLE_REDIRECTION_ENABLE;
        *AcpiSpcrTableTerminalType = DEFAULT_ACPI_SPCR_TABLE_TERMINAL_TYPE;
        *AcpiSpcrTableBaudRate = UART_DEFAULT_BAUD_RATE_INDEX;
        *AcpiSpcrTableFlowControl = UART_DEFAULT_FLOW_CONTROL;
    } else {
#if EFI_SPECIFICATION_VERSION<0x2000A
        *AcpiSpcrTableComPort = gSetupData.AcpiSpcrPort-1;
#else
        *AcpiSpcrTableComPort = gSetupData.AcpiSpcrPort;
#endif
         
        *AcpiSpcrTableConsoleRedirectionEnable = 
                                gSetupData.AcpiSpcrConsoleRedirectionEnable;
        *AcpiSpcrTableTerminalType = gSetupData.AcpiSpcrTerminalType;
        *AcpiSpcrTableBaudRate = 
                            gSetupData.AcpiSpcrBaudRate;
        *AcpiSpcrTableFlowControl = 
                            gSetupData.AcpiSpcrFlowControl;
    }

#endif
}

#include <Protocol\ComponentName.h>
#ifndef EFI_COMPONENT_NAME2_PROTOCOL_GUID //old Core
BOOLEAN LanguageCodesEqual(
    CONST CHAR8* LangCode1, CONST CHAR8* LangCode2
){
    return    LangCode1[0]==LangCode2[0] 
           && LangCode1[1]==LangCode2[1]
           && LangCode1[2]==LangCode2[2];
}
#endif

#ifndef LANGUAGE_CODE_ENGLISH
CHAR8 SupportedLanguages[] = "eng";
#else
CHAR8 SupportedLanguages[] = LANGUAGE_CODE_ENGLISH;
#endif

//****************************************************************************
//****************************************************************************
//**                                                                        **
//**             (C)Copyright 1985-20014, American Megatrends, Inc.          **
//**                                                                        **
//**                          All Rights Reserved.                          **
//**                                                                        **
//**             5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093          **
//**                                                                        **
//**                          Phone (770)-246-8600                          **
//**                                                                        **
//****************************************************************************
//****************************************************************************