xref: /openbmc/linux/kernel/time/tick-internal.h (revision 6441402b)
1f8381cbaSThomas Gleixner /*
2f8381cbaSThomas Gleixner  * tick internal variable and functions used by low/high res code
3f8381cbaSThomas Gleixner  */
46441402bSThomas Gleixner 
56441402bSThomas Gleixner #define TICK_DO_TIMER_NONE	-1
66441402bSThomas Gleixner #define TICK_DO_TIMER_BOOT	-2
76441402bSThomas Gleixner 
8f8381cbaSThomas Gleixner DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
9f8381cbaSThomas Gleixner extern spinlock_t tick_device_lock;
10f8381cbaSThomas Gleixner extern ktime_t tick_next_period;
11f8381cbaSThomas Gleixner extern ktime_t tick_period;
12d3ed7824SThomas Gleixner extern int tick_do_timer_cpu __read_mostly;
13f8381cbaSThomas Gleixner 
14f8381cbaSThomas Gleixner extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
15f8381cbaSThomas Gleixner extern void tick_handle_periodic(struct clock_event_device *dev);
16f8381cbaSThomas Gleixner 
172344abbcSThomas Gleixner extern void clockevents_shutdown(struct clock_event_device *dev);
182344abbcSThomas Gleixner 
19f8381cbaSThomas Gleixner /*
2079bf2bb3SThomas Gleixner  * NO_HZ / high resolution timer shared code
2179bf2bb3SThomas Gleixner  */
2279bf2bb3SThomas Gleixner #ifdef CONFIG_TICK_ONESHOT
2379bf2bb3SThomas Gleixner extern void tick_setup_oneshot(struct clock_event_device *newdev,
2479bf2bb3SThomas Gleixner 			       void (*handler)(struct clock_event_device *),
2579bf2bb3SThomas Gleixner 			       ktime_t nextevt);
261fb9b7d2SThomas Gleixner extern int tick_dev_program_event(struct clock_event_device *dev,
271fb9b7d2SThomas Gleixner 				  ktime_t expires, int force);
2879bf2bb3SThomas Gleixner extern int tick_program_event(ktime_t expires, int force);
2979bf2bb3SThomas Gleixner extern void tick_oneshot_notify(void);
3079bf2bb3SThomas Gleixner extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
31cd05a1f8SThomas Gleixner extern void tick_resume_oneshot(void);
3279bf2bb3SThomas Gleixner # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
3379bf2bb3SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
3479bf2bb3SThomas Gleixner extern void tick_broadcast_oneshot_control(unsigned long reason);
3579bf2bb3SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void);
3679bf2bb3SThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
37cd05a1f8SThomas Gleixner extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc);
3879bf2bb3SThomas Gleixner # else /* BROADCAST */
3979bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
4079bf2bb3SThomas Gleixner {
4179bf2bb3SThomas Gleixner 	BUG();
4279bf2bb3SThomas Gleixner }
4379bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { }
4479bf2bb3SThomas Gleixner static inline void tick_broadcast_switch_to_oneshot(void) { }
4579bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
4679bf2bb3SThomas Gleixner # endif /* !BROADCAST */
4779bf2bb3SThomas Gleixner 
4879bf2bb3SThomas Gleixner #else /* !ONESHOT */
4979bf2bb3SThomas Gleixner static inline
5079bf2bb3SThomas Gleixner void tick_setup_oneshot(struct clock_event_device *newdev,
5179bf2bb3SThomas Gleixner 			void (*handler)(struct clock_event_device *),
5279bf2bb3SThomas Gleixner 			ktime_t nextevt)
5379bf2bb3SThomas Gleixner {
5479bf2bb3SThomas Gleixner 	BUG();
5579bf2bb3SThomas Gleixner }
56cd05a1f8SThomas Gleixner static inline void tick_resume_oneshot(void)
57cd05a1f8SThomas Gleixner {
58cd05a1f8SThomas Gleixner 	BUG();
59cd05a1f8SThomas Gleixner }
6079bf2bb3SThomas Gleixner static inline int tick_program_event(ktime_t expires, int force)
6179bf2bb3SThomas Gleixner {
6279bf2bb3SThomas Gleixner 	return 0;
6379bf2bb3SThomas Gleixner }
6479bf2bb3SThomas Gleixner static inline void tick_oneshot_notify(void) { }
6579bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
6679bf2bb3SThomas Gleixner {
6779bf2bb3SThomas Gleixner 	BUG();
6879bf2bb3SThomas Gleixner }
6979bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { }
7079bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
71cd05a1f8SThomas Gleixner static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
72cd05a1f8SThomas Gleixner {
73cd05a1f8SThomas Gleixner 	return 0;
74cd05a1f8SThomas Gleixner }
7579bf2bb3SThomas Gleixner #endif /* !TICK_ONESHOT */
7679bf2bb3SThomas Gleixner 
7779bf2bb3SThomas Gleixner /*
78f8381cbaSThomas Gleixner  * Broadcasting support
79f8381cbaSThomas Gleixner  */
80f8381cbaSThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
81f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
82f8381cbaSThomas Gleixner extern int tick_check_broadcast_device(struct clock_event_device *dev);
83f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev);
84f8381cbaSThomas Gleixner extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
85f8381cbaSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int *cpup);
866321dd60SThomas Gleixner extern void tick_suspend_broadcast(void);
876321dd60SThomas Gleixner extern int tick_resume_broadcast(void);
88f8381cbaSThomas Gleixner 
89f8381cbaSThomas Gleixner extern void
90f8381cbaSThomas Gleixner tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
91f8381cbaSThomas Gleixner 
92f8381cbaSThomas Gleixner #else /* !BROADCAST */
93f8381cbaSThomas Gleixner 
94f8381cbaSThomas Gleixner static inline int tick_check_broadcast_device(struct clock_event_device *dev)
95f8381cbaSThomas Gleixner {
96f8381cbaSThomas Gleixner 	return 0;
97f8381cbaSThomas Gleixner }
98f8381cbaSThomas Gleixner 
99f8381cbaSThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev)
100f8381cbaSThomas Gleixner {
101f8381cbaSThomas Gleixner 	return 0;
102f8381cbaSThomas Gleixner }
103f8381cbaSThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev,
104f8381cbaSThomas Gleixner 					     int cpu)
105f8381cbaSThomas Gleixner {
106f8381cbaSThomas Gleixner 	return 0;
107f8381cbaSThomas Gleixner }
108f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
109f8381cbaSThomas Gleixner static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
110f8381cbaSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
1116321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { }
1126321dd60SThomas Gleixner static inline int tick_resume_broadcast(void) { return 0; }
113f8381cbaSThomas Gleixner 
114f8381cbaSThomas Gleixner /*
115f8381cbaSThomas Gleixner  * Set the periodic handler in non broadcast mode
116f8381cbaSThomas Gleixner  */
117f8381cbaSThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev,
118f8381cbaSThomas Gleixner 					     int broadcast)
119f8381cbaSThomas Gleixner {
120f8381cbaSThomas Gleixner 	dev->event_handler = tick_handle_periodic;
121f8381cbaSThomas Gleixner }
122f8381cbaSThomas Gleixner #endif /* !BROADCAST */
123f8381cbaSThomas Gleixner 
124f8381cbaSThomas Gleixner /*
125f8381cbaSThomas Gleixner  * Check, if the device is functional or a dummy for broadcast
126f8381cbaSThomas Gleixner  */
127f8381cbaSThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev)
128f8381cbaSThomas Gleixner {
129f8381cbaSThomas Gleixner 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
130f8381cbaSThomas Gleixner }
131