[PATCH v2 3/4] drm/amdkfd: move to dynamic device_info creation
Felix Kuehling
felix.kuehling at amd.com
Fri Nov 19 21:30:20 UTC 2021
On 2021-11-19 2:52 p.m., Graham Sider wrote:
> Change unsupported asic condition to only probe f2g, move device_info
> initialization post-switch and map to heap.
>
> Signed-off-by: Graham Sider <Graham.Sider at amd.com>
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_device.c | 183 ++++++++++--------------
> drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +-
> 2 files changed, 79 insertions(+), 106 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> index 676cb9c3166c..7ddea653b3d9 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
> @@ -574,191 +574,151 @@ static void kfd_device_info_init(struct kfd_dev *kfd,
>
> struct kfd_dev *kgd2kfd_probe(struct amdgpu_device *adev, bool vf)
> {
> - struct kfd_dev *kfd;
> - const struct kfd_device_info *device_info;
> - const struct kfd2kgd_calls *f2g;
> + struct kfd_dev *kfd = NULL;
> + struct kfd_device_info *device_info = NULL;
> + const struct kfd2kgd_calls *f2g = NULL;
> struct pci_dev *pdev = adev->pdev;
> + uint32_t gfx_target_version = 0;
>
> switch (adev->asic_type) {
> #ifdef KFD_SUPPORT_IOMMU_V2
> #ifdef CONFIG_DRM_AMDGPU_CIK
> case CHIP_KAVERI:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &kaveri_device_info;
> - f2g = &gfx_v7_kfd2kgd;
> + gfx_target_version = 70000;
> + if (!vf)
> + f2g = &gfx_v7_kfd2kgd;
> break;
> #endif
> case CHIP_CARRIZO:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &carrizo_device_info;
> - f2g = &gfx_v8_kfd2kgd;
> + gfx_target_version = 80001;
> + if (!vf)
> + f2g = &gfx_v8_kfd2kgd;
> break;
> #endif
> #ifdef CONFIG_DRM_AMDGPU_CIK
> case CHIP_HAWAII:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &hawaii_device_info;
> - f2g = &gfx_v7_kfd2kgd;
> + gfx_target_version = 70001;
> + if (!vf)
> + f2g = &gfx_v7_kfd2kgd;
> break;
> #endif
> case CHIP_TONGA:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &tonga_device_info;
> - f2g = &gfx_v8_kfd2kgd;
> + gfx_target_version = 80002;
> + if (!vf)
> + f2g = &gfx_v8_kfd2kgd;
> break;
> case CHIP_FIJI:
> - if (vf)
> - device_info = &fiji_vf_device_info;
> - else
> - device_info = &fiji_device_info;
> + gfx_target_version = 80003;
> f2g = &gfx_v8_kfd2kgd;
> break;
> case CHIP_POLARIS10:
> - if (vf)
> - device_info = &polaris10_vf_device_info;
> - else
> - device_info = &polaris10_device_info;
> + gfx_target_version = 80003;
> f2g = &gfx_v8_kfd2kgd;
> break;
> case CHIP_POLARIS11:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &polaris11_device_info;
> - f2g = &gfx_v8_kfd2kgd;
> + gfx_target_version = 80003;
> + if (!vf)
> + f2g = &gfx_v8_kfd2kgd;
> break;
> case CHIP_POLARIS12:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &polaris12_device_info;
> - f2g = &gfx_v8_kfd2kgd;
> + gfx_target_version = 80003;
> + if (!vf)
> + f2g = &gfx_v8_kfd2kgd;
> break;
> case CHIP_VEGAM:
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &vegam_device_info;
> - f2g = &gfx_v8_kfd2kgd;
> + gfx_target_version = 80003;
> + if (!vf)
> + f2g = &gfx_v8_kfd2kgd;
> break;
> default:
> switch (adev->ip_versions[GC_HWIP][0]) {
> case IP_VERSION(9, 0, 1):
> - if (vf)
> - device_info = &vega10_vf_device_info;
> - else
> - device_info = &vega10_device_info;
> + gfx_target_version = 90000;
> f2g = &gfx_v9_kfd2kgd;
> break;
> #ifdef KFD_SUPPORT_IOMMU_V2
> case IP_VERSION(9, 1, 0):
> case IP_VERSION(9, 2, 2):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &raven_device_info;
> - f2g = &gfx_v9_kfd2kgd;
> + gfx_target_version = 90002;
> + if (!vf)
> + f2g = &gfx_v9_kfd2kgd;
> break;
> #endif
> case IP_VERSION(9, 2, 1):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &vega12_device_info;
> - f2g = &gfx_v9_kfd2kgd;
> + gfx_target_version = 90004;
> + if (!vf)
> + f2g = &gfx_v9_kfd2kgd;
> break;
> case IP_VERSION(9, 3, 0):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &renoir_device_info;
> - f2g = &gfx_v9_kfd2kgd;
> + gfx_target_version = 90012;
> + if (!vf)
> + f2g = &gfx_v9_kfd2kgd;
> break;
> case IP_VERSION(9, 4, 0):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &vega20_device_info;
> - f2g = &gfx_v9_kfd2kgd;
> + gfx_target_version = 90006;
> + if (!vf)
> + f2g = &gfx_v9_kfd2kgd;
> break;
> case IP_VERSION(9, 4, 1):
> - device_info = &arcturus_device_info;
> + gfx_target_version = 90008;
> f2g = &arcturus_kfd2kgd;
> break;
> case IP_VERSION(9, 4, 2):
> - device_info = &aldebaran_device_info;
> + gfx_target_version = 90010;
> f2g = &aldebaran_kfd2kgd;
> break;
> case IP_VERSION(10, 1, 10):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &navi10_device_info;
> - f2g = &gfx_v10_kfd2kgd;
> + gfx_target_version = 100100;
> + if (!vf)
> + f2g = &gfx_v10_kfd2kgd;
> break;
> case IP_VERSION(10, 1, 2):
> - device_info = &navi12_device_info;
> + gfx_target_version = 100101;
> f2g = &gfx_v10_kfd2kgd;
> break;
> case IP_VERSION(10, 1, 1):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &navi14_device_info;
> - f2g = &gfx_v10_kfd2kgd;
> + gfx_target_version = 100102;
> + if (!vf)
> + f2g = &gfx_v10_kfd2kgd;
> break;
> case IP_VERSION(10, 1, 3):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &cyan_skillfish_device_info;
> - f2g = &gfx_v10_kfd2kgd;
> + gfx_target_version = 100103;
> + if (!vf)
> + f2g = &gfx_v10_kfd2kgd;
> break;
> case IP_VERSION(10, 3, 0):
> - device_info = &sienna_cichlid_device_info;
> + gfx_target_version = 100300;
> f2g = &gfx_v10_3_kfd2kgd;
> break;
> case IP_VERSION(10, 3, 2):
> - device_info = &navy_flounder_device_info;
> + gfx_target_version = 100301;
> f2g = &gfx_v10_3_kfd2kgd;
> break;
> case IP_VERSION(10, 3, 1):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &vangogh_device_info;
> - f2g = &gfx_v10_3_kfd2kgd;
> + gfx_target_version = 100303;
> + if (!vf)
> + f2g = &gfx_v10_3_kfd2kgd;
> break;
> case IP_VERSION(10, 3, 4):
> - device_info = &dimgrey_cavefish_device_info;
> + gfx_target_version = 100302;
> f2g = &gfx_v10_3_kfd2kgd;
> break;
> case IP_VERSION(10, 3, 5):
> - device_info = &beige_goby_device_info;
> + gfx_target_version = 100304;
> f2g = &gfx_v10_3_kfd2kgd;
> break;
> case IP_VERSION(10, 3, 3):
> - if (vf)
> - device_info = NULL;
> - else
> - device_info = &yellow_carp_device_info;
> - f2g = &gfx_v10_3_kfd2kgd;
> + gfx_target_version = 100305;
> + if (!vf)
> + f2g = &gfx_v10_3_kfd2kgd;
> break;
> default:
> - return NULL;
> + break;
> }
> break;
> }
>
> - if (!device_info || !f2g) {
> + if (!f2g) {
> if (adev->ip_versions[GC_HWIP][0])
> dev_err(kfd_device, "GC IP %06x %s not supported in kfd\n",
> adev->ip_versions[GC_HWIP][0], vf ? "VF" : "");
> @@ -773,7 +733,14 @@ struct kfd_dev *kgd2kfd_probe(struct amdgpu_device *adev, bool vf)
> return NULL;
>
> kfd->adev = adev;
> +
> + device_info = kzalloc(sizeof(*device_info), GFP_KERNEL);
Just thinking out loud, no need to change this: Maybe device_info
doesn't need to be dynamically allocated. It could just be a member of
struct kfd_dev. Except that it would result in a bunch of cosmetic
changes s/device_info->/device_info./g.
> + if (!device_info)
> + return NULL;
> +
> + kfd_device_info_init(kfd, device_info, vf, gfx_target_version);
> kfd->device_info = device_info;
> +
> kfd->pdev = pdev;
> kfd->init_complete = false;
> kfd->kfd2kgd = f2g;
> @@ -1039,7 +1006,13 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)
> amdgpu_amdkfd_free_gws(kfd->adev, kfd->gws);
> }
>
> - kfree(kfd);
> + if (kfd->device_info)
> + kfree(kfd->device_info);
NULL-checks are unnecessary before kfree.
> + kfd->device_info = NULL;
This is unnecessary because you're about to free kfd anyway.
> +
> + if (kfd)
> + kfree(kfd);
Same as above.
Regards,
Felix
> + kfd = NULL;
> }
>
> int kgd2kfd_pre_reset(struct kfd_dev *kfd)
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index 3e11febee7c6..1f11e8271f2e 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -232,7 +232,7 @@ struct kfd_vmid_info {
> struct kfd_dev {
> struct amdgpu_device *adev;
>
> - const struct kfd_device_info *device_info;
> + struct kfd_device_info *device_info;
> struct pci_dev *pdev;
> struct drm_device *ddev;
>
More information about the amd-gfx
mailing list