2 * wARM functionality test
4 * written by GraÅžvydas "notaz" Ignotas
6 * see warm.c for license info
14 #include <sys/ioctl.h>
16 #include <sys/types.h>
24 #define warm_init(...) 0
25 #define warm_finish(...)
26 #define warm_cache_op_range(...)
27 #define warm_change_cb_range(...)
30 typedef unsigned long long u64;
31 static u64 start_time, end_time;
33 static unsigned char buff[2 * 1024 * 1024] __attribute__((aligned(32)));
34 static unsigned char *buff_mid = &buff[sizeof(buff) / 2];
38 static u64 xtime(void)
41 gettimeofday(&tv, NULL);
42 return (u64)tv.tv_sec * 1000000 + tv.tv_usec;
45 static void test_start(void)
50 static void test_end(void)
55 static void show_result(const char *name, int bytes)
57 double secs = (end_time - start_time) / 1000000.0;
58 printf("%-16s: %4.1fs, %5.1f MB/s\n", name, secs, bytes / secs / 1048576);
61 static void do_memset(void)
63 memset(buff, 0, sizeof(buff));
66 static void byte_fill(void)
68 char *p = (void *)buff;
70 for (i = sizeof(buff); i > 0; i--)
74 static void word_fill(void)
76 long *p = (void *)buff;
78 for (i = sizeof(buff) / sizeof(*p); i > 0; i--)
82 static void cached_byte_fill(void)
84 char *p = (void *)buff;
87 for (i = sizeof(buff) / 32; i > 0; i--) {
89 for (j = 32; j > 0; j--)
94 static void do_memcpy(void)
96 memcpy(buff, buff_mid, sizeof(buff) / 2);
99 static void byte_cpy(void)
101 char *d = (void *)buff;
102 char *s = (void *)buff_mid;
104 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
108 static void word_cpy(void)
110 long *d = (void *)buff;
111 long *s = (void *)buff_mid;
113 for (i = sizeof(buff) / sizeof(*d) / 2; i > 0; i--)
117 static void word_inc(void)
119 long *p = (void *)buff;
122 for (i = sizeof(buff) / sizeof(*p); i > 0; i--) {
128 #define TEST_PAGE 4096
130 static void page_writes_ref(void *buf)
135 for (j = 0; j < 0x100000 / TEST_PAGE; j++)
136 for (i = 0; i < TEST_PAGE / 4; i++)
137 d[j * TEST_PAGE / 4 + i] = 0;
140 static void page_inc_ref(void *buf)
145 for (j = 0; j < 0x100000 / TEST_PAGE; j++)
146 for (i = 0; i < TEST_PAGE / 4; i++)
147 d[j * TEST_PAGE / 4 + i]++;
150 static void page_writes(void *buf)
155 for (i = 0; i < TEST_PAGE / 4; i++)
156 for (j = 0; j < 0x100000 / TEST_PAGE; j++)
157 d[j * TEST_PAGE / 4 + i] = 0;
160 static void page_inc(void *buf)
165 for (i = 0; i < TEST_PAGE / 4; i++)
166 for (j = 0; j < 0x100000 / TEST_PAGE; j++)
167 d[j * TEST_PAGE / 4 + i]++;
170 #define ONE_TEST(count, func) \
172 for (i = count; i > 0; i--) \
176 static void tests(void)
180 ONE_TEST(REP, do_memset());
181 show_result("memset", sizeof(buff) * REP);
183 ONE_TEST(REP, byte_fill());
184 show_result("byte fill", sizeof(buff) * REP);
186 ONE_TEST(REP, word_fill());
187 show_result("word fill", sizeof(buff) * REP);
189 ONE_TEST(REP, cached_byte_fill());
190 show_result("c. byte fill", sizeof(buff) * REP);
192 ONE_TEST(REP * 2, do_memcpy());
193 show_result("memcpy", sizeof(buff) * REP);
195 ONE_TEST(REP * 2, byte_cpy());
196 show_result("byte copy", sizeof(buff) * REP);
198 ONE_TEST(REP * 2, word_cpy());
199 show_result("word copy", sizeof(buff) * REP);
201 ONE_TEST(REP, word_inc());
202 show_result("word inc", sizeof(buff) * REP);
207 static void page_tests(void *buf)
211 ONE_TEST(REP, page_writes(buf));
212 show_result("page_writes", 0x100000 * REP);
214 ONE_TEST(REP, page_inc(buf));
215 show_result("page_inc", 0x100000 * REP);
219 #include <sys/types.h>
220 #include <sys/stat.h>
222 #include <sys/mman.h>
224 void coherency_test(void)
226 volatile unsigned char *buff_mapped;
227 volatile unsigned char *buff_vol;
228 unsigned long buff_phys, mapped_phys, align;
229 unsigned char buff_mapped_vals[6];
230 unsigned char buff_vals[5];
236 buff_phys = warm_virt2phys(buff_mid);
237 align = buff_phys & 0xfff;
239 memdev = open("/dev/mem", O_RDONLY | O_SYNC);
241 perror("open /dev/mem");
245 /* the mapping is valid for 1 page only.
246 * Also it doesn't work for GP2X F100 (2.4 kernels?),
247 * only upper mem maps correctly there. */
248 buff_mapped = mmap(NULL, 0x1000, PROT_READ,
249 MAP_SHARED, memdev, buff_phys & ~0xfff);
250 if (buff_mapped == MAP_FAILED) {
254 buff_mapped += align;
256 buff_mapped_vals[5] = buff_mapped[0]; /* touch */
257 mapped_phys = warm_virt2phys((void *)buff_mapped);
258 if (buff_phys != mapped_phys)
259 printf("warning: mmap requested %08lx, got %08lx\n", buff_phys, mapped_phys);
261 random_offs = rand() % (0x1000 - align);
263 buff_vol = (volatile void *)buff_mid;
264 buff_vals[0] = buff_vol[random_offs]; buff_mapped_vals[0] = buff_mapped[random_offs];
267 buff_vol[random_offs]++;
268 buff_vals[1] = buff_vol[random_offs]; buff_mapped_vals[1] = buff_mapped[random_offs];
271 warm_cache_op_range(WOP_D_CLEAN, (char *)buff_vol + random_offs, 32);
272 buff_vals[2] = buff_vol[random_offs]; buff_mapped_vals[2] = buff_mapped[random_offs];
275 buff_vol[random_offs]++;
276 buff_vals[3] = buff_vol[random_offs]; buff_mapped_vals[3] = buff_mapped[random_offs];
279 warm_cache_op_range(WOP_D_INVALIDATE, (char *)buff_vol + random_offs, 32);
280 buff_vals[4] = buff_vol[random_offs]; buff_mapped_vals[4] = buff_mapped[random_offs];
282 printf("buff is @ %p -> %lx, mapped %p, random offset %x\n", buff_vol, buff_phys,
283 buff_mapped, random_offs);
284 printf("val: %02x, mmaped: %02x\n", buff_vals[0], buff_mapped_vals[0]);
286 printf("incremented:\n");
287 printf("val: %02x, mmaped: %02x\n", buff_vals[1], buff_mapped_vals[1]);
289 printf("cleaned:\n");
290 printf("val: %02x, mmaped: %02x\n", buff_vals[2], buff_mapped_vals[2]);
292 printf("incremented:\n");
293 printf("val: %02x, mmaped: %02x\n", buff_vals[3], buff_mapped_vals[3]);
295 printf("invalidated:\n");
296 printf("val: %02x, mmaped: %02x\n", buff_vals[4], buff_mapped_vals[4]);
299 #define coherency_test()
304 struct fb_fix_screeninfo fbfix;
313 printf("init failed.\n");
317 printf("buff: %p - %p\n", buff, buff + sizeof(buff) - 1);
322 printf("-- default --\n");
325 printf("-- ncnb --\n");
326 warm_change_cb_range(WCB_C_BIT|WCB_B_BIT, 0, buff, sizeof(buff));
329 printf("-- nc b --\n");
330 warm_change_cb_range(WCB_B_BIT, 1, buff, sizeof(buff));
333 printf("-- cnb --\n");
334 warm_change_cb_range(WCB_C_BIT, 1, buff, sizeof(buff));
335 warm_change_cb_range(WCB_B_BIT, 0, buff, sizeof(buff));
338 //printf("-- c b --\n");
339 warm_change_cb_range(WCB_C_BIT|WCB_B_BIT, 1, buff, sizeof(buff));
344 mmap_mem = mmap((void *)0x60000000, 0x100000, PROT_READ | PROT_WRITE,
345 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
347 // find safe location for section map, we'll use fb
348 fbdev = open("/dev/fb0", O_RDWR);
354 ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix);
356 perror("ioctl(fbdev)");
360 section_mem = (void *)0x70000000;
361 ret = warm_mmap_section(section_mem, fbfix.smem_start, 0x100000,
362 WCB_C_BIT|WCB_B_BIT);
364 fprintf(stderr, "section map failed\n");
369 memset(mmap_mem, 0, 0x100000);
370 memset(section_mem, 0, 0x100000);
372 ONE_TEST(REP, page_writes_ref(mmap_mem));
373 show_result("page_wr_ref_m", 0x100000 * REP);
375 ONE_TEST(REP, page_inc_ref(mmap_mem));
376 show_result("page_inc_ref_m", 0x100000 * REP);
378 ONE_TEST(REP, page_writes_ref(section_mem));
379 show_result("page_wr_ref_s", 0x100000 * REP);
381 ONE_TEST(REP, page_inc_ref(section_mem));
382 show_result("page_inc_ref_s", 0x100000 * REP);
384 printf("== pages ==\n");
385 page_tests(mmap_mem);
387 printf("== section ==\n");
388 printf("-- default --\n");
389 page_tests(section_mem);
391 printf("-- ncnb --\n");
392 warm_change_cb_range(WCB_C_BIT|WCB_B_BIT, 0, section_mem, 0x100000);
393 page_tests(section_mem);
395 printf("-- nc b --\n");
396 warm_change_cb_range(WCB_B_BIT, 1, section_mem, 0x100000);
397 page_tests(section_mem);
399 printf("-- cnb --\n");
400 warm_change_cb_range(WCB_C_BIT, 1, section_mem, 0x100000);
401 warm_change_cb_range(WCB_B_BIT, 0, section_mem, 0x100000);
402 page_tests(section_mem);
404 warm_munmap_section(section_mem, 0x100000);