syncpt.h 4.0 KB

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