clockchips.h 4.1 KB

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