2 * Written by Pekka Paalanen, 2008-2009 <pq@iki.fi>
5 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 #include <linux/module.h>
9 #include <linux/mmiotrace.h>
11 static unsigned long mmio_address
;
12 module_param(mmio_address
, ulong
, 0);
13 MODULE_PARM_DESC(mmio_address
, " Start address of the mapping of 16 kB "
14 "(or 8 MB if read_far is non-zero).");
16 static unsigned long read_far
= 0x400100;
17 module_param(read_far
, ulong
, 0);
18 MODULE_PARM_DESC(read_far
, " Offset of a 32-bit read within 8 MB "
19 "(default: 0x400100).");
21 static unsigned v16(unsigned i
)
26 static unsigned v32(unsigned i
)
28 return i
* 212371 + 13;
31 static void do_write_test(void __iomem
*p
)
34 pr_info("write test.\n");
35 mmiotrace_printk("Write test.\n");
37 for (i
= 0; i
< 256; i
++)
40 for (i
= 1024; i
< (5 * 1024); i
+= 2)
41 iowrite16(v16(i
), p
+ i
);
43 for (i
= (5 * 1024); i
< (16 * 1024); i
+= 4)
44 iowrite32(v32(i
), p
+ i
);
47 static void do_read_test(void __iomem
*p
)
50 unsigned errs
[3] = { 0 };
51 pr_info("read test.\n");
52 mmiotrace_printk("Read test.\n");
54 for (i
= 0; i
< 256; i
++)
55 if (ioread8(p
+ i
) != i
)
58 for (i
= 1024; i
< (5 * 1024); i
+= 2)
59 if (ioread16(p
+ i
) != v16(i
))
62 for (i
= (5 * 1024); i
< (16 * 1024); i
+= 4)
63 if (ioread32(p
+ i
) != v32(i
))
66 mmiotrace_printk("Read errors: 8-bit %d, 16-bit %d, 32-bit %d.\n",
67 errs
[0], errs
[1], errs
[2]);
70 static void do_read_far_test(void __iomem
*p
)
72 pr_info("read far test.\n");
73 mmiotrace_printk("Read far test.\n");
75 ioread32(p
+ read_far
);
78 static void do_test(unsigned long size
)
80 void __iomem
*p
= ioremap_nocache(mmio_address
, size
);
82 pr_err("could not ioremap, aborting.\n");
85 mmiotrace_printk("ioremap returned %p.\n", p
);
88 if (read_far
&& read_far
< size
- 4)
93 static int __init
init(void)
95 unsigned long size
= (read_far
) ? (8 << 20) : (16 << 10);
97 if (mmio_address
== 0) {
98 pr_err("you have to use the module argument mmio_address.\n");
99 pr_err("DO NOT LOAD THIS MODULE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!\n");
103 pr_warning("WARNING: mapping %lu kB @ 0x%08lx in PCI address space, "
104 "and writing 16 kB of rubbish in there.\n",
105 size
>> 10, mmio_address
);
107 pr_info("All done.\n");
111 static void __exit
cleanup(void)
113 pr_debug("unloaded.\n");
117 module_exit(cleanup
);
118 MODULE_LICENSE("GPL");