Line data Source code
1 : // This file (devl.cc) was created by Ron Rechenmacher <ron@fnal.gov> on
2 : // Apr 23, 2014. "TERMS AND CONDITIONS" governing this file are in the README
3 : // or COPYING file. If you do not have such a file, one can be obtained by
4 : // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
5 : // $RCSfile: .emacs.gnu,v $
6 : // rev="$Revision: 1.23 $$Date: 2012/01/23 15:32:40 $";
7 :
8 : #include <getopt.h> /* getopt */
9 : #include <stdint.h> // uint64_t
10 : #include <stdio.h> // printf
11 : #include <stdlib.h> // setenv
12 : #include <unistd.h> /* getopt */
13 :
14 : #include "pcidevl_ioctl.h"
15 : #include "trace.h" // TRACE
16 :
17 : #define USAGE \
18 : "\
19 : usage: %s <devnum> <cmd>\n\
20 : <devnum> should be 0-9, corresponding to an entry in /dev/pcidev*\n\
21 : <cmd> is one of:\n\
22 : hello - TRACE hello\n\
23 : register - pci_register_driver, if necessary\n\
24 : unregister - iounmap, pci_unregister_driver\n\
25 : ioremap - \n\
26 : iounmap - \n\
27 : uint32 <offset> - \n\
28 : read_loop - \n\
29 : ", \
30 : basename(argv[0])
31 :
32 0 : int main(int argc, char *argv[])
33 : {
34 : int sts;
35 : extern int optind; /* for getopt */
36 : const char *cmd;
37 : char devfile[13]; /* /dev/pcidevX */
38 :
39 0 : if (argc == 1)
40 : {
41 0 : printf(USAGE);
42 0 : return (0);
43 : }
44 0 : setenv("TRACE_FILE", "/proc/trace/buffer", 0); // allow user to set in env.
45 0 : setenv("TRACE_LVLS", "0xff", 0); // levels 0,1,2 but no-overwrite -- allow user to set in env.
46 0 : TRACE_CNTL("lvlmskS", (uint64_t)0xff);
47 0 : TRACE_CNTL("modeS", (uint64_t)1);
48 :
49 0 : snprintf(devfile, 13, "/dev/" PCIDEVL_DEV_FILE, atoi(argv[1]));
50 :
51 0 : int fd = open(devfile, O_RDONLY);
52 0 : if (fd == -1)
53 : {
54 0 : perror("open");
55 0 : return (1);
56 : }
57 :
58 0 : optind = 2;
59 0 : cmd = argv[optind++];
60 :
61 0 : if (strcmp(cmd, "hello") == 0)
62 : {
63 0 : TRACE(2, "hello");
64 0 : sts = ioctl(fd, IOC_HELLO);
65 0 : if (sts == -1)
66 : {
67 0 : perror("ioctl HELLO");
68 0 : return (1);
69 : }
70 : }
71 0 : else if (strcmp(cmd, "ioremap") == 0)
72 : {
73 0 : TRACE(2, "ioremap");
74 0 : sts = ioctl(fd, IOC_IOREMAP);
75 0 : if (sts == -1)
76 : {
77 0 : perror("ioctl IOREMAP");
78 0 : return (1);
79 : }
80 : }
81 0 : else if (strcmp(cmd, "iounmap") == 0)
82 : {
83 0 : TRACE(2, "iounmap");
84 0 : sts = ioctl(fd, IOC_IOUNMAP);
85 0 : if (sts == -1)
86 : {
87 0 : perror("ioctl IOUNMAP");
88 0 : return (1);
89 : }
90 : }
91 0 : else if (strcmp(cmd, "uint32") == 0)
92 : {
93 0 : if ((argc - optind) < 1)
94 : {
95 0 : printf("cmd \"uint32\" needs an arg (offset)\n");
96 0 : return (1);
97 : }
98 0 : TRACE(2, "uint32");
99 0 : uint32_t in_out = strtoul(argv[optind], NULL, 0);
100 0 : sts = ioctl(fd, IOC_UINT32, &in_out);
101 0 : if (sts == -1)
102 : {
103 0 : perror("ioctl UINT32");
104 0 : return (1);
105 : }
106 0 : TRACE(2, "val at off=0x%08x", in_out);
107 : }
108 : else
109 : {
110 0 : TRACE(0, "invalid cmd");
111 : }
112 0 : return (0);
113 : } // main
|