Skip to content

Commit 4c953e5

Browse files
jiadozhualexdeucher
authored andcommitted
drm/amdgpu/gfx_9.4.3: wait for reset done before remap
There is a racing condition that cp firmware modifies MQD in reset sequence after driver updates it for remapping. We have to wait till CP_HQD_ACTIVE becoming false then remap the queue. v2: fix KIQ locking (Alex) v3: fix KIQ locking harder Acked-by: Vitaly Prosyak <vitaly.prosyak@amd.com> Signed-off-by: Jiadong Zhu <Jiadong.Zhu@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 6f38589 commit 4c953e5

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,7 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring,
34333433
struct amdgpu_kiq *kiq = &adev->gfx.kiq[ring->xcc_id];
34343434
struct amdgpu_ring *kiq_ring = &kiq->ring;
34353435
unsigned long flags;
3436-
int r;
3436+
int r, i;
34373437

34383438
if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
34393439
return -EINVAL;
@@ -3455,9 +3455,28 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring,
34553455
if (r)
34563456
return r;
34573457

3458+
/* make sure dequeue is complete*/
3459+
gfx_v9_4_3_xcc_set_safe_mode(adev, ring->xcc_id);
3460+
mutex_lock(&adev->srbm_mutex);
3461+
soc15_grbm_select(adev, ring->me, ring->pipe, ring->queue, 0, GET_INST(GC, ring->xcc_id));
3462+
for (i = 0; i < adev->usec_timeout; i++) {
3463+
if (!(RREG32_SOC15(GC, 0, regCP_HQD_ACTIVE) & 1))
3464+
break;
3465+
udelay(1);
3466+
}
3467+
if (i >= adev->usec_timeout)
3468+
r = -ETIMEDOUT;
3469+
soc15_grbm_select(adev, 0, 0, 0, 0, GET_INST(GC, ring->xcc_id));
3470+
mutex_unlock(&adev->srbm_mutex);
3471+
gfx_v9_4_3_xcc_unset_safe_mode(adev, ring->xcc_id);
3472+
if (r) {
3473+
dev_err(adev->dev, "fail to wait on hqd deactive\n");
3474+
return r;
3475+
}
3476+
34583477
r = amdgpu_bo_reserve(ring->mqd_obj, false);
34593478
if (unlikely(r != 0)){
3460-
DRM_ERROR("fail to resv mqd_obj\n");
3479+
dev_err(adev->dev, "fail to resv mqd_obj\n");
34613480
return r;
34623481
}
34633482
r = amdgpu_bo_kmap(ring->mqd_obj, (void **)&ring->mqd_ptr);
@@ -3467,15 +3486,23 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring,
34673486
ring->mqd_ptr = NULL;
34683487
}
34693488
amdgpu_bo_unreserve(ring->mqd_obj);
3470-
if (r){
3471-
DRM_ERROR("fail to unresv mqd_obj\n");
3489+
if (r) {
3490+
dev_err(adev->dev, "fail to unresv mqd_obj\n");
34723491
return r;
34733492
}
3493+
spin_lock_irqsave(&kiq->ring_lock, flags);
34743494
r = amdgpu_ring_alloc(kiq_ring, kiq->pmf->map_queues_size);
3495+
if (r) {
3496+
spin_unlock_irqrestore(&kiq->ring_lock, flags);
3497+
return -ENOMEM;
3498+
}
34753499
kiq->pmf->kiq_map_queues(kiq_ring, ring);
3500+
amdgpu_ring_commit(kiq_ring);
3501+
spin_unlock_irqrestore(&kiq->ring_lock, flags);
3502+
34763503
r = amdgpu_ring_test_ring(kiq_ring);
3477-
if (r){
3478-
DRM_ERROR("fail to remap queue\n");
3504+
if (r) {
3505+
dev_err(adev->dev, "fail to remap queue\n");
34793506
return r;
34803507
}
34813508
return amdgpu_ring_test_ring(ring);

0 commit comments

Comments
 (0)