msm_fence.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013-2016 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. */
  6. #ifndef __MSM_FENCE_H__
  7. #define __MSM_FENCE_H__
  8. #include "msm_drv.h"
  9. /**
  10. * struct msm_fence_context - fence context for gpu
  11. *
  12. * Each ringbuffer has a single fence context, with the GPU writing an
  13. * incrementing fence seqno at the end of each submit
  14. */
  15. struct msm_fence_context {
  16. /** @dev: the drm device */
  17. struct drm_device *dev;
  18. /** @name: human readable name for fence timeline */
  19. char name[32];
  20. /** @context: see dma_fence_context_alloc() */
  21. unsigned context;
  22. /** @index: similar to context, but local to msm_fence_context's */
  23. unsigned index;
  24. /**
  25. * @last_fence:
  26. * Last assigned fence, incremented each time a fence is created
  27. * on this fence context. If last_fence == completed_fence,
  28. * there is no remaining pending work
  29. */
  30. uint32_t last_fence;
  31. /**
  32. * @completed_fence:
  33. * The last completed fence, updated from the CPU after interrupt
  34. * from GPU
  35. */
  36. uint32_t completed_fence;
  37. /**
  38. * @fenceptr:
  39. * The address that the GPU directly writes with completed fence
  40. * seqno. This can be ahead of completed_fence. We can peek at
  41. * this to see if a fence has already signaled but the CPU hasn't
  42. * gotten around to handling the irq and updating completed_fence
  43. */
  44. volatile uint32_t *fenceptr;
  45. /**
  46. * @spinlock: fence context spinlock
  47. */
  48. spinlock_t spinlock;
  49. /*
  50. * TODO this doesn't really deal with multiple deadlines, like
  51. * if userspace got multiple frames ahead.. OTOH atomic updates
  52. * don't queue, so maybe that is ok
  53. */
  54. /** @next_deadline: Time of next deadline */
  55. ktime_t next_deadline;
  56. /**
  57. * @next_deadline_fence:
  58. * Fence value for next pending deadline. The deadline timer is
  59. * canceled when this fence is signaled.
  60. */
  61. uint32_t next_deadline_fence;
  62. /**
  63. * @deadline_timer: tracks nearest deadline of a fence timeline and
  64. * expires just before it.
  65. */
  66. struct hrtimer deadline_timer;
  67. /**
  68. * @deadline_work: work to do after deadline_timer expires
  69. */
  70. struct kthread_work deadline_work;
  71. };
  72. struct msm_fence_context * msm_fence_context_alloc(struct drm_device *dev,
  73. volatile uint32_t *fenceptr, const char *name);
  74. void msm_fence_context_free(struct msm_fence_context *fctx);
  75. bool msm_fence_completed(struct msm_fence_context *fctx, uint32_t fence);
  76. void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence);
  77. struct dma_fence * msm_fence_alloc(void);
  78. void msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx);
  79. static inline bool
  80. fence_before(uint32_t a, uint32_t b)
  81. {
  82. return (int32_t)(a - b) < 0;
  83. }
  84. static inline bool
  85. fence_after(uint32_t a, uint32_t b)
  86. {
  87. return (int32_t)(a - b) > 0;
  88. }
  89. #endif