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
|
/** @file
Implementation for EFI_HII_DATABASE_PROTOCOL.
Copyright (c) 2007 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "HiiDatabase.h"
//
// Global variables
//
EFI_GUID mHiiDatabaseNotifyGuid = HII_DATABASE_NOTIFY_GUID;
/**
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 = 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 pacakge
@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;
}
/**
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;
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 (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);
}
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;
}
AsciiStrCpy (Language, (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 (R8_EfiLibCompareLanguage (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, 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->StringBlock != NULL) {
FreePool (StringPackage->StringBlock);
}
if (StringPackage->StringPkgHdr != NULL) {
FreePool (StringPackage->StringPkgHdr);
}
if (StringPackage != NULL) {
FreePool (StringPackage);
}
return Status;
}
/**
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;
StrCpy (FontInfo->FontName, 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->GlyphBlock != NULL) {
FreePool (FontPackage->GlyphBlock);
}
if (FontPackage != NULL) {
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 = (UINT8 *) 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->SimpleFontPkgHdr != NULL) {
FreePool (SimpleFontPackage->SimpleFontPkgHdr);
}
if (SimpleFontPackage != NULL) {
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->KeyboardPkg != NULL) {
FreePool (KeyboardLayoutPackage->KeyboardPkg);
}
if (KeyboardLayoutPackage != NULL) {
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;
//
// Initialize Variables
//
FontPackage = 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
);
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;
}
Status = InvokeRegisteredFunction (
Private,
NotifyType,
(VOID *) StringPackage,
(UINT8) (PackageHeader.Type),
DatabaseRecord->Handle
);
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));
}
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 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.
@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,
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
)
) {
return EFI_INVALID_PARAMETER;
}
}
//
// Build a PackageList node
//
Status = GenerateHiiDatabaseRecord (Private, &DatabaseRecord);
if (EFI_ERROR (Status)) {
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)) {
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;
return EFI_SUCCESS;
}
/**
This function removes the package list that is associated with a handle 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 andle 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;
}
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)) {
return Status;
}
Status = RemoveFormPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
return Status;
}
Status = RemoveKeyboardLayoutPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
return Status;
}
Status = RemoveStringPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
return Status;
}
Status = RemoveFontPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
return Status;
}
Status = RemoveImagePackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
return Status;
}
Status = RemoveSimpleFontPackages (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
return Status;
}
Status = RemoveDevicePathPackage (Private, Handle, PackageList);
if (EFI_ERROR (Status)) {
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);
return EFI_SUCCESS;
}
}
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;
//
// 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)) {
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
//
return AddPackages (Private, EFI_HII_DATABASE_NOTIFY_ADD_PACK, PackageList, Node);
}
}
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 outputed 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 Handle or HandleBufferLength 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;
//
// Pesudo-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 specifiecd Handle could not be found in the
current database.
@retval EFI_INVALID_PARAMETER Handle or Buffer or BufferSize 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 || Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
if (*BufferSize > 0 && Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if (!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,
&mHiiDatabaseNotifyGuid,
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,
&mHiiDatabaseNotifyGuid,
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,
&mHiiDatabaseNotifyGuid,
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 KeyGuidBuffer or KeyGuidBufferLength was 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;
}
|