1 | #define _GNU_SOURCE
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <errno.h>
|
---|
4 | #include <sys/types.h>
|
---|
5 | #include <unistd.h>
|
---|
6 | #include <stdlib.h>
|
---|
7 | #include <string.h>
|
---|
8 | #include <fcntl.h>
|
---|
9 | #include <sys/mman.h>
|
---|
10 | #include <sys/ioctl.h>
|
---|
11 |
|
---|
12 | #include "dev/pci/sis1100_var.h"
|
---|
13 |
|
---|
14 | int main(int argc, char* argv[])
|
---|
15 | {
|
---|
16 | int p;
|
---|
17 | struct sis1100_ident ident;
|
---|
18 | struct sis1100_ctrl_reg reg;
|
---|
19 | volatile u_int32_t* regspace;
|
---|
20 | u_int32_t regsize;
|
---|
21 | u_int32_t data;
|
---|
22 | enum sis1100_subdev devtype;
|
---|
23 |
|
---|
24 | if (argc!=2)
|
---|
25 | {
|
---|
26 | fprintf(stderr, "usage: %s path\n", argv[0]);
|
---|
27 | return 1;
|
---|
28 | }
|
---|
29 |
|
---|
30 | if ((p=open(argv[1], O_RDWR, 0))<0) {
|
---|
31 | fprintf(stderr, "open \"%s\": %s\n", argv[1], strerror(errno));
|
---|
32 | return 1;
|
---|
33 | }
|
---|
34 |
|
---|
35 | if (ioctl(p, SIS1100_IDENT, &ident)<0) {
|
---|
36 | fprintf(stderr, "ioctl(SIS1100_IDENT): %s\n", strerror(errno));
|
---|
37 | return 2;
|
---|
38 | }
|
---|
39 | printf("local:\n");
|
---|
40 | printf(" hw_type : %d\n", ident.local.hw_type);
|
---|
41 | printf(" hw_version: %d\n", ident.local.hw_version);
|
---|
42 | printf(" fw_type : %d\n", ident.local.fw_type);
|
---|
43 | printf(" fw_version: %d\n\n", ident.local.fw_version);
|
---|
44 | printf("remote:\n");
|
---|
45 | printf(" hw_type : %d\n", ident.remote.hw_type);
|
---|
46 | printf(" hw_version: %d\n", ident.remote.hw_version);
|
---|
47 | printf(" fw_type : %d\n", ident.remote.fw_type);
|
---|
48 | printf(" fw_version: %d\n\n", ident.remote.fw_version);
|
---|
49 |
|
---|
50 | printf(" remote side is %s and %svalid\n",
|
---|
51 | ident.remote_online?"online":"offline",
|
---|
52 | ident.remote_ok?"":"not ");
|
---|
53 |
|
---|
54 | if ((ident.local.hw_type!=1)||(ident.local.hw_version!=1)||
|
---|
55 | (ident.local.fw_type!=1)) {
|
---|
56 | fprintf(stderr, "unsupported bord version\n");
|
---|
57 | return 2;
|
---|
58 | }
|
---|
59 |
|
---|
60 | reg.offset=0;
|
---|
61 | if (ioctl(p, SIS1100_CONTROL_READ, ®)<0) {
|
---|
62 | fprintf(stderr, "ioctl(SIS1100_CONTROL_READ, offs=0): %s\n",
|
---|
63 | strerror(errno));
|
---|
64 | return 2;
|
---|
65 | }
|
---|
66 | if (reg.error!=0) {
|
---|
67 | fprintf(stderr, "ioctl(SIS1100_CONTROL_READ, offs=0): error=0x%x\n",
|
---|
68 | reg.error);
|
---|
69 | return 2;
|
---|
70 | }
|
---|
71 | if (reg.val!=(ident.local.hw_type|
|
---|
72 | (ident.local.hw_version<<8)|
|
---|
73 | (ident.local.fw_type<<16)|
|
---|
74 | (ident.local.fw_version<<24))) {
|
---|
75 | fprintf(stderr, "local ident 0x%08x does not match SIS1100_IDENT\n",
|
---|
76 | reg.val);
|
---|
77 | return 2;
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (ioctl(p, SIS1100_DEVTYPE, &devtype)<0) {
|
---|
81 | printf("ioctl(SIS1100_DEVTYPE): %s\n", strerror(errno));
|
---|
82 | return 1;
|
---|
83 | }
|
---|
84 | if (devtype!=sis1100_subdev_ctrl) {
|
---|
85 | printf("You have to use the control device (sis1100ctrl_xx).\n");
|
---|
86 | return 1;
|
---|
87 | }
|
---|
88 |
|
---|
89 | if (ioctl(p, SIS1100_MAPSIZE, ®size)<0) {
|
---|
90 | fprintf(stderr, "ioctl(SIS1100_MAPSIZE 1): %s\n", strerror(errno));
|
---|
91 | return 1;
|
---|
92 | }
|
---|
93 | printf("size of regspace=0x%x\n", regsize);
|
---|
94 |
|
---|
95 | regspace=mmap(0, regsize, PROT_READ|PROT_WRITE, MAP_SHARED, p, 0);
|
---|
96 | if (regspace==MAP_FAILED) {
|
---|
97 | fprintf(stderr, "mmap register space: %s\n", strerror(errno));
|
---|
98 | return 2;
|
---|
99 | }
|
---|
100 |
|
---|
101 | data=regspace[0];
|
---|
102 | if (data!=reg.val) {
|
---|
103 | fprintf(stderr, "local ident 0x%08x (mapped) does not match SIS1100_IDENT\n",
|
---|
104 | data);
|
---|
105 | return 2;
|
---|
106 | }
|
---|
107 |
|
---|
108 | if (munmap((void*)regspace, regsize)<0) {
|
---|
109 | fprintf(stderr, "munmap: %s\n", strerror(errno));
|
---|
110 | return 2;
|
---|
111 | }
|
---|
112 |
|
---|
113 | if (close(p)<0) {
|
---|
114 | fprintf(stderr, "close: %s\n", strerror(errno));
|
---|
115 | return 2;
|
---|
116 | }
|
---|
117 | return 0;
|
---|
118 | }
|
---|