On Wed, Oct 2, 2024 at 12:39 AM <boyuan.zhang@xxxxxxx> wrote: > > From: Boyuan Zhang <boyuan.zhang@xxxxxxx> > > Add instance number to ip block to track which instance the ip block > belongs to. > > Also, add a new function to allow ip block to save the instance number > along with other ip block driver information. > > Signed-off-by: Boyuan Zhang <boyuan.zhang@xxxxxxx> I think the logic can be added to the existing amdgpu_device_ip_block_add(). Something like the attached patch. Alex > --- > drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 +++ > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 ++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > index 84a9749dcd7d..d77db73c71f7 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -386,6 +386,7 @@ struct amdgpu_ip_block { > struct amdgpu_ip_block_status status; > const struct amdgpu_ip_block_version *version; > struct amdgpu_device *adev; > + unsigned int instance; > }; > > int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev, > @@ -399,6 +400,10 @@ 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_block_add_instance(struct amdgpu_device *adev, > + const struct amdgpu_ip_block_version *ip_block_version, > + unsigned int inst); > + > /* > * BIOS. > */ > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index 263f25ac2d63..4bc109a0d832 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -2321,6 +2321,45 @@ int amdgpu_device_ip_block_add(struct amdgpu_device *adev, > return 0; > } > > +/** > + * amdgpu_device_ip_block_add_instance > + * > + * @adev: amdgpu_device pointer > + * @ip_block_version: pointer to the IP to add > + * > + * Adds the IP block driver information and instance number > + * to the collection of IPs on the asic. > + */ > +int amdgpu_device_ip_block_add_instance(struct amdgpu_device *adev, > + const struct amdgpu_ip_block_version *ip_block_version, > + unsigned int inst) > +{ > + if (!ip_block_version) > + return -EINVAL; > + > + switch (ip_block_version->type) { > + case AMD_IP_BLOCK_TYPE_VCN: > + if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK) > + return 0; > + break; > + case AMD_IP_BLOCK_TYPE_JPEG: > + if (adev->harvest_ip_mask & AMD_HARVEST_IP_JPEG_MASK) > + return 0; > + break; > + default: > + break; > + } > + > + DRM_INFO("add ip block number %d <%s>\n", adev->num_ip_blocks, > + ip_block_version->funcs->name); > + > + adev->ip_blocks[adev->num_ip_blocks].adev = adev; > + adev->ip_blocks[adev->num_ip_blocks].instance = inst; > + adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version; > + > + return 0; > +} > + > /** > * amdgpu_device_enable_virtual_display - enable virtual display feature > * > -- > 2.34.1 >
From ee638fc028584f0c8f567b65fdd5e47df48ad90c Mon Sep 17 00:00:00 2001 From: Alex Deucher <alexander.deucher@xxxxxxx> Date: Wed, 2 Oct 2024 13:30:31 -0400 Subject: [PATCH] drm/amdgpu: track instances of the same IP block When we add a new IP block track the instances of the block if there are multiple blocks of the same type. Signed-off-by: Alex Deucher <alexander.deucher@xxxxxxx> --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index abddc20d573e..ff7704266422 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -385,6 +385,7 @@ struct amdgpu_ip_block_version { struct amdgpu_ip_block { struct amdgpu_ip_block_status status; const struct amdgpu_ip_block_version *version; + unsigned int instance; struct amdgpu_device *adev; }; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index f7209683dd5c..d31525d26727 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -2283,6 +2283,27 @@ int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev, return 1; } +/** + * amdgpu_device_ip_get_num_instances - get number of instances of an IP block + * + * @adev: amdgpu_device pointer + * @type: Type of hardware IP (SMU, GFX, UVD, etc.) + * + * Returns the count of the hardware IP blocks structure for that type. + */ +static unsigned int +amdgpu_device_ip_get_num_instances(struct amdgpu_device *adev, + enum amd_ip_block_type type) +{ + unsigned int i, count = 0; + + for (i = 0; i < adev->num_ip_blocks; i++) + if (adev->ip_blocks[i].version->type == type) + count++; + + return count; +} + /** * amdgpu_device_ip_block_add * @@ -2315,7 +2336,8 @@ int amdgpu_device_ip_block_add(struct amdgpu_device *adev, ip_block_version->funcs->name); adev->ip_blocks[adev->num_ip_blocks].adev = adev; - + adev->ip_blocks[adev->num_ip_blocks].instance = + amdgpu_device_ip_get_num_instances(adev, ip_block_version->type); adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version; return 0; -- 2.46.2