1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910
|
/** @file
Console Splitter Driver. Any Handle that attached console I/O protocols
(Console In device, Console Out device, Console Error device, Simple Pointer
protocol, Absolute Pointer protocol) can be bound by this driver.
So far it works like any other driver by opening a SimpleTextIn and/or
SimpleTextOut protocol with EFI_OPEN_PROTOCOL_BY_DRIVER attributes. The big
difference is this driver does not layer a protocol on the passed in
handle, or construct a child handle like a standard device or bus driver.
This driver produces three virtual handles as children, one for console input
splitter, one for console output splitter and one for error output splitter.
These 3 virtual handles would be installed on gST.
Each virtual handle, that supports the Console I/O protocol, will be produced
in the driver entry point. The virtual handle are added on driver entry and
never removed. Such design ensures system function well during none console
device situation.
Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "ConSplitter.h"
//
// Identify if ConIn is connected in PcdConInConnectOnDemand enabled mode.
// default not connect
//
BOOLEAN mConInIsConnect = FALSE;
//
// Text In Splitter Private Data template
//
GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA mConIn = {
TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,
(EFI_HANDLE)NULL,
{
ConSplitterTextInReset,
ConSplitterTextInReadKeyStroke,
(EFI_EVENT)NULL
},
0,
(EFI_SIMPLE_TEXT_INPUT_PROTOCOL **)NULL,
0,
{
ConSplitterTextInResetEx,
ConSplitterTextInReadKeyStrokeEx,
(EFI_EVENT)NULL,
ConSplitterTextInSetState,
ConSplitterTextInRegisterKeyNotify,
ConSplitterTextInUnregisterKeyNotify
},
0,
(EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **)NULL,
0,
{
(LIST_ENTRY *)NULL,
(LIST_ENTRY *)NULL
},
(EFI_KEY_DATA *)NULL,
0,
0,
FALSE,
{
ConSplitterSimplePointerReset,
ConSplitterSimplePointerGetState,
(EFI_EVENT)NULL,
(EFI_SIMPLE_POINTER_MODE *)NULL
},
{
0x10000,
0x10000,
0x10000,
TRUE,
TRUE
},
0,
(EFI_SIMPLE_POINTER_PROTOCOL **)NULL,
0,
{
ConSplitterAbsolutePointerReset,
ConSplitterAbsolutePointerGetState,
(EFI_EVENT)NULL,
(EFI_ABSOLUTE_POINTER_MODE *)NULL
},
{
0, // AbsoluteMinX
0, // AbsoluteMinY
0, // AbsoluteMinZ
0x10000, // AbsoluteMaxX
0x10000, // AbsoluteMaxY
0x10000, // AbsoluteMaxZ
0 // Attributes
},
0,
(EFI_ABSOLUTE_POINTER_PROTOCOL **)NULL,
0,
FALSE,
FALSE,
FALSE
};
//
// Graphics Output Protocol Private Data template
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {
ConSplitterGraphicsOutputQueryMode,
ConSplitterGraphicsOutputSetMode,
ConSplitterGraphicsOutputBlt,
NULL
};
//
// Text Out Splitter Private Data template
//
GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
(EFI_HANDLE)NULL,
{
ConSplitterTextOutReset,
ConSplitterTextOutOutputString,
ConSplitterTextOutTestString,
ConSplitterTextOutQueryMode,
ConSplitterTextOutSetMode,
ConSplitterTextOutSetAttribute,
ConSplitterTextOutClearScreen,
ConSplitterTextOutSetCursorPosition,
ConSplitterTextOutEnableCursor,
(EFI_SIMPLE_TEXT_OUTPUT_MODE *)NULL
},
{
1,
0,
0,
0,
0,
FALSE,
},
{
NULL,
NULL,
NULL,
NULL
},
(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)NULL,
0,
0,
(TEXT_OUT_AND_GOP_DATA *)NULL,
0,
(TEXT_OUT_SPLITTER_QUERY_DATA *)NULL,
0,
(INT32 *)NULL,
FALSE
};
//
// Standard Error Text Out Splitter Data Template
//
GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
(EFI_HANDLE)NULL,
{
ConSplitterTextOutReset,
ConSplitterTextOutOutputString,
ConSplitterTextOutTestString,
ConSplitterTextOutQueryMode,
ConSplitterTextOutSetMode,
ConSplitterTextOutSetAttribute,
ConSplitterTextOutClearScreen,
ConSplitterTextOutSetCursorPosition,
ConSplitterTextOutEnableCursor,
(EFI_SIMPLE_TEXT_OUTPUT_MODE *)NULL
},
{
1,
0,
0,
0,
0,
FALSE,
},
{
NULL,
NULL,
NULL,
NULL
},
(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)NULL,
0,
0,
(TEXT_OUT_AND_GOP_DATA *)NULL,
0,
(TEXT_OUT_SPLITTER_QUERY_DATA *)NULL,
0,
(INT32 *)NULL,
FALSE
};
//
// Driver binding instance for Console Input Device
//
EFI_DRIVER_BINDING_PROTOCOL gConSplitterConInDriverBinding = {
ConSplitterConInDriverBindingSupported,
ConSplitterConInDriverBindingStart,
ConSplitterConInDriverBindingStop,
0xa,
NULL,
NULL
};
//
// Driver binding instance for Console Out device
//
EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding = {
ConSplitterConOutDriverBindingSupported,
ConSplitterConOutDriverBindingStart,
ConSplitterConOutDriverBindingStop,
0xa,
NULL,
NULL
};
//
// Driver binding instance for Standard Error device
//
EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding = {
ConSplitterStdErrDriverBindingSupported,
ConSplitterStdErrDriverBindingStart,
ConSplitterStdErrDriverBindingStop,
0xa,
NULL,
NULL
};
//
// Driver binding instance for Simple Pointer protocol
//
EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding = {
ConSplitterSimplePointerDriverBindingSupported,
ConSplitterSimplePointerDriverBindingStart,
ConSplitterSimplePointerDriverBindingStop,
0xa,
NULL,
NULL
};
//
// Driver binding instance for Absolute Pointer protocol
//
EFI_DRIVER_BINDING_PROTOCOL gConSplitterAbsolutePointerDriverBinding = {
ConSplitterAbsolutePointerDriverBindingSupported,
ConSplitterAbsolutePointerDriverBindingStart,
ConSplitterAbsolutePointerDriverBindingStop,
0xa,
NULL,
NULL
};
/**
Key notify for toggle state sync.
@param KeyData A pointer to a buffer that is filled in with
the keystroke information for the key that was
pressed.
@retval EFI_SUCCESS Toggle state sync successfully.
**/
EFI_STATUS
EFIAPI
ToggleStateSyncKeyNotify (
IN EFI_KEY_DATA *KeyData
)
{
UINTN Index;
if (((KeyData->KeyState.KeyToggleState & KEY_STATE_VALID_EXPOSED) == KEY_STATE_VALID_EXPOSED) &&
(KeyData->KeyState.KeyToggleState != mConIn.PhysicalKeyToggleState))
{
//
// There is toggle state change, sync to other console input devices.
//
for (Index = 0; Index < mConIn.CurrentNumberOfExConsoles; Index++) {
mConIn.TextInExList[Index]->SetState (
mConIn.TextInExList[Index],
&KeyData->KeyState.KeyToggleState
);
}
mConIn.PhysicalKeyToggleState = KeyData->KeyState.KeyToggleState;
DEBUG ((DEBUG_INFO, "Current toggle state is 0x%02x\n", mConIn.PhysicalKeyToggleState));
}
return EFI_SUCCESS;
}
/**
Initialization for toggle state sync.
@param Private Text In Splitter pointer.
**/
VOID
ToggleStateSyncInitialization (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private
)
{
EFI_KEY_DATA KeyData;
VOID *NotifyHandle;
//
// Initialize PhysicalKeyToggleState that will be synced to new console
// input device to turn on physical TextInEx partial key report for
// toggle state sync.
//
Private->PhysicalKeyToggleState = KEY_STATE_VALID_EXPOSED;
//
// Initialize VirtualKeyStateExported to let the virtual TextInEx not report
// the partial key even though the physical TextInEx turns on the partial
// key report. The virtual TextInEx will report the partial key after it is
// required by calling SetState(X | KEY_STATE_VALID_EXPOSED) explicitly.
//
Private->VirtualKeyStateExported = FALSE;
//
// Register key notify for toggle state sync.
//
KeyData.Key.ScanCode = SCAN_NULL;
KeyData.Key.UnicodeChar = CHAR_NULL;
KeyData.KeyState.KeyShiftState = 0;
KeyData.KeyState.KeyToggleState = 0;
Private->TextInEx.RegisterKeyNotify (
&Private->TextInEx,
&KeyData,
ToggleStateSyncKeyNotify,
&NotifyHandle
);
}
/**
Re-initialization for toggle state sync.
@param Private Text In Splitter pointer.
**/
VOID
ToggleStateSyncReInitialization (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private
)
{
UINTN Index;
//
// Reinitialize PhysicalKeyToggleState that will be synced to new console
// input device to turn on physical TextInEx partial key report for
// toggle state sync.
//
Private->PhysicalKeyToggleState = KEY_STATE_VALID_EXPOSED;
//
// Reinitialize VirtualKeyStateExported to let the virtual TextInEx not report
// the partial key even though the physical TextInEx turns on the partial
// key report. The virtual TextInEx will report the partial key after it is
// required by calling SetState(X | KEY_STATE_VALID_EXPOSED) explicitly.
//
Private->VirtualKeyStateExported = FALSE;
for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
Private->TextInExList[Index]->SetState (
Private->TextInExList[Index],
&Private->PhysicalKeyToggleState
);
}
}
/**
The Entry Point for module ConSplitter. The user code starts with this function.
Installs driver module protocols and. Creates virtual device handles for ConIn,
ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
Installs Graphics Output protocol.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
ConSplitterDriverEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Install driver model protocol(s).
//
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gConSplitterConInDriverBinding,
ImageHandle,
&gConSplitterConInComponentName,
&gConSplitterConInComponentName2
);
ASSERT_EFI_ERROR (Status);
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gConSplitterSimplePointerDriverBinding,
NULL,
&gConSplitterSimplePointerComponentName,
&gConSplitterSimplePointerComponentName2
);
ASSERT_EFI_ERROR (Status);
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gConSplitterAbsolutePointerDriverBinding,
NULL,
&gConSplitterAbsolutePointerComponentName,
&gConSplitterAbsolutePointerComponentName2
);
ASSERT_EFI_ERROR (Status);
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gConSplitterConOutDriverBinding,
NULL,
&gConSplitterConOutComponentName,
&gConSplitterConOutComponentName2
);
ASSERT_EFI_ERROR (Status);
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gConSplitterStdErrDriverBinding,
NULL,
&gConSplitterStdErrComponentName,
&gConSplitterStdErrComponentName2
);
ASSERT_EFI_ERROR (Status);
//
// Graphics Output protocol must be supported.
//
ASSERT (FeaturePcdGet (PcdConOutGopSupport));
//
// The driver creates virtual handles for ConIn, ConOut, StdErr.
// The virtual handles will always exist even if no console exist in the
// system. This is need to support hotplug devices like USB.
//
//
// Create virtual device handle for ConIn Splitter
//
Status = ConSplitterTextInConstructor (&mConIn);
if (!EFI_ERROR (Status)) {
Status = gBS->InstallMultipleProtocolInterfaces (
&mConIn.VirtualHandle,
&gEfiSimpleTextInProtocolGuid,
&mConIn.TextIn,
&gEfiSimpleTextInputExProtocolGuid,
&mConIn.TextInEx,
&gEfiSimplePointerProtocolGuid,
&mConIn.SimplePointer,
&gEfiAbsolutePointerProtocolGuid,
&mConIn.AbsolutePointer,
NULL
);
if (!EFI_ERROR (Status)) {
//
// Update the EFI System Table with new virtual console
// and update the pointer to Simple Text Input protocol.
//
gST->ConsoleInHandle = mConIn.VirtualHandle;
gST->ConIn = &mConIn.TextIn;
}
}
//
// Create virtual device handle for ConOut Splitter
//
Status = ConSplitterTextOutConstructor (&mConOut);
if (!EFI_ERROR (Status)) {
Status = gBS->InstallMultipleProtocolInterfaces (
&mConOut.VirtualHandle,
&gEfiSimpleTextOutProtocolGuid,
&mConOut.TextOut,
NULL
);
if (!EFI_ERROR (Status)) {
//
// Update the EFI System Table with new virtual console
// and Update the pointer to Text Output protocol.
//
gST->ConsoleOutHandle = mConOut.VirtualHandle;
gST->ConOut = &mConOut.TextOut;
}
}
//
// Create virtual device handle for StdErr Splitter
//
Status = ConSplitterTextOutConstructor (&mStdErr);
if (!EFI_ERROR (Status)) {
Status = gBS->InstallMultipleProtocolInterfaces (
&mStdErr.VirtualHandle,
&gEfiSimpleTextOutProtocolGuid,
&mStdErr.TextOut,
NULL
);
if (!EFI_ERROR (Status)) {
//
// Update the EFI System Table with new virtual console
// and update the pointer to Text Output protocol.
//
gST->StandardErrorHandle = mStdErr.VirtualHandle;
gST->StdErr = &mStdErr.TextOut;
}
}
//
// Update the CRC32 in the EFI System Table header
//
gST->Hdr.CRC32 = 0;
gBS->CalculateCrc32 (
(UINT8 *)&gST->Hdr,
gST->Hdr.HeaderSize,
&gST->Hdr.CRC32
);
return EFI_SUCCESS;
}
/**
Construct console input devices' private data.
@param ConInPrivate A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA
structure.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS Text Input Device's private data has been constructed.
@retval other Failed to construct private data.
**/
EFI_STATUS
ConSplitterTextInConstructor (
TEXT_IN_SPLITTER_PRIVATE_DATA *ConInPrivate
)
{
EFI_STATUS Status;
UINTN TextInExListCount;
//
// Allocate buffer for Simple Text Input device
//
Status = ConSplitterGrowBuffer (
sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
&ConInPrivate->TextInListCount,
(VOID **)&ConInPrivate->TextInList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create Event to wait for a key
//
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
ConSplitterTextInWaitForKey,
ConInPrivate,
&ConInPrivate->TextIn.WaitForKey
);
ASSERT_EFI_ERROR (Status);
//
// Allocate buffer for KeyQueue
//
TextInExListCount = ConInPrivate->TextInExListCount;
Status = ConSplitterGrowBuffer (
sizeof (EFI_KEY_DATA),
&TextInExListCount,
(VOID **)&ConInPrivate->KeyQueue
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Allocate buffer for Simple Text Input Ex device
//
Status = ConSplitterGrowBuffer (
sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
&ConInPrivate->TextInExListCount,
(VOID **)&ConInPrivate->TextInExList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create Event to wait for a key Ex
//
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
ConSplitterTextInWaitForKey,
ConInPrivate,
&ConInPrivate->TextInEx.WaitForKeyEx
);
ASSERT_EFI_ERROR (Status);
InitializeListHead (&ConInPrivate->NotifyList);
ToggleStateSyncInitialization (ConInPrivate);
ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;
//
// Allocate buffer for Absolute Pointer device
//
Status = ConSplitterGrowBuffer (
sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
&ConInPrivate->AbsolutePointerListCount,
(VOID **)&ConInPrivate->AbsolutePointerList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create Event to wait for device input for Absolute pointer device
//
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
ConSplitterAbsolutePointerWaitForInput,
ConInPrivate,
&ConInPrivate->AbsolutePointer.WaitForInput
);
ASSERT_EFI_ERROR (Status);
ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;
//
// Allocate buffer for Simple Pointer device
//
Status = ConSplitterGrowBuffer (
sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
&ConInPrivate->PointerListCount,
(VOID **)&ConInPrivate->PointerList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Create Event to wait for device input for Simple pointer device
//
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
ConSplitterSimplePointerWaitForInput,
ConInPrivate,
&ConInPrivate->SimplePointer.WaitForInput
);
ASSERT_EFI_ERROR (Status);
//
// Create Event to signal ConIn connection request
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
EfiEventEmptyFunction,
NULL,
&gConnectConInEventGuid,
&ConInPrivate->ConnectConInEvent
);
return Status;
}
/**
Construct console output devices' private data.
@param ConOutPrivate A pointer to the TEXT_OUT_SPLITTER_PRIVATE_DATA
structure.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_SUCCESS Text Input Devcie's private data has been constructed.
**/
EFI_STATUS
ConSplitterTextOutConstructor (
TEXT_OUT_SPLITTER_PRIVATE_DATA *ConOutPrivate
)
{
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
//
// Copy protocols template
//
if (FeaturePcdGet (PcdConOutGopSupport)) {
CopyMem (&ConOutPrivate->GraphicsOutput, &mGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));
}
//
// Initialize console output splitter's private data.
//
ConOutPrivate->TextOut.Mode = &ConOutPrivate->TextOutMode;
//
// When new console device is added, the new mode will be set later,
// so put current mode back to init state.
//
ConOutPrivate->TextOutMode.Mode = 0xFF;
//
// Allocate buffer for Console Out device
//
Status = ConSplitterGrowBuffer (
sizeof (TEXT_OUT_AND_GOP_DATA),
&ConOutPrivate->TextOutListCount,
(VOID **)&ConOutPrivate->TextOutList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Allocate buffer for Text Out query data
//
Status = ConSplitterGrowBuffer (
sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
&ConOutPrivate->TextOutQueryDataCount,
(VOID **)&ConOutPrivate->TextOutQueryData
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Setup the default console to 80 x 25 and mode to 0
//
ConOutPrivate->TextOutQueryData[0].Columns = 80;
ConOutPrivate->TextOutQueryData[0].Rows = 25;
TextOutSetMode (ConOutPrivate, 0);
if (FeaturePcdGet (PcdConOutGopSupport)) {
//
// Setup resource for mode information in Graphics Output Protocol interface
//
if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel
// DevNull will be updated to user-defined mode after driver has started.
//
if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Info = &ConOutPrivate->GraphicsOutputModeBuffer[0];
Info->Version = 0;
Info->HorizontalResolution = 800;
Info->VerticalResolution = 600;
Info->PixelFormat = PixelBltOnly;
Info->PixelsPerScanLine = 800;
CopyMem (ConOutPrivate->GraphicsOutput.Mode->Info, Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
//
// Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()
// GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
//
ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS)(UINTN)NULL;
ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;
ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;
//
// Initial current mode to unknown state, and then set to mode 0
//
ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;
ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);
}
return EFI_SUCCESS;
}
/**
Test to see if the specified protocol could be supported on the specified device.
@param This Driver Binding protocol pointer.
@param ControllerHandle Handle of device to test.
@param Guid The specified protocol.
@retval EFI_SUCCESS The specified protocol is supported on this device.
@retval EFI_UNSUPPORTED The specified protocol attempts to be installed on virtual handle.
@retval other Failed to open specified protocol on this device.
**/
EFI_STATUS
ConSplitterSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_GUID *Guid
)
{
EFI_STATUS Status;
VOID *Instance;
//
// Make sure the Console Splitter does not attempt to attach to itself
//
if ((ControllerHandle == mConIn.VirtualHandle) ||
(ControllerHandle == mConOut.VirtualHandle) ||
(ControllerHandle == mStdErr.VirtualHandle)
)
{
return EFI_UNSUPPORTED;
}
//
// Check to see whether the specific protocol could be opened BY_DRIVER
//
Status = gBS->OpenProtocol (
ControllerHandle,
Guid,
&Instance,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
gBS->CloseProtocol (
ControllerHandle,
Guid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}
/**
Test to see if Console In Device could be supported on the Controller.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to test.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterConInDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
return ConSplitterSupported (
This,
ControllerHandle,
&gEfiConsoleInDeviceGuid
);
}
/**
Test to see if Simple Pointer protocol could be supported on the Controller.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to test.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterSimplePointerDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
return ConSplitterSupported (
This,
ControllerHandle,
&gEfiSimplePointerProtocolGuid
);
}
/**
Test to see if Absolute Pointer protocol could be supported on the Controller.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to test.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterAbsolutePointerDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
return ConSplitterSupported (
This,
ControllerHandle,
&gEfiAbsolutePointerProtocolGuid
);
}
/**
Test to see if Console Out Device could be supported on the Controller.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to test.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterConOutDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
return ConSplitterSupported (
This,
ControllerHandle,
&gEfiConsoleOutDeviceGuid
);
}
/**
Test to see if Standard Error Device could be supported on the Controller.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to test.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device.
@retval other This driver does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterStdErrDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
return ConSplitterSupported (
This,
ControllerHandle,
&gEfiStandardErrorDeviceGuid
);
}
/**
Start ConSplitter on devcie handle by opening Console Device Guid on device handle
and the console virtual handle. And Get the console interface on controller handle.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device.
@param ConSplitterVirtualHandle Console virtual Handle.
@param DeviceGuid The specified Console Device, such as ConInDev,
ConOutDev.
@param InterfaceGuid The specified protocol to be opened.
@param Interface Protocol interface returned.
@retval EFI_SUCCESS This driver supports this device.
@retval other Failed to open the specified Console Device Guid
or specified protocol.
**/
EFI_STATUS
ConSplitterStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ConSplitterVirtualHandle,
IN EFI_GUID *DeviceGuid,
IN EFI_GUID *InterfaceGuid,
OUT VOID **Interface
)
{
EFI_STATUS Status;
VOID *Instance;
//
// Check to see whether the ControllerHandle has the DeviceGuid on it.
//
Status = gBS->OpenProtocol (
ControllerHandle,
DeviceGuid,
&Instance,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the Parent Handle for the child.
//
Status = gBS->OpenProtocol (
ControllerHandle,
DeviceGuid,
&Instance,
This->DriverBindingHandle,
ConSplitterVirtualHandle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (EFI_ERROR (Status)) {
goto Err;
}
//
// Open InterfaceGuid on the virtual handle.
//
Status = gBS->OpenProtocol (
ControllerHandle,
InterfaceGuid,
Interface,
This->DriverBindingHandle,
ConSplitterVirtualHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
}
//
// close the DeviceGuid on ConSplitter VirtualHandle.
//
gBS->CloseProtocol (
ControllerHandle,
DeviceGuid,
This->DriverBindingHandle,
ConSplitterVirtualHandle
);
Err:
//
// close the DeviceGuid on ControllerHandle.
//
gBS->CloseProtocol (
ControllerHandle,
DeviceGuid,
This->DriverBindingHandle,
ControllerHandle
);
return Status;
}
/**
Start Console In Consplitter on device handle.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Console In Consplitter is added to ControllerHandle.
@retval other Console In Consplitter does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterConInDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
//
// Start ConSplitter on ControllerHandle, and create the virtual
// aggregated console device on first call Start for a SimpleTextIn handle.
//
Status = ConSplitterStart (
This,
ControllerHandle,
mConIn.VirtualHandle,
&gEfiConsoleInDeviceGuid,
&gEfiSimpleTextInProtocolGuid,
(VOID **)&TextIn
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Add this device into Text In devices list.
//
Status = ConSplitterTextInAddDevice (&mConIn, TextIn);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextInputExProtocolGuid,
(VOID **)&TextInEx,
This->DriverBindingHandle,
mConIn.VirtualHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
//
// If Simple Text Input Ex protocol exists,
// add this device into Text In Ex devices list.
//
Status = ConSplitterTextInExAddDevice (&mConIn, TextInEx);
}
return Status;
}
/**
Start Simple Pointer Consplitter on device handle.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Simple Pointer Consplitter is added to ControllerHandle.
@retval other Simple Pointer Consplitter does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterSimplePointerDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
//
// Start ConSplitter on ControllerHandle, and create the virtual
// aggregated console device on first call Start for a SimplePointer handle.
//
Status = ConSplitterStart (
This,
ControllerHandle,
mConIn.VirtualHandle,
&gEfiSimplePointerProtocolGuid,
&gEfiSimplePointerProtocolGuid,
(VOID **)&SimplePointer
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Add this devcie into Simple Pointer devices list.
//
return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);
}
/**
Start Absolute Pointer Consplitter on device handle.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Absolute Pointer Consplitter is added to ControllerHandle.
@retval other Absolute Pointer Consplitter does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterAbsolutePointerDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
//
// Start ConSplitter on ControllerHandle, and create the virtual
// aggregated console device on first call Start for a AbsolutePointer handle.
//
Status = ConSplitterStart (
This,
ControllerHandle,
mConIn.VirtualHandle,
&gEfiAbsolutePointerProtocolGuid,
&gEfiAbsolutePointerProtocolGuid,
(VOID **)&AbsolutePointer
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Add this devcie into Absolute Pointer devices list.
//
return ConSplitterAbsolutePointerAddDevice (&mConIn, AbsolutePointer);
}
/**
Start Console Out Consplitter on device handle.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Console Out Consplitter is added to ControllerHandle.
@retval other Console Out Consplitter does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterConOutDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
UINTN SizeOfInfo;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
//
// Start ConSplitter on ControllerHandle, and create the virtual
// aggregated console device on first call Start for a ConsoleOut handle.
//
Status = ConSplitterStart (
This,
ControllerHandle,
mConOut.VirtualHandle,
&gEfiConsoleOutDeviceGuid,
&gEfiSimpleTextOutProtocolGuid,
(VOID **)&TextOut
);
if (EFI_ERROR (Status)) {
return Status;
}
GraphicsOutput = NULL;
//
// Try to Open Graphics Output protocol
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiGraphicsOutputProtocolGuid,
(VOID **)&GraphicsOutput,
This->DriverBindingHandle,
mConOut.VirtualHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
//
// When new console device is added, the new mode will be set later,
// so put current mode back to init state.
//
mConOut.TextOutMode.Mode = 0xFF;
//
// If both ConOut and StdErr incorporate the same Text Out device,
// their MaxMode and QueryData should be the intersection of both.
//
Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput);
ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
if (GraphicsOutput != NULL) {
Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
FreePool (Info);
}
return Status;
}
/**
Start Standard Error Consplitter on device handle.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS Standard Error Consplitter is added to ControllerHandle.
@retval other Standard Error Consplitter does not support this device.
**/
EFI_STATUS
EFIAPI
ConSplitterStdErrDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
//
// Start ConSplitter on ControllerHandle, and create the virtual
// aggregated console device on first call Start for a StandardError handle.
//
Status = ConSplitterStart (
This,
ControllerHandle,
mStdErr.VirtualHandle,
&gEfiStandardErrorDeviceGuid,
&gEfiSimpleTextOutProtocolGuid,
(VOID **)&TextOut
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// When new console device is added, the new mode will be set later,
// so put current mode back to init state.
//
mStdErr.TextOutMode.Mode = 0xFF;
//
// If both ConOut and StdErr incorporate the same Text Out device,
// their MaxMode and QueryData should be the intersection of both.
//
Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL);
ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
return Status;
}
/**
Stop ConSplitter on device handle by closing Console Device Guid on device handle
and the console virtual handle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device.
@param ConSplitterVirtualHandle Console virtual Handle.
@param DeviceGuid The specified Console Device, such as ConInDev,
ConOutDev.
@param InterfaceGuid The specified protocol to be opened.
@param Interface Protocol interface returned.
@retval EFI_SUCCESS Stop ConSplitter on ControllerHandle successfully.
@retval other Failed to Stop ConSplitter on ControllerHandle.
**/
EFI_STATUS
ConSplitterStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ConSplitterVirtualHandle,
IN EFI_GUID *DeviceGuid,
IN EFI_GUID *InterfaceGuid,
IN VOID **Interface
)
{
EFI_STATUS Status;
Status = gBS->OpenProtocol (
ControllerHandle,
InterfaceGuid,
Interface,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// close the protocol referred.
//
gBS->CloseProtocol (
ControllerHandle,
DeviceGuid,
This->DriverBindingHandle,
ConSplitterVirtualHandle
);
gBS->CloseProtocol (
ControllerHandle,
DeviceGuid,
This->DriverBindingHandle,
ControllerHandle
);
return EFI_SUCCESS;
}
/**
Stop Console In ConSplitter on ControllerHandle by closing Console In Device GUID.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
ConSplitterConInDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
if (NumberOfChildren == 0) {
return EFI_SUCCESS;
}
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleTextInputExProtocolGuid,
(VOID **)&TextInEx,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
//
// If Simple Text Input Ex protocol exists,
// remove device from Text Input Ex devices list.
//
Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Close Simple Text In protocol on controller handle and virtual handle.
//
Status = ConSplitterStop (
This,
ControllerHandle,
mConIn.VirtualHandle,
&gEfiConsoleInDeviceGuid,
&gEfiSimpleTextInProtocolGuid,
(VOID **)&TextIn
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Remove device from Text Input devices list.
//
return ConSplitterTextInDeleteDevice (&mConIn, TextIn);
}
/**
Stop Simple Pointer protocol ConSplitter on ControllerHandle by closing
Simple Pointer protocol.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
ConSplitterSimplePointerDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
if (NumberOfChildren == 0) {
return EFI_SUCCESS;
}
//
// Close Simple Pointer protocol on controller handle and virtual handle.
//
Status = ConSplitterStop (
This,
ControllerHandle,
mConIn.VirtualHandle,
&gEfiSimplePointerProtocolGuid,
&gEfiSimplePointerProtocolGuid,
(VOID **)&SimplePointer
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Remove this device from Simple Pointer device list.
//
return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);
}
/**
Stop Absolute Pointer protocol ConSplitter on ControllerHandle by closing
Absolute Pointer protocol.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
ConSplitterAbsolutePointerDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
if (NumberOfChildren == 0) {
return EFI_SUCCESS;
}
//
// Close Absolute Pointer protocol on controller handle and virtual handle.
//
Status = ConSplitterStop (
This,
ControllerHandle,
mConIn.VirtualHandle,
&gEfiAbsolutePointerProtocolGuid,
&gEfiAbsolutePointerProtocolGuid,
(VOID **)&AbsolutePointer
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Remove this device from Absolute Pointer device list.
//
return ConSplitterAbsolutePointerDeleteDevice (&mConIn, AbsolutePointer);
}
/**
Stop Console Out ConSplitter on device handle by closing Console Out Devcie GUID.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
ConSplitterConOutDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
if (NumberOfChildren == 0) {
return EFI_SUCCESS;
}
//
// Close Absolute Pointer protocol on controller handle and virtual handle.
//
Status = ConSplitterStop (
This,
ControllerHandle,
mConOut.VirtualHandle,
&gEfiConsoleOutDeviceGuid,
&gEfiSimpleTextOutProtocolGuid,
(VOID **)&TextOut
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Remove this device from Text Out device list.
//
return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);
}
/**
Stop Standard Error ConSplitter on ControllerHandle by closing Standard Error GUID.
@param This Driver Binding protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
EFI_STATUS
EFIAPI
ConSplitterStdErrDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
if (NumberOfChildren == 0) {
return EFI_SUCCESS;
}
//
// Close Standard Error Device on controller handle and virtual handle.
//
Status = ConSplitterStop (
This,
ControllerHandle,
mStdErr.VirtualHandle,
&gEfiStandardErrorDeviceGuid,
&gEfiSimpleTextOutProtocolGuid,
(VOID **)&TextOut
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Delete this console error out device's data structures.
//
return ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);
}
/**
Take the passed in Buffer of size ElementSize and grow the buffer
by CONSOLE_SPLITTER_ALLOC_UNIT * ElementSize bytes.
Copy the current data in Buffer to the new version of Buffer and
free the old version of buffer.
@param ElementSize Size of element in array.
@param Count Current number of elements in array.
@param Buffer Bigger version of passed in Buffer with all the
data.
@retval EFI_SUCCESS Buffer size has grown.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterGrowBuffer (
IN UINTN ElementSize,
IN OUT UINTN *Count,
IN OUT VOID **Buffer
)
{
VOID *Ptr;
//
// grow the buffer to new buffer size,
// copy the old buffer's content to the new-size buffer,
// then free the old buffer.
//
Ptr = ReallocatePool (
ElementSize * (*Count),
ElementSize * ((*Count) + CONSOLE_SPLITTER_ALLOC_UNIT),
*Buffer
);
if (Ptr == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*Count += CONSOLE_SPLITTER_ALLOC_UNIT;
*Buffer = Ptr;
return EFI_SUCCESS;
}
/**
Add Text Input Device in Consplitter Text Input list.
@param Private Text In Splitter pointer.
@param TextIn Simple Text Input protocol pointer.
@retval EFI_SUCCESS Text Input Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterTextInAddDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
)
{
EFI_STATUS Status;
//
// If the Text In List is full, enlarge it by calling ConSplitterGrowBuffer().
//
if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {
Status = ConSplitterGrowBuffer (
sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
&Private->TextInListCount,
(VOID **)&Private->TextInList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Add the new text-in device data structure into the Text In List.
//
Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;
Private->CurrentNumberOfConsoles++;
//
// Extra CheckEvent added to reduce the double CheckEvent().
//
gBS->CheckEvent (TextIn->WaitForKey);
return EFI_SUCCESS;
}
/**
Remove Text Input Device from Consplitter Text Input list.
@param Private Text In Splitter pointer.
@param TextIn Simple Text protocol pointer.
@retval EFI_SUCCESS Simple Text Device removed successfully.
@retval EFI_NOT_FOUND No Simple Text Device found.
**/
EFI_STATUS
ConSplitterTextInDeleteDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
)
{
UINTN Index;
//
// Remove the specified text-in device data structure from the Text In List,
// and rearrange the remaining data structures in the Text In List.
//
for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
if (Private->TextInList[Index] == TextIn) {
for ( ; Index < Private->CurrentNumberOfConsoles - 1; Index++) {
Private->TextInList[Index] = Private->TextInList[Index + 1];
}
Private->CurrentNumberOfConsoles--;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Add Text Input Ex Device in Consplitter Text Input Ex list.
@param Private Text In Splitter pointer.
@param TextInEx Simple Text Input Ex Input protocol pointer.
@retval EFI_SUCCESS Text Input Ex Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterTextInExAddDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
UINTN TextInExListCount;
//
// Enlarge the NotifyHandleList and the TextInExList
//
if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
TextInExListCount = Private->TextInExListCount;
Status = ConSplitterGrowBuffer (
sizeof (EFI_HANDLE),
&TextInExListCount,
(VOID **)&CurrentNotify->NotifyHandleList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
TextInExListCount = Private->TextInExListCount;
Status = ConSplitterGrowBuffer (
sizeof (EFI_KEY_DATA),
&TextInExListCount,
(VOID **)&Private->KeyQueue
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
Status = ConSplitterGrowBuffer (
sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
&Private->TextInExListCount,
(VOID **)&Private->TextInExList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Register the key notify in the new text-in device
//
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
Status = TextInEx->RegisterKeyNotify (
TextInEx,
&CurrentNotify->KeyData,
CurrentNotify->KeyNotificationFn,
&CurrentNotify->NotifyHandleList[Private->CurrentNumberOfExConsoles]
);
if (EFI_ERROR (Status)) {
for (Link = Link->BackLink; Link != &Private->NotifyList; Link = Link->BackLink) {
CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
TextInEx->UnregisterKeyNotify (
TextInEx,
CurrentNotify->NotifyHandleList[Private->CurrentNumberOfExConsoles]
);
}
return Status;
}
}
//
// Add the new text-in device data structure into the Text Input Ex List.
//
Private->TextInExList[Private->CurrentNumberOfExConsoles] = TextInEx;
Private->CurrentNumberOfExConsoles++;
//
// Sync current toggle state to this new console input device.
//
TextInEx->SetState (TextInEx, &Private->PhysicalKeyToggleState);
//
// Extra CheckEvent added to reduce the double CheckEvent().
//
gBS->CheckEvent (TextInEx->WaitForKeyEx);
return EFI_SUCCESS;
}
/**
Remove Text Ex Device from Consplitter Text Input Ex list.
@param Private Text In Splitter pointer.
@param TextInEx Simple Text Ex protocol pointer.
@retval EFI_SUCCESS Simple Text Input Ex Device removed successfully.
@retval EFI_NOT_FOUND No Simple Text Input Ex Device found.
**/
EFI_STATUS
ConSplitterTextInExDeleteDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
)
{
UINTN Index;
//
// Remove the specified text-in device data structure from the Text Input Ex List,
// and rearrange the remaining data structures in the Text In List.
//
for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
if (Private->TextInExList[Index] == TextInEx) {
for ( ; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {
Private->TextInExList[Index] = Private->TextInExList[Index + 1];
}
Private->CurrentNumberOfExConsoles--;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Add Simple Pointer Device in Consplitter Simple Pointer list.
@param Private Text In Splitter pointer.
@param SimplePointer Simple Pointer protocol pointer.
@retval EFI_SUCCESS Simple Pointer Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterSimplePointerAddDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
)
{
EFI_STATUS Status;
//
// If the Simple Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
//
if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {
Status = ConSplitterGrowBuffer (
sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
&Private->PointerListCount,
(VOID **)&Private->PointerList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Add the new text-in device data structure into the Simple Pointer List.
//
Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;
Private->CurrentNumberOfPointers++;
return EFI_SUCCESS;
}
/**
Remove Simple Pointer Device from Consplitter Simple Pointer list.
@param Private Text In Splitter pointer.
@param SimplePointer Simple Pointer protocol pointer.
@retval EFI_SUCCESS Simple Pointer Device removed successfully.
@retval EFI_NOT_FOUND No Simple Pointer Device found.
**/
EFI_STATUS
ConSplitterSimplePointerDeleteDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
)
{
UINTN Index;
//
// Remove the specified text-in device data structure from the Simple Pointer List,
// and rearrange the remaining data structures in the Text In List.
//
for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
if (Private->PointerList[Index] == SimplePointer) {
for ( ; Index < Private->CurrentNumberOfPointers - 1; Index++) {
Private->PointerList[Index] = Private->PointerList[Index + 1];
}
Private->CurrentNumberOfPointers--;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Add Absolute Pointer Device in Consplitter Absolute Pointer list.
@param Private Text In Splitter pointer.
@param AbsolutePointer Absolute Pointer protocol pointer.
@retval EFI_SUCCESS Absolute Pointer Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterAbsolutePointerAddDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
)
{
EFI_STATUS Status;
//
// If the Absolute Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
//
if (Private->CurrentNumberOfAbsolutePointers >= Private->AbsolutePointerListCount) {
Status = ConSplitterGrowBuffer (
sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
&Private->AbsolutePointerListCount,
(VOID **)&Private->AbsolutePointerList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Add the new text-in device data structure into the Absolute Pointer List.
//
Private->AbsolutePointerList[Private->CurrentNumberOfAbsolutePointers] = AbsolutePointer;
Private->CurrentNumberOfAbsolutePointers++;
return EFI_SUCCESS;
}
/**
Remove Absolute Pointer Device from Consplitter Absolute Pointer list.
@param Private Text In Splitter pointer.
@param AbsolutePointer Absolute Pointer protocol pointer.
@retval EFI_SUCCESS Absolute Pointer Device removed successfully.
@retval EFI_NOT_FOUND No Absolute Pointer Device found.
**/
EFI_STATUS
ConSplitterAbsolutePointerDeleteDevice (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
)
{
UINTN Index;
//
// Remove the specified text-in device data structure from the Absolute Pointer List,
// and rearrange the remaining data structures from the Absolute Pointer List.
//
for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
if (Private->AbsolutePointerList[Index] == AbsolutePointer) {
for ( ; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {
Private->AbsolutePointerList[Index] = Private->AbsolutePointerList[Index + 1];
}
Private->CurrentNumberOfAbsolutePointers--;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Reallocate Text Out mode map.
Allocate new buffer and copy original buffer into the new buffer.
@param Private Consplitter Text Out pointer.
@retval EFI_SUCCESS Buffer size has grown
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterGrowMapTable (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
)
{
UINTN Size;
UINTN NewSize;
UINTN TotalSize;
INT32 *TextOutModeMap;
INT32 *OldTextOutModeMap;
INT32 *SrcAddress;
INT32 Index;
UINTN OldStepSize;
UINTN NewStepSize;
NewSize = Private->TextOutListCount * sizeof (INT32);
OldTextOutModeMap = Private->TextOutModeMap;
TotalSize = NewSize * (Private->TextOutQueryDataCount);
//
// Allocate new buffer for Text Out List.
//
TextOutModeMap = AllocatePool (TotalSize);
if (TextOutModeMap == NULL) {
return EFI_OUT_OF_RESOURCES;
}
SetMem (TextOutModeMap, TotalSize, 0xFF);
Private->TextOutModeMap = TextOutModeMap;
//
// If TextOutList has been enlarged, need to realloc the mode map table
// The mode map table is regarded as a two dimension array.
//
// Old New
// 0 ---------> TextOutListCount ----> TextOutListCount
// | -------------------------------------------
// | | | |
// | | | |
// | | | |
// | | | |
// | | | |
// \/ | | |
// -------------------------------------------
// QueryDataCount
//
if (OldTextOutModeMap != NULL) {
Size = Private->CurrentNumberOfConsoles * sizeof (INT32);
Index = 0;
SrcAddress = OldTextOutModeMap;
NewStepSize = NewSize / sizeof (INT32);
// If Private->CurrentNumberOfConsoles is not zero and OldTextOutModeMap
// is not NULL, it indicates that the original TextOutModeMap is not enough
// for the new console devices and has been enlarged by CONSOLE_SPLITTER_ALLOC_UNIT columns.
//
OldStepSize = NewStepSize - CONSOLE_SPLITTER_ALLOC_UNIT;
//
// Copy the old data to the new one
//
while (Index < Private->TextOutMode.MaxMode) {
CopyMem (TextOutModeMap, SrcAddress, Size);
//
// Go to next row of new TextOutModeMap.
//
TextOutModeMap += NewStepSize;
//
// Go to next row of old TextOutModeMap.
//
SrcAddress += OldStepSize;
Index++;
}
//
// Free the old buffer
//
FreePool (OldTextOutModeMap);
}
return EFI_SUCCESS;
}
/**
Add new device's output mode to console splitter's mode list.
@param Private Text Out Splitter pointer
@param TextOut Simple Text Output protocol pointer.
@retval EFI_SUCCESS Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterAddOutputMode (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
)
{
EFI_STATUS Status;
INT32 MaxMode;
INT32 Mode;
UINTN Index;
MaxMode = TextOut->Mode->MaxMode;
Private->TextOutMode.MaxMode = MaxMode;
//
// Grow the buffer if query data buffer is not large enough to
// hold all the mode supported by the first console.
//
while (MaxMode > (INT32)Private->TextOutQueryDataCount) {
Status = ConSplitterGrowBuffer (
sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
&Private->TextOutQueryDataCount,
(VOID **)&Private->TextOutQueryData
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
//
// Allocate buffer for the output mode map
//
Status = ConSplitterGrowMapTable (Private);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// As the first textout device, directly add the mode in to QueryData
// and at the same time record the mapping between QueryData and TextOut.
//
Mode = 0;
Index = 0;
while (Mode < MaxMode) {
Status = TextOut->QueryMode (
TextOut,
Mode,
&Private->TextOutQueryData[Mode].Columns,
&Private->TextOutQueryData[Mode].Rows
);
//
// If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
// is clear to 0x0.
//
if ((EFI_ERROR (Status)) && (Mode == 1)) {
Private->TextOutQueryData[Mode].Columns = 0;
Private->TextOutQueryData[Mode].Rows = 0;
}
Private->TextOutModeMap[Index] = Mode;
Mode++;
Index += Private->TextOutListCount;
}
return EFI_SUCCESS;
}
/**
Reconstruct TextOutModeMap to get intersection of modes.
This routine reconstruct TextOutModeMap to get the intersection
of modes for all console out devices. Because EFI/UEFI spec require
mode 0 is 80x25, mode 1 is 80x50, this routine will not check the
intersection for mode 0 and mode 1.
@param TextOutModeMap Current text out mode map, begin with the mode 80x25
@param NewlyAddedMap New text out mode map, begin with the mode 80x25
@param MapStepSize Mode step size for one console device
@param NewMapStepSize New Mode step size for one console device
@param MaxMode IN: Current max text mode, OUT: Updated max text mode.
@param CurrentMode IN: Current text mode, OUT: Updated current text mode.
**/
VOID
ConSplitterGetIntersection (
IN INT32 *TextOutModeMap,
IN INT32 *NewlyAddedMap,
IN UINTN MapStepSize,
IN UINTN NewMapStepSize,
IN OUT INT32 *MaxMode,
IN OUT INT32 *CurrentMode
)
{
INT32 Index;
INT32 *CurrentMapEntry;
INT32 *NextMapEntry;
INT32 *NewMapEntry;
INT32 CurrentMaxMode;
INT32 Mode;
//
// According to EFI/UEFI spec, mode 0 and mode 1 have been reserved
// for 80x25 and 80x50 in Simple Text Out protocol, so don't make intersection
// for mode 0 and mode 1, mode number starts from 2.
//
Index = 2;
CurrentMapEntry = &TextOutModeMap[MapStepSize * 2];
NextMapEntry = CurrentMapEntry;
NewMapEntry = &NewlyAddedMap[NewMapStepSize * 2];
CurrentMaxMode = *MaxMode;
Mode = *CurrentMode;
while (Index < CurrentMaxMode) {
if (*NewMapEntry == -1) {
//
// This mode is not supported any more. Remove it. Special care
// must be taken as this remove will also affect current mode;
//
if (Index == *CurrentMode) {
Mode = -1;
} else if (Index < *CurrentMode) {
Mode--;
}
(*MaxMode)--;
} else {
if (CurrentMapEntry != NextMapEntry) {
CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));
}
NextMapEntry += MapStepSize;
}
CurrentMapEntry += MapStepSize;
NewMapEntry += NewMapStepSize;
Index++;
}
*CurrentMode = Mode;
return;
}
/**
Sync the device's output mode to console splitter's mode list.
@param Private Text Out Splitter pointer.
@param TextOut Simple Text Output protocol pointer.
**/
VOID
ConSplitterSyncOutputMode (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
)
{
INT32 CurrentMaxMode;
INT32 Mode;
INT32 Index;
INT32 *TextOutModeMap;
INT32 *MapTable;
INT32 QueryMode;
TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
UINTN Rows;
UINTN Columns;
UINTN StepSize;
EFI_STATUS Status;
//
// Must make sure that current mode won't change even if mode number changes
//
CurrentMaxMode = Private->TextOutMode.MaxMode;
TextOutModeMap = Private->TextOutModeMap;
StepSize = Private->TextOutListCount;
TextOutQueryData = Private->TextOutQueryData;
//
// Query all the mode that the newly added TextOut supports
//
Mode = 0;
MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
while (Mode < TextOut->Mode->MaxMode) {
Status = TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
if (EFI_ERROR (Status)) {
if (Mode == 1) {
//
// If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
// is clear to 0x0.
//
MapTable[StepSize] = Mode;
TextOutQueryData[Mode].Columns = 0;
TextOutQueryData[Mode].Rows = 0;
}
Mode++;
continue;
}
//
// Search the intersection map and QueryData database to see if they intersects
//
Index = 0;
while (Index < CurrentMaxMode) {
QueryMode = *(TextOutModeMap + Index * StepSize);
if ((TextOutQueryData[QueryMode].Rows == Rows) && (TextOutQueryData[QueryMode].Columns == Columns)) {
MapTable[Index * StepSize] = Mode;
break;
}
Index++;
}
Mode++;
}
//
// Now search the TextOutModeMap table to find the intersection of supported
// mode between ConSplitter and the newly added device.
//
ConSplitterGetIntersection (
TextOutModeMap,
MapTable,
StepSize,
StepSize,
&Private->TextOutMode.MaxMode,
&Private->TextOutMode.Mode
);
return;
}
/**
Sync output device between ConOut and StdErr output.
@retval EFI_SUCCESS Sync implemented successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterGetIntersectionBetweenConOutAndStrErr (
VOID
)
{
UINTN ConOutNumOfConsoles;
UINTN StdErrNumOfConsoles;
TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
UINTN Indexi;
UINTN Indexj;
UINTN ConOutRows;
UINTN ConOutColumns;
UINTN StdErrRows;
UINTN StdErrColumns;
INT32 ConOutMaxMode;
INT32 StdErrMaxMode;
INT32 ConOutMode;
INT32 StdErrMode;
INT32 Mode;
INT32 Index;
INT32 *ConOutModeMap;
INT32 *StdErrModeMap;
INT32 *ConOutMapTable;
INT32 *StdErrMapTable;
TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
UINTN ConOutStepSize;
UINTN StdErrStepSize;
BOOLEAN FoundTheSameTextOut;
UINTN ConOutMapTableSize;
UINTN StdErrMapTableSize;
ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
ConOutTextOutList = mConOut.TextOutList;
StdErrTextOutList = mStdErr.TextOutList;
Indexi = 0;
FoundTheSameTextOut = FALSE;
while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
Indexj = 0;
while (Indexj < StdErrNumOfConsoles) {
if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
FoundTheSameTextOut = TRUE;
break;
}
Indexj++;
StdErrTextOutList++;
}
Indexi++;
ConOutTextOutList++;
}
if (!FoundTheSameTextOut) {
return EFI_SUCCESS;
}
//
// Must make sure that current mode won't change even if mode number changes
//
ConOutMaxMode = mConOut.TextOutMode.MaxMode;
ConOutModeMap = mConOut.TextOutModeMap;
ConOutStepSize = mConOut.TextOutListCount;
ConOutQueryData = mConOut.TextOutQueryData;
StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
StdErrModeMap = mStdErr.TextOutModeMap;
StdErrStepSize = mStdErr.TextOutListCount;
StdErrQueryData = mStdErr.TextOutQueryData;
//
// Allocate the map table and set the map table's index to -1.
//
ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
if (ConOutMapTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
if (StdErrMapTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
//
// Find the intersection of the two set of modes. If they actually intersect, the
// corresponding entry in the map table is set to 1.
//
Mode = 0;
while (Mode < ConOutMaxMode) {
//
// Search the intersection map and QueryData database to see if they intersect
//
Index = 0;
ConOutMode = *(ConOutModeMap + Mode * ConOutStepSize);
ConOutRows = ConOutQueryData[ConOutMode].Rows;
ConOutColumns = ConOutQueryData[ConOutMode].Columns;
while (Index < StdErrMaxMode) {
StdErrMode = *(StdErrModeMap + Index * StdErrStepSize);
StdErrRows = StdErrQueryData[StdErrMode].Rows;
StdErrColumns = StdErrQueryData[StdErrMode].Columns;
if ((StdErrRows == ConOutRows) && (StdErrColumns == ConOutColumns)) {
ConOutMapTable[Mode] = 1;
StdErrMapTable[Index] = 1;
break;
}
Index++;
}
Mode++;
}
//
// Now search the TextOutModeMap table to find the intersection of supported
// mode between ConSplitter and the newly added device.
//
ConSplitterGetIntersection (
ConOutModeMap,
ConOutMapTable,
mConOut.TextOutListCount,
1,
&(mConOut.TextOutMode.MaxMode),
&(mConOut.TextOutMode.Mode)
);
if (mConOut.TextOutMode.Mode < 0) {
mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
}
ConSplitterGetIntersection (
StdErrModeMap,
StdErrMapTable,
mStdErr.TextOutListCount,
1,
&(mStdErr.TextOutMode.MaxMode),
&(mStdErr.TextOutMode.Mode)
);
if (mStdErr.TextOutMode.Mode < 0) {
mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
}
FreePool (ConOutMapTable);
FreePool (StdErrMapTable);
return EFI_SUCCESS;
}
/**
Add Graphics Output modes into Consplitter Text Out list.
@param Private Text Out Splitter pointer.
@param GraphicsOutput Graphics Output protocol pointer.
@retval EFI_SUCCESS Output mode added successfully.
@retval other Failed to add output mode.
**/
EFI_STATUS
ConSplitterAddGraphicsOutputMode (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput
)
{
EFI_STATUS Status;
UINTN Index;
UINTN CurrentIndex;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
UINTN SizeOfInfo;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeBuffer;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *MatchedMode;
UINTN NumberIndex;
BOOLEAN Match;
BOOLEAN AlreadyExist;
ASSERT (GraphicsOutput != NULL);
CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
Index = 0;
CurrentIndex = 0;
Status = EFI_SUCCESS;
if (GraphicsOutput != NULL) {
if (Private->CurrentNumberOfGraphicsOutput == 0) {
//
// This is the first Graphics Output device added
//
CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
//
// Allocate resource for the private mode buffer
//
ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * GraphicsOutput->Mode->MaxMode);
if (ModeBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
FreePool (Private->GraphicsOutputModeBuffer);
Private->GraphicsOutputModeBuffer = ModeBuffer;
//
// Store all supported display modes to the private mode buffer
//
Mode = ModeBuffer;
for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
//
// The Info buffer would be allocated by callee
//
Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32)Index, &SizeOfInfo, &Info);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
CopyMem (Mode, Info, SizeOfInfo);
Mode++;
FreePool (Info);
}
} else {
//
// Check intersection of display mode
//
ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * CurrentGraphicsOutputMode->MaxMode);
if (ModeBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
MatchedMode = ModeBuffer;
Mode = &Private->GraphicsOutputModeBuffer[0];
for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
Match = FALSE;
for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
//
// The Info buffer would be allocated by callee
//
Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32)NumberIndex, &SizeOfInfo, &Info);
if (EFI_ERROR (Status)) {
return Status;
}
if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
(Info->VerticalResolution == Mode->VerticalResolution))
{
//
// If GOP device supports one mode in current mode buffer,
// it will be added into matched mode buffer
//
Match = TRUE;
FreePool (Info);
break;
}
FreePool (Info);
}
if (Match) {
AlreadyExist = FALSE;
//
// Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.
//
for (Info = ModeBuffer; Info < MatchedMode; Info++) {
if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
(Info->VerticalResolution == Mode->VerticalResolution))
{
AlreadyExist = TRUE;
break;
}
}
if (!AlreadyExist) {
CopyMem (MatchedMode, Mode, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
//
// Physical frame buffer is no longer available, change PixelFormat to PixelBltOnly
//
MatchedMode->Version = 0;
MatchedMode->PixelFormat = PixelBltOnly;
ZeroMem (&MatchedMode->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
MatchedMode++;
}
}
Mode++;
}
//
// Drop the old mode buffer, assign it to a new one
//
FreePool (Private->GraphicsOutputModeBuffer);
Private->GraphicsOutputModeBuffer = ModeBuffer;
//
// Physical frame buffer is no longer available when there are more than one physical GOP devices
//
CurrentGraphicsOutputMode->MaxMode = (UINT32)(((UINTN)MatchedMode - (UINTN)ModeBuffer) / sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS)(UINTN)NULL;
CurrentGraphicsOutputMode->FrameBufferSize = 0;
}
//
// Graphics console driver can ensure the same mode for all GOP devices
//
for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
Mode = &Private->GraphicsOutputModeBuffer[Index];
if ((Mode->HorizontalResolution == GraphicsOutput->Mode->Info->HorizontalResolution) &&
(Mode->VerticalResolution == GraphicsOutput->Mode->Info->VerticalResolution))
{
CurrentIndex = Index;
break;
}
}
if (Index >= CurrentGraphicsOutputMode->MaxMode) {
//
// if user defined mode is not found, set to default mode 800x600
//
for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
Mode = &Private->GraphicsOutputModeBuffer[Index];
if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
CurrentIndex = Index;
break;
}
}
}
}
if (GraphicsOutput != NULL) {
Private->CurrentNumberOfGraphicsOutput++;
}
//
// Force GraphicsOutput mode to be set,
//
Mode = &Private->GraphicsOutputModeBuffer[CurrentIndex];
if ((GraphicsOutput != NULL) &&
(Mode->HorizontalResolution == CurrentGraphicsOutputMode->Info->HorizontalResolution) &&
(Mode->VerticalResolution == CurrentGraphicsOutputMode->Info->VerticalResolution))
{
CurrentGraphicsOutputMode->Mode = (UINT32)CurrentIndex;
if ((Mode->HorizontalResolution != GraphicsOutput->Mode->Info->HorizontalResolution) ||
(Mode->VerticalResolution != GraphicsOutput->Mode->Info->VerticalResolution))
{
//
// If all existing video device has been set to common mode, only set new GOP device to
// the common mode
//
for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32)NumberIndex, &SizeOfInfo, &Info);
if (EFI_ERROR (Status)) {
return Status;
}
if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {
FreePool (Info);
break;
}
FreePool (Info);
}
Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32)NumberIndex);
}
} else {
//
// Current mode number may need update now, so set it to an invalid mode number
//
CurrentGraphicsOutputMode->Mode = 0xffff;
//
// Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.
//
Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32)CurrentIndex);
if (EFI_ERROR (Status)) {
//
// If user defined mode is not valid for display device, set to the default mode 800x600.
//
(Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;
(Private->GraphicsOutputModeBuffer[0]).VerticalResolution = 600;
Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);
}
}
return Status;
}
/**
Set the current console out mode.
This routine will get the current console mode information (column, row)
from ConsoleOutMode variable and set it; if the variable does not exist,
set to user defined console mode.
@param Private Consplitter Text Out pointer.
**/
VOID
ConsplitterSetConsoleOutMode (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
)
{
UINTN Col;
UINTN Row;
UINTN Mode;
UINTN PreferMode;
UINTN BaseMode;
UINTN MaxMode;
EFI_STATUS Status;
CONSOLE_OUT_MODE ModeInfo;
CONSOLE_OUT_MODE MaxModeInfo;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
PreferMode = 0xFF;
BaseMode = 0xFF;
TextOut = &Private->TextOut;
MaxMode = (UINTN)(TextOut->Mode->MaxMode);
MaxModeInfo.Column = 0;
MaxModeInfo.Row = 0;
ModeInfo.Column = PcdGet32 (PcdConOutColumn);
ModeInfo.Row = PcdGet32 (PcdConOutRow);
//
// To find the prefer mode and basic mode from Text Out mode list
//
for (Mode = 0; Mode < MaxMode; Mode++) {
Status = TextOut->QueryMode (TextOut, Mode, &Col, &Row);
if (!EFI_ERROR (Status)) {
if ((ModeInfo.Column != 0) && (ModeInfo.Row != 0)) {
//
// Use user defined column and row
//
if ((Col == ModeInfo.Column) && (Row == ModeInfo.Row)) {
PreferMode = Mode;
}
} else {
//
// If user sets PcdConOutColumn or PcdConOutRow to 0,
// find and set the highest text mode.
//
if ((Col >= MaxModeInfo.Column) && (Row >= MaxModeInfo.Row)) {
MaxModeInfo.Column = Col;
MaxModeInfo.Row = Row;
PreferMode = Mode;
}
}
if ((Col == 80) && (Row == 25)) {
BaseMode = Mode;
}
}
}
//
// Set prefer mode to Text Out devices.
//
Status = TextOut->SetMode (TextOut, PreferMode);
if (EFI_ERROR (Status)) {
//
// if current mode setting is failed, default 80x25 mode will be set.
//
Status = TextOut->SetMode (TextOut, BaseMode);
ASSERT (!EFI_ERROR (Status));
Status = PcdSet32S (PcdConOutColumn, 80);
ASSERT (!EFI_ERROR (Status));
Status = PcdSet32S (PcdConOutRow, 25);
ASSERT (!EFI_ERROR (Status));
}
return;
}
/**
Add Text Output Device in Consplitter Text Output list.
@param Private Text Out Splitter pointer.
@param TextOut Simple Text Output protocol pointer.
@param GraphicsOutput Graphics Output protocol pointer.
@retval EFI_SUCCESS Text Output Device added successfully.
@retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
**/
EFI_STATUS
ConSplitterTextOutAddDevice (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput
)
{
EFI_STATUS Status;
UINTN CurrentNumOfConsoles;
INT32 MaxMode;
TEXT_OUT_AND_GOP_DATA *TextAndGop;
UINTN SizeOfInfo;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
EFI_STATUS DeviceStatus;
Status = EFI_SUCCESS;
CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
Private->AddingConOutDevice = TRUE;
//
// If the Text Out List is full, enlarge it by calling ConSplitterGrowBuffer().
//
while (CurrentNumOfConsoles >= Private->TextOutListCount) {
Status = ConSplitterGrowBuffer (
sizeof (TEXT_OUT_AND_GOP_DATA),
&Private->TextOutListCount,
(VOID **)&Private->TextOutList
);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Also need to reallocate the TextOutModeMap table
//
Status = ConSplitterGrowMapTable (Private);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
}
TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
TextAndGop->TextOut = TextOut;
TextAndGop->GraphicsOutput = GraphicsOutput;
if (CurrentNumOfConsoles == 0) {
//
// Add the first device's output mode to console splitter's mode list
//
Status = ConSplitterAddOutputMode (Private, TextOut);
} else {
ConSplitterSyncOutputMode (Private, TextOut);
}
Private->CurrentNumberOfConsoles++;
//
// Scan both TextOutList, for the intersection TextOut device
// maybe both ConOut and StdErr incorporate the same Text Out
// device in them, thus the output of both should be synced.
//
ConSplitterGetIntersectionBetweenConOutAndStrErr ();
MaxMode = Private->TextOutMode.MaxMode;
ASSERT (MaxMode >= 1);
DeviceStatus = EFI_DEVICE_ERROR;
Status = EFI_DEVICE_ERROR;
//
// This device display mode will be added into Graphics Ouput modes.
//
if (GraphicsOutput != NULL) {
DeviceStatus = ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput);
}
if (GraphicsOutput != NULL) {
Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
FreePool (Info);
}
if (((!EFI_ERROR (DeviceStatus)) || (!EFI_ERROR (Status))) &&
((Private->CurrentNumberOfGraphicsOutput) == 1))
{
//
// Graphics Output Protocol is installed
// on virtual handle.
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mConOut.VirtualHandle,
&gEfiGraphicsOutputProtocolGuid,
&mConOut.GraphicsOutput,
NULL
);
}
//
// After adding new console device, all existing console devices should be
// synced to the current shared mode.
//
ConsplitterSetConsoleOutMode (Private);
Private->AddingConOutDevice = FALSE;
return Status;
}
/**
Remove Text Out Device in Consplitter Text Out list.
@param Private Text Out Splitter pointer.
@param TextOut Simple Text Output Pointer protocol pointer.
@retval EFI_SUCCESS Text Out Device removed successfully.
@retval EFI_NOT_FOUND No Text Out Device found.
**/
EFI_STATUS
ConSplitterTextOutDeleteDevice (
IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
)
{
INT32 Index;
UINTN CurrentNumOfConsoles;
TEXT_OUT_AND_GOP_DATA *TextOutList;
EFI_STATUS Status;
//
// Remove the specified text-out device data structure from the Text out List,
// and rearrange the remaining data structures in the Text out List.
//
CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
Index = (INT32)CurrentNumOfConsoles - 1;
TextOutList = Private->TextOutList;
while (Index >= 0) {
if (TextOutList->TextOut == TextOut) {
if (TextOutList->GraphicsOutput != NULL) {
Private->CurrentNumberOfGraphicsOutput--;
}
CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
CurrentNumOfConsoles--;
break;
}
Index--;
TextOutList++;
}
//
// The specified TextOut is not managed by the ConSplitter driver
//
if (Index < 0) {
return EFI_NOT_FOUND;
}
if ((Private->CurrentNumberOfGraphicsOutput == 0)) {
//
// If there is not any physical GOP in system,
// Consplitter GOP protocol will be uninstalled
//
Status = gBS->UninstallProtocolInterface (
Private->VirtualHandle,
&gEfiGraphicsOutputProtocolGuid,
&Private->GraphicsOutput
);
}
if (CurrentNumOfConsoles == 0) {
//
// If the number of consoles is zero, reset all parameters
//
Private->CurrentNumberOfConsoles = 0;
Private->TextOutMode.MaxMode = 1;
Private->TextOutQueryData[0].Columns = 80;
Private->TextOutQueryData[0].Rows = 25;
TextOutSetMode (Private, 0);
return EFI_SUCCESS;
}
//
// Max Mode is really an intersection of the QueryMode command to all
// devices. So we must copy the QueryMode of the first device to
// QueryData.
//
ZeroMem (
Private->TextOutQueryData,
Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
);
FreePool (Private->TextOutModeMap);
Private->TextOutModeMap = NULL;
TextOutList = Private->TextOutList;
//
// Add the first TextOut to the QueryData array and ModeMap table
//
Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
//
// Now add one by one
//
Index = 1;
Private->CurrentNumberOfConsoles = 1;
TextOutList++;
while ((UINTN)Index < CurrentNumOfConsoles) {
ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
Index++;
Private->CurrentNumberOfConsoles++;
TextOutList++;
}
ConSplitterGetIntersectionBetweenConOutAndStrErr ();
return Status;
}
/**
Reset the input device and optionally run diagnostics
@param This Protocol instance pointer.
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInReset (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
Private->KeyEventSignalState = FALSE;
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextInList[Index]->Reset (
Private->TextInList[Index],
ExtendedVerification
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
if (!EFI_ERROR (ReturnStatus)) {
ToggleStateSyncReInitialization (Private);
//
// Empty the key queue.
//
Private->CurrentNumberOfKeys = 0;
}
return ReturnStatus;
}
/**
Dequeue the saved key from internal key queue.
@param Private Protocol instance pointer.
@param KeyData A pointer to a buffer that is filled in with the
keystroke state data for the key that was
pressed.
@retval EFI_NOT_FOUND Queue is empty.
@retval EFI_SUCCESS First key is dequeued and returned.
**/
EFI_STATUS
ConSplitterTextInExDequeueKey (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
OUT EFI_KEY_DATA *KeyData
)
{
if (Private->CurrentNumberOfKeys == 0) {
return EFI_NOT_FOUND;
}
//
// Return the first saved key.
//
CopyMem (KeyData, &Private->KeyQueue[0], sizeof (EFI_KEY_DATA));
Private->CurrentNumberOfKeys--;
CopyMem (
&Private->KeyQueue[0],
&Private->KeyQueue[1],
Private->CurrentNumberOfKeys * sizeof (EFI_KEY_DATA)
);
ZeroMem (&Private->KeyQueue[Private->CurrentNumberOfKeys], sizeof (EFI_KEY_DATA));
return EFI_SUCCESS;
}
/**
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existence of a keystroke via WaitForEvent () call.
@param Private Protocol instance pointer.
@param Key Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keydtroke information was not returned due
to hardware errors.
@retval EFI_UNSUPPORTED The device does not support the ability to read
keystroke data.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInPrivateReadKeyStroke (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
OUT EFI_INPUT_KEY *Key
)
{
EFI_STATUS Status;
UINTN Index;
EFI_KEY_DATA KeyData;
//
// Return the first saved non-NULL key.
//
while (TRUE) {
Status = ConSplitterTextInExDequeueKey (Private, &KeyData);
if (EFI_ERROR (Status)) {
break;
}
if ((KeyData.Key.ScanCode != CHAR_NULL) || (KeyData.Key.UnicodeChar != SCAN_NULL)) {
CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
return Status;
}
}
Key->UnicodeChar = 0;
Key->ScanCode = SCAN_NULL;
//
// if no physical console input device exists, return EFI_NOT_READY;
// if any physical console input device has key input,
// return the key and EFI_SUCCESS.
//
for (Index = 0; Index < Private->CurrentNumberOfConsoles;) {
Status = Private->TextInList[Index]->ReadKeyStroke (
Private->TextInList[Index],
&KeyData.Key
);
if (!EFI_ERROR (Status)) {
//
// If it is not partial keystorke, return the key. Otherwise, continue
// to read key from THIS physical console input device.
//
if ((KeyData.Key.ScanCode != CHAR_NULL) || (KeyData.Key.UnicodeChar != SCAN_NULL)) {
CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
return Status;
}
} else {
//
// Continue to read key from NEXT physical console input device.
//
Index++;
}
}
return EFI_NOT_READY;
}
/**
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existence of a keystroke via WaitForEvent () call.
@param This Protocol instance pointer.
@param Key Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keydtroke information was not returned due
to hardware errors.
@retval EFI_UNSUPPORTED The device does not support the ability to read
keystroke data.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInReadKeyStroke (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
Private->KeyEventSignalState = FALSE;
//
// Signal ConnectConIn event on first call in Lazy ConIn mode
//
if (!mConInIsConnect && PcdGetBool (PcdConInConnectOnDemand)) {
DEBUG ((DEBUG_INFO, "Connect ConIn in first ReadKeyStoke in Lazy ConIn mode.\n"));
gBS->SignalEvent (Private->ConnectConInEvent);
mConInIsConnect = TRUE;
}
return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
}
/**
This event aggregates all the events of the ConIn devices in the spliter.
If any events of physical ConIn devices are signaled, signal the ConIn
spliter event. This will cause the calling code to call
ConSplitterTextInReadKeyStroke ().
@param Event The Event associated with callback.
@param Context Context registered when Event was created.
**/
VOID
EFIAPI
ConSplitterTextInWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *)Context;
if (Private->KeyEventSignalState) {
//
// If KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
//
gBS->SignalEvent (Event);
return;
}
//
// If any physical console input device has key input, signal the event.
//
for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
if (!EFI_ERROR (Status)) {
gBS->SignalEvent (Event);
Private->KeyEventSignalState = TRUE;
}
}
}
/**
Test if the key has been registered on input device.
@param RegsiteredData A pointer to a buffer that is filled in with the
keystroke state data for the key that was
registered.
@param InputData A pointer to a buffer that is filled in with the
keystroke state data for the key that was
pressed.
@retval TRUE Key be pressed matches a registered key.
@retval FALSE Match failed.
**/
BOOLEAN
IsKeyRegistered (
IN EFI_KEY_DATA *RegsiteredData,
IN EFI_KEY_DATA *InputData
)
{
ASSERT (RegsiteredData != NULL && InputData != NULL);
if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
(RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar))
{
return FALSE;
}
//
// Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
//
if ((RegsiteredData->KeyState.KeyShiftState != 0) &&
(RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState))
{
return FALSE;
}
if ((RegsiteredData->KeyState.KeyToggleState != 0) &&
(RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState))
{
return FALSE;
}
return TRUE;
}
/**
Reset the input device and optionally run diagnostics
@param This Protocol instance pointer.
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInResetEx (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
Private->KeyEventSignalState = FALSE;
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {
Status = Private->TextInExList[Index]->Reset (
Private->TextInExList[Index],
ExtendedVerification
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
if (!EFI_ERROR (ReturnStatus)) {
ToggleStateSyncReInitialization (Private);
//
// Empty the key queue.
//
Private->CurrentNumberOfKeys = 0;
}
return ReturnStatus;
}
/**
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existence of a keystroke via WaitForEvent () call.
@param This Protocol instance pointer.
@param KeyData A pointer to a buffer that is filled in with the
keystroke state data for the key that was
pressed.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keystroke information was not returned due
to hardware errors.
@retval EFI_INVALID_PARAMETER KeyData is NULL.
@retval EFI_UNSUPPORTED The device does not support the ability to read
keystroke data.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInReadKeyStrokeEx (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
OUT EFI_KEY_DATA *KeyData
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
EFI_STATUS Status;
UINTN Index;
EFI_KEY_STATE KeyState;
EFI_KEY_DATA CurrentKeyData;
if (KeyData == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
Private->KeyEventSignalState = FALSE;
//
// Signal ConnectConIn event on first call in Lazy ConIn mode
//
if (!mConInIsConnect && PcdGetBool (PcdConInConnectOnDemand)) {
DEBUG ((DEBUG_INFO, "Connect ConIn in first ReadKeyStoke in Lazy ConIn mode.\n"));
gBS->SignalEvent (Private->ConnectConInEvent);
mConInIsConnect = TRUE;
}
//
// Return the first saved key.
//
Status = ConSplitterTextInExDequeueKey (Private, KeyData);
if (!EFI_ERROR (Status)) {
return Status;
}
ASSERT (Private->CurrentNumberOfKeys == 0);
ZeroMem (&KeyState, sizeof (KeyState));
//
// Iterate through all physical consoles to get key state.
// Some physical consoles may return valid key.
// Queue the valid keys.
//
for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
ZeroMem (&CurrentKeyData, sizeof (EFI_KEY_DATA));
Status = Private->TextInExList[Index]->ReadKeyStrokeEx (
Private->TextInExList[Index],
&CurrentKeyData
);
if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {
continue;
}
//
// Consolidate the key state from all physical consoles.
//
if ((CurrentKeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) {
KeyState.KeyShiftState |= CurrentKeyData.KeyState.KeyShiftState;
}
if ((CurrentKeyData.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != 0) {
KeyState.KeyToggleState |= CurrentKeyData.KeyState.KeyToggleState;
}
if (!EFI_ERROR (Status)) {
//
// If virtual KeyState has been required to be exposed, or it is not
// partial keystorke, queue the key.
// It's possible that user presses at multiple keyboards at the same moment,
// Private->KeyQueue[] are the storage to save all the keys.
//
if ((Private->VirtualKeyStateExported) ||
(CurrentKeyData.Key.ScanCode != CHAR_NULL) ||
(CurrentKeyData.Key.UnicodeChar != SCAN_NULL))
{
CopyMem (
&Private->KeyQueue[Private->CurrentNumberOfKeys],
&CurrentKeyData,
sizeof (EFI_KEY_DATA)
);
Private->CurrentNumberOfKeys++;
}
}
}
//
// Consolidate the key state for all keys in Private->KeyQueue[]
//
for (Index = 0; Index < Private->CurrentNumberOfKeys; Index++) {
CopyMem (&Private->KeyQueue[Index].KeyState, &KeyState, sizeof (EFI_KEY_STATE));
}
//
// Return the first saved key.
//
Status = ConSplitterTextInExDequeueKey (Private, KeyData);
if (!EFI_ERROR (Status)) {
return Status;
}
//
// Always return the key state even there is no key pressed.
//
ZeroMem (&KeyData->Key, sizeof (KeyData->Key));
CopyMem (&KeyData->KeyState, &KeyState, sizeof (KeyData->KeyState));
return EFI_NOT_READY;
}
/**
Set certain state for the input device.
@param This Protocol instance pointer.
@param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
state for the input device.
@retval EFI_SUCCESS The device state was set successfully.
@retval EFI_DEVICE_ERROR The device is not functioning correctly and
could not have the setting adjusted.
@retval EFI_UNSUPPORTED The device does not have the ability to set its
state.
@retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInSetState (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_TOGGLE_STATE *KeyToggleState
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
EFI_STATUS Status;
UINTN Index;
EFI_KEY_TOGGLE_STATE PhysicalKeyToggleState;
if (KeyToggleState == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// Always turn on physical TextInEx partial key report for
// toggle state sync.
//
PhysicalKeyToggleState = *KeyToggleState | EFI_KEY_STATE_EXPOSED;
//
// if no physical console input device exists, return EFI_SUCCESS;
// otherwise return the status of setting state of physical console input device
//
for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
Status = Private->TextInExList[Index]->SetState (
Private->TextInExList[Index],
&PhysicalKeyToggleState
);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Record the physical KeyToggleState.
//
Private->PhysicalKeyToggleState = PhysicalKeyToggleState;
//
// Get if virtual KeyState has been required to be exposed.
//
Private->VirtualKeyStateExported = (((*KeyToggleState) & EFI_KEY_STATE_EXPOSED) != 0);
return EFI_SUCCESS;
}
/**
Register a notification function for a particular keystroke for the input device.
@param This Protocol instance pointer.
@param KeyData A pointer to a buffer that is filled in with
the keystroke information for the key that was
pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState
and KeyData.KeyState.KeyShiftState are 0, then any incomplete
keystroke will trigger a notification of the KeyNotificationFunction.
@param KeyNotificationFunction Points to the function to be called when the key
sequence is typed specified by KeyData. This notification function
should be called at <=TPL_CALLBACK.
@param NotifyHandle Points to the unique handle assigned to the
registered notification.
@retval EFI_SUCCESS The notification function was registered
successfully.
@retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necessary data
structures.
@retval EFI_INVALID_PARAMETER KeyData or KeyNotificationFunction or NotifyHandle is NULL.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInRegisterKeyNotify (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN EFI_KEY_DATA *KeyData,
IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
OUT VOID **NotifyHandle
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
EFI_STATUS Status;
UINTN Index;
TEXT_IN_EX_SPLITTER_NOTIFY *NewNotify;
LIST_ENTRY *Link;
TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
if ((KeyData == NULL) || (NotifyHandle == NULL) || (KeyNotificationFunction == NULL)) {
return EFI_INVALID_PARAMETER;
}
Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
//
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
*NotifyHandle = CurrentNotify;
return EFI_SUCCESS;
}
}
}
//
// Allocate resource to save the notification function
//
NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *)AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));
if (NewNotify == NULL) {
return EFI_OUT_OF_RESOURCES;
}
NewNotify->NotifyHandleList = (VOID **)AllocateZeroPool (sizeof (VOID *) * Private->TextInExListCount);
if (NewNotify->NotifyHandleList == NULL) {
gBS->FreePool (NewNotify);
return EFI_OUT_OF_RESOURCES;
}
NewNotify->Signature = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;
NewNotify->KeyNotificationFn = KeyNotificationFunction;
CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));
//
// Return the wrong status of registering key notify of
// physical console input device if meet problems
//
for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
Status = Private->TextInExList[Index]->RegisterKeyNotify (
Private->TextInExList[Index],
KeyData,
KeyNotificationFunction,
&NewNotify->NotifyHandleList[Index]
);
if (EFI_ERROR (Status)) {
//
// Un-register the key notify on all physical console input devices
//
while (Index-- != 0) {
Private->TextInExList[Index]->UnregisterKeyNotify (
Private->TextInExList[Index],
NewNotify->NotifyHandleList[Index]
);
}
gBS->FreePool (NewNotify->NotifyHandleList);
gBS->FreePool (NewNotify);
return Status;
}
}
InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);
*NotifyHandle = NewNotify;
return EFI_SUCCESS;
}
/**
Remove a registered notification function from a particular keystroke.
@param This Protocol instance pointer.
@param NotificationHandle The handle of the notification function being
unregistered.
@retval EFI_SUCCESS The notification function was unregistered
successfully.
@retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
**/
EFI_STATUS
EFIAPI
ConSplitterTextInUnregisterKeyNotify (
IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
IN VOID *NotificationHandle
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
LIST_ENTRY *Link;
if (NotificationHandle == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
if (CurrentNotify == NotificationHandle) {
for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
Private->TextInExList[Index]->UnregisterKeyNotify (
Private->TextInExList[Index],
CurrentNotify->NotifyHandleList[Index]
);
}
RemoveEntryList (&CurrentNotify->NotifyEntry);
gBS->FreePool (CurrentNotify->NotifyHandleList);
gBS->FreePool (CurrentNotify);
return EFI_SUCCESS;
}
}
//
// NotificationHandle is not found in database
//
return EFI_INVALID_PARAMETER;
}
/**
Reset the input device and optionally run diagnostics
@param This Protocol instance pointer.
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
not be reset.
**/
EFI_STATUS
EFIAPI
ConSplitterSimplePointerReset (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
Private->InputEventSignalState = FALSE;
if (Private->CurrentNumberOfPointers == 0) {
return EFI_SUCCESS;
}
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
Status = Private->PointerList[Index]->Reset (
Private->PointerList[Index],
ExtendedVerification
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
return ReturnStatus;
}
/**
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existence of a keystroke via WaitForEvent () call.
@param Private Protocol instance pointer.
@param State The state information of simple pointer device.
@retval EFI_SUCCESS The keystroke information was returned.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keydtroke information was not returned due
to hardware errors.
**/
EFI_STATUS
EFIAPI
ConSplitterSimplePointerPrivateGetState (
IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
IN OUT EFI_SIMPLE_POINTER_STATE *State
)
{
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
UINTN Index;
EFI_SIMPLE_POINTER_STATE CurrentState;
State->RelativeMovementX = 0;
State->RelativeMovementY = 0;
State->RelativeMovementZ = 0;
State->LeftButton = FALSE;
State->RightButton = FALSE;
//
// if no physical console input device exists, return EFI_NOT_READY;
// if any physical console input device has key input,
// return the key and EFI_SUCCESS.
//
ReturnStatus = EFI_NOT_READY;
for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
Status = Private->PointerList[Index]->GetState (
Private->PointerList[Index],
&CurrentState
);
if (!EFI_ERROR (Status)) {
if (ReturnStatus == EFI_NOT_READY) {
ReturnStatus = EFI_SUCCESS;
}
if (CurrentState.LeftButton) {
State->LeftButton = TRUE;
}
if (CurrentState.RightButton) {
State->RightButton = TRUE;
}
if ((CurrentState.RelativeMovementX != 0) && (Private->PointerList[Index]->Mode->ResolutionX != 0)) {
State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32)Private->SimplePointerMode.ResolutionX) / (INT32)Private->PointerList[Index]->Mode->ResolutionX;
}
if ((CurrentState.RelativeMovementY != 0) && (Private->PointerList[Index]->Mode->ResolutionY != 0)) {
State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32)Private->SimplePointerMode.ResolutionY) / (INT32)Private->PointerList[Index]->Mode->ResolutionY;
}
if ((CurrentState.RelativeMovementZ != 0) && (Private->PointerList[Index]->Mode->ResolutionZ != 0)) {
State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32)Private->SimplePointerMode.ResolutionZ) / (INT32)Private->PointerList[Index]->Mode->ResolutionZ;
}
} else if (Status == EFI_DEVICE_ERROR) {
ReturnStatus = EFI_DEVICE_ERROR;
}
}
return ReturnStatus;
}
/**
Reads the next keystroke from the input device. The WaitForKey Event can
be used to test for existance of a keystroke via WaitForEvent () call.
@param This A pointer to protocol instance.
@param State A pointer to state information on the pointer device
@retval EFI_SUCCESS The keystroke information was returned in State.
@retval EFI_NOT_READY There was no keystroke data availiable.
@retval EFI_DEVICE_ERROR The keydtroke information was not returned due
to hardware errors.
**/
EFI_STATUS
EFIAPI
ConSplitterSimplePointerGetState (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN OUT EFI_SIMPLE_POINTER_STATE *State
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
Private->InputEventSignalState = FALSE;
return ConSplitterSimplePointerPrivateGetState (Private, State);
}
/**
This event aggregates all the events of the ConIn devices in the spliter.
If any events of physical ConIn devices are signaled, signal the ConIn
spliter event. This will cause the calling code to call
ConSplitterTextInReadKeyStroke ().
@param Event The Event associated with callback.
@param Context Context registered when Event was created.
**/
VOID
EFIAPI
ConSplitterSimplePointerWaitForInput (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *)Context;
//
// if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
//
if (Private->InputEventSignalState) {
gBS->SignalEvent (Event);
return;
}
//
// if any physical console input device has key input, signal the event.
//
for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
if (!EFI_ERROR (Status)) {
gBS->SignalEvent (Event);
Private->InputEventSignalState = TRUE;
}
}
}
/**
Resets the pointer device hardware.
@param This Protocol instance pointer.
@param ExtendedVerification Driver may perform diagnostics on reset.
@retval EFI_SUCCESS The device was reset.
@retval EFI_DEVICE_ERROR The device is not functioning correctly and
could not be reset.
**/
EFI_STATUS
EFIAPI
ConSplitterAbsolutePointerReset (
IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
Private->AbsoluteInputEventSignalState = FALSE;
if (Private->CurrentNumberOfAbsolutePointers == 0) {
return EFI_SUCCESS;
}
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
Status = Private->AbsolutePointerList[Index]->Reset (
Private->AbsolutePointerList[Index],
ExtendedVerification
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
return ReturnStatus;
}
/**
Retrieves the current state of a pointer device.
@param This Protocol instance pointer.
@param State A pointer to the state information on the
pointer device.
@retval EFI_SUCCESS The state of the pointer device was returned in
State..
@retval EFI_NOT_READY The state of the pointer device has not changed
since the last call to GetState().
@retval EFI_DEVICE_ERROR A device error occurred while attempting to
retrieve the pointer device's current state.
**/
EFI_STATUS
EFIAPI
ConSplitterAbsolutePointerGetState (
IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
IN OUT EFI_ABSOLUTE_POINTER_STATE *State
)
{
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_STATUS ReturnStatus;
UINTN Index;
EFI_ABSOLUTE_POINTER_STATE CurrentState;
UINT64 MinX;
UINT64 MinY;
UINT64 MinZ;
UINT64 MaxX;
UINT64 MaxY;
UINT64 MaxZ;
UINT64 VirtualMinX;
UINT64 VirtualMinY;
UINT64 VirtualMinZ;
UINT64 VirtualMaxX;
UINT64 VirtualMaxY;
UINT64 VirtualMaxZ;
Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
Private->AbsoluteInputEventSignalState = FALSE;
State->CurrentX = 0;
State->CurrentY = 0;
State->CurrentZ = 0;
State->ActiveButtons = 0;
VirtualMinX = Private->AbsolutePointerMode.AbsoluteMinX;
VirtualMinY = Private->AbsolutePointerMode.AbsoluteMinY;
VirtualMinZ = Private->AbsolutePointerMode.AbsoluteMinZ;
VirtualMaxX = Private->AbsolutePointerMode.AbsoluteMaxX;
VirtualMaxY = Private->AbsolutePointerMode.AbsoluteMaxY;
VirtualMaxZ = Private->AbsolutePointerMode.AbsoluteMaxZ;
//
// if no physical pointer device exists, return EFI_NOT_READY;
// if any physical pointer device has changed state,
// return the state and EFI_SUCCESS.
//
ReturnStatus = EFI_NOT_READY;
for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
Status = Private->AbsolutePointerList[Index]->GetState (
Private->AbsolutePointerList[Index],
&CurrentState
);
if (!EFI_ERROR (Status)) {
if (ReturnStatus == EFI_NOT_READY) {
ReturnStatus = EFI_SUCCESS;
}
MinX = Private->AbsolutePointerList[Index]->Mode->AbsoluteMinX;
MinY = Private->AbsolutePointerList[Index]->Mode->AbsoluteMinY;
MinZ = Private->AbsolutePointerList[Index]->Mode->AbsoluteMinZ;
MaxX = Private->AbsolutePointerList[Index]->Mode->AbsoluteMaxX;
MaxY = Private->AbsolutePointerList[Index]->Mode->AbsoluteMaxY;
MaxZ = Private->AbsolutePointerList[Index]->Mode->AbsoluteMaxZ;
State->ActiveButtons = CurrentState.ActiveButtons;
//
// Rescale to Con Splitter virtual Absolute Pointer's resolution.
//
if (!((MinX == 0) && (MaxX == 0))) {
State->CurrentX = VirtualMinX + DivU64x64Remainder (
MultU64x64 (
CurrentState.CurrentX,
VirtualMaxX - VirtualMinX
),
MaxX - MinX,
NULL
);
}
if (!((MinY == 0) && (MaxY == 0))) {
State->CurrentY = VirtualMinY + DivU64x64Remainder (
MultU64x64 (
CurrentState.CurrentY,
VirtualMaxY - VirtualMinY
),
MaxY - MinY,
NULL
);
}
if (!((MinZ == 0) && (MaxZ == 0))) {
State->CurrentZ = VirtualMinZ + DivU64x64Remainder (
MultU64x64 (
CurrentState.CurrentZ,
VirtualMaxZ - VirtualMinZ
),
MaxZ - MinZ,
NULL
);
}
} else if (Status == EFI_DEVICE_ERROR) {
ReturnStatus = EFI_DEVICE_ERROR;
}
}
return ReturnStatus;
}
/**
This event aggregates all the events of the pointer devices in the splitter.
If any events of physical pointer devices are signaled, signal the pointer
splitter event. This will cause the calling code to call
ConSplitterAbsolutePointerGetState ().
@param Event The Event associated with callback.
@param Context Context registered when Event was created.
**/
VOID
EFIAPI
ConSplitterAbsolutePointerWaitForInput (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *)Context;
//
// if AbsoluteInputEventSignalState is flagged before,
// and not cleared by Reset() or GetState(), signal it
//
if (Private->AbsoluteInputEventSignalState) {
gBS->SignalEvent (Event);
return;
}
//
// if any physical console input device has key input, signal the event.
//
for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);
if (!EFI_ERROR (Status)) {
gBS->SignalEvent (Event);
Private->AbsoluteInputEventSignalState = TRUE;
}
}
}
/**
Reset the text output device hardware and optionally run diagnostics
@param This Protocol instance pointer.
@param ExtendedVerification Driver may perform more exhaustive verification
operation of the device during reset.
@retval EFI_SUCCESS The text output device was reset.
@retval EFI_DEVICE_ERROR The text output device is not functioning
correctly and could not be reset.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutReset (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->Reset (
Private->TextOutList[Index].TextOut,
ExtendedVerification
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK));
//
// reset all mode parameters
//
TextOutSetMode (Private, 0);
return ReturnStatus;
}
/**
Write a Unicode string to the output device.
@param This Protocol instance pointer.
@param WString The NULL-terminated Unicode string to be
displayed on the output device(s). All output
devices must also support the Unicode drawing
defined in this file.
@retval EFI_SUCCESS The string was output to the device.
@retval EFI_DEVICE_ERROR The device reported an error while attempting to
output the text.
@retval EFI_UNSUPPORTED The output device's mode is not currently in a
defined text mode.
@retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
characters in the Unicode string could not be
rendered and were skipped.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutOutputString (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN CHAR16 *WString
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
UINTN MaxColumn;
UINTN MaxRow;
This->SetAttribute (This, This->Mode->Attribute);
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->OutputString (
Private->TextOutList[Index].TextOut,
WString
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
if (Private->CurrentNumberOfConsoles > 0) {
Private->TextOutMode.CursorColumn = Private->TextOutList[0].TextOut->Mode->CursorColumn;
Private->TextOutMode.CursorRow = Private->TextOutList[0].TextOut->Mode->CursorRow;
} else {
//
// When there is no real console devices in system,
// update cursor position for the virtual device in consplitter.
//
Private->TextOut.QueryMode (
&Private->TextOut,
Private->TextOutMode.Mode,
&MaxColumn,
&MaxRow
);
for ( ; *WString != CHAR_NULL; WString++) {
switch (*WString) {
case CHAR_BACKSPACE:
if ((Private->TextOutMode.CursorColumn == 0) && (Private->TextOutMode.CursorRow > 0)) {
Private->TextOutMode.CursorRow--;
Private->TextOutMode.CursorColumn = (INT32)(MaxColumn - 1);
} else if (Private->TextOutMode.CursorColumn > 0) {
Private->TextOutMode.CursorColumn--;
}
break;
case CHAR_LINEFEED:
if (Private->TextOutMode.CursorRow < (INT32)(MaxRow - 1)) {
Private->TextOutMode.CursorRow++;
}
break;
case CHAR_CARRIAGE_RETURN:
Private->TextOutMode.CursorColumn = 0;
break;
default:
if (Private->TextOutMode.CursorColumn < (INT32)(MaxColumn - 1)) {
Private->TextOutMode.CursorColumn++;
} else {
Private->TextOutMode.CursorColumn = 0;
if (Private->TextOutMode.CursorRow < (INT32)(MaxRow - 1)) {
Private->TextOutMode.CursorRow++;
}
}
break;
}
}
}
return ReturnStatus;
}
/**
Verifies that all characters in a Unicode string can be output to the
target device.
@param This Protocol instance pointer.
@param WString The NULL-terminated Unicode string to be
examined for the output device(s).
@retval EFI_SUCCESS The device(s) are capable of rendering the
output string.
@retval EFI_UNSUPPORTED Some of the characters in the Unicode string
cannot be rendered by one or more of the output
devices mapped by the EFI handle.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutTestString (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN CHAR16 *WString
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->TestString (
Private->TextOutList[Index].TextOut,
WString
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
//
// There is no DevNullTextOutTestString () since a Unicode buffer would
// always return EFI_SUCCESS.
// ReturnStatus will be EFI_SUCCESS if no consoles are present
//
return ReturnStatus;
}
/**
Returns information for an available text mode that the output device(s)
supports.
@param This Protocol instance pointer.
@param ModeNumber The mode number to return information on.
@param Columns Returns the columns of the text output device
for the requested ModeNumber.
@param Rows Returns the rows of the text output device
for the requested ModeNumber.
@retval EFI_SUCCESS The requested mode information was returned.
@retval EFI_DEVICE_ERROR The device had an error and could not complete
the request.
@retval EFI_UNSUPPORTED The mode number was not valid.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutQueryMode (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN ModeNumber,
OUT UINTN *Columns,
OUT UINTN *Rows
)
{
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN CurrentMode;
INT32 *TextOutModeMap;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// Check whether param ModeNumber is valid.
// ModeNumber should be within range 0 ~ MaxMode - 1.
//
if ((ModeNumber > (UINTN)(((UINT32)-1)>>1))) {
return EFI_UNSUPPORTED;
}
if ((INT32)ModeNumber >= This->Mode->MaxMode) {
return EFI_UNSUPPORTED;
}
//
// We get the available mode from mode intersection map if it's available
//
if (Private->TextOutModeMap != NULL) {
TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
CurrentMode = (UINTN)(*TextOutModeMap);
*Columns = Private->TextOutQueryData[CurrentMode].Columns;
*Rows = Private->TextOutQueryData[CurrentMode].Rows;
} else {
*Columns = Private->TextOutQueryData[ModeNumber].Columns;
*Rows = Private->TextOutQueryData[ModeNumber].Rows;
}
if ((*Columns <= 0) && (*Rows <= 0)) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
/**
Sets the output device(s) to a specified mode.
@param This Protocol instance pointer.
@param ModeNumber The mode number to set.
@retval EFI_SUCCESS The requested text mode was set.
@retval EFI_DEVICE_ERROR The device had an error and could not complete
the request.
@retval EFI_UNSUPPORTED The mode number was not valid.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutSetMode (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN ModeNumber
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
INT32 *TextOutModeMap;
EFI_STATUS ReturnStatus;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// Check whether param ModeNumber is valid.
// ModeNumber should be within range 0 ~ MaxMode - 1.
//
if ((ModeNumber > (UINTN)(((UINT32)-1)>>1))) {
return EFI_UNSUPPORTED;
}
if ((INT32)ModeNumber >= This->Mode->MaxMode) {
return EFI_UNSUPPORTED;
}
//
// If the mode is being set to the curent mode, then just clear the screen and return.
//
if (Private->TextOutMode.Mode == (INT32)ModeNumber) {
return ConSplitterTextOutClearScreen (This);
}
//
// return the worst status met
//
TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
//
// While adding a console out device do not set same mode again for the same device.
//
if ((!Private->AddingConOutDevice) ||
(TextOutModeMap[Index] != Private->TextOutList[Index].TextOut->Mode->Mode))
{
Status = Private->TextOutList[Index].TextOut->SetMode (
Private->TextOutList[Index].TextOut,
TextOutModeMap[Index]
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
}
//
// Set mode parameter to specified mode number
//
TextOutSetMode (Private, ModeNumber);
return ReturnStatus;
}
/**
Sets the background and foreground colors for the OutputString () and
ClearScreen () functions.
@param This Protocol instance pointer.
@param Attribute The attribute to set. Bits 0..3 are the
foreground color, and bits 4..6 are the
background color. All other bits are undefined
and must be zero. The valid Attributes are
defined in this file.
@retval EFI_SUCCESS The attribute was set.
@retval EFI_DEVICE_ERROR The device had an error and could not complete
the request.
@retval EFI_UNSUPPORTED The attribute requested is not defined.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutSetAttribute (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN Attribute
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// Check whether param Attribute is valid.
//
if ((Attribute | 0x7F) != 0x7F) {
return EFI_UNSUPPORTED;
}
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->SetAttribute (
Private->TextOutList[Index].TextOut,
Attribute
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
Private->TextOutMode.Attribute = (INT32)Attribute;
return ReturnStatus;
}
/**
Clears the output device(s) display to the currently selected background
color.
@param This Protocol instance pointer.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR The device had an error and could not complete
the request.
@retval EFI_UNSUPPORTED The output device is not in a valid text mode.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutClearScreen (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
//
// No need to do extra check here as whether (Column, Row) is valid has
// been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
// always be supported.
//
Private->TextOutMode.CursorColumn = 0;
Private->TextOutMode.CursorRow = 0;
Private->TextOutMode.CursorVisible = TRUE;
return ReturnStatus;
}
/**
Sets the current coordinates of the cursor position
@param This Protocol instance pointer.
@param Column The column position to set the cursor to. Must be
greater than or equal to zero and less than the
number of columns by QueryMode ().
@param Row The row position to set the cursor to. Must be
greater than or equal to zero and less than the
number of rows by QueryMode ().
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR The device had an error and could not complete
the request.
@retval EFI_UNSUPPORTED The output device is not in a valid text mode,
or the cursor position is invalid for the
current mode.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutSetCursorPosition (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN Column,
IN UINTN Row
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
UINTN MaxColumn;
UINTN MaxRow;
INT32 *TextOutModeMap;
INT32 ModeNumber;
INT32 CurrentMode;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
TextOutModeMap = NULL;
ModeNumber = Private->TextOutMode.Mode;
//
// Get current MaxColumn and MaxRow from intersection map
//
if (Private->TextOutModeMap != NULL) {
TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
CurrentMode = *TextOutModeMap;
} else {
CurrentMode = ModeNumber;
}
MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;
MaxRow = Private->TextOutQueryData[CurrentMode].Rows;
if ((Column >= MaxColumn) || (Row >= MaxRow)) {
return EFI_UNSUPPORTED;
}
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
Private->TextOutList[Index].TextOut,
Column,
Row
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
//
// No need to do extra check here as whether (Column, Row) is valid has
// been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
// always be supported.
//
Private->TextOutMode.CursorColumn = (INT32)Column;
Private->TextOutMode.CursorRow = (INT32)Row;
return ReturnStatus;
}
/**
Makes the cursor visible or invisible
@param This Protocol instance pointer.
@param Visible If TRUE, the cursor is set to be visible. If
FALSE, the cursor is set to be invisible.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR The device had an error and could not complete
the request, or the device does not support
changing the cursor mode.
@retval EFI_UNSUPPORTED The output device is not in a valid text mode.
**/
EFI_STATUS
EFIAPI
ConSplitterTextOutEnableCursor (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN BOOLEAN Visible
)
{
EFI_STATUS Status;
TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
UINTN Index;
EFI_STATUS ReturnStatus;
Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
//
// return the worst status met
//
for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
Status = Private->TextOutList[Index].TextOut->EnableCursor (
Private->TextOutList[Index].TextOut,
Visible
);
if (EFI_ERROR (Status)) {
ReturnStatus = Status;
}
}
Private->TextOutMode.CursorVisible = Visible;
return ReturnStatus;
}
|