drm/amdgpu/gfx11: add a mutex for the gfx semaphore
authorAlex Deucher <alexander.deucher@amd.com>
Fri, 12 Jul 2024 20:37:33 +0000 (16:37 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 16 Aug 2024 18:24:33 +0000 (14:24 -0400)
This will be used in more places in the future so
add a mutex.

Acked-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c

index a6b8d0ba4758c8dbf3847fda9c7b90527e54f59c..482db4ebcc4ba0702ea3a273689e620ed182ac71 100644 (file)
@@ -4059,6 +4059,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
        mutex_init(&adev->notifier_lock);
        mutex_init(&adev->pm.stable_pstate_ctx_lock);
        mutex_init(&adev->benchmark_mutex);
+       mutex_init(&adev->gfx.reset_sem_mutex);
 
        amdgpu_device_init_apu_flags(adev);
 
index 6fe77e483bb7f4efaac251fc91961800c58d0426..17b945b545b451c110193d3874e77284276a7f02 100644 (file)
@@ -444,6 +444,8 @@ struct amdgpu_gfx {
        uint32_t                        *ip_dump_core;
        uint32_t                        *ip_dump_compute_queues;
        uint32_t                        *ip_dump_gfx_queues;
+
+       struct mutex                    reset_sem_mutex;
 };
 
 struct amdgpu_gfx_ras_reg_entry {
index 98261000e0220cde711a98c963552552dbbd4a05..01f220ee4561896477af74acee563afe13a58fd7 100644 (file)
@@ -4743,10 +4743,12 @@ static int gfx_v11_0_wait_for_idle(void *handle)
 }
 
 static int gfx_v11_0_request_gfx_index_mutex(struct amdgpu_device *adev,
-                                            int req)
+                                            bool req)
 {
        u32 i, tmp, val;
 
+       if (req)
+               mutex_lock(&adev->gfx.reset_sem_mutex);
        for (i = 0; i < adev->usec_timeout; i++) {
                /* Request with MeId=2, PipeId=0 */
                tmp = REG_SET_FIELD(0, CP_GFX_INDEX_MUTEX, REQUEST, req);
@@ -4767,6 +4769,8 @@ static int gfx_v11_0_request_gfx_index_mutex(struct amdgpu_device *adev,
                }
                udelay(1);
        }
+       if (!req)
+               mutex_unlock(&adev->gfx.reset_sem_mutex);
 
        if (i >= adev->usec_timeout)
                return -EINVAL;
@@ -4814,7 +4818,7 @@ static int gfx_v11_0_soft_reset(void *handle)
        mutex_unlock(&adev->srbm_mutex);
 
        /* Try to acquire the gfx mutex before access to CP_VMID_RESET */
-       r = gfx_v11_0_request_gfx_index_mutex(adev, 1);
+       r = gfx_v11_0_request_gfx_index_mutex(adev, true);
        if (r) {
                DRM_ERROR("Failed to acquire the gfx mutex during soft reset\n");
                return r;
@@ -4829,7 +4833,7 @@ static int gfx_v11_0_soft_reset(void *handle)
        RREG32_SOC15(GC, 0, regCP_VMID_RESET);
 
        /* release the gfx mutex */
-       r = gfx_v11_0_request_gfx_index_mutex(adev, 0);
+       r = gfx_v11_0_request_gfx_index_mutex(adev, false);
        if (r) {
                DRM_ERROR("Failed to release the gfx mutex during soft reset\n");
                return r;