clockchips.h 4.2 KB

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