time.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Common time prototypes and such for all ppc machines.
  3. *
  4. * Written by Cort Dougan (cort@cs.nmt.edu) to merge
  5. * Paul Mackerras' version and mine for PReP and Pmac.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #ifndef __PPC64_TIME_H
  13. #define __PPC64_TIME_H
  14. #ifdef __KERNEL__
  15. #include <linux/config.h>
  16. #include <linux/types.h>
  17. #include <linux/mc146818rtc.h>
  18. #include <asm/processor.h>
  19. #include <asm/paca.h>
  20. #include <asm/iSeries/HvCall.h>
  21. /* time.c */
  22. extern unsigned long tb_ticks_per_jiffy;
  23. extern unsigned long tb_ticks_per_usec;
  24. extern unsigned long tb_ticks_per_sec;
  25. extern unsigned long tb_to_xs;
  26. extern unsigned tb_to_us;
  27. extern unsigned long tb_last_stamp;
  28. struct rtc_time;
  29. extern void to_tm(int tim, struct rtc_time * tm);
  30. extern time_t last_rtc_update;
  31. void generic_calibrate_decr(void);
  32. void setup_default_decr(void);
  33. /* Some sane defaults: 125 MHz timebase, 1GHz processor */
  34. extern unsigned long ppc_proc_freq;
  35. #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8)
  36. extern unsigned long ppc_tb_freq;
  37. #define DEFAULT_TB_FREQ 125000000UL
  38. /*
  39. * By putting all of this stuff into a single struct we
  40. * reduce the number of cache lines touched by do_gettimeofday.
  41. * Both by collecting all of the data in one cache line and
  42. * by touching only one TOC entry
  43. */
  44. struct gettimeofday_vars {
  45. unsigned long tb_to_xs;
  46. unsigned long stamp_xsec;
  47. unsigned long tb_orig_stamp;
  48. };
  49. struct gettimeofday_struct {
  50. unsigned long tb_ticks_per_sec;
  51. struct gettimeofday_vars vars[2];
  52. struct gettimeofday_vars * volatile varp;
  53. unsigned var_idx;
  54. unsigned tb_to_us;
  55. };
  56. struct div_result {
  57. unsigned long result_high;
  58. unsigned long result_low;
  59. };
  60. int via_calibrate_decr(void);
  61. static __inline__ unsigned long get_tb(void)
  62. {
  63. return mftb();
  64. }
  65. /* Accessor functions for the decrementer register. */
  66. static __inline__ unsigned int get_dec(void)
  67. {
  68. return (mfspr(SPRN_DEC));
  69. }
  70. static __inline__ void set_dec(int val)
  71. {
  72. #ifdef CONFIG_PPC_ISERIES
  73. struct paca_struct *lpaca = get_paca();
  74. int cur_dec;
  75. if (lpaca->lppaca.shared_proc) {
  76. lpaca->lppaca.virtual_decr = val;
  77. cur_dec = get_dec();
  78. if (cur_dec > val)
  79. HvCall_setVirtualDecr();
  80. } else
  81. #endif
  82. mtspr(SPRN_DEC, val);
  83. }
  84. static inline unsigned long tb_ticks_since(unsigned long tstamp)
  85. {
  86. return get_tb() - tstamp;
  87. }
  88. #define mulhwu(x,y) \
  89. ({unsigned z; asm ("mulhwu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;})
  90. #define mulhdu(x,y) \
  91. ({unsigned long z; asm ("mulhdu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;})
  92. unsigned mulhwu_scale_factor(unsigned, unsigned);
  93. void div128_by_32( unsigned long dividend_high, unsigned long dividend_low,
  94. unsigned divisor, struct div_result *dr );
  95. /* Used to store Processor Utilization register (purr) values */
  96. struct cpu_usage {
  97. u64 current_tb; /* Holds the current purr register values */
  98. };
  99. DECLARE_PER_CPU(struct cpu_usage, cpu_usage_array);
  100. #endif /* __KERNEL__ */
  101. #endif /* __PPC64_TIME_H */