ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-ia64 / delay.h
1 #ifndef _ASM_IA64_DELAY_H
2 #define _ASM_IA64_DELAY_H
3
4 /*
5  * Delay routines using a pre-computed "cycles/usec" value.
6  *
7  * Copyright (C) 1998, 1999 Hewlett-Packard Co
8  *      David Mosberger-Tang <davidm@hpl.hp.com>
9  * Copyright (C) 1999 VA Linux Systems
10  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
11  * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
12  * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
13  */
14
15 #include <linux/config.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/compiler.h>
19
20 #include <asm/intrinsics.h>
21 #include <asm/processor.h>
22
23 static __inline__ void
24 ia64_set_itm (unsigned long val)
25 {
26         ia64_setreg(_IA64_REG_CR_ITM, val);
27         ia64_srlz_d();
28 }
29
30 static __inline__ unsigned long
31 ia64_get_itm (void)
32 {
33         unsigned long result;
34
35         result = ia64_getreg(_IA64_REG_CR_ITM);
36         ia64_srlz_d();
37         return result;
38 }
39
40 static __inline__ void
41 ia64_set_itv (unsigned long val)
42 {
43         ia64_setreg(_IA64_REG_CR_ITV, val);
44         ia64_srlz_d();
45 }
46
47 static __inline__ void
48 ia64_set_itc (unsigned long val)
49 {
50         ia64_setreg(_IA64_REG_AR_ITC, val);
51         ia64_srlz_d();
52 }
53
54 static __inline__ unsigned long
55 ia64_get_itc (void)
56 {
57         unsigned long result;
58
59         result = ia64_getreg(_IA64_REG_AR_ITC);
60         ia64_barrier();
61 #ifdef CONFIG_ITANIUM
62         while (unlikely((__s32) result == -1)) {
63                 result = ia64_getreg(_IA64_REG_AR_ITC);
64                 ia64_barrier();
65         }
66 #endif
67         return result;
68 }
69
70 extern void ia64_delay_loop (unsigned long loops);
71
72 static __inline__ void
73 __delay (unsigned long loops)
74 {
75         if (unlikely(loops < 1))
76                 return;
77
78         ia64_delay_loop (loops - 1);
79 }
80
81 static __inline__ void
82 udelay (unsigned long usecs)
83 {
84         unsigned long start = ia64_get_itc();
85         unsigned long cycles = usecs*local_cpu_data->cyc_per_usec;
86
87         while (ia64_get_itc() - start < cycles)
88                 /* skip */;
89 }
90
91 #endif /* _ASM_IA64_DELAY_H */