On 12/11/2024 4:23 AM, Alex Deucher wrote: > Add a helper to get the number of instances of an IP type. > > Signed-off-by: Alex Deucher <alexander.deucher@xxxxxxx> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 37 ++++++++++++++++++++++ > 2 files changed, 40 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > index 0ef598aac05c9..c3be17835f103 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -410,6 +410,9 @@ amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev, > int amdgpu_device_ip_block_add(struct amdgpu_device *adev, > const struct amdgpu_ip_block_version *ip_block_version); > > +int amdgpu_device_ip_get_num_inst(struct amdgpu_device *adev, > + enum amd_ip_block_type block_type); > + > /* > * BIOS. > */ > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index b5208a16d7d41..fcd8a1e8ae351 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -2371,6 +2371,43 @@ int amdgpu_device_ip_block_add(struct amdgpu_device *adev, > return 0; > } > > +/** > + * amdgpu_device_ip_get_num_inst - get number of instances > + * > + * @adev: amdgpu_device pointer > + * @block_type: Type of hardware IP (SMU, GFX, UVD, etc.) > + * > + * Returns the number of instances of the IP block type. > + */ > +int amdgpu_device_ip_get_num_inst(struct amdgpu_device *adev, > + enum amd_ip_block_type block_type) > +{ > + int i; > + Patches 43 - 48 Now respective ip blocks know about adev-><ip> and use that in one way or the other. Instead of a straight forward usage, now iterating over multiple blocks to find the same information seems a bit too much. If adev-><ip> is already abstracted, then this makes sense, but that's not the case now. Thanks, Lijo > + for (i = 0; i < adev->num_ip_blocks; i++) { > + if (!adev->ip_blocks[i].status.valid) > + continue; > + if (adev->ip_blocks[i].version->type == block_type) { > + switch (block_type) { > + case AMD_IP_BLOCK_TYPE_UVD: > + return adev->uvd.num_uvd_inst; > + case AMD_IP_BLOCK_TYPE_VCN: > + return adev->vcn.num_vcn_inst; > + case AMD_IP_BLOCK_TYPE_SDMA: > + return adev->sdma.num_instances; > + case AMD_IP_BLOCK_TYPE_JPEG: > + return adev->jpeg.num_jpeg_inst; > + case AMD_IP_BLOCK_TYPE_VPE: > + return adev->vpe.num_instances; > + default: > + return 1; > + } > + } > + } > + > + return 0; > +} > + > /** > * amdgpu_device_enable_virtual_display - enable virtual display feature > *