1
2
3
4
5
6
7
8#ifndef _LINUX_CLOCKCHIPS_H
9#define _LINUX_CLOCKCHIPS_H
10
11
12enum clock_event_nofitiers {
13 CLOCK_EVT_NOTIFY_ADD,
14 CLOCK_EVT_NOTIFY_BROADCAST_ON,
15 CLOCK_EVT_NOTIFY_BROADCAST_OFF,
16 CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
17 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
18 CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
19 CLOCK_EVT_NOTIFY_SUSPEND,
20 CLOCK_EVT_NOTIFY_RESUME,
21 CLOCK_EVT_NOTIFY_CPU_DYING,
22 CLOCK_EVT_NOTIFY_CPU_DEAD,
23};
24
25#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
26
27#include <linux/clocksource.h>
28#include <linux/cpumask.h>
29#include <linux/ktime.h>
30#include <linux/notifier.h>
31
32struct clock_event_device;
33struct module;
34
35
36enum clock_event_mode {
37 CLOCK_EVT_MODE_UNUSED = 0,
38 CLOCK_EVT_MODE_SHUTDOWN,
39 CLOCK_EVT_MODE_PERIODIC,
40 CLOCK_EVT_MODE_ONESHOT,
41 CLOCK_EVT_MODE_RESUME,
42};
43
44
45
46
47#define CLOCK_EVT_FEAT_PERIODIC 0x000001
48#define CLOCK_EVT_FEAT_ONESHOT 0x000002
49#define CLOCK_EVT_FEAT_KTIME 0x000004
50
51
52
53
54
55
56#define CLOCK_EVT_FEAT_C3STOP 0x000008
57#define CLOCK_EVT_FEAT_DUMMY 0x000010
58
59
60
61
62#define CLOCK_EVT_FEAT_DYNIRQ 0x000020
63#define CLOCK_EVT_FEAT_PERCPU 0x000040
64
65
66
67
68#define CLOCK_EVT_FEAT_HRTIMER 0x000080
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 clock_event_device {
97 void (*event_handler)(struct clock_event_device *);
98 int (*set_next_event)(unsigned long evt,
99 struct clock_event_device *);
100 int (*set_next_ktime)(ktime_t expires,
101 struct clock_event_device *);
102 ktime_t next_event;
103 u64 max_delta_ns;
104 u64 min_delta_ns;
105 u32 mult;
106 u32 shift;
107 enum clock_event_mode mode;
108 unsigned int features;
109 unsigned long retries;
110
111 void (*broadcast)(const struct cpumask *mask);
112 void (*set_mode)(enum clock_event_mode mode,
113 struct clock_event_device *);
114 void (*suspend)(struct clock_event_device *);
115 void (*resume)(struct clock_event_device *);
116 unsigned long min_delta_ticks;
117 unsigned long max_delta_ticks;
118
119 const char *name;
120 int rating;
121 int irq;
122 int bound_on;
123 const struct cpumask *cpumask;
124 struct list_head list;
125 struct module *owner;
126} ____cacheline_aligned;
127
128
129
130
131
132
133
134
135
136
137
138
139static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
140 int shift)
141{
142 uint64_t tmp = ((uint64_t)ticks) << shift;
143
144 do_div(tmp, nsec);
145 return (unsigned long) tmp;
146}
147
148
149extern u64 clockevent_delta2ns(unsigned long latch,
150 struct clock_event_device *evt);
151extern void clockevents_register_device(struct clock_event_device *dev);
152extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
153
154extern void clockevents_config(struct clock_event_device *dev, u32 freq);
155extern void clockevents_config_and_register(struct clock_event_device *dev,
156 u32 freq, unsigned long min_delta,
157 unsigned long max_delta);
158
159extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
160
161extern void clockevents_exchange_device(struct clock_event_device *old,
162 struct clock_event_device *new);
163extern void clockevents_set_mode(struct clock_event_device *dev,
164 enum clock_event_mode mode);
165extern int clockevents_program_event(struct clock_event_device *dev,
166 ktime_t expires, bool force);
167
168extern void clockevents_handle_noop(struct clock_event_device *dev);
169
170static inline void
171clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
172{
173 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
174 freq, minsec);
175}
176
177extern void clockevents_suspend(void);
178extern void clockevents_resume(void);
179
180#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
181#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
182extern void tick_broadcast(const struct cpumask *mask);
183#else
184#define tick_broadcast NULL
185#endif
186extern int tick_receive_broadcast(void);
187#endif
188
189#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
190extern void tick_setup_hrtimer_broadcast(void);
191extern int tick_check_broadcast_expired(void);
192#else
193static inline int tick_check_broadcast_expired(void) { return 0; }
194static inline void tick_setup_hrtimer_broadcast(void) {};
195#endif
196
197#ifdef CONFIG_GENERIC_CLOCKEVENTS
198extern int clockevents_notify(unsigned long reason, void *arg);
199#else
200static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
201#endif
202
203#else
204
205static inline void clockevents_suspend(void) {}
206static inline void clockevents_resume(void) {}
207
208static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
209static inline int tick_check_broadcast_expired(void) { return 0; }
210static inline void tick_setup_hrtimer_broadcast(void) {};
211
212#endif
213
214#endif
215