1/* 2 * BK Id: SCCS/s.time.h 1.17 10/23/01 08:09:35 trini 3 */ 4/* 5 * Common time prototypes and such for all ppc machines. 6 * 7 * Written by Cort Dougan (cort@fsmlabs.com) to merge 8 * Paul Mackerras' version and mine for PReP and Pmac. 9 */ 10 11#ifdef __KERNEL__ 12#ifndef __ASM_TIME_H__ 13#define __ASM_TIME_H__ 14 15#include <linux/config.h> 16#include <linux/mc146818rtc.h> 17#include <linux/threads.h> 18 19#include <asm/processor.h> 20 21/* time.c */ 22extern unsigned tb_ticks_per_jiffy; 23extern unsigned tb_to_us; 24extern unsigned tb_last_stamp; 25extern unsigned long disarm_decr[NR_CPUS]; 26 27extern void to_tm(int tim, struct rtc_time * tm); 28extern time_t last_rtc_update; 29 30extern void set_dec_cpu6(unsigned int val); 31 32int via_calibrate_decr(void); 33 34/* Accessor functions for the decrementer register. 35 * The 4xx doesn't even have a decrementer. I tried to use the 36 * generic timer interrupt code, which seems OK, with the 4xx PIT 37 * in auto-reload mode. The problem is PIT stops counting when it 38 * hits zero. If it would wrap, we could use it just like a decrementer. 39 */ 40static __inline__ unsigned int get_dec(void) 41{ 42#if defined(CONFIG_4xx) 43 return (mfspr(SPRN_PIT)); 44#else 45 return (mfspr(SPRN_DEC)); 46#endif 47} 48 49static __inline__ void set_dec(unsigned int val) 50{ 51#if defined(CONFIG_4xx) 52 return; /* Have to let it auto-reload */ 53#elif defined(CONFIG_8xx_CPU6) 54 set_dec_cpu6(val); 55#else 56 mtspr(SPRN_DEC, val); 57#endif 58} 59 60/* Accessor functions for the timebase (RTC on 601) registers. */ 61/* If one day CONFIG_POWER is added just define __USE_RTC as 1 */ 62#ifdef CONFIG_6xx 63extern __inline__ int const __USE_RTC(void) { 64 return (mfspr(SPRN_PVR)>>16) == 1; 65} 66#else 67#define __USE_RTC() 0 68#endif 69 70extern __inline__ unsigned long get_tbl(void) { 71 unsigned long tbl; 72 asm volatile("mftb %0" : "=r" (tbl)); 73 return tbl; 74} 75 76extern __inline__ unsigned long get_tbu(void) { 77 unsigned long tbl; 78 asm volatile("mftbu %0" : "=r" (tbl)); 79 return tbl; 80} 81 82extern __inline__ void set_tb(unsigned int upper, unsigned int lower) 83{ 84 mtspr(SPRN_TBWL, 0); 85 mtspr(SPRN_TBWU, upper); 86 mtspr(SPRN_TBWL, lower); 87} 88 89extern __inline__ unsigned long get_rtcl(void) { 90 unsigned long rtcl; 91 asm volatile("mfrtcl %0" : "=r" (rtcl)); 92 return rtcl; 93} 94 95extern __inline__ unsigned get_native_tbl(void) { 96 if (__USE_RTC()) 97 return get_rtcl(); 98 else 99 return get_tbl(); 100} 101 102/* On machines with RTC, this function can only be used safely 103 * after the timestamp and for 1 second. It is only used by gettimeofday 104 * however so it should not matter. 105 */ 106extern __inline__ unsigned tb_ticks_since(unsigned tstamp) { 107 if (__USE_RTC()) { 108 int delta = get_rtcl() - tstamp; 109 return delta<0 ? delta + 1000000000 : delta; 110 } else { 111 return get_tbl() - tstamp; 112 } 113} 114 115 116/* Use mulhwu to scale processor timebase to timeval */ 117#define mulhwu(x,y) \ 118({unsigned z; asm ("mulhwu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;}) 119 120unsigned mulhwu_scale_factor(unsigned, unsigned); 121#endif /* __ASM_TIME_H__ */ 122#endif /* __KERNEL__ */ 123