drm/amdgpu/gfx10: implement queue reset via MMIO
Subsystems (2)
PATCH 1/2 drm/amdgpu/gfx10: implement queue reset via MMIO
implement gfx10 kcq reset via mmio.
Signed-off-by Jesse Zhang <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 121 ++++++++++++++++++------- 1 file changed, 88 insertions(+), 33 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +88 -33
@@ -9457,6 +9457,92 @@ static void gfx_v10_ring_insert_nop(struct amdgpu_ring *ring, uint32_t num_nop)amdgpu_ring_insert_nop (ring, num_nop -1 ); } +static int gfx_v10_0_queue_reset (struct amdgpu_ring *ring,uint32_t vmid,bool use_mmio) +{ +struct amdgpu_device *adev = ring->adev; +struct amdgpu_kiq *kiq = &adev->gfx.kiq[0 ]; +struct amdgpu_ring *kiq_ring = &kiq->ring; +uint32_t queue_type = ring->funcs->type; +unsigned long flags; +int i, r =0 ; + +if (use_mmio) { +if (queue_type ==AMDGPU_RING_TYPE_COMPUTE ) { +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +mutex_lock (&adev->srbm_mutex); +nv_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); + +WREG32_SOC15 (GC ,0 , mmCP_HQD_DEQUEUE_REQUEST,0x2 ); +WREG32_SOC15 (GC ,0 , mmSPI_COMPUTE_QUEUE_RESET,0x1 ); + +nv_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + +/* Make sure dequeue is complete */ +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +mutex_lock (&adev->srbm_mutex); +nv_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); + +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , mmCP_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } + +if (i >= adev->usec_timeout) { + r = -ETIMEDOUT ; +dev_err (adev->dev,"fail to wait on hqd deactivate\n" ); + } + +nv_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + } + }else { +if (queue_type ==AMDGPU_RING_TYPE_COMPUTE ) { +spin_lock_irqsave (&kiq->ring_lock, flags); + +if (amdgpu_ring_alloc (kiq_ring, kiq->pmf->unmap_queues_size)) { +spin_unlock_irqrestore (&kiq->ring_lock, flags); +return -ENOMEM ; + } + + kiq->pmf->kiq_unmap_queues (kiq_ring, ring,RESET_QUEUES ,0 ,0 ); + +amdgpu_ring_commit (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags); + + r =amdgpu_ring_test_ring (kiq_ring); +if (r) +return r; + +/* Make sure dequeue is complete */ +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +mutex_lock (&adev->srbm_mutex); +nv_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); + +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , mmCP_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } +if (i >= adev->usec_timeout) + r = -ETIMEDOUT ; +nv_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); +if (i >= adev->usec_timeout) { + r = -ETIMEDOUT ; +dev_err (adev->dev,"fail to wait on hqd deactivate\n" ); + } + + } + } + +return r; +} +static int gfx_v10_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid) {struct amdgpu_device *adev = ring->adev;
@@ -9531,7 +9617,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,struct amdgpu_kiq *kiq = &adev->gfx.kiq[0 ];struct amdgpu_ring *kiq_ring = &kiq->ring;unsigned long flags; -int i, r; +int r;if (amdgpu_sriov_vf (adev))return -EINVAL ;
@@ -9539,41 +9625,10 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)return -EINVAL ; -spin_lock_irqsave (&kiq->ring_lock, flags); - -if (amdgpu_ring_alloc (kiq_ring, kiq->pmf->unmap_queues_size)) { -spin_unlock_irqrestore (&kiq->ring_lock, flags); -return -ENOMEM ; - } - - kiq->pmf->kiq_unmap_queues (kiq_ring, ring,RESET_QUEUES , -0 ,0 ); -amdgpu_ring_commit (kiq_ring); -spin_unlock_irqrestore (&kiq->ring_lock, flags); - - r =amdgpu_ring_test_ring (kiq_ring); + r =gfx_v10_0_queue_reset (ring, vmid, false);if (r)return r; -/* make sure dequeue is complete*/ -amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); -mutex_lock (&adev->srbm_mutex); -nv_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); -for (i =0 ; i < adev->usec_timeout; i++) { -if (!(RREG32_SOC15 (GC ,0 , mmCP_HQD_ACTIVE) &1 )) -break ; -udelay (1 ); - } -if (i >= adev->usec_timeout) - r = -ETIMEDOUT ; -nv_grbm_select (adev,0 ,0 ,0 ,0 ); -mutex_unlock (&adev->srbm_mutex); -amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); -if (r) { -dev_err (adev->dev,"fail to wait on hqd deactivate\n" ); -return r; - } - r =amdgpu_bo_reserve (ring->mqd_obj, false);if (unlikely (r !=0 )) {dev_err (adev->dev,"fail to resv mqd_obj\n" );
Signature · 1 line
2.25.1
PATCH 2/2 drm/amdgpu/gfx10: implement gfx queue reset via MMIO
implement gfx10 kgq reset via mmio.
Signed-off-by Jesse Zhang <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 98 ++++++++++++++++++-------- 1 file changed, 70 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +70 -28
@@ -9464,6 +9464,8 @@ static int gfx_v10_0_queue_reset(struct amdgpu_ring *ring, uint32_t vmid, bool ustruct amdgpu_ring *kiq_ring = &kiq->ring;uint32_t queue_type = ring->funcs->type;unsigned long flags; +uint32_t tmp; +uint64_t addr;int i, r =0 ;if (use_mmio) {
@@ -9498,6 +9500,40 @@ static int gfx_v10_0_queue_reset(struct amdgpu_ring *ring, uint32_t vmid, bool unv_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + }else if (queue_type ==AMDGPU_RING_TYPE_GFX ) { +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +mutex_lock (&adev->srbm_mutex); +nv_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); + +WREG32_SOC15 (GC ,0 , mmGRBM_GFX_INDEX, + (uint32_t )(0x1 <<GRBM_GFX_INDEX__SE_BROADCAST_WRITES__SHIFT )); + tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); +if (ring->pipe ==0 ) + tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES ,1 << ring->queue); +else + tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES ,1 << ring->queue); +WREG32_SOC15 (GC ,0 , mmCP_VMID_RESET, tmp); + + +nv_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + +mutex_lock (&adev->srbm_mutex); +nv_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +/* wait till dequeue take effects */ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , mmCP_GFX_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } +if (i >= adev->usec_timeout) { +dev_err (adev->dev,"failed to wait on gfx hqd deactivate\n" ); + r = -ETIMEDOUT ; + } + +nv_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); } }else {if (queue_type ==AMDGPU_RING_TYPE_COMPUTE ) {
@@ -9537,6 +9573,28 @@ static int gfx_v10_0_queue_reset(struct amdgpu_ring *ring, uint32_t vmid, bool udev_err (adev->dev,"fail to wait on hqd deactivate\n" ); } + }else if (queue_type ==AMDGPU_RING_TYPE_GFX ) { +if (amdgpu_ring_alloc (kiq_ring,5 +7 +7 )) { +spin_unlock_irqrestore (&kiq->ring_lock, flags); +return -ENOMEM ; + } + + addr =amdgpu_bo_gpu_offset (ring->mqd_obj) + + offsetof(struct v10_gfx_mqd , cp_gfx_hqd_active); + tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); +if (ring->pipe ==0 ) + tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES ,1 << ring->queue); +else + tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES ,1 << ring->queue); + +gfx_v10_0_ring_emit_wreg (kiq_ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), tmp); +gfx_v10_0_wait_reg_mem (kiq_ring,0 ,1 ,0 , +lower_32_bits (addr),upper_32_bits (addr), +0 ,1 ,0x20 ); +gfx_v10_0_ring_emit_reg_wait (kiq_ring, +SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ,0xffffffff ); +amdgpu_ring_commit (kiq_ring); } }
@@ -9549,8 +9607,6 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)struct amdgpu_kiq *kiq = &adev->gfx.kiq[0 ];struct amdgpu_ring *kiq_ring = &kiq->ring;unsigned long flags; -u32 tmp; -u64 addr;int r;if (amdgpu_sriov_vf (adev))
@@ -9560,35 +9616,21 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)return -EINVAL ;spin_lock_irqsave (&kiq->ring_lock, flags); +gfx_v10_0_queue_reset (ring, vmid, false); -if (amdgpu_ring_alloc (kiq_ring,5 +7 +7 + kiq->pmf->map_queues_size)) { -spin_unlock_irqrestore (&kiq->ring_lock, flags); -return -ENOMEM ; - } - - addr =amdgpu_bo_gpu_offset (ring->mqd_obj) + - offsetof(struct v10_gfx_mqd , cp_gfx_hqd_active); - tmp =REG_SET_FIELD (0 ,CP_VMID_RESET ,RESET_REQUEST ,1 << vmid); -if (ring->pipe ==0 ) - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE0_QUEUES ,1 << ring->queue); -else - tmp =REG_SET_FIELD (tmp,CP_VMID_RESET ,PIPE1_QUEUES ,1 << ring->queue); - -gfx_v10_0_ring_emit_wreg (kiq_ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET), tmp); -gfx_v10_0_wait_reg_mem (kiq_ring,0 ,1 ,0 , -lower_32_bits (addr),upper_32_bits (addr), -0 ,1 ,0x20 ); -gfx_v10_0_ring_emit_reg_wait (kiq_ring, -SOC15_REG_OFFSET (GC ,0 , mmCP_VMID_RESET),0 ,0xffffffff ); - kiq->pmf->kiq_map_queues (kiq_ring, ring); -amdgpu_ring_commit (kiq_ring); + r =amdgpu_ring_alloc (kiq_ring, kiq->pmf->map_queues_size); +if (r) { +spin_unlock_irqrestore (&kiq->ring_lock, flags); +return r; + } -spin_unlock_irqrestore (&kiq->ring_lock, flags); + kiq->pmf->kiq_map_queues (kiq_ring, ring); +amdgpu_ring_commit (kiq_ring); +spin_unlock_irqrestore (&kiq->ring_lock, flags); - r =amdgpu_ring_test_ring (kiq_ring); -if (r) -return r; + r =amdgpu_ring_test_ring (kiq_ring); +if (r) +return r; r =amdgpu_bo_reserve (ring->mqd_obj, false);if (unlikely (r !=0 )) {
Signature · 1 line
2.25.1