1
2
3
4
5
6
7
8
9#ifndef _LINUX_CLOCKSOURCE_H
10#define _LINUX_CLOCKSOURCE_H
11
12#include <linux/types.h>
13#include <linux/timex.h>
14#include <linux/time.h>
15#include <linux/list.h>
16#include <linux/cache.h>
17#include <linux/timer.h>
18#include <linux/init.h>
19#include <linux/of.h>
20#include <asm/div64.h>
21#include <asm/io.h>
22
23struct clocksource;
24struct module;
25
26#if defined(CONFIG_ARCH_CLOCKSOURCE_DATA) || \
27 defined(CONFIG_GENERIC_GETTIMEOFDAY)
28#include <asm/clocksource.h>
29#endif
30
31#include <vdso/clocksource.h>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89struct clocksource {
90 u64 (*read)(struct clocksource *cs);
91 u64 mask;
92 u32 mult;
93 u32 shift;
94 u64 max_idle_ns;
95 u32 maxadj;
96#ifdef CONFIG_ARCH_CLOCKSOURCE_DATA
97 struct arch_clocksource_data archdata;
98#endif
99 u64 max_cycles;
100 const char *name;
101 struct list_head list;
102 int rating;
103 enum vdso_clock_mode vdso_clock_mode;
104 unsigned long flags;
105
106 int (*enable)(struct clocksource *cs);
107 void (*disable)(struct clocksource *cs);
108 void (*suspend)(struct clocksource *cs);
109 void (*resume)(struct clocksource *cs);
110 void (*mark_unstable)(struct clocksource *cs);
111 void (*tick_stable)(struct clocksource *cs);
112
113
114#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
115
116 struct list_head wd_list;
117 u64 cs_last;
118 u64 wd_last;
119#endif
120 struct module *owner;
121};
122
123
124
125
126#define CLOCK_SOURCE_IS_CONTINUOUS 0x01
127#define CLOCK_SOURCE_MUST_VERIFY 0x02
128
129#define CLOCK_SOURCE_WATCHDOG 0x10
130#define CLOCK_SOURCE_VALID_FOR_HRES 0x20
131#define CLOCK_SOURCE_UNSTABLE 0x40
132#define CLOCK_SOURCE_SUSPEND_NONSTOP 0x80
133#define CLOCK_SOURCE_RESELECT 0x100
134
135
136#define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
137
138static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
139{
140
141
142
143
144
145
146
147 u64 tmp = ((u64)from) << shift_constant;
148
149 tmp += freq/2;
150 do_div(tmp, freq);
151
152 return (u32)tmp;
153}
154
155
156
157
158
159
160
161
162
163static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
164{
165 return clocksource_freq2mult(khz, shift_constant, NSEC_PER_MSEC);
166}
167
168
169
170
171
172
173
174
175
176
177static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
178{
179 return clocksource_freq2mult(hz, shift_constant, NSEC_PER_SEC);
180}
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195static inline s64 clocksource_cyc2ns(u64 cycles, u32 mult, u32 shift)
196{
197 return ((u64) cycles * mult) >> shift;
198}
199
200
201extern int clocksource_unregister(struct clocksource*);
202extern void clocksource_touch_watchdog(void);
203extern void clocksource_change_rating(struct clocksource *cs, int rating);
204extern void clocksource_suspend(void);
205extern void clocksource_resume(void);
206extern struct clocksource * __init clocksource_default_clock(void);
207extern void clocksource_mark_unstable(struct clocksource *cs);
208extern void
209clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles);
210extern u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 now);
211
212extern u64
213clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask, u64 *max_cycles);
214extern void
215clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
216
217
218
219
220
221extern int
222__clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
223extern void
224__clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq);
225
226
227
228
229
230static inline int __clocksource_register(struct clocksource *cs)
231{
232 return __clocksource_register_scale(cs, 1, 0);
233}
234
235static inline int clocksource_register_hz(struct clocksource *cs, u32 hz)
236{
237 return __clocksource_register_scale(cs, 1, hz);
238}
239
240static inline int clocksource_register_khz(struct clocksource *cs, u32 khz)
241{
242 return __clocksource_register_scale(cs, 1000, khz);
243}
244
245static inline void __clocksource_update_freq_hz(struct clocksource *cs, u32 hz)
246{
247 __clocksource_update_freq_scale(cs, 1, hz);
248}
249
250static inline void __clocksource_update_freq_khz(struct clocksource *cs, u32 khz)
251{
252 __clocksource_update_freq_scale(cs, 1000, khz);
253}
254
255#ifdef CONFIG_ARCH_CLOCKSOURCE_INIT
256extern void clocksource_arch_init(struct clocksource *cs);
257#else
258static inline void clocksource_arch_init(struct clocksource *cs) { }
259#endif
260
261extern int timekeeping_notify(struct clocksource *clock);
262
263extern u64 clocksource_mmio_readl_up(struct clocksource *);
264extern u64 clocksource_mmio_readl_down(struct clocksource *);
265extern u64 clocksource_mmio_readw_up(struct clocksource *);
266extern u64 clocksource_mmio_readw_down(struct clocksource *);
267
268extern int clocksource_mmio_init(void __iomem *, const char *,
269 unsigned long, int, unsigned, u64 (*)(struct clocksource *));
270
271extern int clocksource_i8253_init(void);
272
273#define TIMER_OF_DECLARE(name, compat, fn) \
274 OF_DECLARE_1_RET(timer, name, compat, fn)
275
276#ifdef CONFIG_TIMER_PROBE
277extern void timer_probe(void);
278#else
279static inline void timer_probe(void) {}
280#endif
281
282#define TIMER_ACPI_DECLARE(name, table_id, fn) \
283 ACPI_DECLARE_PROBE_ENTRY(timer, name, table_id, 0, NULL, 0, fn)
284
285#endif
286