Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 1 | /* linux/include/linux/clockchips.h |
| 2 | * |
| 3 | * This file contains the structure definitions for clockchips. |
| 4 | * |
| 5 | * If you are not a clockchip, or the time of day code, you should |
| 6 | * not be including this file! |
| 7 | */ |
| 8 | #ifndef _LINUX_CLOCKCHIPS_H |
| 9 | #define _LINUX_CLOCKCHIPS_H |
| 10 | |
Daniel Lezcano | 4dbad81 | 2013-03-27 10:22:09 +0000 | [diff] [blame] | 11 | /* Clock event notification values */ |
| 12 | enum clock_event_nofitiers { |
| 13 | CLOCK_EVT_NOTIFY_ADD, |
| 14 | CLOCK_EVT_NOTIFY_BROADCAST_ON, |
| 15 | CLOCK_EVT_NOTIFY_BROADCAST_OFF, |
| 16 | CLOCK_EVT_NOTIFY_BROADCAST_FORCE, |
| 17 | CLOCK_EVT_NOTIFY_BROADCAST_ENTER, |
| 18 | CLOCK_EVT_NOTIFY_BROADCAST_EXIT, |
| 19 | CLOCK_EVT_NOTIFY_SUSPEND, |
| 20 | CLOCK_EVT_NOTIFY_RESUME, |
| 21 | CLOCK_EVT_NOTIFY_CPU_DYING, |
| 22 | CLOCK_EVT_NOTIFY_CPU_DEAD, |
| 23 | }; |
| 24 | |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 25 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 26 | |
| 27 | #include <linux/clocksource.h> |
| 28 | #include <linux/cpumask.h> |
| 29 | #include <linux/ktime.h> |
| 30 | #include <linux/notifier.h> |
| 31 | |
| 32 | struct clock_event_device; |
Thomas Gleixner | ccf33d6 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 33 | struct module; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 34 | |
| 35 | /* Clock event mode commands */ |
| 36 | enum clock_event_mode { |
| 37 | CLOCK_EVT_MODE_UNUSED = 0, |
| 38 | CLOCK_EVT_MODE_SHUTDOWN, |
| 39 | CLOCK_EVT_MODE_PERIODIC, |
| 40 | CLOCK_EVT_MODE_ONESHOT, |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 41 | CLOCK_EVT_MODE_RESUME, |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 44 | /* |
| 45 | * Clock event features |
| 46 | */ |
| 47 | #define CLOCK_EVT_FEAT_PERIODIC 0x000001 |
| 48 | #define CLOCK_EVT_FEAT_ONESHOT 0x000002 |
Martin Schwidefsky | 65516f8 | 2011-08-23 15:29:43 +0200 | [diff] [blame] | 49 | #define CLOCK_EVT_FEAT_KTIME 0x000004 |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 50 | /* |
| 51 | * x86(64) specific misfeatures: |
| 52 | * |
| 53 | * - Clockevent source stops in C3 State and needs broadcast support. |
| 54 | * - Local APIC timer is used as a dummy device. |
| 55 | */ |
Martin Schwidefsky | 65516f8 | 2011-08-23 15:29:43 +0200 | [diff] [blame] | 56 | #define CLOCK_EVT_FEAT_C3STOP 0x000008 |
| 57 | #define CLOCK_EVT_FEAT_DUMMY 0x000010 |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 58 | |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 59 | /* |
| 60 | * Core shall set the interrupt affinity dynamically in broadcast mode |
| 61 | */ |
| 62 | #define CLOCK_EVT_FEAT_DYNIRQ 0x000020 |
Soren Brinkmann | 3713c0c | 2013-09-18 11:48:35 -0700 | [diff] [blame] | 63 | #define CLOCK_EVT_FEAT_PERCPU 0x000040 |
Daniel Lezcano | d2348fb | 2013-03-02 11:10:11 +0100 | [diff] [blame] | 64 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 65 | /** |
| 66 | * struct clock_event_device - clock event device descriptor |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 67 | * @event_handler: Assigned by the framework to be called by the low |
| 68 | * level handler of the event source |
Martin Schwidefsky | 65516f8 | 2011-08-23 15:29:43 +0200 | [diff] [blame] | 69 | * @set_next_event: set next event function using a clocksource delta |
| 70 | * @set_next_ktime: set next event function using a direct ktime value |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 71 | * @next_event: local storage for the next event in oneshot mode |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 72 | * @max_delta_ns: maximum delta value in ns |
| 73 | * @min_delta_ns: minimum delta value in ns |
| 74 | * @mult: nanosecond to cycles multiplier |
| 75 | * @shift: nanoseconds to cycles divisor (power of two) |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 76 | * @mode: operating mode assigned by the management code |
| 77 | * @features: features |
| 78 | * @retries: number of forced programming retries |
| 79 | * @set_mode: set mode function |
| 80 | * @broadcast: function to broadcast events |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 81 | * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration |
| 82 | * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 83 | * @name: ptr to clock event name |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 84 | * @rating: variable to rate clock event devices |
Sergei Shtylyov | ce0be12 | 2007-05-08 00:31:55 -0700 | [diff] [blame] | 85 | * @irq: IRQ number (only for non CPU local devices) |
| 86 | * @cpumask: cpumask to indicate for which CPUs this device works |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 87 | * @list: list head for the management code |
Thomas Gleixner | ccf33d6 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 88 | * @owner: module reference |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 89 | */ |
| 90 | struct clock_event_device { |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 91 | void (*event_handler)(struct clock_event_device *); |
| 92 | int (*set_next_event)(unsigned long evt, |
| 93 | struct clock_event_device *); |
Martin Schwidefsky | 65516f8 | 2011-08-23 15:29:43 +0200 | [diff] [blame] | 94 | int (*set_next_ktime)(ktime_t expires, |
| 95 | struct clock_event_device *); |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 96 | ktime_t next_event; |
Jon Hunter | 97813f2 | 2009-08-18 12:45:11 -0500 | [diff] [blame] | 97 | u64 max_delta_ns; |
| 98 | u64 min_delta_ns; |
Thomas Gleixner | 23af368 | 2009-11-11 14:05:25 +0000 | [diff] [blame] | 99 | u32 mult; |
| 100 | u32 shift; |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 101 | enum clock_event_mode mode; |
| 102 | unsigned int features; |
| 103 | unsigned long retries; |
| 104 | |
| 105 | void (*broadcast)(const struct cpumask *mask); |
| 106 | void (*set_mode)(enum clock_event_mode mode, |
| 107 | struct clock_event_device *); |
Rafael J. Wysocki | adc78e6 | 2012-08-06 01:40:41 +0200 | [diff] [blame] | 108 | void (*suspend)(struct clock_event_device *); |
| 109 | void (*resume)(struct clock_event_device *); |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 110 | unsigned long min_delta_ticks; |
| 111 | unsigned long max_delta_ticks; |
| 112 | |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 113 | const char *name; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 114 | int rating; |
| 115 | int irq; |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 116 | const struct cpumask *cpumask; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 117 | struct list_head list; |
Thomas Gleixner | ccf33d6 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 118 | struct module *owner; |
Thomas Gleixner | 847b2f4 | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 119 | } ____cacheline_aligned; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Calculate a multiplication factor for scaled math, which is used to convert |
| 123 | * nanoseconds based values to clock ticks: |
| 124 | * |
| 125 | * clock_ticks = (nanoseconds * factor) >> shift. |
| 126 | * |
| 127 | * div_sc is the rearranged equation to calculate a factor from a given clock |
| 128 | * ticks / nanoseconds ratio: |
| 129 | * |
| 130 | * factor = (clock_ticks << shift) / nanoseconds |
| 131 | */ |
| 132 | static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec, |
| 133 | int shift) |
| 134 | { |
| 135 | uint64_t tmp = ((uint64_t)ticks) << shift; |
| 136 | |
| 137 | do_div(tmp, nsec); |
| 138 | return (unsigned long) tmp; |
| 139 | } |
| 140 | |
| 141 | /* Clock event layer functions */ |
Jon Hunter | 97813f2 | 2009-08-18 12:45:11 -0500 | [diff] [blame] | 142 | extern u64 clockevent_delta2ns(unsigned long latch, |
| 143 | struct clock_event_device *evt); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 144 | extern void clockevents_register_device(struct clock_event_device *dev); |
Thomas Gleixner | 03e13cf | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 145 | extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 146 | |
Magnus Damm | e540032 | 2012-05-09 23:39:34 +0900 | [diff] [blame] | 147 | extern void clockevents_config(struct clock_event_device *dev, u32 freq); |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 148 | extern void clockevents_config_and_register(struct clock_event_device *dev, |
| 149 | u32 freq, unsigned long min_delta, |
| 150 | unsigned long max_delta); |
| 151 | |
Thomas Gleixner | 80b816b | 2011-05-18 21:33:42 +0000 | [diff] [blame] | 152 | extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq); |
| 153 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 154 | extern void clockevents_exchange_device(struct clock_event_device *old, |
| 155 | struct clock_event_device *new); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 156 | extern void clockevents_set_mode(struct clock_event_device *dev, |
| 157 | enum clock_event_mode mode); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 158 | extern int clockevents_program_event(struct clock_event_device *dev, |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 159 | ktime_t expires, bool force); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 160 | |
Venkatesh Pallipadi | 7c1e768 | 2008-09-03 21:36:50 +0000 | [diff] [blame] | 161 | extern void clockevents_handle_noop(struct clock_event_device *dev); |
| 162 | |
Thomas Gleixner | 7d2f944 | 2009-11-11 14:05:29 +0000 | [diff] [blame] | 163 | static inline void |
| 164 | clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec) |
| 165 | { |
| 166 | return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, |
| 167 | freq, minsec); |
| 168 | } |
| 169 | |
Rafael J. Wysocki | adc78e6 | 2012-08-06 01:40:41 +0200 | [diff] [blame] | 170 | extern void clockevents_suspend(void); |
| 171 | extern void clockevents_resume(void); |
| 172 | |
Mark Rutland | 12572db | 2013-01-14 17:05:21 +0000 | [diff] [blame] | 173 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
Mark Rutland | 12ad100 | 2013-01-14 17:05:22 +0000 | [diff] [blame] | 174 | #ifdef CONFIG_ARCH_HAS_TICK_BROADCAST |
| 175 | extern void tick_broadcast(const struct cpumask *mask); |
| 176 | #else |
| 177 | #define tick_broadcast NULL |
| 178 | #endif |
Mark Rutland | 12572db | 2013-01-14 17:05:21 +0000 | [diff] [blame] | 179 | extern int tick_receive_broadcast(void); |
| 180 | #endif |
| 181 | |
Thomas Gleixner | eaa907c | 2013-03-06 11:18:36 +0000 | [diff] [blame] | 182 | #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT) |
| 183 | extern int tick_check_broadcast_expired(void); |
| 184 | #else |
| 185 | static inline int tick_check_broadcast_expired(void) { return 0; } |
| 186 | #endif |
| 187 | |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 188 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 189 | extern void clockevents_notify(unsigned long reason, void *arg); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 190 | #else |
Daniel Lezcano | 4dbad81 | 2013-03-27 10:22:09 +0000 | [diff] [blame] | 191 | static inline void clockevents_notify(unsigned long reason, void *arg) {} |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 192 | #endif |
| 193 | |
| 194 | #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */ |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 195 | |
Rafael J. Wysocki | adc78e6 | 2012-08-06 01:40:41 +0200 | [diff] [blame] | 196 | static inline void clockevents_suspend(void) {} |
| 197 | static inline void clockevents_resume(void) {} |
| 198 | |
Daniel Lezcano | 4dbad81 | 2013-03-27 10:22:09 +0000 | [diff] [blame] | 199 | static inline void clockevents_notify(unsigned long reason, void *arg) {} |
Thomas Gleixner | 1991922 | 2013-03-22 10:48:33 +0100 | [diff] [blame] | 200 | static inline int tick_check_broadcast_expired(void) { return 0; } |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 201 | |
| 202 | #endif |
| 203 | |
| 204 | #endif |