syncpt.h 2.9 KB

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