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