adreno_drawctxt.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2002,2007-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __ADRENO_DRAWCTXT_H
  7. #define __ADRENO_DRAWCTXT_H
  8. #include <linux/types.h>
  9. #include "kgsl_device.h"
  10. struct adreno_context_type {
  11. unsigned int type;
  12. const char *str;
  13. };
  14. #define ADRENO_CONTEXT_DRAWQUEUE_SIZE 128
  15. #define SUBMIT_RETIRE_TICKS_SIZE 7
  16. struct kgsl_device;
  17. struct adreno_device;
  18. struct kgsl_device_private;
  19. /**
  20. * struct adreno_context - Adreno GPU draw context
  21. * @timestamp: Last issued context-specific timestamp
  22. * @internal_timestamp: Global timestamp of the last issued command
  23. * NOTE: guarded by device->mutex, not drawctxt->mutex!
  24. * @type: Context type (GL, CL, RS)
  25. * @mutex: Mutex to protect the drawqueue
  26. * @drawqueue: Queue of drawobjs waiting to be dispatched for this
  27. * context
  28. * @drawqueue_head: Head of the drawqueue queue
  29. * @drawqueue_tail: Tail of the drawqueue queue
  30. * @wq: Workqueue structure for contexts to sleep pending room in the queue
  31. * @waiting: Workqueue structure for contexts waiting for a timestamp or event
  32. * @timeout: Workqueue structure for contexts waiting to invalidate
  33. * @queued: Number of commands queued in the drawqueue
  34. * @fault_policy: GFT fault policy set in _skip_cmd();
  35. * @debug_root: debugfs entry for this context.
  36. * @queued_timestamp: The last timestamp that was queued on this context
  37. * @rb: The ringbuffer in which this context submits commands.
  38. * @submitted_timestamp: The last timestamp that was submitted for this context
  39. * @submit_retire_ticks: Array to hold command obj execution times from submit
  40. * to retire
  41. * @ticks_index: The index into submit_retire_ticks[] where the new delta will
  42. * be written.
  43. * @active_node: Linkage for nodes in active_list
  44. * @active_time: Time when this context last seen
  45. */
  46. struct adreno_context {
  47. struct kgsl_context base;
  48. unsigned int timestamp;
  49. unsigned int internal_timestamp;
  50. unsigned int type;
  51. spinlock_t lock;
  52. /* Dispatcher */
  53. struct kgsl_drawobj *drawqueue[ADRENO_CONTEXT_DRAWQUEUE_SIZE];
  54. unsigned int drawqueue_head;
  55. unsigned int drawqueue_tail;
  56. wait_queue_head_t wq;
  57. wait_queue_head_t waiting;
  58. wait_queue_head_t timeout;
  59. int queued;
  60. unsigned int fault_policy;
  61. struct dentry *debug_root;
  62. unsigned int queued_timestamp;
  63. struct adreno_ringbuffer *rb;
  64. unsigned int submitted_timestamp;
  65. uint64_t submit_retire_ticks[SUBMIT_RETIRE_TICKS_SIZE];
  66. int ticks_index;
  67. struct list_head active_node;
  68. unsigned long active_time;
  69. /** @gmu_context_queue: Queue to dispatch submissions to GMU */
  70. struct kgsl_memdesc gmu_context_queue;
  71. /** @gmu_hw_fence_queue: Queue for GMU to store hardware fences for this context */
  72. struct kgsl_memdesc gmu_hw_fence_queue;
  73. /** @hw_fence_list: List of hardware fences(sorted by timestamp) not yet submitted to GMU */
  74. struct list_head hw_fence_list;
  75. /** @hw_fence_inflight_list: List of hardware fences submitted to GMU */
  76. struct list_head hw_fence_inflight_list;
  77. /** @hw_fence_count: Number of hardware fences not yet sent to Tx Queue */
  78. u32 hw_fence_count;
  79. /** @syncobj_timestamp: Timestamp to check whether GMU has consumed a syncobj */
  80. u32 syncobj_timestamp;
  81. };
  82. /* Flag definitions for flag field in adreno_context */
  83. /**
  84. * enum adreno_context_priv - Private flags for an adreno draw context
  85. * @ADRENO_CONTEXT_FAULT - set if the context has faulted (and recovered)
  86. * @ADRENO_CONTEXT_GPU_HANG - Context has caused a GPU hang
  87. * @ADRENO_CONTEXT_GPU_HANG_FT - Context has caused a GPU hang
  88. * and fault tolerance was successful
  89. * @ADRENO_CONTEXT_SKIP_EOF - Context skip IBs until the next end of frame
  90. * marker.
  91. * @ADRENO_CONTEXT_FORCE_PREAMBLE - Force the preamble for the next submission.
  92. * @ADRENO_CONTEXT_SKIP_CMD - Context's drawobj's skipped during
  93. fault tolerance.
  94. * @ADRENO_CONTEXT_FENCE_LOG - Dump fences on this context.
  95. */
  96. enum adreno_context_priv {
  97. ADRENO_CONTEXT_FAULT = KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC,
  98. ADRENO_CONTEXT_GPU_HANG,
  99. ADRENO_CONTEXT_GPU_HANG_FT,
  100. ADRENO_CONTEXT_SKIP_EOF,
  101. ADRENO_CONTEXT_FORCE_PREAMBLE,
  102. ADRENO_CONTEXT_SKIP_CMD,
  103. ADRENO_CONTEXT_FENCE_LOG,
  104. };
  105. struct kgsl_context *adreno_drawctxt_create(
  106. struct kgsl_device_private *dev_priv,
  107. uint32_t *flags);
  108. void adreno_drawctxt_detach(struct kgsl_context *context);
  109. void adreno_drawctxt_destroy(struct kgsl_context *context);
  110. struct adreno_ringbuffer;
  111. struct adreno_dispatcher_drawqueue;
  112. int adreno_drawctxt_wait(struct adreno_device *adreno_dev,
  113. struct kgsl_context *context,
  114. uint32_t timestamp, unsigned int timeout);
  115. void adreno_drawctxt_invalidate(struct kgsl_device *device,
  116. struct kgsl_context *context);
  117. void adreno_drawctxt_dump(struct kgsl_device *device,
  118. struct kgsl_context *context);
  119. /**
  120. * adreno_drawctxt_detached - Helper function to check if a context is detached
  121. * @drawctxt: Adreno drawctxt to check
  122. *
  123. * Return: True if the context isn't null and it has been detached
  124. */
  125. static inline bool adreno_drawctxt_detached(struct adreno_context *drawctxt)
  126. {
  127. return (drawctxt && kgsl_context_detached(&drawctxt->base));
  128. }
  129. /**
  130. * adreno_put_drawctxt_on_timestamp - Put the refcount on the drawctxt when the
  131. * timestamp expires
  132. * @device: A KGSL device handle
  133. * @drawctxt: The draw context to put away
  134. * @rb: The ringbuffer that will trigger the timestamp event
  135. * @timestamp: The timestamp on @rb that will trigger the event
  136. *
  137. * Add an event to put the refcount on @drawctxt after @timestamp expires on
  138. * @rb. This is used by the context switch to safely put away the context after
  139. * a new context is switched in.
  140. */
  141. void adreno_put_drawctxt_on_timestamp(struct kgsl_device *device,
  142. struct adreno_context *drawctxt,
  143. struct adreno_ringbuffer *rb, u32 timestamp);
  144. /**
  145. * adreno_drawctxt_get_pagetable - Helper function to return the pagetable for a
  146. * context
  147. * @drawctxt: The adreno draw context to query
  148. *
  149. * Return: A pointer to the pagetable for the process that owns the context or
  150. * NULL
  151. */
  152. static inline struct kgsl_pagetable *
  153. adreno_drawctxt_get_pagetable(struct adreno_context *drawctxt)
  154. {
  155. if (drawctxt)
  156. return drawctxt->base.proc_priv->pagetable;
  157. return NULL;
  158. }
  159. /**
  160. * adreno_drawctxt_set_guilty - Mark a context as guilty and invalidate it
  161. * @device: Pointer to a GPU device handle
  162. * @context: Pointer to the context to invalidate
  163. *
  164. * Mark the specified context as guilty and invalidate it
  165. */
  166. void adreno_drawctxt_set_guilty(struct kgsl_device *device,
  167. struct kgsl_context *context);
  168. /**
  169. * adreno_track_context - Add a context to active list and keep track of active contexts
  170. * @adreno_dev: Pointer to adreno device
  171. * @drawqueue: Pointer to the dispatch queue to which context send commands
  172. * @drawctxt: Draw context which is to be tracked
  173. *
  174. * Add the given draw context to the active list and update number of contexts which
  175. * are active overall as well as which are active on the dispatch queue to which
  176. * the given context sends commands.
  177. */
  178. void adreno_track_context(struct adreno_device *adreno_dev,
  179. struct adreno_dispatcher_drawqueue *drawqueue,
  180. struct adreno_context *drawctxt);
  181. #endif /* __ADRENO_DRAWCTXT_H */