]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/amdgpu: update IP count INFO query
authorSathishkumar S <sathishkumar.sundararaju@amd.com>
Wed, 13 Sep 2023 04:06:21 +0000 (09:36 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 20 Sep 2023 20:24:09 +0000 (16:24 -0400)
update the query to return the number of functional
instances where there is more than an instance of the requested
type and for others continue to return one.

v2: count must reflect the actual number of engines (Alex)
v3: fix wrong number of engines for vcn (Alex)

Signed-off-by: Sathishkumar S <sathishkumar.sundararaju@amd.com>
Reviewed-by: Leo Liu <leo.liu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

index 24d866ed5922e76a051e7d751bdffe0e61bf6cb6..01860a132c33eb0ceee15f3bb26031616486cdc2 100644 (file)
@@ -200,6 +200,44 @@ out:
        return r;
 }
 
+static enum amd_ip_block_type
+       amdgpu_ip_get_block_type(struct amdgpu_device *adev, uint32_t ip)
+{
+       enum amd_ip_block_type type;
+
+       switch (ip) {
+       case AMDGPU_HW_IP_GFX:
+               type = AMD_IP_BLOCK_TYPE_GFX;
+               break;
+       case AMDGPU_HW_IP_COMPUTE:
+               type = AMD_IP_BLOCK_TYPE_GFX;
+               break;
+       case AMDGPU_HW_IP_DMA:
+               type = AMD_IP_BLOCK_TYPE_SDMA;
+               break;
+       case AMDGPU_HW_IP_UVD:
+       case AMDGPU_HW_IP_UVD_ENC:
+               type = AMD_IP_BLOCK_TYPE_UVD;
+               break;
+       case AMDGPU_HW_IP_VCE:
+               type = AMD_IP_BLOCK_TYPE_VCE;
+               break;
+       case AMDGPU_HW_IP_VCN_DEC:
+       case AMDGPU_HW_IP_VCN_ENC:
+               type = AMD_IP_BLOCK_TYPE_VCN;
+               break;
+       case AMDGPU_HW_IP_VCN_JPEG:
+               type = (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_JPEG)) ?
+                                  AMD_IP_BLOCK_TYPE_JPEG : AMD_IP_BLOCK_TYPE_VCN;
+               break;
+       default:
+               type = AMD_IP_BLOCK_TYPE_NUM;
+               break;
+       }
+
+       return type;
+}
+
 static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
                                struct drm_amdgpu_query_fw *query_fw,
                                struct amdgpu_device *adev)
@@ -600,45 +638,39 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
        }
        case AMDGPU_INFO_HW_IP_COUNT: {
                enum amd_ip_block_type type;
+               struct amdgpu_ip_block *ip_block = NULL;
                uint32_t count = 0;
 
-               switch (info->query_hw_ip.type) {
-               case AMDGPU_HW_IP_GFX:
-                       type = AMD_IP_BLOCK_TYPE_GFX;
-                       break;
-               case AMDGPU_HW_IP_COMPUTE:
-                       type = AMD_IP_BLOCK_TYPE_GFX;
-                       break;
-               case AMDGPU_HW_IP_DMA:
-                       type = AMD_IP_BLOCK_TYPE_SDMA;
-                       break;
-               case AMDGPU_HW_IP_UVD:
-                       type = AMD_IP_BLOCK_TYPE_UVD;
+               type = amdgpu_ip_get_block_type(adev, info->query_hw_ip.type);
+               ip_block = amdgpu_device_ip_get_ip_block(adev, type);
+               if (!ip_block || !ip_block->status.valid)
+                       return -EINVAL;
+
+               switch (type) {
+               case AMD_IP_BLOCK_TYPE_GFX:
+               case AMD_IP_BLOCK_TYPE_VCE:
+                       count = 1;
                        break;
-               case AMDGPU_HW_IP_VCE:
-                       type = AMD_IP_BLOCK_TYPE_VCE;
+               case AMD_IP_BLOCK_TYPE_SDMA:
+                       count = adev->sdma.num_instances;
                        break;
-               case AMDGPU_HW_IP_UVD_ENC:
-                       type = AMD_IP_BLOCK_TYPE_UVD;
+               case AMD_IP_BLOCK_TYPE_JPEG:
+                       count = adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings;
                        break;
-               case AMDGPU_HW_IP_VCN_DEC:
-               case AMDGPU_HW_IP_VCN_ENC:
-                       type = AMD_IP_BLOCK_TYPE_VCN;
+               case AMD_IP_BLOCK_TYPE_VCN:
+                       count = adev->vcn.num_vcn_inst;
                        break;
-               case AMDGPU_HW_IP_VCN_JPEG:
-                       type = (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_JPEG)) ?
-                               AMD_IP_BLOCK_TYPE_JPEG : AMD_IP_BLOCK_TYPE_VCN;
+               case AMD_IP_BLOCK_TYPE_UVD:
+                       count = adev->uvd.num_uvd_inst;
                        break;
+               /* For all other IP block types not listed in the switch statement
+                * the ip status is valid here and the instance count is one.
+                */
                default:
-                       return -EINVAL;
+                       count = 1;
+                       break;
                }
 
-               for (i = 0; i < adev->num_ip_blocks; i++)
-                       if (adev->ip_blocks[i].version->type == type &&
-                           adev->ip_blocks[i].status.valid &&
-                           count < AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
-                               count++;
-
                return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0;
        }
        case AMDGPU_INFO_TIMESTAMP: