2 * Written by Pekka Paalanen, 2008-2009 <pq@iki.fi>
4 #include <linux/module.h>
6 #include <linux/mmiotrace.h>
8 #define MODULE_NAME "testmmiotrace"
10 static unsigned long mmio_address;
11 module_param(mmio_address, ulong, 0);
12 MODULE_PARM_DESC(mmio_address, " Start address of the mapping of 16 kB "
13 "(or 8 MB if read_far is non-zero).");
15 static unsigned long read_far = 0x400100;
16 module_param(read_far, ulong, 0);
17 MODULE_PARM_DESC(read_far, " Offset of a 32-bit read within 8 MB "
18 "(default: 0x400100).");
20 static unsigned v16(unsigned i)
25 static unsigned v32(unsigned i)
27 return i * 212371 + 13;
30 static void do_write_test(void __iomem *p)
33 pr_info(MODULE_NAME ": write test.\n");
34 mmiotrace_printk("Write test.\n");
36 for (i = 0; i < 256; i++)
39 for (i = 1024; i < (5 * 1024); i += 2)
40 iowrite16(v16(i), p + i);
42 for (i = (5 * 1024); i < (16 * 1024); i += 4)
43 iowrite32(v32(i), p + i);
46 static void do_read_test(void __iomem *p)
49 unsigned errs[3] = { 0 };
50 pr_info(MODULE_NAME ": read test.\n");
51 mmiotrace_printk("Read test.\n");
53 for (i = 0; i < 256; i++)
54 if (ioread8(p + i) != i)
57 for (i = 1024; i < (5 * 1024); i += 2)
58 if (ioread16(p + i) != v16(i))
61 for (i = (5 * 1024); i < (16 * 1024); i += 4)
62 if (ioread32(p + i) != v32(i))
65 mmiotrace_printk("Read errors: 8-bit %d, 16-bit %d, 32-bit %d.\n",
66 errs[0], errs[1], errs[2]);
69 static void do_read_far_test(void __iomem *p)
71 pr_info(MODULE_NAME ": read far test.\n");
72 mmiotrace_printk("Read far test.\n");
74 ioread32(p + read_far);
77 static void do_test(unsigned long size)
79 void __iomem *p = ioremap_nocache(mmio_address, size);
81 pr_err(MODULE_NAME ": could not ioremap, aborting.\n");
84 mmiotrace_printk("ioremap returned %p.\n", p);
87 if (read_far && read_far < size - 4)
92 static int __init init(void)
94 unsigned long size = (read_far) ? (8 << 20) : (16 << 10);
96 if (mmio_address == 0) {
97 pr_err(MODULE_NAME ": you have to use the module argument "
99 pr_err(MODULE_NAME ": DO NOT LOAD THIS MODULE UNLESS"
100 " YOU REALLY KNOW WHAT YOU ARE DOING!\n");
104 pr_warning(MODULE_NAME ": WARNING: mapping %lu kB @ 0x%08lx in PCI "
105 "address space, and writing 16 kB of rubbish in there.\n",
106 size >> 10, mmio_address);
108 pr_info(MODULE_NAME ": All done.\n");
112 static void __exit cleanup(void)
114 pr_debug(MODULE_NAME ": unloaded.\n");
118 module_exit(cleanup);
119 MODULE_LICENSE("GPL");