clockchips.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. /* Clock event notification values */
  11. enum clock_event_nofitiers {
  12. CLOCK_EVT_NOTIFY_ADD,
  13. CLOCK_EVT_NOTIFY_BROADCAST_ON,
  14. CLOCK_EVT_NOTIFY_BROADCAST_OFF,
  15. CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
  16. CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
  17. CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
  18. CLOCK_EVT_NOTIFY_SUSPEND,
  19. CLOCK_EVT_NOTIFY_RESUME,
  20. CLOCK_EVT_NOTIFY_CPU_DYING,
  21. CLOCK_EVT_NOTIFY_CPU_DEAD,
  22. };
  23. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
  24. #include <linux/clocksource.h>
  25. #include <linux/cpumask.h>
  26. #include <linux/ktime.h>
  27. #include <linux/notifier.h>
  28. struct clock_event_device;
  29. struct module;
  30. /* Clock event mode commands */
  31. enum clock_event_mode {
  32. CLOCK_EVT_MODE_UNUSED = 0,
  33. CLOCK_EVT_MODE_SHUTDOWN,
  34. CLOCK_EVT_MODE_PERIODIC,
  35. CLOCK_EVT_MODE_ONESHOT,
  36. CLOCK_EVT_MODE_RESUME,
  37. };
  38. /*
  39. * Clock event features
  40. */
  41. #define CLOCK_EVT_FEAT_PERIODIC 0x000001
  42. #define CLOCK_EVT_FEAT_ONESHOT 0x000002
  43. #define CLOCK_EVT_FEAT_KTIME 0x000004
  44. /*
  45. * x86(64) specific misfeatures:
  46. *
  47. * - Clockevent source stops in C3 State and needs broadcast support.
  48. * - Local APIC timer is used as a dummy device.
  49. */
  50. #define CLOCK_EVT_FEAT_C3STOP 0x000008
  51. #define CLOCK_EVT_FEAT_DUMMY 0x000010
  52. /*
  53. * Core shall set the interrupt affinity dynamically in broadcast mode
  54. */
  55. #define CLOCK_EVT_FEAT_DYNIRQ 0x000020
  56. #define CLOCK_EVT_FEAT_PERCPU 0x000040
  57. /*
  58. * Clockevent device is based on a hrtimer for broadcast
  59. */
  60. #define CLOCK_EVT_FEAT_HRTIMER 0x000080
  61. /**
  62. * struct clock_event_device - clock event device descriptor
  63. * @event_handler: Assigned by the framework to be called by the low
  64. * level handler of the event source
  65. * @set_next_event: set next event function using a clocksource delta
  66. * @set_next_ktime: set next event function using a direct ktime value
  67. * @next_event: local storage for the next event in oneshot mode
  68. * @max_delta_ns: maximum delta value in ns
  69. * @min_delta_ns: minimum delta value in ns
  70. * @mult: nanosecond to cycles multiplier
  71. * @shift: nanoseconds to cycles divisor (power of two)
  72. * @mode: operating mode assigned by the management code
  73. * @features: features
  74. * @retries: number of forced programming retries
  75. * @set_mode: set mode function
  76. * @broadcast: function to broadcast events
  77. * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
  78. * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
  79. * @name: ptr to clock event name
  80. * @rating: variable to rate clock event devices
  81. * @irq: IRQ number (only for non CPU local devices)
  82. * @bound_on: Bound on CPU
  83. * @cpumask: cpumask to indicate for which CPUs this device works
  84. * @list: list head for the management code
  85. * @owner: module reference
  86. */
  87. struct clock_event_device {
  88. void (*event_handler)(struct clock_event_device *);
  89. int (*set_next_event)(unsigned long evt,
  90. struct clock_event_device *);
  91. int (*set_next_ktime)(ktime_t expires,
  92. struct clock_event_device *);
  93. ktime_t next_event;
  94. u64 max_delta_ns;
  95. u64 min_delta_ns;
  96. u32 mult;
  97. u32 shift;
  98. enum clock_event_mode mode;
  99. unsigned int features;
  100. unsigned long retries;
  101. void (*broadcast)(const struct cpumask *mask);
  102. void (*set_mode)(enum clock_event_mode mode,
  103. struct clock_event_device *);
  104. void (*suspend)(struct clock_event_device *);
  105. void (*resume)(struct clock_event_device *);
  106. unsigned long min_delta_ticks;
  107. unsigned long max_delta_ticks;
  108. const char *name;
  109. int rating;
  110. int irq;
  111. int bound_on;
  112. const struct cpumask *cpumask;
  113. struct list_head list;
  114. struct module *owner;
  115. } ____cacheline_aligned;
  116. /*
  117. * Calculate a multiplication factor for scaled math, which is used to convert
  118. * nanoseconds based values to clock ticks:
  119. *
  120. * clock_ticks = (nanoseconds * factor) >> shift.
  121. *
  122. * div_sc is the rearranged equation to calculate a factor from a given clock
  123. * ticks / nanoseconds ratio:
  124. *
  125. * factor = (clock_ticks << shift) / nanoseconds
  126. */
  127. static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
  128. int shift)
  129. {
  130. uint64_t tmp = ((uint64_t)ticks) << shift;
  131. do_div(tmp, nsec);
  132. return (unsigned long) tmp;
  133. }
  134. /* Clock event layer functions */
  135. extern u64 clockevent_delta2ns(unsigned long latch,
  136. struct clock_event_device *evt);
  137. extern void clockevents_register_device(struct clock_event_device *dev);
  138. extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
  139. extern void clockevents_config(struct clock_event_device *dev, u32 freq);
  140. extern void clockevents_config_and_register(struct clock_event_device *dev,
  141. u32 freq, unsigned long min_delta,
  142. unsigned long max_delta);
  143. extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
  144. extern void clockevents_exchange_device(struct clock_event_device *old,
  145. struct clock_event_device *new);
  146. extern void clockevents_set_mode(struct clock_event_device *dev,
  147. enum clock_event_mode mode);
  148. extern int clockevents_program_event(struct clock_event_device *dev,
  149. ktime_t expires, bool force);
  150. extern void clockevents_handle_noop(struct clock_event_device *dev);
  151. static inline void
  152. clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
  153. {
  154. return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
  155. freq, minsec);
  156. }
  157. extern void clockevents_suspend(void);
  158. extern void clockevents_resume(void);
  159. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  160. #ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
  161. extern void tick_broadcast(const struct cpumask *mask);
  162. #else
  163. #define tick_broadcast NULL
  164. #endif
  165. extern int tick_receive_broadcast(void);
  166. #endif
  167. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
  168. extern void tick_setup_hrtimer_broadcast(void);
  169. extern int tick_check_broadcast_expired(void);
  170. #else
  171. static inline int tick_check_broadcast_expired(void) { return 0; }
  172. static inline void tick_setup_hrtimer_broadcast(void) {};
  173. #endif
  174. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  175. extern int clockevents_notify(unsigned long reason, void *arg);
  176. #else
  177. static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
  178. #endif
  179. #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
  180. static inline void clockevents_suspend(void) {}
  181. static inline void clockevents_resume(void) {}
  182. static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
  183. static inline int tick_check_broadcast_expired(void) { return 0; }
  184. static inline void tick_setup_hrtimer_broadcast(void) {};
  185. #endif
  186. #endif