syncpt.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/host1x.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include "intr.h"
  25. struct host1x;
  26. /* Reserved for replacing an expired wait with a NOP */
  27. #define HOST1X_SYNCPT_RESERVED 0
  28. struct host1x_syncpt {
  29. int id;
  30. atomic_t min_val;
  31. atomic_t max_val;
  32. u32 base_val;
  33. const char *name;
  34. bool client_managed;
  35. struct host1x *host;
  36. struct device *dev;
  37. /* interrupt data */
  38. struct host1x_syncpt_intr intr;
  39. };
  40. /* Initialize sync point array */
  41. int host1x_syncpt_init(struct host1x *host);
  42. /* Free sync point array */
  43. void host1x_syncpt_deinit(struct host1x *host);
  44. /* Return number of sync point supported. */
  45. int host1x_syncpt_nb_pts(struct host1x *host);
  46. /* Return number of wait bases supported. */
  47. int host1x_syncpt_nb_bases(struct host1x *host);
  48. /* Return number of mlocks supported. */
  49. int host1x_syncpt_nb_mlocks(struct host1x *host);
  50. /*
  51. * Check sync point sanity. If max is larger than min, there have too many
  52. * sync point increments.
  53. *
  54. * Client managed sync point are not tracked.
  55. * */
  56. static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
  57. {
  58. u32 max;
  59. if (sp->client_managed)
  60. return true;
  61. max = host1x_syncpt_read_max(sp);
  62. return (s32)(max - real) >= 0;
  63. }
  64. /* Return true if sync point is client managed. */
  65. static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
  66. {
  67. return sp->client_managed;
  68. }
  69. /*
  70. * Returns true if syncpoint min == max, which means that there are no
  71. * outstanding operations.
  72. */
  73. static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
  74. {
  75. int min, max;
  76. smp_rmb();
  77. min = atomic_read(&sp->min_val);
  78. max = atomic_read(&sp->max_val);
  79. return (min == max);
  80. }
  81. /* Load current value from hardware to the shadow register. */
  82. u32 host1x_syncpt_load(struct host1x_syncpt *sp);
  83. /* Check if the given syncpoint value has already passed */
  84. bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
  85. /* Save host1x sync point state into shadow registers. */
  86. void host1x_syncpt_save(struct host1x *host);
  87. /* Reset host1x sync point state from shadow registers. */
  88. void host1x_syncpt_restore(struct host1x *host);
  89. /* Read current wait base value into shadow register and return it. */
  90. u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
  91. /* Indicate future operations by incrementing the sync point max. */
  92. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  93. /* Check if sync point id is valid. */
  94. static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
  95. {
  96. return sp->id < host1x_syncpt_nb_pts(sp->host);
  97. }
  98. /* Patch a wait by replacing it with a wait for syncpt 0 value 0 */
  99. int host1x_syncpt_patch_wait(struct host1x_syncpt *sp, void *patch_addr);
  100. #endif