kgsl_drawobj.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __KGSL_DRAWOBJ_H
  7. #define __KGSL_DRAWOBJ_H
  8. #include <linux/dma-fence.h>
  9. #include <linux/kref.h>
  10. #define DRAWOBJ(obj) (&obj->base)
  11. #define SYNCOBJ(obj) \
  12. container_of(obj, struct kgsl_drawobj_sync, base)
  13. #define CMDOBJ(obj) \
  14. container_of(obj, struct kgsl_drawobj_cmd, base)
  15. #define CMDOBJ_TYPE BIT(0)
  16. #define MARKEROBJ_TYPE BIT(1)
  17. #define SYNCOBJ_TYPE BIT(2)
  18. #define BINDOBJ_TYPE BIT(3)
  19. #define TIMELINEOBJ_TYPE BIT(4)
  20. /**
  21. * struct kgsl_drawobj - KGSL drawobj descriptor
  22. * @device: KGSL GPU device that the command was created for
  23. * @context: KGSL context that created the command
  24. * @type: Object type
  25. * @timestamp: Timestamp assigned to the command
  26. * @flags: flags
  27. * @refcount: kref structure to maintain the reference count
  28. */
  29. struct kgsl_drawobj {
  30. struct kgsl_device *device;
  31. struct kgsl_context *context;
  32. uint32_t type;
  33. uint32_t timestamp;
  34. unsigned long flags;
  35. struct kref refcount;
  36. /** @destroy: Callbak function to take down the object */
  37. void (*destroy)(struct kgsl_drawobj *drawobj);
  38. /** @destroy_object: Callback function to free the object memory */
  39. void (*destroy_object)(struct kgsl_drawobj *drawobj);
  40. };
  41. /**
  42. * struct kgsl_drawobj_cmd - KGSL command obj, This covers marker
  43. * cmds also since markers are special form of cmds that do not
  44. * need their cmds to be executed.
  45. * @base: Base kgsl_drawobj, this needs to be the first entry
  46. * @priv: Internal flags
  47. * @global_ts: The ringbuffer timestamp corresponding to this
  48. * command obj
  49. * @fault_policy: Internal policy describing how to handle this command in case
  50. * of a fault
  51. * @fault_recovery: recovery actions actually tried for this batch
  52. * be hung
  53. * @refcount: kref structure to maintain the reference count
  54. * @cmdlist: List of IBs to issue
  55. * @memlist: List of all memory used in this command batch
  56. * @marker_timestamp: For markers, the timestamp of the last "real" command that
  57. * was queued
  58. * @profiling_buf_entry: Mem entry containing the profiling buffer
  59. * @profiling_buffer_gpuaddr: GPU virt address of the profile buffer added here
  60. * for easy access
  61. * @profile_index: Index to store the start/stop ticks in the kernel profiling
  62. * buffer
  63. * @submit_ticks: Variable to hold ticks at the time of
  64. * command obj submit.
  65. */
  66. struct kgsl_drawobj_cmd {
  67. struct kgsl_drawobj base;
  68. unsigned long priv;
  69. unsigned int global_ts;
  70. unsigned long fault_policy;
  71. unsigned long fault_recovery;
  72. struct list_head cmdlist;
  73. struct list_head memlist;
  74. unsigned int marker_timestamp;
  75. struct kgsl_mem_entry *profiling_buf_entry;
  76. uint64_t profiling_buffer_gpuaddr;
  77. unsigned int profile_index;
  78. uint64_t submit_ticks;
  79. /* @numibs: Number of ibs in this cmdobj */
  80. u32 numibs;
  81. /* @requeue_cnt: Number of times cmdobj was requeued before submission to dq succeeded */
  82. u32 requeue_cnt;
  83. };
  84. /* This sync object cannot be sent to hardware */
  85. #define KGSL_SYNCOBJ_SW BIT(0)
  86. /* This sync object can be sent to hardware */
  87. #define KGSL_SYNCOBJ_HW BIT(1)
  88. /**
  89. * struct kgsl_drawobj_sync - KGSL sync object
  90. * @base: Base kgsl_drawobj, this needs to be the first entry
  91. * @synclist: Array of context/timestamp tuples to wait for before issuing
  92. * @numsyncs: Number of sync entries in the array
  93. * @pending: Bitmask of sync events that are active
  94. * @timer: a timer used to track possible sync timeouts for this
  95. * sync obj
  96. * @timeout_jiffies: For a sync obj the jiffies at
  97. * which the timer will expire
  98. */
  99. struct kgsl_drawobj_sync {
  100. struct kgsl_drawobj base;
  101. struct kgsl_drawobj_sync_event *synclist;
  102. unsigned int numsyncs;
  103. unsigned long pending;
  104. struct timer_list timer;
  105. unsigned long timeout_jiffies;
  106. /** @flags: sync object internal flags */
  107. u32 flags;
  108. /** @num_hw_fence: number of hw fences in this syncobj */
  109. u32 num_hw_fence;
  110. };
  111. #define KGSL_BINDOBJ_STATE_START 0
  112. #define KGSL_BINDOBJ_STATE_DONE 1
  113. /**
  114. * struct kgsl_drawobj_bind - KGSL virtual buffer object bind operation
  115. * @base: &struct kgsl_drawobj container
  116. * @state: Current state of the draw operation
  117. * @bind: Pointer to the VBO bind operation struct
  118. */
  119. struct kgsl_drawobj_bind {
  120. struct kgsl_drawobj base;
  121. unsigned long state;
  122. struct kgsl_sharedmem_bind_op *bind;
  123. };
  124. static inline struct kgsl_drawobj_bind *BINDOBJ(struct kgsl_drawobj *obj)
  125. {
  126. return container_of(obj, struct kgsl_drawobj_bind, base);
  127. }
  128. /**
  129. * struct kgsl_drawobj_timeline - KGSL timeline signal operation
  130. */
  131. struct kgsl_drawobj_timeline {
  132. /** @base: &struct kgsl_drawobj container */
  133. struct kgsl_drawobj base;
  134. /** @sig_refcount: Refcount to trigger timeline signaling */
  135. struct kref sig_refcount;
  136. /* @timelines: Array of timeline events to signal */
  137. struct kgsl_timeline_event *timelines;
  138. /** @count: Number of items in timelines */
  139. int count;
  140. };
  141. static inline struct kgsl_drawobj_timeline *
  142. TIMELINEOBJ(struct kgsl_drawobj *obj)
  143. {
  144. return container_of(obj, struct kgsl_drawobj_timeline, base);
  145. }
  146. #define KGSL_FENCE_NAME_LEN 74
  147. struct fence_info {
  148. char name[KGSL_FENCE_NAME_LEN];
  149. };
  150. struct event_fence_info {
  151. struct fence_info *fences;
  152. int num_fences;
  153. };
  154. struct event_timeline_info {
  155. u64 seqno;
  156. u32 timeline;
  157. };
  158. /**
  159. * struct kgsl_drawobj_sync_event
  160. * @id: identifer (positiion within the pending bitmap)
  161. * @type: Syncpoint type
  162. * @syncobj: Pointer to the syncobj that owns the sync event
  163. * @context: KGSL context for whose timestamp we want to
  164. * register this event
  165. * @timestamp: Pending timestamp for the event
  166. * @handle: Pointer to a sync fence handle
  167. * @device: Pointer to the KGSL device
  168. */
  169. struct kgsl_drawobj_sync_event {
  170. unsigned int id;
  171. int type;
  172. struct kgsl_drawobj_sync *syncobj;
  173. struct kgsl_context *context;
  174. unsigned int timestamp;
  175. struct kgsl_sync_fence_cb *handle;
  176. struct kgsl_device *device;
  177. /** @priv: Type specific private information */
  178. void *priv;
  179. /**
  180. * @fence: Pointer to a dma fence for KGSL_CMD_SYNCPOINT_TYPE_TIMELINE
  181. * events
  182. */
  183. struct dma_fence *fence;
  184. /** @cb: Callback struct for KGSL_CMD_SYNCPOINT_TYPE_TIMELINE */
  185. struct dma_fence_cb cb;
  186. /** @work : work_struct for KGSL_CMD_SYNCPOINT_TYPE_TIMELINE */
  187. struct work_struct work;
  188. };
  189. #define KGSL_DRAWOBJ_FLAGS \
  190. { KGSL_DRAWOBJ_MARKER, "MARKER" }, \
  191. { KGSL_DRAWOBJ_CTX_SWITCH, "CTX_SWITCH" }, \
  192. { KGSL_DRAWOBJ_SYNC, "SYNC" }, \
  193. { KGSL_DRAWOBJ_END_OF_FRAME, "EOF" }, \
  194. { KGSL_DRAWOBJ_PWR_CONSTRAINT, "PWR_CONSTRAINT" }, \
  195. { KGSL_DRAWOBJ_SUBMIT_IB_LIST, "IB_LIST" }
  196. /**
  197. * enum kgsl_drawobj_cmd_priv - Internal command obj flags
  198. * @CMDOBJ_SKIP - skip the entire command obj
  199. * @CMDOBJ_FORCE_PREAMBLE - Force the preamble on for
  200. * command obj
  201. * @CMDOBJ_WFI - Force wait-for-idle for the submission
  202. * @CMDOBJ_PROFILE - store the start / retire ticks for
  203. * @CMDOBJ_FAULT - Mark the command object as faulted
  204. * the command obj in the profiling buffer
  205. * @CMDOBJ_RECURRING_START: To track recurring command object at GMU
  206. * @CMDOBJ_RECURRING_STOP: To untrack recurring command object from GMU
  207. * @CMDOBJ_MARKER_EXPIRED: Whether this MARKER object is retired or not
  208. */
  209. enum kgsl_drawobj_cmd_priv {
  210. CMDOBJ_SKIP = 0,
  211. CMDOBJ_FORCE_PREAMBLE,
  212. CMDOBJ_WFI,
  213. CMDOBJ_PROFILE,
  214. CMDOBJ_FAULT,
  215. CMDOBJ_RECURRING_START,
  216. CMDOBJ_RECURRING_STOP,
  217. CMDOBJ_MARKER_EXPIRED,
  218. };
  219. struct kgsl_ibdesc;
  220. struct kgsl_cmd_syncpoint;
  221. struct kgsl_drawobj_cmd *kgsl_drawobj_cmd_create(struct kgsl_device *device,
  222. struct kgsl_context *context, unsigned int flags,
  223. unsigned int type);
  224. int kgsl_drawobj_cmd_add_ibdesc(struct kgsl_device *device,
  225. struct kgsl_drawobj_cmd *cmdobj, struct kgsl_ibdesc *ibdesc);
  226. int kgsl_drawobj_cmd_add_ibdesc_list(struct kgsl_device *device,
  227. struct kgsl_drawobj_cmd *cmdobj, void __user *ptr, int count);
  228. int kgsl_drawobj_cmd_add_cmdlist(struct kgsl_device *device,
  229. struct kgsl_drawobj_cmd *cmdobj, void __user *ptr,
  230. unsigned int size, unsigned int count);
  231. int kgsl_drawobj_cmd_add_memlist(struct kgsl_device *device,
  232. struct kgsl_drawobj_cmd *cmdobj, void __user *ptr,
  233. unsigned int size, unsigned int count);
  234. struct kgsl_drawobj_sync *kgsl_drawobj_sync_create(struct kgsl_device *device,
  235. struct kgsl_context *context);
  236. int kgsl_drawobj_sync_add_syncpoints(struct kgsl_device *device,
  237. struct kgsl_drawobj_sync *syncobj, void __user *ptr,
  238. int count);
  239. int kgsl_drawobj_sync_add_synclist(struct kgsl_device *device,
  240. struct kgsl_drawobj_sync *syncobj, void __user *ptr,
  241. unsigned int size, unsigned int count);
  242. int kgsl_drawobj_sync_add_sync(struct kgsl_device *device,
  243. struct kgsl_drawobj_sync *syncobj,
  244. struct kgsl_cmd_syncpoint *sync);
  245. int kgsl_drawobjs_cache_init(void);
  246. void kgsl_drawobjs_cache_exit(void);
  247. void kgsl_dump_syncpoints(struct kgsl_device *device,
  248. struct kgsl_drawobj_sync *syncobj);
  249. void kgsl_drawobj_destroy(struct kgsl_drawobj *drawobj);
  250. void kgsl_drawobj_destroy_object(struct kref *kref);
  251. static inline bool kgsl_drawobj_events_pending(
  252. struct kgsl_drawobj_sync *syncobj)
  253. {
  254. return !bitmap_empty(&syncobj->pending, KGSL_MAX_SYNCPOINTS);
  255. }
  256. static inline bool kgsl_drawobj_event_pending(
  257. struct kgsl_drawobj_sync *syncobj, unsigned int bit)
  258. {
  259. if (bit >= KGSL_MAX_SYNCPOINTS)
  260. return false;
  261. return test_bit(bit, &syncobj->pending);
  262. }
  263. static inline void kgsl_drawobj_put(struct kgsl_drawobj *drawobj)
  264. {
  265. if (drawobj)
  266. kref_put(&drawobj->refcount, kgsl_drawobj_destroy_object);
  267. }
  268. /**
  269. * kgsl_drawobj_create_timestamp_syncobj - Create a syncobj for a timestamp
  270. * @device: A GPU device handle
  271. * @context: Draw context for the syncobj
  272. * @timestamp: Timestamp to sync on
  273. *
  274. * Create a sync object for @timestamp on @context.
  275. * Return: A pointer to the sync object
  276. */
  277. struct kgsl_drawobj_sync *
  278. kgsl_drawobj_create_timestamp_syncobj(struct kgsl_device *device,
  279. struct kgsl_context *context, unsigned int timestamp);
  280. struct kgsl_drawobj_bind *kgsl_drawobj_bind_create(struct kgsl_device *device,
  281. struct kgsl_context *context);
  282. int kgsl_drawobj_add_bind(struct kgsl_device_private *dev_priv,
  283. struct kgsl_drawobj_bind *bindobj,
  284. void __user *src, u64 cmdsize);
  285. /**
  286. * kgsl_drawobj_timeline_create - Create a timeline draw object
  287. * @device: A GPU device handle
  288. * @context: Draw context for the drawobj
  289. *
  290. * Create a timeline draw object on @context.
  291. * Return: A pointer to the draw object
  292. */
  293. struct kgsl_drawobj_timeline *
  294. kgsl_drawobj_timeline_create(struct kgsl_device *device,
  295. struct kgsl_context *context);
  296. /**
  297. * kgsl_drwobj_add_timeline - Add a timeline to a timeline drawobj
  298. * @dev_priv: Pointer to the process private data
  299. * @timelineobj: Pointer to a timeline drawobject
  300. * @src: Ponter to the &struct kgsl_timeline_val from userspace
  301. * @cmdsize: size of the object in @src
  302. *
  303. * Add a timeline to an draw object.
  304. * Return: 0 on success or negative on failure
  305. */
  306. int kgsl_drawobj_add_timeline(struct kgsl_device_private *dev_priv,
  307. struct kgsl_drawobj_timeline *timelineobj,
  308. void __user *src, u64 cmdsize);
  309. #endif /* __KGSL_DRAWOBJ_H */