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
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
|
/** @file
Implementation for EFI_HII_DATABASE_PROTOCOL.
Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "HiiDatabase.h"
#define BASE_NUMBER 10
EFI_HII_PACKAGE_LIST_HEADER *gRTDatabaseInfoBuffer = NULL;
EFI_STRING gRTConfigRespBuffer = NULL;
UINTN gDatabaseInfoSize = 0;
UINTN gConfigRespSize = 0;
BOOLEAN gExportConfigResp = FALSE;
UINTN gNvDefaultStoreSize = 0;
SKU_ID gSkuId = 0xFFFFFFFFFFFFFFFF;
LIST_ENTRY gVarStorageList = INITIALIZE_LIST_HEAD_VARIABLE (gVarStorageList);
//
// HII database lock.
//
EFI_LOCK mHiiDatabaseLock = EFI_INITIALIZE_LOCK_VARIABLE(TPL_NOTIFY);
/**
This function generates a HII_DATABASE_RECORD node and adds into hii database.
This is a internal function.
@param Private hii database private structure
@param DatabaseNode HII_DATABASE_RECORD node which is used to store a
package list
@retval EFI_SUCCESS A database record is generated successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
database contents.
@retval EFI_INVALID_PARAMETER Private is NULL or DatabaseRecord is NULL.
**/
EFI_STATUS
GenerateHiiDatabaseRecord (
IN HII_DATABASE_PRIVATE_DATA *Private,
OUT HII_DATABASE_RECORD **DatabaseNode
)
{
HII_DATABASE_RECORD *DatabaseRecord;
HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList;
HII_HANDLE *HiiHandle;
if (Private == NULL || DatabaseNode == NULL) {
return EFI_INVALID_PARAMETER;
}
DatabaseRecord = (HII_DATABASE_RECORD *) AllocateZeroPool (sizeof (HII_DATABASE_RECORD));
if (DatabaseRecord == NULL) {
return EFI_OUT_OF_RESOURCES;
}
DatabaseRecord->Signature = HII_DATABASE_RECORD_SIGNATURE;
DatabaseRecord->PackageList = AllocateZeroPool (sizeof (HII_DATABASE_PACKAGE_LIST_INSTANCE));
if (DatabaseRecord->PackageList == NULL) {
FreePool (DatabaseRecord);
return EFI_OUT_OF_RESOURCES;
}
PackageList = DatabaseRecord->PackageList;
InitializeListHead (&PackageList->GuidPkgHdr);
InitializeListHead (&PackageList->FormPkgHdr);
InitializeListHead (&PackageList->KeyboardLayoutHdr);
InitializeListHead (&PackageList->StringPkgHdr);
InitializeListHead (&PackageList->FontPkgHdr);
InitializeListHead (&PackageList->SimpleFontPkgHdr);
PackageList->ImagePkg = NULL;
PackageList->DevicePathPkg = NULL;
//
// Create a new hii handle
//
HiiHandle = (HII_HANDLE *) AllocateZeroPool (sizeof (HII_HANDLE));
if (HiiHandle == NULL) {
FreePool (DatabaseRecord->PackageList);
FreePool (DatabaseRecord);
return EFI_OUT_OF_RESOURCES;
}
HiiHandle->Signature = HII_HANDLE_SIGNATURE;
//
// Backup the number of Hii handles
//
Private->HiiHandleCount++;
HiiHandle->Key = (UINTN) Private->HiiHandleCount;
//
// Insert the handle to hii handle list of the whole database.
//
InsertTailList (&Private->HiiHandleList, &HiiHandle->Handle);
DatabaseRecord->Handle = (EFI_HII_HANDLE) HiiHandle;
//
// Insert the Package List node to Package List link of the whole database.
//
InsertTailList (&Private->DatabaseList, &DatabaseRecord->DatabaseEntry);
*DatabaseNode = DatabaseRecord;
return EFI_SUCCESS;
}
/**
This function checks whether a handle is a valid EFI_HII_HANDLE
This is a internal function.
@param Handle Pointer to a EFI_HII_HANDLE
@retval TRUE Valid
@retval FALSE Invalid
**/
BOOLEAN
IsHiiHandleValid (
EFI_HII_HANDLE Handle
)
{
HII_HANDLE *HiiHandle;
HiiHandle = (HII_HANDLE *) Handle;
if (HiiHandle == NULL) {
return FALSE;
}
if (HiiHandle->Signature != HII_HANDLE_SIGNATURE) {
return FALSE;
}
return TRUE;
}
/**
This function invokes the matching registered function.
This is a internal function.
@param Private HII Database driver private structure.
@param NotifyType The type of change concerning the database.
@param PackageInstance Points to the package referred to by the
notification.
@param PackageType Package type
@param Handle The handle of the package list which contains the
specified package.
@retval EFI_SUCCESS Already checked all registered function and
invoked if matched.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
InvokeRegisteredFunction (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN VOID *PackageInstance,
IN UINT8 PackageType,
IN EFI_HII_HANDLE Handle
)
{
HII_DATABASE_NOTIFY *Notify;
LIST_ENTRY *Link;
EFI_HII_PACKAGE_HEADER *Package;
UINT8 *Buffer;
UINT32 BufferSize;
UINT32 HeaderSize;
UINT32 ImageBlockSize;
UINT32 PaletteInfoSize;
if (Private == NULL || (NotifyType & 0xF) == 0 || PackageInstance == NULL) {
return EFI_INVALID_PARAMETER;
}
if (Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
if (!IsHiiHandleValid (Handle)) {
return EFI_INVALID_PARAMETER;
}
Buffer = NULL;
Package = NULL;
//
// Convert the incoming package from hii database storage format to UEFI
// storage format. e.g. HII_GUID_PACKAGE_INSTANCE to EFI_HII_GUID_PACKAGE_HDR.
//
switch (PackageType) {
case EFI_HII_PACKAGE_TYPE_GUID:
Package = (EFI_HII_PACKAGE_HEADER *) (((HII_GUID_PACKAGE_INSTANCE *) PackageInstance)->GuidPkg);
break;
case EFI_HII_PACKAGE_FORMS:
BufferSize = ((HII_IFR_PACKAGE_INSTANCE *) PackageInstance)->FormPkgHdr.Length;
Buffer = (UINT8 *) AllocateZeroPool (BufferSize);
ASSERT (Buffer != NULL);
CopyMem (
Buffer,
&((HII_IFR_PACKAGE_INSTANCE *) PackageInstance)->FormPkgHdr,
sizeof (EFI_HII_PACKAGE_HEADER)
);
CopyMem (
Buffer + sizeof (EFI_HII_PACKAGE_HEADER),
((HII_IFR_PACKAGE_INSTANCE *) PackageInstance)->IfrData,
BufferSize - sizeof (EFI_HII_PACKAGE_HEADER)
);
Package = (EFI_HII_PACKAGE_HEADER *) Buffer;
break;
case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
Package = (EFI_HII_PACKAGE_HEADER *) (((HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *) PackageInstance)->KeyboardPkg);
break;
case EFI_HII_PACKAGE_STRINGS:
BufferSize = ((HII_STRING_PACKAGE_INSTANCE *) PackageInstance)->StringPkgHdr->Header.Length;
HeaderSize = ((HII_STRING_PACKAGE_INSTANCE *) PackageInstance)->StringPkgHdr->HdrSize;
Buffer = (UINT8 *) AllocateZeroPool (BufferSize);
ASSERT (Buffer != NULL);
CopyMem (
Buffer,
((HII_STRING_PACKAGE_INSTANCE *) PackageInstance)->StringPkgHdr,
HeaderSize
);
CopyMem (
Buffer + HeaderSize,
((HII_STRING_PACKAGE_INSTANCE *) PackageInstance)->StringBlock,
BufferSize - HeaderSize
);
Package = (EFI_HII_PACKAGE_HEADER *) Buffer;
break;
case EFI_HII_PACKAGE_FONTS:
BufferSize = ((HII_FONT_PACKAGE_INSTANCE *) PackageInstance)->FontPkgHdr->Header.Length;
HeaderSize = ((HII_FONT_PACKAGE_INSTANCE *) PackageInstance)->FontPkgHdr->HdrSize;
Buffer = (UINT8 *) AllocateZeroPool (BufferSize);
ASSERT (Buffer != NULL);
CopyMem (
Buffer,
((HII_FONT_PACKAGE_INSTANCE *) PackageInstance)->FontPkgHdr,
HeaderSize
);
CopyMem (
Buffer + HeaderSize,
((HII_FONT_PACKAGE_INSTANCE *) PackageInstance)->GlyphBlock,
BufferSize - HeaderSize
);
Package = (EFI_HII_PACKAGE_HEADER *) Buffer;
break;
case EFI_HII_PACKAGE_IMAGES:
BufferSize = ((HII_IMAGE_PACKAGE_INSTANCE *) PackageInstance)->ImagePkgHdr.Header.Length;
HeaderSize = sizeof (EFI_HII_IMAGE_PACKAGE_HDR);
Buffer = (UINT8 *) AllocateZeroPool (BufferSize);
ASSERT (Buffer != NULL);
CopyMem (
Buffer,
&((HII_IMAGE_PACKAGE_INSTANCE *) PackageInstance)->ImagePkgHdr,
HeaderSize
);
CopyMem (
Buffer + sizeof (EFI_HII_PACKAGE_HEADER),
&HeaderSize,
sizeof (UINT32)
);
ImageBlockSize = ((HII_IMAGE_PACKAGE_INSTANCE *) PackageInstance)->ImageBlockSize;
if (ImageBlockSize != 0) {
CopyMem (
Buffer + HeaderSize,
((HII_IMAGE_PACKAGE_INSTANCE *) PackageInstance)->ImageBlock,
ImageBlockSize
);
}
PaletteInfoSize = ((HII_IMAGE_PACKAGE_INSTANCE *) PackageInstance)->PaletteInfoSize;
if (PaletteInfoSize != 0) {
CopyMem (
Buffer + HeaderSize + ImageBlockSize,
((HII_IMAGE_PACKAGE_INSTANCE *) PackageInstance)->PaletteBlock,
PaletteInfoSize
);
HeaderSize += ImageBlockSize;
CopyMem (
Buffer + sizeof (EFI_HII_PACKAGE_HEADER) + sizeof (UINT32),
&HeaderSize,
sizeof (UINT32)
);
}
Package = (EFI_HII_PACKAGE_HEADER *) Buffer;
break;
case EFI_HII_PACKAGE_SIMPLE_FONTS:
BufferSize = ((HII_SIMPLE_FONT_PACKAGE_INSTANCE *) PackageInstance)->SimpleFontPkgHdr->Header.Length;
Buffer = (UINT8 *) AllocateZeroPool (BufferSize);
ASSERT (Buffer != NULL);
CopyMem (
Buffer,
((HII_SIMPLE_FONT_PACKAGE_INSTANCE *) PackageInstance)->SimpleFontPkgHdr,
BufferSize
);
Package = (EFI_HII_PACKAGE_HEADER *) Buffer;
break;
case EFI_HII_PACKAGE_DEVICE_PATH:
Package = (EFI_HII_PACKAGE_HEADER *) PackageInstance;
break;
default:
return EFI_INVALID_PARAMETER;
}
for (Link = Private->DatabaseNotifyList.ForwardLink;
Link != &Private->DatabaseNotifyList;
Link = Link->ForwardLink
) {
Notify = CR (Link, HII_DATABASE_NOTIFY, DatabaseNotifyEntry, HII_DATABASE_NOTIFY_SIGNATURE);
if (Notify->NotifyType == NotifyType && Notify->PackageType == PackageType) {
//
// Check in case PackageGuid is not NULL when Package is GUID package
//
if (PackageType != EFI_HII_PACKAGE_TYPE_GUID) {
Notify->PackageGuid = NULL;
}
//
// Status of Registered Function is unknown so did not check it
//
Notify->PackageNotifyFn (
Notify->PackageType,
Notify->PackageGuid,
Package,
Handle,
NotifyType
);
}
}
if (Buffer != NULL) {
FreePool (Buffer);
}
return EFI_SUCCESS;
}
/**
This function insert a GUID package to a package list node.
This is a internal function.
@param PackageHdr Pointer to a buffer stored with GUID package
information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created GUID package
@retval EFI_SUCCESS Guid Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Guid package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
**/
EFI_STATUS
InsertGuidPackage (
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_GUID_PACKAGE_INSTANCE **Package
)
{
HII_GUID_PACKAGE_INSTANCE *GuidPackage;
EFI_HII_PACKAGE_HEADER PackageHeader;
if (PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
CopyMem (&PackageHeader, PackageHdr, sizeof (EFI_HII_PACKAGE_HEADER));
//
// Create a GUID package node
//
GuidPackage = (HII_GUID_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_GUID_PACKAGE_INSTANCE));
if (GuidPackage == NULL) {
return EFI_OUT_OF_RESOURCES;
}
GuidPackage->GuidPkg = (UINT8 *) AllocateZeroPool (PackageHeader.Length);
if (GuidPackage->GuidPkg == NULL) {
FreePool (GuidPackage);
return EFI_OUT_OF_RESOURCES;
}
GuidPackage->Signature = HII_GUID_PACKAGE_SIGNATURE;
CopyMem (GuidPackage->GuidPkg, PackageHdr, PackageHeader.Length);
InsertTailList (&PackageList->GuidPkgHdr, &GuidPackage->GuidEntry);
*Package = GuidPackage;
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += PackageHeader.Length;
}
return EFI_SUCCESS;
}
/**
This function exports GUID packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Guid Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportGuidPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
HII_GUID_PACKAGE_INSTANCE *GuidPackage;
LIST_ENTRY *Link;
UINTN PackageLength;
EFI_HII_PACKAGE_HEADER PackageHeader;
EFI_STATUS Status;
if (PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
PackageLength = 0;
Status = EFI_SUCCESS;
for (Link = PackageList->GuidPkgHdr.ForwardLink; Link != &PackageList->GuidPkgHdr; Link = Link->ForwardLink) {
GuidPackage = CR (Link, HII_GUID_PACKAGE_INSTANCE, GuidEntry, HII_GUID_PACKAGE_SIGNATURE);
CopyMem (&PackageHeader, GuidPackage->GuidPkg, sizeof (EFI_HII_PACKAGE_HEADER));
PackageLength += PackageHeader.Length;
if (PackageLength + *ResultSize + UsedSize <= BufferSize) {
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) GuidPackage,
EFI_HII_PACKAGE_TYPE_GUID,
Handle
);
ASSERT_EFI_ERROR (Status);
CopyMem (Buffer, GuidPackage->GuidPkg, PackageHeader.Length);
Buffer = (UINT8 *) Buffer + PackageHeader.Length;
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes all GUID packages from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed GUID packages.
@param PackageList Pointer to a package list that contains removing
packages.
@retval EFI_SUCCESS GUID Package(s) is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveGuidPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *ListHead;
HII_GUID_PACKAGE_INSTANCE *Package;
EFI_STATUS Status;
EFI_HII_PACKAGE_HEADER PackageHeader;
ListHead = &PackageList->GuidPkgHdr;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->ForwardLink,
HII_GUID_PACKAGE_INSTANCE,
GuidEntry,
HII_GUID_PACKAGE_SIGNATURE
);
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_TYPE_GUID,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
RemoveEntryList (&Package->GuidEntry);
CopyMem (&PackageHeader, Package->GuidPkg, sizeof (EFI_HII_PACKAGE_HEADER));
PackageList->PackageListHdr.PackageLength -= PackageHeader.Length;
FreePool (Package->GuidPkg);
FreePool (Package);
}
return EFI_SUCCESS;
}
/**
Check the input question related to EFI variable
@param IfrQuestionHdr Point to Question header
@param EfiVarStoreList Point to EFI VarStore List
@param EfiVarStoreNumber The number of EFI VarStore
@retval Index The index of the found EFI varstore in EFI varstore list
EfiVarStoreNumber will return if no EFI varstore is found.
**/
UINTN
IsEfiVarStoreQuestion (
EFI_IFR_QUESTION_HEADER *IfrQuestionHdr,
EFI_IFR_VARSTORE_EFI **EfiVarStoreList,
UINTN EfiVarStoreNumber
)
{
UINTN Index;
for (Index = 0; Index < EfiVarStoreNumber; Index ++) {
if (IfrQuestionHdr->VarStoreId == EfiVarStoreList[Index]->VarStoreId) {
return Index;
}
}
return EfiVarStoreNumber;
}
/**
Find the matched variable from the input variable storage.
@param[in] VariableStorage Point to the variable storage header.
@param[in] VarGuid A unique identifier for the variable.
@param[in] VarAttribute The attributes bitmask for the variable.
@param[in] VarName A Null-terminated ascii string that is the name of the variable.
@return Pointer to the matched variable header or NULL if not found.
**/
VARIABLE_HEADER *
FindVariableData (
IN VARIABLE_STORE_HEADER *VariableStorage,
IN EFI_GUID *VarGuid,
IN UINT32 VarAttribute,
IN CHAR16 *VarName
)
{
VARIABLE_HEADER *VariableHeader;
VARIABLE_HEADER *VariableEnd;
VariableEnd = (VARIABLE_HEADER *) ((UINT8 *) VariableStorage + VariableStorage->Size);
VariableHeader = (VARIABLE_HEADER *) (VariableStorage + 1);
VariableHeader = (VARIABLE_HEADER *) HEADER_ALIGN (VariableHeader);
while (VariableHeader < VariableEnd) {
if (CompareGuid (&VariableHeader->VendorGuid, VarGuid) &&
VariableHeader->Attributes == VarAttribute &&
StrCmp (VarName, (CHAR16 *) (VariableHeader + 1)) == 0) {
return VariableHeader;
}
VariableHeader = (VARIABLE_HEADER *) ((UINT8 *) VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + VariableHeader->DataSize);
VariableHeader = (VARIABLE_HEADER *) HEADER_ALIGN (VariableHeader);
}
return NULL;
}
/**
Find question default value from PcdNvStoreDefaultValueBuffer
@param DefaultId Default store ID
@param EfiVarStore Point to EFI VarStore header
@param IfrQuestionHdr Point to Question header
@param ValueBuffer Point to Buffer includes the found default setting
@param Width Width of the default value
@param BitFieldQuestion Whether the Question is stored in Bit field.
@retval EFI_SUCCESS Question default value is found.
@retval EFI_NOT_FOUND Question default value is not found.
**/
EFI_STATUS
FindQuestionDefaultSetting (
IN UINT16 DefaultId,
IN EFI_IFR_VARSTORE_EFI *EfiVarStore,
IN EFI_IFR_QUESTION_HEADER *IfrQuestionHdr,
OUT VOID *ValueBuffer,
IN UINTN Width,
IN BOOLEAN BitFieldQuestion
)
{
VARIABLE_HEADER *VariableHeader;
VARIABLE_STORE_HEADER *VariableStorage;
LIST_ENTRY *Link;
VARSTORAGE_DEFAULT_DATA *Entry;
VARIABLE_STORE_HEADER *NvStoreBuffer;
UINT8 *DataBuffer;
UINT8 *BufferEnd;
BOOLEAN IsFound;
UINTN Index;
UINT32 BufferValue;
UINT32 BitFieldVal;
UINTN BitOffset;
UINTN ByteOffset;
UINTN BitWidth;
UINTN StartBit;
UINTN EndBit;
PCD_DEFAULT_DATA *DataHeader;
PCD_DEFAULT_INFO *DefaultInfo;
PCD_DATA_DELTA *DeltaData;
if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
gSkuId = LibPcdGetSku ();
}
//
// Find the DefaultId setting from the full DefaultSetting
//
VariableStorage = NULL;
Link = gVarStorageList.ForwardLink;
while (Link != &gVarStorageList) {
Entry = BASE_CR (Link, VARSTORAGE_DEFAULT_DATA, Entry);
if (Entry->DefaultId == DefaultId) {
VariableStorage = Entry->VariableStorage;
break;
}
Link = Link->ForwardLink;
}
if (Link == &gVarStorageList) {
DataBuffer = (UINT8 *) PcdGetPtr (PcdNvStoreDefaultValueBuffer);
gNvDefaultStoreSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *)DataBuffer)->Length;
//
// The first section data includes NV storage default setting.
//
DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));
NvStoreBuffer = (VARIABLE_STORE_HEADER *) ((UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);
VariableStorage = AllocatePool (NvStoreBuffer->Size);
ASSERT (VariableStorage != NULL);
CopyMem (VariableStorage, NvStoreBuffer, NvStoreBuffer->Size);
//
// Find the matched SkuId and DefaultId in the first section
//
IsFound = FALSE;
DefaultInfo = &(DataHeader->DefaultInfo[0]);
BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;
while ((UINT8 *) DefaultInfo < BufferEnd) {
if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == gSkuId) {
IsFound = TRUE;
break;
}
DefaultInfo ++;
}
//
// Find the matched SkuId and DefaultId in the remaining section
//
Index = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));
DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);
while (!IsFound && Index < gNvDefaultStoreSize && DataHeader->DataSize != 0xFFFF) {
DefaultInfo = &(DataHeader->DefaultInfo[0]);
BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;
while ((UINT8 *) DefaultInfo < BufferEnd) {
if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == gSkuId) {
IsFound = TRUE;
break;
}
DefaultInfo ++;
}
if (IsFound) {
DeltaData = (PCD_DATA_DELTA *) BufferEnd;
BufferEnd = (UINT8 *) DataHeader + DataHeader->DataSize;
while ((UINT8 *) DeltaData < BufferEnd) {
*((UINT8 *) VariableStorage + DeltaData->Offset) = (UINT8) DeltaData->Value;
DeltaData ++;
}
break;
}
Index = (Index + DataHeader->DataSize + 7) & (~7);
DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);
}
//
// Cache the found result in VarStorageList
//
if (!IsFound) {
FreePool (VariableStorage);
VariableStorage = NULL;
}
Entry = AllocatePool (sizeof (VARSTORAGE_DEFAULT_DATA));
if (Entry != NULL) {
Entry->DefaultId = DefaultId;
Entry->VariableStorage = VariableStorage;
InsertTailList (&gVarStorageList, &Entry->Entry);
} else if (VariableStorage != NULL) {
FreePool (VariableStorage);
VariableStorage = NULL;
}
}
//
// The matched variable storage is not found.
//
if (VariableStorage == NULL) {
return EFI_NOT_FOUND;
}
//
// Find the question default value from the variable storage
//
VariableHeader = FindVariableData (VariableStorage, &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *) EfiVarStore->Name);
if (VariableHeader == NULL) {
return EFI_NOT_FOUND;
}
StartBit = 0;
EndBit = 0;
ByteOffset = IfrQuestionHdr->VarStoreInfo.VarOffset;
if (BitFieldQuestion) {
BitOffset = IfrQuestionHdr->VarStoreInfo.VarOffset;
ByteOffset = BitOffset / 8;
BitWidth = Width;
StartBit = BitOffset % 8;
EndBit = StartBit + BitWidth - 1;
Width = EndBit / 8 + 1;
}
if (VariableHeader->DataSize < ByteOffset + Width) {
return EFI_INVALID_PARAMETER;
}
//
// Copy the question value
//
if (ValueBuffer != NULL) {
if (BitFieldQuestion) {
CopyMem (&BufferValue, (UINT8 *) VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);
BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);
CopyMem (ValueBuffer, &BitFieldVal, Width);
} else {
CopyMem (ValueBuffer, (UINT8 *) VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset, Width);
}
}
return EFI_SUCCESS;
}
/**
Update IFR default setting in Form Package.
@param FormPackage Form Package to be updated
**/
VOID
UpdateDefaultSettingInFormPackage (
HII_IFR_PACKAGE_INSTANCE *FormPackage
)
{
UINTN IfrOffset;
UINTN PackageLength;
EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;
EFI_IFR_OP_HEADER *IfrOpHdr;
EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;
UINT8 IfrQuestionType;
UINT8 IfrScope;
EFI_IFR_QUESTION_HEADER *IfrQuestionHdr;
EFI_IFR_VARSTORE_EFI **EfiVarStoreList;
UINTN EfiVarStoreMaxNum;
UINTN EfiVarStoreNumber;
UINT16 *DefaultIdList;
UINTN DefaultIdNumber;
UINTN DefaultIdMaxNum;
UINTN Index;
UINTN EfiVarStoreIndex;
EFI_IFR_TYPE_VALUE IfrValue;
EFI_IFR_TYPE_VALUE IfrManufactValue;
BOOLEAN StandardDefaultIsSet;
BOOLEAN ManufactDefaultIsSet;
EFI_IFR_CHECKBOX *IfrCheckBox;
EFI_STATUS Status;
EFI_IFR_DEFAULT *IfrDefault;
UINTN Width;
EFI_IFR_QUESTION_HEADER VarStoreQuestionHeader;
BOOLEAN QuestionReferBitField;
//
// If no default setting, do nothing
//
if (gNvDefaultStoreSize == 0) {
gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);
}
if (gNvDefaultStoreSize < sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
return;
}
ZeroMem (&VarStoreQuestionHeader, sizeof (VarStoreQuestionHeader));
PackageLength = FormPackage->FormPkgHdr.Length - sizeof (EFI_HII_PACKAGE_HEADER);
Width = 0;
IfrOffset = 0;
IfrScope = 0;
IfrOpHdr = (EFI_IFR_OP_HEADER *) FormPackage->IfrData;
IfrQuestionHdr = NULL;
IfrQuestionType = 0;
EfiVarStoreMaxNum = 0;
EfiVarStoreNumber = 0;
DefaultIdMaxNum = 0;
DefaultIdNumber = 0;
EfiVarStoreList = NULL;
DefaultIdList = NULL;
StandardDefaultIsSet = FALSE;
ManufactDefaultIsSet = FALSE;
QuestionReferBitField = FALSE;
while (IfrOffset < PackageLength) {
switch (IfrOpHdr->OpCode) {
case EFI_IFR_VARSTORE_EFI_OP:
if (EfiVarStoreNumber >= EfiVarStoreMaxNum) {
//
// Reallocate EFI VarStore Buffer
//
EfiVarStoreList = ReallocatePool (EfiVarStoreMaxNum * sizeof (UINTN), (EfiVarStoreMaxNum + BASE_NUMBER) * sizeof (UINTN), EfiVarStoreList);
if (EfiVarStoreList == NULL) {
goto Done;
}
EfiVarStoreMaxNum = EfiVarStoreMaxNum + BASE_NUMBER;
}
IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr;
//
// Convert VarStore Name from ASCII string to Unicode string.
//
EfiVarStoreList [EfiVarStoreNumber] = AllocatePool (IfrEfiVarStore->Header.Length + AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name));
if (EfiVarStoreList [EfiVarStoreNumber] == NULL) {
break;
}
CopyMem (EfiVarStoreList [EfiVarStoreNumber], IfrEfiVarStore, IfrEfiVarStore->Header.Length);
AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name, (CHAR16 *) &(EfiVarStoreList [EfiVarStoreNumber]->Name[0]), AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name) * sizeof (CHAR16));
Status = FindQuestionDefaultSetting (EFI_HII_DEFAULT_CLASS_STANDARD, EfiVarStoreList[EfiVarStoreNumber], &VarStoreQuestionHeader, NULL, IfrEfiVarStore->Size, FALSE);
if (!EFI_ERROR (Status)) {
EfiVarStoreNumber ++;
} else {
FreePool (EfiVarStoreList [EfiVarStoreNumber]);
EfiVarStoreList [EfiVarStoreNumber] = NULL;
}
break;
case EFI_IFR_DEFAULTSTORE_OP:
if (DefaultIdNumber >= DefaultIdMaxNum) {
//
// Reallocate DefaultIdNumber
//
DefaultIdList = ReallocatePool (DefaultIdMaxNum * sizeof (UINT16), (DefaultIdMaxNum + BASE_NUMBER) * sizeof (UINT16), DefaultIdList);
if (DefaultIdList == NULL) {
goto Done;
}
DefaultIdMaxNum = DefaultIdMaxNum + BASE_NUMBER;
}
DefaultIdList[DefaultIdNumber ++] = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId;
break;
case EFI_IFR_FORM_OP:
case EFI_IFR_FORM_MAP_OP:
//
// No EFI varstore is found and directly return.
//
if (EfiVarStoreNumber == 0 || DefaultIdNumber == 0) {
goto Done;
}
break;
case EFI_IFR_CHECKBOX_OP:
IfrScope = IfrOpHdr->Scope;
IfrQuestionType = IfrOpHdr->OpCode;
IfrQuestionHdr = (EFI_IFR_QUESTION_HEADER *) (IfrOpHdr + 1);
IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr;
EfiVarStoreIndex = IsEfiVarStoreQuestion (IfrQuestionHdr, EfiVarStoreList, EfiVarStoreNumber);
Width = sizeof (BOOLEAN);
if (EfiVarStoreIndex < EfiVarStoreNumber) {
for (Index = 0; Index < DefaultIdNumber; Index ++) {
if (DefaultIdList[Index] == EFI_HII_DEFAULT_CLASS_STANDARD) {
Status = FindQuestionDefaultSetting (DefaultIdList[Index], EfiVarStoreList[EfiVarStoreIndex], IfrQuestionHdr, &IfrValue, sizeof (BOOLEAN), QuestionReferBitField);
if (!EFI_ERROR (Status)) {
if (IfrValue.b) {
IfrCheckBox->Flags = IfrCheckBox->Flags | EFI_IFR_CHECKBOX_DEFAULT;
} else {
IfrCheckBox->Flags = IfrCheckBox->Flags & (~EFI_IFR_CHECKBOX_DEFAULT);
}
}
} else if (DefaultIdList[Index] == EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
Status = FindQuestionDefaultSetting (DefaultIdList[Index], EfiVarStoreList[EfiVarStoreIndex], IfrQuestionHdr, &IfrValue, sizeof (BOOLEAN), QuestionReferBitField);
if (!EFI_ERROR (Status)) {
if (IfrValue.b) {
IfrCheckBox->Flags = IfrCheckBox->Flags | EFI_IFR_CHECKBOX_DEFAULT_MFG;
} else {
IfrCheckBox->Flags = IfrCheckBox->Flags & (~EFI_IFR_CHECKBOX_DEFAULT_MFG);
}
}
}
}
}
break;
case EFI_IFR_NUMERIC_OP:
IfrScope = IfrOpHdr->Scope;
IfrQuestionType = IfrOpHdr->OpCode;
IfrQuestionHdr = (EFI_IFR_QUESTION_HEADER *) (IfrOpHdr + 1);
if (QuestionReferBitField) {
Width = (UINTN) (((EFI_IFR_ONE_OF *) IfrOpHdr)->Flags & EDKII_IFR_NUMERIC_SIZE_BIT);
} else {
Width = (UINTN) ((UINT32) 1 << (((EFI_IFR_ONE_OF *) IfrOpHdr)->Flags & EFI_IFR_NUMERIC_SIZE));
}
break;
case EFI_IFR_ONE_OF_OP:
IfrScope = IfrOpHdr->Scope;
IfrQuestionType = IfrOpHdr->OpCode;
IfrQuestionHdr = (EFI_IFR_QUESTION_HEADER *) (IfrOpHdr + 1);
if (QuestionReferBitField) {
Width = (UINTN) (((EFI_IFR_ONE_OF *) IfrOpHdr)->Flags & EDKII_IFR_NUMERIC_SIZE_BIT);
} else {
Width = (UINTN) ((UINT32) 1 << (((EFI_IFR_ONE_OF *) IfrOpHdr)->Flags & EFI_IFR_NUMERIC_SIZE));
}
EfiVarStoreIndex = IsEfiVarStoreQuestion (IfrQuestionHdr, EfiVarStoreList, EfiVarStoreNumber);
StandardDefaultIsSet = FALSE;
ManufactDefaultIsSet = FALSE;
//
// Find Default and Manufacturing default for OneOf question
//
if (EfiVarStoreIndex < EfiVarStoreNumber) {
for (Index = 0; Index < DefaultIdNumber; Index ++) {
if (DefaultIdList[Index] == EFI_HII_DEFAULT_CLASS_STANDARD) {
Status = FindQuestionDefaultSetting (EFI_HII_DEFAULT_CLASS_STANDARD, EfiVarStoreList[EfiVarStoreIndex], IfrQuestionHdr, &IfrValue, Width, QuestionReferBitField);
if (!EFI_ERROR (Status)) {
StandardDefaultIsSet = TRUE;
}
} else if (DefaultIdList[Index] == EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
Status = FindQuestionDefaultSetting (EFI_HII_DEFAULT_CLASS_MANUFACTURING, EfiVarStoreList[EfiVarStoreIndex], IfrQuestionHdr, &IfrManufactValue, Width, QuestionReferBitField);
if (!EFI_ERROR (Status)) {
ManufactDefaultIsSet = TRUE;
}
}
}
}
break;
case EFI_IFR_ORDERED_LIST_OP:
IfrScope = IfrOpHdr->Scope;
IfrQuestionType = IfrOpHdr->OpCode;
IfrQuestionHdr = (EFI_IFR_QUESTION_HEADER *) (IfrOpHdr + 1);
break;
case EFI_IFR_ONE_OF_OPTION_OP:
if (IfrQuestionHdr != NULL && IfrScope > 0) {
IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) IfrOpHdr;
if (IfrQuestionType == EFI_IFR_ONE_OF_OP) {
Width = (UINTN) ((UINT32) 1 << (IfrOneOfOption->Flags & EFI_IFR_NUMERIC_SIZE));
if (StandardDefaultIsSet) {
if (CompareMem (&IfrOneOfOption->Value, &IfrValue, Width) == 0) {
IfrOneOfOption->Flags |= EFI_IFR_OPTION_DEFAULT;
} else {
IfrOneOfOption->Flags &= ~EFI_IFR_OPTION_DEFAULT;
}
}
if (ManufactDefaultIsSet) {
if (CompareMem (&IfrOneOfOption->Value, &IfrManufactValue, Width) == 0) {
IfrOneOfOption->Flags |= EFI_IFR_OPTION_DEFAULT_MFG;
} else {
IfrOneOfOption->Flags &= ~EFI_IFR_OPTION_DEFAULT_MFG;
}
}
}
}
break;
case EFI_IFR_DEFAULT_OP:
if (IfrQuestionHdr != NULL && IfrScope > 0) {
IfrDefault = (EFI_IFR_DEFAULT *) IfrOpHdr;
//
// Collect default value width
//
if (!QuestionReferBitField) {
Width = 0;
if (IfrDefault->Type == EFI_IFR_TYPE_NUM_SIZE_8 || IfrDefault->Type == EFI_IFR_TYPE_BOOLEAN) {
Width = 1;
} else if (IfrDefault->Type == EFI_IFR_TYPE_NUM_SIZE_16) {
Width = 2;
} else if (IfrDefault->Type == EFI_IFR_TYPE_NUM_SIZE_32) {
Width = 4;
} else if (IfrDefault->Type == EFI_IFR_TYPE_NUM_SIZE_64) {
Width = 8;
} else if (IfrDefault->Type == EFI_IFR_TYPE_BUFFER) {
Width = IfrDefault->Header.Length - OFFSET_OF (EFI_IFR_DEFAULT, Value);
}
}
//
// Update the default value
//
if (Width > 0) {
EfiVarStoreIndex = IsEfiVarStoreQuestion (IfrQuestionHdr, EfiVarStoreList, EfiVarStoreNumber);
if (EfiVarStoreIndex < EfiVarStoreNumber) {
Status = FindQuestionDefaultSetting (IfrDefault->DefaultId, EfiVarStoreList[EfiVarStoreIndex], IfrQuestionHdr, &IfrDefault->Value, Width, QuestionReferBitField);
}
}
}
break;
case EFI_IFR_END_OP:
if (IfrQuestionHdr != NULL) {
if (IfrScope > 0) {
IfrScope --;
}
if (IfrScope == 0) {
IfrQuestionHdr = NULL;
QuestionReferBitField = FALSE;
}
}
break;
case EFI_IFR_GUID_OP:
if (CompareGuid ((EFI_GUID *)((UINT8 *)IfrOpHdr + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
QuestionReferBitField = TRUE;
}
break;
default:
break;
}
IfrOffset = IfrOffset + IfrOpHdr->Length;
IfrOpHdr = (EFI_IFR_OP_HEADER *) ((UINT8 *) IfrOpHdr + IfrOpHdr->Length);
if (IfrScope > 0) {
IfrScope += IfrOpHdr->Scope;
}
}
Done:
if (EfiVarStoreList != NULL) {
for (Index = 0; Index < EfiVarStoreNumber; Index ++) {
FreePool (EfiVarStoreList [Index]);
}
}
return;
}
/**
This function insert a Form package to a package list node.
This is a internal function.
@param PackageHdr Pointer to a buffer stored with Form package
information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created Form package
@retval EFI_SUCCESS Form Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Form package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
**/
EFI_STATUS
InsertFormPackage (
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_IFR_PACKAGE_INSTANCE **Package
)
{
HII_IFR_PACKAGE_INSTANCE *FormPackage;
EFI_HII_PACKAGE_HEADER PackageHeader;
if (PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Get the length of the package, including package header itself
//
CopyMem (&PackageHeader, PackageHdr, sizeof (EFI_HII_PACKAGE_HEADER));
//
// Create a Form package node
//
FormPackage = (HII_IFR_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_IFR_PACKAGE_INSTANCE));
if (FormPackage == NULL) {
return EFI_OUT_OF_RESOURCES;
}
FormPackage->IfrData = (UINT8 *) AllocateZeroPool (PackageHeader.Length - sizeof (EFI_HII_PACKAGE_HEADER));
if (FormPackage->IfrData == NULL) {
FreePool (FormPackage);
return EFI_OUT_OF_RESOURCES;
}
FormPackage->Signature = HII_IFR_PACKAGE_SIGNATURE;
//
// Copy Package Header
//
CopyMem (&FormPackage->FormPkgHdr, &PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));
//
// Copy Ifr contents
//
CopyMem (
FormPackage->IfrData,
(UINT8 *) PackageHdr + sizeof (EFI_HII_PACKAGE_HEADER),
PackageHeader.Length - sizeof (EFI_HII_PACKAGE_HEADER)
);
InsertTailList (&PackageList->FormPkgHdr, &FormPackage->IfrEntry);
*Package = FormPackage;
//
// Update FormPackage with the default setting
//
UpdateDefaultSettingInFormPackage (FormPackage);
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += FormPackage->FormPkgHdr.Length;
}
return EFI_SUCCESS;
}
/**
This function exports Form packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Form Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportFormPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
HII_IFR_PACKAGE_INSTANCE *FormPackage;
UINTN PackageLength;
LIST_ENTRY *Link;
EFI_STATUS Status;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
PackageLength = 0;
Status = EFI_SUCCESS;
//
// Export Form packages.
//
for (Link = PackageList->FormPkgHdr.ForwardLink; Link != &PackageList->FormPkgHdr; Link = Link->ForwardLink) {
FormPackage = CR (Link, HII_IFR_PACKAGE_INSTANCE, IfrEntry, HII_IFR_PACKAGE_SIGNATURE);
PackageLength += FormPackage->FormPkgHdr.Length;
if ((Buffer != NULL) && (PackageLength + *ResultSize + UsedSize <= BufferSize)) {
//
// Invoke registered notification if exists
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) FormPackage,
EFI_HII_PACKAGE_FORMS,
Handle
);
ASSERT_EFI_ERROR (Status);
//
// Copy the Form package content.
//
CopyMem (Buffer, (VOID *) (&FormPackage->FormPkgHdr), sizeof (EFI_HII_PACKAGE_HEADER));
Buffer = (UINT8 *) Buffer + sizeof (EFI_HII_PACKAGE_HEADER);
CopyMem (
Buffer,
(VOID *) FormPackage->IfrData,
FormPackage->FormPkgHdr.Length - sizeof (EFI_HII_PACKAGE_HEADER)
);
Buffer = (UINT8 *) Buffer + FormPackage->FormPkgHdr.Length - sizeof (EFI_HII_PACKAGE_HEADER);
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes all Form packages from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed Form packages.
@param PackageList Pointer to a package list that contains removing
packages.
@retval EFI_SUCCESS Form Package(s) is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveFormPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *ListHead;
HII_IFR_PACKAGE_INSTANCE *Package;
EFI_STATUS Status;
ListHead = &PackageList->FormPkgHdr;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->ForwardLink,
HII_IFR_PACKAGE_INSTANCE,
IfrEntry,
HII_IFR_PACKAGE_SIGNATURE
);
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_FORMS,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
RemoveEntryList (&Package->IfrEntry);
PackageList->PackageListHdr.PackageLength -= Package->FormPkgHdr.Length;
FreePool (Package->IfrData);
FreePool (Package);
//
// If Hii runtime support feature is enabled,
// will export Hii info for runtime use after ReadyToBoot event triggered.
// If some driver add/update/remove packages from HiiDatabase after ReadyToBoot,
// will need to export the content of HiiDatabase.
// But if form packages removed, also need to export the ConfigResp string
//
if (gExportAfterReadyToBoot) {
gExportConfigResp = TRUE;
}
}
return EFI_SUCCESS;
}
/**
This function insert a String package to a package list node.
This is a internal function.
@param Private Hii database private structure.
@param PackageHdr Pointer to a buffer stored with String package
information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created String package
@retval EFI_SUCCESS String Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
String package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
@retval EFI_UNSUPPORTED A string package with the same language already
exists in current package list.
**/
EFI_STATUS
InsertStringPackage (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_STRING_PACKAGE_INSTANCE **Package
)
{
HII_STRING_PACKAGE_INSTANCE *StringPackage;
UINT32 HeaderSize;
EFI_STATUS Status;
EFI_HII_PACKAGE_HEADER PackageHeader;
CHAR8 *Language;
UINT32 LanguageSize;
LIST_ENTRY *Link;
if (Private == NULL || PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
if (Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
CopyMem (&PackageHeader, PackageHdr, sizeof (EFI_HII_PACKAGE_HEADER));
CopyMem (&HeaderSize, (UINT8 *) PackageHdr + sizeof (EFI_HII_PACKAGE_HEADER), sizeof (UINT32));
//
// It is illegal to have two string packages with same language within one packagelist
// since the stringid will be duplicate if so. Check it to avoid this potential issue.
//
LanguageSize = HeaderSize - sizeof (EFI_HII_STRING_PACKAGE_HDR) + sizeof (CHAR8);
Language = (CHAR8 *) AllocateZeroPool (LanguageSize);
if (Language == NULL) {
return EFI_OUT_OF_RESOURCES;
}
AsciiStrCpyS (Language, LanguageSize / sizeof (CHAR8), (CHAR8 *) PackageHdr + HeaderSize - LanguageSize);
for (Link = PackageList->StringPkgHdr.ForwardLink; Link != &PackageList->StringPkgHdr; Link = Link->ForwardLink) {
StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
if (HiiCompareLanguage (Language, StringPackage->StringPkgHdr->Language)) {
FreePool (Language);
return EFI_UNSUPPORTED;
}
}
FreePool (Language);
//
// Create a String package node
//
StringPackage = (HII_STRING_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE));
if (StringPackage == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
StringPackage->StringPkgHdr = (EFI_HII_STRING_PACKAGE_HDR *) AllocateZeroPool (HeaderSize);
if (StringPackage->StringPkgHdr == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
StringPackage->StringBlock = (UINT8 *) AllocateZeroPool (PackageHeader.Length - HeaderSize);
if (StringPackage->StringBlock == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
StringPackage->Signature = HII_STRING_PACKAGE_SIGNATURE;
StringPackage->FontId = 0;
InitializeListHead (&StringPackage->FontInfoList);
//
// Copy the String package header.
//
CopyMem (StringPackage->StringPkgHdr, PackageHdr, HeaderSize);
//
// Copy the String blocks
//
CopyMem (
StringPackage->StringBlock,
(UINT8 *) PackageHdr + HeaderSize,
PackageHeader.Length - HeaderSize
);
//
// Collect all font block info
//
Status = FindStringBlock (Private, StringPackage, (EFI_STRING_ID) (-1), NULL, NULL, NULL, &StringPackage->MaxStringId, NULL);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Insert to String package array
//
InsertTailList (&PackageList->StringPkgHdr, &StringPackage->StringEntry);
*Package = StringPackage;
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length;
}
return EFI_SUCCESS;
Error:
if (StringPackage != NULL) {
if (StringPackage->StringBlock != NULL) {
FreePool (StringPackage->StringBlock);
}
if (StringPackage->StringPkgHdr != NULL) {
FreePool (StringPackage->StringPkgHdr);
}
FreePool (StringPackage);
}
return Status;
}
/**
Adjust all string packages in a single package list to have the same max string ID.
@param PackageList Pointer to a package list which will be adjusted.
@retval EFI_SUCCESS Adjust all string packages successfully.
@retval others Can't adjust string packages.
**/
EFI_STATUS
AdjustStringPackage (
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *Link;
HII_STRING_PACKAGE_INSTANCE *StringPackage;
UINT32 Skip2BlockSize;
UINT32 OldBlockSize;
UINT8 *StringBlock;
UINT8 *BlockPtr;
EFI_STRING_ID MaxStringId;
UINT16 SkipCount;
MaxStringId = 0;
for (Link = PackageList->StringPkgHdr.ForwardLink;
Link != &PackageList->StringPkgHdr;
Link = Link->ForwardLink
) {
StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
if (MaxStringId < StringPackage->MaxStringId) {
MaxStringId = StringPackage->MaxStringId;
}
}
for (Link = PackageList->StringPkgHdr.ForwardLink;
Link != &PackageList->StringPkgHdr;
Link = Link->ForwardLink
) {
StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
if (StringPackage->MaxStringId < MaxStringId) {
OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
//
// Create SKIP2 EFI_HII_SIBT_SKIP2_BLOCKs to reserve the missing string IDs.
//
SkipCount = (UINT16) (MaxStringId - StringPackage->MaxStringId);
Skip2BlockSize = (UINT32) sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Skip2BlockSize);
if (StringBlock == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Copy original string blocks, except the EFI_HII_SIBT_END.
//
CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));
//
// Create SKIP2 EFI_HII_SIBT_SKIP2_BLOCK blocks
//
BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);
*BlockPtr = EFI_HII_SIBT_SKIP2;
CopyMem (BlockPtr + 1, &SkipCount, sizeof (UINT16));
BlockPtr += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);
//
// Append a EFI_HII_SIBT_END block to the end.
//
*BlockPtr = EFI_HII_SIBT_END;
FreePool (StringPackage->StringBlock);
StringPackage->StringBlock = StringBlock;
StringPackage->StringPkgHdr->Header.Length += Skip2BlockSize;
PackageList->PackageListHdr.PackageLength += Skip2BlockSize;
StringPackage->MaxStringId = MaxStringId;
}
}
return EFI_SUCCESS;
}
/**
This function exports String packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS String Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportStringPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
LIST_ENTRY *Link;
UINTN PackageLength;
EFI_STATUS Status;
HII_STRING_PACKAGE_INSTANCE *StringPackage;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
PackageLength = 0;
Status = EFI_SUCCESS;
for (Link = PackageList->StringPkgHdr.ForwardLink; Link != &PackageList->StringPkgHdr; Link = Link->ForwardLink) {
StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);
PackageLength += StringPackage->StringPkgHdr->Header.Length;
if (PackageLength + *ResultSize + UsedSize <= BufferSize) {
//
// Invoke registered notification function with EXPORT_PACK notify type
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) StringPackage,
EFI_HII_PACKAGE_STRINGS,
Handle
);
ASSERT_EFI_ERROR (Status);
//
// Copy String package header
//
CopyMem (Buffer, StringPackage->StringPkgHdr, StringPackage->StringPkgHdr->HdrSize);
Buffer = (UINT8 *) Buffer + StringPackage->StringPkgHdr->HdrSize;
//
// Copy String blocks information
//
CopyMem (
Buffer,
StringPackage->StringBlock,
StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize
);
Buffer = (UINT8 *) Buffer + StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes all String packages from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed String packages.
@param PackageList Pointer to a package list that contains removing
packages.
@retval EFI_SUCCESS String Package(s) is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveStringPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *ListHead;
HII_STRING_PACKAGE_INSTANCE *Package;
HII_FONT_INFO *FontInfo;
EFI_STATUS Status;
ListHead = &PackageList->StringPkgHdr;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->ForwardLink,
HII_STRING_PACKAGE_INSTANCE,
StringEntry,
HII_STRING_PACKAGE_SIGNATURE
);
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_STRINGS,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
RemoveEntryList (&Package->StringEntry);
PackageList->PackageListHdr.PackageLength -= Package->StringPkgHdr->Header.Length;
FreePool (Package->StringBlock);
FreePool (Package->StringPkgHdr);
//
// Delete font information
//
while (!IsListEmpty (&Package->FontInfoList)) {
FontInfo = CR (
Package->FontInfoList.ForwardLink,
HII_FONT_INFO,
Entry,
HII_FONT_INFO_SIGNATURE
);
RemoveEntryList (&FontInfo->Entry);
FreePool (FontInfo);
}
FreePool (Package);
}
return EFI_SUCCESS;
}
/**
This function insert a Font package to a package list node.
This is a internal function.
@param Private Hii database private structure.
@param PackageHdr Pointer to a buffer stored with Font package
information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created Font package
@retval EFI_SUCCESS Font Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Font package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
@retval EFI_UNSUPPORTED A font package with same EFI_FONT_INFO already
exists in current hii database.
**/
EFI_STATUS
InsertFontPackage (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_FONT_PACKAGE_INSTANCE **Package
)
{
HII_FONT_PACKAGE_INSTANCE *FontPackage;
EFI_HII_FONT_PACKAGE_HDR *FontPkgHdr;
UINT32 HeaderSize;
EFI_STATUS Status;
EFI_HII_PACKAGE_HEADER PackageHeader;
EFI_FONT_INFO *FontInfo;
UINT32 FontInfoSize;
HII_GLOBAL_FONT_INFO *GlobalFont;
if (Private == NULL || PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
CopyMem (&PackageHeader, PackageHdr, sizeof (EFI_HII_PACKAGE_HEADER));
CopyMem (&HeaderSize, (UINT8 *) PackageHdr + sizeof (EFI_HII_PACKAGE_HEADER), sizeof (UINT32));
FontInfo = NULL;
FontPackage = NULL;
GlobalFont = NULL;
//
// It is illegal to have two font packages with same EFI_FONT_INFO within hii
// database. EFI_FONT_INFO (FontName, FontSize, FontStyle) describes font's
// attributes and identify a font uniquely.
//
FontPkgHdr = (EFI_HII_FONT_PACKAGE_HDR *) AllocateZeroPool (HeaderSize);
if (FontPkgHdr == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
CopyMem (FontPkgHdr, PackageHdr, HeaderSize);
FontInfoSize = sizeof (EFI_FONT_INFO) + HeaderSize - sizeof (EFI_HII_FONT_PACKAGE_HDR);
FontInfo = (EFI_FONT_INFO *) AllocateZeroPool (FontInfoSize);
if (FontInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
FontInfo->FontStyle = FontPkgHdr->FontStyle;
FontInfo->FontSize = FontPkgHdr->Cell.Height;
StrCpyS (FontInfo->FontName, (FontInfoSize - OFFSET_OF(EFI_FONT_INFO,FontName)) / sizeof (CHAR16), FontPkgHdr->FontFamily);
if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, NULL)) {
Status = EFI_UNSUPPORTED;
goto Error;
}
//
// Create a Font package node
//
FontPackage = (HII_FONT_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_FONT_PACKAGE_INSTANCE));
if (FontPackage == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
FontPackage->Signature = HII_FONT_PACKAGE_SIGNATURE;
FontPackage->FontPkgHdr = FontPkgHdr;
InitializeListHead (&FontPackage->GlyphInfoList);
FontPackage->GlyphBlock = (UINT8 *) AllocateZeroPool (PackageHeader.Length - HeaderSize);
if (FontPackage->GlyphBlock == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
CopyMem (FontPackage->GlyphBlock, (UINT8 *) PackageHdr + HeaderSize, PackageHeader.Length - HeaderSize);
//
// Collect all default character cell information and backup in GlyphInfoList.
//
Status = FindGlyphBlock (FontPackage, (CHAR16) (-1), NULL, NULL, NULL);
if (EFI_ERROR (Status)) {
goto Error;
}
//
// This font package describes an unique EFI_FONT_INFO. Backup it in global
// font info list.
//
GlobalFont = (HII_GLOBAL_FONT_INFO *) AllocateZeroPool (sizeof (HII_GLOBAL_FONT_INFO));
if (GlobalFont == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
GlobalFont->Signature = HII_GLOBAL_FONT_INFO_SIGNATURE;
GlobalFont->FontPackage = FontPackage;
GlobalFont->FontInfoSize = FontInfoSize;
GlobalFont->FontInfo = FontInfo;
InsertTailList (&Private->FontInfoList, &GlobalFont->Entry);
//
// Insert this font package to Font package array
//
InsertTailList (&PackageList->FontPkgHdr, &FontPackage->FontEntry);
*Package = FontPackage;
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += FontPackage->FontPkgHdr->Header.Length;
}
return EFI_SUCCESS;
Error:
if (FontPkgHdr != NULL) {
FreePool (FontPkgHdr);
}
if (FontInfo != NULL) {
FreePool (FontInfo);
}
if (FontPackage != NULL) {
if (FontPackage->GlyphBlock != NULL) {
FreePool (FontPackage->GlyphBlock);
}
FreePool (FontPackage);
}
if (GlobalFont != NULL) {
FreePool (GlobalFont);
}
return Status;
}
/**
This function exports Font packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Font Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportFontPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
LIST_ENTRY *Link;
UINTN PackageLength;
EFI_STATUS Status;
HII_FONT_PACKAGE_INSTANCE *Package;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
PackageLength = 0;
Status = EFI_SUCCESS;
for (Link = PackageList->FontPkgHdr.ForwardLink; Link != &PackageList->FontPkgHdr; Link = Link->ForwardLink) {
Package = CR (Link, HII_FONT_PACKAGE_INSTANCE, FontEntry, HII_FONT_PACKAGE_SIGNATURE);
PackageLength += Package->FontPkgHdr->Header.Length;
if (PackageLength + *ResultSize + UsedSize <= BufferSize) {
//
// Invoke registered notification function with EXPORT_PACK notify type
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_FONTS,
Handle
);
ASSERT_EFI_ERROR (Status);
//
// Copy Font package header
//
CopyMem (Buffer, Package->FontPkgHdr, Package->FontPkgHdr->HdrSize);
Buffer = (UINT8 *) Buffer + Package->FontPkgHdr->HdrSize;
//
// Copy Glyph blocks information
//
CopyMem (
Buffer,
Package->GlyphBlock,
Package->FontPkgHdr->Header.Length - Package->FontPkgHdr->HdrSize
);
Buffer = (UINT8 *) Buffer + Package->FontPkgHdr->Header.Length - Package->FontPkgHdr->HdrSize;
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes all Font packages from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed Font packages.
@param PackageList Pointer to a package list that contains removing
packages.
@retval EFI_SUCCESS Font Package(s) is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveFontPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *ListHead;
HII_FONT_PACKAGE_INSTANCE *Package;
EFI_STATUS Status;
HII_GLYPH_INFO *GlyphInfo;
LIST_ENTRY *Link;
HII_GLOBAL_FONT_INFO *GlobalFont;
ListHead = &PackageList->FontPkgHdr;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->ForwardLink,
HII_FONT_PACKAGE_INSTANCE,
FontEntry,
HII_FONT_PACKAGE_SIGNATURE
);
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_FONTS,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
RemoveEntryList (&Package->FontEntry);
PackageList->PackageListHdr.PackageLength -= Package->FontPkgHdr->Header.Length;
if (Package->GlyphBlock != NULL) {
FreePool (Package->GlyphBlock);
}
FreePool (Package->FontPkgHdr);
//
// Delete default character cell information
//
while (!IsListEmpty (&Package->GlyphInfoList)) {
GlyphInfo = CR (
Package->GlyphInfoList.ForwardLink,
HII_GLYPH_INFO,
Entry,
HII_GLYPH_INFO_SIGNATURE
);
RemoveEntryList (&GlyphInfo->Entry);
FreePool (GlyphInfo);
}
//
// Remove corresponding global font info
//
for (Link = Private->FontInfoList.ForwardLink; Link != &Private->FontInfoList; Link = Link->ForwardLink) {
GlobalFont = CR (Link, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);
if (GlobalFont->FontPackage == Package) {
RemoveEntryList (&GlobalFont->Entry);
FreePool (GlobalFont->FontInfo);
FreePool (GlobalFont);
break;
}
}
FreePool (Package);
}
return EFI_SUCCESS;
}
/**
This function insert a Image package to a package list node.
This is a internal function.
@param PackageHdr Pointer to a buffer stored with Image package
information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created Image package
@retval EFI_SUCCESS Image Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Image package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
**/
EFI_STATUS
InsertImagePackage (
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_IMAGE_PACKAGE_INSTANCE **Package
)
{
HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;
UINT32 PaletteSize;
UINT32 ImageSize;
UINT16 Index;
EFI_HII_IMAGE_PALETTE_INFO_HEADER *PaletteHdr;
EFI_HII_IMAGE_PALETTE_INFO *PaletteInfo;
UINT32 PaletteInfoOffset;
UINT32 ImageInfoOffset;
UINT16 CurrentSize;
if (PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Less than one image package is allowed in one package list.
//
if (PackageList->ImagePkg != NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Create a Image package node
//
ImagePackage = (HII_IMAGE_PACKAGE_INSTANCE *) AllocateZeroPool (sizeof (HII_IMAGE_PACKAGE_INSTANCE));
if (ImagePackage == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Copy the Image package header.
//
CopyMem (&ImagePackage->ImagePkgHdr, PackageHdr, sizeof (EFI_HII_IMAGE_PACKAGE_HDR));
PaletteInfoOffset = ImagePackage->ImagePkgHdr.PaletteInfoOffset;
ImageInfoOffset = ImagePackage->ImagePkgHdr.ImageInfoOffset;
//
// If PaletteInfoOffset is zero, there are no palettes in this image package.
//
PaletteSize = 0;
ImagePackage->PaletteBlock = NULL;
if (PaletteInfoOffset != 0) {
PaletteHdr = (EFI_HII_IMAGE_PALETTE_INFO_HEADER *) ((UINT8 *) PackageHdr + PaletteInfoOffset);
PaletteSize = sizeof (EFI_HII_IMAGE_PALETTE_INFO_HEADER);
PaletteInfo = (EFI_HII_IMAGE_PALETTE_INFO *) ((UINT8 *) PaletteHdr + PaletteSize);
for (Index = 0; Index < PaletteHdr->PaletteCount; Index++) {
CopyMem (&CurrentSize, PaletteInfo, sizeof (UINT16));
CurrentSize += sizeof (UINT16);
PaletteSize += (UINT32) CurrentSize;
PaletteInfo = (EFI_HII_IMAGE_PALETTE_INFO *) ((UINT8 *) PaletteInfo + CurrentSize);
}
ImagePackage->PaletteBlock = (UINT8 *) AllocateZeroPool (PaletteSize);
if (ImagePackage->PaletteBlock == NULL) {
FreePool (ImagePackage);
return EFI_OUT_OF_RESOURCES;
}
CopyMem (
ImagePackage->PaletteBlock,
(UINT8 *) PackageHdr + PaletteInfoOffset,
PaletteSize
);
}
//
// If ImageInfoOffset is zero, there are no images in this package.
//
ImageSize = 0;
ImagePackage->ImageBlock = NULL;
if (ImageInfoOffset != 0) {
ImageSize = ImagePackage->ImagePkgHdr.Header.Length -
sizeof (EFI_HII_IMAGE_PACKAGE_HDR) - PaletteSize;
ImagePackage->ImageBlock = AllocateZeroPool (ImageSize);
if (ImagePackage->ImageBlock == NULL) {
FreePool (ImagePackage->PaletteBlock);
FreePool (ImagePackage);
return EFI_OUT_OF_RESOURCES;
}
CopyMem (
ImagePackage->ImageBlock,
(UINT8 *) PackageHdr + ImageInfoOffset,
ImageSize
);
}
ImagePackage->ImageBlockSize = ImageSize;
ImagePackage->PaletteInfoSize = PaletteSize;
PackageList->ImagePkg = ImagePackage;
*Package = ImagePackage;
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += ImagePackage->ImagePkgHdr.Header.Length;
}
return EFI_SUCCESS;
}
/**
This function exports Image packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Image Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportImagePackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
UINTN PackageLength;
EFI_STATUS Status;
HII_IMAGE_PACKAGE_INSTANCE *Package;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
Package = PackageList->ImagePkg;
if (Package == NULL) {
return EFI_SUCCESS;
}
PackageLength = Package->ImagePkgHdr.Header.Length;
if (PackageLength + *ResultSize + UsedSize <= BufferSize) {
//
// Invoke registered notification function with EXPORT_PACK notify type
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_IMAGES,
Handle
);
ASSERT_EFI_ERROR (Status);
ASSERT (Package->ImagePkgHdr.Header.Length ==
sizeof (EFI_HII_IMAGE_PACKAGE_HDR) + Package->ImageBlockSize + Package->PaletteInfoSize);
//
// Copy Image package header,
// then justify the offset for image info and palette info in the header.
//
CopyMem (Buffer, &Package->ImagePkgHdr, sizeof (EFI_HII_IMAGE_PACKAGE_HDR));
Buffer = (UINT8 *) Buffer + sizeof (EFI_HII_IMAGE_PACKAGE_HDR);
//
// Copy Image blocks information
//
if (Package->ImageBlockSize != 0) {
CopyMem (Buffer, Package->ImageBlock, Package->ImageBlockSize);
Buffer = (UINT8 *) Buffer + Package->ImageBlockSize;
}
//
// Copy Palette information
//
if (Package->PaletteInfoSize != 0) {
CopyMem (Buffer, Package->PaletteBlock, Package->PaletteInfoSize);
Buffer = (UINT8 *) Buffer + Package->PaletteInfoSize;
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes Image package from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed Image packages.
@param PackageList Package List which contains the to be removed
Image package.
@retval EFI_SUCCESS Image Package(s) is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveImagePackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
HII_IMAGE_PACKAGE_INSTANCE *Package;
EFI_STATUS Status;
Package = PackageList->ImagePkg;
//
// Image package does not exist, return directly.
//
if (Package == NULL) {
return EFI_SUCCESS;
}
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_IMAGES,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
PackageList->PackageListHdr.PackageLength -= Package->ImagePkgHdr.Header.Length;
FreePool (Package->ImageBlock);
if (Package->PaletteBlock != NULL) {
FreePool (Package->PaletteBlock);
}
FreePool (Package);
PackageList->ImagePkg = NULL;
return EFI_SUCCESS;
}
/**
This function insert a Simple Font package to a package list node.
This is a internal function.
@param PackageHdr Pointer to a buffer stored with Simple Font
package information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created Simple Font package
@retval EFI_SUCCESS Simple Font Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Simple Font package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
**/
EFI_STATUS
InsertSimpleFontPackage (
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_SIMPLE_FONT_PACKAGE_INSTANCE **Package
)
{
HII_SIMPLE_FONT_PACKAGE_INSTANCE *SimpleFontPackage;
EFI_STATUS Status;
EFI_HII_PACKAGE_HEADER Header;
if (PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Create a Simple Font package node
//
SimpleFontPackage = AllocateZeroPool (sizeof (HII_SIMPLE_FONT_PACKAGE_INSTANCE));
if (SimpleFontPackage == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
SimpleFontPackage->Signature = HII_S_FONT_PACKAGE_SIGNATURE;
//
// Copy the Simple Font package.
//
CopyMem (&Header, PackageHdr, sizeof (EFI_HII_PACKAGE_HEADER));
SimpleFontPackage->SimpleFontPkgHdr = AllocateZeroPool (Header.Length);
if (SimpleFontPackage->SimpleFontPkgHdr == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
CopyMem (SimpleFontPackage->SimpleFontPkgHdr, PackageHdr, Header.Length);
//
// Insert to Simple Font package array
//
InsertTailList (&PackageList->SimpleFontPkgHdr, &SimpleFontPackage->SimpleFontEntry);
*Package = SimpleFontPackage;
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += Header.Length;
}
return EFI_SUCCESS;
Error:
if (SimpleFontPackage != NULL) {
if (SimpleFontPackage->SimpleFontPkgHdr != NULL) {
FreePool (SimpleFontPackage->SimpleFontPkgHdr);
}
FreePool (SimpleFontPackage);
}
return Status;
}
/**
This function exports SimpleFont packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS SimpleFont Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportSimpleFontPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
LIST_ENTRY *Link;
UINTN PackageLength;
EFI_STATUS Status;
HII_SIMPLE_FONT_PACKAGE_INSTANCE *Package;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
PackageLength = 0;
Status = EFI_SUCCESS;
for (Link = PackageList->SimpleFontPkgHdr.ForwardLink; Link != &PackageList->SimpleFontPkgHdr; Link = Link->ForwardLink) {
Package = CR (Link, HII_SIMPLE_FONT_PACKAGE_INSTANCE, SimpleFontEntry, HII_S_FONT_PACKAGE_SIGNATURE);
PackageLength += Package->SimpleFontPkgHdr->Header.Length;
if (PackageLength + *ResultSize + UsedSize <= BufferSize) {
//
// Invoke registered notification function with EXPORT_PACK notify type
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_SIMPLE_FONTS,
Handle
);
ASSERT_EFI_ERROR (Status);
//
// Copy SimpleFont package
//
CopyMem (Buffer, Package->SimpleFontPkgHdr, Package->SimpleFontPkgHdr->Header.Length);
Buffer = (UINT8 *) Buffer + Package->SimpleFontPkgHdr->Header.Length;
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes all Simple Font packages from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed Simple Font packages.
@param PackageList Pointer to a package list that contains removing
packages.
@retval EFI_SUCCESS Simple Font Package(s) is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveSimpleFontPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *ListHead;
HII_SIMPLE_FONT_PACKAGE_INSTANCE *Package;
EFI_STATUS Status;
ListHead = &PackageList->SimpleFontPkgHdr;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->ForwardLink,
HII_SIMPLE_FONT_PACKAGE_INSTANCE,
SimpleFontEntry,
HII_S_FONT_PACKAGE_SIGNATURE
);
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_SIMPLE_FONTS,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
RemoveEntryList (&Package->SimpleFontEntry);
PackageList->PackageListHdr.PackageLength -= Package->SimpleFontPkgHdr->Header.Length;
FreePool (Package->SimpleFontPkgHdr);
FreePool (Package);
}
return EFI_SUCCESS;
}
/**
This function insert a Device path package to a package list node.
This is a internal function.
@param DevicePath Pointer to a EFI_DEVICE_PATH_PROTOCOL protocol
instance
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@retval EFI_SUCCESS Device path Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Device path package.
@retval EFI_INVALID_PARAMETER DevicePath is NULL or PackageList is NULL.
**/
EFI_STATUS
InsertDevicePathPackage (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
UINT32 PackageLength;
EFI_HII_PACKAGE_HEADER Header;
if (DevicePath == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Less than one device path package is allowed in one package list.
//
if (PackageList->DevicePathPkg != NULL) {
return EFI_INVALID_PARAMETER;
}
PackageLength = (UINT32) GetDevicePathSize (DevicePath) + sizeof (EFI_HII_PACKAGE_HEADER);
PackageList->DevicePathPkg = (UINT8 *) AllocateZeroPool (PackageLength);
if (PackageList->DevicePathPkg == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Header.Length = PackageLength;
Header.Type = EFI_HII_PACKAGE_DEVICE_PATH;
CopyMem (PackageList->DevicePathPkg, &Header, sizeof (EFI_HII_PACKAGE_HEADER));
CopyMem (
PackageList->DevicePathPkg + sizeof (EFI_HII_PACKAGE_HEADER),
DevicePath,
PackageLength - sizeof (EFI_HII_PACKAGE_HEADER)
);
//
// Since Device Path package is created by NewPackageList, either NEW_PACK
// or ADD_PACK should increase the length of package list.
//
PackageList->PackageListHdr.PackageLength += PackageLength;
return EFI_SUCCESS;
}
/**
This function exports device path package to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Device path Package is exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportDevicePathPackage (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
EFI_STATUS Status;
UINT8 *Package;
EFI_HII_PACKAGE_HEADER Header;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
Package = PackageList->DevicePathPkg;
if (Package == NULL) {
return EFI_SUCCESS;
}
CopyMem (&Header, Package, sizeof (EFI_HII_PACKAGE_HEADER));
if (Header.Length + *ResultSize + UsedSize <= BufferSize) {
//
// Invoke registered notification function with EXPORT_PACK notify type
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_DEVICE_PATH,
Handle
);
ASSERT_EFI_ERROR (Status);
//
// Copy Device path package
//
CopyMem (Buffer, Package, Header.Length);
}
*ResultSize += Header.Length;
return EFI_SUCCESS;
}
/**
This function deletes Device Path package from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list.
@param PackageList Package List which contains the to be removed
Device Path package.
@retval EFI_SUCCESS Device Path Package is deleted successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveDevicePathPackage (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
EFI_STATUS Status;
UINT8 *Package;
EFI_HII_PACKAGE_HEADER Header;
Package = PackageList->DevicePathPkg;
//
// No device path, return directly.
//
if (Package == NULL) {
return EFI_SUCCESS;
}
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_DEVICE_PATH,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem (&Header, Package, sizeof (EFI_HII_PACKAGE_HEADER));
PackageList->PackageListHdr.PackageLength -= Header.Length;
FreePool (Package);
PackageList->DevicePathPkg = NULL;
return EFI_SUCCESS;
}
/**
This function will insert a device path package to package list firstly then
invoke notification functions if any.
This is a internal function.
@param Private Hii database private structure.
@param NotifyType The type of change concerning the database.
@param DevicePath Pointer to a EFI_DEVICE_PATH_PROTOCOL protocol
instance
@param DatabaseRecord Pointer to a database record contains a package
list which will be inserted to.
@retval EFI_SUCCESS Device path Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Device path package.
@retval EFI_INVALID_PARAMETER DevicePath is NULL or PackageList is NULL.
**/
EFI_STATUS
AddDevicePathPackage (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN OUT HII_DATABASE_RECORD *DatabaseRecord
)
{
EFI_STATUS Status;
if (DevicePath == NULL) {
return EFI_SUCCESS;
}
ASSERT (Private != NULL);
ASSERT (DatabaseRecord != NULL);
//
// Create a device path package and insert to packagelist
//
Status = InsertDevicePathPackage (
DevicePath,
NotifyType,
DatabaseRecord->PackageList
);
if (EFI_ERROR (Status)) {
return Status;
}
return InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) DatabaseRecord->PackageList->DevicePathPkg,
EFI_HII_PACKAGE_DEVICE_PATH,
DatabaseRecord->Handle
);
}
/**
This function insert a Keyboard Layout package to a package list node.
This is a internal function.
@param PackageHdr Pointer to a buffer stored with Keyboard Layout
package information.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list which will be inserted
to.
@param Package Created Keyboard Layout package
@retval EFI_SUCCESS Keyboard Layout Package is inserted successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Keyboard Layout package.
@retval EFI_INVALID_PARAMETER PackageHdr is NULL or PackageList is NULL.
**/
EFI_STATUS
InsertKeyboardLayoutPackage (
IN VOID *PackageHdr,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
OUT HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE **Package
)
{
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *KeyboardLayoutPackage;
EFI_HII_PACKAGE_HEADER PackageHeader;
EFI_STATUS Status;
if (PackageHdr == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
CopyMem (&PackageHeader, PackageHdr, sizeof (EFI_HII_PACKAGE_HEADER));
//
// Create a Keyboard Layout package node
//
KeyboardLayoutPackage = AllocateZeroPool (sizeof (HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE));
if (KeyboardLayoutPackage == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
KeyboardLayoutPackage->Signature = HII_KB_LAYOUT_PACKAGE_SIGNATURE;
KeyboardLayoutPackage->KeyboardPkg = (UINT8 *) AllocateZeroPool (PackageHeader.Length);
if (KeyboardLayoutPackage->KeyboardPkg == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Error;
}
CopyMem (KeyboardLayoutPackage->KeyboardPkg, PackageHdr, PackageHeader.Length);
InsertTailList (&PackageList->KeyboardLayoutHdr, &KeyboardLayoutPackage->KeyboardEntry);
*Package = KeyboardLayoutPackage;
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
PackageList->PackageListHdr.PackageLength += PackageHeader.Length;
}
return EFI_SUCCESS;
Error:
if (KeyboardLayoutPackage != NULL) {
if (KeyboardLayoutPackage->KeyboardPkg != NULL) {
FreePool (KeyboardLayoutPackage->KeyboardPkg);
}
FreePool (KeyboardLayoutPackage);
}
return Status;
}
/**
This function exports Keyboard Layout packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Keyboard Layout Packages are exported
successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportKeyboardLayoutPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
)
{
LIST_ENTRY *Link;
UINTN PackageLength;
EFI_STATUS Status;
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *Package;
EFI_HII_PACKAGE_HEADER PackageHeader;
if (Private == NULL || PackageList == NULL || ResultSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
PackageLength = 0;
Status = EFI_SUCCESS;
for (Link = PackageList->KeyboardLayoutHdr.ForwardLink; Link != &PackageList->KeyboardLayoutHdr; Link = Link->ForwardLink) {
Package = CR (Link, HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE, KeyboardEntry, HII_KB_LAYOUT_PACKAGE_SIGNATURE);
CopyMem (&PackageHeader, Package->KeyboardPkg, sizeof (EFI_HII_PACKAGE_HEADER));
PackageLength += PackageHeader.Length;
if (PackageLength + *ResultSize + UsedSize <= BufferSize) {
//
// Invoke registered notification function with EXPORT_PACK notify type
//
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_EXPORT_PACK,
(EFI_HII_PACKAGE_HEADER *) Package,
EFI_HII_PACKAGE_KEYBOARD_LAYOUT,
Handle
);
ASSERT_EFI_ERROR (Status);
//
// Copy Keyboard Layout package
//
CopyMem (Buffer, Package->KeyboardPkg, PackageHeader.Length);
Buffer = (UINT8 *) Buffer + PackageHeader.Length;
}
}
*ResultSize += PackageLength;
return EFI_SUCCESS;
}
/**
This function deletes all Keyboard Layout packages from a package list node.
This is a internal function.
@param Private Hii database private data.
@param Handle Handle of the package list which contains the to
be removed Keyboard Layout packages.
@param PackageList Pointer to a package list that contains removing
packages.
@retval EFI_SUCCESS Keyboard Layout Package(s) is deleted
successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is not valid.
**/
EFI_STATUS
RemoveKeyboardLayoutPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN OUT HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList
)
{
LIST_ENTRY *ListHead;
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *Package;
EFI_HII_PACKAGE_HEADER PackageHeader;
EFI_STATUS Status;
ListHead = &PackageList->KeyboardLayoutHdr;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->ForwardLink,
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE,
KeyboardEntry,
HII_KB_LAYOUT_PACKAGE_SIGNATURE
);
Status = InvokeRegisteredFunction (
Private,
EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
(VOID *) Package,
EFI_HII_PACKAGE_KEYBOARD_LAYOUT,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
RemoveEntryList (&Package->KeyboardEntry);
CopyMem (&PackageHeader, Package->KeyboardPkg, sizeof (EFI_HII_PACKAGE_HEADER));
PackageList->PackageListHdr.PackageLength -= PackageHeader.Length;
FreePool (Package->KeyboardPkg);
FreePool (Package);
}
return EFI_SUCCESS;
}
/**
This function will insert a package list to hii database firstly then
invoke notification functions if any. It is the worker function of
HiiNewPackageList and HiiUpdatePackageList.
This is a internal function.
@param Private Hii database private structure.
@param NotifyType The type of change concerning the database.
@param PackageList Pointer to a package list.
@param DatabaseRecord Pointer to a database record contains a package
list instance which will be inserted to.
@retval EFI_SUCCESS All incoming packages are inserted to current
database.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
Device path package.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
AddPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
IN CONST EFI_HII_PACKAGE_LIST_HEADER *PackageList,
IN OUT HII_DATABASE_RECORD *DatabaseRecord
)
{
EFI_STATUS Status;
HII_GUID_PACKAGE_INSTANCE *GuidPackage;
HII_IFR_PACKAGE_INSTANCE *FormPackage;
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *KeyboardLayoutPackage;
HII_STRING_PACKAGE_INSTANCE *StringPackage;
HII_FONT_PACKAGE_INSTANCE *FontPackage;
HII_SIMPLE_FONT_PACKAGE_INSTANCE *SimpleFontPackage;
HII_IMAGE_PACKAGE_INSTANCE *ImagePackage;
EFI_HII_PACKAGE_HEADER *PackageHdrPtr;
EFI_HII_PACKAGE_HEADER PackageHeader;
UINT32 OldPackageListLen;
BOOLEAN StringPkgIsAdd;
//
// Initialize Variables
//
StringPkgIsAdd = FALSE;
FontPackage = NULL;
StringPackage = NULL;
GuidPackage = NULL;
FormPackage = NULL;
ImagePackage = NULL;
SimpleFontPackage = NULL;
KeyboardLayoutPackage = NULL;
//
// Process the package list header
//
OldPackageListLen = DatabaseRecord->PackageList->PackageListHdr.PackageLength;
CopyMem (
&DatabaseRecord->PackageList->PackageListHdr,
(VOID *) PackageList,
sizeof (EFI_HII_PACKAGE_LIST_HEADER)
);
if (NotifyType == EFI_HII_DATABASE_NOTIFY_ADD_PACK) {
DatabaseRecord->PackageList->PackageListHdr.PackageLength = OldPackageListLen;
}
PackageHdrPtr = (EFI_HII_PACKAGE_HEADER *) ((UINT8 *) PackageList + sizeof (EFI_HII_PACKAGE_LIST_HEADER));
CopyMem (&PackageHeader, PackageHdrPtr, sizeof (EFI_HII_PACKAGE_HEADER));
Status = EFI_SUCCESS;
while (PackageHeader.Type != EFI_HII_PACKAGE_END) {
switch (PackageHeader.Type) {
case EFI_HII_PACKAGE_TYPE_GUID:
Status = InsertGuidPackage (
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&GuidPackage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) GuidPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
break;
case EFI_HII_PACKAGE_FORMS:
Status = InsertFormPackage (
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&FormPackage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) FormPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
//
// If Hii runtime support feature is enabled,
// will export Hii info for runtime use after ReadyToBoot event triggered.
// If some driver add/update/remove packages from HiiDatabase after ReadyToBoot,
// will need to export the content of HiiDatabase.
// But if form packages added/updated, also need to export the ConfigResp string.
//
if (gExportAfterReadyToBoot) {
gExportConfigResp = TRUE;
}
break;
case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
Status = InsertKeyboardLayoutPackage (
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&KeyboardLayoutPackage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) KeyboardLayoutPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
break;
case EFI_HII_PACKAGE_STRINGS:
Status = InsertStringPackage (
Private,
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&StringPackage
);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (StringPackage != NULL);
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) StringPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
StringPkgIsAdd = TRUE;
break;
case EFI_HII_PACKAGE_FONTS:
Status = InsertFontPackage (
Private,
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&FontPackage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) FontPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
break;
case EFI_HII_PACKAGE_IMAGES:
Status = InsertImagePackage (
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&ImagePackage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) ImagePackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
break;
case EFI_HII_PACKAGE_SIMPLE_FONTS:
Status = InsertSimpleFontPackage (
PackageHdrPtr,
NotifyType,
DatabaseRecord->PackageList,
&SimpleFontPackage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) SimpleFontPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
break;
case EFI_HII_PACKAGE_DEVICE_PATH:
Status = AddDevicePathPackage (
Private,
NotifyType,
(EFI_DEVICE_PATH_PROTOCOL *) ((UINT8 *) PackageHdrPtr + sizeof (EFI_HII_PACKAGE_HEADER)),
DatabaseRecord
);
break;
default:
break;
}
if (EFI_ERROR (Status)) {
return Status;
}
//
// goto header of next package
//
PackageHdrPtr = (EFI_HII_PACKAGE_HEADER *) ((UINT8 *) PackageHdrPtr + PackageHeader.Length);
CopyMem (&PackageHeader, PackageHdrPtr, sizeof (EFI_HII_PACKAGE_HEADER));
}
//
// Adjust String Package to make sure all string packages have the same max string ID.
//
if (!EFI_ERROR (Status) && StringPkgIsAdd) {
Status = AdjustStringPackage (DatabaseRecord->PackageList);
}
return Status;
}
/**
This function exports a package list to a buffer. It is the worker function
of HiiExportPackageList.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer has been used by exporting
package lists when Handle is NULL.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@retval EFI_SUCCESS Keyboard Layout Packages are exported
successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportPackageList (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN OUT UINTN *UsedSize,
IN UINTN BufferSize,
OUT EFI_HII_PACKAGE_LIST_HEADER *Buffer
)
{
EFI_STATUS Status;
UINTN ResultSize;
EFI_HII_PACKAGE_HEADER EndofPackageList;
ASSERT (Private != NULL && PackageList != NULL && UsedSize != NULL);
ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
ASSERT (IsHiiHandleValid (Handle));
if (BufferSize > 0 && Buffer == NULL ) {
return EFI_INVALID_PARAMETER;
}
//
// Copy the package list header
// ResultSize indicates the length of the exported bytes of this package list
//
ResultSize = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
if (ResultSize + *UsedSize <= BufferSize) {
CopyMem ((VOID *) Buffer, PackageList, ResultSize);
}
//
// Copy the packages and invoke EXPORT_PACK notify functions if exists.
//
Status = ExportGuidPackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportFormPackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportKeyboardLayoutPackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportStringPackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportFontPackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportImagePackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportSimpleFontPackages (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = ExportDevicePathPackage (
Private,
Handle,
PackageList,
*UsedSize,
BufferSize,
(VOID *) ((UINT8 *) Buffer + ResultSize),
&ResultSize
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Append the package list end.
//
EndofPackageList.Length = sizeof (EFI_HII_PACKAGE_HEADER);
EndofPackageList.Type = EFI_HII_PACKAGE_END;
if (ResultSize + *UsedSize + sizeof (EFI_HII_PACKAGE_HEADER) <= BufferSize) {
CopyMem (
(VOID *) ((UINT8 *) Buffer + ResultSize),
(VOID *) &EndofPackageList,
sizeof (EFI_HII_PACKAGE_HEADER)
);
}
*UsedSize += ResultSize + sizeof (EFI_HII_PACKAGE_HEADER);
return EFI_SUCCESS;
}
/**
This function mainly use to get and update ConfigResp string.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL instance.
@retval EFI_SUCCESS Get the information successfully.
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the Configuration Setting data.
**/
EFI_STATUS
HiiGetConfigRespInfo(
IN CONST EFI_HII_DATABASE_PROTOCOL *This
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
EFI_STRING ConfigAltResp;
UINTN ConfigSize;
ConfigAltResp = NULL;
ConfigSize = 0;
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
//
// Get ConfigResp string
//
Status = HiiConfigRoutingExportConfig(&Private->ConfigRouting,&ConfigAltResp);
if (!EFI_ERROR (Status)){
ConfigSize = StrSize(ConfigAltResp);
if (ConfigSize > gConfigRespSize){
//
// Do 25% overallocation to minimize the number of memory allocations after ReadyToBoot.
// Since lots of allocation after ReadyToBoot may change memory map and cause S4 resume issue.
//
gConfigRespSize = ConfigSize + (ConfigSize >> 2);
if (gRTConfigRespBuffer != NULL){
FreePool(gRTConfigRespBuffer);
DEBUG ((DEBUG_WARN, "[HiiDatabase]: Memory allocation is required after ReadyToBoot, which may change memory map and cause S4 resume issue.\n"));
}
gRTConfigRespBuffer = (EFI_STRING) AllocateRuntimeZeroPool (gConfigRespSize);
if (gRTConfigRespBuffer == NULL){
FreePool(ConfigAltResp);
DEBUG ((DEBUG_ERROR, "[HiiDatabase]: No enough memory resource to store the ConfigResp string.\n"));
return EFI_OUT_OF_RESOURCES;
}
} else {
ZeroMem(gRTConfigRespBuffer,gConfigRespSize);
}
CopyMem(gRTConfigRespBuffer,ConfigAltResp,ConfigSize);
gBS->InstallConfigurationTable (&gEfiHiiConfigRoutingProtocolGuid, gRTConfigRespBuffer);
FreePool(ConfigAltResp);
}
return EFI_SUCCESS;
}
/**
This is an internal function,mainly use to get HiiDatabase information.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL instance.
@retval EFI_SUCCESS Get the information successfully.
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the Hiidatabase data.
**/
EFI_STATUS
HiiGetDatabaseInfo(
IN CONST EFI_HII_DATABASE_PROTOCOL *This
)
{
EFI_STATUS Status;
EFI_HII_PACKAGE_LIST_HEADER *DatabaseInfo;
UINTN DatabaseInfoSize;
DatabaseInfo = NULL;
DatabaseInfoSize = 0;
//
// Get HiiDatabase information.
//
Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, DatabaseInfo);
ASSERT(Status == EFI_BUFFER_TOO_SMALL);
if(DatabaseInfoSize > gDatabaseInfoSize ) {
//
// Do 25% overallocation to minimize the number of memory allocations after ReadyToBoot.
// Since lots of allocation after ReadyToBoot may change memory map and cause S4 resume issue.
//
gDatabaseInfoSize = DatabaseInfoSize + (DatabaseInfoSize >> 2);
if (gRTDatabaseInfoBuffer != NULL){
FreePool(gRTDatabaseInfoBuffer);
DEBUG ((DEBUG_WARN, "[HiiDatabase]: Memory allocation is required after ReadyToBoot, which may change memory map and cause S4 resume issue.\n"));
}
gRTDatabaseInfoBuffer = AllocateRuntimeZeroPool (gDatabaseInfoSize);
if (gRTDatabaseInfoBuffer == NULL){
DEBUG ((DEBUG_ERROR, "[HiiDatabase]: No enough memory resource to store the HiiDatabase info.\n"));
return EFI_OUT_OF_RESOURCES;
}
} else {
ZeroMem(gRTDatabaseInfoBuffer,gDatabaseInfoSize);
}
Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, gRTDatabaseInfoBuffer);
ASSERT_EFI_ERROR (Status);
gBS->InstallConfigurationTable (&gEfiHiiDatabaseProtocolGuid, gRTDatabaseInfoBuffer);
return EFI_SUCCESS;
}
/**
This function adds the packages in the package list to the database and returns a handle. If there is a
EFI_DEVICE_PATH_PROTOCOL associated with the DriverHandle, then this function will
create a package of type EFI_PACKAGE_TYPE_DEVICE_PATH and add it to the package list.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param PackageList A pointer to an EFI_HII_PACKAGE_LIST_HEADER
structure.
@param DriverHandle Associate the package list with this EFI handle.
If a NULL is specified, this data will not be associate
with any drivers and cannot have a callback induced.
@param Handle A pointer to the EFI_HII_HANDLE instance.
@retval EFI_SUCCESS The package list associated with the Handle was
added to the HII database.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary resources for the new
database contents.
@retval EFI_INVALID_PARAMETER PackageList is NULL or Handle is NULL.
@retval EFI_INVALID_PARAMETER PackageListGuid already exists in database.
**/
EFI_STATUS
EFIAPI
HiiNewPackageList (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN CONST EFI_HII_PACKAGE_LIST_HEADER *PackageList,
IN CONST EFI_HANDLE DriverHandle, OPTIONAL
OUT EFI_HII_HANDLE *Handle
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_RECORD *DatabaseRecord;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
LIST_ENTRY *Link;
EFI_GUID PackageListGuid;
if (This == NULL || PackageList == NULL || Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
CopyMem (&PackageListGuid, (VOID *) PackageList, sizeof (EFI_GUID));
//
// Check the Package list GUID to guarantee this GUID is unique in database.
//
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
if (CompareGuid (
&(DatabaseRecord->PackageList->PackageListHdr.PackageListGuid),
&PackageListGuid) &&
DatabaseRecord->DriverHandle == DriverHandle) {
return EFI_INVALID_PARAMETER;
}
}
EfiAcquireLock (&mHiiDatabaseLock);
//
// Build a PackageList node
//
Status = GenerateHiiDatabaseRecord (Private, &DatabaseRecord);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
//
// Fill in information of the created Package List node
// according to incoming package list.
//
Status = AddPackages (Private, EFI_HII_DATABASE_NOTIFY_NEW_PACK, PackageList, DatabaseRecord);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
DatabaseRecord->DriverHandle = DriverHandle;
//
// Create a Device path package and add into the package list if exists.
//
Status = gBS->HandleProtocol (
DriverHandle,
&gEfiDevicePathProtocolGuid,
(VOID **) &DevicePath
);
if (!EFI_ERROR (Status)) {
Status = AddDevicePathPackage (Private, EFI_HII_DATABASE_NOTIFY_NEW_PACK, DevicePath, DatabaseRecord);
ASSERT_EFI_ERROR (Status);
}
*Handle = DatabaseRecord->Handle;
//
// Check whether need to get the Database info.
// Only after ReadyToBoot, need to do the export.
//
if (gExportAfterReadyToBoot) {
HiiGetDatabaseInfo (This);
}
EfiReleaseLock (&mHiiDatabaseLock);
//
// Notes:
// HiiGetDatabaseInfo () will get the contents of HII data base,
// belong to the atomic behavior of Hii Database update.
// And since HiiGetConfigRespInfo () will get the configuration setting info from HII drivers
// we can not think it belong to the atomic behavior of Hii Database update.
// That's why EfiReleaseLock (&mHiiDatabaseLock) is callled before HiiGetConfigRespInfo ().
//
// Check whether need to get the configuration setting info from HII drivers.
// When after ReadyToBoot and need to do the export for form package add.
//
if (gExportAfterReadyToBoot && gExportConfigResp) {
HiiGetConfigRespInfo (This);
}
return EFI_SUCCESS;
}
/**
This function removes the package list that is associated with Handle
from the HII database. Before removing the package, any registered functions
with the notification type REMOVE_PACK and the same package type will be called.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param Handle The handle that was registered to the data that is
requested for removal.
@retval EFI_SUCCESS The data associated with the Handle was removed
from the HII database.
@retval EFI_NOT_FOUND The specified handle is not in database.
@retval EFI_INVALID_PARAMETER The Handle was not valid.
**/
EFI_STATUS
EFIAPI
HiiRemovePackageList (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE Handle
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
LIST_ENTRY *Link;
HII_DATABASE_RECORD *Node;
HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList;
HII_HANDLE *HiiHandle;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
if (!IsHiiHandleValid (Handle)) {
return EFI_NOT_FOUND;
}
EfiAcquireLock (&mHiiDatabaseLock);
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
//
// Get the packagelist to be removed.
//
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
if (Node->Handle == Handle) {
PackageList = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (Node->PackageList);
ASSERT (PackageList != NULL);
//
// Call registered functions with REMOVE_PACK before removing packages
// then remove them.
//
Status = RemoveGuidPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveFormPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveKeyboardLayoutPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveStringPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveFontPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveImagePackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveSimpleFontPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
Status = RemoveDevicePathPackage (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
//
// Free resources of the package list
//
RemoveEntryList (&Node->DatabaseEntry);
HiiHandle = (HII_HANDLE *) Handle;
RemoveEntryList (&HiiHandle->Handle);
Private->HiiHandleCount--;
ASSERT (Private->HiiHandleCount >= 0);
HiiHandle->Signature = 0;
FreePool (HiiHandle);
FreePool (Node->PackageList);
FreePool (Node);
//
// Check whether need to get the Database info.
// Only after ReadyToBoot, need to do the export.
//
if (gExportAfterReadyToBoot) {
HiiGetDatabaseInfo (This);
}
EfiReleaseLock (&mHiiDatabaseLock);
//
// Notes:
// HiiGetDatabaseInfo () will get the contents of HII data base,
// belong to the atomic behavior of Hii Database update.
// And since HiiGetConfigRespInfo () will get the configuration setting info from HII drivers
// we can not think it belong to the atomic behavior of Hii Database update.
// That's why EfiReleaseLock (&mHiiDatabaseLock) is callled before HiiGetConfigRespInfo ().
//
//
// Check whether need to get the configuration setting info from HII drivers.
// When after ReadyToBoot and need to do the export for form package remove.
//
if (gExportAfterReadyToBoot && gExportConfigResp) {
HiiGetConfigRespInfo (This);
}
return EFI_SUCCESS;
}
}
EfiReleaseLock (&mHiiDatabaseLock);
return EFI_NOT_FOUND;
}
/**
This function updates the existing package list (which has the specified Handle)
in the HII databases, using the new package list specified by PackageList.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param Handle The handle that was registered to the data that is
requested to be updated.
@param PackageList A pointer to an EFI_HII_PACKAGE_LIST_HEADER
package.
@retval EFI_SUCCESS The HII database was successfully updated.
@retval EFI_OUT_OF_RESOURCES Unable to allocate enough memory for the updated
database.
@retval EFI_INVALID_PARAMETER PackageList was NULL.
@retval EFI_NOT_FOUND The specified Handle is not in database.
**/
EFI_STATUS
EFIAPI
HiiUpdatePackageList (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN CONST EFI_HII_PACKAGE_LIST_HEADER *PackageList
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
LIST_ENTRY *Link;
HII_DATABASE_RECORD *Node;
EFI_HII_PACKAGE_HEADER *PackageHdrPtr;
HII_DATABASE_PACKAGE_LIST_INSTANCE *OldPackageList;
EFI_HII_PACKAGE_HEADER PackageHeader;
if (This == NULL || PackageList == NULL) {
return EFI_INVALID_PARAMETER;
}
if (!IsHiiHandleValid (Handle)) {
return EFI_NOT_FOUND;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
PackageHdrPtr = (EFI_HII_PACKAGE_HEADER *) ((UINT8 *) PackageList + sizeof (EFI_HII_PACKAGE_LIST_HEADER));
Status = EFI_SUCCESS;
EfiAcquireLock (&mHiiDatabaseLock);
//
// Get original packagelist to be updated
//
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
if (Node->Handle == Handle) {
OldPackageList = Node->PackageList;
//
// Remove the package if its type matches one of the package types which is
// contained in the new package list.
//
CopyMem (&PackageHeader, PackageHdrPtr, sizeof (EFI_HII_PACKAGE_HEADER));
while (PackageHeader.Type != EFI_HII_PACKAGE_END) {
switch (PackageHeader.Type) {
case EFI_HII_PACKAGE_TYPE_GUID:
Status = RemoveGuidPackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_FORMS:
Status = RemoveFormPackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
Status = RemoveKeyboardLayoutPackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_STRINGS:
Status = RemoveStringPackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_FONTS:
Status = RemoveFontPackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_IMAGES:
Status = RemoveImagePackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_SIMPLE_FONTS:
Status = RemoveSimpleFontPackages (Private, Handle, OldPackageList);
break;
case EFI_HII_PACKAGE_DEVICE_PATH:
Status = RemoveDevicePathPackage (Private, Handle, OldPackageList);
break;
}
if (EFI_ERROR (Status)) {
EfiReleaseLock (&mHiiDatabaseLock);
return Status;
}
PackageHdrPtr = (EFI_HII_PACKAGE_HEADER *) ((UINT8 *) PackageHdrPtr + PackageHeader.Length);
CopyMem (&PackageHeader, PackageHdrPtr, sizeof (EFI_HII_PACKAGE_HEADER));
}
//
// Add all of the packages within the new package list
//
Status = AddPackages (Private, EFI_HII_DATABASE_NOTIFY_ADD_PACK, PackageList, Node);
//
// Check whether need to get the Database info.
// Only after ReadyToBoot, need to do the export.
//
if (gExportAfterReadyToBoot && Status == EFI_SUCCESS) {
HiiGetDatabaseInfo (This);
}
EfiReleaseLock (&mHiiDatabaseLock);
//
// Notes:
// HiiGetDatabaseInfo () will get the contents of HII data base,
// belong to the atomic behavior of Hii Database update.
// And since HiiGetConfigRespInfo () will get the configuration setting info from HII drivers
// we can not think it belong to the atomic behavior of Hii Database update.
// That's why EfiReleaseLock (&mHiiDatabaseLock) is callled before HiiGetConfigRespInfo ().
//
//
// Check whether need to get the configuration setting info from HII drivers.
// When after ReadyToBoot and need to do the export for form package update.
//
if (gExportAfterReadyToBoot && gExportConfigResp && Status == EFI_SUCCESS) {
HiiGetConfigRespInfo (This);
}
return Status;
}
}
EfiReleaseLock (&mHiiDatabaseLock);
return EFI_NOT_FOUND;
}
/**
This function returns a list of the package handles of the specified type
that are currently active in the database. The pseudo-type
EFI_HII_PACKAGE_TYPE_ALL will cause all package handles to be listed.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param PackageType Specifies the package type of the packages to list
or EFI_HII_PACKAGE_TYPE_ALL for all packages to be
listed.
@param PackageGuid If PackageType is EFI_HII_PACKAGE_TYPE_GUID, then
this is the pointer to the GUID which must match
the Guid field of EFI_HII_GUID_PACKAGE_GUID_HDR.
Otherwise, it must be NULL.
@param HandleBufferLength On input, a pointer to the length of the handle
buffer. On output, the length of the handle
buffer that is required for the handles found.
@param Handle An array of EFI_HII_HANDLE instances returned.
@retval EFI_SUCCESS The matching handles are outputted successfully.
HandleBufferLength is updated with the actual length.
@retval EFI_BUFFER_TO_SMALL The HandleBufferLength parameter indicates that
Handle is too small to support the number of
handles. HandleBufferLength is updated with a
value that will enable the data to fit.
@retval EFI_NOT_FOUND No matching handle could not be found in database.
@retval EFI_INVALID_PARAMETER HandleBufferLength was NULL.
@retval EFI_INVALID_PARAMETER The value referenced by HandleBufferLength was not
zero and Handle was NULL.
@retval EFI_INVALID_PARAMETER PackageType is not a EFI_HII_PACKAGE_TYPE_GUID but
PackageGuid is not NULL, PackageType is a EFI_HII_
PACKAGE_TYPE_GUID but PackageGuid is NULL.
**/
EFI_STATUS
EFIAPI
HiiListPackageLists (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN UINT8 PackageType,
IN CONST EFI_GUID *PackageGuid,
IN OUT UINTN *HandleBufferLength,
OUT EFI_HII_HANDLE *Handle
)
{
HII_GUID_PACKAGE_INSTANCE *GuidPackage;
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_RECORD *Node;
LIST_ENTRY *Link;
BOOLEAN Matched;
HII_HANDLE **Result;
UINTN ResultSize;
HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList;
LIST_ENTRY *Link1;
//
// Check input parameters
//
if (This == NULL || HandleBufferLength == NULL) {
return EFI_INVALID_PARAMETER;
}
if (*HandleBufferLength > 0 && Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
if ((PackageType == EFI_HII_PACKAGE_TYPE_GUID && PackageGuid == NULL) ||
(PackageType != EFI_HII_PACKAGE_TYPE_GUID && PackageGuid != NULL)) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
Matched = FALSE;
Result = (HII_HANDLE **) Handle;
ResultSize = 0;
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
PackageList = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (Node->PackageList);
switch (PackageType) {
case EFI_HII_PACKAGE_TYPE_GUID:
for (Link1 = PackageList->GuidPkgHdr.ForwardLink; Link1 != &PackageList->GuidPkgHdr; Link1 = Link1->ForwardLink) {
GuidPackage = CR (Link1, HII_GUID_PACKAGE_INSTANCE, GuidEntry, HII_GUID_PACKAGE_SIGNATURE);
if (CompareGuid (
(EFI_GUID *) PackageGuid,
(EFI_GUID *) (GuidPackage->GuidPkg + sizeof (EFI_HII_PACKAGE_HEADER))
)) {
Matched = TRUE;
break;
}
}
break;
case EFI_HII_PACKAGE_FORMS:
if (!IsListEmpty (&PackageList->FormPkgHdr)) {
Matched = TRUE;
}
break;
case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
if (!IsListEmpty (&PackageList->KeyboardLayoutHdr)) {
Matched = TRUE;
}
break;
case EFI_HII_PACKAGE_STRINGS:
if (!IsListEmpty (&PackageList->StringPkgHdr)) {
Matched = TRUE;
}
break;
case EFI_HII_PACKAGE_FONTS:
if (!IsListEmpty (&PackageList->FontPkgHdr)) {
Matched = TRUE;
}
break;
case EFI_HII_PACKAGE_IMAGES:
if (PackageList->ImagePkg != NULL) {
Matched = TRUE;
}
break;
case EFI_HII_PACKAGE_SIMPLE_FONTS:
if (!IsListEmpty (&PackageList->SimpleFontPkgHdr)) {
Matched = TRUE;
}
break;
case EFI_HII_PACKAGE_DEVICE_PATH:
if (PackageList->DevicePathPkg != NULL) {
Matched = TRUE;
}
break;
//
// Pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package handles
// to be listed.
//
case EFI_HII_PACKAGE_TYPE_ALL:
Matched = TRUE;
break;
default:
break;
}
//
// This active package list has the specified package type, list it.
//
if (Matched) {
ResultSize += sizeof (EFI_HII_HANDLE);
if (ResultSize <= *HandleBufferLength) {
*Result++ = Node->Handle;
}
}
Matched = FALSE;
}
if (ResultSize == 0) {
return EFI_NOT_FOUND;
}
if (*HandleBufferLength < ResultSize) {
*HandleBufferLength = ResultSize;
return EFI_BUFFER_TOO_SMALL;
}
*HandleBufferLength = ResultSize;
return EFI_SUCCESS;
}
/**
This function will export one or all package lists in the database to a buffer.
For each package list exported, this function will call functions registered
with EXPORT_PACK and then copy the package list to the buffer.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param Handle An EFI_HII_HANDLE that corresponds to the desired
package list in the HII database to export or NULL
to indicate all package lists should be exported.
@param BufferSize On input, a pointer to the length of the buffer.
On output, the length of the buffer that is
required for the exported data.
@param Buffer A pointer to a buffer that will contain the
results of the export function.
@retval EFI_SUCCESS Package exported.
@retval EFI_BUFFER_TO_SMALL The HandleBufferLength parameter indicates that
Handle is too small to support the number of
handles. HandleBufferLength is updated with a
value that will enable the data to fit.
@retval EFI_NOT_FOUND The specified Handle could not be found in the
current database.
@retval EFI_INVALID_PARAMETER BufferSize was NULL.
@retval EFI_INVALID_PARAMETER The value referenced by BufferSize was not zero
and Buffer was NULL.
**/
EFI_STATUS
EFIAPI
HiiExportPackageLists (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN OUT UINTN *BufferSize,
OUT EFI_HII_PACKAGE_LIST_HEADER *Buffer
)
{
LIST_ENTRY *Link;
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_RECORD *Node;
UINTN UsedSize;
if (This == NULL || BufferSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (*BufferSize > 0 && Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if ((Handle != NULL) && (!IsHiiHandleValid (Handle))) {
return EFI_NOT_FOUND;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
UsedSize = 0;
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
if (Handle == NULL) {
//
// Export all package lists in current hii database.
//
Status = ExportPackageList (
Private,
Node->Handle,
(HII_DATABASE_PACKAGE_LIST_INSTANCE *) (Node->PackageList),
&UsedSize,
*BufferSize,
(EFI_HII_PACKAGE_LIST_HEADER *)((UINT8 *) Buffer + UsedSize)
);
ASSERT_EFI_ERROR (Status);
} else if (Handle != NULL && Node->Handle == Handle) {
Status = ExportPackageList (
Private,
Handle,
(HII_DATABASE_PACKAGE_LIST_INSTANCE *) (Node->PackageList),
&UsedSize,
*BufferSize,
Buffer
);
ASSERT_EFI_ERROR (Status);
if (*BufferSize < UsedSize) {
*BufferSize = UsedSize;
return EFI_BUFFER_TOO_SMALL;
}
return EFI_SUCCESS;
}
}
if (Handle == NULL && UsedSize != 0) {
if (*BufferSize < UsedSize) {
*BufferSize = UsedSize;
return EFI_BUFFER_TOO_SMALL;
}
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}
/**
This function registers a function which will be called when specified actions related to packages of
the specified type occur in the HII database. By registering a function, other HII-related drivers are
notified when specific package types are added, removed or updated in the HII database.
Each driver or application which registers a notification should use
EFI_HII_DATABASE_PROTOCOL.UnregisterPackageNotify() before exiting.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param PackageType Specifies the package type of the packages to list
or EFI_HII_PACKAGE_TYPE_ALL for all packages to be
listed.
@param PackageGuid If PackageType is EFI_HII_PACKAGE_TYPE_GUID, then
this is the pointer to the GUID which must match
the Guid field of
EFI_HII_GUID_PACKAGE_GUID_HDR. Otherwise, it must
be NULL.
@param PackageNotifyFn Points to the function to be called when the event
specified by
NotificationType occurs.
@param NotifyType Describes the types of notification which this
function will be receiving.
@param NotifyHandle Points to the unique handle assigned to the
registered notification. Can be used in
EFI_HII_DATABASE_PROTOCOL.UnregisterPackageNotify()
to stop notifications.
@retval EFI_SUCCESS Notification registered successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate necessary data structures
@retval EFI_INVALID_PARAMETER NotifyHandle is NULL.
@retval EFI_INVALID_PARAMETER PackageGuid is not NULL when PackageType is not
EFI_HII_PACKAGE_TYPE_GUID.
@retval EFI_INVALID_PARAMETER PackageGuid is NULL when PackageType is
EFI_HII_PACKAGE_TYPE_GUID.
**/
EFI_STATUS
EFIAPI
HiiRegisterPackageNotify (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN UINT8 PackageType,
IN CONST EFI_GUID *PackageGuid,
IN CONST EFI_HII_DATABASE_NOTIFY PackageNotifyFn,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
OUT EFI_HANDLE *NotifyHandle
)
{
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_NOTIFY *Notify;
EFI_STATUS Status;
if (This == NULL || NotifyHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
if ((PackageType == EFI_HII_PACKAGE_TYPE_GUID && PackageGuid == NULL) ||
(PackageType != EFI_HII_PACKAGE_TYPE_GUID && PackageGuid != NULL)) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
//
// Allocate a notification node
//
Notify = (HII_DATABASE_NOTIFY *) AllocateZeroPool (sizeof (HII_DATABASE_NOTIFY));
if (Notify == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Generate a notify handle
//
Status = gBS->InstallMultipleProtocolInterfaces (
&Notify->NotifyHandle,
&gEfiCallerIdGuid,
NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Fill in the information to the notification node
//
Notify->Signature = HII_DATABASE_NOTIFY_SIGNATURE;
Notify->PackageType = PackageType;
Notify->PackageGuid = (EFI_GUID *) PackageGuid;
Notify->PackageNotifyFn = (EFI_HII_DATABASE_NOTIFY) PackageNotifyFn;
Notify->NotifyType = NotifyType;
InsertTailList (&Private->DatabaseNotifyList, &Notify->DatabaseNotifyEntry);
*NotifyHandle = Notify->NotifyHandle;
return EFI_SUCCESS;
}
/**
Removes the specified HII database package-related notification.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param NotificationHandle The handle of the notification function being
unregistered.
@retval EFI_SUCCESS Notification is unregistered successfully.
@retval EFI_INVALID_PARAMETER The Handle is invalid.
@retval EFI_NOT_FOUND The incoming notification handle does not exist
in current hii database.
**/
EFI_STATUS
EFIAPI
HiiUnregisterPackageNotify (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HANDLE NotificationHandle
)
{
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_NOTIFY *Notify;
LIST_ENTRY *Link;
EFI_STATUS Status;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
if (NotificationHandle == NULL) {
return EFI_NOT_FOUND;
}
Status = gBS->OpenProtocol (
NotificationHandle,
&gEfiCallerIdGuid,
NULL,
NULL,
NULL,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
for (Link = Private->DatabaseNotifyList.ForwardLink; Link != &Private->DatabaseNotifyList; Link = Link->ForwardLink) {
Notify = CR (Link, HII_DATABASE_NOTIFY, DatabaseNotifyEntry, HII_DATABASE_NOTIFY_SIGNATURE);
if (Notify->NotifyHandle == NotificationHandle) {
//
// Remove the matching notification node
//
RemoveEntryList (&Notify->DatabaseNotifyEntry);
Status = gBS->UninstallMultipleProtocolInterfaces (
Notify->NotifyHandle,
&gEfiCallerIdGuid,
NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
FreePool (Notify);
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
This routine retrieves an array of GUID values for each keyboard layout that
was previously registered in the system.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param KeyGuidBufferLength On input, a pointer to the length of the keyboard
GUID buffer. On output, the length of the handle
buffer that is required for the handles found.
@param KeyGuidBuffer An array of keyboard layout GUID instances
returned.
@retval EFI_SUCCESS KeyGuidBuffer was updated successfully.
@retval EFI_BUFFER_TOO_SMALL The KeyGuidBufferLength parameter indicates
that KeyGuidBuffer is too small to support the
number of GUIDs. KeyGuidBufferLength is
updated with a value that will enable the data to
fit.
@retval EFI_INVALID_PARAMETER The KeyGuidBufferLength is NULL.
@retval EFI_INVALID_PARAMETER The value referenced by KeyGuidBufferLength is not
zero and KeyGuidBuffer is NULL.
@retval EFI_NOT_FOUND There was no keyboard layout.
**/
EFI_STATUS
EFIAPI
HiiFindKeyboardLayouts (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN OUT UINT16 *KeyGuidBufferLength,
OUT EFI_GUID *KeyGuidBuffer
)
{
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_RECORD *Node;
HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList;
LIST_ENTRY *Link;
LIST_ENTRY *Link1;
UINT16 ResultSize;
UINTN Index;
UINT16 LayoutCount;
UINT16 LayoutLength;
UINT8 *Layout;
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *Package;
if (This == NULL || KeyGuidBufferLength == NULL) {
return EFI_INVALID_PARAMETER;
}
if (*KeyGuidBufferLength > 0 && KeyGuidBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
ResultSize = 0;
//
// Search all package lists in whole database to retrieve keyboard layout.
//
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
PackageList = Node->PackageList;
for (Link1 = PackageList->KeyboardLayoutHdr.ForwardLink;
Link1 != &PackageList->KeyboardLayoutHdr;
Link1 = Link1->ForwardLink
) {
//
// Find out all Keyboard Layout packages in this package list.
//
Package = CR (
Link1,
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE,
KeyboardEntry,
HII_KB_LAYOUT_PACKAGE_SIGNATURE
);
Layout = (UINT8 *) Package->KeyboardPkg + sizeof (EFI_HII_PACKAGE_HEADER) + sizeof (UINT16);
CopyMem (
&LayoutCount,
(UINT8 *) Package->KeyboardPkg + sizeof (EFI_HII_PACKAGE_HEADER),
sizeof (UINT16)
);
for (Index = 0; Index < LayoutCount; Index++) {
ResultSize += sizeof (EFI_GUID);
if (ResultSize <= *KeyGuidBufferLength) {
CopyMem (KeyGuidBuffer + (ResultSize / sizeof (EFI_GUID) - 1), Layout + sizeof (UINT16), sizeof (EFI_GUID));
CopyMem (&LayoutLength, Layout, sizeof (UINT16));
Layout = Layout + LayoutLength;
}
}
}
}
if (ResultSize == 0) {
return EFI_NOT_FOUND;
}
if (*KeyGuidBufferLength < ResultSize) {
*KeyGuidBufferLength = ResultSize;
return EFI_BUFFER_TOO_SMALL;
}
*KeyGuidBufferLength = ResultSize;
return EFI_SUCCESS;
}
/**
This routine retrieves the requested keyboard layout. The layout is a physical description of the keys
on a keyboard and the character(s) that are associated with a particular set of key strokes.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param KeyGuid A pointer to the unique ID associated with a given
keyboard layout. If KeyGuid is NULL then the
current layout will be retrieved.
@param KeyboardLayoutLength On input, a pointer to the length of the
KeyboardLayout buffer. On output, the length of
the data placed into KeyboardLayout.
@param KeyboardLayout A pointer to a buffer containing the retrieved
keyboard layout.
@retval EFI_SUCCESS The keyboard layout was retrieved successfully.
@retval EFI_NOT_FOUND The requested keyboard layout was not found.
@retval EFI_INVALID_PARAMETER The KeyboardLayout or KeyboardLayoutLength was
NULL.
@retval EFI_BUFFER_TOO_SMALL The KeyboardLayoutLength parameter indicates
that KeyboardLayout is too small to support the
requested keyboard layout. KeyboardLayoutLength is
updated with a value that will enable the
data to fit.
**/
EFI_STATUS
EFIAPI
HiiGetKeyboardLayout (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN CONST EFI_GUID *KeyGuid,
IN OUT UINT16 *KeyboardLayoutLength,
OUT EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout
)
{
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_RECORD *Node;
HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList;
LIST_ENTRY *Link;
LIST_ENTRY *Link1;
UINTN Index;
UINT8 *Layout;
UINT16 LayoutCount;
UINT16 LayoutLength;
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE *Package;
if (This == NULL || KeyboardLayoutLength == NULL) {
return EFI_INVALID_PARAMETER;
}
if (*KeyboardLayoutLength > 0 && KeyboardLayout == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
//
// Retrieve the current keyboard layout.
//
if (KeyGuid == NULL) {
if (Private->CurrentLayout == NULL) {
return EFI_NOT_FOUND;
}
CopyMem (&LayoutLength, Private->CurrentLayout, sizeof (UINT16));
if (*KeyboardLayoutLength < LayoutLength) {
*KeyboardLayoutLength = LayoutLength;
return EFI_BUFFER_TOO_SMALL;
}
CopyMem (KeyboardLayout, Private->CurrentLayout, LayoutLength);
return EFI_SUCCESS;
}
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
PackageList = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (Node->PackageList);
for (Link1 = PackageList->KeyboardLayoutHdr.ForwardLink;
Link1 != &PackageList->KeyboardLayoutHdr;
Link1 = Link1->ForwardLink
) {
Package = CR (
Link1,
HII_KEYBOARD_LAYOUT_PACKAGE_INSTANCE,
KeyboardEntry,
HII_KB_LAYOUT_PACKAGE_SIGNATURE
);
Layout = (UINT8 *) Package->KeyboardPkg +
sizeof (EFI_HII_PACKAGE_HEADER) + sizeof (UINT16);
CopyMem (&LayoutCount, Layout - sizeof (UINT16), sizeof (UINT16));
for (Index = 0; Index < LayoutCount; Index++) {
CopyMem (&LayoutLength, Layout, sizeof (UINT16));
if (CompareMem (Layout + sizeof (UINT16), KeyGuid, sizeof (EFI_GUID)) == 0) {
if (LayoutLength <= *KeyboardLayoutLength) {
CopyMem (KeyboardLayout, Layout, LayoutLength);
return EFI_SUCCESS;
} else {
*KeyboardLayoutLength = LayoutLength;
return EFI_BUFFER_TOO_SMALL;
}
}
Layout = Layout + LayoutLength;
}
}
}
return EFI_NOT_FOUND;
}
/**
This routine sets the default keyboard layout to the one referenced by KeyGuid. When this routine
is called, an event will be signaled of the EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID
group type. This is so that agents which are sensitive to the current keyboard layout being changed
can be notified of this change.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param KeyGuid A pointer to the unique ID associated with a given
keyboard layout.
@retval EFI_SUCCESS The current keyboard layout was successfully set.
@retval EFI_NOT_FOUND The referenced keyboard layout was not found, so
action was taken.
@retval EFI_INVALID_PARAMETER The KeyGuid was NULL.
**/
EFI_STATUS
EFIAPI
HiiSetKeyboardLayout (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN CONST EFI_GUID *KeyGuid
)
{
HII_DATABASE_PRIVATE_DATA *Private;
EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout;
UINT16 KeyboardLayoutLength;
EFI_STATUS Status;
if (This == NULL || KeyGuid == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
//
// The specified GUID equals the current keyboard layout GUID,
// return directly.
//
if (CompareGuid (&Private->CurrentLayoutGuid, KeyGuid)) {
return EFI_SUCCESS;
}
//
// Try to find the incoming keyboard layout data in current database.
//
KeyboardLayoutLength = 0;
KeyboardLayout = NULL;
Status = HiiGetKeyboardLayout (This, KeyGuid, &KeyboardLayoutLength, KeyboardLayout);
if (Status != EFI_BUFFER_TOO_SMALL) {
return Status;
}
KeyboardLayout = (EFI_HII_KEYBOARD_LAYOUT *) AllocateZeroPool (KeyboardLayoutLength);
ASSERT (KeyboardLayout != NULL);
Status = HiiGetKeyboardLayout (This, KeyGuid, &KeyboardLayoutLength, KeyboardLayout);
ASSERT_EFI_ERROR (Status);
//
// Backup current keyboard layout.
//
CopyMem (&Private->CurrentLayoutGuid, KeyGuid, sizeof (EFI_GUID));
if (Private->CurrentLayout != NULL) {
FreePool(Private->CurrentLayout);
}
Private->CurrentLayout = KeyboardLayout;
//
// Signal EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group to notify
// current keyboard layout is changed.
//
Status = gBS->SignalEvent (gHiiKeyboardLayoutChanged);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}
/**
Return the EFI handle associated with a package list.
@param This A pointer to the EFI_HII_DATABASE_PROTOCOL
instance.
@param PackageListHandle An EFI_HII_HANDLE that corresponds to the desired
package list in the HIIdatabase.
@param DriverHandle On return, contains the EFI_HANDLE which was
registered with the package list in
NewPackageList().
@retval EFI_SUCCESS The DriverHandle was returned successfully.
@retval EFI_INVALID_PARAMETER The PackageListHandle was not valid or
DriverHandle was NULL.
@retval EFI_NOT_FOUND This PackageList handle can not be found in
current database.
**/
EFI_STATUS
EFIAPI
HiiGetPackageListHandle (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE PackageListHandle,
OUT EFI_HANDLE *DriverHandle
)
{
HII_DATABASE_PRIVATE_DATA *Private;
HII_DATABASE_RECORD *Node;
LIST_ENTRY *Link;
if (This == NULL || DriverHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
if (!IsHiiHandleValid (PackageListHandle)) {
return EFI_INVALID_PARAMETER;
}
Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
if (Node->Handle == PackageListHandle) {
*DriverHandle = Node->DriverHandle;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
|