1 /* linux/include/linux/clockchips.h
3 * This file contains the structure definitions for clockchips.
5 * If you are not a clockchip, or the time of day code, you should
6 * not be including this file!
8 #ifndef _LINUX_CLOCKCHIPS_H
9 #define _LINUX_CLOCKCHIPS_H
11 /* Clock event notification values */
12 enum clock_event_nofitiers
{
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
,
25 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
27 #include <linux/clocksource.h>
28 #include <linux/cpumask.h>
29 #include <linux/ktime.h>
30 #include <linux/notifier.h>
32 struct clock_event_device
;
35 /* Clock event mode commands */
36 enum 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
,
43 /* Legacy ->set_mode() callback doesn't support below modes */
47 * Clock event features
49 #define CLOCK_EVT_FEAT_PERIODIC 0x000001
50 #define CLOCK_EVT_FEAT_ONESHOT 0x000002
51 #define CLOCK_EVT_FEAT_KTIME 0x000004
53 * x86(64) specific misfeatures:
55 * - Clockevent source stops in C3 State and needs broadcast support.
56 * - Local APIC timer is used as a dummy device.
58 #define CLOCK_EVT_FEAT_C3STOP 0x000008
59 #define CLOCK_EVT_FEAT_DUMMY 0x000010
62 * Core shall set the interrupt affinity dynamically in broadcast mode
64 #define CLOCK_EVT_FEAT_DYNIRQ 0x000020
65 #define CLOCK_EVT_FEAT_PERCPU 0x000040
68 * Clockevent device is based on a hrtimer for broadcast
70 #define CLOCK_EVT_FEAT_HRTIMER 0x000080
73 * struct clock_event_device - clock event device descriptor
74 * @event_handler: Assigned by the framework to be called by the low
75 * level handler of the event source
76 * @set_next_event: set next event function using a clocksource delta
77 * @set_next_ktime: set next event function using a direct ktime value
78 * @next_event: local storage for the next event in oneshot mode
79 * @max_delta_ns: maximum delta value in ns
80 * @min_delta_ns: minimum delta value in ns
81 * @mult: nanosecond to cycles multiplier
82 * @shift: nanoseconds to cycles divisor (power of two)
83 * @mode: operating mode assigned by the management code
85 * @retries: number of forced programming retries
86 * @set_mode: legacy set mode function, only for modes <= CLOCK_EVT_MODE_RESUME.
87 * @set_mode_periodic: switch mode to periodic, if !set_mode
88 * @set_mode_oneshot: switch mode to oneshot, if !set_mode
89 * @set_mode_shutdown: switch mode to shutdown, if !set_mode
90 * @set_mode_resume: resume clkevt device, if !set_mode
91 * @broadcast: function to broadcast events
92 * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
93 * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
94 * @name: ptr to clock event name
95 * @rating: variable to rate clock event devices
96 * @irq: IRQ number (only for non CPU local devices)
97 * @bound_on: Bound on CPU
98 * @cpumask: cpumask to indicate for which CPUs this device works
99 * @list: list head for the management code
100 * @owner: module reference
102 struct clock_event_device
{
103 void (*event_handler
)(struct clock_event_device
*);
104 int (*set_next_event
)(unsigned long evt
,
105 struct clock_event_device
*);
106 int (*set_next_ktime
)(ktime_t expires
,
107 struct clock_event_device
*);
113 enum clock_event_mode mode
;
114 unsigned int features
;
115 unsigned long retries
;
118 * Mode transition callback(s): Only one of the two groups should be
120 * - set_mode(), only for modes <= CLOCK_EVT_MODE_RESUME.
121 * - set_mode_{shutdown|periodic|oneshot|resume}().
123 void (*set_mode
)(enum clock_event_mode mode
,
124 struct clock_event_device
*);
125 int (*set_mode_periodic
)(struct clock_event_device
*);
126 int (*set_mode_oneshot
)(struct clock_event_device
*);
127 int (*set_mode_shutdown
)(struct clock_event_device
*);
128 int (*set_mode_resume
)(struct clock_event_device
*);
130 void (*broadcast
)(const struct cpumask
*mask
);
131 void (*suspend
)(struct clock_event_device
*);
132 void (*resume
)(struct clock_event_device
*);
133 unsigned long min_delta_ticks
;
134 unsigned long max_delta_ticks
;
140 const struct cpumask
*cpumask
;
141 struct list_head list
;
142 struct module
*owner
;
143 } ____cacheline_aligned
;
146 * Calculate a multiplication factor for scaled math, which is used to convert
147 * nanoseconds based values to clock ticks:
149 * clock_ticks = (nanoseconds * factor) >> shift.
151 * div_sc is the rearranged equation to calculate a factor from a given clock
152 * ticks / nanoseconds ratio:
154 * factor = (clock_ticks << shift) / nanoseconds
156 static inline unsigned long div_sc(unsigned long ticks
, unsigned long nsec
,
159 uint64_t tmp
= ((uint64_t)ticks
) << shift
;
162 return (unsigned long) tmp
;
165 /* Clock event layer functions */
166 extern u64
clockevent_delta2ns(unsigned long latch
,
167 struct clock_event_device
*evt
);
168 extern void clockevents_register_device(struct clock_event_device
*dev
);
169 extern int clockevents_unbind_device(struct clock_event_device
*ced
, int cpu
);
171 extern void clockevents_config(struct clock_event_device
*dev
, u32 freq
);
172 extern void clockevents_config_and_register(struct clock_event_device
*dev
,
173 u32 freq
, unsigned long min_delta
,
174 unsigned long max_delta
);
176 extern int clockevents_update_freq(struct clock_event_device
*ce
, u32 freq
);
178 extern void clockevents_exchange_device(struct clock_event_device
*old
,
179 struct clock_event_device
*new);
180 extern void clockevents_set_mode(struct clock_event_device
*dev
,
181 enum clock_event_mode mode
);
182 extern int clockevents_program_event(struct clock_event_device
*dev
,
183 ktime_t expires
, bool force
);
185 extern void clockevents_handle_noop(struct clock_event_device
*dev
);
188 clockevents_calc_mult_shift(struct clock_event_device
*ce
, u32 freq
, u32 minsec
)
190 return clocks_calc_mult_shift(&ce
->mult
, &ce
->shift
, NSEC_PER_SEC
,
194 extern void clockevents_suspend(void);
195 extern void clockevents_resume(void);
197 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
198 #ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
199 extern void tick_broadcast(const struct cpumask
*mask
);
201 #define tick_broadcast NULL
203 extern int tick_receive_broadcast(void);
206 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
207 extern void tick_setup_hrtimer_broadcast(void);
208 extern int tick_check_broadcast_expired(void);
210 static inline int tick_check_broadcast_expired(void) { return 0; }
211 static inline void tick_setup_hrtimer_broadcast(void) {};
214 #ifdef CONFIG_GENERIC_CLOCKEVENTS
215 extern int clockevents_notify(unsigned long reason
, void *arg
);
217 static inline int clockevents_notify(unsigned long reason
, void *arg
) { return 0; }
220 #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
222 static inline void clockevents_suspend(void) {}
223 static inline void clockevents_resume(void) {}
225 static inline int clockevents_notify(unsigned long reason
, void *arg
) { return 0; }
226 static inline int tick_check_broadcast_expired(void) { return 0; }
227 static inline void tick_setup_hrtimer_broadcast(void) {};