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