summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/BootOnly/protocol.c
blob: d112674a0f658254d06f492eb57c4c3335ce2c3d (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
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2014, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/BootOnly/protocol.c $
//
// $Author: Premkumara $
//
// $Revision: 51 $
//
// $Date: 8/28/14 7:36a $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/BootOnly/protocol.c $
// 
// 51    8/28/14 7:36a Premkumara
// [TAG]		EIP107833, 125388
// [Category]	Improvement
// [Symptom:]	Setting best text and GOP mode while using TSEPostinterfaces
// before TSE or after TSE.
// [Files]		Protocol.c, AMITSE.sdl, CommonHelper.c, MiniSetup.sdl,
// PostMgmtc, PostmgmtExt.c, MessagBox.c
// 
// 50    5/02/14 7:06a Premkumara
// [TAG]  		EIP137373
// [Category]  	Improvement
// [Description]  	Added signal event for BeforeTimeOut and AfterTimeOut
// with guids
// [Files]  		AMIVfr.h,protocol.c
// 
// 49    5/02/14 6:15a Arunsb
// [TAG]  		EIP128665
// [Category]  	Improvement
// [Description]  	Providing support to invalidate the BGRT status bit.
// Defined gTSEInvalidateBgrtStatusProtocolGuid
// [Files]  		protocol.c and amivfr.h
// 
// 48    5/02/14 6:12a Arunsb
// [TAG]  		EIP128665
// [Category]  	Improvement
// [Description]  	Providing support to invalidate the BGRT status bit
// [Files]  		protocol.c and amivfr.h
// 
// 47    2/11/14 8:09p Arunsb
// Changes reverted for 2.16.1243 label
// 
// 46    11/07/13 1:55a Premkumara
// [TAG]	EIP-137373
// [Category]	Improvement
// [Description]	Added signal event for BeforeTimeOut and AfterTimeOut
// with GUID
// [Files]	Protocol.c, AMIVfr.h
// 
// 45    10/07/13 3:17a Premkumara
// Resolved build error in EIP-128665
// 
// 44    9/13/13 2:01p Premkumara
// Uploaded back for EIP-128665 after TSEBootOnly 1240 release
// Files - Protocol.c, Protocol.h, AMIPostMgr.h
// 
// 43    8/26/13 2:16a Premkumara
// Reverted back for BootOnly1240 release
// 
// 41    4/18/13 6:15a Arunsb
// [TAG]  		EIP113081 
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	Post message displays twice
// [RootCause]  	Buffer not cleared after displaying post message
// [Solution]  	Buffer cleared properly. Save and restored the post
// graphics screen properly.
// [Files]  		protocol.c, screen.c and string.c
// 
// 40    4/17/13 12:38p Arunsb
// [TAG]  		EIP107967 
// [Category]  	Bug Fix
// [Severity]  	Important
// [Symptom]  	Ami Post Management functionalities reliant on ConOut need
// checks added.
// [Files]  		protocol.c
// 
// 39    12/05/12 5:31a Rajashakerg
// [TAG]  		EIP103381 
// [Category]  	Improvement
// [Description]  	adopting SDL to control timeout spec
// [Files]  		AMITSE.sdl, CommonHelper.c, protocol.c
// 
// 38    12/05/12 4:50a Arunsb
// [TAG]  		EIP107967
// [Category]  	Improvement
// [Description]  	Ami Post Management functionalities reliant on ConOut
// need checks added
// [Files]  		protocol.c
// 
// 37    10/18/12 5:59a Arunsb
// Updated for 2.16.1235 QA submission
// 
// 31    10/10/12 12:36p Arunsb
// Synched the source for v2.16.1232, backup with Aptio
// 
// 35    9/24/12 9:14a Premkumara
// [TAG]  		EIP 93797
// [Category]  	Improvement
// [Description] 	Add support to check for enabled device in BBS priority
// order before launching legacy boot.
// [Files]  		bbs.c, Boot.c, Protocol.c
// 
// 34    9/17/12 6:10a Rajashakerg
// Updated EIP changes for 2.16 release.
// 
// 32    8/27/12 6:21a Premkumara
// [TAG]  		EIP 94616
// [Category]  	Improvement
// [Description]  	TSE should not wait for key if fast boot is in progress
// [Files]  		AMITSE.sdl, CommonHelper.c, Notify.c, Protocol.c
// 
// 31    5/29/12 4:35a Arunsb
// [TAG]  		EIP91109
// [Category]  	Improvement
// [Description]  	Sync the Aptio IV source for AptioV
// 
// 30    5/28/12 5:52a Premkumara
// [TAG]  		EIP75236
// [Category]  	Improvement
// [Description]  	Add the support to control the GOP dependency in TSE
// notification.
// [Files]  		AMITSE.sdl, CommonHelper.c, Notify.c, Minisetup.h,
// Minisetup.sdl, protocol.c, FormBrowser.c, FormBrowser2.c
// 
// 29    4/27/12 10:25a Premkumara
// [TAG]  		EIP87769
// [Category]  	Bug Fix
// [Severity]  	Minor
// [Symptom]  	Strings are not cleared after calling
// PostManagerSwitchToPostScreen() function
// [RootCause]  	DoRealFlushLines() is not done in
// PostManagerSwitchToPostScreen() function
// [Solution]  	Updateed the PostManagerSwitchToPostScreen() function to
// perform DoRealFlushLines().
// [Files]  		Protocol.c
// 
// 28    4/04/12 12:27a Rajashakerg
// [TAG]  		EIP86253 
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	Mouse and SoftKbd does not work after displaying "No option
// to boot to" in POST
// [RootCause]  	Mouse timer cleared once after displaying the "No option
// to boot to" in POST
// [Solution]  	Mouse timer cleared only when its going to boot.
// [Files]  		CommonHelper.c, commonoem.c, minisetupext.c, protocol.c
// 
// 27    4/03/12 9:54a Premkumara
// [TAG]  		EIP84150
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	All the timers for mouse drivers before exiting from setup
// is not  stopped
// [RootCause]  	MouseDestroy() is not called StopPointingDevice()
// function to stop Mouse device
// [Solution]  	StopPointingDevice() function is called in MouseDestroy()
// function
// [Files]  		Mouse.c, Protocol.c, Ezport/StyleCommon.c,
// EzportPlus/StyleCommon.c, Legacy/StyleCommon.c, Minisetupext.c
// 
// 26    4/03/12 3:01a Premkumara
// [TAG]  		EIP84150
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	All the timers for mouse drivers before exiting from setup
// is not  stopped
// [RootCause]  	MouseDestroy() is not called StopPointingDevice()
// function to stop Mouse device
// [Solution]  	StopPointingDevice() function is called in MouseDestroy()
// function
// [Files]  		Mouse.c, Protocol.c, Ezport/StyleCommon.c,
// EzportPlus/StyleCommon.c, Legacy/StyleCommon.c, Minisetupext.c
// 
// 25    1/25/12 5:12a Rajashakerg
// [TAG]  		EIP81549 
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	BOOT_FLOW_NORMAL_INFINITE_LOOP enabled and pressing F7
// while displaying "No option to boot to" is not working properly
// [RootCause]  	When F7 key is pressed we have gBootFlow =
// BOOT_FLOW_CONDITION_BBS_POPUP, and returning from checkforkey() and the
// F7 key is not getting consumed and keeps on looping. 
// [Solution]  	Checking gBootFlow and making to normal in the loop.
// [Files]  		protocol.c
// 
// 24    12/30/11 1:51a Arunsb
// [TAG]  		EIP76721
// [Category]  	Bug Fix
// [Severity]  	Important
// [Symptom]  	BOOT_FLOW_NORMAL_INFINITE_LOOP option is not working
// properly
// [RootCause]  	Iterating variable reinitialized to 0 so in next loop it
// becoming 1 so its missing first boot option
// [Solution]  	Iterating vairable reinitialized to -1.
// [Files]  		Protocol.c
// 
// 23    11/21/11 5:48a Rajashakerg
// [TAG]  		EIP74591
// [Category]  	Improvement
// [Description]  	Make MainSetupLoop as board module hook
// [Files]  		AMITSE.sdl, CommonHelper.c, protocol.c, minisetup.h,
// FormBrowser.c, FormBrowser2.c
// 
// 22    11/20/11 7:19a Rajashakerg
// [TAG]  		EIP62763
// [Category]  	Improvement
// [Description]  	Utilize the Improvements done from mouse driver in
// AMITSE
// [Files]  		HookAnchor.h, TseCommon.h, AMITSE.sdl, CommonHelper.c,
// commonoem.c, commonoem.h, buffer.c, globals.c, HookAnchor.c,
// minisetup.h, notify.c, postmgmt.c, protocol.c, ezport.c, stylecommon.c,
// Mouse.c, Action.c, Date.c, frame.c, MessageBox.c, minisetupext.c,
// minisetupext.h, numeric.c, numeric.h, page.c, PopupEdit.c, PopupEdit.h,
// PopupPassword.c, postmgmtext.c, time.c.
// 
// 21    10/31/11 2:14p Premkumara
// [TAG]  		EIP73751 
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	L"BootFlow" variable uses inconsistent attributes
// [RootCause]  	L"BootFlow" variable uses inconsistent attributes in
// protocol.c
// [Solution]  	Made consistent use of L"Bootlow" variable with 
// EFI_VARIABLE_BOOTSERVICE_ACCESS attribute
// [Files]  		protocol.c
// 
// 20    9/29/11 7:02p Blaines
// [TAG] - EIP 66860
// [Category]- Function Request
// [Synopsis]- AmiPostManager interface for text entry.
// [Files] - LogoLib.h, AMIPostMgr.h, protocol.c, protocol.h,
// TseAdvanced.c, TseLitehelper.c, TseUefiHii.h, Uefi21Wapper.c
// 
// 19    6/23/11 7:38p Arunsb
// [TAG]           EIP57660 
// [Category]      New Feature
// [Description]   Non-removable media boot behavior as described in UEFI
//                 specification v 2.3.1, p. 3.4.1.
//                 Checks for the setup key if no boot options avail
//                 or not succedded to boot. If setup key pressed launches
// the setup.
//                 If no boot option avail then inserting thumb drive with
// image efi\boot\bootxxxx.efi TSE will launch that image.     
// [Files]         amitse.sdl, bootflow.c and protocol.c
// 
// 18    6/20/11 3:59p Arunsb
// [TAG]             EIP57660 
// [Category]       New Feature
// [Description]   Non-removable media boot behavior as described in UEFI
// specification v 2.3.1, p. 3.4.1.
//                       Checks for the setup key if no boot options avail
// or succedded to boot and launches the setup.
// [Files]             amitse.sdl, bootflow.c, bootflow.h, commonoem.c,
// boot.c and protocol.c
// 
// 17    1/06/11 1:58a Mallikarjunanv
// [TAG]  		EIP50479
// [Category]  	Bug Fix
// [Severity]  	Important
// [Symptom]  	Calls to PostManagerProtocol->SwitchToPostScreen() after
// legacy option ROM execution cause CPU exception.
// [RootCause]  	After the notification, if the graphics driver
// uninstalled and reinstalled from core module then gGOP is getting
// corrupted.
// [Solution]  	Updated the files, by making gGOP/gUgaDraw to NULL in the
// update function and in switch to posty screen returining status as
// aborted if the gGOP/gUgaDraw is NULL
// [Files]  		protocol.c,notify.c,postmgmt.c
// 
// 16    12/29/10 2:33a Mallikarjunanv
// [TAG]  		EIP50479
// [Category]  	Bug Fix
// [Severity]  	Important
// [Symptom]  	Calls to PostManagerProtocol->SwitchToPostScreen() after
// legacy option ROM execution cause CPU exception.
// [RootCause]  	After the notification, if the graphics driver
// uninstalled and reinstalled from core module then gGOP getting
// corrupted.
// [Solution]  	Updated gGop/Ugadraw before using it in AMITSE. 
// [Files]  		logo.c,minisetup.h, notify.c, postmgmt.c ,protocol.c
// 
// 15    12/02/10 1:07p Madhans
// [TAG] - EIP 41838  
// [Category]- Enhancement
// [Severity]- Mordarate
// [Symptom]- Update AMI Post Manager Protocol witht he following. 2.
// Updating the interface PostManagerDisplayPostMessageEx to handle the
// cursor position properly. 2. Need to add new interface to GetAttribute
// To keep the GetAttribute to end of protocol.
// [Rootcause] - 1. Display string is over written by the next string if
// the interface PostManagerDisplayPostMessageEx used simultaneously. 2.
// Need to get the attribute info to use PostManagerDisplayPostMessage
// interfaces effectively
// [Solution]- Fix in string.c to handle cursor and line positions. The
// files Protocol.c, Protocol.h and AmiPostMgr.h have the new interface
// implementaion to get the attribute.
// [Files] - Protocol.c, Protocol.h, AmiPostMgr.h and string.c
// 
// 14    11/16/10 8:56a Mallikarjunanv
// [TAG] - EIP 41838  
// [Category]- Enhancement
// [Severity]- Mordarate
// [Symptom]- Update AMI Post Manager Protocol witht he following. 2.
// Updating the interface PostManagerDisplayPostMessageEx to handle the
// cursor position properly. 2. Need to add new interface to GetAttribute
// [Rootcause] - 1. Display string is over written by the next string if
// the interface PostManagerDisplayPostMessageEx used simultaneously. 2.
// Need to get the attribute info to use PostManagerDisplayPostMessage
// interfaces effectively
// [Solution]- Fix in string.c to handle cursor and line positions. The
// files Protocol.c, Protocol.h and AmiPostMgr.h have the new interface
// implementaion to get the attribute.
// [Files] - Protocol.c, Protocol.h, AmiPostMgr.h and string.c
// 
// 13    10/05/10 6:41p Madhans
// [TAG] - EIP 45301  
// [Category]- Bug Fix
// [Severity]- Minor
// [Symptom]- when TSE_PRESERVE_DISABLED_BBS_DEVICE_ORDER is set disabling
// first device cause system not to boot.
// [Rootcause] - protocol.c was assuming disabled opens are coming in the
// End.
// [Solution]- Fix in protocol.c to handle this case.
// [Files] - protocol.c
// 
// 12    9/16/10 8:38p Madhans
// Update for TSE 2.10. Refer Changelog.log for more details.
// 
// 23    9/13/10 4:34p Madhans
// 1. To preserve FastBootflow condition before going to Boottimeout.
// 2. Preformance Calls optimized.
// 
// 22    9/13/10 12:11p Blaines
// Fix for the gPostMsgProtocolActive not being available past a certain
// point 
// 
// 21    9/08/10 6:53a Mallikarjunanv
// EIP-42080: TSE updates with respect to Fast Boot Support
// 
// 20    6/17/10 4:19p Madhans
// 
// 19    6/17/10 3:20p Blaines
// Added error checking to PostManagerDisplayQuietBootMessage()  for
// messages that are 0 in length. 
// 
// 18    6/14/10 7:06p Madhans
// 
// 17    4/02/10 4:34p Madhans
// 
// 16    3/30/10 4:45p Blaines
// Fix to prevent BBS Popup from being launched twice when selecting 
// ENTER_SETUP option
// 
// 15    3/23/10 5:09p Blaines
// Add PostManager Extentions
// 
// 14    2/19/10 8:14a Mallikarjunanv
// updated year in copyright message
// 
// 13    2/17/10 7:02p Madhans
// To support PrintQuiteBootmessage for UEFI 2.1
// 
// 12    2/15/10 10:12p Madhans
// To support Printquitebootmessage
// 
// 11    2/04/10 11:21p Madhans
// To remove Conout dependance
// 
// 10    2/04/10 12:10p Blaines
// Correct function header description for PostManagerSetAtribute.
// 
// 9     2/04/10 12:03p Blaines
// EIP-28005
// 
// Added PostManagerSetAttribute to support display of text in color.
// Added support for handling string characters --- \n, \r.
// 
// 8     1/09/10 5:35a Mallikarjunanv
// Updated TSE2.01 Release sources with coding standards
// 
// 7     12/14/09 12:21p Blaines
// Include EIP Comment
// 
// EIP 28007, FIX: If Post message printed in the Quiteboot by using Set
// cur position It is better to flash all the screen.
// 		
// 
// 6     10/28/09 5:37p Madhans
// 
// 5     9/17/09 9:04a Sudhirv
// Remove Load Driver Option from TSE 2.x as it will be handled from Core
// 
// 4     9/16/09 6:15p Madhans
// EIP 25416  : Support have 1/10 sec Timeout
// 
// 3     6/23/09 6:56p Blaines
// Coding standard update, 
// Remove spaces from file header to allow proper chm function list
// creation.
// 
// 2     6/12/09 7:41p Presannar
// Initial implementation of coding standards
// 
// 1     6/04/09 8:05p Madhans
// 
// 2     5/13/09 2:22p Madhans
// To patch the version number in the Bootonly TSE. update the build
// number.
// 
// 1     4/28/09 11:12p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 6     4/28/09 9:39p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 5     3/31/09 4:00p Madhans
// UEFI2.1
// 
// 4     2/05/09 5:19p Madhans
// PostMgrStatus interface added.
// 
// 3     2/05/09 10:15a Madhans
// Style Module created.
// 
// 2     1/30/09 6:06p Madhans
// Function headers added. 
// 
// 1     12/18/08 7:58p Madhans
// Intial version of TSE Lite sources
//*****************************************************************//
//*****************************************************************//

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		PROTOCOL.C
//
// Description:	This file contains code for TSE exported protocol
//              functions.
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include "minisetup.h"

UINT32 gBootFlow = BOOT_FLOW_CONDITION_NORMAL;

BOOLEAN gDoNotBoot = FALSE;
VOID StopClickEvent(VOID);//EIP-84150 Stopping ClickEvents

static EFI_HANDLE gProtocolHandle = NULL;
EFI_GUID gAmiPostManagerProtocolGuid = AMI_POST_MANAGER_PROTOCOL_GUID;
EFI_GUID gTSEInvalidateBgrtStatusProtocolGuid = TSE_INVALIDATE_BGRT_STATUS_PROTOCOL_GUID;

BOOLEAN TseIgnoreKeyForFastBoot(); //EIP-94616 Don't wait for key when FastBoot is Enabled
BOOLEAN GetBBSOptionStatus(BOOT_DATA *pBootData); //EIP-93797

static AMI_POST_MANAGER_PROTOCOL	gPostManagerProtocol =
{
	PostManagerHandshake,
	PostManagerDisplayPostMessage,
    PostManagerDisplayPostMessageEx,
    PostManagerDisplayQuietBootMessage,
    PostManagerDisplayMsgBox,
    PostManagerSwitchToPostScreen,
	PostManagerSetCursorPosition,
	PostManagerGetCursorPosition,
	PostManagerInitProgressBar,
	PostManagerSetProgressBarPosition,
	PostManagerGetPostStatus,
	PostManagerDisplayInfoBox,
	PostManagerSetAttribute,
	PostManagerDisplayMenu,
	PostManagerDisplayMsgBoxEx,
	PostManagerDisplayProgress,
	PostManagerGetAttribute, 	//EIP-41838: New interface added to get the attribute
    PostManagerDisplayTextBox 	//EIP-64877: New interface added to get the text input
};

//EIP 128665 starts
EFI_STATUS InvalidateBgrtStatusByProtocol (VOID);
TSE_INVALIDATE_BGRT_STATUS_PROTOCOL gInvalidateBgrtStatus = {InvalidateBgrtStatusByProtocol};
EFI_STATUS InstallInvalBGRTStatusProtocol (EFI_HANDLE Handle);
//EIP 128665 ends

EFI_STATUS ShowPostMsgBox(IN CHAR16  *MsgBoxTitle,IN CHAR16  *Message,IN UINT8  MsgBoxType, UINT8 *pSelection);


EFI_STATUS ShowPostMsgBoxEx(
	IN CHAR16			*Title,
 	IN CHAR16			*Message,
 	IN CHAR16			*Legend,
 	IN MSGBOX_EX_CATAGORY	 	MsgBoxExCatagory,
 	IN UINT8	 		MsgBoxType,
    	IN UINT16			*OptionPtrTokens,	// Valid only with MSGBOX_TYPE_CUSTOM 
    	IN UINT16	 		OptionCount,		// Valid only with MSGBOX_TYPE_CUSTOM
    	IN AMI_POST_MGR_KEY		*HotKeyList, 		// NULL - AnyKeyPress closes
    	IN UINT16 			HotKeyListCount, 
    	OUT UINT8			*MsgBoxSel,
    	OUT AMI_POST_MGR_KEY		*OutKey
	);
EFI_STATUS ShowInfoBox(IN CHAR16  *InfoBoxTitle, IN CHAR16  *Message, IN UINTN   TimeLimit, EFI_EVENT  *RetEvent);

EFI_STATUS HiiString2BltBuffer(	CHAR16 *Message,
								EFI_UGA_PIXEL Foreground, 
								EFI_UGA_PIXEL Background, 
								OUT	UINTN *Width,
								OUT EFI_UGA_PIXEL **BltBuffer,
								OUT UINTN *BltGlyphWidth);
EFI_STATUS DrawHiiStringBltBuffer(CHAR16 *Message, INTN CoOrdX, INTN CoOrdY, CO_ORD_ATTRIBUTE Attribute, EFI_UGA_PIXEL Foreground, EFI_UGA_PIXEL Background);
EFI_STATUS ShowPostMenu (
    IN VOID	*HiiHandle, 	
    IN UINT16 	TitleToken, 
    IN UINT16 	LegendToken,	  
    IN POSTMENU_TEMPLATE *MenuData,
    IN UINT16 	MenuCount,
    OUT UINT16  *pSelection
);

EFI_STATUS ShowPostTextBox(
    IN VOID	    *HiiHandle, 	
    IN UINT16 	TitleToken, 
    IN TEXT_INPUT_TEMPLATE *InputData,
    IN UINT16 	ItemCount,
    IN DISPLAY_TEXT_KEY_VALIDATE DisplayTextKeyValidate
);

EFI_STATUS ShowPostProgress(
    IN UINT8			ProgressBoxState, 
    IN CHAR16			*Title,
    IN CHAR16			*Message,
    IN CHAR16			*Legend,	
    IN UINTN 			Percent,	
    IN OUT VOID			**Handle,	
    OUT AMI_POST_MGR_KEY	*OutKey
);
BOOLEAN   	IsTseBestTextGOPModeSupported (VOID);
EFI_STATUS	SaveCurrentTextGOP ( UINTN *currenttextModeCols, UINTN *currenttextModeRows, UINT32 *currentGOPMode ); //EIP-107833 Fixing proper mode and resolution for post interfaces
EFI_STATUS	RestoreTextGOPMode ( UINTN prevTextModeCols, UINTN prevTextModeRows, UINT32 prevGOPMode ); //EIP-107833 Fixing proper mode and resolution for post interfaces

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	InstallProtocol
//
// Description:	This function installs different protocols exported.
//
// Input:		VOID
//
// Output:		Return Status based on errors that occurred in library
//              functions.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS InstallProtocol( VOID )
{
	EFI_STATUS Status;

	Status = gBS->InstallMultipleProtocolInterfaces(
			&gProtocolHandle,
			&gAmiPostManagerProtocolGuid, &gPostManagerProtocol,
#ifdef USE_COMPONENT_NAME
			&gEfiComponentNameProtocolGuid, &gComponentName,
#endif
			NULL
			);
	if ( !EFI_ERROR( Status ) )
	{
		Status = InstallFormBrowserProtocol(gProtocolHandle);
		Status = InstallInvalBGRTStatusProtocol (gProtocolHandle);
	}

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	UninstallProtocol
//
// Description:	This function uninstalls different protocols exported.
//
// Input:		VOID
//
// Output:		VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID UninstallProtocol( VOID )
{
	gBS->UninstallMultipleProtocolInterfaces(
			&gProtocolHandle,
			&gAmiPostManagerProtocolGuid, &gPostManagerProtocol,
#ifdef USE_COMPONENT_NAME
			&gEfiComponentNameProtocolGuid, &gComponentName,
#endif
			NULL
			);

	UnInstallFormBrowserProtocol(gProtocolHandle);

}

VOID SetBootTimeout( EFI_EVENT Event, BOOLEAN *timeout )
{
	if ( timeout != NULL )
		*timeout = TRUE;
}

VOID AboartFastBootPath(VOID)
{
	gBootFlow = BOOT_FLOW_CONDITION_NORMAL;
	gPostManagerHandshakeCallIndex--;
    gRT->SetVariable(
    			L"BootFlow",
    			&_gBootFlowGuid,
    			EFI_VARIABLE_BOOTSERVICE_ACCESS,
    			sizeof(gBootFlow),
    			&gBootFlow
    			);
}
BOOLEAN IsBootTimeOutValueZero(VOID);
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerHandshake
//
// Description:	This function is the handshake function to which BDS
//              hands-off.
//
// Input:		VOID
//
// Output:		This function never returns. It only boots different
//              options.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerHandshake( VOID )
{
	EFI_EVENT timer = NULL;
	EFI_STATUS Status = EFI_UNSUPPORTED;

	volatile BOOLEAN bootTimeout = FALSE;
	UINT16  Value = 1;
    UINT64  TimeoutValue;
	UINTN   size = 0;
	EFI_GUID    AmitseAfterFirstBootOptionGuid = AMITSE_AFTER_FIRST_BOOT_OPTION_GUID;
	EFI_GUID AmiTseBeforeTimeOutGuid = AMITSE_BEFORE_TIMEOUT_GUID;
	EFI_GUID AmiTseAfterTimeOutGuid = AMITSE_AFTER_TIMEOUT_GUID;
	BOOLEAN AfterFirstBootSignalled = FALSE;
	UINT16  *pBootOrder=NULL;
    UINT16  u16BootCount = 0,i;				//Dont change i data type, in infinite loop it is reinitialized to -1.
    UINT16  BootNext, *pBootNext = NULL;

	// Performance measurement starta
	PERF_START (0, AMITSE_TEXT("Boot"), NULL, 0);

	RUNTIME_DEBUG( L"mre" );

	gPostManagerHandshakeCallIndex++;

	if(gPostManagerHandshakeCallIndex!=1)
	{
		gEnterSetup = TRUE;
		goto _ShowMainMenu;
	}

    PostManagerHandShakeHookHook();

#ifndef STANDALONE_APPLICATION
	if ( ! gConsoleControl )
	{
		//All necessary protocols are not available yet.
		//We can still proceed if Uga Draw is the only protocol not available yet.
		ActivateApplication();
		//EIP-75236 
		if (!IsDelayLogoTillInputSupported())
			ActivateInput();
	}
#endif

    if(!gVariableList)
        VarLoadVariables( (VOID **)&gVariableList, NULL );

	TimerStopTimer( &gKeyTimer );

	// this *MUST* be run a EFI_TPL_APPLICATION
	gBS->RaiseTPL( EFI_TPL_HIGH_LEVEL );	// guarantees that RestoreTPL won't ASSERT
	gBS->RestoreTPL( EFI_TPL_APPLICATION );

	// Performance measurement Pause
//	PERF_END (0,L"Boot", NULL, 0);
	// Exclude IDEPasswordCheck IDEPasswordCheck that it may get the use input.
	// IDE password Module takes care of the Password check.
	//TSEIDEPasswordCheck(); 

	// Performance measurement continue
//	PERF_START (0, L"Boot", NULL, 0);    

    // get the current boot options and languages
	BootGetBootOptions();
	BootGetLanguages();

	StyleUpdateVersionString();

	gPostStatus = TSE_POST_STATUS_IN_BOOT_TIME_OUT;

	//EIP 103381 - Providing boot time out value depending on TSE_BOOT_TIME_OUT_AS_ZERO token
	if(!IsBootTimeOutValueZero())
		Value = GetBootTimeOut(Value);
	else
		Value = 0;

#ifdef STANDALONE_APPLICATION
    Value = 0;
    gEnterSetup = TRUE;
#endif

	if ( Value == 0 )
		bootTimeout = TRUE;

	if ( !TseIgnoreKeyForFastBoot() ) //EIP-94616
	{
		CheckForKeyHook( (EFI_EVENT)NULL, NULL );
	}

    if((BOOT_FLOW_CONDITION_NORMAL != gBootFlow) || (gEnterSetup==TRUE))
    {
        UINT32 condition = BOOT_FLOW_CONDITION_NORMAL;
        UINT32 *conditionPtr;

        size = 0;
        conditionPtr = VarGetNvramName( L"BootFlow", &_gBootFlowGuid, NULL, &size );
        if ( conditionPtr != NULL )
        	condition = *conditionPtr;
        
        MemFreePointer( (VOID **)&conditionPtr );

		if((condition == BOOT_FLOW_CONDITION_FAST_BOOT) && ((gBootFlow != condition)||(gEnterSetup==TRUE)))
		{
			// Take the Normal boot path as Fast boot path is altered by CheckForKeyHook().
			AboartFastBootPath();
			return EFI_UNSUPPORTED;
		}

        if(BOOT_FLOW_CONDITION_NORMAL == condition)
        {
            gRT->SetVariable(
    					L"BootFlow",
    					&_gBootFlowGuid,
    					EFI_VARIABLE_BOOTSERVICE_ACCESS,//EIP-73751 BootFlow wil use RS attribute to avoid inconsistent attributes
    					sizeof(UINT32),
    					&gBootFlow
    					);
        }
        else
            gBootFlow = BOOT_FLOW_CONDITION_NORMAL;
    }

	Status = BootFlowManageEntry();
	if (Status == EFI_UNSUPPORTED)
    {
        Value = 0xFFFF;
        gDoNotBoot = TRUE;
    }
	if(Status == EFI_NOT_STARTED)
		bootTimeout = TRUE;

	if(gBootFlow == BOOT_FLOW_CONDITION_FAST_BOOT)
	{
		UINT32 PasswordInstalled = PasswordCheckInstalled();
		
		if((gPasswordType == AMI_PASSWORD_NONE) && (PasswordInstalled != AMI_PASSWORD_NONE))
		{
			if(CheckSystemPasswordPolicy(PasswordInstalled))
			{
				// Take the Normal boot path as Password is installed and not validated by the user yet
				AboartFastBootPath();
				return EFI_UNSUPPORTED;
			}
		}
	}
    else
    {
	// Reinit Before Boottimeout So any action can set the boot flow again.
	gBootFlow = BOOT_FLOW_CONDITION_NORMAL;
    }

	if ( Value != 0xFFFF )
    {
        TimeoutValue = (UINT64) TIMER_TENTH_SECOND;
        TimeoutValue = MultU64x32( TimeoutValue, (UINT32) Value );

        TimerCreateTimer( &timer, SetBootTimeout, (VOID *)&bootTimeout, TimerRelative, TimeoutValue, EFI_TPL_CALLBACK );
    }

	// Performance measurement Pause
	PERF_END (0, AMITSE_TEXT("Boot"), NULL, 0);

	// While the boot timeout has not expired
	EfiLibNamedEventSignal (&AmiTseBeforeTimeOutGuid);
	while ( ! bootTimeout )
	{
		if ( gEnterSetup || gBootFlow )
		{
			bootTimeout = TRUE;
            continue;
		}
		if ( !TseIgnoreKeyForFastBoot() ) //EIP-94616
		{
			// check for 'hotkey' actions that would invoke something
			CheckForKeyHook( (EFI_EVENT)NULL, NULL );
		}

        TimeOutLoopHookHook();
	}
	EfiLibNamedEventSignal (&AmiTseAfterTimeOutGuid);

	// Performance measurement continue
	PERF_START (0, AMITSE_TEXT("Boot"), NULL, 0);

	TimerStopTimer( &timer );

    if ((!gDoNotBoot) && (gBootFlow))
    {
        gRT->SetVariable(
					L"BootFlow",
					&_gBootFlowGuid,
					EFI_VARIABLE_BOOTSERVICE_ACCESS,//EIP-73751 BootFlow wil use RS attribute to avoid inconsistent attributes
					sizeof(UINT32),
					&gBootFlow
					);
        BootFlowManageEntry();
    }

_ShowMainMenu:

	if ( gEnterSetup )
	{
    	// Performance measurement Pause
    	PERF_END (0, AMITSE_TEXT("Boot"), NULL, 0);
    	// Disable access to the post manager protocol display post message functions and to 
        //  the switch to post screen functions of post manager protocol
    	gPostMsgProtocolActive = FALSE;

		gPostStatus = TSE_POST_STATUS_ENTERING_TSE;
		gSetupContextActive = TRUE;

		Status = gST->ConIn->Reset( gST->ConIn, FALSE );
		Status = MainSetupLoopHook();//EIP74591 : Modified MainSetupLoop as board module hook
		gSetupContextActive = FALSE;
		

    	// Reenable access to the post manager protocol display post message functions and to 
        //  the switch to post screen functions of post manager protocol
    	gPostMsgProtocolActive = TRUE;
    	// Performance measurement continue
    	PERF_START (0, AMITSE_TEXT("Boot"), NULL, 0);
	}


	if(gPostManagerHandshakeCallIndex!=1)
	{
		// In case of not a first call
		// Don't do the Boot Manager Work just exit the to caller.
		gPostManagerHandshakeCallIndex--;
		return Status;
	}

	// Pass control to the boot process to handle the selected boot option
	// if the boot is allowed
    if (gDoNotBoot)
   {
		if(!ItkSupport())
		{
			gEnterSetup = TRUE;
			goto _ShowMainMenu;
		}
		else
			gEnterSetup = FALSE;
    }

	if(!NoVarStoreSupport())
	{
		size = 0;
		//VarGetNvram( VARIABLE_ID_AMITSESETUP, &size );
		HelperGetVariable( VARIABLE_ID_AMITSESETUP, (CHAR16 *)NULL, (EFI_GUID *)NULL, NULL, &size );
	
		if(size < sizeof(AMITSESETUP))
		{
			Status = MiniSetupEntry();
			MiniSetupExit( Status );
		}
	}

	gPostStatus = TSE_POST_STATUS_PROCEED_TO_BOOT;

	// LoadDriverOrder();	//EIP: 25799 - Remove Load Driver Option from TSE 2.x as it is handling from Core.

    ProcessProceedToBootHook();

    TSEUnlockHDD();

	if(ItkSupport())
	    BbsItkBoot();
	else
	{
	    //Try boot next first
	    size = 0;
	    pBootNext = (UINT16 *)VarGetNvramName(L"BootNext", &gEfiGlobalVariableGuid, NULL, &size);
	    if(pBootNext && (size == sizeof(UINT16)))
	    {
	        BootNext = *pBootNext;
	        //Clear Boot next
	        VarSetNvramName(L"BootNext",
	                        &gEfiGlobalVariableGuid,
	                        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
	                        pBootNext,
	                        0);
	        if( gBootFlow == BOOT_FLOW_CONDITION_FAST_BOOT) { 
				// FastBoot module normally checks for Bootnext before taking the FastBoot path
				// If the Boot next is set in FastBoot case then do the full boot.
				    AboartFastBootPath();
					return Status;
				}
			else {
				BootLaunchBootOption(BootNext, NULL, 0);
			}
		}
	
	
	    if(pBootNext)
	        MemFreePointer((void **) &pBootNext);
	
	    size =0 ;
	    pBootOrder = (UINT16 *)VarGetNvramName( L"BootOrder", &gEfiGlobalVariableGuid, NULL, &size );
	
	#ifdef EFI_NT_EMULATOR
	    if(!pBootOrder || !gBootData)
	    {
	        VarSetNvramName(L"BootOrder",
	        &gEfiGlobalVariableGuid,
	        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
	        NULL,
	        0);
	
	        return Status;
	    }
	#endif
	
	    //Get enabled options count
	    for(u16BootCount=0; u16BootCount<(UINT16)(size/sizeof(UINT16)); u16BootCount++ )
	    {
            if(!IsPreservedDisabledBootOptionOrder())
            {
    	        BOOT_DATA *pBootData;

	            pBootData = BootGetBootData(pBootOrder[u16BootCount]);
	            if(!(pBootData->Active & LOAD_OPTION_ACTIVE))
	                break;
            }
	    }
	
		if(!u16BootCount)
	    {
	        //No valid/enabled boot option
			Status = BootFlowManageExit();
	            //infinite loop
	            while(EFI_NOT_STARTED == Status)
	            {
                    CHAR16 *text = NULL;
                    
                    text = HiiGetString( gHiiHandle, STRING_TOKEN(STR_NO_BOOT_OPTIONS));
                    if ( ( text != NULL ) && (gST->ConOut != NULL))
                    gST->ConOut->OutputString(gST->ConOut, text);
                    
                    //Wait for key
                    gBS->WaitForEvent( 1, &gST->ConIn->WaitForKey, &size );
                    CheckForKeyHook( (EFI_EVENT)NULL, NULL );
                    if (TRUE == gEnterSetup)                          //If setup key detects then launch the setup
                    {
                        goto _ShowMainMenu;
                    }
                    Status = BootFlowManageExit ();                 //EIP: 57660 Condition: If user plugs the any thumb drive after boot then TSE will try to launch the image from that file system using the path efi\boot\bootxxxx.efi
					if( gBootFlow )//EIP 81549 : Checking for gBootFlow, making gBootFlow to normal such that the key will be consumed in chcekforkey
						gBootFlow = BOOT_FLOW_CONDITION_NORMAL;
	            }
	    }
	
		if ( !gEnterSetup )//EIP-86253  If no key is pressed to go to setup then stopping MousePointingDevice and stopping ClickEvents
		{
			StopClickEvent();
			MouseDestroy();
		}
	    for ( i = 0; i < u16BootCount; i++)
	    {
	        BOOT_DATA *pBootData;

	        pBootData = BootGetBootData(pBootOrder[i]);

  	        if(pBootData == NULL || !(pBootData->Active & LOAD_OPTION_ACTIVE))
                continue;

			if ( BBSValidDevicePath(pBootData->DevicePath) ) //EIP-93797
				if ( GetBBSOptionStatus (pBootData) )
					continue;

	        Status = BootLaunchBootOption(pBootOrder[i], pBootOrder+i, u16BootCount - i);
	
	        if ( !AfterFirstBootSignalled )
			{
				EfiLibNamedEventSignal ( &AmitseAfterFirstBootOptionGuid );

				if( gBootFlow == BOOT_FLOW_CONDITION_FAST_BOOT) {
				    AboartFastBootPath();
					return Status;
				}	

				AfterFirstBootSignalled = TRUE;
			}
	
	        if((i+1) >= u16BootCount)
	        {
	            Status = BootFlowManageExit();
	            if ( EFI_NOT_STARTED == Status )
				{
                    CheckForKeyHook( (EFI_EVENT)NULL, NULL );
                    if (TRUE == gEnterSetup)                          //If setup key detects then launch the setup
                    {
                        goto _ShowMainMenu;
                    }
					// Infinite loop is true so we start again
					i = -1;											//Changed 0 to -1. Then only in next iteration it will be zero otherwise it will be 1.
				}													//If it is i = 0 then it will miss first boot option
	        }
	    }

	}
#ifndef STANDALONE_APPLICATION
    gEnterSetup = TRUE;
    goto _ShowMainMenu;
#else
	return Status;
#endif

}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerDisplayPostMessage
//
// Description:	This function is the protocol to display messages in
//              the post screen.
//
// Input:		CHAR16 *message: Unicode string to be displayed.
//
// Output:		Return Status based on errors that occurred in library
//              functions.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerDisplayPostMessage( CHAR16 *message )
{
	if ( ! gPostMsgProtocolActive )
		return EFI_UNSUPPORTED;

	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	return PrintPostMessage(message, TRUE);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerDisplayPostMessageEx
//
// Description:	This function is the protocol to display messages with
//              attributes in the post screen.
//
// Input:		CHAR16 *message: Unicode string to be displayed.
//              UINTN Attribute: Attribute for the message
//
// Output:		Return Status based on errors that occurred in library
//              functions.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerDisplayPostMessageEx( CHAR16 *message, UINTN Attribute )
{
	if ( ! gPostMsgProtocolActive )
		return EFI_UNSUPPORTED;

	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	switch(Attribute)
    {
        case PM_EX_DONT_ADVANCE_TO_NEXT_LINE:
            return PrintPostMessage(message, FALSE);
    }

    return EFI_UNSUPPORTED;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerSwitchToPostScreen
//
// Description:	This function is the protocol to switch to post screen
//
// Input:		VOID
//
// Output:		Return Status based on errors that occurred in library
//              functions.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerSwitchToPostScreen( VOID )
{
#ifdef STANDALONE_APPLICATION
	return EFI_UNSUPPORTED;
#else
	if ( ! gPostMsgProtocolActive )
		return EFI_UNSUPPORTED;

    if ( gQuietBoot )
	{
		UpdateGoPUgaDraw();//EIP:50479 : Function to Update gGop before using it in AMITSE.
#if SETUP_USE_GRAPHICS_OUTPUT_PROTOCOL
      if (!gGOP)
#else
      if (!gUgaDraw)
#endif
		 return EFI_UNSUPPORTED;//EIP:50479 : Returning unsupported if the GOP is NULL
	
		gQuietBoot = FALSE;
		CleanUpLogo();
		//EIP 28007, FIX: If Post message printed in the Quiteboot by using Set cur position
		// It is better to flash all the screen.
		FlushLines( 0, gMaxRows - 1 );
		DoRealFlushLines(); //EIP-87769
		InitPostScreen();
        return EFI_SUCCESS;
	}

    return EFI_UNSUPPORTED;
#endif
}
//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerInitProgressBar
//
// Description:  Initializes the PostManagerProgressBar
//
// Input:		 UINTN x - Column or Left screen position of ProgressBar in pixels
//				 UINTN y - Row or Top screen position of ProgressBar in pixels
//				 UINTN w - Width of ProgressBar in pixels
//				 UINTN h - Height of ProgressBar in pixels
//				 UINTN iterate - Total number of iterations or Calls
//								 to advanced the progressbar to 100% of the given width.
//								 The delta or changed value will be computed.								 
//
// Output:		 EFI_STATUS status - If the function runs correctly, returns
//				 EFI_SUCCESS, else other EFI defined error values.
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PostManagerInitProgressBar(
	UINTN x,
	UINTN y,
	UINTN w,
	UINTN h,
	UINTN iterate)
{
	EFI_STATUS Status = 0; 

	EFI_UGA_PIXEL	*BGColor;
	EFI_UGA_PIXEL	*BDRColor;
	EFI_UGA_PIXEL	*FillColor;
		
	BGColor = EfiLibAllocateZeroPool(sizeof (EFI_UGA_PIXEL));
	BDRColor = EfiLibAllocateZeroPool(sizeof (EFI_UGA_PIXEL));
	FillColor = EfiLibAllocateZeroPool(sizeof (EFI_UGA_PIXEL));
	
	GetProgressColor(BGColor,BDRColor,FillColor);

	gProgress->delta = w/iterate;
	gProgress->w = gProgress->delta*iterate;
	gProgress->h = h;
	gProgress->x = x;
	gProgress->y = y;
	gProgress->backgroundColor = BGColor;
	gProgress->borderColor = BDRColor;
	gProgress->fillColor = FillColor;
	gProgress->quiteBootActive = FALSE ;
	gProgress->active = TRUE ;         // progressbar has been initialized
	
	return Status;
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerSetProgressBarPosition
//
// Description:  Increments the PostManagerProgressBar
//
// Input:		 None
//				 
//
// Output:		 EFI_STATUS status - If the function runs correctly, returns
//				 EFI_SUCCESS, else other EFI defined error values.
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PostManagerSetProgressBarPosition()
{
	EFI_STATUS Status = EFI_SUCCESS;
	if(gProgress->active)
		DrawBltProgressBar();
	else
		Status = EFI_UNSUPPORTED;
			
	return Status;
}



	
//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerSetCursorPosition
//
// Description:  Wrapper function for SetCurPos
//
// Input:		 UINTN X - Value of the column 
//				 UINTN Y - Number of row below the last written line
//
// Output:		 EFI_STATUS status - If the function runs correctly, returns
//				 EFI_SUCCESS, else other EFI defined error values.
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PostManagerSetCursorPosition(UINTN X, UINTN Y)
{
	return SetCurPos(X,Y);
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerGetCursorPosition
//
// Description:  Wrapper function for GetCurPos
//               Writes cursor position into given X and Y locations.
//
// Input:    UINTN *pX - Pointer to storage for current column value 
//			 UINTN *pY - Pointer to storage for current row value
//
// Output: EFI_STATUS status - EFI_SUCCESS if OK,
//                             EFI_INVALID_PARAMETER if NULL pointer
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>

EFI_STATUS PostManagerGetCursorPosition(UINTN *pX, UINTN *pY)
{
	return GetCurPos(pX, pY);
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerDisplayMsgBox
//
// Description:  
// 
//
// Input:    IN CHAR16  *MsgBoxTitle,
//    		IN CHAR16  *Message,
//    		IN UINT8   MsgBoxType,
//
// Output: EFI_STATUS status and UINT8 MsgBoxSel
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID SaveGraphicsScreen(VOID);
VOID RestoreGraphicsScreen(VOID);
EFI_STATUS
PostManagerDisplayMsgBox (
    IN CHAR16  *MsgBoxTitle,
    IN CHAR16  *Message,
    IN UINT8   MsgBoxType,
    OUT UINT8  *MsgBoxSel
	)
{
	UINTN currenttextModeCols = 0, currenttextModeRows = 0;
	UINT32 currentGOPMode = 0;
	
	EFI_STATUS Status = EFI_UNSUPPORTED;

	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	if( gPostStatus == TSE_POST_STATUS_IN_POST_SCREEN )
		SaveGraphicsScreen();

	Status = SaveCurrentTextGOP (&currenttextModeCols, &currenttextModeRows, &currentGOPMode);
	if (EFI_ERROR(Status))
		return Status;

	Status = ShowPostMsgBox(MsgBoxTitle, Message, MsgBoxType,MsgBoxSel);

	RestoreTextGOPMode (currenttextModeCols, currenttextModeRows, currentGOPMode);

	if( gPostStatus == TSE_POST_STATUS_IN_POST_SCREEN )
		RestoreGraphicsScreen();

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerDisplayQuietBootMessage
//
// Description:	Function for the quit booting display.
//
// Input:	CHAR16 *Message, INTN CoOrdX, INTN CoOrdY,
//					CO_ORD_ATTRIBUTE Attribute, EFI_UGA_PIXEL Foreground,
//					EFI_UGA_PIXEL Background
//
// Output:	Status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
PostManagerDisplayQuietBootMessage(
    CHAR16 *Message,
    INTN CoOrdX,
    INTN CoOrdY,
    CO_ORD_ATTRIBUTE Attribute,
    EFI_UGA_PIXEL Foreground,
    EFI_UGA_PIXEL Background
    )
{
#ifdef STANDALONE_APPLICATION
	return EFI_UNSUPPORTED;
#elif defined TSE_FOR_APTIO_4_50
    UINTN BltGlyphWidth=0;
    EFI_UGA_PIXEL *BltBuffer=NULL;
    UINTN BltIndex;
    EFI_STATUS Status = EFI_SUCCESS;
    UINTN SizeOfX, SizeOfY;

	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

    UpdateGoPUgaDraw();//EIP:50479 : Function to Update gGop before using it in AMITSE.
    if(EFI_SUCCESS != HiiInitializeProtocol())
        return EFI_UNSUPPORTED;

    if(
        (EFI_SUCCESS != GetScreenResolution(&SizeOfX, &SizeOfY))||
        (!gQuietBoot)
        )
        return EFI_UNSUPPORTED;

    if ((Message != NULL) && (EfiStrLen(Message) == 0)) 
		return EFI_SUCCESS;
    BltIndex = 0;

	Status = HiiString2BltBuffer(Message,Foreground,Background,&BltIndex,&BltBuffer,&BltGlyphWidth);
	if(Status == EFI_SUCCESS)
	    DrawBltBuffer(BltBuffer, Attribute, BltIndex, HiiGetGlyphHeight(), CoOrdX, CoOrdY, BltGlyphWidth);

    //Free BltBuffer
    MemFreePointer((VOID **)&BltBuffer);

    return Status;
#else
// For EDK Nt32 support.
//    Status = DrawHiiStringBltBuffer(Message, CoOrdX, CoOrdY, Attribute, Foreground, Background);
	return EFI_UNSUPPORTED;
#endif
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerGetPostStatus
//
// Description:	Function returns current Post status.
//
// Input:		none
//
// Output:		One of the TSE_POST_STATUS
// 					TSE_POST_STATUS_BEFORE_POST_SCREEN 	- TSE Loaded and yet goto post screen
// 					TSE_POST_STATUS_IN_POST_SCREEN		- In the post screen
// 					TSE_POST_STATUS_IN_QUITE_BOOT_SCREEN- In the quite boot screen
// 					TSE_POST_STATUS_IN_BOOT_TIME_OUT	- Witing for Boot timeout
// 					TSE_POST_STATUS_ENTERING_TSE		- Entering TSE
// 					TSE_POST_STATUS_IN_TSE				- Inside TSE
// 					TSE_POST_STATUS_IN_BBS_POPUP		- Inside BBS Poupup
// 					TSE_POST_STATUS_PROCEED_TO_BOOT		- Outside TSE and Booting or in Shell
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
TSE_POST_STATUS	PostManagerGetPostStatus(VOID)
{
	return gPostStatus;
}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PostManagerDisplayInfoBox
//
// Description:	Function to display the Information box
//
// Input:		none
//
// Output:		One of the TSE_POST_STATUS
// 					TSE_POST_STATUS_BEFORE_POST_SCREEN 	- TSE Loaded and yet goto post screen
// 					TSE_POST_STATUS_IN_POST_SCREEN		- In the post screen
// 					TSE_POST_STATUS_IN_QUITE_BOOT_SCREEN- In the quite boot screen
// 					TSE_POST_STATUS_IN_BOOT_TIME_OUT	- Witing for Boot timeout
// 					TSE_POST_STATUS_ENTERING_TSE		- Entering TSE
// 					TSE_POST_STATUS_IN_TSE				- Inside TSE
// 					TSE_POST_STATUS_IN_BBS_POPUP		- Inside BBS Poupup
// 					TSE_POST_STATUS_PROCEED_TO_BOOT		- Outside TSE and Booting or in Shell
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
PostManagerDisplayInfoBox(	IN CHAR16		*InfoBoxTitle,
							IN CHAR16		*InfoString,
							IN UINTN		Timeout,
							OUT EFI_EVENT	*Event
						 )
{
	UINTN currenttextModeCols = 0, currenttextModeRows = 0;
	UINT32 currentGOPMode = 0;
	EFI_STATUS Status = EFI_SUCCESS;

	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	Status = SaveCurrentTextGOP (&currenttextModeCols, &currenttextModeRows, &currentGOPMode);

	if ( EFI_ERROR(Status) )
		return Status;

	Status = ShowInfoBox(InfoBoxTitle, InfoString, Timeout, Event);

	RestoreTextGOPMode (currenttextModeCols, currenttextModeRows, currentGOPMode);

	return Status;

}


//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     	PostManagerSetAtribute
//
// Description:  	Function to set color
//
// Input:		UINT8 Attrib - Text color 
//			 
//
// Output:		EFI_STATUS status - If the function runs correctly, returns
//			EFI_SUCCESS, else other EFI defined error values.
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerSetAttribute(UINT8 Attrib)
{
	gPostMgrAttribute = Attrib ;
	return EFI_SUCCESS ;
}
//EIP-41838: New interface to get the attribute using AMI Post Manager Protocol
//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     	PostManagerGetAttribute
//
// Description:  	Function to Get color
//
// Input:		UINT8 *Attrib - Pointer to get Text color 
//			 
//
// Output:		EFI_STATUS status - If the function runs correctly, returns
//			EFI_SUCCESS, else other EFI defined error values.
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerGetAttribute(UINT8 *Attrib)
{
	*Attrib = gPostMgrAttribute ;
	return EFI_SUCCESS ;
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerDisplayMsgBoxEx
//
// Description:  Wrapper function for Display OEM Message box. 
//               
//
// Input:    IN CHAR16  *MsgBoxTitle - Caption of the Message Box
//			 IN CHAR16  *Message	 - String to be displayed by the Message Box
//			 IN CHAR16  *Legend		 - Legend String to be displayed by the Message Box
//			 IN UINT8   MsgBoxType   - Message Box type
//
// Output: EFI_STATUS status - EFI_SUCCESS if OK,
//                             EFI_INVALID_PARAMETER if NULL pointer
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerDisplayMsgBoxEx (
    IN CHAR16			*Title,
    IN CHAR16			*Message,
    IN CHAR16			*Legend,
    IN MSGBOX_EX_CATAGORY	MsgBoxExCatagory,
    IN UINT8	 		MsgBoxType,
    IN UINT16			*OptionPtrTokens,	// Valid only with MSGBOX_TYPE_CUSTOM 
    IN UINT16	 		OptionCount,		// Valid only with MSGBOX_TYPE_CUSTOM
    IN AMI_POST_MGR_KEY		*HotKeyList, 		// NULL - AnyKeyPress closes
    IN UINT16 			HotKeyListCount, 
    OUT UINT8			*MsgBoxSel,
    OUT AMI_POST_MGR_KEY	*OutKey
)
{
	UINTN currenttextModeCols = 0, currenttextModeRows = 0;
	UINT32 currentGOPMode = 0;
	EFI_STATUS Status = EFI_SUCCESS;
	
	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	Status = SaveCurrentTextGOP (&currenttextModeCols, &currenttextModeRows, &currentGOPMode);

	if ( EFI_ERROR(Status) )
		return Status;

	Status = ShowPostMsgBoxEx (Title, Message, Legend, MsgBoxExCatagory,
										MsgBoxType, OptionPtrTokens, OptionCount,
										HotKeyList, HotKeyListCount, MsgBoxSel, OutKey
										);

	RestoreTextGOPMode (currenttextModeCols, currenttextModeRows, currentGOPMode);

	return Status;
}
//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerDisplayProgress
//
// Description:  Wrapper function for Display OEM Message box. 
//               
//
// Input:    IIN UINTN Percent  - Percent Complete
//
// Output: EFI_STATUS status - EFI_SUCCESS if OK,
//                             EFI_INVALID_PARAMETER if NULL pointer
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerDisplayProgress (
    IN UINT8	ProgressBoxState, 
    IN CHAR16	*Title,
    IN CHAR16	*Message,
    IN CHAR16	*Legend,
    IN UINTN 	Percent,	// 0 - 100
    IN OUT VOID	**Handle,	//Out HANDLE. Valid Handle for update and close
    OUT AMI_POST_MGR_KEY	*OutKey	//Out Key 
)
{
	EFI_STATUS Status = EFI_UNSUPPORTED;
	
	if (NULL == gST->ConOut)
		return EFI_NOT_READY;
		
	Status =  ShowPostProgress( ProgressBoxState, Title, Message, Legend, Percent, Handle, OutKey) ;
	return Status ;
}
//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	PostManagerDisplayMenu
//
// Description:	Wrapper function for Display Menu. 
//               
//
// Input:    	IN VOID	*HiiHandle, 		- Handle that contains String
//    		IN UINT16 	TitleToken,     - Menu Title Token
//    		IN UINT16 	LegendToken,	- Menu Legend Token  
//    		IN POSTMENU_TEMPLATE *MenuData, - Menu Items to be displayed 
//    		IN UINT16 	MenuCount,	- Number of Menu items
//    		OUT UINT16  *pSelection		- Menu selection (DEFAULT)
//
// Output: 	EFI_STATUS status 		- EFI_SUCCESS if OK,
//                             			EFI_INVALID_PARAMETER if NULL pointer
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PostManagerDisplayMenu (
    IN VOID	*HiiHandle, 	
    IN UINT16 	TitleToken, 
    IN UINT16 	LegendToken,	  
    IN POSTMENU_TEMPLATE *MenuData,
    IN UINT16 	MenuCount,
    OUT UINT16  *pSelection
)
{
	UINTN currenttextModeCols = 0, currenttextModeRows = 0;
	UINT32 currentGOPMode = 0;
	EFI_STATUS 	Status = EFI_SUCCESS;

	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	if(gPostStatus < TSE_POST_STATUS_IN_BOOT_TIME_OUT)
		return EFI_NOT_READY;
	
	Status = SaveCurrentTextGOP (&currenttextModeCols, &currenttextModeRows, &currentGOPMode);

	if ( EFI_ERROR(Status) )
		return Status;
		
	Status = ShowPostMenu(HiiHandle, TitleToken, LegendToken, MenuData, MenuCount, pSelection);

	RestoreTextGOPMode (currenttextModeCols, currenttextModeRows, currentGOPMode);

	return Status;
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     PostManagerDisplayTextBox
//
// Description:  Function to display text entry interface
// 
//
// Input:   IN VOID    *HiiHandle,
//    		IN UINT16 	TitleToken,
//    		IN TEXT_INPUT_TEMPLATE *InputData,
//          IN UINT16 	ItemCount,
//          IN DISPLAY_TEXT_KEY_VALIDATE ValidateKeyFunc
//
// Output: EFI_STATUS
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS
PostManagerDisplayTextBox (
    IN VOID	    *HiiHandle, 	
    IN UINT16 	TitleToken, 
    IN TEXT_INPUT_TEMPLATE *InputData,
    IN UINT16 	ItemCount,
    IN DISPLAY_TEXT_KEY_VALIDATE ValidateKeyFunc
	)
{
	UINTN currenttextModeCols = 0, currenttextModeRows = 0;
	UINT32 currentGOPMode = 0;
	EFI_STATUS Status = EFI_UNSUPPORTED;
	
	if (NULL == gST->ConOut)
		return EFI_NOT_READY;

	Status = SaveCurrentTextGOP (&currenttextModeCols, &currenttextModeRows, &currentGOPMode);

	if ( EFI_ERROR(Status) )
		return Status;

	Status = ShowPostTextBox(HiiHandle, TitleToken, InputData, ItemCount, ValidateKeyFunc);

	RestoreTextGOPMode (currenttextModeCols, currenttextModeRows, currentGOPMode);

	return Status;
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	StopClickEvent
//
// Description:	Function to Stop the Click Event
//               
// Input:    	VOID	
//
// Output: 	VOID 
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID StopClickEvent(VOID)
{
	if(gClickTimer)
	{
		gBS->SetTimer ( gClickTimer,TimerCancel,0);
		TimerStopTimer( &gClickTimer );
	}
}

//EIP 128665 starts
//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name:	     	InvalidateBgrtStatusByProtocol
//
// Description: 	Protocol interface to invalidate BGRT status
// 
//
// Input:   		VOID
// 
//
// Output: 			EFI_STATUS
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID InvalidateStatusInBgrtWrapper (VOID);
EFI_STATUS InvalidateBgrtStatusByProtocol (VOID)
{
	InvalidateStatusInBgrtWrapper();
	return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:	InvalidateBGRTStatusProtocol
//
// Description:	Install Invalidate BGRT status protocol
//
// Parameter:	EFI_HANDLE Handle
//
// Return value:EFI_STATUS
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS InstallInvalBGRTStatusProtocol (EFI_HANDLE Handle)
{
  EFI_STATUS Status = EFI_SUCCESS;

  Status = gBS->InstallMultipleProtocolInterfaces (
                  &Handle,
                  &gTSEInvalidateBgrtStatusProtocolGuid,
                  &gInvalidateBgrtStatus,
                  NULL
                  );

  return Status;
}
//EIP 128665 ends

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name				:	SaveCurrentTextGOP
//
// Description		:	Function to Save current TextMode and GOP
//               
// Input				:  UINTN currentTextModCols, UINTN currentTextModRows, UINT32 currentGOPMode
//
// Output			:	EFI_STATUS
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS SaveCurrentTextGOP ( UINTN *currenttextModeCols, UINTN *currenttextModeRows, UINT32 *currentGOPMode )
{

	EFI_STATUS 	Status = EFI_SUCCESS;
	
	if ( IsTseBestTextGOPModeSupported() && TSE_POST_STATUS_IN_TSE != gPostStatus )
	{
		if (gGOP)
		{
			*currentGOPMode = gGOP->Mode->Mode;
		}

		if (TSE_BEST_HORIZONTAL_RESOLUTION != gGOP->Mode->Info->HorizontalResolution || TSE_BEST_VERTICAL_RESOLUTION != gGOP->Mode->Info->VerticalResolution)
		{
			SetScreenResolution(TSE_BEST_HORIZONTAL_RESOLUTION,TSE_BEST_VERTICAL_RESOLUTION); //If any postinterface is invoked during QuietBoot
		}

		Status = gST->ConOut->QueryMode( gST->ConOut, gST->ConOut->Mode->Mode, currenttextModeCols, currenttextModeRows);
		if (EFI_ERROR(Status))
			return EFI_NOT_FOUND;

		if ((STYLE_FULL_MAX_COLS != *currenttextModeCols)  || (STYLE_FULL_MAX_ROWS != *currenttextModeRows))
		{
			gMaxRows = STYLE_FULL_MAX_ROWS;
			gMaxCols = STYLE_FULL_MAX_COLS;
			SetDesiredTextMode ();
		}
	}
	return Status;
}

//<AMI_PHDR_START>
//--------------------------------------------------------------------------
//
// Name				:	RestoreTextGOPMode
//
// Description		:	Function to Save current TextMode and GOP
//               
// Input				:  UINTN currentTextModCols, UINTN currentTextModRows, UINT32 currentGOPMode
//
// Output			:	EFI_STATUS
//
//--------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS RestoreTextGOPMode ( UINTN prevTextModeCols, UINTN prevTextModeRows, UINT32 prevGOPMode )
{
	EFI_STATUS 	Status = EFI_SUCCESS;

	if ( IsTseBestTextGOPModeSupported() && TSE_POST_STATUS_IN_TSE != gPostStatus )
	{
		if ( (gMaxRows != prevTextModeRows) || (gMaxCols != prevTextModeCols) )
		{
			gMaxRows = prevTextModeRows; 
			gMaxCols = prevTextModeCols;
			SetDesiredTextMode (); //Restoring to previous textmode if any changed
		}

		if (gGOP && prevGOPMode != gGOP->Mode->Mode)
		{
			Status = gGOP->SetMode (gGOP, prevGOPMode);	//In some case changing text mode will change the graphcis mode, so reverting here.
		}
	}
	return Status;
}
//EIP-107833 END

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**         (C)Copyright 2014, American Megatrends, Inc.             **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093     **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************