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