xref: /openbmc/linux/kernel/time/tick-internal.h (revision e2830b5c)
1f8381cbaSThomas Gleixner /*
2f8381cbaSThomas Gleixner  * tick internal variable and functions used by low/high res code
3f8381cbaSThomas Gleixner  */
4e2830b5cSTorben Hohn #include <linux/hrtimer.h>
5e2830b5cSTorben Hohn #include <linux/tick.h>
66441402bSThomas Gleixner 
76441402bSThomas Gleixner #define TICK_DO_TIMER_NONE	-1
86441402bSThomas Gleixner #define TICK_DO_TIMER_BOOT	-2
96441402bSThomas Gleixner 
10f8381cbaSThomas Gleixner DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
11f8381cbaSThomas Gleixner extern ktime_t tick_next_period;
12f8381cbaSThomas Gleixner extern ktime_t tick_period;
13d3ed7824SThomas Gleixner extern int tick_do_timer_cpu __read_mostly;
14f8381cbaSThomas Gleixner 
15f8381cbaSThomas Gleixner extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
16f8381cbaSThomas Gleixner extern void tick_handle_periodic(struct clock_event_device *dev);
17f8381cbaSThomas Gleixner 
182344abbcSThomas Gleixner extern void clockevents_shutdown(struct clock_event_device *dev);
192344abbcSThomas Gleixner 
20f8381cbaSThomas Gleixner /*
2179bf2bb3SThomas Gleixner  * NO_HZ / high resolution timer shared code
2279bf2bb3SThomas Gleixner  */
2379bf2bb3SThomas Gleixner #ifdef CONFIG_TICK_ONESHOT
2479bf2bb3SThomas Gleixner extern void tick_setup_oneshot(struct clock_event_device *newdev,
2579bf2bb3SThomas Gleixner 			       void (*handler)(struct clock_event_device *),
2679bf2bb3SThomas Gleixner 			       ktime_t nextevt);
271fb9b7d2SThomas Gleixner extern int tick_dev_program_event(struct clock_event_device *dev,
281fb9b7d2SThomas Gleixner 				  ktime_t expires, int force);
2979bf2bb3SThomas Gleixner extern int tick_program_event(ktime_t expires, int force);
3079bf2bb3SThomas Gleixner extern void tick_oneshot_notify(void);
3179bf2bb3SThomas Gleixner extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
32cd05a1f8SThomas Gleixner extern void tick_resume_oneshot(void);
3379bf2bb3SThomas Gleixner # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
3479bf2bb3SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
3579bf2bb3SThomas Gleixner extern void tick_broadcast_oneshot_control(unsigned long reason);
3679bf2bb3SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void);
3779bf2bb3SThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
38cd05a1f8SThomas Gleixner extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc);
3927ce4cb4SThomas Gleixner extern int tick_broadcast_oneshot_active(void);
40fb02fbc1SThomas Gleixner extern void tick_check_oneshot_broadcast(int cpu);
4179bf2bb3SThomas Gleixner # else /* BROADCAST */
4279bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
4379bf2bb3SThomas Gleixner {
4479bf2bb3SThomas Gleixner 	BUG();
4579bf2bb3SThomas Gleixner }
4679bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { }
4779bf2bb3SThomas Gleixner static inline void tick_broadcast_switch_to_oneshot(void) { }
4879bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
4927ce4cb4SThomas Gleixner static inline int tick_broadcast_oneshot_active(void) { return 0; }
50fb02fbc1SThomas Gleixner static inline void tick_check_oneshot_broadcast(int cpu) { }
5179bf2bb3SThomas Gleixner # endif /* !BROADCAST */
5279bf2bb3SThomas Gleixner 
5379bf2bb3SThomas Gleixner #else /* !ONESHOT */
5479bf2bb3SThomas Gleixner static inline
5579bf2bb3SThomas Gleixner void tick_setup_oneshot(struct clock_event_device *newdev,
5679bf2bb3SThomas Gleixner 			void (*handler)(struct clock_event_device *),
5779bf2bb3SThomas Gleixner 			ktime_t nextevt)
5879bf2bb3SThomas Gleixner {
5979bf2bb3SThomas Gleixner 	BUG();
6079bf2bb3SThomas Gleixner }
61cd05a1f8SThomas Gleixner static inline void tick_resume_oneshot(void)
62cd05a1f8SThomas Gleixner {
63cd05a1f8SThomas Gleixner 	BUG();
64cd05a1f8SThomas Gleixner }
6579bf2bb3SThomas Gleixner static inline int tick_program_event(ktime_t expires, int force)
6679bf2bb3SThomas Gleixner {
6779bf2bb3SThomas Gleixner 	return 0;
6879bf2bb3SThomas Gleixner }
6979bf2bb3SThomas Gleixner static inline void tick_oneshot_notify(void) { }
7079bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
7179bf2bb3SThomas Gleixner {
7279bf2bb3SThomas Gleixner 	BUG();
7379bf2bb3SThomas Gleixner }
7479bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { }
7579bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
76cd05a1f8SThomas Gleixner static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
77cd05a1f8SThomas Gleixner {
78cd05a1f8SThomas Gleixner 	return 0;
79cd05a1f8SThomas Gleixner }
80f8e256c6SIngo Molnar static inline int tick_broadcast_oneshot_active(void) { return 0; }
8179bf2bb3SThomas Gleixner #endif /* !TICK_ONESHOT */
8279bf2bb3SThomas Gleixner 
8379bf2bb3SThomas Gleixner /*
84f8381cbaSThomas Gleixner  * Broadcasting support
85f8381cbaSThomas Gleixner  */
86f8381cbaSThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
87f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
88f8381cbaSThomas Gleixner extern int tick_check_broadcast_device(struct clock_event_device *dev);
89f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev);
90f8381cbaSThomas Gleixner extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
91f8381cbaSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int *cpup);
926321dd60SThomas Gleixner extern void tick_suspend_broadcast(void);
936321dd60SThomas Gleixner extern int tick_resume_broadcast(void);
94f8381cbaSThomas Gleixner 
95f8381cbaSThomas Gleixner extern void
96f8381cbaSThomas Gleixner tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
97f8381cbaSThomas Gleixner 
98f8381cbaSThomas Gleixner #else /* !BROADCAST */
99f8381cbaSThomas Gleixner 
100f8381cbaSThomas Gleixner static inline int tick_check_broadcast_device(struct clock_event_device *dev)
101f8381cbaSThomas Gleixner {
102f8381cbaSThomas Gleixner 	return 0;
103f8381cbaSThomas Gleixner }
104f8381cbaSThomas Gleixner 
105f8381cbaSThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev)
106f8381cbaSThomas Gleixner {
107f8381cbaSThomas Gleixner 	return 0;
108f8381cbaSThomas Gleixner }
109f8381cbaSThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev,
110f8381cbaSThomas Gleixner 					     int cpu)
111f8381cbaSThomas Gleixner {
112f8381cbaSThomas Gleixner 	return 0;
113f8381cbaSThomas Gleixner }
114f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
115f8381cbaSThomas Gleixner static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
116f8381cbaSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
1176321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { }
1186321dd60SThomas Gleixner static inline int tick_resume_broadcast(void) { return 0; }
119f8381cbaSThomas Gleixner 
120f8381cbaSThomas Gleixner /*
121f8381cbaSThomas Gleixner  * Set the periodic handler in non broadcast mode
122f8381cbaSThomas Gleixner  */
123f8381cbaSThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev,
124f8381cbaSThomas Gleixner 					     int broadcast)
125f8381cbaSThomas Gleixner {
126f8381cbaSThomas Gleixner 	dev->event_handler = tick_handle_periodic;
127f8381cbaSThomas Gleixner }
128f8381cbaSThomas Gleixner #endif /* !BROADCAST */
129f8381cbaSThomas Gleixner 
130f8381cbaSThomas Gleixner /*
131f8381cbaSThomas Gleixner  * Check, if the device is functional or a dummy for broadcast
132f8381cbaSThomas Gleixner  */
133f8381cbaSThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev)
134f8381cbaSThomas Gleixner {
135f8381cbaSThomas Gleixner 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
136f8381cbaSThomas Gleixner }
137e2830b5cSTorben Hohn 
138e2830b5cSTorben Hohn extern void do_timer(unsigned long ticks);
139e2830b5cSTorben Hohn extern seqlock_t xtime_lock;
140