2 * Common time prototypes and such for all ppc machines.
4 * Written by Cort Dougan (cort@fsmlabs.com) to merge
5 * Paul Mackerras' version and mine for PReP and Pmac.
10 #define __ASM_TIME_H__
12 #include <linux/types.h>
13 #include <linux/rtc.h>
14 #include <linux/threads.h>
19 extern unsigned tb_ticks_per_jiffy;
20 extern unsigned tb_to_us;
21 extern unsigned tb_last_stamp;
22 extern unsigned long disarm_decr[NR_CPUS];
24 extern void to_tm(int tim, struct rtc_time * tm);
25 extern time_t last_rtc_update;
27 extern void set_dec_cpu6(unsigned int val);
29 int via_calibrate_decr(void);
31 /* Accessor functions for the decrementer register.
32 * The 4xx doesn't even have a decrementer. I tried to use the
33 * generic timer interrupt code, which seems OK, with the 4xx PIT
34 * in auto-reload mode. The problem is PIT stops counting when it
35 * hits zero. If it would wrap, we could use it just like a decrementer.
37 static __inline__ unsigned int get_dec(void)
39 #if defined(CONFIG_40x)
40 return (mfspr(SPRN_PIT));
42 return (mfspr(SPRN_DEC));
46 static __inline__ void set_dec(unsigned int val)
48 #if defined(CONFIG_40x)
49 return; /* Have to let it auto-reload */
50 #elif defined(CONFIG_8xx_CPU6)
57 /* Accessor functions for the timebase (RTC on 601) registers. */
58 /* If one day CONFIG_POWER is added just define __USE_RTC as 1 */
60 extern __inline__ int __attribute_pure__ __USE_RTC(void) {
61 return (mfspr(SPRN_PVR)>>16) == 1;
67 extern __inline__ unsigned long get_tbl(void) {
69 #if defined(CONFIG_403GCX)
70 asm volatile("mfspr %0, 0x3dd" : "=r" (tbl));
72 asm volatile("mftb %0" : "=r" (tbl));
77 extern __inline__ unsigned long get_tbu(void) {
79 #if defined(CONFIG_403GCX)
80 asm volatile("mfspr %0, 0x3dc" : "=r" (tbl));
82 asm volatile("mftbu %0" : "=r" (tbl));
87 extern __inline__ void set_tb(unsigned int upper, unsigned int lower)
90 mtspr(SPRN_TBWU, upper);
91 mtspr(SPRN_TBWL, lower);
94 extern __inline__ unsigned long get_rtcl(void) {
96 asm volatile("mfrtcl %0" : "=r" (rtcl));
100 extern __inline__ unsigned long get_rtcu(void)
103 asm volatile("mfrtcu %0" : "=r" (rtcu));
107 extern __inline__ unsigned get_native_tbl(void) {
114 /* On machines with RTC, this function can only be used safely
115 * after the timestamp and for 1 second. It is only used by gettimeofday
116 * however so it should not matter.
118 extern __inline__ unsigned tb_ticks_since(unsigned tstamp) {
120 int delta = get_rtcl() - tstamp;
121 return delta<0 ? delta + 1000000000 : delta;
123 return get_tbl() - tstamp;
128 extern __inline__ unsigned long get_bin_rtcl(void) {
129 unsigned long rtcl, rtcu1, rtcu2;
136 : "=r" (rtcu1), "=r" (rtcl), "=r" (rtcu2)
138 return rtcu2*1000000000+rtcl;
141 extern __inline__ unsigned binary_tbl(void) {
143 return get_bin_rtcl();
149 /* Use mulhwu to scale processor timebase to timeval */
150 /* Specifically, this computes (x * y) / 2^32. -- paulus */
151 #define mulhwu(x,y) \
152 ({unsigned z; asm ("mulhwu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;})
154 unsigned mulhwu_scale_factor(unsigned, unsigned);
156 #define account_process_vtime(tsk) do { } while (0)
157 #define calculate_steal_time() do { } while (0)
158 #define snapshot_timebases() do { } while (0)
160 #endif /* __ASM_TIME_H__ */
161 #endif /* __KERNEL__ */