~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/clockchips.h

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.11 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.84 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.154 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.201 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.201 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.77 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 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 
 18 struct clock_event_device;
 19 struct module;
 20 
 21 /*
 22  * Possible states of a clock event device.
 23  *
 24  * DETACHED:    Device is not used by clockevents core. Initial state or can be
 25  *              reached from SHUTDOWN.
 26  * SHUTDOWN:    Device is powered-off. Can be reached from PERIODIC or ONESHOT.
 27  * PERIODIC:    Device is programmed to generate events periodically. Can be
 28  *              reached from DETACHED or SHUTDOWN.
 29  * ONESHOT:     Device is programmed to generate event only once. Can be reached
 30  *              from DETACHED or SHUTDOWN.
 31  * ONESHOT_STOPPED: Device was programmed in ONESHOT mode and is temporarily
 32  *                  stopped.
 33  */
 34 enum clock_event_state {
 35         CLOCK_EVT_STATE_DETACHED,
 36         CLOCK_EVT_STATE_SHUTDOWN,
 37         CLOCK_EVT_STATE_PERIODIC,
 38         CLOCK_EVT_STATE_ONESHOT,
 39         CLOCK_EVT_STATE_ONESHOT_STOPPED,
 40 };
 41 
 42 /*
 43  * Clock event features
 44  */
 45 # define CLOCK_EVT_FEAT_PERIODIC        0x000001
 46 # define CLOCK_EVT_FEAT_ONESHOT         0x000002
 47 # define CLOCK_EVT_FEAT_KTIME           0x000004
 48 
 49 /*
 50  * x86(64) specific (mis)features:
 51  *
 52  * - Clockevent source stops in C3 State and needs broadcast support.
 53  * - Local APIC timer is used as a dummy device.
 54  */
 55 # define CLOCK_EVT_FEAT_C3STOP          0x000008
 56 # define CLOCK_EVT_FEAT_DUMMY           0x000010
 57 
 58 /*
 59  * Core shall set the interrupt affinity dynamically in broadcast mode
 60  */
 61 # define CLOCK_EVT_FEAT_DYNIRQ          0x000020
 62 # define CLOCK_EVT_FEAT_PERCPU          0x000040
 63 
 64 /*
 65  * Clockevent device is based on a hrtimer for broadcast
 66  */
 67 # define CLOCK_EVT_FEAT_HRTIMER         0x000080
 68 
 69 /**
 70  * struct clock_event_device - clock event device descriptor
 71  * @event_handler:      Assigned by the framework to be called by the low
 72  *                      level handler of the event source
 73  * @set_next_event:     set next event function using a clocksource delta
 74  * @set_next_ktime:     set next event function using a direct ktime value
 75  * @next_event:         local storage for the next event in oneshot mode
 76  * @max_delta_ns:       maximum delta value in ns
 77  * @min_delta_ns:       minimum delta value in ns
 78  * @mult:               nanosecond to cycles multiplier
 79  * @shift:              nanoseconds to cycles divisor (power of two)
 80  * @state_use_accessors:current state of the device, assigned by the core code
 81  * @features:           features
 82  * @retries:            number of forced programming retries
 83  * @set_state_periodic: switch state to periodic
 84  * @set_state_oneshot:  switch state to oneshot
 85  * @set_state_oneshot_stopped: switch state to oneshot_stopped
 86  * @set_state_shutdown: switch state to shutdown
 87  * @tick_resume:        resume clkevt device
 88  * @broadcast:          function to broadcast events
 89  * @min_delta_ticks:    minimum delta value in ticks stored for reconfiguration
 90  * @max_delta_ticks:    maximum delta value in ticks stored for reconfiguration
 91  * @name:               ptr to clock event name
 92  * @rating:             variable to rate clock event devices
 93  * @irq:                IRQ number (only for non CPU local devices)
 94  * @bound_on:           Bound on CPU
 95  * @cpumask:            cpumask to indicate for which CPUs this device works
 96  * @list:               list head for the management code
 97  * @owner:              module reference
 98  */
 99 struct clock_event_device {
100         void                    (*event_handler)(struct clock_event_device *);
101         int                     (*set_next_event)(unsigned long evt, struct clock_event_device *);
102         int                     (*set_next_ktime)(ktime_t expires, struct clock_event_device *);
103         ktime_t                 next_event;
104         u64                     max_delta_ns;
105         u64                     min_delta_ns;
106         u32                     mult;
107         u32                     shift;
108         enum clock_event_state  state_use_accessors;
109         unsigned int            features;
110         unsigned long           retries;
111 
112         int                     (*set_state_periodic)(struct clock_event_device *);
113         int                     (*set_state_oneshot)(struct clock_event_device *);
114         int                     (*set_state_oneshot_stopped)(struct clock_event_device *);
115         int                     (*set_state_shutdown)(struct clock_event_device *);
116         int                     (*tick_resume)(struct clock_event_device *);
117 
118         void                    (*broadcast)(const struct cpumask *mask);
119         void                    (*suspend)(struct clock_event_device *);
120         void                    (*resume)(struct clock_event_device *);
121         unsigned long           min_delta_ticks;
122         unsigned long           max_delta_ticks;
123 
124         const char              *name;
125         int                     rating;
126         int                     irq;
127         int                     bound_on;
128         const struct cpumask    *cpumask;
129         struct list_head        list;
130         struct module           *owner;
131 } ____cacheline_aligned;
132 
133 /* Helpers to verify state of a clockevent device */
134 static inline bool clockevent_state_detached(struct clock_event_device *dev)
135 {
136         return dev->state_use_accessors == CLOCK_EVT_STATE_DETACHED;
137 }
138 
139 static inline bool clockevent_state_shutdown(struct clock_event_device *dev)
140 {
141         return dev->state_use_accessors == CLOCK_EVT_STATE_SHUTDOWN;
142 }
143 
144 static inline bool clockevent_state_periodic(struct clock_event_device *dev)
145 {
146         return dev->state_use_accessors == CLOCK_EVT_STATE_PERIODIC;
147 }
148 
149 static inline bool clockevent_state_oneshot(struct clock_event_device *dev)
150 {
151         return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT;
152 }
153 
154 static inline bool clockevent_state_oneshot_stopped(struct clock_event_device *dev)
155 {
156         return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT_STOPPED;
157 }
158 
159 /*
160  * Calculate a multiplication factor for scaled math, which is used to convert
161  * nanoseconds based values to clock ticks:
162  *
163  * clock_ticks = (nanoseconds * factor) >> shift.
164  *
165  * div_sc is the rearranged equation to calculate a factor from a given clock
166  * ticks / nanoseconds ratio:
167  *
168  * factor = (clock_ticks << shift) / nanoseconds
169  */
170 static inline unsigned long
171 div_sc(unsigned long ticks, unsigned long nsec, int shift)
172 {
173         u64 tmp = ((u64)ticks) << shift;
174 
175         do_div(tmp, nsec);
176 
177         return (unsigned long) tmp;
178 }
179 
180 /* Clock event layer functions */
181 extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt);
182 extern void clockevents_register_device(struct clock_event_device *dev);
183 extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
184 
185 extern void clockevents_config_and_register(struct clock_event_device *dev,
186                                             u32 freq, unsigned long min_delta,
187                                             unsigned long max_delta);
188 
189 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
190 
191 static inline void
192 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 maxsec)
193 {
194         return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, freq, maxsec);
195 }
196 
197 extern void clockevents_suspend(void);
198 extern void clockevents_resume(void);
199 
200 # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
201 #  ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
202 extern void tick_broadcast(const struct cpumask *mask);
203 #  else
204 #   define tick_broadcast       NULL
205 #  endif
206 extern int tick_receive_broadcast(void);
207 # endif
208 
209 # if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
210 extern void tick_setup_hrtimer_broadcast(void);
211 extern int tick_check_broadcast_expired(void);
212 # else
213 static inline int tick_check_broadcast_expired(void) { return 0; }
214 static inline void tick_setup_hrtimer_broadcast(void) { }
215 # endif
216 
217 #else /* !CONFIG_GENERIC_CLOCKEVENTS: */
218 
219 static inline void clockevents_suspend(void) { }
220 static inline void clockevents_resume(void) { }
221 static inline int tick_check_broadcast_expired(void) { return 0; }
222 static inline void tick_setup_hrtimer_broadcast(void) { }
223 
224 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
225 
226 #endif /* _LINUX_CLOCKCHIPS_H */
227 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp