1 | #include <stdio.h>
|
---|
2 | #include <errno.h>
|
---|
3 | #include <string.h>
|
---|
4 | #include <sys/types.h>
|
---|
5 | #include <fcntl.h>
|
---|
6 | #include <sys/ioctl.h>
|
---|
7 |
|
---|
8 | #include <dev/pci/sis1100_var.h>
|
---|
9 |
|
---|
10 | static u_int32_t read_remote_register(int p, u_int32_t offs)
|
---|
11 | {
|
---|
12 | struct sis1100_ctrl_reg reg;
|
---|
13 |
|
---|
14 | reg.offset=offs;
|
---|
15 | if (ioctl(p, SIS3100_CONTROL_READ, ®)<0) {
|
---|
16 | fprintf(stderr, "ioctl(SIS3100_CONTROL_READ, offs=0x%x): errno=%s\n",
|
---|
17 | offs, strerror(errno));
|
---|
18 | return -1;
|
---|
19 | }
|
---|
20 | if (reg.error) {
|
---|
21 | fprintf(stderr, "ioctl(SIS3100_CONTROL_READ, offs=0x%x): error=%d\n",
|
---|
22 | offs, reg.error);
|
---|
23 | return -1;
|
---|
24 | }
|
---|
25 | return reg.val;
|
---|
26 | }
|
---|
27 |
|
---|
28 | static u_int32_t read_local_register(int p, u_int32_t offs)
|
---|
29 | {
|
---|
30 | struct sis1100_ctrl_reg reg;
|
---|
31 |
|
---|
32 | reg.offset=offs;
|
---|
33 | if (ioctl(p, SIS1100_CONTROL_READ, ®)<0) {
|
---|
34 | fprintf(stderr, "ioctl(SIS1100_CONTROL_READ, offs=0x%x): errno=%s\n",
|
---|
35 | offs, strerror(errno));
|
---|
36 | return -1;
|
---|
37 | }
|
---|
38 | if (reg.error) {
|
---|
39 | fprintf(stderr, "ioctl(SIS1100_CONTROL_READ, offs=0x%x): error=%d\n",
|
---|
40 | offs, reg.error);
|
---|
41 | return -1;
|
---|
42 | }
|
---|
43 | return reg.val;
|
---|
44 | }
|
---|
45 |
|
---|
46 | static u_int32_t read_ident(int p, struct sis1100_ident* ident)
|
---|
47 | {
|
---|
48 | if (ioctl(p, SIS1100_IDENT, ident)<0) {
|
---|
49 | fprintf(stderr, "ioctl(SIS1100_IDENT): %s\n",strerror(errno));
|
---|
50 | return -1;
|
---|
51 | }
|
---|
52 | return 0;
|
---|
53 | }
|
---|
54 |
|
---|
55 | int main(int argc, char* argv[])
|
---|
56 | {
|
---|
57 | int p;
|
---|
58 | u_int32_t id;
|
---|
59 | struct sis1100_ident ident;
|
---|
60 |
|
---|
61 | if (argc<2)
|
---|
62 | {
|
---|
63 | fprintf(stderr, "usage: %s path\n", argv[0]);
|
---|
64 | return 1;
|
---|
65 | }
|
---|
66 |
|
---|
67 | if ((p=open(argv[1], O_RDWR, 0))<0)
|
---|
68 | {
|
---|
69 | fprintf(stderr, "open(\"%s\"): %s\n", argv[1], strerror(errno));
|
---|
70 | return 1;
|
---|
71 | }
|
---|
72 |
|
---|
73 | id=read_local_register(p, 0);
|
---|
74 | printf("local id : 0x%08x\n\n", id);
|
---|
75 |
|
---|
76 | read_ident(p, &ident);
|
---|
77 | printf("local hw_type : %d\n", ident.local.hw_type);
|
---|
78 | printf("local hw_version: %d\n", ident.local.hw_version);
|
---|
79 | printf("local fw_type : %d\n", ident.local.fw_type);
|
---|
80 | printf("local fw_version: %d\n\n", ident.local.fw_version);
|
---|
81 |
|
---|
82 | id=read_remote_register(p, 0);
|
---|
83 | printf("remote id : 0x%08x\n\n", id);
|
---|
84 |
|
---|
85 | if (!ident.remote_ok) {
|
---|
86 | printf("remote id not available\n");
|
---|
87 | } else {
|
---|
88 | printf("remote hw_type : %d\n", ident.remote.hw_type);
|
---|
89 | printf("remote hw_version: %d\n", ident.remote.hw_version);
|
---|
90 | printf("remote fw_type : %d\n", ident.remote.fw_type);
|
---|
91 | printf("remote fw_version: %d\n\n", ident.remote.fw_version);
|
---|
92 | }
|
---|
93 |
|
---|
94 | close(p);
|
---|
95 | return 0;
|
---|
96 | }
|
---|