timekeeping: Provide timespec64 based interfaces
[firefly-linux-kernel-4.4.55.git] / include / linux / timekeeping.h
1 #ifndef _LINUX_TIMEKEEPING_H
2 #define _LINUX_TIMEKEEPING_H
3
4 /* Included from linux/ktime.h */
5
6 void timekeeping_init(void);
7 extern int timekeeping_suspended;
8
9 /*
10  * Get and set timeofday
11  */
12 extern void do_gettimeofday(struct timeval *tv);
13 extern int do_settimeofday(const struct timespec *tv);
14 extern int do_sys_settimeofday(const struct timespec *tv,
15                                const struct timezone *tz);
16
17 /*
18  * Kernel time accessors
19  */
20 unsigned long get_seconds(void);
21 struct timespec current_kernel_time(void);
22 /* does not take xtime_lock */
23 struct timespec __current_kernel_time(void);
24
25 /*
26  * timespec based interfaces
27  */
28 struct timespec get_monotonic_coarse(void);
29 extern void getrawmonotonic(struct timespec *ts);
30 extern void monotonic_to_bootbased(struct timespec *ts);
31 extern void get_monotonic_boottime(struct timespec *ts);
32 extern void ktime_get_ts64(struct timespec64 *ts);
33
34 extern int __getnstimeofday64(struct timespec64 *tv);
35 extern void getnstimeofday64(struct timespec64 *tv);
36
37 #if BITS_PER_LONG == 64
38 static inline int __getnstimeofday(struct timespec *ts)
39 {
40         return __getnstimeofday64(ts);
41 }
42
43 static inline void getnstimeofday(struct timespec *ts)
44 {
45         getnstimeofday64(ts);
46 }
47
48 static inline void ktime_get_ts(struct timespec *ts)
49 {
50         ktime_get_ts64(ts);
51 }
52
53 static inline void ktime_get_real_ts(struct timespec *ts)
54 {
55         getnstimeofday64(ts);
56 }
57
58 #else
59 static inline int __getnstimeofday(struct timespec *ts)
60 {
61         struct timespec64 ts64;
62         int ret = __getnstimeofday64(&ts64);
63
64         *ts = timespec64_to_timespec(ts64);
65         return ret;
66 }
67
68 static inline void getnstimeofday(struct timespec *ts)
69 {
70         struct timespec64 ts64;
71
72         getnstimeofday64(&ts64);
73         *ts = timespec64_to_timespec(ts64);
74 }
75
76 static inline void ktime_get_ts(struct timespec *ts)
77 {
78         struct timespec64 ts64;
79
80         ktime_get_ts64(&ts64);
81         *ts = timespec64_to_timespec(ts64);
82 }
83
84 static inline void ktime_get_real_ts(struct timespec *ts)
85 {
86         struct timespec64 ts64;
87
88         getnstimeofday64(&ts64);
89         *ts = timespec64_to_timespec(ts64);
90 }
91 #endif
92
93 extern void getboottime(struct timespec *ts);
94
95 #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts)
96 #define ktime_get_real_ts64(ts) getnstimeofday64(ts)
97
98 /*
99  * ktime_t based interfaces
100  */
101 extern ktime_t ktime_get(void);
102 extern ktime_t ktime_get_real(void);
103 extern ktime_t ktime_get_boottime(void);
104 extern ktime_t ktime_get_monotonic_offset(void);
105 extern ktime_t ktime_get_clocktai(void);
106
107 /*
108  * RTC specific
109  */
110 extern void timekeeping_inject_sleeptime(struct timespec *delta);
111
112 /*
113  * PPS accessor
114  */
115 extern void getnstime_raw_and_real(struct timespec *ts_raw,
116                                    struct timespec *ts_real);
117
118 /*
119  * Persistent clock related interfaces
120  */
121 extern bool persistent_clock_exist;
122 extern int persistent_clock_is_local;
123
124 static inline bool has_persistent_clock(void)
125 {
126         return persistent_clock_exist;
127 }
128
129 extern void read_persistent_clock(struct timespec *ts);
130 extern void read_boot_clock(struct timespec *ts);
131 extern int update_persistent_clock(struct timespec now);
132
133
134 #endif