drm/amdgpu: Use transient mode during xcp switch
authorLijo Lazar <lijo.lazar@amd.com>
Fri, 20 Jan 2023 10:23:47 +0000 (15:53 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 9 Jun 2023 13:55:31 +0000 (09:55 -0400)
During partition switch, keep the state as transient mode. Fetch the
latest state if switch fails.

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h

index 5b999e5334bbd28acb6b006cd7788f4d2de0cafa..e8aa4d6c6b6214f3c739337e24669ac54f043ae5 100644 (file)
@@ -139,7 +139,7 @@ static int __amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps)
 
 int amdgpu_xcp_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, int mode)
 {
-       int ret, num_xcps = 0;
+       int ret, curr_mode, num_xcps = 0;
 
        if (!xcp_mgr || mode == AMDGPU_XCP_MODE_NONE)
                return -EINVAL;
@@ -152,10 +152,22 @@ int amdgpu_xcp_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, int mode)
 
        mutex_lock(&xcp_mgr->xcp_lock);
 
+       curr_mode = xcp_mgr->mode;
+       /* State set to transient mode */
+       xcp_mgr->mode = AMDGPU_XCP_MODE_TRANS;
+
        ret = xcp_mgr->funcs->switch_partition_mode(xcp_mgr, mode, &num_xcps);
 
-       if (ret)
+       if (ret) {
+               /* Failed, get whatever mode it's at now */
+               if (xcp_mgr->funcs->query_partition_mode)
+                       xcp_mgr->mode = amdgpu_xcp_query_partition_mode(
+                               xcp_mgr, AMDGPU_XCP_FL_LOCKED);
+               else
+                       xcp_mgr->mode = curr_mode;
+
                goto out;
+       }
 
        if (!num_xcps || num_xcps > MAX_XCP) {
                ret = -EINVAL;
@@ -183,7 +195,7 @@ int amdgpu_xcp_query_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, u32 flags)
        if (!(flags & AMDGPU_XCP_FL_LOCKED))
                mutex_lock(&xcp_mgr->xcp_lock);
        mode = xcp_mgr->funcs->query_partition_mode(xcp_mgr);
-       if (mode != xcp_mgr->mode)
+       if (xcp_mgr->mode != AMDGPU_XCP_MODE_TRANS && mode != xcp_mgr->mode)
                dev_WARN(
                        xcp_mgr->adev->dev,
                        "Cached partition mode %d not matching with device mode %d",
index 9fa6f0ea20612c796e01e3fbfc5ff515bd5bae44..1d3dc7d68f5437b90cff8a5bab1976620363d540 100644 (file)
@@ -29,6 +29,7 @@
 #define MAX_XCP 8
 
 #define AMDGPU_XCP_MODE_NONE -1
+#define AMDGPU_XCP_MODE_TRANS -2
 
 #define AMDGPU_XCP_FL_NONE 0
 #define AMDGPU_XCP_FL_LOCKED (1 << 0)