2 * Copyright (c) 2004 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <asm/uaccess.h>
34 #include <linux/config.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/netdevice.h>
44 #include <asm/processor.h>
47 #define DRIVER_AUTHOR "Ali Saidi"
48 #define DRIVER_DESC "Interface to time uncacachable read and writes to device registers"
49 #define DRIVER_VER "0.1"
51 static char *dataAddr
= NULL
;
54 static int memTest
= 0;
57 static inline uint32_t cycleCounter(uint32_t dep
);
59 static int __init
devtime_start(void)
67 struct net_device
*dev
;
69 printk("Devtime Driver Version %s Loaded...\n", DRIVER_VER
);
73 addr
= 0xfffffc0000000000;
74 // addr += 16*1024*1024;
76 printk("Preparing memory test.\n");
78 t1
= cycleCounter(trash
);
79 for (x
= 0; x
< count
; x
++) {
81 t2
= cycleCounter(trash
);
82 times
[num
++] = t2
- t1
;
87 printk("Measurements:\n");
88 for (x
= 0; x
< count
; x
++) {
89 printk("%d ", times
[x
]);
90 if (((x
+ 1) % 10) == 0)
96 if (dataAddr
!= 0 && count
!= 0) {
97 addr
= simple_strtoull(dataAddr
, NULL
, 0);
99 addr
= ioremap(addr
, PAGE_SIZE
);
101 * Make sure that the remapping actually worked. On alpha we have
102 * linear addressing, so its not a problem. But it can fail in x86
103 * if physical memory is mapped to this address.
105 times
= kmalloc(sizeof(uint32_t) * count
, GFP_USER
);
107 printk("Could not allocate memory... Try again later.\n");
112 printk("Preparing to read %#llx %d times.\n", addr
, count
);
114 t1
= cycleCounter(trash
);
115 for (x
= 0; x
< count
; x
++) {
117 t2
= cycleCounter(trash
);
118 times
[num
++] = t2
- t1
;
127 printk("Measurements:\n");
128 for (x
= 0; x
< count
; x
++) {
129 printk("%d ", times
[x
]);
130 if (((x
+ 1) % 10) == 0)
135 printk("Unable to remap address. Please try again later.\n");
138 dev
= dev_get_by_name("eth0");
140 printk("Eth0: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
141 dev
->mem_start
, dev
->mem_end
, dev
->base_addr
);
145 dev
= dev_get_by_name("eth1");
147 printk("Eth1: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
148 dev
->mem_start
, dev
->mem_end
, dev
->base_addr
);
152 printk("Required information not supplied.\n");
160 static inline uint32_t cycleCounter(uint32_t dep
)
171 inline uint32_t cycleCounter(uint32_t dep
)
174 asm volatile ("rpcc %0, %1" : "=r"(res
) : "r" (dep
) : "memory");
178 #error Architecture NOT SUPPORTED
181 static void __exit
devtime_end(void)
183 printk("Devtime Driver Version %s Unloaded...\n", DRIVER_VER
);
187 module_init(devtime_start
);
188 module_exit(devtime_end
);
190 MODULE_LICENSE("Dual BSD/GPL");
191 MODULE_AUTHOR(DRIVER_AUTHOR
);
192 MODULE_DESCRIPTION(DRIVER_DESC
);
193 module_param(dataAddr
, charp
, 0);
194 module_param(count
, int, 0);
196 module_param(memTest
, int, 0);