1 /* 2 * Written by Pekka Paalanen, 2008 <pq@iki.fi> 3 */ 4 #include <linux/module.h> 5 #include <linux/io.h> 6 #include <linux/mmiotrace.h> 7 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; 17 mmiotrace_printk("Write test.\n"); 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; 29 mmiotrace_printk("Read test.\n"); 30 for (i = 0; i < 256; i++) 31 ioread8(p + i); 32 for (i = 1024; i < (5 * 1024); i += 2) 33 ioread16(p + i); 34 for (i = (5 * 1024); i < (16 * 1024); i += 4) 35 ioread32(p + i); 36 } 37 38 static void do_test(void) 39 { 40 void __iomem *p = ioremap_nocache(mmio_address, 0x4000); 41 if (!p) { 42 pr_err(MODULE_NAME ": could not ioremap, aborting.\n"); 43 return; 44 } 45 mmiotrace_printk("ioremap returned %p.\n", p); 46 do_write_test(p); 47 do_read_test(p); 48 iounmap(p); 49 } 50 51 static int __init init(void) 52 { 53 if (mmio_address == 0) { 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" 57 " YOU REALLY KNOW WHAT YOU ARE DOING!\n"); 58 return -ENXIO; 59 } 60 61 pr_warning(MODULE_NAME ": WARNING: mapping 16 kB @ 0x%08lx " 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 { 70 pr_debug(MODULE_NAME ": unloaded.\n"); 71 } 72 73 module_init(init); 74 module_exit(cleanup); 75 MODULE_LICENSE("GPL"); 76