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 7eb93e4d9SThomas Gleixner extern seqlock_t jiffies_lock; 8eb93e4d9SThomas Gleixner 97cf37e87SThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD 106441402bSThomas Gleixner 116441402bSThomas Gleixner #define TICK_DO_TIMER_NONE -1 126441402bSThomas Gleixner #define TICK_DO_TIMER_BOOT -2 136441402bSThomas Gleixner 14f8381cbaSThomas Gleixner DECLARE_PER_CPU(struct tick_device, tick_cpu_device); 15f8381cbaSThomas Gleixner extern ktime_t tick_next_period; 16f8381cbaSThomas Gleixner extern ktime_t tick_period; 17d3ed7824SThomas Gleixner extern int tick_do_timer_cpu __read_mostly; 18f8381cbaSThomas Gleixner 19f8381cbaSThomas Gleixner extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast); 20f8381cbaSThomas Gleixner extern void tick_handle_periodic(struct clock_event_device *dev); 217172a286SThomas Gleixner extern void tick_check_new_device(struct clock_event_device *dev); 228c53daf6SThomas Gleixner extern void tick_handover_do_timer(int *cpup); 238c53daf6SThomas Gleixner extern void tick_shutdown(unsigned int *cpup); 248c53daf6SThomas Gleixner extern void tick_suspend(void); 258c53daf6SThomas Gleixner extern void tick_resume(void); 26f8381cbaSThomas Gleixner 272344abbcSThomas Gleixner extern void clockevents_shutdown(struct clock_event_device *dev); 282344abbcSThomas Gleixner 29f8381cbaSThomas Gleixner /* 3079bf2bb3SThomas Gleixner * NO_HZ / high resolution timer shared code 3179bf2bb3SThomas Gleixner */ 3279bf2bb3SThomas Gleixner #ifdef CONFIG_TICK_ONESHOT 3379bf2bb3SThomas Gleixner extern void tick_setup_oneshot(struct clock_event_device *newdev, 3479bf2bb3SThomas Gleixner void (*handler)(struct clock_event_device *), 3579bf2bb3SThomas Gleixner ktime_t nextevt); 3679bf2bb3SThomas Gleixner extern int tick_program_event(ktime_t expires, int force); 3779bf2bb3SThomas Gleixner extern void tick_oneshot_notify(void); 3879bf2bb3SThomas Gleixner extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)); 39cd05a1f8SThomas Gleixner extern void tick_resume_oneshot(void); 4079bf2bb3SThomas Gleixner # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 4179bf2bb3SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc); 4279bf2bb3SThomas Gleixner extern void tick_broadcast_oneshot_control(unsigned long reason); 4379bf2bb3SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void); 4479bf2bb3SThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup); 45cd05a1f8SThomas Gleixner extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc); 4627ce4cb4SThomas Gleixner extern int tick_broadcast_oneshot_active(void); 47fb02fbc1SThomas Gleixner extern void tick_check_oneshot_broadcast(int cpu); 483a142a06SThomas Gleixner bool tick_broadcast_oneshot_available(void); 4979bf2bb3SThomas Gleixner # else /* BROADCAST */ 5079bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) 5179bf2bb3SThomas Gleixner { 5279bf2bb3SThomas Gleixner BUG(); 5379bf2bb3SThomas Gleixner } 5479bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { } 5579bf2bb3SThomas Gleixner static inline void tick_broadcast_switch_to_oneshot(void) { } 5679bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } 5727ce4cb4SThomas Gleixner static inline int tick_broadcast_oneshot_active(void) { return 0; } 58fb02fbc1SThomas Gleixner static inline void tick_check_oneshot_broadcast(int cpu) { } 593a142a06SThomas Gleixner static inline bool tick_broadcast_oneshot_available(void) { return true; } 6079bf2bb3SThomas Gleixner # endif /* !BROADCAST */ 6179bf2bb3SThomas Gleixner 6279bf2bb3SThomas Gleixner #else /* !ONESHOT */ 6379bf2bb3SThomas Gleixner static inline 6479bf2bb3SThomas Gleixner void tick_setup_oneshot(struct clock_event_device *newdev, 6579bf2bb3SThomas Gleixner void (*handler)(struct clock_event_device *), 6679bf2bb3SThomas Gleixner ktime_t nextevt) 6779bf2bb3SThomas Gleixner { 6879bf2bb3SThomas Gleixner BUG(); 6979bf2bb3SThomas Gleixner } 70cd05a1f8SThomas Gleixner static inline void tick_resume_oneshot(void) 71cd05a1f8SThomas Gleixner { 72cd05a1f8SThomas Gleixner BUG(); 73cd05a1f8SThomas Gleixner } 7479bf2bb3SThomas Gleixner static inline int tick_program_event(ktime_t expires, int force) 7579bf2bb3SThomas Gleixner { 7679bf2bb3SThomas Gleixner return 0; 7779bf2bb3SThomas Gleixner } 7879bf2bb3SThomas Gleixner static inline void tick_oneshot_notify(void) { } 7979bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) 8079bf2bb3SThomas Gleixner { 8179bf2bb3SThomas Gleixner BUG(); 8279bf2bb3SThomas Gleixner } 8379bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { } 8479bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } 85cd05a1f8SThomas Gleixner static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc) 86cd05a1f8SThomas Gleixner { 87cd05a1f8SThomas Gleixner return 0; 88cd05a1f8SThomas Gleixner } 89f8e256c6SIngo Molnar static inline int tick_broadcast_oneshot_active(void) { return 0; } 903a142a06SThomas Gleixner static inline bool tick_broadcast_oneshot_available(void) { return false; } 9179bf2bb3SThomas Gleixner #endif /* !TICK_ONESHOT */ 9279bf2bb3SThomas Gleixner 9379bf2bb3SThomas Gleixner /* 94f8381cbaSThomas Gleixner * Broadcasting support 95f8381cbaSThomas Gleixner */ 96f8381cbaSThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 97f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu); 987172a286SThomas Gleixner extern void tick_install_broadcast_device(struct clock_event_device *dev); 99f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev); 100f8381cbaSThomas Gleixner extern void tick_broadcast_on_off(unsigned long reason, int *oncpu); 101f8381cbaSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int *cpup); 1026321dd60SThomas Gleixner extern void tick_suspend_broadcast(void); 1036321dd60SThomas Gleixner extern int tick_resume_broadcast(void); 104b352bc1cSThomas Gleixner extern void tick_broadcast_init(void); 105f8381cbaSThomas Gleixner extern void 106f8381cbaSThomas Gleixner tick_set_periodic_handler(struct clock_event_device *dev, int broadcast); 107f8381cbaSThomas Gleixner 108f8381cbaSThomas Gleixner #else /* !BROADCAST */ 109f8381cbaSThomas Gleixner 1107172a286SThomas Gleixner static inline void tick_install_broadcast_device(struct clock_event_device *dev) 111f8381cbaSThomas Gleixner { 112f8381cbaSThomas Gleixner } 113f8381cbaSThomas Gleixner 114f8381cbaSThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev) 115f8381cbaSThomas Gleixner { 116f8381cbaSThomas Gleixner return 0; 117f8381cbaSThomas Gleixner } 118f8381cbaSThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev, 119f8381cbaSThomas Gleixner int cpu) 120f8381cbaSThomas Gleixner { 121f8381cbaSThomas Gleixner return 0; 122f8381cbaSThomas Gleixner } 123f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { } 124f8381cbaSThomas Gleixner static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { } 125f8381cbaSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int *cpup) { } 1266321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { } 1276321dd60SThomas Gleixner static inline int tick_resume_broadcast(void) { return 0; } 128b352bc1cSThomas Gleixner static inline void tick_broadcast_init(void) { } 129f8381cbaSThomas Gleixner 130f8381cbaSThomas Gleixner /* 131f8381cbaSThomas Gleixner * Set the periodic handler in non broadcast mode 132f8381cbaSThomas Gleixner */ 133f8381cbaSThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev, 134f8381cbaSThomas Gleixner int broadcast) 135f8381cbaSThomas Gleixner { 136f8381cbaSThomas Gleixner dev->event_handler = tick_handle_periodic; 137f8381cbaSThomas Gleixner } 138f8381cbaSThomas Gleixner #endif /* !BROADCAST */ 139f8381cbaSThomas Gleixner 140f8381cbaSThomas Gleixner /* 141f8381cbaSThomas Gleixner * Check, if the device is functional or a dummy for broadcast 142f8381cbaSThomas Gleixner */ 143f8381cbaSThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev) 144f8381cbaSThomas Gleixner { 145f8381cbaSThomas Gleixner return !(dev->features & CLOCK_EVT_FEAT_DUMMY); 146f8381cbaSThomas Gleixner } 147e2830b5cSTorben Hohn 1487cf37e87SThomas Gleixner #endif 1497cf37e87SThomas Gleixner 150e2830b5cSTorben Hohn extern void do_timer(unsigned long ticks); 151