kgsl_sync.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2014,2018-2019, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __KGSL_SYNC_H
  7. #define __KGSL_SYNC_H
  8. #include <linux/dma-fence.h>
  9. /**
  10. * struct kgsl_sync_timeline - A sync timeline associated with a kgsl context
  11. * @kref: Refcount to keep the struct alive until all its fences are signaled,
  12. and as long as the context exists
  13. * @name: String to describe this timeline
  14. * @fence_context: Used by the fence driver to identify fences belonging to
  15. * this context
  16. * @child_list_head: List head for all fences on this timeline
  17. * @lock: Spinlock to protect this timeline
  18. * @last_timestamp: Last timestamp when signaling fences
  19. * @device: kgsl device
  20. * @context: kgsl context
  21. */
  22. struct kgsl_sync_timeline {
  23. struct kref kref;
  24. char name[32];
  25. u64 fence_context;
  26. struct list_head child_list_head;
  27. spinlock_t lock;
  28. unsigned int last_timestamp;
  29. struct kgsl_device *device;
  30. struct kgsl_context *context;
  31. };
  32. /**
  33. * struct kgsl_sync_fence - A struct containing a fence and other data
  34. * associated with it
  35. * @fence: The fence struct
  36. * @sync_file: Pointer to the sync file
  37. * @parent: Pointer to the kgsl sync timeline this fence is on
  38. * @child_list: List of fences on the same timeline
  39. * @context_id: kgsl context id
  40. * @timestamp: Context timestamp that this fence is associated with
  41. */
  42. struct kgsl_sync_fence {
  43. struct dma_fence fence;
  44. struct sync_file *sync_file;
  45. struct kgsl_sync_timeline *parent;
  46. struct list_head child_list;
  47. u32 context_id;
  48. unsigned int timestamp;
  49. /** @hw_fence_index: Index of hw fence in hw fence table */
  50. u64 hw_fence_index;
  51. /** @hw_fence_handle: Handle to the hw fence client */
  52. void *hw_fence_handle;
  53. };
  54. /**
  55. * struct kgsl_sync_fence_cb - Used for fence callbacks
  56. * fence_cb: Fence callback struct
  57. * fence: Pointer to the fence for which the callback is done
  58. * priv: Private data for the callback
  59. * func: Pointer to the kgsl function to call. This function should return
  60. * false if the sync callback is marked for cancellation in a separate thread.
  61. */
  62. struct kgsl_sync_fence_cb {
  63. struct dma_fence_cb fence_cb;
  64. struct dma_fence *fence;
  65. void *priv;
  66. bool (*func)(void *priv);
  67. };
  68. struct kgsl_device_private;
  69. struct kgsl_drawobj_sync_event;
  70. struct event_fence_info;
  71. struct kgsl_process_private;
  72. struct kgsl_syncsource;
  73. #if defined(CONFIG_SYNC_FILE)
  74. int kgsl_add_fence_event(struct kgsl_device *device,
  75. u32 context_id, u32 timestamp, void __user *data, int len,
  76. struct kgsl_device_private *owner);
  77. int kgsl_sync_timeline_create(struct kgsl_context *context);
  78. void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline);
  79. void kgsl_sync_timeline_put(struct kgsl_sync_timeline *ktimeline);
  80. struct kgsl_sync_fence_cb *kgsl_sync_fence_async_wait(int fd, bool (*func)(void *priv), void *priv);
  81. void kgsl_get_fence_info(struct kgsl_drawobj_sync_event *event);
  82. void kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_cb *kcb);
  83. long kgsl_ioctl_syncsource_create(struct kgsl_device_private *dev_priv,
  84. unsigned int cmd, void *data);
  85. long kgsl_ioctl_syncsource_destroy(struct kgsl_device_private *dev_priv,
  86. unsigned int cmd, void *data);
  87. long kgsl_ioctl_syncsource_create_fence(struct kgsl_device_private *dev_priv,
  88. unsigned int cmd, void *data);
  89. long kgsl_ioctl_syncsource_signal_fence(struct kgsl_device_private *dev_priv,
  90. unsigned int cmd, void *data);
  91. void kgsl_syncsource_put(struct kgsl_syncsource *syncsource);
  92. void kgsl_syncsource_process_release_syncsources(
  93. struct kgsl_process_private *private);
  94. bool is_kgsl_fence(struct dma_fence *f);
  95. void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline,
  96. u32 timestamp);
  97. #else
  98. static inline int kgsl_add_fence_event(struct kgsl_device *device,
  99. u32 context_id, u32 timestamp, void __user *data, int len,
  100. struct kgsl_device_private *owner)
  101. {
  102. return -EINVAL;
  103. }
  104. static inline int kgsl_sync_timeline_create(struct kgsl_context *context)
  105. {
  106. context->ktimeline = NULL;
  107. return 0;
  108. }
  109. static inline void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline)
  110. {
  111. }
  112. static inline void kgsl_sync_timeline_put(struct kgsl_sync_timeline *ktimeline)
  113. {
  114. }
  115. static inline void kgsl_get_fence_info(struct kgsl_drawobj_sync_event *event)
  116. {
  117. }
  118. static inline struct kgsl_sync_fence_cb *kgsl_sync_fence_async_wait(int fd,
  119. bool (*func)(void *priv), void *priv);
  120. {
  121. return NULL;
  122. }
  123. static inline void
  124. kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_cb *kcb)
  125. {
  126. }
  127. static inline long
  128. kgsl_ioctl_syncsource_create(struct kgsl_device_private *dev_priv,
  129. unsigned int cmd, void *data)
  130. {
  131. return -ENOIOCTLCMD;
  132. }
  133. static inline long
  134. kgsl_ioctl_syncsource_destroy(struct kgsl_device_private *dev_priv,
  135. unsigned int cmd, void *data)
  136. {
  137. return -ENOIOCTLCMD;
  138. }
  139. static inline long
  140. kgsl_ioctl_syncsource_create_fence(struct kgsl_device_private *dev_priv,
  141. unsigned int cmd, void *data)
  142. {
  143. return -ENOIOCTLCMD;
  144. }
  145. static inline long
  146. kgsl_ioctl_syncsource_signal_fence(struct kgsl_device_private *dev_priv,
  147. unsigned int cmd, void *data)
  148. {
  149. return -ENOIOCTLCMD;
  150. }
  151. static inline void kgsl_syncsource_put(struct kgsl_syncsource *syncsource)
  152. {
  153. }
  154. static inline void kgsl_syncsource_process_release_syncsources(
  155. struct kgsl_process_private *private)
  156. {
  157. }
  158. bool is_kgsl_fence(struct dma_fence *f)
  159. {
  160. }
  161. void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline,
  162. u32 timestamp)
  163. {
  164. }
  165. #endif /* CONFIG_SYNC_FILE */
  166. #endif /* __KGSL_SYNC_H */