clockchips.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /**
  57. * struct clock_event_device - clock event device descriptor
  58. * @event_handler: Assigned by the framework to be called by the low
  59. * level handler of the event source
  60. * @set_next_event: set next event function using a clocksource delta
  61. * @set_next_ktime: set next event function using a direct ktime value
  62. * @next_event: local storage for the next event in oneshot mode
  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)
  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. * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
  73. * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
  74. * @name: ptr to clock event name
  75. * @rating: variable to rate clock event devices
  76. * @irq: IRQ number (only for non CPU local devices)
  77. * @cpumask: cpumask to indicate for which CPUs this device works
  78. * @list: list head for the management code
  79. * @owner: module reference
  80. */
  81. struct clock_event_device {
  82. void (*event_handler)(struct clock_event_device *);
  83. int (*set_next_event)(unsigned long evt,
  84. struct clock_event_device *);
  85. int (*set_next_ktime)(ktime_t expires,
  86. struct clock_event_device *);
  87. ktime_t next_event;
  88. u64 max_delta_ns;
  89. u64 min_delta_ns;
  90. u32 mult;
  91. u32 shift;
  92. enum clock_event_mode mode;
  93. unsigned int features;
  94. unsigned long retries;
  95. void (*broadcast)(const struct cpumask *mask);
  96. void (*set_mode)(enum clock_event_mode mode,
  97. struct clock_event_device *);
  98. void (*suspend)(struct clock_event_device *);
  99. void (*resume)(struct clock_event_device *);
  100. unsigned long min_delta_ticks;
  101. unsigned long max_delta_ticks;
  102. const char *name;
  103. int rating;
  104. int irq;
  105. const struct cpumask *cpumask;
  106. struct list_head list;
  107. struct module *owner;
  108. } ____cacheline_aligned;
  109. /*
  110. * Calculate a multiplication factor for scaled math, which is used to convert
  111. * nanoseconds based values to clock ticks:
  112. *
  113. * clock_ticks = (nanoseconds * factor) >> shift.
  114. *
  115. * div_sc is the rearranged equation to calculate a factor from a given clock
  116. * ticks / nanoseconds ratio:
  117. *
  118. * factor = (clock_ticks << shift) / nanoseconds
  119. */
  120. static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
  121. int shift)
  122. {
  123. uint64_t tmp = ((uint64_t)ticks) << shift;
  124. do_div(tmp, nsec);
  125. return (unsigned long) tmp;
  126. }
  127. /* Clock event layer functions */
  128. extern u64 clockevent_delta2ns(unsigned long latch,
  129. struct clock_event_device *evt);
  130. extern void clockevents_register_device(struct clock_event_device *dev);
  131. extern void clockevents_config(struct clock_event_device *dev, u32 freq);
  132. extern void clockevents_config_and_register(struct clock_event_device *dev,
  133. u32 freq, unsigned long min_delta,
  134. unsigned long max_delta);
  135. extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
  136. extern void clockevents_exchange_device(struct clock_event_device *old,
  137. struct clock_event_device *new);
  138. extern void clockevents_set_mode(struct clock_event_device *dev,
  139. enum clock_event_mode mode);
  140. extern int clockevents_program_event(struct clock_event_device *dev,
  141. ktime_t expires, bool force);
  142. extern void clockevents_handle_noop(struct clock_event_device *dev);
  143. static inline void
  144. clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
  145. {
  146. return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
  147. freq, minsec);
  148. }
  149. extern void clockevents_suspend(void);
  150. extern void clockevents_resume(void);
  151. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  152. #ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
  153. extern void tick_broadcast(const struct cpumask *mask);
  154. #else
  155. #define tick_broadcast NULL
  156. #endif
  157. extern int tick_receive_broadcast(void);
  158. #endif
  159. #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
  160. extern int tick_check_broadcast_expired(void);
  161. #else
  162. static inline int tick_check_broadcast_expired(void) { return 0; }
  163. #endif
  164. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  165. extern void clockevents_notify(unsigned long reason, void *arg);
  166. #else
  167. static inline void clockevents_notify(unsigned long reason, void *arg) {}
  168. #endif
  169. #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
  170. static inline void clockevents_suspend(void) {}
  171. static inline void clockevents_resume(void) {}
  172. static inline void clockevents_notify(unsigned long reason, void *arg) {}
  173. static inline int tick_check_broadcast_expired(void) { return 0; }
  174. #endif
  175. #endif