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 |
| 48 | /* |
| 49 | * x86(64) specific misfeatures: |
| 50 | * |
| 51 | * - Clockevent source stops in C3 State and needs broadcast support. |
| 52 | * - Local APIC timer is used as a dummy device. |
| 53 | */ |
| 54 | #define CLOCK_EVT_FEAT_C3STOP 0x000004 |
| 55 | #define CLOCK_EVT_FEAT_DUMMY 0x000008 |
| 56 | |
| 57 | /** |
| 58 | * struct clock_event_device - clock event device descriptor |
| 59 | * @name: ptr to clock event name |
Sergei Shtylyov | ce0be12 | 2007-05-08 00:31:55 -0700 | [diff] [blame] | 60 | * @features: features |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 61 | * @max_delta_ns: maximum delta value in ns |
| 62 | * @min_delta_ns: minimum delta value in ns |
| 63 | * @mult: nanosecond to cycles multiplier |
| 64 | * @shift: nanoseconds to cycles divisor (power of two) |
| 65 | * @rating: variable to rate clock event devices |
Sergei Shtylyov | ce0be12 | 2007-05-08 00:31:55 -0700 | [diff] [blame] | 66 | * @irq: IRQ number (only for non CPU local devices) |
| 67 | * @cpumask: cpumask to indicate for which CPUs this device works |
| 68 | * @set_next_event: set next event function |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 69 | * @set_mode: set mode function |
Sergei Shtylyov | ce0be12 | 2007-05-08 00:31:55 -0700 | [diff] [blame] | 70 | * @event_handler: Assigned by the framework to be called by the low |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 71 | * level handler of the event source |
| 72 | * @broadcast: function to broadcast events |
| 73 | * @list: list head for the management code |
| 74 | * @mode: operating mode assigned by the management code |
| 75 | * @next_event: local storage for the next event in oneshot mode |
Thomas Gleixner | 80a05b9 | 2010-03-12 17:34:14 +0100 | [diff] [blame] | 76 | * @retries: number of forced programming retries |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 77 | */ |
| 78 | struct clock_event_device { |
| 79 | const char *name; |
| 80 | unsigned int features; |
Jon Hunter | 97813f2 | 2009-08-18 12:45:11 -0500 | [diff] [blame] | 81 | u64 max_delta_ns; |
| 82 | u64 min_delta_ns; |
Thomas Gleixner | 23af368 | 2009-11-11 14:05:25 +0000 | [diff] [blame] | 83 | u32 mult; |
| 84 | u32 shift; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 85 | int rating; |
| 86 | int irq; |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 87 | const struct cpumask *cpumask; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 88 | int (*set_next_event)(unsigned long evt, |
| 89 | struct clock_event_device *); |
| 90 | void (*set_mode)(enum clock_event_mode mode, |
| 91 | struct clock_event_device *); |
| 92 | void (*event_handler)(struct clock_event_device *); |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 93 | void (*broadcast)(const struct cpumask *mask); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 94 | struct list_head list; |
| 95 | enum clock_event_mode mode; |
| 96 | ktime_t next_event; |
Thomas Gleixner | 80a05b9 | 2010-03-12 17:34:14 +0100 | [diff] [blame] | 97 | unsigned long retries; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /* |
| 101 | * Calculate a multiplication factor for scaled math, which is used to convert |
| 102 | * nanoseconds based values to clock ticks: |
| 103 | * |
| 104 | * clock_ticks = (nanoseconds * factor) >> shift. |
| 105 | * |
| 106 | * div_sc is the rearranged equation to calculate a factor from a given clock |
| 107 | * ticks / nanoseconds ratio: |
| 108 | * |
| 109 | * factor = (clock_ticks << shift) / nanoseconds |
| 110 | */ |
| 111 | static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec, |
| 112 | int shift) |
| 113 | { |
| 114 | uint64_t tmp = ((uint64_t)ticks) << shift; |
| 115 | |
| 116 | do_div(tmp, nsec); |
| 117 | return (unsigned long) tmp; |
| 118 | } |
| 119 | |
| 120 | /* Clock event layer functions */ |
Jon Hunter | 97813f2 | 2009-08-18 12:45:11 -0500 | [diff] [blame] | 121 | extern u64 clockevent_delta2ns(unsigned long latch, |
| 122 | struct clock_event_device *evt); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 123 | extern void clockevents_register_device(struct clock_event_device *dev); |
| 124 | |
| 125 | extern void clockevents_exchange_device(struct clock_event_device *old, |
| 126 | struct clock_event_device *new); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 127 | extern void clockevents_set_mode(struct clock_event_device *dev, |
| 128 | enum clock_event_mode mode); |
| 129 | extern int clockevents_register_notifier(struct notifier_block *nb); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 130 | extern int clockevents_program_event(struct clock_event_device *dev, |
| 131 | ktime_t expires, ktime_t now); |
| 132 | |
Venkatesh Pallipadi | 7c1e768 | 2008-09-03 21:36:50 +0000 | [diff] [blame] | 133 | extern void clockevents_handle_noop(struct clock_event_device *dev); |
| 134 | |
Thomas Gleixner | 7d2f944 | 2009-11-11 14:05:29 +0000 | [diff] [blame] | 135 | static inline void |
| 136 | clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec) |
| 137 | { |
| 138 | return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, |
| 139 | freq, minsec); |
| 140 | } |
| 141 | |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 142 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 143 | extern void clockevents_notify(unsigned long reason, void *arg); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 144 | #else |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 145 | # define clockevents_notify(reason, arg) do { } while (0) |
| 146 | #endif |
| 147 | |
| 148 | #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */ |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 149 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 150 | #define clockevents_notify(reason, arg) do { } while (0) |
| 151 | |
| 152 | #endif |
| 153 | |
| 154 | #endif |