Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Written by Pekka Paalanen, 2008 <pq@iki.fi> |
| 3 | */ |
| 4 | #include <linux/module.h> |
Pekka Paalanen | 970e6fa | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 5 | #include <linux/io.h> |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 6 | #include <linux/mmiotrace.h> |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 7 | |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 8 | #define MODULE_NAME "testmmiotrace" |
| 9 | |
| 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 | |
| 14 | static void do_write_test(void __iomem *p) |
| 15 | { |
| 16 | unsigned int i; |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 17 | mmiotrace_printk("Write test.\n"); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 18 | for (i = 0; i < 256; i++) |
| 19 | iowrite8(i, p + i); |
| 20 | for (i = 1024; i < (5 * 1024); i += 2) |
| 21 | iowrite16(i * 12 + 7, p + i); |
| 22 | for (i = (5 * 1024); i < (16 * 1024); i += 4) |
| 23 | iowrite32(i * 212371 + 13, p + i); |
| 24 | } |
| 25 | |
| 26 | static void do_read_test(void __iomem *p) |
| 27 | { |
| 28 | unsigned int i; |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 29 | mmiotrace_printk("Read test.\n"); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 30 | for (i = 0; i < 256; i++) |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 31 | ioread8(p + i); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 32 | for (i = 1024; i < (5 * 1024); i += 2) |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 33 | ioread16(p + i); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 34 | for (i = (5 * 1024); i < (16 * 1024); i += 4) |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 35 | ioread32(p + i); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static void do_test(void) |
| 39 | { |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 40 | void __iomem *p = ioremap_nocache(mmio_address, 0x4000); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 41 | if (!p) { |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 42 | pr_err(MODULE_NAME ": could not ioremap, aborting.\n"); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 43 | return; |
| 44 | } |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 45 | mmiotrace_printk("ioremap returned %p.\n", p); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 46 | do_write_test(p); |
| 47 | do_read_test(p); |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 48 | iounmap(p); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static int __init init(void) |
| 52 | { |
| 53 | if (mmio_address == 0) { |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 54 | pr_err(MODULE_NAME ": you have to use the module argument " |
| 55 | "mmio_address.\n"); |
| 56 | pr_err(MODULE_NAME ": DO NOT LOAD THIS MODULE UNLESS" |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 57 | " YOU REALLY KNOW WHAT YOU ARE DOING!\n"); |
| 58 | return -ENXIO; |
| 59 | } |
| 60 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 61 | pr_warning(MODULE_NAME ": WARNING: mapping 16 kB @ 0x%08lx " |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 62 | "in PCI address space, and writing " |
| 63 | "rubbish in there.\n", mmio_address); |
| 64 | do_test(); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static void __exit cleanup(void) |
| 69 | { |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 70 | pr_debug(MODULE_NAME ": unloaded.\n"); |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | module_init(init); |
| 74 | module_exit(cleanup); |
| 75 | MODULE_LICENSE("GPL"); |