[PATCH 43/48] drm/amdgpu: add a helper to get the number of instances

Alex Deucher alexdeucher at gmail.com
Wed Dec 11 17:32:44 UTC 2024


On Wed, Dec 11, 2024 at 2:10 AM Lazar, Lijo <lijo.lazar at amd.com> wrote:
>
>
>
> 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 at amd.com>
> > ---
> >  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.

These last few patches were more of a proof of concept to hide the IP
specific details from other IPs and core code.  I agree that we can
probably skip the iteration in this function for now since it's not
necessary and add it later if we do split instances to IP blocks.

Thanks,

Alex

>
> 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
> >   *
>


More information about the amd-gfx mailing list