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> |
| 5 | #include <asm/io.h> |
| 6 | |
| 7 | extern void __iomem *ioremap_nocache_trace(unsigned long offset, |
| 8 | unsigned long size); |
| 9 | extern void iounmap_trace(volatile void __iomem *addr); |
| 10 | |
| 11 | #define MODULE_NAME "testmmiotrace" |
| 12 | |
| 13 | static unsigned long mmio_address; |
| 14 | module_param(mmio_address, ulong, 0); |
| 15 | MODULE_PARM_DESC(mmio_address, "Start address of the mapping of 16 kB."); |
| 16 | |
| 17 | static void do_write_test(void __iomem *p) |
| 18 | { |
| 19 | unsigned int i; |
| 20 | for (i = 0; i < 256; i++) |
| 21 | iowrite8(i, p + i); |
| 22 | for (i = 1024; i < (5 * 1024); i += 2) |
| 23 | iowrite16(i * 12 + 7, p + i); |
| 24 | for (i = (5 * 1024); i < (16 * 1024); i += 4) |
| 25 | iowrite32(i * 212371 + 13, p + i); |
| 26 | } |
| 27 | |
| 28 | static void do_read_test(void __iomem *p) |
| 29 | { |
| 30 | unsigned int i; |
| 31 | volatile unsigned int v; |
| 32 | for (i = 0; i < 256; i++) |
| 33 | v = ioread8(p + i); |
| 34 | for (i = 1024; i < (5 * 1024); i += 2) |
| 35 | v = ioread16(p + i); |
| 36 | for (i = (5 * 1024); i < (16 * 1024); i += 4) |
| 37 | v = ioread32(p + i); |
| 38 | } |
| 39 | |
| 40 | static void do_test(void) |
| 41 | { |
| 42 | void __iomem *p = ioremap_nocache_trace(mmio_address, 0x4000); |
| 43 | if (!p) { |
| 44 | printk(KERN_ERR MODULE_NAME ": could not ioremap IO memory, " |
| 45 | "aborting.\n"); |
| 46 | return; |
| 47 | } |
| 48 | do_write_test(p); |
| 49 | do_read_test(p); |
| 50 | iounmap_trace(p); |
| 51 | } |
| 52 | |
| 53 | static int __init init(void) |
| 54 | { |
| 55 | if (mmio_address == 0) { |
| 56 | printk(KERN_ERR MODULE_NAME ": you have to use the module " |
| 57 | "argument mmio_address.\n"); |
| 58 | printk(KERN_ERR MODULE_NAME ": DO NOT LOAD THIS MODULE UNLESS" |
| 59 | " YOU REALLY KNOW WHAT YOU ARE DOING!\n"); |
| 60 | return -ENXIO; |
| 61 | } |
| 62 | |
| 63 | printk(KERN_WARNING MODULE_NAME ": WARNING: mapping 16 kB @ 0x%08lx " |
| 64 | "in PCI address space, and writing " |
| 65 | "rubbish in there.\n", mmio_address); |
| 66 | do_test(); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static void __exit cleanup(void) |
| 71 | { |
| 72 | printk(KERN_DEBUG MODULE_NAME ": unloaded.\n"); |
| 73 | } |
| 74 | |
| 75 | module_init(init); |
| 76 | module_exit(cleanup); |
| 77 | MODULE_LICENSE("GPL"); |