syncpt.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Tegra host1x Syncpoints
  4. *
  5. * Copyright (c) 2010-2013, NVIDIA Corporation.
  6. */
  7. #ifndef __HOST1X_SYNCPT_H
  8. #define __HOST1X_SYNCPT_H
  9. #include <linux/atomic.h>
  10. #include <linux/host1x.h>
  11. #include <linux/kernel.h>
  12. #include <linux/kref.h>
  13. #include <linux/sched.h>
  14. #include "intr.h"
  15. struct host1x;
  16. /* Reserved for replacing an expired wait with a NOP */
  17. #define HOST1X_SYNCPT_RESERVED 0
  18. struct host1x_syncpt_base {
  19. unsigned int id;
  20. bool requested;
  21. };
  22. struct host1x_syncpt {
  23. struct kref ref;
  24. unsigned int id;
  25. atomic_t min_val;
  26. atomic_t max_val;
  27. u32 base_val;
  28. const char *name;
  29. bool client_managed;
  30. struct host1x *host;
  31. struct host1x_syncpt_base *base;
  32. /* interrupt data */
  33. struct host1x_syncpt_intr intr;
  34. /*
  35. * If a submission incrementing this syncpoint fails, lock it so that
  36. * further submission cannot be made until application has handled the
  37. * failure.
  38. */
  39. bool locked;
  40. };
  41. /* Initialize sync point array */
  42. int host1x_syncpt_init(struct host1x *host);
  43. /* Free sync point array */
  44. void host1x_syncpt_deinit(struct host1x *host);
  45. /* Return number of sync point supported. */
  46. unsigned int host1x_syncpt_nb_pts(struct host1x *host);
  47. /* Return number of wait bases supported. */
  48. unsigned int host1x_syncpt_nb_bases(struct host1x *host);
  49. /* Return number of mlocks supported. */
  50. unsigned int host1x_syncpt_nb_mlocks(struct host1x *host);
  51. /*
  52. * Check sync point sanity. If max is larger than min, there have too many
  53. * sync point increments.
  54. *
  55. * Client managed sync point are not tracked.
  56. * */
  57. static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real)
  58. {
  59. u32 max;
  60. if (sp->client_managed)
  61. return true;
  62. max = host1x_syncpt_read_max(sp);
  63. return (s32)(max - real) >= 0;
  64. }
  65. /* Return true if sync point is client managed. */
  66. static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp)
  67. {
  68. return sp->client_managed;
  69. }
  70. /*
  71. * Returns true if syncpoint min == max, which means that there are no
  72. * outstanding operations.
  73. */
  74. static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp)
  75. {
  76. int min, max;
  77. smp_rmb();
  78. min = atomic_read(&sp->min_val);
  79. max = atomic_read(&sp->max_val);
  80. return (min == max);
  81. }
  82. /* Load current value from hardware to the shadow register. */
  83. u32 host1x_syncpt_load(struct host1x_syncpt *sp);
  84. /* Check if the given syncpoint value has already passed */
  85. bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh);
  86. /* Save host1x sync point state into shadow registers. */
  87. void host1x_syncpt_save(struct host1x *host);
  88. /* Reset host1x sync point state from shadow registers. */
  89. void host1x_syncpt_restore(struct host1x *host);
  90. /* Read current wait base value into shadow register and return it. */
  91. u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp);
  92. /* Indicate future operations by incrementing the sync point max. */
  93. u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs);
  94. /* Check if sync point id is valid. */
  95. static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
  96. {
  97. return sp->id < host1x_syncpt_nb_pts(sp->host);
  98. }
  99. static inline void host1x_syncpt_set_locked(struct host1x_syncpt *sp)
  100. {
  101. sp->locked = true;
  102. }
  103. #endif