1 | #if 0
|
---|
2 | #define _GNU_SOURCE
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <errno.h>
|
---|
6 | #include <string.h>
|
---|
7 | #include <sys/types.h>
|
---|
8 | #include <unistd.h>
|
---|
9 | #include <fcntl.h>
|
---|
10 | #include <sys/mman.h>
|
---|
11 | #include <sys/ioctl.h>
|
---|
12 | #include <signal.h>
|
---|
13 |
|
---|
14 | #include "dev/pci/sis1100_var.h"
|
---|
15 |
|
---|
16 | struct mapinfo {
|
---|
17 | u_int32_t header;
|
---|
18 | u_int32_t bordaddr;
|
---|
19 | int bordsize;
|
---|
20 | int modifier;
|
---|
21 | int mapidx, mapnum;
|
---|
22 | char* mapbase;
|
---|
23 | off_t mapsize;
|
---|
24 | char* bordbase;
|
---|
25 | };
|
---|
26 |
|
---|
27 | /****************************************************************************/
|
---|
28 | static void
|
---|
29 | clear_maps(int p)
|
---|
30 | {
|
---|
31 | int i;
|
---|
32 | struct sis1100_ctrl_reg reg;
|
---|
33 |
|
---|
34 | for (i=0; i<64; i++) {
|
---|
35 | /* clear the .adl register; --> mark as unused */
|
---|
36 | reg.offset=0x408+16*i;
|
---|
37 | reg.val=0;
|
---|
38 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
39 | }
|
---|
40 | }
|
---|
41 | /****************************************************************************/
|
---|
42 | static void
|
---|
43 | dump_map(int p, struct mapinfo* map)
|
---|
44 | {
|
---|
45 | int i;
|
---|
46 | printf("---------------------------\n");
|
---|
47 | printf("header =0x%08x\n", map->header);
|
---|
48 | printf("bordaddr=0x%08x\n", map->bordaddr);
|
---|
49 | printf("bordsize=0x%08x\n", map->bordsize);
|
---|
50 | printf("modifier= 0x%02x\n", map->modifier);
|
---|
51 | printf("mapidx = %8d\n", map->mapidx);
|
---|
52 | printf("mapnum = %8d\n", map->mapnum);
|
---|
53 | printf("mapbase =%p\n", map->mapbase);
|
---|
54 | printf("mapsize =0x%08lx\n", map->mapsize);
|
---|
55 | printf("bordbase=%p\n", map->bordbase);
|
---|
56 | printf("\n");
|
---|
57 |
|
---|
58 | for (i=map->mapidx; i<map->mapidx+map->mapnum; i++) {
|
---|
59 | struct sis1100_ctrl_reg reg;
|
---|
60 | u_int32_t offs=0x400+16*i;
|
---|
61 |
|
---|
62 | printf("idx=%d\n", i);
|
---|
63 | reg.offset=offs+0;
|
---|
64 | ioctl(p, SIS1100_CONTROL_READ, ®);
|
---|
65 | printf(".hdr=0x%08x\n", reg.val);
|
---|
66 | reg.offset=offs+4;
|
---|
67 | ioctl(p, SIS1100_CONTROL_READ, ®);
|
---|
68 | printf(".am =0x%08x\n", reg.val);
|
---|
69 | reg.offset=offs+8;
|
---|
70 | ioctl(p, SIS1100_CONTROL_READ, ®);
|
---|
71 | printf(".adl=0x%08x\n", reg.val);
|
---|
72 | reg.offset=offs+12;
|
---|
73 | ioctl(p, SIS1100_CONTROL_READ, ®);
|
---|
74 | printf(".adh=0x%08x\n", reg.val);
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|
78 | /****************************************************************************/
|
---|
79 | static int
|
---|
80 | map_it(int p, struct mapinfo* map)
|
---|
81 | {
|
---|
82 | u_int32_t spacebase;
|
---|
83 | u_int32_t spacesize;
|
---|
84 | u_int32_t bordoffs;
|
---|
85 | struct sis1100_ctrl_reg reg;
|
---|
86 | int i;
|
---|
87 |
|
---|
88 | /* get size of VME-space */
|
---|
89 | if (ioctl(p, SIS1100_MAPSIZE, &spacesize)<0) {
|
---|
90 | printf("SIS1100_MAPSIZE: %s\n", strerror(errno));
|
---|
91 | return -1;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*
|
---|
95 | printf("size of VME space=0x%x\n", spacesize);
|
---|
96 | */
|
---|
97 |
|
---|
98 | spacebase=map->bordaddr & MAPMASK;
|
---|
99 | bordoffs=map->bordaddr & OFFMASK;
|
---|
100 | map->mapnum=(map->bordsize+bordoffs+MAPSIZE-1)/MAPSIZE;
|
---|
101 | map->mapsize=map->mapnum*MAPSIZE;
|
---|
102 |
|
---|
103 | /* this code is only to find an unused map entry */
|
---|
104 | /* not really necessary */
|
---|
105 | for (i=0; i<64; i++) {
|
---|
106 | reg.offset=0x408+16*i;
|
---|
107 | if (ioctl(p, SIS1100_CONTROL_READ, ®)<0) {
|
---|
108 | printf("SIS1100_CONTROL_READ: %s\n", strerror(errno));
|
---|
109 | return -1;
|
---|
110 | }
|
---|
111 | if (reg.error) {
|
---|
112 | printf("SIS1100_CONTROL_READ: error=0x%x\n", reg.error);
|
---|
113 | return -1;
|
---|
114 | }
|
---|
115 | if (reg.val==0) break;
|
---|
116 | }
|
---|
117 | if (i>=(64-map->mapnum)) {
|
---|
118 | printf("map_it: no maps available\n");
|
---|
119 | return -1;
|
---|
120 | }
|
---|
121 | /*printf("found free entry at %d\n", i);*/
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 | map->mapidx=i;
|
---|
126 | for (i=0; i<map->mapnum; i++) {
|
---|
127 | u_int32_t offs=0x400+16*(map->mapidx+i);
|
---|
128 |
|
---|
129 | reg.offset=offs+0;
|
---|
130 | reg.val=map->header;
|
---|
131 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
132 |
|
---|
133 | reg.offset=offs+4;
|
---|
134 | reg.val=map->modifier;
|
---|
135 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
136 | reg.offset=offs+8;
|
---|
137 |
|
---|
138 | /* the '|0xa5a5' is only used to mark the entry as 'in use' */
|
---|
139 | /* the lowest 22 bits are ignored, so we can misuse them */
|
---|
140 | reg.val=spacebase+MAPSIZE*i|0xa5a5;
|
---|
141 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
142 |
|
---|
143 | reg.offset=offs+12;
|
---|
144 | reg.val=0;
|
---|
145 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
146 | }
|
---|
147 |
|
---|
148 | map->mapbase=mmap(0,
|
---|
149 | map->mapsize,
|
---|
150 | PROT_READ|PROT_WRITE, MAP_SHARED,
|
---|
151 | p,
|
---|
152 | mapinfo.offset+map->mapidx*MAPSIZE);
|
---|
153 | /* ^^^^^^^^^^^^^^^^^^^ */
|
---|
154 | /* only this term is really missing in your code*/
|
---|
155 |
|
---|
156 |
|
---|
157 | if (map->mapbase==MAP_FAILED) {
|
---|
158 | printf("mmap: %s\n", strerror(errno));
|
---|
159 | for (i=0; i<map->mapnum; i++) {
|
---|
160 | reg.offset=0x400+16*(map->mapidx+i)+8;
|
---|
161 | reg.val=0;
|
---|
162 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
163 | }
|
---|
164 | return -1;
|
---|
165 | }
|
---|
166 | map->bordbase=map->mapbase+bordoffs;
|
---|
167 | return 0;
|
---|
168 | }
|
---|
169 | /****************************************************************************/
|
---|
170 | static void
|
---|
171 | unmap_it(int p, struct mapinfo* map)
|
---|
172 | {
|
---|
173 | struct sis1100_ctrl_reg reg;
|
---|
174 | int i;
|
---|
175 |
|
---|
176 | munmap(map->mapbase, map->mapsize);
|
---|
177 | for (i=0; i<map->mapnum; i++) {
|
---|
178 | reg.offset=0x400+16*(map->mapidx+i)+8;
|
---|
179 | reg.val=0;
|
---|
180 | ioctl(p, SIS1100_CONTROL_WRITE, ®);
|
---|
181 | }
|
---|
182 | }
|
---|
183 | /****************************************************************************/
|
---|
184 | int main(int argc, char* argv[])
|
---|
185 | {
|
---|
186 | int p, p, i;
|
---|
187 | struct mapinfo map[5];
|
---|
188 | volatile u_int32_t val;
|
---|
189 |
|
---|
190 | if (argc!=3) {
|
---|
191 | fprintf(stderr, "usage: %s path controlpath\n", argv[0]);
|
---|
192 | return 1;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if ((p=open(argv[1], O_RDWR, 0))<0) {
|
---|
196 | printf("open %s: %s\n", argv[1], strerror(errno));
|
---|
197 | return 1;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /* mark all maps as unused */
|
---|
201 | clear_maps(cp);
|
---|
202 |
|
---|
203 | map[0].header=0xff010800;
|
---|
204 | map[0].bordaddr=0x00222200;
|
---|
205 | map[0].bordsize=0x400000;
|
---|
206 | map[0].modifier=0x39;
|
---|
207 |
|
---|
208 | map[1].header=0xff010800;
|
---|
209 | map[1].bordaddr=0x00d00000;
|
---|
210 | map[1].bordsize=0x300000;
|
---|
211 | map[1].modifier=0x39;
|
---|
212 |
|
---|
213 | map[2].header=0xff010800;
|
---|
214 | map[2].bordaddr=0xee000000;
|
---|
215 | map[2].bordsize=0x400000;
|
---|
216 | map[2].modifier=0x9;
|
---|
217 |
|
---|
218 | map[3].header=0xff010800;
|
---|
219 | map[3].bordaddr=0x00f00000;
|
---|
220 | map[3].bordsize=0x100000;
|
---|
221 | map[3].modifier=0x39;
|
---|
222 |
|
---|
223 | map[4].header=0xff010800;
|
---|
224 | map[4].bordaddr=0x00380000;
|
---|
225 | map[4].bordsize=0x00200000;
|
---|
226 | map[4].modifier=0x39;
|
---|
227 |
|
---|
228 | for (i=0; i<5; i++) {
|
---|
229 | if (map_it(p, map+i)<0) return 1;
|
---|
230 | dump_map(p, map+i);
|
---|
231 | }
|
---|
232 |
|
---|
233 | /* the real access */
|
---|
234 | val=*(u_int16_t*)(map[0].bordbase+0xfa);
|
---|
235 | val=*(u_int16_t*)(map[1].bordbase+0xfe02);
|
---|
236 | val=*(u_int16_t*)(map[2].bordbase+0x1000);
|
---|
237 | val=*(u_int16_t*)(map[3].bordbase+0x0);
|
---|
238 | val=*(u_int16_t*)(map[4].bordbase+0x100000);
|
---|
239 |
|
---|
240 | for (i=0; i<5; i++) {
|
---|
241 | unmap_it(p, map+i);
|
---|
242 | }
|
---|
243 |
|
---|
244 | close(p);
|
---|
245 | return 0;
|
---|
246 | }
|
---|
247 | /****************************************************************************/
|
---|
248 | /****************************************************************************/
|
---|
249 | #else
|
---|
250 | int main(void) {return 0;}
|
---|
251 | #endif
|
---|