drm/amdkfd: Use array to probe kfd2kgd_calls
authorYong Zhao <Yong.Zhao@amd.com>
Sat, 28 Sep 2019 02:03:42 +0000 (22:03 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 3 Oct 2019 14:11:05 +0000 (09:11 -0500)
This is the same idea as the kfd device info probe and move all the
probe control together for easy maintenance.

Signed-off-by: Yong Zhao <Yong.Zhao@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
drivers/gpu/drm/amd/amdkfd/kfd_device.c

index 92666b1..8c53179 100644 (file)
@@ -63,47 +63,10 @@ void amdgpu_amdkfd_fini(void)
 
 void amdgpu_amdkfd_device_probe(struct amdgpu_device *adev)
 {
-       const struct kfd2kgd_calls *kfd2kgd;
        bool vf = amdgpu_sriov_vf(adev);
 
-       switch (adev->asic_type) {
-#ifdef CONFIG_DRM_AMDGPU_CIK
-       case CHIP_KAVERI:
-       case CHIP_HAWAII:
-               kfd2kgd = amdgpu_amdkfd_gfx_7_get_functions();
-               break;
-#endif
-       case CHIP_CARRIZO:
-       case CHIP_TONGA:
-       case CHIP_FIJI:
-       case CHIP_POLARIS10:
-       case CHIP_POLARIS11:
-       case CHIP_POLARIS12:
-       case CHIP_VEGAM:
-               kfd2kgd = amdgpu_amdkfd_gfx_8_0_get_functions();
-               break;
-       case CHIP_VEGA10:
-       case CHIP_VEGA12:
-       case CHIP_VEGA20:
-       case CHIP_RAVEN:
-       case CHIP_RENOIR:
-               kfd2kgd = amdgpu_amdkfd_gfx_9_0_get_functions();
-               break;
-       case CHIP_ARCTURUS:
-               kfd2kgd = amdgpu_amdkfd_arcturus_get_functions();
-               break;
-       case CHIP_NAVI10:
-       case CHIP_NAVI14:
-       case CHIP_NAVI12:
-               kfd2kgd = amdgpu_amdkfd_gfx_10_0_get_functions();
-               break;
-       default:
-               dev_info(adev->dev, "kfd not supported on this ASIC\n");
-               return;
-       }
-
        adev->kfd.dev = kgd2kfd_probe((struct kgd_dev *)adev,
-                                     adev->pdev, kfd2kgd, adev->asic_type, vf);
+                                     adev->pdev, adev->asic_type, vf);
 
        if (adev->kfd.dev)
                amdgpu_amdkfd_total_mem_size += adev->gmc.real_vram_size;
@@ -711,33 +674,7 @@ int amdgpu_amdkfd_evict_userptr(struct kgd_mem *mem, struct mm_struct *mm)
        return 0;
 }
 
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void)
-{
-       return NULL;
-}
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void)
-{
-       return NULL;
-}
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_9_0_get_functions(void)
-{
-       return NULL;
-}
-
-struct kfd2kgd_calls *amdgpu_amdkfd_arcturus_get_functions(void)
-{
-       return NULL;
-}
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_10_0_get_functions(void)
-{
-       return NULL;
-}
-
 struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev,
-                             const struct kfd2kgd_calls *f2g,
                              unsigned int asic_type, bool vf)
 {
        return NULL;
index 4eb2fb8..069d5d2 100644 (file)
@@ -137,12 +137,6 @@ int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_type engine,
 void amdgpu_amdkfd_set_compute_idle(struct kgd_dev *kgd, bool idle);
 bool amdgpu_amdkfd_have_atomics_support(struct kgd_dev *kgd);
 
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void);
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void);
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_9_0_get_functions(void);
-struct kfd2kgd_calls *amdgpu_amdkfd_arcturus_get_functions(void);
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_10_0_get_functions(void);
-
 bool amdgpu_amdkfd_is_kfd_vmid(struct amdgpu_device *adev, u32 vmid);
 
 int amdgpu_amdkfd_pre_reset(struct amdgpu_device *adev);
@@ -248,7 +242,6 @@ void amdgpu_amdkfd_unreserve_memory_limit(struct amdgpu_bo *bo);
 int kgd2kfd_init(void);
 void kgd2kfd_exit(void);
 struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev,
-                             const struct kfd2kgd_calls *f2g,
                              unsigned int asic_type, bool vf);
 bool kgd2kfd_device_init(struct kfd_dev *kfd,
                         struct drm_device *ddev,
index 4a49dbe..e1fbbeb 100644 (file)
@@ -262,7 +262,7 @@ static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd,
        return 0;
 }
 
-static const struct kfd2kgd_calls kfd2kgd = {
+const struct kfd2kgd_calls arcturus_kfd2kgd = {
        .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
        .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
        .init_interrupts = kgd_gfx_v9_init_interrupts,
@@ -286,9 +286,3 @@ static const struct kfd2kgd_calls kfd2kgd = {
        .invalidate_tlbs_vmid = kgd_gfx_v9_invalidate_tlbs_vmid,
        .get_hive_id = amdgpu_amdkfd_get_hive_id,
 };
-
-struct kfd2kgd_calls *amdgpu_amdkfd_arcturus_get_functions(void)
-{
-       return (struct kfd2kgd_calls *)&kfd2kgd;
-}
-
index 174bf91..0878f59 100644 (file)
@@ -815,7 +815,7 @@ static void set_vm_context_page_table_base(struct kgd_dev *kgd, uint32_t vmid,
        gfxhub_v2_0_setup_vm_pt_regs(adev, vmid, page_table_base);
 }
 
-static const struct kfd2kgd_calls kfd2kgd = {
+const struct kfd2kgd_calls gfx_v10_kfd2kgd = {
        .program_sh_mem_settings = kgd_program_sh_mem_settings,
        .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,
        .init_interrupts = kgd_init_interrupts,
@@ -839,8 +839,3 @@ static const struct kfd2kgd_calls kfd2kgd = {
        .invalidate_tlbs_vmid = invalidate_tlbs_vmid,
        .get_hive_id = amdgpu_amdkfd_get_hive_id,
 };
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_10_0_get_functions()
-{
-       return (struct kfd2kgd_calls *)&kfd2kgd;
-}
index 4415260..6e6f0a9 100644 (file)
@@ -751,7 +751,7 @@ static uint32_t read_vmid_from_vmfault_reg(struct kgd_dev *kgd)
        return REG_GET_FIELD(status, VM_CONTEXT1_PROTECTION_FAULT_STATUS, VMID);
 }
 
-static const struct kfd2kgd_calls kfd2kgd = {
+const struct kfd2kgd_calls gfx_v7_kfd2kgd = {
        .program_sh_mem_settings = kgd_program_sh_mem_settings,
        .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,
        .init_interrupts = kgd_init_interrupts,
@@ -775,8 +775,3 @@ static const struct kfd2kgd_calls kfd2kgd = {
        .invalidate_tlbs_vmid = invalidate_tlbs_vmid,
        .read_vmid_from_vmfault_reg = read_vmid_from_vmfault_reg,
 };
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_7_get_functions(void)
-{
-       return (struct kfd2kgd_calls *)&kfd2kgd;
-}
index f62e008..bfbdded 100644 (file)
@@ -696,7 +696,7 @@ static int invalidate_tlbs_vmid(struct kgd_dev *kgd, uint16_t vmid)
        return 0;
 }
 
-static const struct kfd2kgd_calls kfd2kgd = {
+const struct kfd2kgd_calls gfx_v8_kfd2kgd = {
        .program_sh_mem_settings = kgd_program_sh_mem_settings,
        .set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,
        .init_interrupts = kgd_init_interrupts,
@@ -720,8 +720,3 @@ static const struct kfd2kgd_calls kfd2kgd = {
        .invalidate_tlbs = invalidate_tlbs,
        .invalidate_tlbs_vmid = invalidate_tlbs_vmid,
 };
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_8_0_get_functions(void)
-{
-       return (struct kfd2kgd_calls *)&kfd2kgd;
-}
index fdc4f8f..c72246f 100644 (file)
@@ -786,7 +786,7 @@ void kgd_gfx_v9_set_vm_context_page_table_base(struct kgd_dev *kgd, uint32_t vmi
        gfxhub_v1_0_setup_vm_pt_regs(adev, vmid, page_table_base);
 }
 
-static const struct kfd2kgd_calls kfd2kgd = {
+const struct kfd2kgd_calls gfx_v9_kfd2kgd = {
        .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
        .set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
        .init_interrupts = kgd_gfx_v9_init_interrupts,
@@ -810,8 +810,3 @@ static const struct kfd2kgd_calls kfd2kgd = {
        .invalidate_tlbs_vmid = kgd_gfx_v9_invalidate_tlbs_vmid,
        .get_hive_id = amdgpu_amdkfd_get_hive_id,
 };
-
-struct kfd2kgd_calls *amdgpu_amdkfd_gfx_9_0_get_functions(void)
-{
-       return (struct kfd2kgd_calls *)&kfd2kgd;
-}
index 96a9e06..0db2735 100644 (file)
  */
 static atomic_t kfd_locked = ATOMIC_INIT(0);
 
+extern const struct kfd2kgd_calls gfx_v7_kfd2kgd;
+extern const struct kfd2kgd_calls gfx_v8_kfd2kgd;
+extern const struct kfd2kgd_calls gfx_v9_kfd2kgd;
+extern const struct kfd2kgd_calls arcturus_kfd2kgd;
+extern const struct kfd2kgd_calls gfx_v10_kfd2kgd;
+
+static const struct kfd2kgd_calls *kfd2kgd_funcs[] = {
+#ifdef KFD_SUPPORT_IOMMU_V2
+       [CHIP_KAVERI] = &gfx_v7_kfd2kgd,
+       [CHIP_CARRIZO] = &gfx_v8_kfd2kgd,
+       [CHIP_RAVEN] = &gfx_v9_kfd2kgd,
+#endif
+       [CHIP_HAWAII] = &gfx_v7_kfd2kgd,
+       [CHIP_TONGA] = &gfx_v8_kfd2kgd,
+       [CHIP_FIJI] = &gfx_v8_kfd2kgd,
+       [CHIP_POLARIS10] = &gfx_v8_kfd2kgd,
+       [CHIP_POLARIS11] = &gfx_v8_kfd2kgd,
+       [CHIP_POLARIS12] = &gfx_v8_kfd2kgd,
+       [CHIP_VEGAM] = &gfx_v8_kfd2kgd,
+       [CHIP_VEGA10] = &gfx_v9_kfd2kgd,
+       [CHIP_VEGA12] = &gfx_v9_kfd2kgd,
+       [CHIP_VEGA20] = &gfx_v9_kfd2kgd,
+       [CHIP_RENOIR] = &gfx_v9_kfd2kgd,
+       [CHIP_ARCTURUS] = &arcturus_kfd2kgd,
+       [CHIP_NAVI10] = &gfx_v10_kfd2kgd,
+       [CHIP_NAVI12] = &gfx_v10_kfd2kgd,
+       [CHIP_NAVI14] = &gfx_v10_kfd2kgd,
+};
+
 #ifdef KFD_SUPPORT_IOMMU_V2
 static const struct kfd_device_info kaveri_device_info = {
        .asic_family = CHIP_KAVERI,
@@ -454,20 +483,22 @@ static void kfd_gtt_sa_fini(struct kfd_dev *kfd);
 static int kfd_resume(struct kfd_dev *kfd);
 
 struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd,
-       struct pci_dev *pdev, const struct kfd2kgd_calls *f2g,
-       unsigned int asic_type, bool vf)
+       struct pci_dev *pdev, unsigned int asic_type, bool vf)
 {
        struct kfd_dev *kfd;
        const struct kfd_device_info *device_info;
+       const struct kfd2kgd_calls *f2g;
 
-       if (asic_type >= sizeof(kfd_supported_devices) / (sizeof(void *) * 2)) {
+       if (asic_type >= sizeof(kfd_supported_devices) / (sizeof(void *) * 2)
+               || asic_type >= sizeof(kfd2kgd_funcs) / sizeof(void *)) {
                dev_err(kfd_device, "asic_type %d out of range\n", asic_type);
                return NULL; /* asic_type out of range */
        }
 
        device_info = kfd_supported_devices[asic_type][vf];
+       f2g = kfd2kgd_funcs[asic_type];
 
-       if (!device_info) {
+       if (!device_info && !f2g) {
                dev_err(kfd_device, "%s %s not supported in kfd\n",
                        amdgpu_asic_name[asic_type], vf ? "VF" : "");
                return NULL;