1 | #define _GNU_SOURCE
|
---|
2 | #define _LARGEFILE_SOURCE
|
---|
3 | #define _LARGEFILE64_SOURCE
|
---|
4 | #define _FILE_OFFSET_BITS 64
|
---|
5 | #include <stdio.h>
|
---|
6 | #include <errno.h>
|
---|
7 | #include <string.h>
|
---|
8 | #include <sys/types.h>
|
---|
9 | #include <time.h>
|
---|
10 | #include <unistd.h>
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <fcntl.h>
|
---|
13 | #include <sys/ioctl.h>
|
---|
14 |
|
---|
15 | #include "dev/pci/sis1100_var.h"
|
---|
16 |
|
---|
17 | /****************************************************************************/
|
---|
18 | static int* alloc_buf(int num)
|
---|
19 | {
|
---|
20 | unsigned long int p;
|
---|
21 | int pagesize, pagemask;
|
---|
22 |
|
---|
23 | pagesize=getpagesize();
|
---|
24 | pagemask=pagesize-1;
|
---|
25 | p=(unsigned long int)calloc(num+pagesize, 1);
|
---|
26 | if (!p) return (int*)p;
|
---|
27 | p=(p+pagesize-1)&(~pagemask);
|
---|
28 | return (int*)p;
|
---|
29 | }
|
---|
30 |
|
---|
31 | static int generate_size(int max)
|
---|
32 | {
|
---|
33 | int maxbits, bits;
|
---|
34 | int mask, size;
|
---|
35 |
|
---|
36 | maxbits=0;
|
---|
37 | while (1<<maxbits<max) maxbits++;
|
---|
38 | bits=random()%maxbits+1;
|
---|
39 | mask=0xffffffff>>(32-bits);
|
---|
40 | size=random()%mask+1;
|
---|
41 | return size;
|
---|
42 | }
|
---|
43 |
|
---|
44 | static int generate_start(int max, int size)
|
---|
45 | {
|
---|
46 | int space, offs;
|
---|
47 | space=max-size;
|
---|
48 | offs=random()%(space+1);
|
---|
49 | return offs;
|
---|
50 | }
|
---|
51 |
|
---|
52 | static void check_it(int p, int size, int* ob, int* ib, int mem, int err_addr)
|
---|
53 | {
|
---|
54 | u_int32_t data;
|
---|
55 | int l;
|
---|
56 |
|
---|
57 | lseek(p, sizeof(int)*(mem+err_addr), SEEK_SET);
|
---|
58 | read(p, &data, sizeof(int));
|
---|
59 | printf("/524288=%d %%524288=%d diff to end=%d\n",
|
---|
60 | ((err_addr+1)*4)/524288,
|
---|
61 | ((err_addr+1)*4)%524288,
|
---|
62 | size-err_addr);
|
---|
63 | /*
|
---|
64 | printf("** ob: %08X mem: %08X ib: %08X\n", ob[err_addr], data, ib[err_addr]);
|
---|
65 | printf("** ob+offs=%08X ib+offs=%08X\n",
|
---|
66 | (unsigned int)(ob+err_addr), (unsigned int)(ib+err_addr));
|
---|
67 | */
|
---|
68 | for (l=0; l<5; l++) {
|
---|
69 | lseek(p, sizeof(int)*mem, SEEK_SET);
|
---|
70 | write(p, ob, size*sizeof(int));
|
---|
71 | lseek(p, sizeof(int)*mem, SEEK_SET);
|
---|
72 | read(p, ib, size*sizeof(int));
|
---|
73 | if (bcmp(ib, ob, size*sizeof(int))) {
|
---|
74 | int i, n;
|
---|
75 | printf("## size=%08X ob=%08lX ib=%08lX mem=%08lX\n", size,
|
---|
76 | (unsigned long)ob, (unsigned long)ib, (unsigned long)mem);
|
---|
77 | for (i=0, n=0; (i<size) && (n<20); i++) {
|
---|
78 | if (ib[i]!=ob[i]) {
|
---|
79 | printf("## [%08X] %08X %08X\n", i, ob[i], ib[i]);
|
---|
80 | n++;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | int main(int argc, char* argv[])
|
---|
88 | {
|
---|
89 | int *ibuf, *obuf;
|
---|
90 | off_t max;
|
---|
91 | int p, i, n, size;
|
---|
92 |
|
---|
93 | if (argc!=2) {
|
---|
94 | fprintf(stderr, "usage: %s path\n", argv[0]);
|
---|
95 | return 1;
|
---|
96 | }
|
---|
97 |
|
---|
98 | if ((p=open(argv[1], O_RDWR, 0))<0) {
|
---|
99 | perror("open");
|
---|
100 | return 1;
|
---|
101 | }
|
---|
102 |
|
---|
103 | max=lseek(p, 0, SEEK_END);
|
---|
104 | if (max==(off_t)-1) {
|
---|
105 | perror("lseek(0, SEEK_END)");
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 | fprintf(stderr, "size of sdram is %08Lx (%Ld MByte)\n", max, max/(1<<20));
|
---|
109 |
|
---|
110 | max/=sizeof(int);
|
---|
111 |
|
---|
112 | ibuf=alloc_buf(max*sizeof(int));
|
---|
113 | printf("ibuf=%08X\n", (unsigned int)ibuf);
|
---|
114 | obuf=alloc_buf(max*sizeof(int));
|
---|
115 | printf("obuf=%08X\n", (unsigned int)obuf);
|
---|
116 | if (!ibuf || !obuf) {
|
---|
117 | perror("calloc");
|
---|
118 | return 1;
|
---|
119 | }
|
---|
120 | size=max;
|
---|
121 | while (1) {
|
---|
122 | int res;
|
---|
123 | int ob_start, ib_start, mem_start;
|
---|
124 | int *ib, *ob;
|
---|
125 | off_t pos;
|
---|
126 |
|
---|
127 | /*size=generate_size(max);*/
|
---|
128 | ob_start=generate_start(max, size);
|
---|
129 | ib_start=generate_start(max, size);
|
---|
130 | mem_start=generate_start(max, size);
|
---|
131 | /*printf("%8d %8d %8d %8d\n", size, ob_start, ib_start, mem_start);*/
|
---|
132 | /*printf("."); fflush(stdout);*/
|
---|
133 | ob=obuf+ob_start;
|
---|
134 | for (i=0; i<size; i++) *ob++=random();
|
---|
135 |
|
---|
136 | pos=lseek(p, sizeof(int)*mem_start, SEEK_SET);
|
---|
137 | if (pos==(off_t)-1) {
|
---|
138 | perror("lseek");
|
---|
139 | return -1;
|
---|
140 | }
|
---|
141 |
|
---|
142 | ob=obuf+ob_start;
|
---|
143 | res=write(p, ob, size*sizeof(int));
|
---|
144 | if (res!=size*sizeof(int)) {
|
---|
145 | u_int32_t error;
|
---|
146 | ioctl(p, SIS1100_LAST_ERROR, &error);
|
---|
147 | if (res<0) {
|
---|
148 | fprintf(stderr, "write: %s; error=0x%x\n", strerror(errno), error);
|
---|
149 | } else {
|
---|
150 | fprintf(stderr, "write: res=%d; error=0x%x\n", res, error);
|
---|
151 | }
|
---|
152 | return -1;
|
---|
153 | }
|
---|
154 |
|
---|
155 | pos=lseek(p, sizeof(int)*mem_start, SEEK_SET);
|
---|
156 | if (pos==(off_t)-1) {
|
---|
157 | perror("lseek");
|
---|
158 | return -1;
|
---|
159 | }
|
---|
160 |
|
---|
161 | ib=ibuf+ib_start;
|
---|
162 | res=read(p, ib, size*sizeof(int));
|
---|
163 | if (res!=size*sizeof(int)) {
|
---|
164 | u_int32_t error;
|
---|
165 | ioctl(p, SIS1100_LAST_ERROR, &error);
|
---|
166 | if (res<0) {
|
---|
167 | fprintf(stderr, "read: %s; error=0x%x\n", strerror(errno), error);
|
---|
168 | } else {
|
---|
169 | fprintf(stderr, "read: res=%d; error=0x%x\n", res, error);
|
---|
170 | }
|
---|
171 | return -1;
|
---|
172 | }
|
---|
173 |
|
---|
174 | if (bcmp(ib, ob, size*sizeof(int))) {
|
---|
175 | int err_addr;
|
---|
176 |
|
---|
177 | printf("\nsize=%08X ob=%08lX ib=%08lX mem=%08lX\n", size,
|
---|
178 | (unsigned long)ob, (unsigned long)ib, (unsigned long)mem_start);
|
---|
179 | err_addr=-1;
|
---|
180 | for (i=0, n=0; (i<size) && (n<20); i++) {
|
---|
181 | if (ib[i]!=ob[i]) {
|
---|
182 | printf("[%08X] %08X %08X\n", i, ob[i], ib[i]);
|
---|
183 | if (err_addr==-1) err_addr=i;
|
---|
184 | n++;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | check_it(p, size, ob, ib, mem_start, err_addr);
|
---|
188 | size=size/10;
|
---|
189 | printf("new size=%d\n", size);
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | close(p);
|
---|
194 |
|
---|
195 | return 0;
|
---|
196 | }
|
---|