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 <linux/clocksource_ids.h>
21#include <asm/div64.h>
22#include <asm/io.h>
23
24struct clocksource;
25struct module;
26
27#if defined(CONFIG_ARCH_CLOCKSOURCE_DATA) || \
28 defined(CONFIG_GENERIC_GETTIMEOFDAY)
29#include <asm/clocksource.h>
30#endif
31
32#include <vdso/clocksource.h>
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
89
90
91
92
93
94
95
96struct clocksource {
97 u64 (*read)(struct clocksource *cs);
98 u64 mask;
99 u32 mult;
100 u32 shift;
101 u64 max_idle_ns;
102 u32 maxadj;
103 u32 uncertainty_margin;
104#ifdef CONFIG_ARCH_CLOCKSOURCE_DATA
105 struct arch_clocksource_data archdata;
106#endif
107 u64 max_cycles;
108 const char *name;
109 struct list_head list;
110 int rating;
111 enum clocksource_ids id;
112 enum vdso_clock_mode vdso_clock_mode;
113 unsigned long flags;
114
115 int (*enable)(struct clocksource *cs);
116 void (*disable)(struct clocksource *cs);
117 void (*suspend)(struct clocksource *cs);
118 void (*resume)(struct clocksource *cs);
119 void (*mark_unstable)(struct clocksource *cs);
120 void (*tick_stable)(struct clocksource *cs);
121
122
123#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
124
125 struct list_head wd_list;
126 u64 cs_last;
127 u64 wd_last;
128#endif
129 struct module *owner;
130};
131
132
133
134
135#define CLOCK_SOURCE_IS_CONTINUOUS 0x01
136#define CLOCK_SOURCE_MUST_VERIFY 0x02
137
138#define CLOCK_SOURCE_WATCHDOG 0x10
139#define CLOCK_SOURCE_VALID_FOR_HRES 0x20
140#define CLOCK_SOURCE_UNSTABLE 0x40
141#define CLOCK_SOURCE_SUSPEND_NONSTOP 0x80
142#define CLOCK_SOURCE_RESELECT 0x100
143#define CLOCK_SOURCE_VERIFY_PERCPU 0x200
144
145#define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
146
147static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
148{
149
150
151
152
153
154
155
156 u64 tmp = ((u64)from) << shift_constant;
157
158 tmp += freq/2;
159 do_div(tmp, freq);
160
161 return (u32)tmp;
162}
163
164
165
166
167
168
169
170
171
172static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
173{
174 return clocksource_freq2mult(khz, shift_constant, NSEC_PER_MSEC);
175}
176
177
178
179
180
181
182
183
184
185
186static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
187{
188 return clocksource_freq2mult(hz, shift_constant, NSEC_PER_SEC);
189}
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204static inline s64 clocksource_cyc2ns(u64 cycles, u32 mult, u32 shift)
205{
206 return ((u64) cycles * mult) >> shift;
207}
208
209
210extern int clocksource_unregister(struct clocksource*);
211extern void clocksource_touch_watchdog(void);
212extern void clocksource_change_rating(struct clocksource *cs, int rating);
213extern void clocksource_suspend(void);
214extern void clocksource_resume(void);
215extern struct clocksource * __init clocksource_default_clock(void);
216extern void clocksource_mark_unstable(struct clocksource *cs);
217extern void
218clocksource_start_suspend_timing(struct clocksource *cs, u64 start_cycles);
219extern u64 clocksource_stop_suspend_timing(struct clocksource *cs, u64 now);
220
221extern u64
222clocks_calc_max_nsecs(u32 mult, u32 shift, u32 maxadj, u64 mask, u64 *max_cycles);
223extern void
224clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
225
226
227
228
229
230extern int
231__clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
232extern void
233__clocksource_update_freq_scale(struct clocksource *cs, u32 scale, u32 freq);
234
235
236
237
238
239static inline int __clocksource_register(struct clocksource *cs)
240{
241 return __clocksource_register_scale(cs, 1, 0);
242}
243
244static inline int clocksource_register_hz(struct clocksource *cs, u32 hz)
245{
246 return __clocksource_register_scale(cs, 1, hz);
247}
248
249static inline int clocksource_register_khz(struct clocksource *cs, u32 khz)
250{
251 return __clocksource_register_scale(cs, 1000, khz);
252}
253
254static inline void __clocksource_update_freq_hz(struct clocksource *cs, u32 hz)
255{
256 __clocksource_update_freq_scale(cs, 1, hz);
257}
258
259static inline void __clocksource_update_freq_khz(struct clocksource *cs, u32 khz)
260{
261 __clocksource_update_freq_scale(cs, 1000, khz);
262}
263
264#ifdef CONFIG_ARCH_CLOCKSOURCE_INIT
265extern void clocksource_arch_init(struct clocksource *cs);
266#else
267static inline void clocksource_arch_init(struct clocksource *cs) { }
268#endif
269
270extern int timekeeping_notify(struct clocksource *clock);
271
272extern u64 clocksource_mmio_readl_up(struct clocksource *);
273extern u64 clocksource_mmio_readl_down(struct clocksource *);
274extern u64 clocksource_mmio_readw_up(struct clocksource *);
275extern u64 clocksource_mmio_readw_down(struct clocksource *);
276
277extern int clocksource_mmio_init(void __iomem *, const char *,
278 unsigned long, int, unsigned, u64 (*)(struct clocksource *));
279
280extern int clocksource_i8253_init(void);
281
282#define TIMER_OF_DECLARE(name, compat, fn) \
283 OF_DECLARE_1_RET(timer, name, compat, fn)
284
285#ifdef CONFIG_TIMER_PROBE
286extern void timer_probe(void);
287#else
288static inline void timer_probe(void) {}
289#endif
290
291#define TIMER_ACPI_DECLARE(name, table_id, fn) \
292 ACPI_DECLARE_PROBE_ENTRY(timer, name, table_id, 0, NULL, 0, fn)
293
294extern ulong max_cswd_read_retries;
295void clocksource_verify_percpu(struct clocksource *cs);
296
297#endif
298