blob: 20a100fe2b4f3040554f3994706d8f7b238460af [file] [log] [blame]
Thomas Gleixnerd316c572007-02-16 01:28:00 -08001/* 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 Gleixnerde68d9b2007-10-12 23:04:05 +020011#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
Thomas Gleixnerd316c572007-02-16 01:28:00 -080012
13#include <linux/clocksource.h>
14#include <linux/cpumask.h>
15#include <linux/ktime.h>
16#include <linux/notifier.h>
17
18struct clock_event_device;
19
20/* Clock event mode commands */
21enum 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 Gleixner18de5bc2007-07-21 04:37:34 -070026 CLOCK_EVT_MODE_RESUME,
Thomas Gleixnerd316c572007-02-16 01:28:00 -080027};
28
29/* Clock event notification values */
30enum clock_event_nofitiers {
31 CLOCK_EVT_NOTIFY_ADD,
32 CLOCK_EVT_NOTIFY_BROADCAST_ON,
33 CLOCK_EVT_NOTIFY_BROADCAST_OFF,
Thomas Gleixner1595f452007-10-14 22:57:45 +020034 CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
Thomas Gleixnerd316c572007-02-16 01:28:00 -080035 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
36 CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
37 CLOCK_EVT_NOTIFY_SUSPEND,
38 CLOCK_EVT_NOTIFY_RESUME,
Sebastien Dugue94df7de2008-12-01 14:09:07 +010039 CLOCK_EVT_NOTIFY_CPU_DYING,
Thomas Gleixnerd316c572007-02-16 01:28:00 -080040 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 Shtylyovce0be122007-05-08 00:31:55 -070060 * @features: features
Thomas Gleixnerd316c572007-02-16 01:28:00 -080061 * @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 Shtylyovce0be122007-05-08 00:31:55 -070066 * @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 Gleixnerd316c572007-02-16 01:28:00 -080069 * @set_mode: set mode function
Sergei Shtylyovce0be122007-05-08 00:31:55 -070070 * @event_handler: Assigned by the framework to be called by the low
Thomas Gleixnerd316c572007-02-16 01:28:00 -080071 * 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
76 */
77struct clock_event_device {
78 const char *name;
79 unsigned int features;
80 unsigned long max_delta_ns;
81 unsigned long min_delta_ns;
82 unsigned long mult;
83 int shift;
84 int rating;
85 int irq;
Rusty Russell320ab2b2008-12-13 21:20:26 +103086 const struct cpumask *cpumask;
Thomas Gleixnerd316c572007-02-16 01:28:00 -080087 int (*set_next_event)(unsigned long evt,
88 struct clock_event_device *);
89 void (*set_mode)(enum clock_event_mode mode,
90 struct clock_event_device *);
91 void (*event_handler)(struct clock_event_device *);
Rusty Russell320ab2b2008-12-13 21:20:26 +103092 void (*broadcast)(const struct cpumask *mask);
Thomas Gleixnerd316c572007-02-16 01:28:00 -080093 struct list_head list;
94 enum clock_event_mode mode;
95 ktime_t next_event;
96};
97
98/*
99 * Calculate a multiplication factor for scaled math, which is used to convert
100 * nanoseconds based values to clock ticks:
101 *
102 * clock_ticks = (nanoseconds * factor) >> shift.
103 *
104 * div_sc is the rearranged equation to calculate a factor from a given clock
105 * ticks / nanoseconds ratio:
106 *
107 * factor = (clock_ticks << shift) / nanoseconds
108 */
109static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
110 int shift)
111{
112 uint64_t tmp = ((uint64_t)ticks) << shift;
113
114 do_div(tmp, nsec);
115 return (unsigned long) tmp;
116}
117
118/* Clock event layer functions */
119extern unsigned long clockevent_delta2ns(unsigned long latch,
120 struct clock_event_device *evt);
121extern void clockevents_register_device(struct clock_event_device *dev);
122
123extern void clockevents_exchange_device(struct clock_event_device *old,
124 struct clock_event_device *new);
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800125extern void clockevents_set_mode(struct clock_event_device *dev,
126 enum clock_event_mode mode);
127extern int clockevents_register_notifier(struct notifier_block *nb);
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800128extern int clockevents_program_event(struct clock_event_device *dev,
129 ktime_t expires, ktime_t now);
130
Venkatesh Pallipadi7c1e7682008-09-03 21:36:50 +0000131extern void clockevents_handle_noop(struct clock_event_device *dev);
132
Thomas Gleixnerde68d9b2007-10-12 23:04:05 +0200133#ifdef CONFIG_GENERIC_CLOCKEVENTS
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800134extern void clockevents_notify(unsigned long reason, void *arg);
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800135#else
Thomas Gleixnerde68d9b2007-10-12 23:04:05 +0200136# define clockevents_notify(reason, arg) do { } while (0)
137#endif
138
139#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800140
Thomas Gleixnerd316c572007-02-16 01:28:00 -0800141#define clockevents_notify(reason, arg) do { } while (0)
142
143#endif
144
145#endif
Arun R Bharadwajeea08f32009-04-16 12:16:41 +0530146
147#ifdef CONFIG_GENERIC_CLOCKEVENTS
148extern ktime_t clockevents_get_next_event(int cpu);
149#else
150static inline ktime_t clockevents_get_next_event(int cpu)
151{
152 return (ktime_t) { .tv64 = KTIME_MAX };
153}
154#endif