testmmiotrace.c 1.6 KB
Newer Older
1 2 3 4
/*
 * Written by Pekka Paalanen, 2008 <pq@iki.fi>
 */
#include <linux/module.h>
P
Pekka Paalanen 已提交
5
#include <linux/io.h>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

#define MODULE_NAME "testmmiotrace"

static unsigned long mmio_address;
module_param(mmio_address, ulong, 0);
MODULE_PARM_DESC(mmio_address, "Start address of the mapping of 16 kB.");

static void do_write_test(void __iomem *p)
{
	unsigned int i;
	for (i = 0; i < 256; i++)
		iowrite8(i, p + i);
	for (i = 1024; i < (5 * 1024); i += 2)
		iowrite16(i * 12 + 7, p + i);
	for (i = (5 * 1024); i < (16 * 1024); i += 4)
		iowrite32(i * 212371 + 13, p + i);
}

static void do_read_test(void __iomem *p)
{
	unsigned int i;
	for (i = 0; i < 256; i++)
P
Pekka Paalanen 已提交
28
		ioread8(p + i);
29
	for (i = 1024; i < (5 * 1024); i += 2)
P
Pekka Paalanen 已提交
30
		ioread16(p + i);
31
	for (i = (5 * 1024); i < (16 * 1024); i += 4)
P
Pekka Paalanen 已提交
32
		ioread32(p + i);
33 34 35 36
}

static void do_test(void)
{
P
Pekka Paalanen 已提交
37
	void __iomem *p = ioremap_nocache(mmio_address, 0x4000);
38
	if (!p) {
39
		pr_err(MODULE_NAME ": could not ioremap, aborting.\n");
40 41 42 43
		return;
	}
	do_write_test(p);
	do_read_test(p);
P
Pekka Paalanen 已提交
44
	iounmap(p);
45 46 47 48 49
}

static int __init init(void)
{
	if (mmio_address == 0) {
50 51 52
		pr_err(MODULE_NAME ": you have to use the module argument "
							"mmio_address.\n");
		pr_err(MODULE_NAME ": DO NOT LOAD THIS MODULE UNLESS"
53 54 55 56
				" YOU REALLY KNOW WHAT YOU ARE DOING!\n");
		return -ENXIO;
	}

57
	pr_warning(MODULE_NAME ": WARNING: mapping 16 kB @ 0x%08lx "
58 59 60 61 62 63 64 65
					"in PCI address space, and writing "
					"rubbish in there.\n", mmio_address);
	do_test();
	return 0;
}

static void __exit cleanup(void)
{
66
	pr_debug(MODULE_NAME ": unloaded.\n");
67 68 69 70 71
}

module_init(init);
module_exit(cleanup);
MODULE_LICENSE("GPL");