Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: fix ip count query for xcp partitions

fix wrong ip count INFO on spatial partitions. update the query
to return the instance count corresponding to the partition id.

v2:
initialize variables only when required to be (Christian)
move variable declarations to the beginning of function (Christian)

Signed-off-by: Sathishkumar S <sathishkumar.sundararaju@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Sathishkumar S and committed by
Alex Deucher
cbad0dd1 c207c365

+36 -8
+36 -8
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
··· 595 595 struct drm_amdgpu_info *info = data; 596 596 struct amdgpu_mode_info *minfo = &adev->mode_info; 597 597 void __user *out = (void __user *)(uintptr_t)info->return_pointer; 598 + struct amdgpu_fpriv *fpriv; 599 + struct amdgpu_ip_block *ip_block; 600 + enum amd_ip_block_type type; 601 + struct amdgpu_xcp *xcp; 602 + u32 count, inst_mask; 598 603 uint32_t size = info->return_size; 599 604 struct drm_crtc *crtc; 600 605 uint32_t ui32 = 0; 601 606 uint64_t ui64 = 0; 602 - int i, found; 607 + int i, found, ret; 603 608 int ui32_size = sizeof(ui32); 604 609 605 610 if (!info->return_size || !info->return_pointer) ··· 632 627 return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0; 633 628 case AMDGPU_INFO_HW_IP_INFO: { 634 629 struct drm_amdgpu_info_hw_ip ip = {}; 635 - int ret; 636 630 637 631 ret = amdgpu_hw_ip_info(adev, info, &ip); 638 632 if (ret) ··· 641 637 return ret ? -EFAULT : 0; 642 638 } 643 639 case AMDGPU_INFO_HW_IP_COUNT: { 644 - enum amd_ip_block_type type; 645 - struct amdgpu_ip_block *ip_block = NULL; 646 - uint32_t count = 0; 647 - 640 + fpriv = (struct amdgpu_fpriv *)filp->driver_priv; 648 641 type = amdgpu_ip_get_block_type(adev, info->query_hw_ip.type); 649 642 ip_block = amdgpu_device_ip_get_ip_block(adev, type); 643 + 650 644 if (!ip_block || !ip_block->status.valid) 651 645 return -EINVAL; 646 + 647 + if (adev->xcp_mgr && adev->xcp_mgr->num_xcps > 0 && 648 + fpriv->xcp_id >= 0 && fpriv->xcp_id < adev->xcp_mgr->num_xcps) { 649 + xcp = &adev->xcp_mgr->xcp[fpriv->xcp_id]; 650 + switch (type) { 651 + case AMD_IP_BLOCK_TYPE_GFX: 652 + ret = amdgpu_xcp_get_inst_details(xcp, AMDGPU_XCP_GFX, &inst_mask); 653 + count = hweight32(inst_mask); 654 + break; 655 + case AMD_IP_BLOCK_TYPE_SDMA: 656 + ret = amdgpu_xcp_get_inst_details(xcp, AMDGPU_XCP_SDMA, &inst_mask); 657 + count = hweight32(inst_mask); 658 + break; 659 + case AMD_IP_BLOCK_TYPE_JPEG: 660 + ret = amdgpu_xcp_get_inst_details(xcp, AMDGPU_XCP_VCN, &inst_mask); 661 + count = hweight32(inst_mask) * adev->jpeg.num_jpeg_rings; 662 + break; 663 + case AMD_IP_BLOCK_TYPE_VCN: 664 + ret = amdgpu_xcp_get_inst_details(xcp, AMDGPU_XCP_VCN, &inst_mask); 665 + count = hweight32(inst_mask); 666 + break; 667 + default: 668 + return -EINVAL; 669 + } 670 + if (ret) 671 + return ret; 672 + return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0; 673 + } 652 674 653 675 switch (type) { 654 676 case AMD_IP_BLOCK_TYPE_GFX: ··· 708 678 return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 709 679 case AMDGPU_INFO_FW_VERSION: { 710 680 struct drm_amdgpu_info_firmware fw_info; 711 - int ret; 712 681 713 682 /* We only support one instance of each IP block right now. */ 714 683 if (info->query_fw.ip_instance != 0) ··· 852 823 struct drm_amdgpu_info_device *dev_info; 853 824 uint64_t vm_size; 854 825 uint32_t pcie_gen_mask; 855 - int ret; 856 826 857 827 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); 858 828 if (!dev_info)