<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks. Will check that and fix the missing const. </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Yong</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Sent:</b> Monday, September 30, 2019 11:42 AM<br>
<b>To:</b> Zhao, Yong <Yong.Zhao@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH 4/6] drm/amdkfd: Use array to probe kfd2kgd_calls</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On 2019-09-27 11:41 p.m., Zhao, Yong wrote:<br>
> This is the same idea as the kfd device info probe and move all the<br>
> probe control together for easy maintenance.<br>
><br>
> Change-Id: I85c98bb08eb2a4a1a80c3b913c32691cc74602d1<br>
> Signed-off-by: Yong Zhao <Yong.Zhao@amd.com><br>
<br>
Nice clean-up. See one comment inline.<br>
<br>
Also, please check that this doesn't break the build if CONFIG_HSA_AMD <br>
is undefined.<br>
<br>
With that fixed and checked, this patch is<br>
<br>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com><br>
<br>
<br>
> ---<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 65 +------------------<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  7 --<br>
>   .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c   |  8 +--<br>
>   .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c    |  7 +-<br>
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c |  7 +-<br>
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c |  7 +-<br>
>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c |  7 +-<br>
>   drivers/gpu/drm/amd/amdkfd/kfd_device.c       | 39 +++++++++--<br>
>   8 files changed, 41 insertions(+), 106 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
> index 92666b197f6c..8c531793fe17 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
> @@ -63,47 +63,10 @@ void amdgpu_amdkfd_fini(void)<br>
>   <br>
>   void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev)<br>
>   {<br>
> -     const struct kfd2kgd_calls *kfd2kgd;<br>
>        bool vf = amdgpu_sriov_vf(adev);<br>
>   <br>
> -     switch (adev->asic_type) {<br>
> -#ifdef CONFIG_DRM_AMDGPU_CIK<br>
> -     case CHIP_KAVERI:<br>
> -     case CHIP_HAWAII:<br>
> -             kfd2kgd = amdgpu_amdkfd_gfx_7_get_functions();<br>
> -             break;<br>
> -#endif<br>
> -     case CHIP_CARRIZO:<br>
> -     case CHIP_TONGA:<br>
> -     case CHIP_FIJI:<br>
> -     case CHIP_POLARIS10:<br>
> -     case CHIP_POLARIS11:<br>
> -     case CHIP_POLARIS12:<br>
> -     case CHIP_VEGAM:<br>
> -             kfd2kgd = amdgpu_amdkfd_gfx_8_0_get_functions();<br>
> -             break;<br>
> -     case CHIP_VEGA10:<br>
> -     case CHIP_VEGA12:<br>
> -     case CHIP_VEGA20:<br>
> -     case CHIP_RAVEN:<br>
> -     case CHIP_RENOIR:<br>
> -             kfd2kgd = amdgpu_amdkfd_gfx_9_0_get_functions();<br>
> -             break;<br>
> -     case CHIP_ARCTURUS:<br>
> -             kfd2kgd = amdgpu_amdkfd_arcturus_get_functions();<br>
> -             break;<br>
> -     case CHIP_NAVI10:<br>
> -     case CHIP_NAVI14:<br>
> -     case CHIP_NAVI12:<br>
> -             kfd2kgd = amdgpu_amdkfd_gfx_10_0_get_functions();<br>
> -             break;<br>
> -     default:<br>
> -             dev_info(adev->dev, "kfd not supported on this ASIC\n");<br>
> -             return;<br>
> -     }<br>
> -<br>
>        adev->kfd.dev = kgd2kfd_probe((struct kgd_dev *)adev,<br>
> -                                   adev->pdev, kfd2kgd, adev->asic_type, vf);<br>
> +                                   adev->pdev, adev->asic_type, vf);<br>
>   <br>
>        if (adev->kfd.dev)<br>
>                amdgpu_amdkfd_total_mem_size += adev->gmc.real_vram_size;<br>
> @@ -711,33 +674,7 @@ int amdgpu_amdkfd_evict_userptr(struct kgd_mem *mem, struct mm_struct *mm)<br>
>        return 0;<br>
>   }<br>
>   <br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void)<br>
> -{<br>
> -     return NULL;<br>
> -}<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void)<br>
> -{<br>
> -     return NULL;<br>
> -}<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_9_0_get_functions(void)<br>
> -{<br>
> -     return NULL;<br>
> -}<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_arcturus_get_functions(void)<br>
> -{<br>
> -     return NULL;<br>
> -}<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_10_0_get_functions(void)<br>
> -{<br>
> -     return NULL;<br>
> -}<br>
> -<br>
>   struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev,<br>
> -                           const struct kfd2kgd_calls *f2g,<br>
>                              unsigned int asic_type, bool vf)<br>
>   {<br>
>        return NULL;<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h<br>
> index 4eb2fb85de26..069d5d230810 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h<br>
> @@ -137,12 +137,6 @@ int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_type engine,<br>
>   void amdgpu_amdkfd_set_compute_idle(struct kgd_dev *kgd, bool idle);<br>
>   bool amdgpu_amdkfd_have_atomics_support(struct kgd_dev *kgd);<br>
>   <br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void);<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void);<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_9_0_get_functions(void);<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_arcturus_get_functions(void);<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_10_0_get_functions(void);<br>
> -<br>
>   bool amdgpu_amdkfd_is_kfd_vmid(struct amdgpu_device *adev, u32 vmid);<br>
>   <br>
>   int amdgpu_amdkfd_pre_reset(struct amdgpu_device *adev);<br>
> @@ -248,7 +242,6 @@ void amdgpu_amdkfd_unreserve_memory_limit(struct amdgpu_bo *bo);<br>
>   int kgd2kfd_init(void);<br>
>   void kgd2kfd_exit(void);<br>
>   struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev,<br>
> -                           const struct kfd2kgd_calls *f2g,<br>
>                              unsigned int asic_type, bool vf);<br>
>   bool kgd2kfd_device_init(struct kfd_dev *kfd,<br>
>                         struct drm_device *ddev,<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c<br>
> index 4a49dbee26a1..e1fbbebce4fd 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c<br>
> @@ -262,7 +262,7 @@ static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd,<br>
>        return 0;<br>
>   }<br>
>   <br>
> -static const struct kfd2kgd_calls kfd2kgd = {<br>
> +const struct kfd2kgd_calls arcturus_kfd2kgd = {<br>
>        .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,<br>
>        .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,<br>
>        .init_interrupts = kgd_gfx_v9_init_interrupts,<br>
> @@ -286,9 +286,3 @@ static const struct kfd2kgd_calls kfd2kgd = {<br>
>        .invalidate_tlbs_vmid = kgd_gfx_v9_invalidate_tlbs_vmid,<br>
>        .get_hive_id = amdgpu_amdkfd_get_hive_id,<br>
>   };<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_arcturus_get_functions(void)<br>
> -{<br>
> -     return (struct kfd2kgd_calls *)&kfd2kgd;<br>
> -}<br>
> -<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c<br>
> index be9b873ec683..a01704bc91cd 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c<br>
> @@ -815,7 +815,7 @@ static void set_vm_context_page_table_base(struct kgd_dev *kgd, uint32_t vmid,<br>
>        gfxhub_v2_0_setup_vm_pt_regs(adev, vmid, page_table_base);<br>
>   }<br>
>   <br>
> -static const struct kfd2kgd_calls kfd2kgd = {<br>
> +struct kfd2kgd_calls gfx_v10_kfd2kgd = {<br>
<br>
This should be const. Can you fix that too while you're here?<br>
<br>
<br>
>        .program_sh_mem_settings = kgd_program_sh_mem_settings,<br>
>        .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,<br>
>        .init_interrupts = kgd_init_interrupts,<br>
> @@ -839,8 +839,3 @@ static const struct kfd2kgd_calls kfd2kgd = {<br>
>        .invalidate_tlbs_vmid = invalidate_tlbs_vmid,<br>
>        .get_hive_id = amdgpu_amdkfd_get_hive_id,<br>
>   };<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_10_0_get_functions()<br>
> -{<br>
> -     return (struct kfd2kgd_calls *)&kfd2kgd;<br>
> -}<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c<br>
> index 9c4ebcadad62..0b9cc6515e64 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c<br>
> @@ -751,7 +751,7 @@ static uint32_t read_vmid_from_vmfault_reg(struct kgd_dev *kgd)<br>
>        return REG_GET_FIELD(status, VM_CONTEXT1_PROTECTION_FAULT_STATUS, VMID);<br>
>   }<br>
>   <br>
> -static const struct kfd2kgd_calls kfd2kgd = {<br>
> +const struct kfd2kgd_calls gfx_v7_kfd2kgd = {<br>
>        .program_sh_mem_settings = kgd_program_sh_mem_settings,<br>
>        .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,<br>
>        .init_interrupts = kgd_init_interrupts,<br>
> @@ -775,8 +775,3 @@ static const struct kfd2kgd_calls kfd2kgd = {<br>
>        .invalidate_tlbs_vmid = invalidate_tlbs_vmid,<br>
>        .read_vmid_from_vmfault_reg = read_vmid_from_vmfault_reg,<br>
>   };<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void)<br>
> -{<br>
> -     return (struct kfd2kgd_calls *)&kfd2kgd;<br>
> -}<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c<br>
> index f2e52b496044..3416a7f27dc7 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c<br>
> @@ -696,7 +696,7 @@ static int invalidate_tlbs_vmid(struct kgd_dev *kgd, uint16_t vmid)<br>
>        return 0;<br>
>   }<br>
>   <br>
> -static const struct kfd2kgd_calls kfd2kgd = {<br>
> +const struct kfd2kgd_calls gfx_v8_kfd2kgd = {<br>
>        .program_sh_mem_settings = kgd_program_sh_mem_settings,<br>
>        .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,<br>
>        .init_interrupts = kgd_init_interrupts,<br>
> @@ -720,8 +720,3 @@ static const struct kfd2kgd_calls kfd2kgd = {<br>
>        .invalidate_tlbs = invalidate_tlbs,<br>
>        .invalidate_tlbs_vmid = invalidate_tlbs_vmid,<br>
>   };<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void)<br>
> -{<br>
> -     return (struct kfd2kgd_calls *)&kfd2kgd;<br>
> -}<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c<br>
> index 12f30df2174c..82ed9316b096 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c<br>
> @@ -786,7 +786,7 @@ void kgd_gfx_v9_set_vm_context_page_table_base(struct kgd_dev *kgd, uint32_t vmi<br>
>        gfxhub_v1_0_setup_vm_pt_regs(adev, vmid, page_table_base);<br>
>   }<br>
>   <br>
> -static const struct kfd2kgd_calls kfd2kgd = {<br>
> +const struct kfd2kgd_calls gfx_v9_kfd2kgd = {<br>
>        .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,<br>
>        .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,<br>
>        .init_interrupts = kgd_gfx_v9_init_interrupts,<br>
> @@ -810,8 +810,3 @@ static const struct kfd2kgd_calls kfd2kgd = {<br>
>        .invalidate_tlbs_vmid = kgd_gfx_v9_invalidate_tlbs_vmid,<br>
>        .get_hive_id = amdgpu_amdkfd_get_hive_id,<br>
>   };<br>
> -<br>
> -struct kfd2kgd_calls *amdgpu_amdkfd_gfx_9_0_get_functions(void)<br>
> -{<br>
> -     return (struct kfd2kgd_calls *)&kfd2kgd;<br>
> -}<br>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c<br>
> index 96a9e0653db2..0db273587af4 100644<br>
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c<br>
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c<br>
> @@ -39,6 +39,35 @@<br>
>    */<br>
>   static atomic_t kfd_locked = ATOMIC_INIT(0);<br>
>   <br>
> +extern const struct kfd2kgd_calls gfx_v7_kfd2kgd;<br>
> +extern const struct kfd2kgd_calls gfx_v8_kfd2kgd;<br>
> +extern const struct kfd2kgd_calls gfx_v9_kfd2kgd;<br>
> +extern const struct kfd2kgd_calls arcturus_kfd2kgd;<br>
> +extern const struct kfd2kgd_calls gfx_v10_kfd2kgd;<br>
> +<br>
> +static const struct kfd2kgd_calls *kfd2kgd_funcs[] = {<br>
> +#ifdef KFD_SUPPORT_IOMMU_V2<br>
> +     [CHIP_KAVERI] = &gfx_v7_kfd2kgd,<br>
> +     [CHIP_CARRIZO] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_RAVEN] = &gfx_v9_kfd2kgd,<br>
> +#endif<br>
> +     [CHIP_HAWAII] = &gfx_v7_kfd2kgd,<br>
> +     [CHIP_TONGA] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_FIJI] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_POLARIS10] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_POLARIS11] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_POLARIS12] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_VEGAM] = &gfx_v8_kfd2kgd,<br>
> +     [CHIP_VEGA10] = &gfx_v9_kfd2kgd,<br>
> +     [CHIP_VEGA12] = &gfx_v9_kfd2kgd,<br>
> +     [CHIP_VEGA20] = &gfx_v9_kfd2kgd,<br>
> +     [CHIP_RENOIR] = &gfx_v9_kfd2kgd,<br>
> +     [CHIP_ARCTURUS] = &arcturus_kfd2kgd,<br>
> +     [CHIP_NAVI10] = &gfx_v10_kfd2kgd,<br>
> +     [CHIP_NAVI12] = &gfx_v10_kfd2kgd,<br>
> +     [CHIP_NAVI14] = &gfx_v10_kfd2kgd,<br>
> +};<br>
> +<br>
>   #ifdef KFD_SUPPORT_IOMMU_V2<br>
>   static const struct kfd_device_info kaveri_device_info = {<br>
>        .asic_family = CHIP_KAVERI,<br>
> @@ -454,20 +483,22 @@ static void kfd_gtt_sa_fini(struct kfd_dev *kfd);<br>
>   static int kfd_resume(struct kfd_dev *kfd);<br>
>   <br>
>   struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd,<br>
> -     struct pci_dev *pdev, const struct kfd2kgd_calls *f2g,<br>
> -     unsigned int asic_type, bool vf)<br>
> +     struct pci_dev *pdev, unsigned int asic_type, bool vf)<br>
>   {<br>
>        struct kfd_dev *kfd;<br>
>        const struct kfd_device_info *device_info;<br>
> +     const struct kfd2kgd_calls *f2g;<br>
>   <br>
> -     if (asic_type >= sizeof(kfd_supported_devices) / (sizeof(void *) * 2)) {<br>
> +     if (asic_type >= sizeof(kfd_supported_devices) / (sizeof(void *) * 2)<br>
> +             || asic_type >= sizeof(kfd2kgd_funcs) / sizeof(void *)) {<br>
>                dev_err(kfd_device, "asic_type %d out of range\n", asic_type);<br>
>                return NULL; /* asic_type out of range */<br>
>        }<br>
>   <br>
>        device_info = kfd_supported_devices[asic_type][vf];<br>
> +     f2g = kfd2kgd_funcs[asic_type];<br>
>   <br>
> -     if (!device_info) {<br>
> +     if (!device_info && !f2g) {<br>
>                dev_err(kfd_device, "%s %s not supported in kfd\n",<br>
>                        amdgpu_asic_name[asic_type], vf ? "VF" : "");<br>
>                return NULL;<br>
</div>
</span></font></div>
</body>
</html>