1 /* $Id: delay.h,v 1.12.2.1 2002/02/02 02:11:52 kanoj Exp $
2  * delay.h: Linux delay routines on the V9.
3  *
4  * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu).
5  */
6 
7 #ifndef __SPARC64_DELAY_H
8 #define __SPARC64_DELAY_H
9 
10 #include <linux/config.h>
11 #include <linux/param.h>
12 
13 #ifndef __ASSEMBLY__
14 
15 #ifdef CONFIG_SMP
16 #include <asm/smp.h>
17 #else
18 extern unsigned long loops_per_jiffy;
19 #endif
20 
__delay(unsigned long loops)21 extern __inline__ void __delay(unsigned long loops)
22 {
23 	__asm__ __volatile__(
24 "	b,pt	%%xcc, 1f\n"
25 "	 cmp	%0, 0\n"
26 "	.align	32\n"
27 "1:\n"
28 "	bne,pt	%%xcc, 1b\n"
29 "	 subcc	%0, 1, %0\n"
30 	: "=&r" (loops)
31 	: "0" (loops)
32 	: "cc");
33 }
34 
__udelay(unsigned long usecs,unsigned long lps)35 extern __inline__ void __udelay(unsigned long usecs, unsigned long lps)
36 {
37 	usecs *= 0x00000000000010c6UL;		/* 2**32 / 1000000 */
38 
39 	__asm__ __volatile__(
40 "	mulx	%1, %2, %0\n"
41 "	srlx	%0, 32, %0\n"
42 	: "=r" (usecs)
43 	: "r" (usecs), "r" (lps));
44 
45 	__delay(usecs * HZ);
46 }
47 
__ndelay(unsigned long usecs,unsigned long lps)48 extern __inline__ void __ndelay(unsigned long usecs, unsigned long lps)
49 {
50 	usecs *= 0x0000000000000005UL;		/* 2**32 / 10000 */
51 
52 	__asm__ __volatile__(
53 "	mulx	%1, %2, %0\n"
54 "	srlx	%0, 32, %0\n"
55 	: "=r" (usecs)
56 	: "r" (usecs), "r" (lps));
57 
58 	__delay(usecs * HZ);
59 }
60 
61 #ifdef CONFIG_SMP
62 #define __udelay_val cpu_data[smp_processor_id()].udelay_val
63 #else
64 #define __udelay_val loops_per_jiffy
65 #endif
66 
67 #define udelay(usecs) __udelay((usecs),__udelay_val)
68 #define ndelay(usecs) __ndelay((usecs),__udelay_val)
69 
70 #endif /* !__ASSEMBLY__ */
71 
72 #endif /* defined(__SPARC64_DELAY_H) */
73