msm_fence.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013-2016 Red Hat
  4. * Author: Rob Clark <[email protected]>
  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. struct drm_device *dev;
  17. /** name: human readable name for fence timeline */
  18. char name[32];
  19. /** context: see dma_fence_context_alloc() */
  20. unsigned context;
  21. /** index: similar to context, but local to msm_fence_context's */
  22. unsigned index;
  23. /**
  24. * last_fence:
  25. *
  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. *
  34. * The last completed fence, updated from the CPU after interrupt
  35. * from GPU
  36. */
  37. uint32_t completed_fence;
  38. /**
  39. * fenceptr:
  40. *
  41. * The address that the GPU directly writes with completed fence
  42. * seqno. This can be ahead of completed_fence. We can peek at
  43. * this to see if a fence has already signaled but the CPU hasn't
  44. * gotten around to handling the irq and updating completed_fence
  45. */
  46. volatile uint32_t *fenceptr;
  47. spinlock_t spinlock;
  48. };
  49. struct msm_fence_context * msm_fence_context_alloc(struct drm_device *dev,
  50. volatile uint32_t *fenceptr, const char *name);
  51. void msm_fence_context_free(struct msm_fence_context *fctx);
  52. bool msm_fence_completed(struct msm_fence_context *fctx, uint32_t fence);
  53. void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence);
  54. struct dma_fence * msm_fence_alloc(struct msm_fence_context *fctx);
  55. static inline bool
  56. fence_before(uint32_t a, uint32_t b)
  57. {
  58. return (int32_t)(a - b) < 0;
  59. }
  60. static inline bool
  61. fence_after(uint32_t a, uint32_t b)
  62. {
  63. return (int32_t)(a - b) > 0;
  64. }
  65. #endif