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
|
/*
* drivers/s390/char/hwc_rw.c
* driver: reading from and writing to system console on S/390 via HWC
*
* S390 version
* Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
* Author(s): Martin Peschke <peschke@fh-brandenburg.de>
*
*
*
*
*
*
*/
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/ctype.h>
#include <linux/mm.h>
#include <linux/timer.h>
#include <asm/ebcdic.h>
#include <asm/uaccess.h>
#include <asm/types.h>
#include <asm/bitops.h>
#include <asm/setup.h>
#include <asm/page.h>
#include <asm/s390_ext.h>
#ifndef MIN
#define MIN(a,b) (((a<b) ? a : b))
#endif
#define HWC_ASCEBC(x) ((MACHINE_IS_VM ? _ascebc[x] : _ascebc_500[x]))
#define HWC_EBCASC_STR(s,c) ((MACHINE_IS_VM ? EBCASC(s,c) : EBCASC_500(s,c)))
#define HWC_RW_PRINT_HEADER "hwc low level driver: "
#define USE_VM_DETECTION
#define DEFAULT_CASE_DELIMITER '%'
#define DUMP_HWC_INIT_ERROR
#define DUMP_HWC_WRITE_ERROR
#define DUMP_HWC_WRITE_LIST_ERROR
#define DUMP_HWC_READ_ERROR
#undef DUMP_HWCB_INPUT
#undef BUFFER_STRESS_TEST
#undef MEASURE_HWC_OUTPUT
typedef struct {
unsigned char *next;
unsigned short int mto_char_sum;
unsigned char mto_number;
unsigned char times_lost;
unsigned short int mto_number_lost;
unsigned long int mto_char_sum_lost;
} __attribute__ ((packed))
hwcb_list_t;
#define MAX_HWCB_ROOM (PAGE_SIZE - sizeof(hwcb_list_t))
#define MAX_MESSAGE_SIZE (MAX_HWCB_ROOM - sizeof(write_hwcb_t))
#define BUF_HWCB hwc_data.hwcb_list_tail
#define OUT_HWCB hwc_data.hwcb_list_head
#define ALL_HWCB_MTO hwc_data.mto_number
#define ALL_HWCB_CHAR hwc_data.mto_char_sum
#define _LIST(hwcb) ((hwcb_list_t*)(&(hwcb)[PAGE_SIZE-sizeof(hwcb_list_t)]))
#define _HWCB_CHAR(hwcb) (_LIST(hwcb)->mto_char_sum)
#define _HWCB_MTO(hwcb) (_LIST(hwcb)->mto_number)
#define _HWCB_CHAR_LOST(hwcb) (_LIST(hwcb)->mto_char_sum_lost)
#define _HWCB_MTO_LOST(hwcb) (_LIST(hwcb)->mto_number_lost)
#define _HWCB_TIMES_LOST(hwcb) (_LIST(hwcb)->times_lost)
#define _HWCB_NEXT(hwcb) (_LIST(hwcb)->next)
#define BUF_HWCB_CHAR _HWCB_CHAR(BUF_HWCB)
#define BUF_HWCB_MTO _HWCB_MTO(BUF_HWCB)
#define BUF_HWCB_NEXT _HWCB_NEXT(BUF_HWCB)
#define OUT_HWCB_CHAR _HWCB_CHAR(OUT_HWCB)
#define OUT_HWCB_MTO _HWCB_MTO(OUT_HWCB)
#define OUT_HWCB_NEXT _HWCB_NEXT(OUT_HWCB)
#define BUF_HWCB_CHAR_LOST _HWCB_CHAR_LOST(BUF_HWCB)
#define BUF_HWCB_MTO_LOST _HWCB_MTO_LOST(BUF_HWCB)
#define OUT_HWCB_CHAR_LOST _HWCB_CHAR_LOST(OUT_HWCB)
#define OUT_HWCB_MTO_LOST _HWCB_MTO_LOST(OUT_HWCB)
#define BUF_HWCB_TIMES_LOST _HWCB_TIMES_LOST(BUF_HWCB)
#include "hwc.h"
#define __HWC_RW_C__
#include "hwc_rw.h"
#undef __HWC_RW_C__
static unsigned char _obuf[MAX_HWCB_ROOM];
static unsigned char
_page[PAGE_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
typedef unsigned long kmem_pages_t;
#define MAX_KMEM_PAGES (sizeof(kmem_pages_t) << 3)
#define HWC_WTIMER_RUNS 1
#define HWC_FLUSH 2
#define HWC_INIT 4
#define HWC_BROKEN 8
#define HWC_INTERRUPT 16
#define HWC_PTIMER_RUNS 32
static struct {
hwc_ioctls_t ioctls;
hwc_ioctls_t init_ioctls;
unsigned char *hwcb_list_head;
unsigned char *hwcb_list_tail;
unsigned short int mto_number;
unsigned int mto_char_sum;
unsigned char hwcb_count;
unsigned long kmem_start;
unsigned long kmem_end;
kmem_pages_t kmem_pages;
unsigned char *obuf;
unsigned short int obuf_cursor;
unsigned short int obuf_count;
unsigned short int obuf_start;
unsigned char *page;
u32 current_servc;
unsigned char *current_hwcb;
unsigned char write_nonprio:1;
unsigned char write_prio:1;
unsigned char read_nonprio:1;
unsigned char read_prio:1;
unsigned char read_statechange:1;
unsigned char flags;
hwc_high_level_calls_t *calls;
spinlock_t lock;
struct timer_list write_timer;
struct timer_list poll_timer;
} hwc_data =
{
{
},
{
8,
0,
80,
1,
50,
MAX_KMEM_PAGES,
0,
0x6c,
0,
0,
0
},
NULL,
NULL,
0,
0,
0,
0,
0,
0,
_obuf,
0,
0,
0,
_page,
0,
NULL,
0,
0,
0,
0,
0,
0,
NULL
};
static unsigned long cr0 __attribute__ ((aligned (8)));
static unsigned long cr0_save __attribute__ ((aligned (8)));
static unsigned char psw_mask __attribute__ ((aligned (8)));
#define DELAYED_WRITE 0
#define IMMEDIATE_WRITE 1
static signed int do_hwc_write (int from_user, unsigned char *,
unsigned int,
unsigned char);
static asmlinkage int
internal_print (char write_time, char *fmt,...)
{
va_list args;
int i;
unsigned char buf[512];
va_start (args, fmt);
i = vsprintf (buf, fmt, args);
va_end (args);
return do_hwc_write (0, buf, i, write_time);
}
int
hwc_printk (const char *fmt,...)
{
va_list args;
int i;
unsigned char buf[512];
unsigned long flags;
int retval;
spin_lock_irqsave (&hwc_data.lock, flags);
i = vsprintf (buf, fmt, args);
va_end (args);
retval = do_hwc_write (0, buf, i, IMMEDIATE_WRITE);
spin_unlock_irqrestore (&hwc_data.lock, flags);
return retval;
}
#ifdef DUMP_HWCB_INPUT
static void
dump_storage_area (unsigned char *area, unsigned short int count)
{
unsigned short int index;
ioctl_nl_t old_final_nl;
if (!area || !count)
return;
old_final_nl = hwc_data.ioctls.final_nl;
hwc_data.ioctls.final_nl = 1;
internal_print (DELAYED_WRITE, "\n%8x ", area);
for (index = 0; index < count; index++) {
if (area[index] <= 0xF)
internal_print (DELAYED_WRITE, "0%x", area[index]);
else
internal_print (DELAYED_WRITE, "%x", area[index]);
if ((index & 0xF) == 0xF)
internal_print (DELAYED_WRITE, "\n%8x ",
&area[index + 1]);
else if ((index & 3) == 3)
internal_print (DELAYED_WRITE, " ");
}
internal_print (IMMEDIATE_WRITE, "\n");
hwc_data.ioctls.final_nl = old_final_nl;
}
#endif
static inline u32
service_call (
u32 hwc_command_word,
unsigned char hwcb[])
{
unsigned int condition_code = 1;
__asm__ __volatile__ ("L 1, 0(%0) \n\t"
"LRA 2, 0(%1) \n\t"
".long 0xB2200012 \n\t"
:
:"a" (&hwc_command_word), "a" (hwcb)
:"1", "2", "memory");
__asm__ __volatile__ ("IPM %0 \n\t"
"SRL %0, 28 \n\t"
:"=r" (condition_code));
return condition_code;
}
static inline unsigned char *
ext_int_param (void)
{
u32 param;
__asm__ __volatile__ ("L %0,128\n\t"
:"=r" (param));
return ((unsigned char *) param);
}
static int
prepare_write_hwcb (void)
{
write_hwcb_t *hwcb;
if (!BUF_HWCB)
return -ENOMEM;
BUF_HWCB_MTO = 0;
BUF_HWCB_CHAR = 0;
hwcb = (write_hwcb_t *) BUF_HWCB;
memcpy (hwcb, &write_hwcb_template, sizeof (write_hwcb_t));
return 0;
}
static int
sane_write_hwcb (void)
{
unsigned short int lost_msg;
unsigned int lost_char;
unsigned char lost_hwcb;
unsigned char *bad_addr;
unsigned long page;
int page_nr;
if (!OUT_HWCB)
return -ENOMEM;
if ((unsigned long) OUT_HWCB & 0xFFF) {
bad_addr = OUT_HWCB;
#ifdef DUMP_HWC_WRITE_LIST_ERROR
__asm__ ("LHI 1,0xe30\n\t"
"LRA 2,0(%0) \n\t"
"J .+0 \n\t"
:
: "a" (bad_addr)
: "1", "2");
#endif
hwc_data.kmem_pages = 0;
if ((unsigned long) BUF_HWCB & 0xFFF) {
lost_hwcb = hwc_data.hwcb_count;
lost_msg = ALL_HWCB_MTO;
lost_char = ALL_HWCB_CHAR;
OUT_HWCB = NULL;
BUF_HWCB = NULL;
ALL_HWCB_MTO = 0;
ALL_HWCB_CHAR = 0;
hwc_data.hwcb_count = 0;
} else {
lost_hwcb = hwc_data.hwcb_count - 1;
lost_msg = ALL_HWCB_MTO - BUF_HWCB_MTO;
lost_char = ALL_HWCB_CHAR - BUF_HWCB_CHAR;
OUT_HWCB = BUF_HWCB;
ALL_HWCB_MTO = BUF_HWCB_MTO;
ALL_HWCB_CHAR = BUF_HWCB_CHAR;
hwc_data.hwcb_count = 1;
page = (unsigned long) BUF_HWCB;
if (page >= hwc_data.kmem_start &&
page <= hwc_data.kmem_end) {
page_nr = (int)
((page - hwc_data.kmem_start) >> 12);
set_bit (page_nr, &hwc_data.kmem_pages);
}
}
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"found invalid HWCB at address 0x%x. List corrupted. "
"Lost %i HWCBs with %i characters within up to %i "
"messages. Saved %i HWCB with last %i characters i"
"within up to %i messages.\n",
(unsigned int) bad_addr,
lost_hwcb, lost_char, lost_msg,
hwc_data.hwcb_count,
ALL_HWCB_CHAR, ALL_HWCB_MTO);
}
return 0;
}
static int
reuse_write_hwcb (void)
{
int retval;
if (hwc_data.hwcb_count < 2)
#ifdef DUMP_HWC_WRITE_LIST_ERROR
__asm__ ("LHI 1,0xe31\n\t"
"LRA 2,0(%0)\n\t"
"LRA 3,0(%1)\n\t"
"J .+0 \n\t"
:
: "a" (BUF_HWCB), "a" (OUT_HWCB)
: "1", "2", "3");
#else
return -EPERM;
#endif
if (hwc_data.current_hwcb == OUT_HWCB) {
if (hwc_data.hwcb_count > 2) {
BUF_HWCB_NEXT = OUT_HWCB_NEXT;
BUF_HWCB = OUT_HWCB_NEXT;
OUT_HWCB_NEXT = BUF_HWCB_NEXT;
BUF_HWCB_NEXT = NULL;
}
} else {
BUF_HWCB_NEXT = OUT_HWCB;
BUF_HWCB = OUT_HWCB;
OUT_HWCB = OUT_HWCB_NEXT;
BUF_HWCB_NEXT = NULL;
}
BUF_HWCB_TIMES_LOST += 1;
BUF_HWCB_CHAR_LOST += BUF_HWCB_CHAR;
BUF_HWCB_MTO_LOST += BUF_HWCB_MTO;
ALL_HWCB_MTO -= BUF_HWCB_MTO;
ALL_HWCB_CHAR -= BUF_HWCB_CHAR;
retval = prepare_write_hwcb ();
if (hwc_data.hwcb_count == hwc_data.ioctls.max_hwcb)
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"reached my own limit of "
"allowed buffer space for output (%i HWCBs = %li "
"bytes), skipped content of oldest HWCB %i time(s) "
"(%i lines = %i characters)\n",
hwc_data.ioctls.max_hwcb,
hwc_data.ioctls.max_hwcb * PAGE_SIZE,
BUF_HWCB_TIMES_LOST,
BUF_HWCB_MTO_LOST,
BUF_HWCB_CHAR_LOST);
else
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"page allocation failed, "
"could not expand buffer for output (currently in "
"use: %i HWCBs = %li bytes), skipped content of "
"oldest HWCB %i time(s) (%i lines = %i characters)\n",
hwc_data.hwcb_count,
hwc_data.hwcb_count * PAGE_SIZE,
BUF_HWCB_TIMES_LOST,
BUF_HWCB_MTO_LOST,
BUF_HWCB_CHAR_LOST);
return retval;
}
static int
allocate_write_hwcb (void)
{
unsigned char *page;
int page_nr;
if (hwc_data.hwcb_count == hwc_data.ioctls.max_hwcb)
return -ENOMEM;
page_nr = find_first_zero_bit (&hwc_data.kmem_pages, MAX_KMEM_PAGES);
if (page_nr < hwc_data.ioctls.kmem_hwcb) {
page = (unsigned char *)
(hwc_data.kmem_start + (page_nr << 12));
set_bit (page_nr, &hwc_data.kmem_pages);
} else
page = (unsigned char *) __get_free_page (GFP_ATOMIC);
if (!page)
return -ENOMEM;
if (!OUT_HWCB)
OUT_HWCB = page;
else
BUF_HWCB_NEXT = page;
BUF_HWCB = page;
BUF_HWCB_NEXT = NULL;
hwc_data.hwcb_count++;
prepare_write_hwcb ();
BUF_HWCB_TIMES_LOST = 0;
BUF_HWCB_MTO_LOST = 0;
BUF_HWCB_CHAR_LOST = 0;
#ifdef BUFFER_STRESS_TEST
internal_print (
DELAYED_WRITE,
"*** " HWC_RW_PRINT_HEADER
"page #%i at 0x%x for buffering allocated. ***\n",
hwc_data.hwcb_count, page);
#endif
return 0;
}
static int
release_write_hwcb (void)
{
unsigned long page;
int page_nr;
if (!hwc_data.hwcb_count)
return -ENODATA;
if (hwc_data.hwcb_count == 1) {
prepare_write_hwcb ();
ALL_HWCB_CHAR = 0;
ALL_HWCB_MTO = 0;
BUF_HWCB_TIMES_LOST = 0;
BUF_HWCB_MTO_LOST = 0;
BUF_HWCB_CHAR_LOST = 0;
} else {
page = (unsigned long) OUT_HWCB;
ALL_HWCB_MTO -= OUT_HWCB_MTO;
ALL_HWCB_CHAR -= OUT_HWCB_CHAR;
hwc_data.hwcb_count--;
OUT_HWCB = OUT_HWCB_NEXT;
if (page >= hwc_data.kmem_start &&
page <= hwc_data.kmem_end) {
/*memset((void *) page, 0, PAGE_SIZE); */
page_nr = (int) ((page - hwc_data.kmem_start) >> 12);
clear_bit (page_nr, &hwc_data.kmem_pages);
} else
free_page (page);
#ifdef BUFFER_STRESS_TEST
internal_print (
DELAYED_WRITE,
"*** " HWC_RW_PRINT_HEADER
"page at 0x%x released, %i pages still in use ***\n",
page, hwc_data.hwcb_count);
#endif
}
return 0;
}
static int
add_mto (
unsigned char *message,
unsigned short int count)
{
unsigned short int mto_size;
write_hwcb_t *hwcb;
mto_t *mto;
void *dest;
if (!BUF_HWCB)
return -ENOMEM;
if (BUF_HWCB == hwc_data.current_hwcb)
return -ENOMEM;
mto_size = sizeof (mto_t) + count;
hwcb = (write_hwcb_t *) BUF_HWCB;
if ((MAX_HWCB_ROOM - hwcb->length) < mto_size)
return -ENOMEM;
mto = (mto_t *) (((unsigned long) hwcb) + hwcb->length);
memcpy (mto, &mto_template, sizeof (mto_t));
dest = (void *) (((unsigned long) mto) + sizeof (mto_t));
memcpy (dest, message, count);
mto->length += count;
hwcb->length += mto_size;
hwcb->msgbuf.length += mto_size;
hwcb->msgbuf.mdb.length += mto_size;
BUF_HWCB_MTO++;
ALL_HWCB_MTO++;
BUF_HWCB_CHAR += count;
ALL_HWCB_CHAR += count;
#ifdef MEASURE_HWC_OUTPUT
hwc_data.ioctls.measured_lines++;
hwc_data.ioctls.measured_chars += count;
#endif
return count;
}
static int write_event_data_1 (void);
static void
do_poll_hwc (unsigned long data)
{
unsigned long flags;
spin_lock_irqsave (&hwc_data.lock, flags);
write_event_data_1 ();
spin_unlock_irqrestore (&hwc_data.lock, flags);
}
void
start_poll_hwc (void)
{
init_timer (&hwc_data.poll_timer);
hwc_data.poll_timer.function = do_poll_hwc;
hwc_data.poll_timer.data = (unsigned long) NULL;
hwc_data.poll_timer.expires = jiffies + 2 * HZ;
add_timer (&hwc_data.poll_timer);
hwc_data.flags |= HWC_PTIMER_RUNS;
}
static int
write_event_data_1 (void)
{
unsigned short int condition_code;
int retval;
write_hwcb_t *hwcb = (write_hwcb_t *) OUT_HWCB;
if ((!hwc_data.write_prio) &&
(!hwc_data.write_nonprio) &&
hwc_data.read_statechange)
return -EOPNOTSUPP;
if (hwc_data.current_servc)
return -EBUSY;
retval = sane_write_hwcb ();
if (retval < 0)
return -EIO;
if (!OUT_HWCB_MTO)
return -ENODATA;
if (!hwc_data.write_nonprio && hwc_data.write_prio)
hwcb->msgbuf.type = ET_PMsgCmd;
else
hwcb->msgbuf.type = ET_Msg;
condition_code = service_call (HWC_CMDW_WRITEDATA, OUT_HWCB);
#ifdef DUMP_HWC_WRITE_ERROR
if (condition_code != HWC_COMMAND_INITIATED)
__asm__ ("LHI 1,0xe20\n\t"
"L 2,0(%0)\n\t"
"LRA 3,0(%1)\n\t"
"J .+0 \n\t"
:
: "a" (&condition_code), "a" (OUT_HWCB)
: "1", "2", "3");
#endif
switch (condition_code) {
case HWC_COMMAND_INITIATED:
hwc_data.current_servc = HWC_CMDW_WRITEDATA;
hwc_data.current_hwcb = OUT_HWCB;
retval = condition_code;
#ifdef MEASURE_HWC_OUTPUT
hwc_data.ioctls.measured_wcalls++;
#endif
break;
case HWC_BUSY:
retval = -EBUSY;
break;
case HWC_NOT_OPERATIONAL:
start_poll_hwc ();
default:
retval = -EIO;
}
return retval;
}
static void
flush_hwcbs (void)
{
while (hwc_data.hwcb_count > 1)
release_write_hwcb ();
release_write_hwcb ();
hwc_data.flags &= ~HWC_FLUSH;
}
static int
write_event_data_2 (void)
{
write_hwcb_t *hwcb;
int retval = 0;
#ifdef DUMP_HWC_WRITE_ERROR
unsigned char *param;
param = ext_int_param ();
if (param != hwc_data.current_hwcb) {
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"write_event_data_2 : "
"HWCB address does not fit "
"(expected: 0x%x, got: 0x%x).\n",
hwc_data.current_hwcb,
param);
return -EINVAL;
}
#endif
hwcb = (write_hwcb_t *) OUT_HWCB;
#ifdef DUMP_HWC_WRITE_LIST_ERROR
if (((unsigned char *) hwcb) != hwc_data.current_hwcb) {
__asm__ ("LHI 1,0xe22\n\t"
"LRA 2,0(%0)\n\t"
"LRA 3,0(%1)\n\t"
"LRA 4,0(%2)\n\t"
"LRA 5,0(%3)\n\t"
"J .+0 \n\t"
:
: "a" (OUT_HWCB),
"a" (hwc_data.current_hwcb),
"a" (BUF_HWCB),
"a" (hwcb)
: "1", "2", "3", "4", "5");
}
#endif
#ifdef DUMP_HWC_WRITE_ERROR
if (hwcb->response_code != 0x0020) {
__asm__ ("LHI 1,0xe21\n\t"
"LRA 2,0(%0)\n\t"
"LRA 3,0(%1)\n\t"
"LRA 4,0(%2)\n\t"
"LH 5,0(%3)\n\t"
"SRL 5,8\n\t"
"J .+0 \n\t"
:
: "a" (OUT_HWCB), "a" (hwc_data.current_hwcb),
"a" (BUF_HWCB),
"a" (&(hwc_data.hwcb_count))
: "1", "2", "3", "4", "5");
}
#endif
switch (hwcb->response_code) {
case 0x0020:
retval = OUT_HWCB_CHAR;
release_write_hwcb ();
break;
case 0x0040:
case 0x0340:
case 0x40F0:
if (!hwc_data.read_statechange) {
hwcb->response_code = 0;
start_poll_hwc ();
}
retval = -EIO;
break;
default:
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"write_event_data_2 : "
"failed operation "
"(response code: 0x%x "
"HWCB address: 0x%x).\n",
hwcb->response_code,
hwcb);
retval = -EIO;
}
if (retval == -EIO) {
hwcb->control_mask[0] = 0;
hwcb->control_mask[1] = 0;
hwcb->control_mask[2] = 0;
hwcb->response_code = 0;
}
hwc_data.current_servc = 0;
hwc_data.current_hwcb = NULL;
if (hwc_data.flags & HWC_FLUSH)
flush_hwcbs ();
return retval;
}
static void
do_put_line (
unsigned char *message,
unsigned short count)
{
if (add_mto (message, count) != count) {
if (allocate_write_hwcb () < 0)
reuse_write_hwcb ();
#ifdef DUMP_HWC_WRITE_LIST_ERROR
if (add_mto (message, count) != count)
__asm__ ("LHI 1,0xe32\n\t"
"LRA 2,0(%0)\n\t"
"L 3,0(%1)\n\t"
"LRA 4,0(%2)\n\t"
"LRA 5,0(%3)\n\t"
"J .+0 \n\t"
:
: "a" (message), "a" (&hwc_data.kmem_pages),
"a" (BUF_HWCB), "a" (OUT_HWCB)
: "1", "2", "3", "4", "5");
#else
add_mto (message, count);
#endif
}
}
static void
put_line (
unsigned char *message,
unsigned short count)
{
if ((!hwc_data.obuf_start) && (hwc_data.flags & HWC_WTIMER_RUNS)) {
del_timer (&hwc_data.write_timer);
hwc_data.flags &= ~HWC_WTIMER_RUNS;
}
hwc_data.obuf_start += count;
do_put_line (message, count);
hwc_data.obuf_start -= count;
}
static void
set_alarm (void)
{
write_hwcb_t *hwcb;
if ((!BUF_HWCB) || (BUF_HWCB == hwc_data.current_hwcb))
allocate_write_hwcb ();
hwcb = (write_hwcb_t *) BUF_HWCB;
hwcb->msgbuf.mdb.mdb_body.go.general_msg_flags |= GMF_SndAlrm;
}
static void
hwc_write_timeout (unsigned long data)
{
unsigned long flags;
spin_lock_irqsave (&hwc_data.lock, flags);
hwc_data.obuf_start = hwc_data.obuf_count;
if (hwc_data.obuf_count)
put_line (hwc_data.obuf, hwc_data.obuf_count);
hwc_data.obuf_start = 0;
hwc_data.obuf_cursor = 0;
hwc_data.obuf_count = 0;
write_event_data_1 ();
spin_unlock_irqrestore (&hwc_data.lock, flags);
}
static int
do_hwc_write (
int from_user,
unsigned char *msg,
unsigned int count,
unsigned char write_time)
{
unsigned int i_msg = 0;
unsigned short int spaces = 0;
unsigned int processed_characters = 0;
unsigned char ch;
unsigned short int obuf_count;
unsigned short int obuf_cursor;
unsigned short int obuf_columns;
if (hwc_data.obuf_start) {
obuf_cursor = 0;
obuf_count = 0;
obuf_columns = MIN (hwc_data.ioctls.columns,
MAX_MESSAGE_SIZE - hwc_data.obuf_start);
} else {
obuf_cursor = hwc_data.obuf_cursor;
obuf_count = hwc_data.obuf_count;
obuf_columns = hwc_data.ioctls.columns;
}
for (i_msg = 0; i_msg < count; i_msg++) {
if (from_user)
get_user (ch, msg + i_msg);
else
ch = msg[i_msg];
processed_characters++;
if ((obuf_cursor == obuf_columns) &&
(ch != '\n') &&
(ch != '\t')) {
put_line (&hwc_data.obuf[hwc_data.obuf_start],
obuf_columns);
obuf_cursor = 0;
obuf_count = 0;
}
switch (ch) {
case '\n':
put_line (&hwc_data.obuf[hwc_data.obuf_start],
obuf_count);
obuf_cursor = 0;
obuf_count = 0;
break;
case '\a':
hwc_data.obuf_start += obuf_count;
set_alarm ();
hwc_data.obuf_start -= obuf_count;
break;
case '\t':
do {
if (obuf_cursor < obuf_columns) {
hwc_data.obuf[hwc_data.obuf_start +
obuf_cursor]
= HWC_ASCEBC (' ');
obuf_cursor++;
} else
break;
} while (obuf_cursor % hwc_data.ioctls.width_htab);
break;
case '\f':
case '\v':
spaces = obuf_cursor;
put_line (&hwc_data.obuf[hwc_data.obuf_start],
obuf_count);
obuf_count = obuf_cursor;
while (spaces) {
hwc_data.obuf[hwc_data.obuf_start +
obuf_cursor - spaces]
= HWC_ASCEBC (' ');
spaces--;
}
break;
case '\b':
if (obuf_cursor)
obuf_cursor--;
break;
case '\r':
obuf_cursor = 0;
break;
case 0x00:
put_line (&hwc_data.obuf[hwc_data.obuf_start],
obuf_count);
obuf_cursor = 0;
obuf_count = 0;
goto out;
default:
if (isprint (ch))
hwc_data.obuf[hwc_data.obuf_start +
obuf_cursor++]
= HWC_ASCEBC (ch);
}
if (obuf_cursor > obuf_count)
obuf_count = obuf_cursor;
}
if (obuf_cursor) {
if (hwc_data.obuf_start ||
(hwc_data.ioctls.final_nl == 0)) {
put_line (&hwc_data.obuf[hwc_data.obuf_start],
obuf_count);
obuf_cursor = 0;
obuf_count = 0;
} else {
if (hwc_data.ioctls.final_nl > 0) {
if (hwc_data.flags & HWC_WTIMER_RUNS) {
mod_timer (&hwc_data.write_timer,
jiffies + hwc_data.ioctls.final_nl * HZ / 10);
} else {
init_timer (&hwc_data.write_timer);
hwc_data.write_timer.function =
hwc_write_timeout;
hwc_data.write_timer.data =
(unsigned long) NULL;
hwc_data.write_timer.expires =
jiffies +
hwc_data.ioctls.final_nl * HZ / 10;
add_timer (&hwc_data.write_timer);
hwc_data.flags |= HWC_WTIMER_RUNS;
}
} else;
}
} else;
out:
if (!hwc_data.obuf_start) {
hwc_data.obuf_cursor = obuf_cursor;
hwc_data.obuf_count = obuf_count;
}
if (write_time == IMMEDIATE_WRITE)
write_event_data_1 ();
return processed_characters;
}
signed int
hwc_write (int from_user, const unsigned char *msg, unsigned int count)
{
unsigned long flags;
int retval;
spin_lock_irqsave (&hwc_data.lock, flags);
retval = do_hwc_write (from_user, (unsigned char *) msg,
count, IMMEDIATE_WRITE);
spin_unlock_irqrestore (&hwc_data.lock, flags);
return retval;
}
unsigned int
hwc_chars_in_buffer (unsigned char flag)
{
unsigned short int number = 0;
unsigned long flags;
spin_lock_irqsave (&hwc_data.lock, flags);
if (flag & IN_HWCB)
number += ALL_HWCB_CHAR;
if (flag & IN_WRITE_BUF)
number += hwc_data.obuf_cursor;
spin_unlock_irqrestore (&hwc_data.lock, flags);
return number;
}
static inline int
nr_setbits (kmem_pages_t arg)
{
int i;
int nr = 0;
for (i = 0; i < (sizeof (arg) << 3); i++) {
if (arg & 1)
nr++;
arg >>= 1;
}
return nr;
}
unsigned int
hwc_write_room (unsigned char flag)
{
unsigned int number = 0;
unsigned long flags;
write_hwcb_t *hwcb;
spin_lock_irqsave (&hwc_data.lock, flags);
if (flag & IN_HWCB) {
if (BUF_HWCB) {
hwcb = (write_hwcb_t *) BUF_HWCB;
number += MAX_HWCB_ROOM - hwcb->length;
}
number += (hwc_data.ioctls.kmem_hwcb -
nr_setbits (hwc_data.kmem_pages)) *
(MAX_HWCB_ROOM -
(sizeof (write_hwcb_t) + sizeof (mto_t)));
}
if (flag & IN_WRITE_BUF)
number += MAX_HWCB_ROOM - hwc_data.obuf_cursor;
spin_unlock_irqrestore (&hwc_data.lock, flags);
return number;
}
void
hwc_flush_buffer (unsigned char flag)
{
unsigned long flags;
spin_lock_irqsave (&hwc_data.lock, flags);
if (flag & IN_HWCB) {
if (hwc_data.current_servc != HWC_CMDW_WRITEDATA)
flush_hwcbs ();
else
hwc_data.flags |= HWC_FLUSH;
}
if (flag & IN_WRITE_BUF) {
hwc_data.obuf_cursor = 0;
hwc_data.obuf_count = 0;
}
spin_unlock_irqrestore (&hwc_data.lock, flags);
}
unsigned short int
seperate_cases (unsigned char *buf, unsigned short int count)
{
unsigned short int i_in;
unsigned short int i_out = 0;
unsigned char _case = 0;
for (i_in = 0; i_in < count; i_in++) {
if (buf[i_in] == hwc_data.ioctls.delim) {
if ((i_in + 1 < count) &&
(buf[i_in + 1] == hwc_data.ioctls.delim)) {
buf[i_out] = hwc_data.ioctls.delim;
i_out++;
i_in++;
} else
_case = ~_case;
} else {
if (_case) {
if (hwc_data.ioctls.tolower)
buf[i_out] = _ebc_toupper[buf[i_in]];
else
buf[i_out] = _ebc_tolower[buf[i_in]];
} else
buf[i_out] = buf[i_in];
i_out++;
}
}
return i_out;
}
#ifdef DUMP_HWCB_INPUT
static int
gds_vector_name (u16 id, unsigned char name[])
{
int retval = 0;
switch (id) {
case GDS_ID_MDSMU:
name = "Multiple Domain Support Message Unit";
break;
case GDS_ID_MDSRouteInfo:
name = "MDS Routing Information";
break;
case GDS_ID_AgUnWrkCorr:
name = "Agent Unit of Work Correlator";
break;
case GDS_ID_SNACondReport:
name = "SNA Condition Report";
break;
case GDS_ID_CPMSU:
name = "CP Management Services Unit";
break;
case GDS_ID_RoutTargInstr:
name = "Routing and Targeting Instructions";
break;
case GDS_ID_OpReq:
name = "Operate Request";
break;
case GDS_ID_TextCmd:
name = "Text Command";
break;
default:
name = "unknown GDS variable";
retval = -EINVAL;
}
return retval;
}
#endif
inline static gds_vector_t *
find_gds_vector (
gds_vector_t * start, void *end, u16 id)
{
gds_vector_t *vec;
gds_vector_t *retval = NULL;
vec = start;
while (((void *) vec) < end) {
if (vec->gds_id == id) {
#ifdef DUMP_HWCB_INPUT
int retval_name;
unsigned char name[64];
retval_name = gds_vector_name (id, name);
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"%s at 0x%x up to 0x%x, length: %d",
name,
(unsigned long) vec,
((unsigned long) vec) + vec->length - 1,
vec->length);
if (retval_name < 0)
internal_print (
IMMEDIATE_WRITE,
", id: 0x%x\n",
vec->gds_id);
else
internal_print (
IMMEDIATE_WRITE,
"\n");
#endif
retval = vec;
break;
}
vec = (gds_vector_t *) (((unsigned long) vec) + vec->length);
}
return retval;
}
inline static gds_subvector_t *
find_gds_subvector (
gds_subvector_t * start, void *end, u8 key)
{
gds_subvector_t *subvec;
gds_subvector_t *retval = NULL;
subvec = start;
while (((void *) subvec) < end) {
if (subvec->key == key) {
retval = subvec;
break;
}
subvec = (gds_subvector_t *)
(((unsigned long) subvec) + subvec->length);
}
return retval;
}
inline static int
get_input (void *start, void *end)
{
int count;
count = ((unsigned long) end) - ((unsigned long) start);
if (hwc_data.ioctls.tolower)
EBC_TOLOWER (start, count);
if (hwc_data.ioctls.delim)
count = seperate_cases (start, count);
HWC_EBCASC_STR (start, count);
if (hwc_data.ioctls.echo)
do_hwc_write (0, start, count, IMMEDIATE_WRITE);
if (hwc_data.calls != NULL)
if (hwc_data.calls->move_input != NULL)
(hwc_data.calls->move_input) (start, count);
return count;
}
inline static int
eval_selfdeftextmsg (gds_subvector_t * start, void *end)
{
gds_subvector_t *subvec;
void *subvec_data;
void *subvec_end;
int retval = 0;
subvec = start;
while (((void *) subvec) < end) {
subvec = find_gds_subvector (subvec, end, 0x30);
if (!subvec)
break;
subvec_data = (void *)
(((unsigned long) subvec) +
sizeof (gds_subvector_t));
subvec_end = (void *)
(((unsigned long) subvec) + subvec->length);
retval += get_input (subvec_data, subvec_end);
subvec = (gds_subvector_t *) subvec_end;
}
return retval;
}
inline static int
eval_textcmd (gds_subvector_t * start, void *end)
{
gds_subvector_t *subvec;
gds_subvector_t *subvec_data;
void *subvec_end;
int retval = 0;
subvec = start;
while (((void *) subvec) < end) {
subvec = find_gds_subvector (
subvec, end, GDS_KEY_SelfDefTextMsg);
if (!subvec)
break;
subvec_data = (gds_subvector_t *)
(((unsigned long) subvec) +
sizeof (gds_subvector_t));
subvec_end = (void *)
(((unsigned long) subvec) + subvec->length);
retval += eval_selfdeftextmsg (subvec_data, subvec_end);
subvec = (gds_subvector_t *) subvec_end;
}
return retval;
}
inline static int
eval_cpmsu (gds_vector_t * start, void *end)
{
gds_vector_t *vec;
gds_subvector_t *vec_data;
void *vec_end;
int retval = 0;
vec = start;
while (((void *) vec) < end) {
vec = find_gds_vector (vec, end, GDS_ID_TextCmd);
if (!vec)
break;
vec_data = (gds_subvector_t *)
(((unsigned long) vec) + sizeof (gds_vector_t));
vec_end = (void *) (((unsigned long) vec) + vec->length);
retval += eval_textcmd (vec_data, vec_end);
vec = (gds_vector_t *) vec_end;
}
return retval;
}
inline static int
eval_mdsmu (gds_vector_t * start, void *end)
{
gds_vector_t *vec;
gds_vector_t *vec_data;
void *vec_end;
int retval = 0;
vec = find_gds_vector (start, end, GDS_ID_CPMSU);
if (vec) {
vec_data = (gds_vector_t *)
(((unsigned long) vec) + sizeof (gds_vector_t));
vec_end = (void *) (((unsigned long) vec) + vec->length);
retval = eval_cpmsu (vec_data, vec_end);
}
return retval;
}
static int
eval_evbuf (gds_vector_t * start, void *end)
{
gds_vector_t *vec;
gds_vector_t *vec_data;
void *vec_end;
int retval = 0;
vec = find_gds_vector (start, end, GDS_ID_MDSMU);
if (vec) {
vec_data = (gds_vector_t *)
(((unsigned long) vec) + sizeof (gds_vector_t));
vec_end = (void *) (((unsigned long) vec) + vec->length);
retval = eval_mdsmu (vec_data, vec_end);
}
return retval;
}
static inline int
eval_hwc_receive_mask (_hwcb_mask_t mask)
{
hwc_data.write_nonprio
= ((mask & ET_Msg_Mask) == ET_Msg_Mask);
hwc_data.write_prio
= ((mask & ET_PMsgCmd_Mask) == ET_PMsgCmd_Mask);
if (hwc_data.write_prio || hwc_data.write_nonprio) {
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can write messages\n");
return 0;
} else {
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can not write messages\n");
return -1;
}
}
static inline int
eval_hwc_send_mask (_hwcb_mask_t mask)
{
hwc_data.read_statechange
= ((mask & ET_StateChange_Mask) == ET_StateChange_Mask);
if (hwc_data.read_statechange)
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can read state change notifications\n");
else
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can not read state change notifications\n");
hwc_data.read_nonprio
= ((mask & ET_OpCmd_Mask) == ET_OpCmd_Mask);
if (hwc_data.read_nonprio)
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can read commands\n");
hwc_data.read_prio
= ((mask & ET_PMsgCmd_Mask) == ET_PMsgCmd_Mask);
if (hwc_data.read_prio)
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can read priority commands\n");
if (hwc_data.read_prio || hwc_data.read_nonprio) {
return 0;
} else {
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"can not read commands from operator\n");
return -1;
}
}
static int
eval_statechangebuf (statechangebuf_t * scbuf)
{
int retval = 0;
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"HWC state change detected\n");
if (scbuf->validity_hwc_active_facility_mask) {
}
if (scbuf->validity_hwc_receive_mask) {
if (scbuf->mask_length != 4) {
#ifdef DUMP_HWC_INIT_ERROR
__asm__ ("LHI 1,0xe50\n\t"
"LRA 2,0(%0)\n\t"
"J .+0 \n\t"
:
: "a" (scbuf)
: "1", "2");
#endif
} else {
retval += eval_hwc_receive_mask
(scbuf->hwc_receive_mask);
}
}
if (scbuf->validity_hwc_send_mask) {
if (scbuf->mask_length != 4) {
#ifdef DUMP_HWC_INIT_ERROR
__asm__ ("LHI 1,0xe51\n\t"
"LRA 2,0(%0)\n\t"
"J .+0 \n\t"
:
: "a" (scbuf)
: "1", "2");
#endif
} else {
retval += eval_hwc_send_mask
(scbuf->hwc_send_mask);
}
}
if (scbuf->validity_read_data_function_mask) {
}
return retval;
}
static int
process_evbufs (void *start, void *end)
{
int retval = 0;
evbuf_t *evbuf;
void *evbuf_end;
gds_vector_t *evbuf_data;
evbuf = (evbuf_t *) start;
while (((void *) evbuf) < end) {
evbuf_data = (gds_vector_t *)
(((unsigned long) evbuf) + sizeof (evbuf_t));
evbuf_end = (void *) (((unsigned long) evbuf) + evbuf->length);
switch (evbuf->type) {
case ET_OpCmd:
case ET_CntlProgOpCmd:
case ET_PMsgCmd:
#ifdef DUMP_HWCB_INPUT
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"event buffer "
"at 0x%x up to 0x%x, length: %d\n",
(unsigned long) evbuf,
(unsigned long) (evbuf_end - 1),
evbuf->length);
dump_storage_area ((void *) evbuf, evbuf->length);
#endif
retval += eval_evbuf (evbuf_data, evbuf_end);
break;
case ET_StateChange:
retval += eval_statechangebuf
((statechangebuf_t *) evbuf);
break;
default:
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: "
"unknown event buffer found, "
"type 0x%x",
evbuf->type);
retval = -ENOSYS;
}
evbuf = (evbuf_t *) evbuf_end;
}
return retval;
}
static int
unconditional_read_1 (void)
{
unsigned short int condition_code;
read_hwcb_t *hwcb = (read_hwcb_t *) hwc_data.page;
int retval;
#if 0
if ((!hwc_data.read_prio) && (!hwc_data.read_nonprio))
return -EOPNOTSUPP;
if (hwc_data.current_servc)
return -EBUSY;
#endif
memset (hwcb, 0x00, PAGE_SIZE);
memcpy (hwcb, &read_hwcb_template, sizeof (read_hwcb_t));
condition_code = service_call (HWC_CMDW_READDATA, hwc_data.page);
#ifdef DUMP_HWC_READ_ERROR
if (condition_code == HWC_NOT_OPERATIONAL)
__asm__ ("LHI 1,0xe40\n\t"
"L 2,0(%0)\n\t"
"LRA 3,0(%1)\n\t"
"J .+0 \n\t"
:
: "a" (&condition_code), "a" (hwc_data.page)
: "1", "2", "3");
#endif
switch (condition_code) {
case HWC_COMMAND_INITIATED:
hwc_data.current_servc = HWC_CMDW_READDATA;
hwc_data.current_hwcb = hwc_data.page;
retval = condition_code;
break;
case HWC_BUSY:
retval = -EBUSY;
break;
default:
retval = -EIO;
}
return retval;
}
static int
unconditional_read_2 (void)
{
read_hwcb_t *hwcb = (read_hwcb_t *) hwc_data.page;
#ifdef DUMP_HWC_READ_ERROR
if ((hwcb->response_code != 0x0020) &&
(hwcb->response_code != 0x0220) &&
(hwcb->response_code != 0x60F0) &&
(hwcb->response_code != 0x62F0))
__asm__ ("LHI 1,0xe41\n\t"
"LRA 2,0(%0)\n\t"
"L 3,0(%1)\n\t"
"J .+0\n\t"
:
: "a" (hwc_data.page), "a" (&(hwcb->response_code))
: "1", "2", "3");
#endif
hwc_data.current_servc = 0;
hwc_data.current_hwcb = NULL;
switch (hwcb->response_code) {
case 0x0020:
case 0x0220:
return process_evbufs (
(void *) (((unsigned long) hwcb) + sizeof (read_hwcb_t)),
(void *) (((unsigned long) hwcb) + hwcb->length));
case 0x60F0:
case 0x62F0:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: "
"got interrupt and tried to read input, "
"but nothing found (response code=0x%x).\n",
hwcb->response_code);
return 0;
case 0x0100:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: HWCB boundary violation - this "
"must not occur in a correct driver, please contact "
"author\n");
return -EIO;
case 0x0300:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: "
"insufficient HWCB length - this must not occur in a "
"correct driver, please contact author\n");
return -EIO;
case 0x01F0:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: "
"invalid command - this must not occur in a correct "
"driver, please contact author\n");
return -EIO;
case 0x40F0:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: invalid function code\n");
return -EIO;
case 0x70F0:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: invalid selection mask\n");
return -EIO;
case 0x0040:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: HWC equipment check\n");
return -EIO;
default:
internal_print (
IMMEDIATE_WRITE,
HWC_RW_PRINT_HEADER
"unconditional read: invalid response code %x - this "
"must not occur in a correct driver, please contact "
"author\n",
hwcb->response_code);
return -EIO;
}
}
static int
write_event_mask_1 (void)
{
unsigned int condition_code;
int retval;
condition_code = service_call (HWC_CMDW_WRITEMASK, hwc_data.page);
#ifdef DUMP_HWC_INIT_ERROR
if (condition_code == HWC_NOT_OPERATIONAL)
__asm__ ("LHI 1,0xe10\n\t"
"L 2,0(%0)\n\t"
"LRA 3,0(%1)\n\t"
"J .+0\n\t"
:
: "a" (&condition_code), "a" (hwc_data.page)
: "1", "2", "3");
#endif
switch (condition_code) {
case HWC_COMMAND_INITIATED:
hwc_data.current_servc = HWC_CMDW_WRITEMASK;
hwc_data.current_hwcb = hwc_data.page;
retval = condition_code;
break;
case HWC_BUSY:
retval = -EBUSY;
break;
default:
retval = -EIO;
}
return retval;
}
static int
write_event_mask_2 (void)
{
init_hwcb_t *hwcb = (init_hwcb_t *) hwc_data.page;
int retval = 0;
if (hwcb->response_code != 0x0020) {
#ifdef DUMP_HWC_INIT_ERROR
__asm__ ("LHI 1,0xe11\n\t"
"LRA 2,0(%0)\n\t"
"L 3,0(%1)\n\t"
"J .+0\n\t"
:
: "a" (hwcb), "a" (&(hwcb->response_code))
: "1", "2", "3");
#else
retval = -1;
#endif
} else {
if (hwcb->mask_length != 4) {
#ifdef DUMP_HWC_INIT_ERROR
__asm__ ("LHI 1,0xe52\n\t"
"LRA 2,0(%0)\n\t"
"J .+0 \n\t"
:
: "a" (hwcb)
: "1", "2");
#endif
} else {
retval += eval_hwc_receive_mask
(hwcb->hwc_receive_mask);
retval += eval_hwc_send_mask (hwcb->hwc_send_mask);
}
}
hwc_data.current_servc = 0;
hwc_data.current_hwcb = NULL;
return retval;
}
static int
set_hwc_ioctls (hwc_ioctls_t * ioctls, char correct)
{
int retval = 0;
hwc_ioctls_t tmp;
if (ioctls->width_htab > MAX_MESSAGE_SIZE) {
if (correct)
tmp.width_htab = MAX_MESSAGE_SIZE;
else
retval = -EINVAL;
} else
tmp.width_htab = ioctls->width_htab;
tmp.echo = ioctls->echo;
if (ioctls->columns > MAX_MESSAGE_SIZE) {
if (correct)
tmp.columns = MAX_MESSAGE_SIZE;
else
retval = -EINVAL;
} else
tmp.columns = ioctls->columns;
tmp.final_nl = ioctls->final_nl;
if (ioctls->max_hwcb < 2) {
if (correct)
tmp.max_hwcb = 2;
else
retval = -EINVAL;
} else
tmp.max_hwcb = ioctls->max_hwcb;
tmp.tolower = ioctls->tolower;
if (ioctls->kmem_hwcb > ioctls->max_hwcb) {
if (correct)
tmp.kmem_hwcb = ioctls->max_hwcb;
else
retval = -EINVAL;
} else
tmp.kmem_hwcb = ioctls->kmem_hwcb;
if (ioctls->kmem_hwcb > MAX_KMEM_PAGES) {
if (correct)
ioctls->kmem_hwcb = MAX_KMEM_PAGES;
else
retval = -EINVAL;
}
if (ioctls->kmem_hwcb < 2) {
if (correct)
ioctls->kmem_hwcb = 2;
else
retval = -EINVAL;
}
tmp.delim = ioctls->delim;
tmp.measured_lines = ioctls->measured_lines;
tmp.measured_chars = ioctls->measured_chars;
tmp.measured_wcalls = ioctls->measured_wcalls;
if (!(retval < 0))
hwc_data.ioctls = tmp;
return retval;
}
int
do_hwc_init (void)
{
int retval;
memcpy (hwc_data.page, &init_hwcb_template, sizeof (init_hwcb_t));
do {
retval = write_event_mask_1 ();
if (retval == -EBUSY) {
hwc_data.flags |= HWC_INIT;
asm volatile ("STCTL 0,0,%0":"=m" (cr0));
cr0_save = cr0;
cr0 |= 0x00000200;
cr0 &= 0xFFFFF3AC;
asm volatile ("LCTL 0,0,%0"::"m" (cr0):"memory");
asm volatile ("STOSM %0,0x01"
:"=m" (psw_mask)::"memory");
while (!(hwc_data.flags & HWC_INTERRUPT))
barrier ();
asm volatile ("STNSM %0,0xFE"
:"=m" (psw_mask)::"memory");
asm volatile ("LCTL 0,0,%0"
::"m" (cr0_save):"memory");
hwc_data.flags &= ~HWC_INIT;
}
} while (retval == -EBUSY);
if (retval == -EIO) {
hwc_data.flags |= HWC_BROKEN;
printk (HWC_RW_PRINT_HEADER "HWC not operational\n");
}
return retval;
}
void do_hwc_interrupt (struct pt_regs *regs, __u16 code);
int
hwc_init (unsigned long *kmem_start)
{
int retval;
#ifdef BUFFER_STRESS_TEST
init_hwcb_t *hwcb;
int i;
#endif
if (register_external_interrupt (0x2401, do_hwc_interrupt) != 0)
panic ("Couldn't request external interrupts 0x2401");
spin_lock_init (&hwc_data.lock);
#ifdef USE_VM_DETECTION
if (MACHINE_IS_VM) {
if (hwc_data.init_ioctls.columns > 76)
hwc_data.init_ioctls.columns = 76;
hwc_data.init_ioctls.tolower = 1;
if (!hwc_data.init_ioctls.delim)
hwc_data.init_ioctls.delim = DEFAULT_CASE_DELIMITER;
} else {
hwc_data.init_ioctls.tolower = 0;
hwc_data.init_ioctls.delim = 0;
}
#endif
retval = set_hwc_ioctls (&hwc_data.init_ioctls, 1);
*kmem_start = (*kmem_start + PAGE_SIZE - 1) & -4096L;
hwc_data.kmem_start = *kmem_start;
*kmem_start += hwc_data.ioctls.kmem_hwcb * PAGE_SIZE;
hwc_data.kmem_end = *kmem_start - 1;
retval = do_hwc_init ();
ctl_set_bit (0, 9);
#ifdef BUFFER_STRESS_TEST
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"use %i bytes for buffering.\n",
hwc_data.ioctls.kmem_hwcb * PAGE_SIZE);
for (i = 0; i < 2000; i++) {
hwcb = (init_hwcb_t *) BUF_HWCB;
internal_print (
DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"This is stress test message #%i, free: %i bytes\n",
i,
MAX_HWCB_ROOM - (hwcb->length + sizeof (mto_t)));
}
#endif
return /*retval */ 0;
}
signed int
hwc_register_calls (hwc_high_level_calls_t * calls)
{
if (calls == NULL)
return -EINVAL;
if (hwc_data.calls != NULL)
return -EBUSY;
hwc_data.calls = calls;
return 0;
}
signed int
hwc_unregister_calls (hwc_high_level_calls_t * calls)
{
if (hwc_data.calls == NULL)
return -EINVAL;
if (calls != hwc_data.calls)
return -EINVAL;
hwc_data.calls = NULL;
return 0;
}
void
do_hwc_interrupt (struct pt_regs *regs, __u16 code)
{
if (hwc_data.flags & HWC_INIT) {
hwc_data.flags |= HWC_INTERRUPT;
} else if (hwc_data.flags & HWC_BROKEN) {
if (!do_hwc_init ()) {
hwc_data.flags &= ~HWC_BROKEN;
internal_print (DELAYED_WRITE,
HWC_RW_PRINT_HEADER
"delayed HWC setup after"
" temporary breakdown\n");
}
} else {
spin_lock (&hwc_data.lock);
if (hwc_data.flags & HWC_PTIMER_RUNS) {
del_timer (&hwc_data.poll_timer);
hwc_data.flags &= ~HWC_PTIMER_RUNS;
}
if (!hwc_data.current_servc) {
unconditional_read_1 ();
} else {
switch (hwc_data.current_servc) {
case HWC_CMDW_WRITEMASK:
write_event_mask_2 ();
break;
case HWC_CMDW_WRITEDATA:
write_event_data_2 ();
break;
case HWC_CMDW_READDATA:
unconditional_read_2 ();
break;
}
write_event_data_1 ();
}
if (hwc_data.calls != NULL)
if (hwc_data.calls->wake_up != NULL)
(hwc_data.calls->wake_up) ();
spin_unlock (&hwc_data.lock);
}
}
void
hwc_unblank (void)
{
spin_lock (&hwc_data.lock);
spin_unlock (&hwc_data.lock);
asm volatile ("STCTL 0,0,%0":"=m" (cr0));
cr0_save = cr0;
cr0 |= 0x00000200;
cr0 &= 0xFFFFF3AC;
asm volatile ("LCTL 0,0,%0"::"m" (cr0):"memory");
asm volatile ("STOSM %0,0x01":"=m" (psw_mask)::"memory");
while (ALL_HWCB_CHAR)
barrier ();
asm volatile ("STNSM %0,0xFE":"=m" (psw_mask)::"memory");
asm volatile ("LCTL 0,0,%0"::"m" (cr0_save):"memory");
}
int
hwc_ioctl (unsigned int cmd, unsigned long arg)
{
hwc_ioctls_t tmp = hwc_data.ioctls;
int retval = 0;
unsigned long flags;
unsigned int obuf;
spin_lock_irqsave (&hwc_data.lock, flags);
switch (cmd) {
case TIOCHWCSMEAS:
hwc_data.ioctls.measured_lines = 0;
hwc_data.ioctls.measured_chars = 0;
hwc_data.ioctls.measured_wcalls = 0;
break;
case TIOCHWCSHTAB:
if (get_user (tmp.width_htab, (ioctl_htab_t *) arg))
goto fault;
break;
case TIOCHWCSECHO:
if (get_user (tmp.echo, (ioctl_echo_t *) arg))
goto fault;
break;
case TIOCHWCSCOLS:
if (get_user (tmp.columns, (ioctl_cols_t *) arg))
goto fault;
break;
case TIOCHWCSNL:
if (get_user (tmp.final_nl, (ioctl_nl_t *) arg))
goto fault;
break;
case TIOCHWCSOBUF:
if (get_user (obuf, (unsigned int *) arg))
goto fault;
if (obuf & 0xFFF)
tmp.max_hwcb = (((obuf | 0xFFF) + 1) >> 12);
else
tmp.max_hwcb = (obuf >> 12);
break;
case TIOCHWCSCASE:
if (get_user (tmp.tolower, (ioctl_case_t *) arg))
goto fault;
break;
case TIOCHWCSDELIM:
if (get_user (tmp.delim, (ioctl_delim_t *) arg))
goto fault;
break;
case TIOCHWCSINIT:
retval = set_hwc_ioctls (&hwc_data.init_ioctls, 1);
break;
case TIOCHWCGMEASL:
if (put_user (tmp.measured_lines, (ioctl_meas_t *) arg))
goto fault;
break;
case TIOCHWCGMEASC:
if (put_user (tmp.measured_chars, (ioctl_meas_t *) arg))
goto fault;
break;
case TIOCHWCGMEASS:
if (put_user (tmp.measured_wcalls, (ioctl_meas_t *) arg))
goto fault;
break;
case TIOCHWCGHTAB:
if (put_user (tmp.width_htab, (ioctl_htab_t *) arg))
goto fault;
break;
case TIOCHWCGECHO:
if (put_user (tmp.echo, (ioctl_echo_t *) arg))
goto fault;
break;
case TIOCHWCGCOLS:
if (put_user (tmp.columns, (ioctl_cols_t *) arg))
goto fault;
break;
case TIOCHWCGNL:
if (put_user (tmp.final_nl, (ioctl_nl_t *) arg))
goto fault;
break;
case TIOCHWCGOBUF:
if (put_user (tmp.max_hwcb, (ioctl_obuf_t *) arg))
goto fault;
break;
case TIOCHWCGKBUF:
if (put_user (tmp.kmem_hwcb, (ioctl_obuf_t *) arg))
goto fault;
break;
case TIOCHWCGCASE:
if (put_user (tmp.tolower, (ioctl_case_t *) arg))
goto fault;
break;
case TIOCHWCGDELIM:
if (put_user (tmp.delim, (ioctl_delim_t *) arg))
goto fault;
break;
#if 0
case TIOCHWCGINIT:
if (put_user (&hwc_data.init_ioctls, (hwc_ioctls_t *) arg))
goto fault;
break;
case TIOCHWCGCURR:
if (put_user (&hwc_data.ioctls, (hwc_ioctls_t *) arg))
goto fault;
break;
#endif
default:
goto noioctlcmd;
}
if (_IOC_DIR (cmd) == _IOC_WRITE)
retval = set_hwc_ioctls (&tmp, 0);
goto out;
fault:
retval = -EFAULT;
goto out;
noioctlcmd:
retval = -ENOIOCTLCMD;
out:
spin_unlock_irqrestore (&hwc_data.lock, flags);
return retval;
}
|