amdgpu_ring.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright 2016 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Christian König
  23. */
  24. #ifndef __AMDGPU_RING_H__
  25. #define __AMDGPU_RING_H__
  26. #include "gpu_scheduler.h"
  27. /* max number of rings */
  28. #define AMDGPU_MAX_RINGS 18
  29. #define AMDGPU_MAX_GFX_RINGS 1
  30. #define AMDGPU_MAX_COMPUTE_RINGS 8
  31. #define AMDGPU_MAX_VCE_RINGS 3
  32. #define AMDGPU_MAX_UVD_ENC_RINGS 2
  33. /* some special values for the owner field */
  34. #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
  35. #define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
  36. #define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
  37. #define AMDGPU_FENCE_FLAG_INT (1 << 1)
  38. enum amdgpu_ring_type {
  39. AMDGPU_RING_TYPE_GFX,
  40. AMDGPU_RING_TYPE_COMPUTE,
  41. AMDGPU_RING_TYPE_SDMA,
  42. AMDGPU_RING_TYPE_UVD,
  43. AMDGPU_RING_TYPE_VCE,
  44. AMDGPU_RING_TYPE_KIQ,
  45. AMDGPU_RING_TYPE_UVD_ENC,
  46. AMDGPU_RING_TYPE_VCN_DEC,
  47. AMDGPU_RING_TYPE_VCN_ENC
  48. };
  49. struct amdgpu_device;
  50. struct amdgpu_ring;
  51. struct amdgpu_ib;
  52. struct amdgpu_cs_parser;
  53. /*
  54. * Fences.
  55. */
  56. struct amdgpu_fence_driver {
  57. uint64_t gpu_addr;
  58. volatile uint32_t *cpu_addr;
  59. /* sync_seq is protected by ring emission lock */
  60. uint32_t sync_seq;
  61. atomic_t last_seq;
  62. bool initialized;
  63. struct amdgpu_irq_src *irq_src;
  64. unsigned irq_type;
  65. struct timer_list fallback_timer;
  66. unsigned num_fences_mask;
  67. spinlock_t lock;
  68. struct dma_fence **fences;
  69. };
  70. int amdgpu_fence_driver_init(struct amdgpu_device *adev);
  71. void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
  72. void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
  73. void amdgpu_fence_driver_force_completion_ring(struct amdgpu_ring *ring);
  74. int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
  75. unsigned num_hw_submission);
  76. int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
  77. struct amdgpu_irq_src *irq_src,
  78. unsigned irq_type);
  79. void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
  80. void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
  81. int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence);
  82. void amdgpu_fence_process(struct amdgpu_ring *ring);
  83. int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
  84. unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
  85. /*
  86. * Rings.
  87. */
  88. /* provided by hw blocks that expose a ring buffer for commands */
  89. struct amdgpu_ring_funcs {
  90. enum amdgpu_ring_type type;
  91. uint32_t align_mask;
  92. u32 nop;
  93. bool support_64bit_ptrs;
  94. unsigned vmhub;
  95. /* ring read/write ptr handling */
  96. u64 (*get_rptr)(struct amdgpu_ring *ring);
  97. u64 (*get_wptr)(struct amdgpu_ring *ring);
  98. void (*set_wptr)(struct amdgpu_ring *ring);
  99. /* validating and patching of IBs */
  100. int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
  101. /* constants to calculate how many DW are needed for an emit */
  102. unsigned emit_frame_size;
  103. unsigned emit_ib_size;
  104. /* command emit functions */
  105. void (*emit_ib)(struct amdgpu_ring *ring,
  106. struct amdgpu_ib *ib,
  107. unsigned vm_id, bool ctx_switch);
  108. void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
  109. uint64_t seq, unsigned flags);
  110. void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
  111. void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
  112. uint64_t pd_addr);
  113. void (*emit_hdp_flush)(struct amdgpu_ring *ring);
  114. void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
  115. void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
  116. uint32_t gds_base, uint32_t gds_size,
  117. uint32_t gws_base, uint32_t gws_size,
  118. uint32_t oa_base, uint32_t oa_size);
  119. /* testing functions */
  120. int (*test_ring)(struct amdgpu_ring *ring);
  121. int (*test_ib)(struct amdgpu_ring *ring, long timeout);
  122. /* insert NOP packets */
  123. void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
  124. void (*insert_start)(struct amdgpu_ring *ring);
  125. void (*insert_end)(struct amdgpu_ring *ring);
  126. /* pad the indirect buffer to the necessary number of dw */
  127. void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
  128. unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
  129. void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
  130. /* note usage for clock and power gating */
  131. void (*begin_use)(struct amdgpu_ring *ring);
  132. void (*end_use)(struct amdgpu_ring *ring);
  133. void (*emit_switch_buffer) (struct amdgpu_ring *ring);
  134. void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
  135. void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
  136. void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
  137. void (*emit_tmz)(struct amdgpu_ring *ring, bool start);
  138. };
  139. struct amdgpu_ring {
  140. struct amdgpu_device *adev;
  141. const struct amdgpu_ring_funcs *funcs;
  142. struct amdgpu_fence_driver fence_drv;
  143. struct amd_gpu_scheduler sched;
  144. struct list_head lru_list;
  145. struct amdgpu_bo *ring_obj;
  146. volatile uint32_t *ring;
  147. unsigned rptr_offs;
  148. u64 wptr;
  149. u64 wptr_old;
  150. unsigned ring_size;
  151. unsigned max_dw;
  152. int count_dw;
  153. uint64_t gpu_addr;
  154. uint64_t ptr_mask;
  155. uint32_t buf_mask;
  156. bool ready;
  157. u32 idx;
  158. u32 me;
  159. u32 pipe;
  160. u32 queue;
  161. struct amdgpu_bo *mqd_obj;
  162. uint64_t mqd_gpu_addr;
  163. void *mqd_ptr;
  164. uint64_t eop_gpu_addr;
  165. u32 doorbell_index;
  166. bool use_doorbell;
  167. unsigned wptr_offs;
  168. unsigned fence_offs;
  169. uint64_t current_ctx;
  170. char name[16];
  171. unsigned cond_exe_offs;
  172. u64 cond_exe_gpu_addr;
  173. volatile u32 *cond_exe_cpu_addr;
  174. unsigned vm_inv_eng;
  175. bool has_compute_vm_bug;
  176. #if defined(CONFIG_DEBUG_FS)
  177. struct dentry *ent;
  178. #endif
  179. };
  180. int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
  181. void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
  182. void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
  183. void amdgpu_ring_commit(struct amdgpu_ring *ring);
  184. void amdgpu_ring_undo(struct amdgpu_ring *ring);
  185. int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
  186. unsigned ring_size, struct amdgpu_irq_src *irq_src,
  187. unsigned irq_type);
  188. void amdgpu_ring_fini(struct amdgpu_ring *ring);
  189. int amdgpu_ring_lru_get(struct amdgpu_device *adev, int type, int *blacklist,
  190. int num_blacklist, struct amdgpu_ring **ring);
  191. void amdgpu_ring_lru_touch(struct amdgpu_device *adev, struct amdgpu_ring *ring);
  192. static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
  193. {
  194. int i = 0;
  195. while (i <= ring->buf_mask)
  196. ring->ring[i++] = ring->funcs->nop;
  197. }
  198. #endif