syncpt.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /* Reserved for replacing an expired wait with a NOP */
  26. #define HOST1X_SYNCPT_RESERVED 0
  27. struct host1x_syncpt {
  28. int id;
  29. atomic_t min_val;
  30. atomic_t max_val;
  31. u32 base_val;
  32. const char *name;
  33. int client_managed;
  34. struct host1x *host;
  35. struct device *dev;
  36. /* interrupt data */
  37. struct host1x_syncpt_intr intr;
  38. };
  39. /* Initialize sync point array */
  40. int host1x_syncpt_init(struct host1x *host);
  41. /* Free sync point array */
  42. void host1x_syncpt_deinit(struct host1x *host);
  43. /*
  44. * Read max. It indicates how many operations there are in queue, either in
  45. * channel or in a software thread.
  46. * */
  47. static inline u32 host1x_syncpt_read_max(struct host1x_syncpt *sp)
  48. {
  49. smp_rmb();
  50. return (u32)atomic_read(&sp->max_val);
  51. }
  52. /*
  53. * Read min, which is a shadow of the current sync point value in hardware.
  54. */
  55. static inline u32 host1x_syncpt_read_min(struct host1x_syncpt *sp)
  56. {
  57. smp_rmb();
  58. return (u32)atomic_read(&sp->min_val);
  59. }
  60. /* Return number of sync point supported. */
  61. int host1x_syncpt_nb_pts(struct host1x *host);
  62. /* Return number of wait bases supported. */
  63. int host1x_syncpt_nb_bases(struct host1x *host);
  64. /* Return number of mlocks supported. */
  65. int host1x_syncpt_nb_mlocks(struct host1x *host);
  66. /*
  67. * Check sync point sanity. If max is larger than min, there have too many
  68. * sync point increments.
  69. *
  70. * Client managed sync point are not tracked.
  71. * */
  72. static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
  73. {
  74. u32 max;
  75. if (sp->client_managed)
  76. return true;
  77. max = host1x_syncpt_read_max(sp);
  78. return (s32)(max - real) >= 0;
  79. }
  80. /* Return true if sync point is client managed. */
  81. static inline int host1x_syncpt_client_managed(struct host1x_syncpt *sp)
  82. {
  83. return sp->client_managed;
  84. }
  85. /*
  86. * Returns true if syncpoint min == max, which means that there are no
  87. * outstanding operations.
  88. */
  89. static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
  90. {
  91. int min, max;
  92. smp_rmb();
  93. min = atomic_read(&sp->min_val);
  94. max = atomic_read(&sp->max_val);
  95. return (min == max);
  96. }
  97. /* Return pointer to struct denoting sync point id. */
  98. struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
  99. /* Request incrementing a sync point. */
  100. void host1x_syncpt_cpu_incr(struct host1x_syncpt *sp);
  101. /* Load current value from hardware to the shadow register. */
  102. u32 host1x_syncpt_load(struct host1x_syncpt *sp);
  103. /* Check if the given syncpoint value has already passed */
  104. bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
  105. /* Save host1x sync point state into shadow registers. */
  106. void host1x_syncpt_save(struct host1x *host);
  107. /* Reset host1x sync point state from shadow registers. */
  108. void host1x_syncpt_restore(struct host1x *host);
  109. /* Read current wait base value into shadow register and return it. */
  110. u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
  111. /* Increment sync point and its max. */
  112. void host1x_syncpt_incr(struct host1x_syncpt *sp);
  113. /* Indicate future operations by incrementing the sync point max. */
  114. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  115. /* Wait until sync point reaches a threshold value, or a timeout. */
  116. int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh,
  117. long timeout, u32 *value);
  118. /* Check if sync point id is valid. */
  119. static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
  120. {
  121. return sp->id < host1x_syncpt_nb_pts(sp->host);
  122. }
  123. /* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
  124. int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr);
  125. /* Return id of the sync point */
  126. u32 host1x_syncpt_id(struct host1x_syncpt *sp);
  127. /* Allocate a sync point for a device. */
  128. struct host1x_syncpt *host1x_syncpt_request(struct device *dev,
  129. int client_managed);
  130. /* Free a sync point. */
  131. void host1x_syncpt_free(struct host1x_syncpt *sp);
  132. #endif