Merge git://git.infradead.org/~dedekind/ubi-2.6
[pandora-kernel.git] / arch / x86 / lib / delay_64.c
1 /*
2  *      Precise Delay Loops for x86-64
3  *
4  *      Copyright (C) 1993 Linus Torvalds
5  *      Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6  *
7  *      The __delay function must _NOT_ be inlined as its execution time
8  *      depends wildly on alignment on many x86 processors. 
9  */
10
11 #include <linux/module.h>
12 #include <linux/sched.h>
13 #include <linux/preempt.h>
14 #include <linux/delay.h>
15
16 #include <asm/delay.h>
17 #include <asm/msr.h>
18
19 #ifdef CONFIG_SMP
20 #include <asm/smp.h>
21 #endif
22
23 int read_current_timer(unsigned long *timer_value)
24 {
25         rdtscll(*timer_value);
26         return 0;
27 }
28
29 void __delay(unsigned long loops)
30 {
31         unsigned bclock, now;
32
33         preempt_disable();              /* TSC's are pre-cpu */
34         rdtscl(bclock);
35         do {
36                 rep_nop(); 
37                 rdtscl(now);
38         }
39         while ((now-bclock) < loops);
40         preempt_enable();
41 }
42 EXPORT_SYMBOL(__delay);
43
44 inline void __const_udelay(unsigned long xloops)
45 {
46         __delay(((xloops * HZ *
47                 cpu_data(raw_smp_processor_id()).loops_per_jiffy) >> 32) + 1);
48 }
49 EXPORT_SYMBOL(__const_udelay);
50
51 void __udelay(unsigned long usecs)
52 {
53         __const_udelay(usecs * 0x000010c7);  /* 2**32 / 1000000 (rounded up) */
54 }
55 EXPORT_SYMBOL(__udelay);
56
57 void __ndelay(unsigned long nsecs)
58 {
59         __const_udelay(nsecs * 0x00005);  /* 2**32 / 1000000000 (rounded up) */
60 }
61 EXPORT_SYMBOL(__ndelay);