]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - include/linux/clockchips.h
clockevents: Restructure clock_event_device members
[mirror_ubuntu-focal-kernel.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
de68d9b1 11#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
d316c57f
TG
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,
18de5bc4 26 CLOCK_EVT_MODE_RESUME,
d316c57f
TG
27};
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,
1595f452 34 CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
d316c57f
TG
35 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
36 CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
37 CLOCK_EVT_NOTIFY_SUSPEND,
38 CLOCK_EVT_NOTIFY_RESUME,
94df7de0 39 CLOCK_EVT_NOTIFY_CPU_DYING,
d316c57f
TG
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
847b2f42
TG
59 * @event_handler: Assigned by the framework to be called by the low
60 * level handler of the event source
61 * @set_next_event: set next event function
62 * @next_event: local storage for the next event in oneshot mode
d316c57f
TG
63 * @max_delta_ns: maximum delta value in ns
64 * @min_delta_ns: minimum delta value in ns
65 * @mult: nanosecond to cycles multiplier
66 * @shift: nanoseconds to cycles divisor (power of two)
847b2f42
TG
67 * @mode: operating mode assigned by the management code
68 * @features: features
69 * @retries: number of forced programming retries
70 * @set_mode: set mode function
71 * @broadcast: function to broadcast events
72 * @name: ptr to clock event name
d316c57f 73 * @rating: variable to rate clock event devices
ce0be127
SS
74 * @irq: IRQ number (only for non CPU local devices)
75 * @cpumask: cpumask to indicate for which CPUs this device works
d316c57f 76 * @list: list head for the management code
d316c57f
TG
77 */
78struct clock_event_device {
847b2f42
TG
79 void (*event_handler)(struct clock_event_device *);
80 int (*set_next_event)(unsigned long evt,
81 struct clock_event_device *);
82 ktime_t next_event;
97813f2f
JH
83 u64 max_delta_ns;
84 u64 min_delta_ns;
23af368e
TG
85 u32 mult;
86 u32 shift;
847b2f42
TG
87 enum clock_event_mode mode;
88 unsigned int features;
89 unsigned long retries;
90
91 void (*broadcast)(const struct cpumask *mask);
92 void (*set_mode)(enum clock_event_mode mode,
93 struct clock_event_device *);
94 const char *name;
d316c57f
TG
95 int rating;
96 int irq;
320ab2b0 97 const struct cpumask *cpumask;
d316c57f 98 struct list_head list;
847b2f42 99} ____cacheline_aligned;
d316c57f
TG
100
101/*
102 * Calculate a multiplication factor for scaled math, which is used to convert
103 * nanoseconds based values to clock ticks:
104 *
105 * clock_ticks = (nanoseconds * factor) >> shift.
106 *
107 * div_sc is the rearranged equation to calculate a factor from a given clock
108 * ticks / nanoseconds ratio:
109 *
110 * factor = (clock_ticks << shift) / nanoseconds
111 */
112static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
113 int shift)
114{
115 uint64_t tmp = ((uint64_t)ticks) << shift;
116
117 do_div(tmp, nsec);
118 return (unsigned long) tmp;
119}
120
121/* Clock event layer functions */
97813f2f
JH
122extern u64 clockevent_delta2ns(unsigned long latch,
123 struct clock_event_device *evt);
d316c57f
TG
124extern void clockevents_register_device(struct clock_event_device *dev);
125
126extern void clockevents_exchange_device(struct clock_event_device *old,
127 struct clock_event_device *new);
d316c57f
TG
128extern void clockevents_set_mode(struct clock_event_device *dev,
129 enum clock_event_mode mode);
130extern int clockevents_register_notifier(struct notifier_block *nb);
d316c57f
TG
131extern int clockevents_program_event(struct clock_event_device *dev,
132 ktime_t expires, ktime_t now);
133
7c1e7689
VP
134extern void clockevents_handle_noop(struct clock_event_device *dev);
135
7d2f944a
TG
136static inline void
137clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
138{
139 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
140 freq, minsec);
141}
142
de68d9b1 143#ifdef CONFIG_GENERIC_CLOCKEVENTS
d316c57f 144extern void clockevents_notify(unsigned long reason, void *arg);
d316c57f 145#else
de68d9b1
TG
146# define clockevents_notify(reason, arg) do { } while (0)
147#endif
148
149#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
d316c57f 150
d316c57f
TG
151#define clockevents_notify(reason, arg) do { } while (0)
152
153#endif
154
155#endif