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