2004-07-05 21:49:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/config.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <asm/io.h>
|
2004-07-05 22:49:56 +02:00
|
|
|
#include <asm/page.h>
|
2004-07-05 21:49:42 +02:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/msr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Ali Saidi"
|
|
|
|
#define DRIVER_DESC "Interface to time uncacachable read and writes to device registers"
|
|
|
|
#define DRIVER_VER "0.1"
|
|
|
|
|
|
|
|
static char *dataAddr = NULL;
|
|
|
|
static int count = 0;
|
2004-08-19 05:12:16 +02:00
|
|
|
#ifdef __alpha__
|
|
|
|
static int memTest = 0;
|
|
|
|
#endif
|
2004-07-05 21:49:42 +02:00
|
|
|
|
|
|
|
static inline uint32_t cycleCounter(uint32_t dep);
|
|
|
|
|
|
|
|
static int __init devtime_start(void)
|
|
|
|
{
|
|
|
|
uint64_t addr;
|
2004-07-13 05:01:53 +02:00
|
|
|
uint32_t t1, t2;
|
2004-07-05 21:49:42 +02:00
|
|
|
uint32_t trash;
|
|
|
|
int x;
|
2004-07-13 04:51:20 +02:00
|
|
|
uint32_t *times;
|
|
|
|
uint32_t num = 0;
|
2004-07-05 21:49:42 +02:00
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
printk("Devtime Driver Version %s Loaded...\n", DRIVER_VER);
|
|
|
|
|
2004-08-19 05:12:16 +02:00
|
|
|
#ifdef __alpha__
|
|
|
|
if (memTest) {
|
|
|
|
addr = 0xfffffc0000000000;
|
|
|
|
// addr += 16*1024*1024;
|
|
|
|
|
|
|
|
printk("Preparing memory test.\n");
|
|
|
|
|
|
|
|
t1 = cycleCounter(trash);
|
|
|
|
for (x = 0; x < count; x++) {
|
|
|
|
trash = readl(addr);
|
|
|
|
t2 = cycleCounter(trash);
|
|
|
|
times[num++] = t2 - t1;
|
|
|
|
t1 = t2;
|
|
|
|
addr += 4096;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk("Measurements:\n");
|
|
|
|
for (x = 0; x < count; x++) {
|
|
|
|
printk("%d ", times[x]);
|
|
|
|
if (((x + 1) % 10) == 0)
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
printk("\nDone.\n");
|
|
|
|
} else
|
|
|
|
#endif
|
2004-07-13 05:01:53 +02:00
|
|
|
if (dataAddr != 0 && count != 0) {
|
2004-07-05 21:49:42 +02:00
|
|
|
addr = simple_strtoull(dataAddr, NULL, 0);
|
|
|
|
|
2004-07-05 22:49:56 +02:00
|
|
|
addr = ioremap(addr, PAGE_SIZE);
|
|
|
|
/**
|
|
|
|
* Make sure that the remapping actually worked. On alpha we have
|
|
|
|
* linear addressing, so its not a problem. But it can fail in x86
|
|
|
|
* if physical memory is mapped to this address.
|
|
|
|
*/
|
2004-07-13 04:51:20 +02:00
|
|
|
times = kmalloc(sizeof(uint32_t) * count, GFP_USER);
|
2004-07-13 05:01:53 +02:00
|
|
|
if (!times) {
|
2004-07-13 04:51:20 +02:00
|
|
|
printk("Could not allocate memory... Try again later.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-07-13 05:01:53 +02:00
|
|
|
if (addr) {
|
2004-07-05 22:49:56 +02:00
|
|
|
printk("Preparing to read %#llx %d times.\n", addr, count);
|
|
|
|
|
|
|
|
t1 = cycleCounter(trash);
|
2004-07-13 05:01:53 +02:00
|
|
|
for (x = 0; x < count; x++) {
|
2004-07-05 22:49:56 +02:00
|
|
|
trash = readl(addr);
|
|
|
|
t2 = cycleCounter(trash);
|
2004-07-13 04:51:20 +02:00
|
|
|
times[num++] = t2 - t1;
|
2004-07-05 22:49:56 +02:00
|
|
|
t1 = t2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unmap the address.
|
|
|
|
*/
|
|
|
|
iounmap(addr);
|
|
|
|
|
2004-07-13 04:51:20 +02:00
|
|
|
printk("Measurements:\n");
|
2004-07-13 05:01:53 +02:00
|
|
|
for (x = 0; x < count; x++) {
|
2004-07-13 04:51:20 +02:00
|
|
|
printk("%d ", times[x]);
|
2004-07-13 05:01:53 +02:00
|
|
|
if (((x + 1) % 10) == 0)
|
2004-07-13 04:51:20 +02:00
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
printk("\nDone.\n");
|
2004-07-13 05:01:53 +02:00
|
|
|
} else {
|
2004-07-05 22:49:56 +02:00
|
|
|
printk("Unable to remap address. Please try again later.\n");
|
2004-07-13 05:01:53 +02:00
|
|
|
}
|
2004-07-05 21:49:42 +02:00
|
|
|
} else {
|
|
|
|
dev = dev_get_by_name("eth0");
|
2004-07-13 05:01:53 +02:00
|
|
|
if (dev) {
|
|
|
|
printk("Eth0: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
|
|
|
|
dev->mem_start, dev->mem_end, dev->base_addr);
|
2004-07-05 21:49:42 +02:00
|
|
|
dev_put(dev);
|
|
|
|
}
|
2004-07-05 22:49:56 +02:00
|
|
|
dev = 0;
|
2004-07-05 21:49:42 +02:00
|
|
|
dev = dev_get_by_name("eth1");
|
2004-07-13 05:01:53 +02:00
|
|
|
if (dev) {
|
|
|
|
printk("Eth1: MemStart: %#lx MemEnd: %#lx I/O Addr: %#lx\n",
|
|
|
|
dev->mem_start, dev->mem_end, dev->base_addr);
|
2004-07-05 21:49:42 +02:00
|
|
|
dev_put(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
printk("Required information not supplied.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
static inline uint32_t cycleCounter(uint32_t dep)
|
|
|
|
{
|
|
|
|
uint32_t time;
|
|
|
|
cpuid_eax(0);
|
|
|
|
rdtscl(time);
|
|
|
|
cpuid_eax(0);
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif __alpha__
|
|
|
|
|
|
|
|
inline uint32_t cycleCounter(uint32_t dep)
|
|
|
|
{
|
|
|
|
uint32_t res;
|
|
|
|
asm volatile ("rpcc %0, %1" : "=r"(res) : "r" (dep) : "memory");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#else
|
2004-08-19 05:12:16 +02:00
|
|
|
#error Architecture NOT SUPPORTED
|
2004-07-05 21:49:42 +02:00
|
|
|
#endif
|
|
|
|
|
2004-07-13 05:01:53 +02:00
|
|
|
static void __exit devtime_end(void)
|
|
|
|
{
|
2004-07-05 21:49:42 +02:00
|
|
|
printk("Devtime Driver Version %s Unloaded...\n", DRIVER_VER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(devtime_start);
|
|
|
|
module_exit(devtime_end);
|
|
|
|
|
2004-07-13 04:51:20 +02:00
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
2004-07-05 21:49:42 +02:00
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
module_param(dataAddr, charp, 0);
|
|
|
|
module_param(count, int, 0);
|
2004-08-19 05:12:16 +02:00
|
|
|
#ifdef __alpha__
|
|
|
|
module_param(memTest, int, 0);
|
|
|
|
#endif
|