qdf_hrtimer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_hrtimer
  20. * This file abstracts high resolution timers running in hardware context.
  21. */
  22. #ifndef _QDF_HRTIMER_H
  23. #define _QDF_HRTIMER_H
  24. #include <qdf_types.h>
  25. #include <i_qdf_hrtimer.h>
  26. #include <qdf_time.h>
  27. /* Context independent hrtimer object */
  28. typedef __qdf_hrtimer_data_t qdf_hrtimer_data_t;
  29. /* Platform independent timer callback function */
  30. typedef enum qdf_hrtimer_restart_status(*qdf_hrtimer_func_t)
  31. (qdf_hrtimer_data_t *timer);
  32. /**
  33. * qdf_hrtimer_start() - Starts hrtimer in given context
  34. * @timer: pointer to the qdf_hrtimer_data_t object
  35. * @interval: interval to forward as qdf_ktime_t object
  36. * @mode: mode of qdf_hrtimer_data_t
  37. *
  38. * Starts hrtimer in given context
  39. *
  40. * Return: void
  41. */
  42. static inline
  43. void qdf_hrtimer_start(qdf_hrtimer_data_t *timer, qdf_ktime_t interval,
  44. enum qdf_hrtimer_mode mode)
  45. {
  46. __qdf_hrtimer_start(timer, interval, mode);
  47. }
  48. /**
  49. * qdf_hrtimer_cancel() - Cancels hrtimer in given context
  50. * @timer: pointer to the qdf_hrtimer_data_t object
  51. *
  52. * Cancels hrtimer in given context
  53. *
  54. * Return: void
  55. */
  56. static inline
  57. void qdf_hrtimer_cancel(qdf_hrtimer_data_t *timer)
  58. {
  59. __qdf_hrtimer_cancel(timer);
  60. }
  61. /**
  62. * qdf_hrtimer_init() - init hrtimer based on context
  63. * @timer: pointer to the qdf_hrtimer_data_t object
  64. * @callback: callback function to be fired
  65. * @qdf_clock_id: clock type
  66. * @qdf_hrtimer_mode: mode of qdf_hrtimer_data_t
  67. * @qdf_context_mode: interrupt context mode
  68. *
  69. * starts hrtimer in a context passed as per qdf_context_mode
  70. *
  71. * Return: void
  72. */
  73. static inline void qdf_hrtimer_init(qdf_hrtimer_data_t *timer,
  74. qdf_hrtimer_func_t callback,
  75. enum qdf_clock_id clock,
  76. enum qdf_hrtimer_mode mode,
  77. enum qdf_context_mode ctx)
  78. {
  79. __qdf_hrtimer_init(timer, callback, clock, mode, ctx);
  80. }
  81. /**
  82. * qdf_hrtimer_kill() - kills hrtimer in given context
  83. * @timer: pointer to the hrtimer object
  84. *
  85. * kills hrtimer in given context
  86. *
  87. * Return: void
  88. */
  89. static inline
  90. void qdf_hrtimer_kill(__qdf_hrtimer_data_t *timer)
  91. {
  92. __qdf_hrtimer_kill(timer);
  93. }
  94. /**
  95. * qdf_hrtimer_get_remaining() - check remaining time in the timer
  96. * @timer: pointer to the qdf_hrtimer_data_t object
  97. *
  98. * check whether the timer is on one of the queues
  99. *
  100. * Return: remaining time as qdf_ktime_t object
  101. */
  102. static inline qdf_ktime_t qdf_hrtimer_get_remaining(qdf_hrtimer_data_t *timer)
  103. {
  104. return __qdf_hrtimer_get_remaining(timer);
  105. }
  106. /**
  107. * qdf_hrtimer_is_queued() - check whether the timer is on one of the queues
  108. * @timer: pointer to the qdf_hrtimer_data_t object
  109. *
  110. * check whether the timer is on one of the queues
  111. *
  112. * Return: false when the timer was not in queue
  113. * true when the timer was in queue
  114. */
  115. static inline bool qdf_hrtimer_is_queued(qdf_hrtimer_data_t *timer)
  116. {
  117. return __qdf_hrtimer_is_queued(timer);
  118. }
  119. /**
  120. * qdf_hrtimer_callback_running() - check if callback is running
  121. * @timer: pointer to the qdf_hrtimer_data_t object
  122. *
  123. * check whether the timer is running the callback function
  124. *
  125. * Return: false when callback is not running
  126. * true when callback is running
  127. */
  128. static inline bool qdf_hrtimer_callback_running(qdf_hrtimer_data_t *timer)
  129. {
  130. return __qdf_hrtimer_callback_running(timer);
  131. }
  132. /**
  133. * qdf_hrtimer_active() - check if timer is active
  134. * @timer: pointer to the qdf_hrtimer_data_t object
  135. *
  136. * Check if timer is active. A timer is active, when it is enqueued into
  137. * the rbtree or the callback function is running.
  138. *
  139. * Return: false if timer is not active
  140. * true if timer is active
  141. */
  142. static inline bool qdf_hrtimer_active(qdf_hrtimer_data_t *timer)
  143. {
  144. return __qdf_hrtimer_active(timer);
  145. }
  146. /**
  147. * qdf_hrtimer_cb_get_time() - get remaining time in callback
  148. * @timer: pointer to the qdf_hrtimer_data_t object
  149. *
  150. * Get remaining time in the hrtimer callback
  151. *
  152. * Return: time remaining as qdf_ktime_t object
  153. */
  154. static inline qdf_ktime_t qdf_hrtimer_cb_get_time(qdf_hrtimer_data_t *timer)
  155. {
  156. return __qdf_hrtimer_cb_get_time(timer);
  157. }
  158. /**
  159. * qdf_hrtimer_forward() - forward the hrtimer
  160. * @timer: pointer to the qdf_hrtimer_data_t object
  161. * @now: current time as qdf_ktime_t object
  162. * @interval: interval to forward as qdf_ktime_t object
  163. *
  164. * Forward the timer expiry so it will expire in the future
  165. *
  166. * Return: the number of overruns
  167. */
  168. static inline uint64_t qdf_hrtimer_forward(qdf_hrtimer_data_t *timer,
  169. qdf_ktime_t now,
  170. qdf_ktime_t interval)
  171. {
  172. return __qdf_hrtimer_forward(timer, now, interval);
  173. }
  174. #endif /* _QDF_HRTIMER_H */