syncpt.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Tegra host1x Syncpoints
  3. *
  4. * Copyright (c) 2010-2013, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __HOST1X_SYNCPT_H
  19. #define __HOST1X_SYNCPT_H
  20. #include <linux/atomic.h>
  21. #include <linux/kernel.h>
  22. #include <linux/sched.h>
  23. #include "intr.h"
  24. struct host1x;
  25. struct host1x_syncpt {
  26. int id;
  27. atomic_t min_val;
  28. atomic_t max_val;
  29. u32 base_val;
  30. const char *name;
  31. int client_managed;
  32. struct host1x *host;
  33. struct device *dev;
  34. /* interrupt data */
  35. struct host1x_syncpt_intr intr;
  36. };
  37. /* Initialize sync point array */
  38. int host1x_syncpt_init(struct host1x *host);
  39. /* Free sync point array */
  40. void host1x_syncpt_deinit(struct host1x *host);
  41. /*
  42. * Read max. It indicates how many operations there are in queue, either in
  43. * channel or in a software thread.
  44. * */
  45. static inline u32 host1x_syncpt_read_max(struct host1x_syncpt *sp)
  46. {
  47. smp_rmb();
  48. return (u32)atomic_read(&sp->max_val);
  49. }
  50. /*
  51. * Read min, which is a shadow of the current sync point value in hardware.
  52. */
  53. static inline u32 host1x_syncpt_read_min(struct host1x_syncpt *sp)
  54. {
  55. smp_rmb();
  56. return (u32)atomic_read(&sp->min_val);
  57. }
  58. /* Return number of sync point supported. */
  59. int host1x_syncpt_nb_pts(struct host1x *host);
  60. /* Return number of wait bases supported. */
  61. int host1x_syncpt_nb_bases(struct host1x *host);
  62. /* Return number of mlocks supported. */
  63. int host1x_syncpt_nb_mlocks(struct host1x *host);
  64. /*
  65. * Check sync point sanity. If max is larger than min, there have too many
  66. * sync point increments.
  67. *
  68. * Client managed sync point are not tracked.
  69. * */
  70. static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
  71. {
  72. u32 max;
  73. if (sp->client_managed)
  74. return true;
  75. max = host1x_syncpt_read_max(sp);
  76. return (s32)(max - real) >= 0;
  77. }
  78. /* Return true if sync point is client managed. */
  79. static inline int host1x_syncpt_client_managed(struct host1x_syncpt *sp)
  80. {
  81. return sp->client_managed;
  82. }
  83. /*
  84. * Returns true if syncpoint min == max, which means that there are no
  85. * outstanding operations.
  86. */
  87. static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
  88. {
  89. int min, max;
  90. smp_rmb();
  91. min = atomic_read(&sp->min_val);
  92. max = atomic_read(&sp->max_val);
  93. return (min == max);
  94. }
  95. /* Return pointer to struct denoting sync point id. */
  96. struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
  97. /* Request incrementing a sync point. */
  98. void host1x_syncpt_cpu_incr(struct host1x_syncpt *sp);
  99. /* Load current value from hardware to the shadow register. */
  100. u32 host1x_syncpt_load(struct host1x_syncpt *sp);
  101. /* Check if the given syncpoint value has already passed */
  102. bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
  103. /* Save host1x sync point state into shadow registers. */
  104. void host1x_syncpt_save(struct host1x *host);
  105. /* Reset host1x sync point state from shadow registers. */
  106. void host1x_syncpt_restore(struct host1x *host);
  107. /* Read current wait base value into shadow register and return it. */
  108. u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
  109. /* Increment sync point and its max. */
  110. void host1x_syncpt_incr(struct host1x_syncpt *sp);
  111. /* Indicate future operations by incrementing the sync point max. */
  112. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  113. /* Wait until sync point reaches a threshold value, or a timeout. */
  114. int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
  115. long timeout, u32 *value);
  116. /* Check if sync point id is valid. */
  117. static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
  118. {
  119. return sp->id < host1x_syncpt_nb_pts(sp->host);
  120. }
  121. /* Return id of the sync point */
  122. u32 host1x_syncpt_id(struct host1x_syncpt *sp);
  123. /* Allocate a sync point for a device. */
  124. struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
  125. int client_managed);
  126. /* Free a sync point. */
  127. void host1x_syncpt_free(struct host1x_syncpt *sp);
  128. #endif