178023016SChristian König /* 278023016SChristian König * Copyright 2016 Advanced Micro Devices, Inc. 378023016SChristian König * 478023016SChristian König * Permission is hereby granted, free of charge, to any person obtaining a 578023016SChristian König * copy of this software and associated documentation files (the "Software"), 678023016SChristian König * to deal in the Software without restriction, including without limitation 778023016SChristian König * the rights to use, copy, modify, merge, publish, distribute, sublicense, 878023016SChristian König * and/or sell copies of the Software, and to permit persons to whom the 978023016SChristian König * Software is furnished to do so, subject to the following conditions: 1078023016SChristian König * 1178023016SChristian König * The above copyright notice and this permission notice shall be included in 1278023016SChristian König * all copies or substantial portions of the Software. 1378023016SChristian König * 1478023016SChristian König * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1578023016SChristian König * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1678023016SChristian König * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1778023016SChristian König * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1878023016SChristian König * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1978023016SChristian König * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2078023016SChristian König * OTHER DEALINGS IN THE SOFTWARE. 2178023016SChristian König * 2278023016SChristian König * Authors: Christian König 2378023016SChristian König */ 2478023016SChristian König #ifndef __AMDGPU_RING_H__ 2578023016SChristian König #define __AMDGPU_RING_H__ 2678023016SChristian König 27b2ff0e8aSAndres Rodriguez #include <drm/amdgpu_drm.h> 281b1f42d8SLucas Stach #include <drm/gpu_scheduler.h> 2961b100e9SFelix Kuehling #include <drm/drm_print.h> 3078023016SChristian König 31a190f8dcSChristian König struct amdgpu_device; 32a190f8dcSChristian König struct amdgpu_ring; 33a190f8dcSChristian König struct amdgpu_ib; 34a190f8dcSChristian König struct amdgpu_cs_parser; 35a190f8dcSChristian König struct amdgpu_job; 36a190f8dcSChristian König struct amdgpu_vm; 37a190f8dcSChristian König 3878023016SChristian König /* max number of rings */ 398b75a521SJames Zhu #define AMDGPU_MAX_RINGS 28 401c6d567bSNirmoy Das #define AMDGPU_MAX_HWIP_RINGS 8 41a644d85aSHawking Zhang #define AMDGPU_MAX_GFX_RINGS 2 420c97a19aSJiadong.Zhu #define AMDGPU_MAX_SW_GFX_RINGS 2 4378023016SChristian König #define AMDGPU_MAX_COMPUTE_RINGS 8 4478023016SChristian König #define AMDGPU_MAX_VCE_RINGS 3 45f7243053SLeo Liu #define AMDGPU_MAX_UVD_ENC_RINGS 2 4678023016SChristian König 4734eaf30fSNirmoy Das enum amdgpu_ring_priority_level { 4834eaf30fSNirmoy Das AMDGPU_RING_PRIO_0, 4934eaf30fSNirmoy Das AMDGPU_RING_PRIO_1, 5034eaf30fSNirmoy Das AMDGPU_RING_PRIO_DEFAULT = 1, 5134eaf30fSNirmoy Das AMDGPU_RING_PRIO_2, 5234eaf30fSNirmoy Das AMDGPU_RING_PRIO_MAX 5334eaf30fSNirmoy Das }; 541c6d567bSNirmoy Das 5578023016SChristian König /* some special values for the owner field */ 5678023016SChristian König #define AMDGPU_FENCE_OWNER_UNDEFINED ((void *)0ul) 5778023016SChristian König #define AMDGPU_FENCE_OWNER_VM ((void *)1ul) 58d8d019ccSFelix Kuehling #define AMDGPU_FENCE_OWNER_KFD ((void *)2ul) 5978023016SChristian König 6078023016SChristian König #define AMDGPU_FENCE_FLAG_64BIT (1 << 0) 6178023016SChristian König #define AMDGPU_FENCE_FLAG_INT (1 << 1) 62d240cd9eSMarek Olšák #define AMDGPU_FENCE_FLAG_TC_WB_ONLY (1 << 2) 63be254550SJiadong.Zhu #define AMDGPU_FENCE_FLAG_EXEC (1 << 3) 6478023016SChristian König 650e28b10fSChristian König #define to_amdgpu_ring(s) container_of((s), struct amdgpu_ring, sched) 660e28b10fSChristian König 679ecefb19SChristian König #define AMDGPU_IB_POOL_SIZE (1024 * 1024) 689ecefb19SChristian König 6978023016SChristian König enum amdgpu_ring_type { 7007e14845SNirmoy Das AMDGPU_RING_TYPE_GFX = AMDGPU_HW_IP_GFX, 7107e14845SNirmoy Das AMDGPU_RING_TYPE_COMPUTE = AMDGPU_HW_IP_COMPUTE, 7207e14845SNirmoy Das AMDGPU_RING_TYPE_SDMA = AMDGPU_HW_IP_DMA, 7307e14845SNirmoy Das AMDGPU_RING_TYPE_UVD = AMDGPU_HW_IP_UVD, 7407e14845SNirmoy Das AMDGPU_RING_TYPE_VCE = AMDGPU_HW_IP_VCE, 7507e14845SNirmoy Das AMDGPU_RING_TYPE_UVD_ENC = AMDGPU_HW_IP_UVD_ENC, 7607e14845SNirmoy Das AMDGPU_RING_TYPE_VCN_DEC = AMDGPU_HW_IP_VCN_DEC, 7707e14845SNirmoy Das AMDGPU_RING_TYPE_VCN_ENC = AMDGPU_HW_IP_VCN_ENC, 7807e14845SNirmoy Das AMDGPU_RING_TYPE_VCN_JPEG = AMDGPU_HW_IP_VCN_JPEG, 79cdca7979SJack Xiao AMDGPU_RING_TYPE_KIQ, 80cdca7979SJack Xiao AMDGPU_RING_TYPE_MES 8178023016SChristian König }; 8278023016SChristian König 839ecefb19SChristian König enum amdgpu_ib_pool_type { 849ecefb19SChristian König /* Normal submissions to the top of the pipeline. */ 859ecefb19SChristian König AMDGPU_IB_POOL_DELAYED, 869ecefb19SChristian König /* Immediate submissions to the bottom of the pipeline. */ 879ecefb19SChristian König AMDGPU_IB_POOL_IMMEDIATE, 889ecefb19SChristian König /* Direct submission to the ring buffer during init and reset. */ 899ecefb19SChristian König AMDGPU_IB_POOL_DIRECT, 909ecefb19SChristian König 919ecefb19SChristian König AMDGPU_IB_POOL_MAX 929ecefb19SChristian König }; 939ecefb19SChristian König 94a190f8dcSChristian König struct amdgpu_ib { 95a190f8dcSChristian König struct amdgpu_sa_bo *sa_bo; 96a190f8dcSChristian König uint32_t length_dw; 97a190f8dcSChristian König uint64_t gpu_addr; 98a190f8dcSChristian König uint32_t *ptr; 99a190f8dcSChristian König uint32_t flags; 100a190f8dcSChristian König }; 10178023016SChristian König 1021c6d567bSNirmoy Das struct amdgpu_sched { 1031c6d567bSNirmoy Das u32 num_scheds; 1041c6d567bSNirmoy Das struct drm_gpu_scheduler *sched[AMDGPU_MAX_HWIP_RINGS]; 1051c6d567bSNirmoy Das }; 1061c6d567bSNirmoy Das 10778023016SChristian König /* 10878023016SChristian König * Fences. 10978023016SChristian König */ 11078023016SChristian König struct amdgpu_fence_driver { 11178023016SChristian König uint64_t gpu_addr; 11278023016SChristian König volatile uint32_t *cpu_addr; 11378023016SChristian König /* sync_seq is protected by ring emission lock */ 11478023016SChristian König uint32_t sync_seq; 11578023016SChristian König atomic_t last_seq; 11678023016SChristian König bool initialized; 11778023016SChristian König struct amdgpu_irq_src *irq_src; 11878023016SChristian König unsigned irq_type; 1198c5e13ecSAndrey Grodzovsky struct timer_list fallback_timer; 12078023016SChristian König unsigned num_fences_mask; 12178023016SChristian König spinlock_t lock; 122220196b3SDave Airlie struct dma_fence **fences; 12378023016SChristian König }; 12478023016SChristian König 125a190f8dcSChristian König extern const struct drm_sched_backend_ops amdgpu_sched_ops; 126a190f8dcSChristian König 127bf67014dSHuang Rui void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring); 1282f9d4084SMonk Liu void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring); 12978023016SChristian König 1305fd8518dSAndrey Grodzovsky int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring); 13178023016SChristian König int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, 13278023016SChristian König struct amdgpu_irq_src *irq_src, 13378023016SChristian König unsigned irq_type); 1348d35a259SLikun Gao void amdgpu_fence_driver_hw_init(struct amdgpu_device *adev); 135067f44c8SGuchun Chen void amdgpu_fence_driver_hw_fini(struct amdgpu_device *adev); 136067f44c8SGuchun Chen int amdgpu_fence_driver_sw_init(struct amdgpu_device *adev); 137067f44c8SGuchun Chen void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev); 138c530b02fSJack Zhang int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence, struct amdgpu_job *job, 139d240cd9eSMarek Olšák unsigned flags); 14004e4e2e9SYintian Tao int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s, 14104e4e2e9SYintian Tao uint32_t timeout); 14295d7fc4aSAndrey Grodzovsky bool amdgpu_fence_process(struct amdgpu_ring *ring); 14378023016SChristian König int amdgpu_fence_wait_empty(struct amdgpu_ring *ring); 14443ca8efaSpding signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring, 14543ca8efaSpding uint32_t wait_seq, 14643ca8efaSpding signed long timeout); 14778023016SChristian König unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring); 1483f4c175dSJiadong.Zhu 1499e225fb9SAndrey Grodzovsky void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop); 15078023016SChristian König 1513f4c175dSJiadong.Zhu u64 amdgpu_fence_last_unsignaled_time_us(struct amdgpu_ring *ring); 1523f4c175dSJiadong.Zhu void amdgpu_fence_update_start_timestamp(struct amdgpu_ring *ring, uint32_t seq, 1533f4c175dSJiadong.Zhu ktime_t timestamp); 1543f4c175dSJiadong.Zhu 15578023016SChristian König /* 15678023016SChristian König * Rings. 15778023016SChristian König */ 15878023016SChristian König 15978023016SChristian König /* provided by hw blocks that expose a ring buffer for commands */ 16078023016SChristian König struct amdgpu_ring_funcs { 16121cd942eSChristian König enum amdgpu_ring_type type; 16279887142SChristian König uint32_t align_mask; 16379887142SChristian König u32 nop; 164536fbf94SKen Wang bool support_64bit_ptrs; 165120c2125SLeo Liu bool no_user_fence; 1668c0f11ffSLang Yu bool secure_submission_supported; 1670eeb68b3SChristian König unsigned vmhub; 168c8c1a1d2SBoyuan Zhang unsigned extra_dw; 16921cd942eSChristian König 17078023016SChristian König /* ring read/write ptr handling */ 171536fbf94SKen Wang u64 (*get_rptr)(struct amdgpu_ring *ring); 172536fbf94SKen Wang u64 (*get_wptr)(struct amdgpu_ring *ring); 17378023016SChristian König void (*set_wptr)(struct amdgpu_ring *ring); 17478023016SChristian König /* validating and patching of IBs */ 175cdc7893fSChristian König int (*parse_cs)(struct amdgpu_cs_parser *p, 176cdc7893fSChristian König struct amdgpu_job *job, 177cdc7893fSChristian König struct amdgpu_ib *ib); 178cdc7893fSChristian König int (*patch_cs_in_place)(struct amdgpu_cs_parser *p, 179cdc7893fSChristian König struct amdgpu_job *job, 180cdc7893fSChristian König struct amdgpu_ib *ib); 181e12f3d7aSChristian König /* constants to calculate how many DW are needed for an emit */ 182e12f3d7aSChristian König unsigned emit_frame_size; 183e12f3d7aSChristian König unsigned emit_ib_size; 18478023016SChristian König /* command emit functions */ 18578023016SChristian König void (*emit_ib)(struct amdgpu_ring *ring, 18634955e03SRex Zhu struct amdgpu_job *job, 18778023016SChristian König struct amdgpu_ib *ib, 188c4c905ecSJack Xiao uint32_t flags); 18978023016SChristian König void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr, 19078023016SChristian König uint64_t seq, unsigned flags); 19178023016SChristian König void (*emit_pipeline_sync)(struct amdgpu_ring *ring); 192c4f46f22SChristian König void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vmid, 193c633c00bSChristian König uint64_t pd_addr); 19478023016SChristian König void (*emit_hdp_flush)(struct amdgpu_ring *ring); 19578023016SChristian König void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid, 19678023016SChristian König uint32_t gds_base, uint32_t gds_size, 19778023016SChristian König uint32_t gws_base, uint32_t gws_size, 19878023016SChristian König uint32_t oa_base, uint32_t oa_size); 19978023016SChristian König /* testing functions */ 20078023016SChristian König int (*test_ring)(struct amdgpu_ring *ring); 20178023016SChristian König int (*test_ib)(struct amdgpu_ring *ring, long timeout); 20278023016SChristian König /* insert NOP packets */ 20378023016SChristian König void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count); 204ef44f854SLeo Liu void (*insert_start)(struct amdgpu_ring *ring); 205135d4735SLeo Liu void (*insert_end)(struct amdgpu_ring *ring); 20678023016SChristian König /* pad the indirect buffer to the necessary number of dw */ 20778023016SChristian König void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib); 20878023016SChristian König unsigned (*init_cond_exec)(struct amdgpu_ring *ring); 20978023016SChristian König void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset); 21078023016SChristian König /* note usage for clock and power gating */ 21178023016SChristian König void (*begin_use)(struct amdgpu_ring *ring); 21278023016SChristian König void (*end_use)(struct amdgpu_ring *ring); 21378023016SChristian König void (*emit_switch_buffer) (struct amdgpu_ring *ring); 2140bb5d5b0SLuben Tuikov void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags); 21554208194SYintian Tao void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg, 21654208194SYintian Tao uint32_t reg_val_offs); 217b6091c12SXiangliang Yu void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val); 218c1e877daSChristian König void (*emit_reg_wait)(struct amdgpu_ring *ring, uint32_t reg, 219c1e877daSChristian König uint32_t val, uint32_t mask); 22082853638SAlex Deucher void (*emit_reg_write_reg_wait)(struct amdgpu_ring *ring, 22182853638SAlex Deucher uint32_t reg0, uint32_t reg1, 22282853638SAlex Deucher uint32_t ref, uint32_t mask); 223f77c9affSHuang Rui void (*emit_frame_cntl)(struct amdgpu_ring *ring, bool start, 224f77c9affSHuang Rui bool secure); 2257876fa4fSChristian König /* Try to soft recover the ring to make the fence signal */ 2267876fa4fSChristian König void (*soft_recovery)(struct amdgpu_ring *ring, unsigned vmid); 227692441f2SRex Zhu int (*preempt_ib)(struct amdgpu_ring *ring); 22822301177SAndrey Grodzovsky void (*emit_mem_sync)(struct amdgpu_ring *ring); 2290a52a6caSNirmoy Das void (*emit_wave_limit)(struct amdgpu_ring *ring, bool enable); 23078023016SChristian König }; 23178023016SChristian König 23278023016SChristian König struct amdgpu_ring { 23378023016SChristian König struct amdgpu_device *adev; 23478023016SChristian König const struct amdgpu_ring_funcs *funcs; 23578023016SChristian König struct amdgpu_fence_driver fence_drv; 2361b1f42d8SLucas Stach struct drm_gpu_scheduler sched; 23778023016SChristian König 23878023016SChristian König struct amdgpu_bo *ring_obj; 23978023016SChristian König volatile uint32_t *ring; 24078023016SChristian König unsigned rptr_offs; 241d74c5b06SJack Xiao u64 rptr_gpu_addr; 242d74c5b06SJack Xiao volatile u32 *rptr_cpu_addr; 243536fbf94SKen Wang u64 wptr; 244536fbf94SKen Wang u64 wptr_old; 24578023016SChristian König unsigned ring_size; 24678023016SChristian König unsigned max_dw; 24778023016SChristian König int count_dw; 24878023016SChristian König uint64_t gpu_addr; 249536fbf94SKen Wang uint64_t ptr_mask; 250536fbf94SKen Wang uint32_t buf_mask; 25178023016SChristian König u32 idx; 25278023016SChristian König u32 me; 25378023016SChristian König u32 pipe; 25478023016SChristian König u32 queue; 25578023016SChristian König struct amdgpu_bo *mqd_obj; 256f3972b53SMonk Liu uint64_t mqd_gpu_addr; 25759a82d7dSXiangliang Yu void *mqd_ptr; 25834534610SAlex Deucher uint64_t eop_gpu_addr; 25978023016SChristian König u32 doorbell_index; 26078023016SChristian König bool use_doorbell; 2612ffe31deSPixel Ding bool use_pollmem; 26278023016SChristian König unsigned wptr_offs; 263d74c5b06SJack Xiao u64 wptr_gpu_addr; 264d74c5b06SJack Xiao volatile u32 *wptr_cpu_addr; 26578023016SChristian König unsigned fence_offs; 266d74c5b06SJack Xiao u64 fence_gpu_addr; 267d74c5b06SJack Xiao volatile u32 *fence_cpu_addr; 26878023016SChristian König uint64_t current_ctx; 26978023016SChristian König char name[16]; 270ef3e1323SJack Xiao u32 trail_seq; 271ef3e1323SJack Xiao unsigned trail_fence_offs; 272ef3e1323SJack Xiao u64 trail_fence_gpu_addr; 273ef3e1323SJack Xiao volatile u32 *trail_fence_cpu_addr; 27478023016SChristian König unsigned cond_exe_offs; 27578023016SChristian König u64 cond_exe_gpu_addr; 27678023016SChristian König volatile u32 *cond_exe_cpu_addr; 2774789c463SChristian König unsigned vm_inv_eng; 2783af81440SChristian König struct dma_fence *vmid_wait; 279dd684d31SAlex Xie bool has_compute_vm_bug; 280cb3d1085SAlex Deucher bool no_scheduler; 281ebdd2e9dSNirmoy Das int hw_prio; 2825fd8518dSAndrey Grodzovsky unsigned num_hw_submission; 2835fd8518dSAndrey Grodzovsky atomic_t *sched_score; 284c6abbcbcSJack Xiao 285c6abbcbcSJack Xiao /* used for mes */ 286c6abbcbcSJack Xiao bool is_mes_queue; 287c6abbcbcSJack Xiao uint32_t hw_queue_id; 288c6abbcbcSJack Xiao struct amdgpu_mes_ctx_data *mes_ctx; 289ded946f3SJiadong.Zhu 290ded946f3SJiadong.Zhu bool is_sw_ring; 291ded946f3SJiadong.Zhu unsigned int entry_index; 292ded946f3SJiadong.Zhu 29378023016SChristian König }; 29478023016SChristian König 295cdc7893fSChristian König #define amdgpu_ring_parse_cs(r, p, job, ib) ((r)->funcs->parse_cs((p), (job), (ib))) 296cdc7893fSChristian König #define amdgpu_ring_patch_cs_in_place(r, p, job, ib) ((r)->funcs->patch_cs_in_place((p), (job), (ib))) 2970a7845dbSHuang Rui #define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r)) 298*6c1a6d0bSJesseZhang #define amdgpu_ring_test_ib(r, t) ((r)->funcs->test_ib ? (r)->funcs->test_ib((r), (t)) : 0) 2990a7845dbSHuang Rui #define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r)) 3000a7845dbSHuang Rui #define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r)) 3010a7845dbSHuang Rui #define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r)) 302c4c905ecSJack Xiao #define amdgpu_ring_emit_ib(r, job, ib, flags) ((r)->funcs->emit_ib((r), (job), (ib), (flags))) 3030a7845dbSHuang Rui #define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r)) 3040a7845dbSHuang Rui #define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr)) 3050a7845dbSHuang Rui #define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags)) 3060a7845dbSHuang Rui #define amdgpu_ring_emit_gds_switch(r, v, db, ds, wb, ws, ab, as) (r)->funcs->emit_gds_switch((r), (v), (db), (ds), (wb), (ws), (ab), (as)) 3070a7845dbSHuang Rui #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r)) 3080a7845dbSHuang Rui #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r)) 3090bb5d5b0SLuben Tuikov #define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d)) 31054208194SYintian Tao #define amdgpu_ring_emit_rreg(r, d, o) (r)->funcs->emit_rreg((r), (d), (o)) 3110a7845dbSHuang Rui #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v)) 3120a7845dbSHuang Rui #define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m)) 3130a7845dbSHuang Rui #define amdgpu_ring_emit_reg_write_reg_wait(r, d0, d1, v, m) (r)->funcs->emit_reg_write_reg_wait((r), (d0), (d1), (v), (m)) 314f77c9affSHuang Rui #define amdgpu_ring_emit_frame_cntl(r, b, s) (r)->funcs->emit_frame_cntl((r), (b), (s)) 3150a7845dbSHuang Rui #define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib))) 3160a7845dbSHuang Rui #define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r)) 3170a7845dbSHuang Rui #define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o)) 318692441f2SRex Zhu #define amdgpu_ring_preempt_ib(r) (r)->funcs->preempt_ib(r) 3190a7845dbSHuang Rui 32078023016SChristian König int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw); 3213f4c175dSJiadong.Zhu void amdgpu_ring_ib_begin(struct amdgpu_ring *ring); 3223f4c175dSJiadong.Zhu void amdgpu_ring_ib_end(struct amdgpu_ring *ring); 3233f4c175dSJiadong.Zhu 32478023016SChristian König void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count); 32578023016SChristian König void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib); 32678023016SChristian König void amdgpu_ring_commit(struct amdgpu_ring *ring); 32778023016SChristian König void amdgpu_ring_undo(struct amdgpu_ring *ring); 32878023016SChristian König int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, 329cf8cc382SMa Jun unsigned int max_dw, struct amdgpu_irq_src *irq_src, 330cf8cc382SMa Jun unsigned int irq_type, unsigned int hw_prio, 331c107171bSChristian König atomic_t *sched_score); 33278023016SChristian König void amdgpu_ring_fini(struct amdgpu_ring *ring); 33382853638SAlex Deucher void amdgpu_ring_emit_reg_write_reg_wait_helper(struct amdgpu_ring *ring, 33482853638SAlex Deucher uint32_t reg0, uint32_t val0, 33582853638SAlex Deucher uint32_t reg1, uint32_t val1); 3367876fa4fSChristian König bool amdgpu_ring_soft_recovery(struct amdgpu_ring *ring, unsigned int vmid, 3377876fa4fSChristian König struct dma_fence *fence); 33882853638SAlex Deucher 339dfc98479SRex Zhu static inline void amdgpu_ring_set_preempt_cond_exec(struct amdgpu_ring *ring, 340dfc98479SRex Zhu bool cond_exec) 341dfc98479SRex Zhu { 342dfc98479SRex Zhu *ring->cond_exe_cpu_addr = cond_exec; 343dfc98479SRex Zhu } 344dfc98479SRex Zhu 345c79ecfbfSMonk Liu static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring) 346c79ecfbfSMonk Liu { 347c79ecfbfSMonk Liu int i = 0; 348e09706f4SMonk Liu while (i <= ring->buf_mask) 349c79ecfbfSMonk Liu ring->ring[i++] = ring->funcs->nop; 350c79ecfbfSMonk Liu 351c79ecfbfSMonk Liu } 35278023016SChristian König 353e8110b1cSChristian König static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v) 354e8110b1cSChristian König { 355e8110b1cSChristian König if (ring->count_dw <= 0) 356e8110b1cSChristian König DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); 357e8110b1cSChristian König ring->ring[ring->wptr++ & ring->buf_mask] = v; 358e8110b1cSChristian König ring->wptr &= ring->ptr_mask; 359e8110b1cSChristian König ring->count_dw--; 360e8110b1cSChristian König } 361e8110b1cSChristian König 362e8110b1cSChristian König static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, 363e8110b1cSChristian König void *src, int count_dw) 364e8110b1cSChristian König { 365e8110b1cSChristian König unsigned occupied, chunk1, chunk2; 366e8110b1cSChristian König void *dst; 367e8110b1cSChristian König 368369421cbSChristian König if (unlikely(ring->count_dw < count_dw)) 369e8110b1cSChristian König DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); 370e8110b1cSChristian König 371e8110b1cSChristian König occupied = ring->wptr & ring->buf_mask; 372e8110b1cSChristian König dst = (void *)&ring->ring[occupied]; 373e8110b1cSChristian König chunk1 = ring->buf_mask + 1 - occupied; 374e8110b1cSChristian König chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1; 375e8110b1cSChristian König chunk2 = count_dw - chunk1; 376e8110b1cSChristian König chunk1 <<= 2; 377e8110b1cSChristian König chunk2 <<= 2; 378e8110b1cSChristian König 379e8110b1cSChristian König if (chunk1) 380e8110b1cSChristian König memcpy(dst, src, chunk1); 381e8110b1cSChristian König 382e8110b1cSChristian König if (chunk2) { 383e8110b1cSChristian König src += chunk1; 384e8110b1cSChristian König dst = (void *)ring->ring; 385e8110b1cSChristian König memcpy(dst, src, chunk2); 386e8110b1cSChristian König } 387e8110b1cSChristian König 388e8110b1cSChristian König ring->wptr += count_dw; 389e8110b1cSChristian König ring->wptr &= ring->ptr_mask; 390e8110b1cSChristian König ring->count_dw -= count_dw; 391e8110b1cSChristian König } 392e8110b1cSChristian König 3932bc956efSJack Xiao #define amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset) \ 3942bc956efSJack Xiao (ring->is_mes_queue && ring->mes_ctx ? \ 3952bc956efSJack Xiao (ring->mes_ctx->meta_data_gpu_addr + offset) : 0) 3962bc956efSJack Xiao 3972bc956efSJack Xiao #define amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset) \ 3982bc956efSJack Xiao (ring->is_mes_queue && ring->mes_ctx ? \ 3992bc956efSJack Xiao (void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset) : \ 4002bc956efSJack Xiao NULL) 4012bc956efSJack Xiao 402c66ed765SAndrey Grodzovsky int amdgpu_ring_test_helper(struct amdgpu_ring *ring); 403c66ed765SAndrey Grodzovsky 40462d266b2SNirmoy Das void amdgpu_debugfs_ring_init(struct amdgpu_device *adev, 405fd23cfccSAlex Deucher struct amdgpu_ring *ring); 406a190f8dcSChristian König 40780af9daaSJack Xiao int amdgpu_ring_init_mqd(struct amdgpu_ring *ring); 40880af9daaSJack Xiao 409cdc7893fSChristian König static inline u32 amdgpu_ib_get_value(struct amdgpu_ib *ib, int idx) 410cdc7893fSChristian König { 411cdc7893fSChristian König return ib->ptr[idx]; 412cdc7893fSChristian König } 413cdc7893fSChristian König 414cdc7893fSChristian König static inline void amdgpu_ib_set_value(struct amdgpu_ib *ib, int idx, 415cdc7893fSChristian König uint32_t value) 416cdc7893fSChristian König { 417cdc7893fSChristian König ib->ptr[idx] = value; 418cdc7893fSChristian König } 419cdc7893fSChristian König 420a190f8dcSChristian König int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, 421a190f8dcSChristian König unsigned size, 422a190f8dcSChristian König enum amdgpu_ib_pool_type pool, 423a190f8dcSChristian König struct amdgpu_ib *ib); 424a190f8dcSChristian König void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, 425a190f8dcSChristian König struct dma_fence *f); 426a190f8dcSChristian König int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, 427a190f8dcSChristian König struct amdgpu_ib *ibs, struct amdgpu_job *job, 428a190f8dcSChristian König struct dma_fence **f); 429a190f8dcSChristian König int amdgpu_ib_pool_init(struct amdgpu_device *adev); 430a190f8dcSChristian König void amdgpu_ib_pool_fini(struct amdgpu_device *adev); 431a190f8dcSChristian König int amdgpu_ib_ring_tests(struct amdgpu_device *adev); 432a190f8dcSChristian König 43378023016SChristian König #endif 434