Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
[deliverable/linux.git] / include / linux / clockchips.h
CommitLineData
d316c57f
TG
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
4dbad816
DL
11/* Clock event notification values */
12enum 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
de68d9b1 25#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
d316c57f
TG
26
27#include <linux/clocksource.h>
28#include <linux/cpumask.h>
29#include <linux/ktime.h>
30#include <linux/notifier.h>
31
32struct clock_event_device;
ccf33d68 33struct module;
d316c57f
TG
34
35/* Clock event mode commands */
36enum clock_event_mode {
37 CLOCK_EVT_MODE_UNUSED = 0,
38 CLOCK_EVT_MODE_SHUTDOWN,
39 CLOCK_EVT_MODE_PERIODIC,
40 CLOCK_EVT_MODE_ONESHOT,
18de5bc4 41 CLOCK_EVT_MODE_RESUME,
d316c57f
TG
42};
43
d316c57f
TG
44/*
45 * Clock event features
46 */
47#define CLOCK_EVT_FEAT_PERIODIC 0x000001
48#define CLOCK_EVT_FEAT_ONESHOT 0x000002
65516f8a 49#define CLOCK_EVT_FEAT_KTIME 0x000004
d316c57f
TG
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 */
65516f8a
MS
56#define CLOCK_EVT_FEAT_C3STOP 0x000008
57#define CLOCK_EVT_FEAT_DUMMY 0x000010
d316c57f 58
d2348fb6
DL
59/*
60 * Core shall set the interrupt affinity dynamically in broadcast mode
61 */
62#define CLOCK_EVT_FEAT_DYNIRQ 0x000020
3713c0cf 63#define CLOCK_EVT_FEAT_PERCPU 0x000040
d2348fb6 64
d316c57f
TG
65/**
66 * struct clock_event_device - clock event device descriptor
847b2f42
TG
67 * @event_handler: Assigned by the framework to be called by the low
68 * level handler of the event source
65516f8a
MS
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
847b2f42 71 * @next_event: local storage for the next event in oneshot mode
d316c57f
TG
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)
847b2f42
TG
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
57f0fcbe
TG
81 * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
82 * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
847b2f42 83 * @name: ptr to clock event name
d316c57f 84 * @rating: variable to rate clock event devices
ce0be127
SS
85 * @irq: IRQ number (only for non CPU local devices)
86 * @cpumask: cpumask to indicate for which CPUs this device works
d316c57f 87 * @list: list head for the management code
ccf33d68 88 * @owner: module reference
d316c57f
TG
89 */
90struct clock_event_device {
847b2f42
TG
91 void (*event_handler)(struct clock_event_device *);
92 int (*set_next_event)(unsigned long evt,
93 struct clock_event_device *);
65516f8a
MS
94 int (*set_next_ktime)(ktime_t expires,
95 struct clock_event_device *);
847b2f42 96 ktime_t next_event;
97813f2f
JH
97 u64 max_delta_ns;
98 u64 min_delta_ns;
23af368e
TG
99 u32 mult;
100 u32 shift;
847b2f42
TG
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 *);
adc78e6b
RW
108 void (*suspend)(struct clock_event_device *);
109 void (*resume)(struct clock_event_device *);
57f0fcbe
TG
110 unsigned long min_delta_ticks;
111 unsigned long max_delta_ticks;
112
847b2f42 113 const char *name;
d316c57f
TG
114 int rating;
115 int irq;
320ab2b0 116 const struct cpumask *cpumask;
d316c57f 117 struct list_head list;
ccf33d68 118 struct module *owner;
847b2f42 119} ____cacheline_aligned;
d316c57f
TG
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 */
132static 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 */
97813f2f
JH
142extern u64 clockevent_delta2ns(unsigned long latch,
143 struct clock_event_device *evt);
d316c57f 144extern void clockevents_register_device(struct clock_event_device *dev);
03e13cf5 145extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
d316c57f 146
e5400321 147extern void clockevents_config(struct clock_event_device *dev, u32 freq);
57f0fcbe
TG
148extern void clockevents_config_and_register(struct clock_event_device *dev,
149 u32 freq, unsigned long min_delta,
150 unsigned long max_delta);
151
80b816b7
TG
152extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
153
d316c57f
TG
154extern void clockevents_exchange_device(struct clock_event_device *old,
155 struct clock_event_device *new);
d316c57f
TG
156extern void clockevents_set_mode(struct clock_event_device *dev,
157 enum clock_event_mode mode);
d316c57f 158extern int clockevents_program_event(struct clock_event_device *dev,
d1748302 159 ktime_t expires, bool force);
d316c57f 160
7c1e7689
VP
161extern void clockevents_handle_noop(struct clock_event_device *dev);
162
7d2f944a
TG
163static inline void
164clockevents_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
adc78e6b
RW
170extern void clockevents_suspend(void);
171extern void clockevents_resume(void);
172
12572dbb 173#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
12ad1000
MR
174#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
175extern void tick_broadcast(const struct cpumask *mask);
176#else
177#define tick_broadcast NULL
178#endif
12572dbb
MR
179extern int tick_receive_broadcast(void);
180#endif
181
eaa907c5
TG
182#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
183extern int tick_check_broadcast_expired(void);
184#else
185static inline int tick_check_broadcast_expired(void) { return 0; }
186#endif
187
de68d9b1 188#ifdef CONFIG_GENERIC_CLOCKEVENTS
d316c57f 189extern void clockevents_notify(unsigned long reason, void *arg);
d316c57f 190#else
4dbad816 191static inline void clockevents_notify(unsigned long reason, void *arg) {}
de68d9b1
TG
192#endif
193
194#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
d316c57f 195
adc78e6b
RW
196static inline void clockevents_suspend(void) {}
197static inline void clockevents_resume(void) {}
198
4dbad816 199static inline void clockevents_notify(unsigned long reason, void *arg) {}
19919226 200static inline int tick_check_broadcast_expired(void) { return 0; }
d316c57f
TG
201
202#endif
203
204#endif
This page took 0.557716 seconds and 5 git commands to generate.