clockchips.h 5.3 KB

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