Commit | Line | Data |
---|---|---|
d316c57f TG |
1 | /* linux/include/linux/clockchips.h |
2 | * | |
3 | * This file contains the structure definitions for clockchips. | |
4 | * | |
5 | * If you are not a clockchip, or the time of day code, you should | |
6 | * not be including this file! | |
7 | */ | |
8 | #ifndef _LINUX_CLOCKCHIPS_H | |
9 | #define _LINUX_CLOCKCHIPS_H | |
10 | ||
9f083b74 | 11 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
d316c57f | 12 | |
9eed56e8 IM |
13 | # include <linux/clocksource.h> |
14 | # include <linux/cpumask.h> | |
15 | # include <linux/ktime.h> | |
16 | # include <linux/notifier.h> | |
d316c57f TG |
17 | |
18 | struct clock_event_device; | |
ccf33d68 | 19 | struct module; |
d316c57f | 20 | |
77e32c89 | 21 | /* Clock event mode commands for legacy ->set_mode(): OBSOLETE */ |
d316c57f | 22 | enum clock_event_mode { |
9eed56e8 | 23 | CLOCK_EVT_MODE_UNUSED, |
d316c57f TG |
24 | CLOCK_EVT_MODE_SHUTDOWN, |
25 | CLOCK_EVT_MODE_PERIODIC, | |
26 | CLOCK_EVT_MODE_ONESHOT, | |
18de5bc4 | 27 | CLOCK_EVT_MODE_RESUME, |
77e32c89 | 28 | }; |
bd624d75 | 29 | |
77e32c89 VK |
30 | /* |
31 | * Possible states of a clock event device. | |
32 | * | |
33 | * DETACHED: Device is not used by clockevents core. Initial state or can be | |
34 | * reached from SHUTDOWN. | |
35 | * SHUTDOWN: Device is powered-off. Can be reached from PERIODIC or ONESHOT. | |
36 | * PERIODIC: Device is programmed to generate events periodically. Can be | |
37 | * reached from DETACHED or SHUTDOWN. | |
38 | * ONESHOT: Device is programmed to generate event only once. Can be reached | |
39 | * from DETACHED or SHUTDOWN. | |
8fff52fd VK |
40 | * ONESHOT_STOPPED: Device was programmed in ONESHOT mode and is temporarily |
41 | * stopped. | |
77e32c89 VK |
42 | */ |
43 | enum clock_event_state { | |
9eed56e8 | 44 | CLOCK_EVT_STATE_DETACHED, |
77e32c89 VK |
45 | CLOCK_EVT_STATE_SHUTDOWN, |
46 | CLOCK_EVT_STATE_PERIODIC, | |
47 | CLOCK_EVT_STATE_ONESHOT, | |
8fff52fd | 48 | CLOCK_EVT_STATE_ONESHOT_STOPPED, |
d316c57f TG |
49 | }; |
50 | ||
d316c57f TG |
51 | /* |
52 | * Clock event features | |
53 | */ | |
9eed56e8 IM |
54 | # define CLOCK_EVT_FEAT_PERIODIC 0x000001 |
55 | # define CLOCK_EVT_FEAT_ONESHOT 0x000002 | |
56 | # define CLOCK_EVT_FEAT_KTIME 0x000004 | |
57 | ||
d316c57f | 58 | /* |
9eed56e8 | 59 | * x86(64) specific (mis)features: |
d316c57f TG |
60 | * |
61 | * - Clockevent source stops in C3 State and needs broadcast support. | |
62 | * - Local APIC timer is used as a dummy device. | |
63 | */ | |
9eed56e8 IM |
64 | # define CLOCK_EVT_FEAT_C3STOP 0x000008 |
65 | # define CLOCK_EVT_FEAT_DUMMY 0x000010 | |
d316c57f | 66 | |
d2348fb6 DL |
67 | /* |
68 | * Core shall set the interrupt affinity dynamically in broadcast mode | |
69 | */ | |
9eed56e8 IM |
70 | # define CLOCK_EVT_FEAT_DYNIRQ 0x000020 |
71 | # define CLOCK_EVT_FEAT_PERCPU 0x000040 | |
d2348fb6 | 72 | |
5d1638ac PM |
73 | /* |
74 | * Clockevent device is based on a hrtimer for broadcast | |
75 | */ | |
9eed56e8 | 76 | # define CLOCK_EVT_FEAT_HRTIMER 0x000080 |
5d1638ac | 77 | |
d316c57f TG |
78 | /** |
79 | * struct clock_event_device - clock event device descriptor | |
847b2f42 TG |
80 | * @event_handler: Assigned by the framework to be called by the low |
81 | * level handler of the event source | |
65516f8a MS |
82 | * @set_next_event: set next event function using a clocksource delta |
83 | * @set_next_ktime: set next event function using a direct ktime value | |
847b2f42 | 84 | * @next_event: local storage for the next event in oneshot mode |
d316c57f TG |
85 | * @max_delta_ns: maximum delta value in ns |
86 | * @min_delta_ns: minimum delta value in ns | |
87 | * @mult: nanosecond to cycles multiplier | |
88 | * @shift: nanoseconds to cycles divisor (power of two) | |
77e32c89 | 89 | * @mode: operating mode, relevant only to ->set_mode(), OBSOLETE |
be3ef76e | 90 | * @state_use_accessors:current state of the device, assigned by the core code |
847b2f42 TG |
91 | * @features: features |
92 | * @retries: number of forced programming retries | |
bd624d75 | 93 | * @set_mode: legacy set mode function, only for modes <= CLOCK_EVT_MODE_RESUME. |
77e32c89 VK |
94 | * @set_state_periodic: switch state to periodic, if !set_mode |
95 | * @set_state_oneshot: switch state to oneshot, if !set_mode | |
8fff52fd | 96 | * @set_state_oneshot_stopped: switch state to oneshot_stopped, if !set_mode |
77e32c89 | 97 | * @set_state_shutdown: switch state to shutdown, if !set_mode |
554ef387 | 98 | * @tick_resume: resume clkevt device, if !set_mode |
847b2f42 | 99 | * @broadcast: function to broadcast events |
57f0fcbe TG |
100 | * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration |
101 | * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration | |
847b2f42 | 102 | * @name: ptr to clock event name |
d316c57f | 103 | * @rating: variable to rate clock event devices |
ce0be127 | 104 | * @irq: IRQ number (only for non CPU local devices) |
5d1638ac | 105 | * @bound_on: Bound on CPU |
ce0be127 | 106 | * @cpumask: cpumask to indicate for which CPUs this device works |
d316c57f | 107 | * @list: list head for the management code |
ccf33d68 | 108 | * @owner: module reference |
d316c57f TG |
109 | */ |
110 | struct clock_event_device { | |
847b2f42 | 111 | void (*event_handler)(struct clock_event_device *); |
9eed56e8 IM |
112 | int (*set_next_event)(unsigned long evt, struct clock_event_device *); |
113 | int (*set_next_ktime)(ktime_t expires, struct clock_event_device *); | |
847b2f42 | 114 | ktime_t next_event; |
97813f2f JH |
115 | u64 max_delta_ns; |
116 | u64 min_delta_ns; | |
23af368e TG |
117 | u32 mult; |
118 | u32 shift; | |
847b2f42 | 119 | enum clock_event_mode mode; |
be3ef76e | 120 | enum clock_event_state state_use_accessors; |
847b2f42 TG |
121 | unsigned int features; |
122 | unsigned long retries; | |
123 | ||
bd624d75 | 124 | /* |
77e32c89 | 125 | * State transition callback(s): Only one of the two groups should be |
bd624d75 VK |
126 | * defined: |
127 | * - set_mode(), only for modes <= CLOCK_EVT_MODE_RESUME. | |
8fff52fd | 128 | * - set_state_{shutdown|periodic|oneshot|oneshot_stopped}(), tick_resume(). |
bd624d75 | 129 | */ |
9eed56e8 | 130 | void (*set_mode)(enum clock_event_mode mode, struct clock_event_device *); |
77e32c89 VK |
131 | int (*set_state_periodic)(struct clock_event_device *); |
132 | int (*set_state_oneshot)(struct clock_event_device *); | |
8fff52fd | 133 | int (*set_state_oneshot_stopped)(struct clock_event_device *); |
77e32c89 | 134 | int (*set_state_shutdown)(struct clock_event_device *); |
554ef387 | 135 | int (*tick_resume)(struct clock_event_device *); |
bd624d75 VK |
136 | |
137 | void (*broadcast)(const struct cpumask *mask); | |
adc78e6b RW |
138 | void (*suspend)(struct clock_event_device *); |
139 | void (*resume)(struct clock_event_device *); | |
57f0fcbe TG |
140 | unsigned long min_delta_ticks; |
141 | unsigned long max_delta_ticks; | |
142 | ||
847b2f42 | 143 | const char *name; |
d316c57f TG |
144 | int rating; |
145 | int irq; | |
5d1638ac | 146 | int bound_on; |
320ab2b0 | 147 | const struct cpumask *cpumask; |
d316c57f | 148 | struct list_head list; |
ccf33d68 | 149 | struct module *owner; |
847b2f42 | 150 | } ____cacheline_aligned; |
d316c57f | 151 | |
3434d23b VK |
152 | /* Helpers to verify state of a clockevent device */ |
153 | static inline bool clockevent_state_detached(struct clock_event_device *dev) | |
154 | { | |
be3ef76e | 155 | return dev->state_use_accessors == CLOCK_EVT_STATE_DETACHED; |
3434d23b VK |
156 | } |
157 | ||
158 | static inline bool clockevent_state_shutdown(struct clock_event_device *dev) | |
159 | { | |
be3ef76e | 160 | return dev->state_use_accessors == CLOCK_EVT_STATE_SHUTDOWN; |
3434d23b VK |
161 | } |
162 | ||
163 | static inline bool clockevent_state_periodic(struct clock_event_device *dev) | |
164 | { | |
be3ef76e | 165 | return dev->state_use_accessors == CLOCK_EVT_STATE_PERIODIC; |
3434d23b VK |
166 | } |
167 | ||
168 | static inline bool clockevent_state_oneshot(struct clock_event_device *dev) | |
169 | { | |
be3ef76e | 170 | return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT; |
3434d23b VK |
171 | } |
172 | ||
173 | static inline bool clockevent_state_oneshot_stopped(struct clock_event_device *dev) | |
174 | { | |
be3ef76e | 175 | return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT_STOPPED; |
3434d23b VK |
176 | } |
177 | ||
d316c57f TG |
178 | /* |
179 | * Calculate a multiplication factor for scaled math, which is used to convert | |
180 | * nanoseconds based values to clock ticks: | |
181 | * | |
182 | * clock_ticks = (nanoseconds * factor) >> shift. | |
183 | * | |
184 | * div_sc is the rearranged equation to calculate a factor from a given clock | |
185 | * ticks / nanoseconds ratio: | |
186 | * | |
187 | * factor = (clock_ticks << shift) / nanoseconds | |
188 | */ | |
9eed56e8 IM |
189 | static inline unsigned long |
190 | div_sc(unsigned long ticks, unsigned long nsec, int shift) | |
d316c57f | 191 | { |
9eed56e8 | 192 | u64 tmp = ((u64)ticks) << shift; |
d316c57f TG |
193 | |
194 | do_div(tmp, nsec); | |
9eed56e8 | 195 | |
d316c57f TG |
196 | return (unsigned long) tmp; |
197 | } | |
198 | ||
199 | /* Clock event layer functions */ | |
9eed56e8 | 200 | extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt); |
d316c57f | 201 | extern void clockevents_register_device(struct clock_event_device *dev); |
03e13cf5 | 202 | extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu); |
d316c57f | 203 | |
e5400321 | 204 | extern void clockevents_config(struct clock_event_device *dev, u32 freq); |
57f0fcbe TG |
205 | extern void clockevents_config_and_register(struct clock_event_device *dev, |
206 | u32 freq, unsigned long min_delta, | |
207 | unsigned long max_delta); | |
208 | ||
80b816b7 TG |
209 | extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq); |
210 | ||
7d2f944a TG |
211 | static inline void |
212 | clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec) | |
213 | { | |
9eed56e8 | 214 | return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, freq, minsec); |
7d2f944a TG |
215 | } |
216 | ||
adc78e6b RW |
217 | extern void clockevents_suspend(void); |
218 | extern void clockevents_resume(void); | |
219 | ||
9eed56e8 IM |
220 | # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
221 | # ifdef CONFIG_ARCH_HAS_TICK_BROADCAST | |
12ad1000 | 222 | extern void tick_broadcast(const struct cpumask *mask); |
9eed56e8 IM |
223 | # else |
224 | # define tick_broadcast NULL | |
225 | # endif | |
12572dbb | 226 | extern int tick_receive_broadcast(void); |
9eed56e8 | 227 | # endif |
12572dbb | 228 | |
9eed56e8 | 229 | # if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT) |
5d1638ac | 230 | extern void tick_setup_hrtimer_broadcast(void); |
eaa907c5 | 231 | extern int tick_check_broadcast_expired(void); |
9eed56e8 | 232 | # else |
eaa907c5 | 233 | static inline int tick_check_broadcast_expired(void) { return 0; } |
9eed56e8 IM |
234 | static inline void tick_setup_hrtimer_broadcast(void) { } |
235 | # endif | |
eaa907c5 | 236 | |
9eed56e8 | 237 | #else /* !CONFIG_GENERIC_CLOCKEVENTS: */ |
adc78e6b | 238 | |
9eed56e8 IM |
239 | static inline void clockevents_suspend(void) { } |
240 | static inline void clockevents_resume(void) { } | |
19919226 | 241 | static inline int tick_check_broadcast_expired(void) { return 0; } |
9eed56e8 | 242 | static inline void tick_setup_hrtimer_broadcast(void) { } |
d316c57f | 243 | |
9eed56e8 | 244 | #endif /* !CONFIG_GENERIC_CLOCKEVENTS */ |
d316c57f | 245 | |
9eed56e8 | 246 | #endif /* _LINUX_CLOCKCHIPS_H */ |