2005-04-16 16:20:36 -06: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 05:59:44 -06:00
|
|
|
#include <linux/module.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/sched.h>
|
2007-11-14 18:00:41 -07:00
|
|
|
#include <linux/preempt.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/delay.h>
|
2007-11-14 18:00:41 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/delay.h>
|
2005-06-23 01:08:13 -06:00
|
|
|
#include <asm/msr.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#endif
|
|
|
|
|
2005-06-23 01:08:13 -06:00
|
|
|
int read_current_timer(unsigned long *timer_value)
|
|
|
|
{
|
|
|
|
rdtscll(*timer_value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
void __delay(unsigned long loops)
|
|
|
|
{
|
|
|
|
unsigned bclock, now;
|
2007-11-14 18:00:41 -07:00
|
|
|
|
|
|
|
preempt_disable(); /* TSC's are pre-cpu */
|
2005-04-16 16:20:36 -06:00
|
|
|
rdtscl(bclock);
|
2007-11-14 18:00:41 -07:00
|
|
|
do {
|
2005-04-16 16:20:36 -06:00
|
|
|
rep_nop();
|
|
|
|
rdtscl(now);
|
|
|
|
}
|
2007-11-14 18:00:41 -07:00
|
|
|
while ((now-bclock) < loops);
|
|
|
|
preempt_enable();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-06-26 05:59:44 -06:00
|
|
|
EXPORT_SYMBOL(__delay);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
inline void __const_udelay(unsigned long xloops)
|
|
|
|
{
|
2007-10-19 12:35:04 -06:00
|
|
|
__delay(((xloops * HZ *
|
|
|
|
cpu_data(raw_smp_processor_id()).loops_per_jiffy) >> 32) + 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-06-26 05:59:44 -06:00
|
|
|
EXPORT_SYMBOL(__const_udelay);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
void __udelay(unsigned long usecs)
|
|
|
|
{
|
2006-12-06 18:14:07 -07:00
|
|
|
__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-06-26 05:59:44 -06:00
|
|
|
EXPORT_SYMBOL(__udelay);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
void __ndelay(unsigned long nsecs)
|
|
|
|
{
|
|
|
|
__const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
|
|
|
|
}
|
2006-06-26 05:59:44 -06:00
|
|
|
EXPORT_SYMBOL(__ndelay);
|