1 /*
2 * Copyright (C) 1993, 2000 Linus Torvalds
3 *
4 * Delay routines, using a pre-computed "loops_per_jiffy" value.
5 */
6 #include <linux/config.h>
7 #include <linux/sched.h>
8 #include <asm/param.h>
9 #include <asm/smp.h>
10 #include <linux/delay.h>
11
12 /*
13 * Use only for very small delays (< 1 msec).
14 *
15 * The active part of our cycle counter is only 32-bits wide, and
16 * we're treating the difference between two marks as signed. On
17 * a 1GHz box, that's about 2 seconds.
18 */
19
__delay(int loops)20 void __delay(int loops)
21 {
22 long long dummy;
23 __asm__ __volatile__("gettr " __t0 ", %1\n\t"
24 "_pta 4, " __t0 "\n\t"
25 "addi %0, -1, %0\n\t"
26 "bne %0, r63, " __t0 "\n\t"
27 "ptabs %1, " __t0 "\n\t":"=r"(loops),
28 "=r"(dummy)
29 :"0"(loops));
30 }
31
__udelay(unsigned long long usecs,unsigned long lpj)32 void __udelay(unsigned long long usecs, unsigned long lpj)
33 {
34 usecs *= (((unsigned long long) HZ << 32) / 1000000) * lpj;
35 __delay((long long) usecs >> 32);
36 }
37
__ndelay(unsigned long long nsecs,unsigned long lpj)38 void __ndelay(unsigned long long nsecs, unsigned long lpj)
39 {
40 nsecs *= (((unsigned long long) HZ << 32) / 1000000000) * lpj;
41 __delay((long long) nsecs >> 32);
42 }
43
udelay(unsigned long usecs)44 void udelay(unsigned long usecs)
45 {
46 __udelay(usecs, loops_per_jiffy);
47 }
48
ndelay(unsigned long nsecs)49 void ndelay(unsigned long nsecs)
50 {
51 __ndelay(nsecs, loops_per_jiffy);
52 }
53
54