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