syncpt.h 3.5 KB

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