clockchips.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /*
  43. * x86(64) specific misfeatures:
  44. *
  45. * - Clockevent source stops in C3 State and needs broadcast support.
  46. * - Local APIC timer is used as a dummy device.
  47. */
  48. #define CLOCK_EVT_FEAT_C3STOP 0x000004
  49. #define CLOCK_EVT_FEAT_DUMMY 0x000008
  50. /**
  51. * struct clock_event_device - clock event device descriptor
  52. * @name: ptr to clock event name
  53. * @features: features
  54. * @max_delta_ns: maximum delta value in ns
  55. * @min_delta_ns: minimum delta value in ns
  56. * @mult: nanosecond to cycles multiplier
  57. * @shift: nanoseconds to cycles divisor (power of two)
  58. * @rating: variable to rate clock event devices
  59. * @irq: IRQ number (only for non CPU local devices)
  60. * @cpumask: cpumask to indicate for which CPUs this device works
  61. * @set_next_event: set next event function
  62. * @set_mode: set mode function
  63. * @event_handler: Assigned by the framework to be called by the low
  64. * level handler of the event source
  65. * @broadcast: function to broadcast events
  66. * @list: list head for the management code
  67. * @mode: operating mode assigned by the management code
  68. * @next_event: local storage for the next event in oneshot mode
  69. */
  70. struct clock_event_device {
  71. const char *name;
  72. unsigned int features;
  73. unsigned long max_delta_ns;
  74. unsigned long min_delta_ns;
  75. unsigned long mult;
  76. int shift;
  77. int rating;
  78. int irq;
  79. const struct cpumask *cpumask;
  80. int (*set_next_event)(unsigned long evt,
  81. struct clock_event_device *);
  82. void (*set_mode)(enum clock_event_mode mode,
  83. struct clock_event_device *);
  84. void (*event_handler)(struct clock_event_device *);
  85. void (*broadcast)(const struct cpumask *mask);
  86. struct list_head list;
  87. enum clock_event_mode mode;
  88. ktime_t next_event;
  89. };
  90. /*
  91. * Calculate a multiplication factor for scaled math, which is used to convert
  92. * nanoseconds based values to clock ticks:
  93. *
  94. * clock_ticks = (nanoseconds * factor) >> shift.
  95. *
  96. * div_sc is the rearranged equation to calculate a factor from a given clock
  97. * ticks / nanoseconds ratio:
  98. *
  99. * factor = (clock_ticks << shift) / nanoseconds
  100. */
  101. static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
  102. int shift)
  103. {
  104. uint64_t tmp = ((uint64_t)ticks) << shift;
  105. do_div(tmp, nsec);
  106. return (unsigned long) tmp;
  107. }
  108. /* Clock event layer functions */
  109. extern unsigned long clockevent_delta2ns(unsigned long latch,
  110. struct clock_event_device *evt);
  111. extern void clockevents_register_device(struct clock_event_device *dev);
  112. extern void clockevents_exchange_device(struct clock_event_device *old,
  113. struct clock_event_device *new);
  114. extern void clockevents_set_mode(struct clock_event_device *dev,
  115. enum clock_event_mode mode);
  116. extern int clockevents_register_notifier(struct notifier_block *nb);
  117. extern int clockevents_program_event(struct clock_event_device *dev,
  118. ktime_t expires, ktime_t now);
  119. extern void clockevents_handle_noop(struct clock_event_device *dev);
  120. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  121. extern void clockevents_notify(unsigned long reason, void *arg);
  122. #else
  123. # define clockevents_notify(reason, arg) do { } while (0)
  124. #endif
  125. #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
  126. #define clockevents_notify(reason, arg) do { } while (0)
  127. #endif
  128. #endif