adreno_gen7_hwsched_hfi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _ADRENO_GEN7_HWSCHED_HFI_H_
  7. #define _ADRENO_GEN7_HWSCHED_HFI_H_
  8. /* Maximum number of IBs in a submission */
  9. #define HWSCHED_MAX_NUMIBS \
  10. ((HFI_MAX_MSG_SIZE - offsetof(struct hfi_issue_cmd_cmd, ibs)) \
  11. / sizeof(struct hfi_issue_ib))
  12. /*
  13. * This is used to put userspace threads to sleep when hardware fence unack count reaches a
  14. * threshold. This bit is cleared in two scenarios:
  15. * 1. If the hardware fence unack count drops to a desired threshold.
  16. * 2. If there is a GMU/GPU fault. Because we don't want the threads to keep sleeping through fault
  17. * recovery, which can easily take 100s of milliseconds to complete.
  18. */
  19. #define GEN7_HWSCHED_HW_FENCE_SLEEP_BIT 0x0
  20. /*
  21. * This is used to avoid creating any more hardware fences until the hardware fence unack count
  22. * drops to a desired threshold. This bit is required in cases where GEN7_HWSCHED_HW_FENCE_SLEEP_BIT
  23. * will be cleared, but we still want to avoid creating any more hardware fences. For example, if
  24. * hardware fence unack count reaches a maximum threshold, both GEN7_HWSCHED_HW_FENCE_SLEEP_BIT and
  25. * GEN7_HWSCHED_HW_FENCE_MAX_BIT will be set. Say, a GMU/GPU fault happens and
  26. * GEN7_HWSCHED_HW_FENCE_SLEEP_BIT will be cleared to wake up any sleeping threads. But,
  27. * GEN7_HWSCHED_HW_FENCE_MAX_BIT will remain set to avoid creating any new hardware fences until
  28. * recovery is complete and deferred drawctxt (if any) is handled.
  29. */
  30. #define GEN7_HWSCHED_HW_FENCE_MAX_BIT 0x1
  31. /*
  32. * This is used to avoid creating any more hardware fences until concurrent reset/recovery completes
  33. */
  34. #define GEN7_HWSCHED_HW_FENCE_ABORT_BIT 0x2
  35. struct gen7_hwsched_hfi {
  36. struct hfi_mem_alloc_entry mem_alloc_table[32];
  37. u32 mem_alloc_entries;
  38. /** @irq_mask: Store the hfi interrupt mask */
  39. u32 irq_mask;
  40. /** @msglock: To protect the list of un-ACKed hfi packets */
  41. rwlock_t msglock;
  42. /** @msglist: List of un-ACKed hfi packets */
  43. struct list_head msglist;
  44. /** @f2h_task: Task for processing gmu fw to host packets */
  45. struct task_struct *f2h_task;
  46. /** @f2h_wq: Waitqueue for the f2h_task */
  47. wait_queue_head_t f2h_wq;
  48. /** @big_ib: GMU buffer to hold big IBs */
  49. struct kgsl_memdesc *big_ib;
  50. /** @big_ib_recurring: GMU buffer to hold big recurring IBs */
  51. struct kgsl_memdesc *big_ib_recurring;
  52. /** @perfctr_scratch: Buffer to hold perfcounter PM4 commands */
  53. struct kgsl_memdesc *perfctr_scratch;
  54. /** @msg_mutex: Mutex for accessing the msgq */
  55. struct mutex msgq_mutex;
  56. struct {
  57. /** @lock: Spinlock for managing hardware fences */
  58. spinlock_t lock;
  59. /**
  60. * @unack_count: Number of hardware fences sent to GMU but haven't yet been ack'd
  61. * by GMU
  62. */
  63. u32 unack_count;
  64. /**
  65. * @unack_wq: Waitqueue to wait on till number of unacked hardware fences drops to
  66. * a desired threshold
  67. */
  68. wait_queue_head_t unack_wq;
  69. /**
  70. * @defer_drawctxt: Drawctxt to send hardware fences from as soon as unacked
  71. * hardware fences drops to a desired threshold
  72. */
  73. struct adreno_context *defer_drawctxt;
  74. /**
  75. * @defer_ts: The timestamp of the hardware fence which got deferred
  76. */
  77. u32 defer_ts;
  78. /**
  79. * @flags: Flags to control the creation of new hardware fences
  80. */
  81. unsigned long flags;
  82. /** @seqnum: Sequence number for hardware fence packet header */
  83. atomic_t seqnum;
  84. } hw_fence;
  85. /**
  86. * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop
  87. * to a desired threshold in given amount of time
  88. */
  89. struct timer_list hw_fence_timer;
  90. /**
  91. * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires
  92. */
  93. struct work_struct hw_fence_ws;
  94. /** @detached_hw_fences_list: List of hardware fences belonging to detached contexts */
  95. struct list_head detached_hw_fence_list;
  96. /** @defer_hw_fence_work: The work structure to send deferred hardware fences to GMU */
  97. struct kthread_work defer_hw_fence_work;
  98. };
  99. struct kgsl_drawobj_cmd;
  100. /**
  101. * gen7_hwsched_hfi_probe - Probe hwsched hfi resources
  102. * @adreno_dev: Pointer to adreno device structure
  103. *
  104. * Return: 0 on success and negative error on failure.
  105. */
  106. int gen7_hwsched_hfi_probe(struct adreno_device *adreno_dev);
  107. /**
  108. * gen7_hwsched_hfi_remove - Release hwsched hfi resources
  109. * @adreno_dev: Pointer to adreno device structure
  110. */
  111. void gen7_hwsched_hfi_remove(struct adreno_device *adreno_dev);
  112. /**
  113. * gen7_hwsched_hfi_init - Initialize hfi resources
  114. * @adreno_dev: Pointer to adreno device structure
  115. *
  116. * This function is used to initialize hfi resources
  117. * once before the very first gmu boot
  118. *
  119. * Return: 0 on success and negative error on failure.
  120. */
  121. int gen7_hwsched_hfi_init(struct adreno_device *adreno_dev);
  122. /**
  123. * gen7_hwsched_hfi_start - Start hfi resources
  124. * @adreno_dev: Pointer to adreno device structure
  125. *
  126. * Send the various hfi packets before booting the gpu
  127. *
  128. * Return: 0 on success and negative error on failure.
  129. */
  130. int gen7_hwsched_hfi_start(struct adreno_device *adreno_dev);
  131. /**
  132. * gen7_hwsched_hfi_stop - Stop the hfi resources
  133. * @adreno_dev: Pointer to the adreno device
  134. *
  135. * This function does the hfi cleanup when powering down the gmu
  136. */
  137. void gen7_hwsched_hfi_stop(struct adreno_device *adreno_dev);
  138. /**
  139. * gen7_hwched_cp_init - Send CP_INIT via HFI
  140. * @adreno_dev: Pointer to adreno device structure
  141. *
  142. * This function is used to send CP INIT packet and bring
  143. * GPU out of secure mode using hfi raw packets.
  144. *
  145. * Return: 0 on success and negative error on failure.
  146. */
  147. int gen7_hwsched_cp_init(struct adreno_device *adreno_dev);
  148. /**
  149. * gen7_hwsched_counter_inline_enable - Configure a performance counter for a countable
  150. * @adreno_dev - Adreno device to configure
  151. * @group - Desired performance counter group
  152. * @counter - Desired performance counter in the group
  153. * @countable - Desired countable
  154. *
  155. * Physically set up a counter within a group with the desired countable
  156. * Return 0 on success or negative error on failure.
  157. */
  158. int gen7_hwsched_counter_inline_enable(struct adreno_device *adreno_dev,
  159. const struct adreno_perfcount_group *group,
  160. u32 counter, u32 countable);
  161. /**
  162. * gen7_hfi_send_cmd_async - Send an hfi packet
  163. * @adreno_dev: Pointer to adreno device structure
  164. * @data: Data to be sent in the hfi packet
  165. * @size_bytes: Size of the packet in bytes
  166. *
  167. * Send data in the form of an HFI packet to gmu and wait for
  168. * it's ack asynchronously
  169. *
  170. * Return: 0 on success and negative error on failure.
  171. */
  172. int gen7_hfi_send_cmd_async(struct adreno_device *adreno_dev, void *data, u32 size_bytes);
  173. /**
  174. * gen7_hwsched_submit_drawobj - Dispatch IBs to dispatch queues
  175. * @adreno_dev: Pointer to adreno device structure
  176. * @drawobj: The command draw object which needs to be submitted
  177. *
  178. * This function is used to register the context if needed and submit
  179. * IBs to the hfi dispatch queues.
  180. * Return: 0 on success and negative error on failure
  181. */
  182. int gen7_hwsched_submit_drawobj(struct adreno_device *adreno_dev,
  183. struct kgsl_drawobj *drawobj);
  184. /**
  185. * gen7_hwsched_context_detach - Unregister a context with GMU
  186. * @drawctxt: Pointer to the adreno context
  187. *
  188. * This function sends context unregister HFI and waits for the ack
  189. * to ensure all submissions from this context have retired
  190. */
  191. void gen7_hwsched_context_detach(struct adreno_context *drawctxt);
  192. /* Helper function to get to gen7 hwsched hfi device from adreno device */
  193. struct gen7_hwsched_hfi *to_gen7_hwsched_hfi(struct adreno_device *adreno_dev);
  194. /**
  195. * gen7_hwsched_preempt_count_get - Get preemption count from GMU
  196. * @adreno_dev: Pointer to adreno device
  197. *
  198. * This function sends a GET_VALUE HFI packet to get the number of
  199. * preemptions completed since last SLUMBER exit.
  200. *
  201. * Return: Preemption count
  202. */
  203. u32 gen7_hwsched_preempt_count_get(struct adreno_device *adreno_dev);
  204. /**
  205. * gen7_hwsched_lpac_cp_init - Send CP_INIT to LPAC via HFI
  206. * @adreno_dev: Pointer to adreno device structure
  207. *
  208. * This function is used to send CP INIT packet to LPAC and
  209. * enable submission to LPAC queue.
  210. *
  211. * Return: 0 on success and negative error on failure.
  212. */
  213. int gen7_hwsched_lpac_cp_init(struct adreno_device *adreno_dev);
  214. /**
  215. * gen7_hfi_send_lpac_feature_ctrl - Send the lpac feature hfi packet
  216. * @adreno_dev: Pointer to the adreno device
  217. *
  218. * Return: 0 on success or negative error on failure
  219. */
  220. int gen7_hfi_send_lpac_feature_ctrl(struct adreno_device *adreno_dev);
  221. /**
  222. * gen7_hwsched_context_destroy - Destroy any hwsched related resources during context destruction
  223. * @adreno_dev: Pointer to adreno device
  224. * @drawctxt: Pointer to the adreno context
  225. *
  226. * This functions destroys any hwsched related resources when this context is destroyed
  227. */
  228. void gen7_hwsched_context_destroy(struct adreno_device *adreno_dev,
  229. struct adreno_context *drawctxt);
  230. /**
  231. * gen7_hwsched_hfi_get_value - Send GET_VALUE packet to GMU to get the value of a property
  232. * @adreno_dev: Pointer to adreno device
  233. * @prop: property to get from GMU
  234. *
  235. * This functions sends GET_VALUE HFI packet to query value of a property
  236. *
  237. * Return: On success, return the value in the GMU response. On failure, return 0
  238. */
  239. u32 gen7_hwsched_hfi_get_value(struct adreno_device *adreno_dev, u32 prop);
  240. /**
  241. * gen7_send_hw_fence_hfi_wait_ack - Send hardware fence info to GMU
  242. * @adreno_dev: Pointer to adreno device
  243. * @entry: Pointer to the adreno hardware fence entry
  244. * @flags: Flags for this hardware fence
  245. *
  246. * Send the hardware fence info to the GMU and wait for the ack
  247. *
  248. * Return: 0 on success or negative error on failure
  249. */
  250. int gen7_send_hw_fence_hfi_wait_ack(struct adreno_device *adreno_dev,
  251. struct adreno_hw_fence_entry *entry, u64 flags);
  252. /**
  253. * gen7_hwsched_create_hw_fence - Create a hardware fence
  254. * @adreno_dev: Pointer to adreno device
  255. * @kfence: Pointer to the kgsl fence
  256. *
  257. * Create a hardware fence, set up hardware fence info and send it to GMU if required
  258. */
  259. void gen7_hwsched_create_hw_fence(struct adreno_device *adreno_dev,
  260. struct kgsl_sync_fence *kfence);
  261. /**
  262. * gen7_hwsched_drain_context_hw_fences - Drain context's hardware fences via GMU
  263. * @adreno_dev: Pointer to adreno device
  264. * @drawctxt: Pointer to the adreno context which is to be flushed
  265. *
  266. * Trigger hardware fences that were never dispatched to GMU
  267. *
  268. * Return: Zero on success or negative error on failure
  269. */
  270. int gen7_hwsched_drain_context_hw_fences(struct adreno_device *adreno_dev,
  271. struct adreno_context *drawctxt);
  272. /**
  273. * gen7_hwsched_check_context_inflight_hw_fences - Check whether all hardware fences
  274. * from a context have been sent to the TxQueue or not
  275. * @adreno_dev: Pointer to adreno device
  276. * @drawctxt: Pointer to the adreno context which is to be flushed
  277. *
  278. * Check if all hardware fences from this context have been sent to the
  279. * TxQueue. If not, log an error and return error code.
  280. *
  281. * Return: Zero on success or negative error on failure
  282. */
  283. int gen7_hwsched_check_context_inflight_hw_fences(struct adreno_device *adreno_dev,
  284. struct adreno_context *drawctxt);
  285. /**
  286. * gen7_remove_hw_fence_entry - Remove hardware fence entry
  287. * @adreno_dev: pointer to the adreno device
  288. * @entry: Pointer to the hardware fence entry
  289. */
  290. void gen7_remove_hw_fence_entry(struct adreno_device *adreno_dev,
  291. struct adreno_hw_fence_entry *entry);
  292. /**
  293. * gen7_trigger_hw_fence_cpu - Trigger hardware fence from cpu
  294. * @adreno_dev: pointer to the adreno device
  295. * @fence: hardware fence entry to be triggered
  296. *
  297. * Trigger the hardware fence by sending it to GMU's TxQueue and raise the
  298. * interrupt from GMU to APPS
  299. */
  300. void gen7_trigger_hw_fence_cpu(struct adreno_device *adreno_dev,
  301. struct adreno_hw_fence_entry *fence);
  302. /**
  303. * gen7_hwsched_disable_hw_fence_throttle - Disable hardware fence throttling after reset
  304. * @adreno_dev: pointer to the adreno device
  305. *
  306. * After device reset, clear hardware fence related data structures and send any hardware fences
  307. * that got deferred (prior to reset) and re-open the gates for hardware fence creation
  308. *
  309. * Return: Zero on success or negative error on failure
  310. */
  311. int gen7_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev);
  312. /**
  313. * gen7_hwsched_process_msgq - Process msgq
  314. * @adreno_dev: pointer to the adreno device
  315. *
  316. * This function grabs the msgq mutex and processes msgq for any outstanding hfi packets
  317. */
  318. void gen7_hwsched_process_msgq(struct adreno_device *adreno_dev);
  319. /**
  320. * gen7_hwsched_boot_gpu - Send the command to boot GPU
  321. * @adreno_dev: Pointer to adreno device
  322. *
  323. * Send the hfi to boot GPU, and check the ack, incase of a failure
  324. * get a snapshot and capture registers of interest.
  325. *
  326. * Return: Zero on success or negative error on failure
  327. */
  328. int gen7_hwsched_boot_gpu(struct adreno_device *adreno_dev);
  329. #endif