amdgpu_ring.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 16
  29. #define AMDGPU_MAX_GFX_RINGS 1
  30. #define AMDGPU_MAX_COMPUTE_RINGS 8
  31. #define AMDGPU_MAX_VCE_RINGS 3
  32. /* some special values for the owner field */
  33. #define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
  34. #define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
  35. #define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
  36. #define AMDGPU_FENCE_FLAG_INT (1 << 1)
  37. enum amdgpu_ring_type {
  38. AMDGPU_RING_TYPE_GFX,
  39. AMDGPU_RING_TYPE_COMPUTE,
  40. AMDGPU_RING_TYPE_SDMA,
  41. AMDGPU_RING_TYPE_UVD,
  42. AMDGPU_RING_TYPE_VCE,
  43. AMDGPU_RING_TYPE_KIQ
  44. };
  45. struct amdgpu_device;
  46. struct amdgpu_ring;
  47. struct amdgpu_ib;
  48. struct amdgpu_cs_parser;
  49. /*
  50. * Fences.
  51. */
  52. struct amdgpu_fence_driver {
  53. uint64_t gpu_addr;
  54. volatile uint32_t *cpu_addr;
  55. /* sync_seq is protected by ring emission lock */
  56. uint32_t sync_seq;
  57. atomic_t last_seq;
  58. bool initialized;
  59. struct amdgpu_irq_src *irq_src;
  60. unsigned irq_type;
  61. struct timer_list fallback_timer;
  62. unsigned num_fences_mask;
  63. spinlock_t lock;
  64. struct dma_fence **fences;
  65. };
  66. int amdgpu_fence_driver_init(struct amdgpu_device *adev);
  67. void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
  68. void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
  69. int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
  70. unsigned num_hw_submission);
  71. int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
  72. struct amdgpu_irq_src *irq_src,
  73. unsigned irq_type);
  74. void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
  75. void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
  76. int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence);
  77. void amdgpu_fence_process(struct amdgpu_ring *ring);
  78. int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
  79. unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
  80. /*
  81. * Rings.
  82. */
  83. /* provided by hw blocks that expose a ring buffer for commands */
  84. struct amdgpu_ring_funcs {
  85. enum amdgpu_ring_type type;
  86. uint32_t align_mask;
  87. u32 nop;
  88. /* ring read/write ptr handling */
  89. u32 (*get_rptr)(struct amdgpu_ring *ring);
  90. u32 (*get_wptr)(struct amdgpu_ring *ring);
  91. void (*set_wptr)(struct amdgpu_ring *ring);
  92. /* validating and patching of IBs */
  93. int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
  94. /* constants to calculate how many DW are needed for an emit */
  95. unsigned emit_frame_size;
  96. unsigned emit_ib_size;
  97. /* command emit functions */
  98. void (*emit_ib)(struct amdgpu_ring *ring,
  99. struct amdgpu_ib *ib,
  100. unsigned vm_id, bool ctx_switch);
  101. void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
  102. uint64_t seq, unsigned flags);
  103. void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
  104. void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
  105. uint64_t pd_addr);
  106. void (*emit_hdp_flush)(struct amdgpu_ring *ring);
  107. void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
  108. void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
  109. uint32_t gds_base, uint32_t gds_size,
  110. uint32_t gws_base, uint32_t gws_size,
  111. uint32_t oa_base, uint32_t oa_size);
  112. /* testing functions */
  113. int (*test_ring)(struct amdgpu_ring *ring);
  114. int (*test_ib)(struct amdgpu_ring *ring, long timeout);
  115. /* insert NOP packets */
  116. void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
  117. /* pad the indirect buffer to the necessary number of dw */
  118. void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
  119. unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
  120. void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
  121. /* note usage for clock and power gating */
  122. void (*begin_use)(struct amdgpu_ring *ring);
  123. void (*end_use)(struct amdgpu_ring *ring);
  124. void (*emit_switch_buffer) (struct amdgpu_ring *ring);
  125. void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
  126. void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
  127. void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
  128. };
  129. struct amdgpu_ring {
  130. struct amdgpu_device *adev;
  131. const struct amdgpu_ring_funcs *funcs;
  132. struct amdgpu_fence_driver fence_drv;
  133. struct amd_gpu_scheduler sched;
  134. struct amdgpu_bo *ring_obj;
  135. volatile uint32_t *ring;
  136. unsigned rptr_offs;
  137. unsigned wptr;
  138. unsigned wptr_old;
  139. unsigned ring_size;
  140. unsigned max_dw;
  141. int count_dw;
  142. uint64_t gpu_addr;
  143. uint32_t ptr_mask;
  144. bool ready;
  145. u32 idx;
  146. u32 me;
  147. u32 pipe;
  148. u32 queue;
  149. struct amdgpu_bo *mqd_obj;
  150. u32 doorbell_index;
  151. bool use_doorbell;
  152. unsigned wptr_offs;
  153. unsigned fence_offs;
  154. uint64_t current_ctx;
  155. char name[16];
  156. unsigned cond_exe_offs;
  157. u64 cond_exe_gpu_addr;
  158. volatile u32 *cond_exe_cpu_addr;
  159. #if defined(CONFIG_DEBUG_FS)
  160. struct dentry *ent;
  161. #endif
  162. };
  163. int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
  164. void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
  165. void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
  166. void amdgpu_ring_commit(struct amdgpu_ring *ring);
  167. void amdgpu_ring_undo(struct amdgpu_ring *ring);
  168. int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
  169. unsigned ring_size, struct amdgpu_irq_src *irq_src,
  170. unsigned irq_type);
  171. void amdgpu_ring_fini(struct amdgpu_ring *ring);
  172. #endif