kgsl_timeline.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __KGSL_TIMELINE_H
  7. #define __KGSL_TIMELINE_H
  8. /**
  9. * struct kgsl_timeline - Container for a timeline object
  10. */
  11. struct kgsl_timeline {
  12. /** @context: dma-fence timeline context */
  13. u64 context;
  14. /** @id: Timeline identifier */
  15. int id;
  16. /** @value: Current value of the timeline */
  17. u64 value;
  18. /** @fence_lock: Lock to protect @fences */
  19. spinlock_t fence_lock;
  20. /** @lock: Lock to use for locking each fence in @fences */
  21. spinlock_t lock;
  22. /** @ref: Reference count for the struct */
  23. struct kref ref;
  24. /** @fences: sorted list of active fences */
  25. struct list_head fences;
  26. /** @events: sorted list of events to be retired */
  27. struct list_head events;
  28. /** @name: Name of the timeline for debugging */
  29. const char name[32];
  30. /** @dev_priv: pointer to the owning device instance */
  31. struct kgsl_device_private *dev_priv;
  32. };
  33. /**
  34. * struct kgsl_timeline_event - Contains data to signal a timeline
  35. */
  36. struct kgsl_timeline_event {
  37. /** @timeline: Pointer to the timeline to signal */
  38. struct kgsl_timeline *timeline;
  39. /** @seqno: seqno of the timeline to signal */
  40. u64 seqno;
  41. /** @context: context this event is waiting for */
  42. struct kgsl_context *context;
  43. /** @timestamp: context timestamp this event is waiting for */
  44. unsigned int timestamp;
  45. /** @node: list node */
  46. struct list_head node;
  47. };
  48. /**
  49. * kgsl_timeline_add_signal - Notify a timeline of an upcoming signal
  50. * @signal: Pointer to a kgsl_timeline_event
  51. *
  52. * Notify the timeline that a GPU AUX command is expected to signal.
  53. */
  54. void kgsl_timeline_add_signal(struct kgsl_timeline_event *signal);
  55. /**
  56. * kgsl_timeline_signal - Signal the timeline
  57. * @timeline: Pointer to a timeline container
  58. * @seqno: Seqeuence number to signal
  59. *
  60. * Advance @timeline to sequence number @seqno and signal any fences that might
  61. * have expired.
  62. */
  63. void kgsl_timeline_signal(struct kgsl_timeline *timeline, u64 seqno);
  64. /**
  65. * kgsl_timeline_destroy - Timeline destroy callback
  66. * @kref: Refcount pointer for the timeline
  67. *
  68. * Reference count callback for the timeline called when the all the object
  69. * references have been released.
  70. */
  71. void kgsl_timeline_destroy(struct kref *kref);
  72. /**
  73. * kgsl_timeline_fence_alloc - Allocate a new fence on a timeline
  74. * @timeline: Pointer to a timeline container
  75. * @seqno: Sequence number for the new fence to wait for
  76. *
  77. * Create and return a new fence on the timeline that will expire when the
  78. * timeline value is greater or equal to @seqno.
  79. * Return: A pointer to the newly created fence
  80. */
  81. struct dma_fence *kgsl_timeline_fence_alloc(struct kgsl_timeline *timeline,
  82. u64 seqno);
  83. /**
  84. * kgsl_timeline_by_id - Look up a timeline by an id
  85. * @device: A KGSL device handle
  86. * @id: Lookup identifier
  87. *
  88. * Find and return the timeline associated with identifer @id.
  89. * Return: A pointer to a timeline or PTR_ERR() encoded error on failure.
  90. */
  91. struct kgsl_timeline *kgsl_timeline_by_id(struct kgsl_device *device,
  92. u32 id);
  93. /**
  94. * kgsl_timeline_get - Get a reference to an existing timeline
  95. * @timeline: Pointer to a timeline container
  96. *
  97. * Get a new reference to the timeline and return the pointer back to the user.
  98. * Return: The pointer to the timeline or PTR_ERR encoded error on failure
  99. */
  100. struct kgsl_timeline *kgsl_timeline_get(struct kgsl_timeline *timeline);
  101. /**
  102. * kgsl_timeline_put - Release a reference to a timeline
  103. * @timeline: Pointer to a timeline container
  104. *
  105. * Release a reference to a timeline and destroy it if there are no other
  106. * references
  107. */
  108. static inline void kgsl_timeline_put(struct kgsl_timeline *timeline)
  109. {
  110. if (!IS_ERR_OR_NULL(timeline))
  111. kref_put(&timeline->ref, kgsl_timeline_destroy);
  112. }
  113. /**
  114. * kgsl_timelines_to_fence_array - Return a dma-fence array of timeline fences
  115. * @device: A KGSL device handle
  116. * @timelines: Userspace pointer to an array of &struct kgsl_timeline_val
  117. * @count: Number of entries in @timelines
  118. * @usize: Size of each entry in @timelines
  119. * @any: True if the fence should expire on any timeline expiring or false if it
  120. * should wait until all timelines have expired
  121. *
  122. * Give a list of &struct kgsl_timeline_val entries, create a dma-fence-array
  123. * containing fences for each timeline/seqno pair. If @any is set the
  124. * dma-fence-array will be set to expire if any of the encapsulated timeline
  125. * fences expire. If @any is false, then the fence will wait for ALL of the
  126. * encapsulated timeline fences to expire.
  127. */
  128. struct dma_fence *kgsl_timelines_to_fence_array(struct kgsl_device *device,
  129. u64 timelines, u32 count, u64 usize, bool any);
  130. #endif