2 * wARM functionality test
4 * written by GraÅžvydas "notaz" Ignotas
6 * see warm.c for license info
18 #define warm_init(...) 0
19 #define warm_finish(...)
20 #define warm_cache_op_range(...)
21 #define warm_change_cb_range(...)
24 typedef unsigned long long u64;
25 static u64 start_time, end_time;
27 static unsigned char buff[8 * 1024 * 1024] __attribute__((aligned(32)));
28 static unsigned char *buff_mid = &buff[8 * 1024 * 1024 / 2];
30 static u64 xtime(void)
33 gettimeofday(&tv, NULL);
34 return (u64)tv.tv_sec * 1000000 + tv.tv_usec;
37 static void test_start(void)
42 static void test_end(void)
47 static void show_result(const char *name, int bytes)
49 double secs = (end_time - start_time) / 1000000.0;
50 printf("%-16s: %4.1fs, %5.1f MB/s\n", name, secs, bytes / secs / 1048576);
53 static void do_memset(void)
55 memset(buff, 0, sizeof(buff));
58 static void byte_fill(void)
60 char *p = (void *)buff;
62 for (i = sizeof(buff); i > 0; i--)
66 static void word_fill(void)
68 long *p = (void *)buff;
70 for (i = sizeof(buff) / sizeof(*p); i > 0; i--)
74 static void do_memcpy(void)
76 memcpy(buff, buff_mid, sizeof(buff) / 2);
79 static void byte_cpy(void)
81 char *d = (void *)buff;
82 char *s = (void *)buff_mid;
84 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
88 static void word_cpy(void)
90 long *d = (void *)buff;
91 long *s = (void *)buff_mid;
93 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
97 static void word_inc(void)
99 long *p = (void *)buff;
102 for (i = sizeof(buff) / sizeof(*p); i > 0; i--) {
108 #define ONE_TEST(count, func) \
110 for (i = count; i > 0; i--) \
114 static void tests(void)
118 ONE_TEST(64, do_memset);
119 show_result("memset", sizeof(buff) * 64);
121 ONE_TEST(64, byte_fill);
122 show_result("byte fill", sizeof(buff) * 64);
124 ONE_TEST(64, word_fill);
125 show_result("word fill", sizeof(buff) * 64);
127 ONE_TEST(128, do_memcpy);
128 show_result("memcpy", sizeof(buff) * 128 / 2);
130 ONE_TEST(128, byte_cpy);
131 show_result("byte copy", sizeof(buff) * 128 / 2);
133 ONE_TEST(128, word_cpy);
134 show_result("word copy", sizeof(buff) * 128 / 2);
136 ONE_TEST(64, word_inc);
137 show_result("word inc", sizeof(buff) * 64);
143 #include <sys/types.h>
144 #include <sys/stat.h>
146 #include <sys/mman.h>
148 void coherency_test(void)
150 volatile unsigned char *buff_mapped;
151 volatile unsigned char *buff_vol;
152 unsigned long buff_phys, mapped_phys, align;
153 unsigned char buff_mapped_vals[6];
154 unsigned char buff_vals[5];
160 buff_phys = warm_virt2phys(buff_mid);
161 align = buff_phys & 0xfff;
163 memdev = open("/dev/mem", O_RDONLY | O_SYNC);
165 perror("open /dev/mem");
169 /* the mapping is valid for 1 page only.
170 * Also it doesn't work for GP2X F100 (2.4 kernels?),
171 * only upper mem maps correctly there. */
172 buff_mapped = mmap(NULL, 0x1000, PROT_READ,
173 MAP_SHARED, memdev, buff_phys & ~0xfff);
174 if (buff_mapped == MAP_FAILED) {
178 buff_mapped += align;
180 buff_mapped_vals[5] = buff_mapped[0]; /* touch */
181 mapped_phys = warm_virt2phys((void *)buff_mapped);
182 if (buff_phys != mapped_phys)
183 printf("warning: mmap requested %08lx, got %08lx\n", buff_phys, mapped_phys);
185 random_offs = rand() % (0x1000 - align);
187 buff_vol = (volatile void *)buff_mid;
188 buff_vals[0] = buff_vol[random_offs]; buff_mapped_vals[0] = buff_mapped[random_offs];
191 buff_vol[random_offs]++;
192 buff_vals[1] = buff_vol[random_offs]; buff_mapped_vals[1] = buff_mapped[random_offs];
195 warm_cache_op_range(WOP_D_CLEAN, (char *)buff_vol + random_offs, 32);
196 buff_vals[2] = buff_vol[random_offs]; buff_mapped_vals[2] = buff_mapped[random_offs];
199 buff_vol[random_offs]++;
200 buff_vals[3] = buff_vol[random_offs]; buff_mapped_vals[3] = buff_mapped[random_offs];
203 warm_cache_op_range(WOP_D_INVALIDATE, (char *)buff_vol + random_offs, 32);
204 buff_vals[4] = buff_vol[random_offs]; buff_mapped_vals[4] = buff_mapped[random_offs];
206 printf("buff is @ %p -> %lx, mapped %p, random offset %x\n", buff_vol, buff_phys,
207 buff_mapped, random_offs);
208 printf("val: %02x, mmaped: %02x\n", buff_vals[0], buff_mapped_vals[0]);
210 printf("incremented:\n");
211 printf("val: %02x, mmaped: %02x\n", buff_vals[1], buff_mapped_vals[1]);
213 printf("cleaned:\n");
214 printf("val: %02x, mmaped: %02x\n", buff_vals[2], buff_mapped_vals[2]);
216 printf("incremented:\n");
217 printf("val: %02x, mmaped: %02x\n", buff_vals[3], buff_mapped_vals[3]);
219 printf("invalidated:\n");
220 printf("val: %02x, mmaped: %02x\n", buff_vals[4], buff_mapped_vals[4]);
223 #define coherency_test()
233 printf("init failed.\n");
237 printf("buff: %p - %p\n", buff, buff + sizeof(buff) - 1);
239 printf("-- default --\n");
242 printf("-- ncnb --\n");
243 warm_change_cb_range(WCB_C_BIT|WCB_B_BIT, 0, buff, sizeof(buff));
246 printf("-- nc b --\n");
247 warm_change_cb_range(WCB_B_BIT, 1, buff, sizeof(buff));
250 printf("-- cnb --\n");
251 warm_change_cb_range(WCB_C_BIT, 1, buff, sizeof(buff));
252 warm_change_cb_range(WCB_B_BIT, 0, buff, sizeof(buff));
255 warm_change_cb_range(WCB_C_BIT|WCB_B_BIT, 1, buff, sizeof(buff));