2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Precise Delay Loops for x86-64
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993 Linus Torvalds
|
|
|
|
* Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
|
|
|
|
*
|
|
|
|
* The __delay function must _NOT_ be inlined as its execution time
|
|
|
|
* depends wildly on alignment on many x86 processors.
|
|
|
|
*/
|
|
|
|
|
2006-06-26 13:59:44 +02:00
|
|
|
#include <linux/module.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <asm/delay.h>
|
2005-06-23 09:08:13 +02:00
|
|
|
#include <asm/msr.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#endif
|
|
|
|
|
2005-06-23 09:08:13 +02:00
|
|
|
int read_current_timer(unsigned long *timer_value)
|
|
|
|
{
|
|
|
|
rdtscll(*timer_value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
void __delay(unsigned long loops)
|
|
|
|
{
|
|
|
|
unsigned bclock, now;
|
|
|
|
|
|
|
|
rdtscl(bclock);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
rep_nop();
|
|
|
|
rdtscl(now);
|
|
|
|
}
|
|
|
|
while((now-bclock) < loops);
|
|
|
|
}
|
2006-06-26 13:59:44 +02:00
|
|
|
EXPORT_SYMBOL(__delay);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
inline void __const_udelay(unsigned long xloops)
|
|
|
|
{
|
2006-12-07 02:14:07 +01:00
|
|
|
__delay(((xloops * HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32) + 1);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-06-26 13:59:44 +02:00
|
|
|
EXPORT_SYMBOL(__const_udelay);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
void __udelay(unsigned long usecs)
|
|
|
|
{
|
2006-12-07 02:14:07 +01:00
|
|
|
__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-06-26 13:59:44 +02:00
|
|
|
EXPORT_SYMBOL(__udelay);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
void __ndelay(unsigned long nsecs)
|
|
|
|
{
|
|
|
|
__const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
|
|
|
|
}
|
2006-06-26 13:59:44 +02:00
|
|
|
EXPORT_SYMBOL(__ndelay);
|