]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu: Add utility functions for xcp
authorLijo Lazar <lijo.lazar@amd.com>
Wed, 25 Jan 2023 14:34:52 +0000 (20:04 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 9 Jun 2023 13:56:48 +0000 (09:56 -0400)
Add utility functions to get details of xcp and iterate through
available xcps.

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Le Ma <le.ma@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 e8aa4d6c6b6214f3c739337e24669ac54f043ae5..337d558a3145affe9201871b808d0ffbdb5fac91 100644 (file)
@@ -256,3 +256,15 @@ int amdgpu_xcp_get_partition(struct amdgpu_xcp_mgr *xcp_mgr,
 
        return id_mask;
 }
+
+int amdgpu_xcp_get_inst_details(struct amdgpu_xcp *xcp,
+                               enum AMDGPU_XCP_IP_BLOCK ip,
+                               uint32_t *inst_mask)
+{
+       if (!xcp->valid || !inst_mask || !(xcp->ip[ip].valid))
+               return -EINVAL;
+
+       *inst_mask = xcp->ip[ip].inst_mask;
+
+       return 0;
+}
index 1d3dc7d68f5437b90cff8a5bab1976620363d540..45d590d7fd95dffd1587fd63a51df881d801efaa 100644 (file)
@@ -108,4 +108,35 @@ int amdgpu_xcp_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, int mode);
 int amdgpu_xcp_get_partition(struct amdgpu_xcp_mgr *xcp_mgr,
                             enum AMDGPU_XCP_IP_BLOCK ip, int instance);
 
+int amdgpu_xcp_get_inst_details(struct amdgpu_xcp *xcp,
+                               enum AMDGPU_XCP_IP_BLOCK ip,
+                               uint32_t *inst_mask);
+
+static inline int amdgpu_xcp_get_num_xcp(struct amdgpu_xcp_mgr *xcp_mgr)
+{
+       if (!xcp_mgr)
+               return 1;
+       else
+               return xcp_mgr->num_xcps;
+}
+
+static inline struct amdgpu_xcp *
+amdgpu_get_next_xcp(struct amdgpu_xcp_mgr *xcp_mgr, int *from)
+{
+       if (!xcp_mgr)
+               return NULL;
+
+       while (*from < MAX_XCP) {
+               if (xcp_mgr->xcp[*from].valid)
+                       return &xcp_mgr->xcp[*from];
+               ++(*from);
+       }
+
+       return NULL;
+}
+
+#define for_each_xcp(xcp_mgr, xcp, i)                            \
+       for (i = 0, xcp = amdgpu_get_next_xcp(xcp_mgr, &i); xcp; \
+            xcp = amdgpu_get_next_xcp(xcp_mgr, &i))
+
 #endif