xref: /openbmc/linux/kernel/time/tick-internal.h (revision d3ed7824)
1f8381cbaSThomas Gleixner /*
2f8381cbaSThomas Gleixner  * tick internal variable and functions used by low/high res code
3f8381cbaSThomas Gleixner  */
4f8381cbaSThomas Gleixner DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
5f8381cbaSThomas Gleixner extern spinlock_t tick_device_lock;
6f8381cbaSThomas Gleixner extern ktime_t tick_next_period;
7f8381cbaSThomas Gleixner extern ktime_t tick_period;
8d3ed7824SThomas Gleixner extern int tick_do_timer_cpu __read_mostly;
9f8381cbaSThomas Gleixner 
10f8381cbaSThomas Gleixner extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
11f8381cbaSThomas Gleixner extern void tick_handle_periodic(struct clock_event_device *dev);
12f8381cbaSThomas Gleixner 
13f8381cbaSThomas Gleixner /*
1479bf2bb3SThomas Gleixner  * NO_HZ / high resolution timer shared code
1579bf2bb3SThomas Gleixner  */
1679bf2bb3SThomas Gleixner #ifdef CONFIG_TICK_ONESHOT
1779bf2bb3SThomas Gleixner extern void tick_setup_oneshot(struct clock_event_device *newdev,
1879bf2bb3SThomas Gleixner 			       void (*handler)(struct clock_event_device *),
1979bf2bb3SThomas Gleixner 			       ktime_t nextevt);
2079bf2bb3SThomas Gleixner extern int tick_program_event(ktime_t expires, int force);
2179bf2bb3SThomas Gleixner extern void tick_oneshot_notify(void);
2279bf2bb3SThomas Gleixner extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
23cd05a1f8SThomas Gleixner extern void tick_resume_oneshot(void);
2479bf2bb3SThomas Gleixner # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
2579bf2bb3SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
2679bf2bb3SThomas Gleixner extern void tick_broadcast_oneshot_control(unsigned long reason);
2779bf2bb3SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void);
2879bf2bb3SThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
29cd05a1f8SThomas Gleixner extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc);
3079bf2bb3SThomas Gleixner # else /* BROADCAST */
3179bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
3279bf2bb3SThomas Gleixner {
3379bf2bb3SThomas Gleixner 	BUG();
3479bf2bb3SThomas Gleixner }
3579bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { }
3679bf2bb3SThomas Gleixner static inline void tick_broadcast_switch_to_oneshot(void) { }
3779bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
3879bf2bb3SThomas Gleixner # endif /* !BROADCAST */
3979bf2bb3SThomas Gleixner 
4079bf2bb3SThomas Gleixner #else /* !ONESHOT */
4179bf2bb3SThomas Gleixner static inline
4279bf2bb3SThomas Gleixner void tick_setup_oneshot(struct clock_event_device *newdev,
4379bf2bb3SThomas Gleixner 			void (*handler)(struct clock_event_device *),
4479bf2bb3SThomas Gleixner 			ktime_t nextevt)
4579bf2bb3SThomas Gleixner {
4679bf2bb3SThomas Gleixner 	BUG();
4779bf2bb3SThomas Gleixner }
48cd05a1f8SThomas Gleixner static inline void tick_resume_oneshot(void)
49cd05a1f8SThomas Gleixner {
50cd05a1f8SThomas Gleixner 	BUG();
51cd05a1f8SThomas Gleixner }
5279bf2bb3SThomas Gleixner static inline int tick_program_event(ktime_t expires, int force)
5379bf2bb3SThomas Gleixner {
5479bf2bb3SThomas Gleixner 	return 0;
5579bf2bb3SThomas Gleixner }
5679bf2bb3SThomas Gleixner static inline void tick_oneshot_notify(void) { }
5779bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc)
5879bf2bb3SThomas Gleixner {
5979bf2bb3SThomas Gleixner 	BUG();
6079bf2bb3SThomas Gleixner }
6179bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { }
6279bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
63cd05a1f8SThomas Gleixner static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
64cd05a1f8SThomas Gleixner {
65cd05a1f8SThomas Gleixner 	return 0;
66cd05a1f8SThomas Gleixner }
6779bf2bb3SThomas Gleixner #endif /* !TICK_ONESHOT */
6879bf2bb3SThomas Gleixner 
6979bf2bb3SThomas Gleixner /*
70f8381cbaSThomas Gleixner  * Broadcasting support
71f8381cbaSThomas Gleixner  */
72f8381cbaSThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
73f8381cbaSThomas Gleixner extern int tick_do_broadcast(cpumask_t mask);
74f8381cbaSThomas Gleixner 
75f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
76f8381cbaSThomas Gleixner extern int tick_check_broadcast_device(struct clock_event_device *dev);
77f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev);
78f8381cbaSThomas Gleixner extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
79f8381cbaSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int *cpup);
806321dd60SThomas Gleixner extern void tick_suspend_broadcast(void);
816321dd60SThomas Gleixner extern int tick_resume_broadcast(void);
82f8381cbaSThomas Gleixner 
83f8381cbaSThomas Gleixner extern void
84f8381cbaSThomas Gleixner tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
85f8381cbaSThomas Gleixner 
86f8381cbaSThomas Gleixner #else /* !BROADCAST */
87f8381cbaSThomas Gleixner 
88f8381cbaSThomas Gleixner static inline int tick_check_broadcast_device(struct clock_event_device *dev)
89f8381cbaSThomas Gleixner {
90f8381cbaSThomas Gleixner 	return 0;
91f8381cbaSThomas Gleixner }
92f8381cbaSThomas Gleixner 
93f8381cbaSThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev)
94f8381cbaSThomas Gleixner {
95f8381cbaSThomas Gleixner 	return 0;
96f8381cbaSThomas Gleixner }
97f8381cbaSThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev,
98f8381cbaSThomas Gleixner 					     int cpu)
99f8381cbaSThomas Gleixner {
100f8381cbaSThomas Gleixner 	return 0;
101f8381cbaSThomas Gleixner }
102f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
103f8381cbaSThomas Gleixner static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
104f8381cbaSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
1056321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { }
1066321dd60SThomas Gleixner static inline int tick_resume_broadcast(void) { return 0; }
107f8381cbaSThomas Gleixner 
108f8381cbaSThomas Gleixner /*
109f8381cbaSThomas Gleixner  * Set the periodic handler in non broadcast mode
110f8381cbaSThomas Gleixner  */
111f8381cbaSThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev,
112f8381cbaSThomas Gleixner 					     int broadcast)
113f8381cbaSThomas Gleixner {
114f8381cbaSThomas Gleixner 	dev->event_handler = tick_handle_periodic;
115f8381cbaSThomas Gleixner }
116f8381cbaSThomas Gleixner #endif /* !BROADCAST */
117f8381cbaSThomas Gleixner 
118f8381cbaSThomas Gleixner /*
119f8381cbaSThomas Gleixner  * Check, if the device is functional or a dummy for broadcast
120f8381cbaSThomas Gleixner  */
121f8381cbaSThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev)
122f8381cbaSThomas Gleixner {
123f8381cbaSThomas Gleixner 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
124f8381cbaSThomas Gleixner }
125