]>
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 | ||
4dbad816 DL |
11 | /* Clock event notification values */ |
12 | enum 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 | ||
de68d9b1 | 25 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD |
d316c57f TG |
26 | |
27 | #include <linux/clocksource.h> | |
28 | #include <linux/cpumask.h> | |
29 | #include <linux/ktime.h> | |
30 | #include <linux/notifier.h> | |
31 | ||
32 | struct clock_event_device; | |
33 | ||
34 | /* Clock event mode commands */ | |
35 | enum clock_event_mode { | |
36 | CLOCK_EVT_MODE_UNUSED = 0, | |
37 | CLOCK_EVT_MODE_SHUTDOWN, | |
38 | CLOCK_EVT_MODE_PERIODIC, | |
39 | CLOCK_EVT_MODE_ONESHOT, | |
18de5bc4 | 40 | CLOCK_EVT_MODE_RESUME, |
d316c57f TG |
41 | }; |
42 | ||
d316c57f TG |
43 | /* |
44 | * Clock event features | |
45 | */ | |
46 | #define CLOCK_EVT_FEAT_PERIODIC 0x000001 | |
47 | #define CLOCK_EVT_FEAT_ONESHOT 0x000002 | |
65516f8a | 48 | #define CLOCK_EVT_FEAT_KTIME 0x000004 |
d316c57f TG |
49 | /* |
50 | * x86(64) specific misfeatures: | |
51 | * | |
52 | * - Clockevent source stops in C3 State and needs broadcast support. | |
53 | * - Local APIC timer is used as a dummy device. | |
54 | */ | |
65516f8a MS |
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 | */ | |
61 | #define CLOCK_EVT_FEAT_DYNIRQ 0x000020 | |
62 | ||
d316c57f TG |
63 | /** |
64 | * struct clock_event_device - clock event device descriptor | |
847b2f42 TG |
65 | * @event_handler: Assigned by the framework to be called by the low |
66 | * level handler of the event source | |
65516f8a MS |
67 | * @set_next_event: set next event function using a clocksource delta |
68 | * @set_next_ktime: set next event function using a direct ktime value | |
847b2f42 | 69 | * @next_event: local storage for the next event in oneshot mode |
d316c57f TG |
70 | * @max_delta_ns: maximum delta value in ns |
71 | * @min_delta_ns: minimum delta value in ns | |
72 | * @mult: nanosecond to cycles multiplier | |
73 | * @shift: nanoseconds to cycles divisor (power of two) | |
847b2f42 TG |
74 | * @mode: operating mode assigned by the management code |
75 | * @features: features | |
76 | * @retries: number of forced programming retries | |
77 | * @set_mode: set mode function | |
78 | * @broadcast: function to broadcast events | |
57f0fcbe TG |
79 | * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration |
80 | * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration | |
847b2f42 | 81 | * @name: ptr to clock event name |
d316c57f | 82 | * @rating: variable to rate clock event devices |
ce0be127 SS |
83 | * @irq: IRQ number (only for non CPU local devices) |
84 | * @cpumask: cpumask to indicate for which CPUs this device works | |
d316c57f | 85 | * @list: list head for the management code |
d316c57f TG |
86 | */ |
87 | struct clock_event_device { | |
847b2f42 TG |
88 | void (*event_handler)(struct clock_event_device *); |
89 | int (*set_next_event)(unsigned long evt, | |
90 | struct clock_event_device *); | |
65516f8a MS |
91 | int (*set_next_ktime)(ktime_t expires, |
92 | struct clock_event_device *); | |
847b2f42 | 93 | ktime_t next_event; |
97813f2f JH |
94 | u64 max_delta_ns; |
95 | u64 min_delta_ns; | |
23af368e TG |
96 | u32 mult; |
97 | u32 shift; | |
847b2f42 TG |
98 | enum clock_event_mode mode; |
99 | unsigned int features; | |
100 | unsigned long retries; | |
101 | ||
102 | void (*broadcast)(const struct cpumask *mask); | |
103 | void (*set_mode)(enum clock_event_mode mode, | |
104 | struct clock_event_device *); | |
adc78e6b RW |
105 | void (*suspend)(struct clock_event_device *); |
106 | void (*resume)(struct clock_event_device *); | |
57f0fcbe TG |
107 | unsigned long min_delta_ticks; |
108 | unsigned long max_delta_ticks; | |
109 | ||
847b2f42 | 110 | const char *name; |
d316c57f TG |
111 | int rating; |
112 | int irq; | |
320ab2b0 | 113 | const struct cpumask *cpumask; |
d316c57f | 114 | struct list_head list; |
847b2f42 | 115 | } ____cacheline_aligned; |
d316c57f TG |
116 | |
117 | /* | |
118 | * Calculate a multiplication factor for scaled math, which is used to convert | |
119 | * nanoseconds based values to clock ticks: | |
120 | * | |
121 | * clock_ticks = (nanoseconds * factor) >> shift. | |
122 | * | |
123 | * div_sc is the rearranged equation to calculate a factor from a given clock | |
124 | * ticks / nanoseconds ratio: | |
125 | * | |
126 | * factor = (clock_ticks << shift) / nanoseconds | |
127 | */ | |
128 | static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec, | |
129 | int shift) | |
130 | { | |
131 | uint64_t tmp = ((uint64_t)ticks) << shift; | |
132 | ||
133 | do_div(tmp, nsec); | |
134 | return (unsigned long) tmp; | |
135 | } | |
136 | ||
137 | /* Clock event layer functions */ | |
97813f2f JH |
138 | extern u64 clockevent_delta2ns(unsigned long latch, |
139 | struct clock_event_device *evt); | |
d316c57f TG |
140 | extern void clockevents_register_device(struct clock_event_device *dev); |
141 | ||
e5400321 | 142 | extern void clockevents_config(struct clock_event_device *dev, u32 freq); |
57f0fcbe TG |
143 | extern void clockevents_config_and_register(struct clock_event_device *dev, |
144 | u32 freq, unsigned long min_delta, | |
145 | unsigned long max_delta); | |
146 | ||
80b816b7 TG |
147 | extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq); |
148 | ||
d316c57f TG |
149 | extern void clockevents_exchange_device(struct clock_event_device *old, |
150 | struct clock_event_device *new); | |
d316c57f TG |
151 | extern void clockevents_set_mode(struct clock_event_device *dev, |
152 | enum clock_event_mode mode); | |
153 | extern int clockevents_register_notifier(struct notifier_block *nb); | |
d316c57f | 154 | extern int clockevents_program_event(struct clock_event_device *dev, |
d1748302 | 155 | ktime_t expires, bool force); |
d316c57f | 156 | |
7c1e7689 VP |
157 | extern void clockevents_handle_noop(struct clock_event_device *dev); |
158 | ||
7d2f944a TG |
159 | static inline void |
160 | clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec) | |
161 | { | |
162 | return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, | |
163 | freq, minsec); | |
164 | } | |
165 | ||
adc78e6b RW |
166 | extern void clockevents_suspend(void); |
167 | extern void clockevents_resume(void); | |
168 | ||
12572dbb | 169 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
12ad1000 MR |
170 | #ifdef CONFIG_ARCH_HAS_TICK_BROADCAST |
171 | extern void tick_broadcast(const struct cpumask *mask); | |
172 | #else | |
173 | #define tick_broadcast NULL | |
174 | #endif | |
12572dbb MR |
175 | extern int tick_receive_broadcast(void); |
176 | #endif | |
177 | ||
eaa907c5 TG |
178 | #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT) |
179 | extern int tick_check_broadcast_expired(void); | |
180 | #else | |
181 | static inline int tick_check_broadcast_expired(void) { return 0; } | |
182 | #endif | |
183 | ||
de68d9b1 | 184 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
d316c57f | 185 | extern void clockevents_notify(unsigned long reason, void *arg); |
d316c57f | 186 | #else |
4dbad816 | 187 | static inline void clockevents_notify(unsigned long reason, void *arg) {} |
de68d9b1 TG |
188 | #endif |
189 | ||
190 | #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */ | |
d316c57f | 191 | |
adc78e6b RW |
192 | static inline void clockevents_suspend(void) {} |
193 | static inline void clockevents_resume(void) {} | |
194 | ||
4dbad816 | 195 | static inline void clockevents_notify(unsigned long reason, void *arg) {} |
19919226 | 196 | static inline int tick_check_broadcast_expired(void) { return 0; } |
d316c57f TG |
197 | |
198 | #endif | |
199 | ||
200 | #endif |