2 * Precise Delay Loops for i386
4 * Copyright (C) 1993 Linus Torvalds
5 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
7 * The __delay function must _NOT_ be inlined as its execution time
8 * depends wildly on alignment on many x86 processors. The additional
9 * jump magic is needed to get the timing stable on all the CPU's
10 * we have to worry about.
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/delay.h>
16 #include <asm/processor.h>
17 #include <asm/delay.h>
23 int x86_udelay_tsc = 0; /* Delay via TSC */
27 * Do a udelay using the TSC for any CPU that happens
28 * to have one that we trust.
31 static void __rdtsc_delay(unsigned long loops)
33 unsigned long bclock, now;
40 } while ((now-bclock) < loops);
44 * Non TSC based delay loop for 386, 486, MediaGX
47 static void __loop_delay(unsigned long loops)
55 "2:\tdecl %0\n\tjns 2b"
59 extern void __cyclone_delay(unsigned long loops);
60 extern int use_cyclone;
61 void __delay(unsigned long loops)
64 __cyclone_delay(loops);
65 else if (x86_udelay_tsc)
71 inline void __const_udelay(unsigned long xloops)
75 :"=d" (xloops), "=&a" (d0)
76 :"1" (xloops),"0" (current_cpu_data.loops_per_jiffy));
80 void __udelay(unsigned long usecs)
82 __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
85 void __ndelay(unsigned long nsecs)
87 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */