Loading...
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 | /**
* @file memain.c
*
* @brief Main Meilhaus device driver.
* @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
* @author Guenter Gebhardt
* @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
*/
/*
* Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include <linux/module.h>
#include <linux/pci.h>
//#include <linux/usb.h>
#include <linux/errno.h>
#include <linux/uaccess.h>
#include <linux/cdev.h>
#include <linux/rwsem.h>
#include "medefines.h"
#include "metypes.h"
#include "meerror.h"
#include "medebug.h"
#include "memain.h"
#include "medevice.h"
#include "meioctl.h"
#include "mecommon.h"
/* Module parameters
*/
#ifdef BOSCH
static unsigned int me_bosch_fw = 0;
EXPORT_SYMBOL(me_bosch_fw);
# ifdef module_param
module_param(me_bosch_fw, int, S_IRUGO);
# else
MODULE_PARM(me_bosch_fw, "i");
# endif
MODULE_PARM_DESC(me_bosch_fw,
"Flags which signals the ME-4600 driver to load the bosch firmware (default = 0).");
#endif //BOSCH
static unsigned int major = 0;
#ifdef module_param
module_param(major, int, S_IRUGO);
#else
MODULE_PARM(major, "i");
#endif
/* Global Driver Lock
*/
static struct file *me_filep = NULL;
static int me_count = 0;
static DEFINE_SPINLOCK(me_lock);
static DECLARE_RWSEM(me_rwsem);
/* Board instances are kept in a global list */
LIST_HEAD(me_device_list);
/* Prototypes
*/
static int me_probe_pci(struct pci_dev *dev, const struct pci_device_id *id);
static void me_remove_pci(struct pci_dev *dev);
static int insert_to_device_list(me_device_t *n_device);
static int replace_with_dummy(int vendor_id, int device_id, int serial_no);
static void clear_device_list(void);
static int me_open(struct inode *inode_ptr, struct file *filep);
static int me_release(struct inode *, struct file *);
static int me_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
//static int me_probe_usb(struct usb_interface *interface, const struct usb_device_id *id);
//static void me_disconnect_usb(struct usb_interface *interface);
/* Character device structure
*/
static struct cdev *cdevp;
/* File operations provided by the module
*/
static struct file_operations me_file_operations = {
.owner = THIS_MODULE,
.ioctl = me_ioctl,
.open = me_open,
.release = me_release,
};
struct pci_driver me_pci_driver = {
.name = MEMAIN_NAME,
.id_table = me_pci_table,
.probe = me_probe_pci,
.remove = me_remove_pci
};
/* //me_usb_driver
static struct usb_driver me_usb_driver =
{
.name = MEMAIN_NAME,
.id_table = me_usb_table,
.probe = me_probe_usb,
.disconnect = me_disconnect_usb
};
*/
#ifdef ME_LOCK_MULTIPLEX_TEMPLATE
ME_LOCK_MULTIPLEX_TEMPLATE("me_lock_device",
me_lock_device_t,
me_lock_device,
me_device_lock_device,
(device, filep, karg.lock, karg.flags))
ME_LOCK_MULTIPLEX_TEMPLATE("me_lock_subdevice",
me_lock_subdevice_t,
me_lock_subdevice,
me_device_lock_subdevice,
(device, filep, karg.subdevice, karg.lock,
karg.flags))
#else
#error macro ME_LOCK_MULTIPLEX_TEMPLATE not defined
#endif
#ifdef ME_IO_MULTIPLEX_TEMPLATE
ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_start",
me_io_irq_start_t,
me_io_irq_start,
me_device_io_irq_start,
(device,
filep,
karg.subdevice,
karg.channel,
karg.irq_source,
karg.irq_edge, karg.irq_arg, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_wait",
me_io_irq_wait_t,
me_io_irq_wait,
me_device_io_irq_wait,
(device,
filep,
karg.subdevice,
karg.channel,
&karg.irq_count, &karg.value, karg.time_out, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_irq_stop",
me_io_irq_stop_t,
me_io_irq_stop,
me_device_io_irq_stop,
(device,
filep, karg.subdevice, karg.channel, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_reset_device",
me_io_reset_device_t,
me_io_reset_device,
me_device_io_reset_device, (device, filep, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_reset_subdevice",
me_io_reset_subdevice_t,
me_io_reset_subdevice,
me_device_io_reset_subdevice,
(device, filep, karg.subdevice, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_single_config",
me_io_single_config_t,
me_io_single_config,
me_device_io_single_config,
(device,
filep,
karg.subdevice,
karg.channel,
karg.single_config,
karg.ref,
karg.trig_chan,
karg.trig_type, karg.trig_edge, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_new_values",
me_io_stream_new_values_t,
me_io_stream_new_values,
me_device_io_stream_new_values,
(device,
filep,
karg.subdevice, karg.time_out, &karg.count, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_read",
me_io_stream_read_t,
me_io_stream_read,
me_device_io_stream_read,
(device,
filep,
karg.subdevice,
karg.read_mode, karg.values, &karg.count, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_status",
me_io_stream_status_t,
me_io_stream_status,
me_device_io_stream_status,
(device,
filep,
karg.subdevice,
karg.wait, &karg.status, &karg.count, karg.flags))
ME_IO_MULTIPLEX_TEMPLATE("me_io_stream_write",
me_io_stream_write_t,
me_io_stream_write,
me_device_io_stream_write,
(device,
filep,
karg.subdevice,
karg.write_mode, karg.values, &karg.count, karg.flags))
#else
#error macro ME_IO_MULTIPLEX_TEMPLATE not defined
#endif
#ifdef ME_QUERY_MULTIPLEX_STR_TEMPLATE
ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_name_device",
me_query_name_device_t,
me_query_name_device,
me_device_query_name_device, (device, &msg))
ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_name_device_driver",
me_query_name_device_driver_t,
me_query_name_device_driver,
me_device_query_name_device_driver,
(device, &msg))
ME_QUERY_MULTIPLEX_STR_TEMPLATE("me_query_description_device",
me_query_description_device_t,
me_query_description_device,
me_device_query_description_device,
(device, &msg))
#else
#error macro ME_QUERY_MULTIPLEX_STR_TEMPLATE not defined
#endif
#ifdef ME_QUERY_MULTIPLEX_TEMPLATE
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_info_device",
me_query_info_device_t,
me_query_info_device,
me_device_query_info_device,
(device,
&karg.vendor_id,
&karg.device_id,
&karg.serial_no,
&karg.bus_type,
&karg.bus_no,
&karg.dev_no, &karg.func_no, &karg.plugged))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_subdevices",
me_query_number_subdevices_t,
me_query_number_subdevices,
me_device_query_number_subdevices,
(device, &karg.number))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_channels",
me_query_number_channels_t,
me_query_number_channels,
me_device_query_number_channels,
(device, karg.subdevice, &karg.number))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_by_type",
me_query_subdevice_by_type_t,
me_query_subdevice_by_type,
me_device_query_subdevice_by_type,
(device,
karg.start_subdevice,
karg.type, karg.subtype, &karg.subdevice))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_type",
me_query_subdevice_type_t,
me_query_subdevice_type,
me_device_query_subdevice_type,
(device, karg.subdevice, &karg.type, &karg.subtype))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_caps",
me_query_subdevice_caps_t,
me_query_subdevice_caps,
me_device_query_subdevice_caps,
(device, karg.subdevice, &karg.caps))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_subdevice_caps_args",
me_query_subdevice_caps_args_t,
me_query_subdevice_caps_args,
me_device_query_subdevice_caps_args,
(device, karg.subdevice, karg.cap, karg.args,
karg.count))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_number_ranges",
me_query_number_ranges_t,
me_query_number_ranges,
me_device_query_number_ranges,
(device, karg.subdevice, karg.unit, &karg.number))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_range_by_min_max",
me_query_range_by_min_max_t,
me_query_range_by_min_max,
me_device_query_range_by_min_max,
(device,
karg.subdevice,
karg.unit,
&karg.min, &karg.max, &karg.max_data, &karg.range))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_range_info",
me_query_range_info_t,
me_query_range_info,
me_device_query_range_info,
(device,
karg.subdevice,
karg.range,
&karg.unit, &karg.min, &karg.max, &karg.max_data))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_timer",
me_query_timer_t,
me_query_timer,
me_device_query_timer,
(device,
karg.subdevice,
karg.timer,
&karg.base_frequency,
&karg.min_ticks, &karg.max_ticks))
ME_QUERY_MULTIPLEX_TEMPLATE("me_query_version_device_driver",
me_query_version_device_driver_t,
me_query_version_device_driver,
me_device_query_version_device_driver,
(device, &karg.version))
#else
#error macro ME_QUERY_MULTIPLEX_TEMPLATE not defined
#endif
/** ******************************************************************************** **/
static me_device_t *get_dummy_instance(unsigned short vendor_id,
unsigned short device_id,
unsigned int serial_no,
int bus_type,
int bus_no, int dev_no, int func_no)
{
int err;
me_dummy_constructor_t constructor = NULL;
me_device_t *instance;
PDEBUG("executed.\n");
if ((constructor = symbol_get(medummy_constructor)) == NULL) {
err = request_module(MEDUMMY_NAME);
if (err) {
PERROR("Error while request for module %s.\n",
MEDUMMY_NAME);
return NULL;
}
if ((constructor = symbol_get(medummy_constructor)) == NULL) {
PERROR("Can't get %s driver module constructor.\n",
MEDUMMY_NAME);
return NULL;
}
}
if ((instance = (*constructor) (vendor_id,
device_id,
serial_no,
bus_type,
bus_no, dev_no, func_no)) == NULL)
symbol_put(medummy_constructor);
return instance;
}
static int me_probe_pci(struct pci_dev *dev, const struct pci_device_id *id)
{
int err;
me_pci_constructor_t constructor = NULL;
#ifdef BOSCH
me_bosch_constructor_t constructor_bosch = NULL;
#endif
me_device_t *n_device = NULL;
uint32_t device;
char constructor_name[24] = "me0000_pci_constructor";
char module_name[7] = "me0000";
PDEBUG("executed.\n");
device = dev->device;
if ((device & 0xF000) == 0x6000) { // Exceptions: me61xx, me62xx, me63xx are handled by one driver.
device &= 0xF0FF;
}
constructor_name[2] += (char)((device >> 12) & 0x000F);
constructor_name[3] += (char)((device >> 8) & 0x000F);
PDEBUG("constructor_name: %s\n", constructor_name);
module_name[2] += (char)((device >> 12) & 0x000F);
module_name[3] += (char)((device >> 8) & 0x000F);
PDEBUG("module_name: %s\n", module_name);
if ((constructor =
(me_pci_constructor_t) symbol_get(constructor_name)) == NULL) {
if (request_module(module_name)) {
PERROR("Error while request for module %s.\n",
module_name);
return -ENODEV;
}
if ((constructor =
(me_pci_constructor_t) symbol_get(constructor_name)) ==
NULL) {
PERROR("Can't get %s driver module constructor.\n",
module_name);
return -ENODEV;
}
}
#ifdef BOSCH
if ((device & 0xF000) == 0x4000) { // Bosch build has differnt constructor for me4600.
if ((n_device =
(*constructor_bosch) (dev, me_bosch_fw)) == NULL) {
symbol_put(constructor_name);
PERROR
("Can't get device instance of %s driver module.\n",
module_name);
return -ENODEV;
}
} else {
#endif
if ((n_device = (*constructor) (dev)) == NULL) {
symbol_put(constructor_name);
PERROR
("Can't get device instance of %s driver module.\n",
module_name);
return -ENODEV;
}
#ifdef BOSCH
}
#endif
insert_to_device_list(n_device);
err =
n_device->me_device_io_reset_device(n_device, NULL,
ME_IO_RESET_DEVICE_NO_FLAGS);
if (err) {
PERROR("Error while reseting device.\n");
} else {
PDEBUG("Reseting device was sucessful.\n");
}
return ME_ERRNO_SUCCESS;
}
static void release_instance(me_device_t *device)
{
int vendor_id;
int device_id;
int serial_no;
int bus_type;
int bus_no;
int dev_no;
int func_no;
int plugged;
uint32_t dev_id;
char constructor_name[24] = "me0000_pci_constructor";
PDEBUG("executed.\n");
device->me_device_query_info_device(device,
&vendor_id,
&device_id,
&serial_no,
&bus_type,
&bus_no,
&dev_no, &func_no, &plugged);
dev_id = device_id;
device->me_device_destructor(device);
if (plugged != ME_PLUGGED_IN) {
PDEBUG("release: medummy_constructor\n");
symbol_put("medummy_constructor");
} else {
if ((dev_id & 0xF000) == 0x6000) { // Exceptions: me61xx, me62xx, me63xx are handled by one driver.
dev_id &= 0xF0FF;
}
constructor_name[2] += (char)((dev_id >> 12) & 0x000F);
constructor_name[3] += (char)((dev_id >> 8) & 0x000F);
PDEBUG("release: %s\n", constructor_name);
symbol_put(constructor_name);
}
}
static int insert_to_device_list(me_device_t *n_device)
{
me_device_t *o_device = NULL;
struct list_head *pos;
int n_vendor_id;
int n_device_id;
int n_serial_no;
int n_bus_type;
int n_bus_no;
int n_dev_no;
int n_func_no;
int n_plugged;
int o_vendor_id;
int o_device_id;
int o_serial_no;
int o_bus_type;
int o_bus_no;
int o_dev_no;
int o_func_no;
int o_plugged;
PDEBUG("executed.\n");
n_device->me_device_query_info_device(n_device,
&n_vendor_id,
&n_device_id,
&n_serial_no,
&n_bus_type,
&n_bus_no,
&n_dev_no,
&n_func_no, &n_plugged);
down_write(&me_rwsem);
list_for_each(pos, &me_device_list) {
o_device = list_entry(pos, me_device_t, list);
o_device->me_device_query_info_device(o_device,
&o_vendor_id,
&o_device_id,
&o_serial_no,
&o_bus_type,
&o_bus_no,
&o_dev_no,
&o_func_no, &o_plugged);
if (o_plugged == ME_PLUGGED_OUT) {
if (((o_vendor_id == n_vendor_id) &&
(o_device_id == n_device_id) &&
(o_serial_no == n_serial_no) &&
(o_bus_type == n_bus_type)) ||
((o_vendor_id == n_vendor_id) &&
(o_device_id == n_device_id) &&
(o_bus_type == n_bus_type) &&
(o_bus_no == n_bus_no) &&
(o_dev_no == n_dev_no) &&
(o_func_no == n_func_no))) {
n_device->list.prev = pos->prev;
n_device->list.next = pos->next;
pos->prev->next = &n_device->list;
pos->next->prev = &n_device->list;
release_instance(o_device);
break;
}
}
}
if (pos == &me_device_list) {
list_add_tail(&n_device->list, &me_device_list);
}
up_write(&me_rwsem);
return 0;
}
static void me_remove_pci(struct pci_dev *dev)
{
int vendor_id = dev->vendor;
int device_id = dev->device;
int subsystem_vendor = dev->subsystem_vendor;
int subsystem_device = dev->subsystem_device;
int serial_no = (subsystem_device << 16) | subsystem_vendor;
PDEBUG("executed.\n");
PINFO("Vendor id = 0x%08X\n", vendor_id);
PINFO("Device id = 0x%08X\n", device_id);
PINFO("Serial Number = 0x%08X\n", serial_no);
replace_with_dummy(vendor_id, device_id, serial_no);
}
static int replace_with_dummy(int vendor_id, int device_id, int serial_no)
{
struct list_head *pos;
me_device_t *n_device = NULL;
me_device_t *o_device = NULL;
int o_vendor_id;
int o_device_id;
int o_serial_no;
int o_bus_type;
int o_bus_no;
int o_dev_no;
int o_func_no;
int o_plugged;
PDEBUG("executed.\n");
down_write(&me_rwsem);
list_for_each(pos, &me_device_list) {
o_device = list_entry(pos, me_device_t, list);
o_device->me_device_query_info_device(o_device,
&o_vendor_id,
&o_device_id,
&o_serial_no,
&o_bus_type,
&o_bus_no,
&o_dev_no,
&o_func_no, &o_plugged);
if (o_plugged == ME_PLUGGED_IN) {
if (((o_vendor_id == vendor_id) &&
(o_device_id == device_id) &&
(o_serial_no == serial_no))) {
n_device = get_dummy_instance(o_vendor_id,
o_device_id,
o_serial_no,
o_bus_type,
o_bus_no,
o_dev_no,
o_func_no);
if (!n_device) {
up_write(&me_rwsem);
PERROR("Cannot get dummy instance.\n");
return 1;
}
n_device->list.prev = pos->prev;
n_device->list.next = pos->next;
pos->prev->next = &n_device->list;
pos->next->prev = &n_device->list;
release_instance(o_device);
break;
}
}
}
up_write(&me_rwsem);
return 0;
}
static void clear_device_list(void)
{
struct list_head *entry;
me_device_t *device;
// Clear the device info list .
down_write(&me_rwsem);
while (!list_empty(&me_device_list)) {
entry = me_device_list.next;
device = list_entry(entry, me_device_t, list);
list_del(entry);
release_instance(device);
}
up_write(&me_rwsem);
}
static int lock_driver(struct file *filep, int lock, int flags)
{
int err = ME_ERRNO_SUCCESS;
me_device_t *device;
PDEBUG("executed.\n");
down_read(&me_rwsem);
spin_lock(&me_lock);
switch (lock) {
case ME_LOCK_SET:
if (me_count) {
PERROR
("Driver System is currently used by another process.\n");
err = ME_ERRNO_USED;
} else if ((me_filep != NULL) && (me_filep != filep)) {
PERROR
("Driver System is already logged by another process.\n");
err = ME_ERRNO_LOCKED;
} else {
list_for_each_entry(device, &me_device_list, list) {
err =
device->me_device_lock_device(device, filep,
ME_LOCK_CHECK,
flags);
if (err)
break;
}
if (!err)
me_filep = filep;
}
break;
case ME_LOCK_RELEASE:
if ((me_filep != NULL) && (me_filep != filep)) {
err = ME_ERRNO_SUCCESS;
} else {
list_for_each_entry(device, &me_device_list, list) {
device->me_device_lock_device(device, filep,
ME_LOCK_RELEASE,
flags);
}
me_filep = NULL;
}
break;
default:
PERROR("Invalid lock specified.\n");
err = ME_ERRNO_INVALID_LOCK;
break;
}
spin_unlock(&me_lock);
up_read(&me_rwsem);
return err;
}
static int me_lock_driver(struct file *filep, me_lock_driver_t *arg)
{
int err = 0;
me_lock_driver_t lock;
PDEBUG("executed.\n");
err = copy_from_user(&lock, arg, sizeof(me_lock_driver_t));
if (err) {
PERROR("Can't copy arguments to kernel space.\n");
return -EFAULT;
}
lock.errno = lock_driver(filep, lock.lock, lock.flags);
err = copy_to_user(arg, &lock, sizeof(me_lock_driver_t));
if (err) {
PERROR("Can't copy query back to user space.\n");
return -EFAULT;
}
return ME_ERRNO_SUCCESS;
}
static int me_open(struct inode *inode_ptr, struct file *filep)
{
PDEBUG("executed.\n");
// Nothing to do here.
return 0;
}
static int me_release(struct inode *inode_ptr, struct file *filep)
{
PDEBUG("executed.\n");
lock_driver(filep, ME_LOCK_RELEASE, ME_LOCK_DRIVER_NO_FLAGS);
return 0;
}
static int me_query_version_main_driver(struct file *filep,
me_query_version_main_driver_t *arg)
{
int err;
me_query_version_main_driver_t karg;
PDEBUG("executed.\n");
karg.version = ME_VERSION_DRIVER;
karg.errno = ME_ERRNO_SUCCESS;
err = copy_to_user(arg, &karg, sizeof(me_query_version_main_driver_t));
if (err) {
PERROR("Can't copy query back to user space.\n");
return -EFAULT;
}
return 0;
}
static int me_config_load_device(struct file *filep,
me_cfg_device_entry_t *karg, int device_no)
{
int err = ME_ERRNO_SUCCESS;
int k = 0;
struct list_head *pos = NULL;
me_device_t *device = NULL;
PDEBUG("executed.\n");
list_for_each(pos, &me_device_list) {
if (k == device_no) {
device = list_entry(pos, me_device_t, list);
break;
}
k++;
}
if (pos == &me_device_list) {
PERROR("Invalid device number specified.\n");
return ME_ERRNO_INVALID_DEVICE;
} else {
spin_lock(&me_lock);
if ((me_filep != NULL) && (me_filep != filep)) {
spin_unlock(&me_lock);
PERROR("Resource is locked by another process.\n");
return ME_ERRNO_LOCKED;
} else {
me_count++;
spin_unlock(&me_lock);
err =
device->me_device_config_load(device, filep, karg);
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
}
}
return err;
}
static int me_config_load(struct file *filep, me_config_load_t *arg)
{
int err;
int i;
me_config_load_t cfg_setup;
me_config_load_t karg_cfg_setup;
struct list_head *pos = NULL;
struct list_head new_list;
me_device_t *o_device;
me_device_t *n_device;
int o_vendor_id;
int o_device_id;
int o_serial_no;
int o_bus_type;
int o_bus_no;
int o_dev_no;
int o_func_no;
int o_plugged;
PDEBUG("executed.\n");
// Copy argument to kernel space.
err = copy_from_user(&karg_cfg_setup, arg, sizeof(me_config_load_t));
if (err) {
PERROR("Can't copy arguments to kernel space.\n");
return -EFAULT;
}
// Allocate kernel buffer for device list.
cfg_setup.device_list =
kmalloc(sizeof(me_cfg_device_entry_t) * karg_cfg_setup.count,
GFP_KERNEL);
if (!cfg_setup.device_list) {
PERROR("Can't get buffer %li for device list.\n",
sizeof(me_cfg_device_entry_t) * karg_cfg_setup.count);
return -ENOMEM;
}
// Copy device list to kernel space.
err =
copy_from_user(cfg_setup.device_list, karg_cfg_setup.device_list,
sizeof(me_cfg_device_entry_t) *
karg_cfg_setup.count);
if (err) {
PERROR("Can't copy device list to kernel space.\n");
kfree(cfg_setup.device_list);
return -EFAULT;
}
cfg_setup.count = karg_cfg_setup.count;
INIT_LIST_HEAD(&new_list);
down_write(&me_rwsem);
spin_lock(&me_lock);
if ((me_filep != NULL) && (me_filep != filep)) {
spin_unlock(&me_lock);
PERROR("Driver System is logged by another process.\n");
karg_cfg_setup.errno = ME_ERRNO_LOCKED;
} else {
me_count++;
spin_unlock(&me_lock);
for (i = 0; i < karg_cfg_setup.count; i++) {
PDEBUG("me_config_load() device=%d.\n", i);
if (cfg_setup.device_list[i].tcpip.access_type ==
ME_ACCESS_TYPE_LOCAL) {
list_for_each(pos, &me_device_list) {
o_device =
list_entry(pos, me_device_t, list);
o_device->
me_device_query_info_device
(o_device, &o_vendor_id,
&o_device_id, &o_serial_no,
&o_bus_type, &o_bus_no, &o_dev_no,
&o_func_no, &o_plugged);
if (cfg_setup.device_list[i].info.
hw_location.bus_type ==
ME_BUS_TYPE_PCI) {
if (((o_vendor_id ==
cfg_setup.device_list[i].
info.vendor_id)
&& (o_device_id ==
cfg_setup.
device_list[i].info.
device_id)
&& (o_serial_no ==
cfg_setup.
device_list[i].info.
serial_no)
&& (o_bus_type ==
cfg_setup.
device_list[i].info.
hw_location.bus_type))
||
((o_vendor_id ==
cfg_setup.device_list[i].
info.vendor_id)
&& (o_device_id ==
cfg_setup.
device_list[i].info.
device_id)
&& (o_bus_type ==
cfg_setup.
device_list[i].info.
hw_location.bus_type)
&& (o_bus_no ==
cfg_setup.
device_list[i].info.
hw_location.pci.bus_no)
&& (o_dev_no ==
cfg_setup.
device_list[i].info.
hw_location.pci.
device_no)
&& (o_func_no ==
cfg_setup.
device_list[i].info.
hw_location.pci.
function_no))) {
list_move_tail(pos,
&new_list);
break;
}
}
/*
else if (cfg_setup.device_list[i].info.hw_location.bus_type == ME_BUS_TYPE_USB)
{
if (((o_vendor_id == cfg_setup.device_list[i].info.vendor_id) &&
(o_device_id == cfg_setup.device_list[i].info.device_id) &&
(o_serial_no == cfg_setup.device_list[i].info.serial_no) &&
(o_bus_type == cfg_setup.device_list[i].info.hw_location.bus_type)) ||
((o_vendor_id == cfg_setup.device_list[i].info.vendor_id) &&
(o_device_id == cfg_setup.device_list[i].info.device_id) &&
(o_bus_type == cfg_setup.device_list[i].info.hw_location.bus_type) &&
(o_bus_no == cfg_setup.device_list[i].info.hw_location.usb.root_hub_no)))
{
list_move_tail(pos, &new_list);
break;
}
}
*/
else {
PERROR("Wrong bus type: %d.\n",
cfg_setup.device_list[i].
info.hw_location.
bus_type);
}
}
if (pos == &me_device_list) { // Device is not already in the list
if (cfg_setup.device_list[i].info.
hw_location.bus_type ==
ME_BUS_TYPE_PCI) {
n_device =
get_dummy_instance
(cfg_setup.device_list[i].
info.vendor_id,
cfg_setup.device_list[i].
info.device_id,
cfg_setup.device_list[i].
info.serial_no,
cfg_setup.device_list[i].
info.hw_location.bus_type,
cfg_setup.device_list[i].
info.hw_location.pci.
bus_no,
cfg_setup.device_list[i].
info.hw_location.pci.
device_no,
cfg_setup.device_list[i].
info.hw_location.pci.
function_no);
if (!n_device) {
PERROR
("Can't get dummy instance.\n");
kfree(cfg_setup.
device_list);
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
up_write(&me_rwsem);
return -EFAULT;
}
list_add_tail(&n_device->list,
&new_list);
}
/*
else if (cfg_setup.device_list[i].info.hw_location.bus_type == ME_BUS_TYPE_USB)
{
n_device = get_dummy_instance(
cfg_setup.device_list[i].info.vendor_id,
cfg_setup.device_list[i].info.device_id,
cfg_setup.device_list[i].info.serial_no,
cfg_setup.device_list[i].info.hw_location.bus_type,
cfg_setup.device_list[i].info.hw_location.usb.root_hub_no,
0,
0);
if (!n_device)
{
PERROR("Can't get dummy instance.\n");
kfree(cfg_setup.device_list);
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
up_write(&me_rwsem);
return -EFAULT;
}
list_add_tail(&n_device->list, &new_list);
}
*/
}
} else {
n_device = get_dummy_instance(0,
0, 0, 0, 0, 0, 0);
if (!n_device) {
PERROR("Can't get dummy instance.\n");
kfree(cfg_setup.device_list);
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
up_write(&me_rwsem);
return -EFAULT;
}
list_add_tail(&n_device->list, &new_list);
}
}
while (!list_empty(&me_device_list)) {
o_device =
list_entry(me_device_list.next, me_device_t, list);
o_device->me_device_query_info_device(o_device,
&o_vendor_id,
&o_device_id,
&o_serial_no,
&o_bus_type,
&o_bus_no,
&o_dev_no,
&o_func_no,
&o_plugged);
if (o_plugged == ME_PLUGGED_IN) {
list_move_tail(me_device_list.next, &new_list);
} else {
list_del(me_device_list.next);
release_instance(o_device);
}
}
// Move temporary new list to global driver list.
list_splice(&new_list, &me_device_list);
karg_cfg_setup.errno = ME_ERRNO_SUCCESS;
}
for (i = 0; i < cfg_setup.count; i++) {
karg_cfg_setup.errno =
me_config_load_device(filep, &cfg_setup.device_list[i], i);
if (karg_cfg_setup.errno) {
PERROR("me_config_load_device(%d)=%d\n", i,
karg_cfg_setup.errno);
break;
}
}
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
up_write(&me_rwsem);
err = copy_to_user(arg, &karg_cfg_setup, sizeof(me_config_load_t));
if (err) {
PERROR("Can't copy config list to user space.\n");
kfree(cfg_setup.device_list);
return -EFAULT;
}
kfree(cfg_setup.device_list);
return 0;
}
static int me_io_stream_start(struct file *filep, me_io_stream_start_t *arg)
{
int err;
int i, k;
struct list_head *pos;
me_device_t *device;
me_io_stream_start_t karg;
meIOStreamStart_t *list;
PDEBUG("executed.\n");
err = copy_from_user(&karg, arg, sizeof(me_io_stream_start_t));
if (err) {
PERROR("Can't copy arguments to kernel space.\n");
return -EFAULT;
}
karg.errno = ME_ERRNO_SUCCESS;
list = kmalloc(sizeof(meIOStreamStart_t) * karg.count, GFP_KERNEL);
if (!list) {
PERROR("Can't get buffer for start list.\n");
return -ENOMEM;
}
err =
copy_from_user(list, karg.start_list,
sizeof(meIOStreamStart_t) * karg.count);
if (err) {
PERROR("Can't copy start list to kernel space.\n");
kfree(list);
return -EFAULT;
}
spin_lock(&me_lock);
if ((me_filep != NULL) && (me_filep != filep)) {
spin_unlock(&me_lock);
PERROR("Driver System is logged by another process.\n");
for (i = 0; i < karg.count; i++) {
list[i].iErrno = ME_ERRNO_LOCKED;
}
} else {
me_count++;
spin_unlock(&me_lock);
for (i = 0; i < karg.count; i++) {
down_read(&me_rwsem);
k = 0;
list_for_each(pos, &me_device_list) {
if (k == list[i].iDevice) {
device =
list_entry(pos, me_device_t, list);
break;
}
k++;
}
if (pos == &me_device_list) {
up_read(&me_rwsem);
PERROR("Invalid device number specified.\n");
list[i].iErrno = ME_ERRNO_INVALID_DEVICE;
karg.errno = ME_ERRNO_INVALID_DEVICE;
break;
} else {
list[i].iErrno =
device->me_device_io_stream_start(device,
filep,
list[i].
iSubdevice,
list[i].
iStartMode,
list[i].
iTimeOut,
list[i].
iFlags);
if (list[i].iErrno) {
up_read(&me_rwsem);
karg.errno = list[i].iErrno;
break;
}
}
up_read(&me_rwsem);
}
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
}
err = copy_to_user(arg, &karg, sizeof(me_io_stream_start_t));
if (err) {
PERROR("Can't copy arguments to user space.\n");
kfree(list);
return -EFAULT;
}
err =
copy_to_user(karg.start_list, list,
sizeof(meIOStreamStart_t) * karg.count);
if (err) {
PERROR("Can't copy start list to user space.\n");
kfree(list);
return -EFAULT;
}
kfree(list);
return err;
}
static int me_io_single(struct file *filep, me_io_single_t *arg)
{
int err;
int i, k;
struct list_head *pos;
me_device_t *device;
me_io_single_t karg;
meIOSingle_t *list;
PDEBUG("executed.\n");
err = copy_from_user(&karg, arg, sizeof(me_io_single_t));
if (err) {
PERROR("Can't copy arguments to kernel space.\n");
return -EFAULT;
}
karg.errno = ME_ERRNO_SUCCESS;
list = kmalloc(sizeof(meIOSingle_t) * karg.count, GFP_KERNEL);
if (!list) {
PERROR("Can't get buffer for single list.\n");
return -ENOMEM;
}
err =
copy_from_user(list, karg.single_list,
sizeof(meIOSingle_t) * karg.count);
if (err) {
PERROR("Can't copy single list to kernel space.\n");
kfree(list);
return -EFAULT;
}
spin_lock(&me_lock);
if ((me_filep != NULL) && (me_filep != filep)) {
spin_unlock(&me_lock);
PERROR("Driver System is logged by another process.\n");
for (i = 0; i < karg.count; i++) {
list[i].iErrno = ME_ERRNO_LOCKED;
}
} else {
me_count++;
spin_unlock(&me_lock);
for (i = 0; i < karg.count; i++) {
k = 0;
down_read(&me_rwsem);
list_for_each(pos, &me_device_list) {
if (k == list[i].iDevice) {
device =
list_entry(pos, me_device_t, list);
break;
}
k++;
}
if (pos == &me_device_list) {
up_read(&me_rwsem);
PERROR("Invalid device number specified.\n");
list[i].iErrno = ME_ERRNO_INVALID_DEVICE;
karg.errno = ME_ERRNO_INVALID_DEVICE;
break;
} else {
if (list[i].iDir == ME_DIR_OUTPUT) {
list[i].iErrno =
device->
me_device_io_single_write(device,
filep,
list[i].
iSubdevice,
list[i].
iChannel,
list[i].
iValue,
list[i].
iTimeOut,
list[i].
iFlags);
if (list[i].iErrno) {
up_read(&me_rwsem);
karg.errno = list[i].iErrno;
break;
}
} else if (list[i].iDir == ME_DIR_INPUT) {
list[i].iErrno =
device->
me_device_io_single_read(device,
filep,
list[i].
iSubdevice,
list[i].
iChannel,
&list[i].
iValue,
list[i].
iTimeOut,
list[i].
iFlags);
if (list[i].iErrno) {
up_read(&me_rwsem);
karg.errno = list[i].iErrno;
break;
}
} else {
up_read(&me_rwsem);
PERROR
("Invalid single direction specified.\n");
list[i].iErrno = ME_ERRNO_INVALID_DIR;
karg.errno = ME_ERRNO_INVALID_DIR;
break;
}
}
up_read(&me_rwsem);
}
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
}
err = copy_to_user(arg, &karg, sizeof(me_io_single_t));
if (err) {
PERROR("Can't copy arguments to user space.\n");
return -EFAULT;
}
err =
copy_to_user(karg.single_list, list,
sizeof(meIOSingle_t) * karg.count);
if (err) {
PERROR("Can't copy single list to user space.\n");
kfree(list);
return -EFAULT;
}
kfree(list);
return err;
}
static int me_io_stream_config(struct file *filep, me_io_stream_config_t *arg)
{
int err;
int k = 0;
struct list_head *pos;
me_device_t *device;
me_io_stream_config_t karg;
meIOStreamConfig_t *list;
PDEBUG("executed.\n");
err = copy_from_user(&karg, arg, sizeof(me_io_stream_config_t));
if (err) {
PERROR("Can't copy arguments to kernel space.\n");
return -EFAULT;
}
list = kmalloc(sizeof(meIOStreamConfig_t) * karg.count, GFP_KERNEL);
if (!list) {
PERROR("Can't get buffer for config list.\n");
return -ENOMEM;
}
err =
copy_from_user(list, karg.config_list,
sizeof(meIOStreamConfig_t) * karg.count);
if (err) {
PERROR("Can't copy config list to kernel space.\n");
kfree(list);
return -EFAULT;
}
spin_lock(&me_lock);
if ((me_filep != NULL) && (me_filep != filep)) {
spin_unlock(&me_lock);
PERROR("Driver System is logged by another process.\n");
karg.errno = ME_ERRNO_LOCKED;
} else {
me_count++;
spin_unlock(&me_lock);
down_read(&me_rwsem);
list_for_each(pos, &me_device_list) {
if (k == karg.device) {
device = list_entry(pos, me_device_t, list);
break;
}
k++;
}
if (pos == &me_device_list) {
PERROR("Invalid device number specified.\n");
karg.errno = ME_ERRNO_INVALID_DEVICE;
} else {
karg.errno =
device->me_device_io_stream_config(device, filep,
karg.subdevice,
list, karg.count,
&karg.trigger,
karg.
fifo_irq_threshold,
karg.flags);
}
up_read(&me_rwsem);
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
}
err = copy_to_user(arg, &karg, sizeof(me_io_stream_config_t));
if (err) {
PERROR("Can't copy back to user space.\n");
kfree(list);
return -EFAULT;
}
kfree(list);
return err;
}
static int me_query_number_devices(struct file *filep,
me_query_number_devices_t *arg)
{
int err;
me_query_number_devices_t karg;
struct list_head *pos;
PDEBUG("executed.\n");
karg.number = 0;
down_read(&me_rwsem);
list_for_each(pos, &me_device_list) {
karg.number++;
}
up_read(&me_rwsem);
karg.errno = ME_ERRNO_SUCCESS;
err = copy_to_user(arg, &karg, sizeof(me_query_number_devices_t));
if (err) {
PERROR("Can't copy query back to user space.\n");
return -EFAULT;
}
return 0;
}
static int me_io_stream_stop(struct file *filep, me_io_stream_stop_t *arg)
{
int err;
int i, k;
struct list_head *pos;
me_device_t *device;
me_io_stream_stop_t karg;
meIOStreamStop_t *list;
PDEBUG("executed.\n");
err = copy_from_user(&karg, arg, sizeof(me_io_stream_stop_t));
if (err) {
PERROR("Can't copy arguments to kernel space.\n");
return -EFAULT;
}
karg.errno = ME_ERRNO_SUCCESS;
list = kmalloc(sizeof(meIOStreamStop_t) * karg.count, GFP_KERNEL);
if (!list) {
PERROR("Can't get buffer for stop list.\n");
return -ENOMEM;
}
err =
copy_from_user(list, karg.stop_list,
sizeof(meIOStreamStop_t) * karg.count);
if (err) {
PERROR("Can't copy stop list to kernel space.\n");
kfree(list);
return -EFAULT;
}
spin_lock(&me_lock);
if ((me_filep != NULL) && (me_filep != filep)) {
spin_unlock(&me_lock);
PERROR("Driver System is logged by another process.\n");
for (i = 0; i < karg.count; i++) {
list[i].iErrno = ME_ERRNO_LOCKED;
}
} else {
me_count++;
spin_unlock(&me_lock);
for (i = 0; i < karg.count; i++) {
k = 0;
down_read(&me_rwsem);
list_for_each(pos, &me_device_list) {
if (k == list[i].iDevice) {
device =
list_entry(pos, me_device_t, list);
break;
}
k++;
}
if (pos == &me_device_list) {
up_read(&me_rwsem);
PERROR("Invalid device number specified.\n");
list[i].iErrno = ME_ERRNO_INVALID_DEVICE;
karg.errno = ME_ERRNO_INVALID_DEVICE;
break;
} else {
list[i].iErrno =
device->me_device_io_stream_stop(device,
filep,
list[i].
iSubdevice,
list[i].
iStopMode,
list[i].
iFlags);
if (list[i].iErrno) {
up_read(&me_rwsem);
karg.errno = list[i].iErrno;
break;
}
}
up_read(&me_rwsem);
}
spin_lock(&me_lock);
me_count--;
spin_unlock(&me_lock);
}
err = copy_to_user(arg, &karg, sizeof(me_io_stream_stop_t));
if (err) {
PERROR("Can't copy arguments to user space.\n");
return -EFAULT;
}
err =
copy_to_user(karg.stop_list, list,
sizeof(meIOStreamStop_t) * karg.count);
if (err) {
PERROR("Can't copy stop list to user space.\n");
kfree(list);
return -EFAULT;
}
kfree(list);
return err;
}
/* //me_probe_usb
static int me_probe_usb(struct usb_interface *interface, const struct usb_device_id *id)
{
//int err;
//me_usb_constructor_t *constructor = NULL;
me_device_t *n_device = NULL;
PDEBUG("executed.\n");
switch (id->idProduct)
{
case USB_DEVICE_ID_MEPHISTO_S1:
if((constructor = symbol_get(mephisto_s1_constructor)) == NULL){
err = request_module(MEPHISTO_S1_NAME);
if(err){
PERROR("Error while request for module %s.\n", MEPHISTO_S1_NAME);
return -ENODEV;
}
if((constructor = symbol_get(mephisto_s1_constructor)) == NULL){
PERROR("Can't get %s driver module constructor.\n", MEPHISTO_S1_NAME);
return -ENODEV;
}
}
if((n_device = (*constructor)(interface)) == NULL){
symbol_put(mephisto_s1_constructor);
PERROR("Can't get device instance of %s driver module.\n", MEPHISTO_S1_NAME);
return -ENODEV;
}
break;
default:
PERROR("Invalid product id.\n");
return -EINVAL;
}
return insert_to_device_list(n_device);
}
*/
/* //me_disconnect_usb
static void me_disconnect_usb(struct usb_interface *interface)
{
struct usb_device *device = interface_to_usbdev(interface);
int vendor_id = device->descriptor.idVendor;
int device_id = device->descriptor.idProduct;
int serial_no;
sscanf(&device->serial[2], "%x", &serial_no);
PDEBUG("executed.\n");
PINFO("Vendor id = 0x%08X\n", vendor_id);
PINFO("Device id = 0x%08X\n", device_id);
PINFO("Serial Number = 0x%08X\n", serial_no);
replace_with_dummy(vendor_id, device_id, serial_no);
}
*/
static int me_ioctl(struct inode *inodep,
struct file *filep, unsigned int service, unsigned long arg)
{
PDEBUG("executed.\n");
if (_IOC_TYPE(service) != MEMAIN_MAGIC) {
PERROR("Invalid magic number.\n");
return -ENOTTY;
}
PDEBUG("service number: 0x%x.\n", service);
switch (service) {
case ME_IO_IRQ_ENABLE:
return me_io_irq_start(filep, (me_io_irq_start_t *) arg);
case ME_IO_IRQ_WAIT:
return me_io_irq_wait(filep, (me_io_irq_wait_t *) arg);
case ME_IO_IRQ_DISABLE:
return me_io_irq_stop(filep, (me_io_irq_stop_t *) arg);
case ME_IO_RESET_DEVICE:
return me_io_reset_device(filep, (me_io_reset_device_t *) arg);
case ME_IO_RESET_SUBDEVICE:
return me_io_reset_subdevice(filep,
(me_io_reset_subdevice_t *) arg);
case ME_IO_SINGLE_CONFIG:
return me_io_single_config(filep,
(me_io_single_config_t *) arg);
case ME_IO_SINGLE:
return me_io_single(filep, (me_io_single_t *) arg);
case ME_IO_STREAM_CONFIG:
return me_io_stream_config(filep,
(me_io_stream_config_t *) arg);
case ME_IO_STREAM_NEW_VALUES:
return me_io_stream_new_values(filep,
(me_io_stream_new_values_t *)
arg);
case ME_IO_STREAM_READ:
return me_io_stream_read(filep, (me_io_stream_read_t *) arg);
case ME_IO_STREAM_START:
return me_io_stream_start(filep, (me_io_stream_start_t *) arg);
case ME_IO_STREAM_STATUS:
return me_io_stream_status(filep,
(me_io_stream_status_t *) arg);
case ME_IO_STREAM_STOP:
return me_io_stream_stop(filep, (me_io_stream_stop_t *) arg);
case ME_IO_STREAM_WRITE:
return me_io_stream_write(filep, (me_io_stream_write_t *) arg);
case ME_LOCK_DRIVER:
return me_lock_driver(filep, (me_lock_driver_t *) arg);
case ME_LOCK_DEVICE:
return me_lock_device(filep, (me_lock_device_t *) arg);
case ME_LOCK_SUBDEVICE:
return me_lock_subdevice(filep, (me_lock_subdevice_t *) arg);
case ME_QUERY_INFO_DEVICE:
return me_query_info_device(filep,
(me_query_info_device_t *) arg);
case ME_QUERY_DESCRIPTION_DEVICE:
return me_query_description_device(filep,
(me_query_description_device_t
*) arg);
case ME_QUERY_NAME_DEVICE:
return me_query_name_device(filep,
(me_query_name_device_t *) arg);
case ME_QUERY_NAME_DEVICE_DRIVER:
return me_query_name_device_driver(filep,
(me_query_name_device_driver_t
*) arg);
case ME_QUERY_NUMBER_DEVICES:
return me_query_number_devices(filep,
(me_query_number_devices_t *)
arg);
case ME_QUERY_NUMBER_SUBDEVICES:
return me_query_number_subdevices(filep,
(me_query_number_subdevices_t
*) arg);
case ME_QUERY_NUMBER_CHANNELS:
return me_query_number_channels(filep,
(me_query_number_channels_t *)
arg);
case ME_QUERY_NUMBER_RANGES:
return me_query_number_ranges(filep,
(me_query_number_ranges_t *) arg);
case ME_QUERY_RANGE_BY_MIN_MAX:
return me_query_range_by_min_max(filep,
(me_query_range_by_min_max_t *)
arg);
case ME_QUERY_RANGE_INFO:
return me_query_range_info(filep,
(me_query_range_info_t *) arg);
case ME_QUERY_SUBDEVICE_BY_TYPE:
return me_query_subdevice_by_type(filep,
(me_query_subdevice_by_type_t
*) arg);
case ME_QUERY_SUBDEVICE_TYPE:
return me_query_subdevice_type(filep,
(me_query_subdevice_type_t *)
arg);
case ME_QUERY_SUBDEVICE_CAPS:
return me_query_subdevice_caps(filep,
(me_query_subdevice_caps_t *)
arg);
case ME_QUERY_SUBDEVICE_CAPS_ARGS:
return me_query_subdevice_caps_args(filep,
(me_query_subdevice_caps_args_t
*) arg);
case ME_QUERY_TIMER:
return me_query_timer(filep, (me_query_timer_t *) arg);
case ME_QUERY_VERSION_MAIN_DRIVER:
return me_query_version_main_driver(filep,
(me_query_version_main_driver_t
*) arg);
case ME_QUERY_VERSION_DEVICE_DRIVER:
return me_query_version_device_driver(filep,
(me_query_version_device_driver_t
*) arg);
case ME_CONFIG_LOAD:
return me_config_load(filep, (me_config_load_t *) arg);
}
PERROR("Invalid ioctl number.\n");
return -ENOTTY;
}
// Init and exit of module.
static int memain_init(void)
{
int result = 0;
dev_t dev = MKDEV(major, 0);
PDEBUG("executed.\n");
// Register pci driver. This will return 0 if the PCI subsystem is not available.
result = pci_register_driver(&me_pci_driver);
if (result < 0) {
PERROR("Can't register pci driver.\n");
goto INIT_ERROR_1;
}
/*
// Register usb driver. This will return -ENODEV if no USB subsystem is available.
result = usb_register(&me_usb_driver);
if (result)
{
if (result == -ENODEV)
{
PERROR("No USB subsystem available.\n");
}
else
{
PERROR("Can't register usb driver.\n");
goto INIT_ERROR_2;
}
}
*/
// Register the character device.
if (major) {
result = register_chrdev_region(dev, 1, MEMAIN_NAME);
} else {
result = alloc_chrdev_region(&dev, 0, 1, MEMAIN_NAME);
major = MAJOR(dev);
}
if (result < 0) {
PERROR("Can't get major driver no.\n");
goto INIT_ERROR_3;
}
cdevp = cdev_alloc();
if (!cdevp) {
PERROR("Can't get character device structure.\n");
result = -ENOMEM;
goto INIT_ERROR_4;
}
cdevp->ops = &me_file_operations;
cdevp->owner = THIS_MODULE;
result = cdev_add(cdevp, dev, 1);
if (result < 0) {
PERROR("Cannot add character device structure.\n");
goto INIT_ERROR_5;
}
return 0;
INIT_ERROR_5:
cdev_del(cdevp);
INIT_ERROR_4:
unregister_chrdev_region(dev, 1);
INIT_ERROR_3:
// usb_deregister(&me_usb_driver);
//INIT_ERROR_2:
pci_unregister_driver(&me_pci_driver);
clear_device_list();
INIT_ERROR_1:
return result;
}
static void __exit memain_exit(void)
{
dev_t dev = MKDEV(major, 0);
PDEBUG("executed.\n");
cdev_del(cdevp);
unregister_chrdev_region(dev, 1);
pci_unregister_driver(&me_pci_driver);
// usb_deregister(&me_usb_driver);
clear_device_list();
}
module_init(memain_init);
module_exit(memain_exit);
// Administrative stuff for modinfo.
MODULE_AUTHOR
("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
MODULE_DESCRIPTION("Central module for Meilhaus Driver System.");
MODULE_SUPPORTED_DEVICE("Meilhaus PCI/cPCI boards.");
MODULE_LICENSE("GPL");
|