-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtester.c
More file actions
68 lines (54 loc) · 1.35 KB
/
tester.c
File metadata and controls
68 lines (54 loc) · 1.35 KB
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <signal.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "mymiscdev_ioctl.h"
void sigint_handler(int sig)
{
}
int main()
{
int fd = open("/dev/mymiscdev", O_RDWR);
if (fd==-1) {
perror("open");
return -1;
}
size_t bufsize = 32768;
int rc;
long page_size = sysconf(_SC_PAGESIZE);
// pass offset==1*page_size for driver allocated consistent dma mapping
// pass offset==2*page_size for driver allocated streaming dma mapping
void *mapptr = mmap(NULL, bufsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 1*page_size);
if (mapptr==MAP_FAILED) {
perror("mmap");
return -1;
}
memset(mapptr, 0x5A, bufsize);
void *memptr = 0;
rc = posix_memalign(&memptr, 128, bufsize);
assert(memptr!=0);
printf("%p %zu\n", memptr, bufsize);
struct mymiscdev_ioctl param = { memptr, bufsize };
rc = ioctl(fd, SAMPLE_IOCTL_CMD_1, ¶m);
if (rc==-1) {
perror("ioctl");
}
signal(SIGINT, sigint_handler);
printf("attempting read\n");
rc = read(fd, memptr, bufsize);
if (rc==-1) {
perror("read");
}
else {
printf("read returned %d\n", rc);
}
free(memptr);
close(fd);
return 0;
}