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