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 1403e13cf5SThomas Gleixner #define CS_NAME_LEN 32 1503e13cf5SThomas Gleixner 16f8381cbaSThomas Gleixner DECLARE_PER_CPU(struct tick_device, tick_cpu_device); 17f8381cbaSThomas Gleixner extern ktime_t tick_next_period; 18f8381cbaSThomas Gleixner extern ktime_t tick_period; 19d3ed7824SThomas Gleixner extern int tick_do_timer_cpu __read_mostly; 20f8381cbaSThomas Gleixner 21f8381cbaSThomas Gleixner extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast); 22f8381cbaSThomas Gleixner extern void tick_handle_periodic(struct clock_event_device *dev); 237172a286SThomas Gleixner extern void tick_check_new_device(struct clock_event_device *dev); 248c53daf6SThomas Gleixner extern void tick_handover_do_timer(int *cpup); 258c53daf6SThomas Gleixner extern void tick_shutdown(unsigned int *cpup); 268c53daf6SThomas Gleixner extern void tick_suspend(void); 278c53daf6SThomas Gleixner extern void tick_resume(void); 2803e13cf5SThomas Gleixner extern bool tick_check_replacement(struct clock_event_device *curdev, 2903e13cf5SThomas Gleixner struct clock_event_device *newdev); 3003e13cf5SThomas Gleixner extern void tick_install_replacement(struct clock_event_device *dev); 31f8381cbaSThomas Gleixner 322344abbcSThomas Gleixner extern void clockevents_shutdown(struct clock_event_device *dev); 332344abbcSThomas Gleixner 3403e13cf5SThomas Gleixner extern size_t sysfs_get_uname(const char *buf, char *dst, size_t cnt); 3503e13cf5SThomas Gleixner 36f8381cbaSThomas Gleixner /* 3779bf2bb3SThomas Gleixner * NO_HZ / high resolution timer shared code 3879bf2bb3SThomas Gleixner */ 3979bf2bb3SThomas Gleixner #ifdef CONFIG_TICK_ONESHOT 4079bf2bb3SThomas Gleixner extern void tick_setup_oneshot(struct clock_event_device *newdev, 4179bf2bb3SThomas Gleixner void (*handler)(struct clock_event_device *), 4279bf2bb3SThomas Gleixner ktime_t nextevt); 4379bf2bb3SThomas Gleixner extern int tick_program_event(ktime_t expires, int force); 4479bf2bb3SThomas Gleixner extern void tick_oneshot_notify(void); 4579bf2bb3SThomas Gleixner extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)); 46cd05a1f8SThomas Gleixner extern void tick_resume_oneshot(void); 4779bf2bb3SThomas Gleixner # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 4879bf2bb3SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc); 4979bf2bb3SThomas Gleixner extern void tick_broadcast_oneshot_control(unsigned long reason); 5079bf2bb3SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void); 5179bf2bb3SThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup); 52cd05a1f8SThomas Gleixner extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc); 5327ce4cb4SThomas Gleixner extern int tick_broadcast_oneshot_active(void); 54fb02fbc1SThomas Gleixner extern void tick_check_oneshot_broadcast(int cpu); 553a142a06SThomas Gleixner bool tick_broadcast_oneshot_available(void); 5679bf2bb3SThomas Gleixner # else /* BROADCAST */ 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_broadcast_switch_to_oneshot(void) { } 6379bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } 6427ce4cb4SThomas Gleixner static inline int tick_broadcast_oneshot_active(void) { return 0; } 65fb02fbc1SThomas Gleixner static inline void tick_check_oneshot_broadcast(int cpu) { } 663a142a06SThomas Gleixner static inline bool tick_broadcast_oneshot_available(void) { return true; } 6779bf2bb3SThomas Gleixner # endif /* !BROADCAST */ 6879bf2bb3SThomas Gleixner 6979bf2bb3SThomas Gleixner #else /* !ONESHOT */ 7079bf2bb3SThomas Gleixner static inline 7179bf2bb3SThomas Gleixner void tick_setup_oneshot(struct clock_event_device *newdev, 7279bf2bb3SThomas Gleixner void (*handler)(struct clock_event_device *), 7379bf2bb3SThomas Gleixner ktime_t nextevt) 7479bf2bb3SThomas Gleixner { 7579bf2bb3SThomas Gleixner BUG(); 7679bf2bb3SThomas Gleixner } 77cd05a1f8SThomas Gleixner static inline void tick_resume_oneshot(void) 78cd05a1f8SThomas Gleixner { 79cd05a1f8SThomas Gleixner BUG(); 80cd05a1f8SThomas Gleixner } 8179bf2bb3SThomas Gleixner static inline int tick_program_event(ktime_t expires, int force) 8279bf2bb3SThomas Gleixner { 8379bf2bb3SThomas Gleixner return 0; 8479bf2bb3SThomas Gleixner } 8579bf2bb3SThomas Gleixner static inline void tick_oneshot_notify(void) { } 8679bf2bb3SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) 8779bf2bb3SThomas Gleixner { 8879bf2bb3SThomas Gleixner BUG(); 8979bf2bb3SThomas Gleixner } 9079bf2bb3SThomas Gleixner static inline void tick_broadcast_oneshot_control(unsigned long reason) { } 9179bf2bb3SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } 92cd05a1f8SThomas Gleixner static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc) 93cd05a1f8SThomas Gleixner { 94cd05a1f8SThomas Gleixner return 0; 95cd05a1f8SThomas Gleixner } 96f8e256c6SIngo Molnar static inline int tick_broadcast_oneshot_active(void) { return 0; } 973a142a06SThomas Gleixner static inline bool tick_broadcast_oneshot_available(void) { return false; } 9879bf2bb3SThomas Gleixner #endif /* !TICK_ONESHOT */ 9979bf2bb3SThomas Gleixner 10079bf2bb3SThomas Gleixner /* 101f8381cbaSThomas Gleixner * Broadcasting support 102f8381cbaSThomas Gleixner */ 103f8381cbaSThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 104f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu); 1057172a286SThomas Gleixner extern void tick_install_broadcast_device(struct clock_event_device *dev); 106f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev); 107f8381cbaSThomas Gleixner extern void tick_broadcast_on_off(unsigned long reason, int *oncpu); 108f8381cbaSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int *cpup); 1096321dd60SThomas Gleixner extern void tick_suspend_broadcast(void); 1106321dd60SThomas Gleixner extern int tick_resume_broadcast(void); 111b352bc1cSThomas Gleixner extern void tick_broadcast_init(void); 112f8381cbaSThomas Gleixner extern void 113f8381cbaSThomas Gleixner tick_set_periodic_handler(struct clock_event_device *dev, int broadcast); 114f8381cbaSThomas Gleixner 115f8381cbaSThomas Gleixner #else /* !BROADCAST */ 116f8381cbaSThomas Gleixner 1177172a286SThomas Gleixner static inline void tick_install_broadcast_device(struct clock_event_device *dev) 118f8381cbaSThomas Gleixner { 119f8381cbaSThomas Gleixner } 120f8381cbaSThomas Gleixner 121f8381cbaSThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev) 122f8381cbaSThomas Gleixner { 123f8381cbaSThomas Gleixner return 0; 124f8381cbaSThomas Gleixner } 125f8381cbaSThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev, 126f8381cbaSThomas Gleixner int cpu) 127f8381cbaSThomas Gleixner { 128f8381cbaSThomas Gleixner return 0; 129f8381cbaSThomas Gleixner } 130f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { } 131f8381cbaSThomas Gleixner static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { } 132f8381cbaSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int *cpup) { } 1336321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { } 1346321dd60SThomas Gleixner static inline int tick_resume_broadcast(void) { return 0; } 135b352bc1cSThomas Gleixner static inline void tick_broadcast_init(void) { } 136f8381cbaSThomas Gleixner 137f8381cbaSThomas Gleixner /* 138f8381cbaSThomas Gleixner * Set the periodic handler in non broadcast mode 139f8381cbaSThomas Gleixner */ 140f8381cbaSThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev, 141f8381cbaSThomas Gleixner int broadcast) 142f8381cbaSThomas Gleixner { 143f8381cbaSThomas Gleixner dev->event_handler = tick_handle_periodic; 144f8381cbaSThomas Gleixner } 145f8381cbaSThomas Gleixner #endif /* !BROADCAST */ 146f8381cbaSThomas Gleixner 147f8381cbaSThomas Gleixner /* 148f8381cbaSThomas Gleixner * Check, if the device is functional or a dummy for broadcast 149f8381cbaSThomas Gleixner */ 150f8381cbaSThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev) 151f8381cbaSThomas Gleixner { 152f8381cbaSThomas Gleixner return !(dev->features & CLOCK_EVT_FEAT_DUMMY); 153f8381cbaSThomas Gleixner } 154e2830b5cSTorben Hohn 1557cf37e87SThomas Gleixner #endif 1567cf37e87SThomas Gleixner 157e2830b5cSTorben Hohn extern void do_timer(unsigned long ticks); 158