Lynx framebuffers multidomain implementation.
[linux/elbrus.git] / drivers / mcst / msps / msps_test.c
blob337675c307aa5b31b581f136776a8a1f27faef28
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <unistd.h>
7 #include <errno.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <sys/ioctl.h>
12 #include <sys/mman.h>
14 #include <linux/mcst/msps_io.h>
15 #include <linux/mcst/mcst_selftest.h>
17 #include <sys/time.h>
19 #define myprintf(fmt, args...) printf("* msps_test:\t" fmt, ## args)
21 #define DEV_NAME "/dev/msps0"
23 u_long *dma[2];
24 char dev_name[1024] = DEV_NAME;
25 int instance = 0;
26 int selftest_flag = 0;
27 int active_work = 0;
28 int data_size = 64; /* bytes */
29 int write_flag = 0;
30 int testmode_flag = 0; /* plug at PLIS 1 -> 0, 3 -> 2, 5 -> 4 */
31 int nothing_flag = 0;
33 static time_t test_time = 60;
34 static time_t print_time = 5;
36 void print_first_dma()
38 myprintf("first dma bytes: 0x%lx 0x%lx\n",
39 *(dma[0] + 0), *(dma[1] + 0));
40 myprintf("second dma bytes: 0x%lx 0x%lx\n",
41 *(dma[0] + 1), *(dma[1] + 1));
45 static void
46 test_opt(int ac, char **av)
48 int i;
49 while ((i = getopt(ac, av, "?hnTi:t:Ss:p:aA:")) != EOF) {
50 switch (i) {
51 case 'i':
52 instance = atol(optarg);
53 if (instance == 1 || instance == 3 || instance == 5)
54 write_flag = 1;
55 sprintf(dev_name, "/dev/msps%d", instance);
56 break;
57 case 'a':
58 active_work = 1;
59 break;
60 case 'A':
61 active_work = atol(optarg);
62 if (active_work < 0)
63 active_work = 0;
64 break;
65 case 'd': /* temporary off */
66 sprintf(dev_name, "%s", optarg);
67 break;
68 case 't':
69 test_time = atol(optarg);
70 if (test_time < 0)
71 test_time = 0;
72 break;
73 case 'T':
74 testmode_flag = 1;
75 break;
76 case 'S':
77 selftest_flag = 1;
78 break;
79 case 's':
80 data_size = atol(optarg);
81 if (data_size <= 0)
82 data_size = 1;
83 break;
84 case 'p':
85 print_time = atol(optarg);
86 break;
87 case 'n':
88 nothing_flag = 1;
89 break;
90 case '?':
91 case 'h':
92 printf("Parameters:\n"
93 "\t[-d path to device (temporary off)]\n"
94 "\t[-i instance number/dev/msps?]\n"
95 "\t[-t test time]\n"
96 "\t[-s size data]\n"
97 "\t[-S run internal test]\n"
98 "\t[-p period output print]\n"
99 "\t[-T test exchange mode]\n"
100 "\t[-n do nothing, only open/close (-S working)]\n"
101 "\t[-a active wait on cpu (not interrupt) 10 microsec]\n"
102 "\t[-A active wait on cpu - arg - time waiting]\n");
103 exit(0);
104 break;
109 int main(int ac, char **av)
112 int fd, res;
113 msps_status_t status;
114 msps_setup_a_t activetask;
115 msps_setup_t *task = &activetask.s;
116 int i;
117 u_long mask = 0;
119 test_opt(ac, av);
121 fd = open(dev_name, O_RDWR);
122 if (fd == -1) {
123 myprintf("Cant open device (%s): %s\n",
124 dev_name, strerror(errno));
125 return -1;
128 if (selftest_flag) {
129 selftest_t test;
131 res = ioctl(fd, MCST_SELFTEST_MAGIC, &test);
132 if (res < 0) {
133 myprintf("selfttest ioctl get error\n");
134 } else {
136 printf("selftest: %d %d (0x%x 0x%x 0x%x) [%d %d] (0x%x 0x%x 0x%x) \"%s\"\n",
137 test.bus_type,
138 test.error,
139 test.info.pci.vendor,
140 test.info.pci.device,
141 test.info.pci.class,
142 test.info.pci.major,
143 test.info.pci.minor,
144 test.info.pci.bus,
145 test.info.pci.slot,
146 test.info.pci.func,
147 test.info.pci.name
152 if (nothing_flag)
153 goto end;
155 dma[0] = (u_long *)mmap(0, MSPS_DMA_SIZE, PROT_READ | PROT_WRITE,
156 MAP_SHARED, fd,
157 MSPS_DMA_MMAP_0);
158 if (dma[0] == (u_long *)-1) {
159 myprintf("Error mmap dma[0]: %s\n", strerror(errno));
160 return -1;
163 dma[1] = (u_long *)mmap(0, MSPS_DMA_SIZE, PROT_READ | PROT_WRITE,
164 MAP_SHARED, fd,
165 MSPS_DMA_MMAP_1);
166 if (dma[1] == (u_long *)-1) {
167 myprintf("Error mmap dma[1]: %s\n", strerror(errno));
168 return -1;
170 myprintf("mmap - ok\n");
172 for (i = 0; i < (data_size/sizeof(u_long)); i++) {
173 (*(dma[0] + i)) = 0x0;
174 (*(dma[1] + i)) = 0x0;
177 print_first_dma();
179 htonll(*dma[3])
182 if (testmode_flag) {
183 printf("Device test mode - are on\n");
184 ioctl(fd, MSPS_TEST_MODE_ON, NULL);
187 res = ioctl(fd, MSPS_GET_STATUS, &status);
188 if (res < 0) {
189 myprintf("ioctl get status error\n");
190 return -1;
193 task->size = data_size;
194 activetask.time = active_work * 1000; /* mili or micro seconds!? 0_o */
196 if (write_flag)
197 mask = 0x55555555;
199 for (i = 0; i < (data_size/sizeof(u_long)); i++) {
200 (*(dma[0] + i)) = mask;
201 (*(dma[1] + i)) = mask;
204 printf("%s with msps %s (%s):\n",
205 write_flag ? "Write" : "Read",
206 dev_name,
207 active_work ? "active" : "interrupt");
209 if (active_work)
210 res = ioctl(fd, MSPS_EXCH_DATA_ACTIVE, &activetask);
211 else
212 res = ioctl(fd, MSPS_EXCH_DATA, task);
214 if (res < 0) {
215 myprintf("ioctl exch_data error\n");
216 } else {
217 myprintf("%d -> state: 0x%x, size: %d, buf: %d\n",
218 task->size,
219 task->status.state,
220 task->status.size,
221 task->status.buffer
225 print_first_dma();
229 typedef struct msps_status {
230 msps_exch_stat_t input;
231 msps_exch_stat_t output;
232 } msps_status_t;
234 typedef struct msps_exch_stat {
235 u_int state; // if == 0 - then finished
236 u_int size; // size of last exchange
237 u_int buffer; // which buffer used for last exchange
238 } msps_exch_stat_t;
242 myprintf("status:\n\tstate\t0x%x\n\tsize\t0x%x\n\tbuffer\t0x%x\n\n",
243 status.state,
244 status.size,
245 status.buffer);
247 if (testmode_flag) {
248 printf("Device test mode - are off\n");
249 ioctl(fd, MSPS_TEST_MODE_OFF, NULL);
252 munmap(dma[0], MSPS_DMA_SIZE);
253 munmap(dma[1], MSPS_DMA_SIZE);
254 end:
255 close(fd);
257 return 0;