<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">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Series is:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Graham Sider <Graham.Sider@amd.com><br>
<b>Sent:</b> Tuesday, November 9, 2021 5:42 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Kuehling, Felix <Felix.Kuehling@amd.com>; Kasiviswanathan, Harish <Harish.Kasiviswanathan@amd.com>; Sider, Graham <Graham.Sider@amd.com><br>
<b>Subject:</b> [PATCH v2 3/3] drm/amdkfd: convert misc checks to IP version checking</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Switch to IP version checking instead of asic_type on various KFD<br>
version checks.<br>
<br>
Signed-off-by: Graham Sider <Graham.Sider@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c      |  2 +-<br>
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c         |  2 +-<br>
 drivers/gpu/drm/amd/amdkfd/kfd_device.c       | 27 ++++++++++---------<br>
 .../drm/amd/amdkfd/kfd_device_queue_manager.c |  3 +--<br>
 .../amd/amdkfd/kfd_device_queue_manager_v9.c  |  2 +-<br>
 drivers/gpu/drm/amd/amdkfd/kfd_events.c       |  6 +++--<br>
 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c      |  2 +-<br>
 drivers/gpu/drm/amd/amdkfd/kfd_process.c      |  7 +++--<br>
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c          |  6 ++---<br>
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c     |  4 +--<br>
 10 files changed, 31 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
index 2466a73b8c7d..f70117b00b14 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
@@ -1603,7 +1603,7 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,<br>
         }<br>
         mutex_unlock(&p->mutex);<br>
 <br>
-       if (dev->device_info->asic_family == CHIP_ALDEBARAN) {<br>
+       if (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2)) {<br>
                 err = amdgpu_amdkfd_gpuvm_sync_memory(dev->adev,<br>
                                 (struct kgd_mem *) mem, true);<br>
                 if (err) {<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c<br>
index 19dd472e9b06..b6d887edac85 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c<br>
@@ -1992,7 +1992,7 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,<br>
                 sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;<br>
                 sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;<br>
                 sub_type_hdr->num_hops_xgmi = 1;<br>
-               if (kdev->adev->asic_type == CHIP_ALDEBARAN) {<br>
+               if (KFD_GC_VERSION(kdev) == IP_VERSION(9, 4, 2)) {<br>
                         sub_type_hdr->minimum_bandwidth_mbs =<br>
                                         amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(<br>
                                                         kdev->adev, NULL, true);<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c<br>
index ee813bd57c92..594dd28a391f 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c<br>
@@ -848,23 +848,23 @@ struct kfd_dev *kgd2kfd_probe(struct amdgpu_device *adev, bool vf)<br>
 static void kfd_cwsr_init(struct kfd_dev *kfd)<br>
 {<br>
         if (cwsr_enable && kfd->device_info->supports_cwsr) {<br>
-               if (kfd->device_info->asic_family < CHIP_VEGA10) {<br>
+               if (KFD_GC_VERSION(kfd) < IP_VERSION(9, 0, 1)) {<br>
                         BUILD_BUG_ON(sizeof(cwsr_trap_gfx8_hex) > PAGE_SIZE);<br>
                         kfd->cwsr_isa = cwsr_trap_gfx8_hex;<br>
                         kfd->cwsr_isa_size = sizeof(cwsr_trap_gfx8_hex);<br>
-               } else if (kfd->device_info->asic_family == CHIP_ARCTURUS) {<br>
+               } else if (KFD_GC_VERSION(kfd) == IP_VERSION(9, 4, 1)) {<br>
                         BUILD_BUG_ON(sizeof(cwsr_trap_arcturus_hex) > PAGE_SIZE);<br>
                         kfd->cwsr_isa = cwsr_trap_arcturus_hex;<br>
                         kfd->cwsr_isa_size = sizeof(cwsr_trap_arcturus_hex);<br>
-               } else if (kfd->device_info->asic_family == CHIP_ALDEBARAN) {<br>
+               } else if (KFD_GC_VERSION(kfd) == IP_VERSION(9, 4, 2)) {<br>
                         BUILD_BUG_ON(sizeof(cwsr_trap_aldebaran_hex) > PAGE_SIZE);<br>
                         kfd->cwsr_isa = cwsr_trap_aldebaran_hex;<br>
                         kfd->cwsr_isa_size = sizeof(cwsr_trap_aldebaran_hex);<br>
-               } else if (kfd->device_info->asic_family < CHIP_NAVI10) {<br>
+               } else if (KFD_GC_VERSION(kfd) < IP_VERSION(10, 1, 1)) {<br>
                         BUILD_BUG_ON(sizeof(cwsr_trap_gfx9_hex) > PAGE_SIZE);<br>
                         kfd->cwsr_isa = cwsr_trap_gfx9_hex;<br>
                         kfd->cwsr_isa_size = sizeof(cwsr_trap_gfx9_hex);<br>
-               } else if (kfd->device_info->asic_family < CHIP_SIENNA_CICHLID) {<br>
+               } else if (KFD_GC_VERSION(kfd) < IP_VERSION(10, 3, 0)) {<br>
                         BUILD_BUG_ON(sizeof(cwsr_trap_nv1x_hex) > PAGE_SIZE);<br>
                         kfd->cwsr_isa = cwsr_trap_nv1x_hex;<br>
                         kfd->cwsr_isa_size = sizeof(cwsr_trap_nv1x_hex);<br>
@@ -886,14 +886,16 @@ static int kfd_gws_init(struct kfd_dev *kfd)<br>
                 return 0;<br>
 <br>
         if (hws_gws_support<br>
-               || (kfd->device_info->asic_family == CHIP_VEGA10<br>
+               || (KFD_GC_VERSION(kfd) == IP_VERSION(9, 0, 1)<br>
                         && kfd->mec2_fw_version >= 0x81b3)<br>
-               || (kfd->device_info->asic_family >= CHIP_VEGA12<br>
-                       && kfd->device_info->asic_family <= CHIP_RAVEN<br>
+               || ((KFD_GC_VERSION(kfd) == IP_VERSION(9, 2, 1)<br>
+                       || KFD_GC_VERSION(kfd) == IP_VERSION(9, 4, 0)<br>
+                       || KFD_GC_VERSION(kfd) == IP_VERSION(9, 1, 0)<br>
+                       || KFD_GC_VERSION(kfd) == IP_VERSION(9, 2, 2))<br>
                         && kfd->mec2_fw_version >= 0x1b3)<br>
-               || (kfd->device_info->asic_family == CHIP_ARCTURUS<br>
+               || (KFD_GC_VERSION(kfd) == IP_VERSION(9, 4, 1)<br>
                         && kfd->mec2_fw_version >= 0x30)<br>
-               || (kfd->device_info->asic_family == CHIP_ALDEBARAN<br>
+               || (KFD_GC_VERSION(kfd) == IP_VERSION(9, 4, 2)<br>
                         && kfd->mec2_fw_version >= 0x28))<br>
                 ret = amdgpu_amdkfd_alloc_gws(kfd->adev,<br>
                                 kfd->adev->gds.gws_size, &kfd->gws);<br>
@@ -962,10 +964,9 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,<br>
          * calculate max size of runlist packet.<br>
          * There can be only 2 packets at once<br>
          */<br>
-       map_process_packet_size =<br>
-                       kfd->device_info->asic_family == CHIP_ALDEBARAN ?<br>
+       map_process_packet_size = KFD_GC_VERSION(kfd) == IP_VERSION(9, 4, 2) ?<br>
                                 sizeof(struct pm4_mes_map_process_aldebaran) :<br>
-                                       sizeof(struct pm4_mes_map_process);<br>
+                               sizeof(struct pm4_mes_map_process);<br>
         size += (KFD_MAX_NUM_OF_PROCESSES * map_process_packet_size +<br>
                 max_num_of_queues_per_device * sizeof(struct pm4_mes_map_queues)<br>
                 + sizeof(struct pm4_mes_runlist)) * 2;<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c<br>
index 93d41e0b9b41..c894cbe58a36 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c<br>
@@ -250,8 +250,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,<br>
 <br>
         program_sh_mem_settings(dqm, qpd);<br>
 <br>
-       if (dqm->dev->device_info->asic_family >= CHIP_VEGA10 &&<br>
-           dqm->dev->cwsr_enabled)<br>
+       if (KFD_IS_SOC15(dqm->dev) && dqm->dev->cwsr_enabled)<br>
                 program_trap_handler_settings(dqm, qpd);<br>
 <br>
         /* qpd->page_table_base is set earlier when register_process()<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v9.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v9.c<br>
index b5c3d13643f1..f20434d9980e 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v9.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager_v9.c<br>
@@ -62,7 +62,7 @@ static int update_qpd_v9(struct device_queue_manager *dqm,<br>
                                 SH_MEM_ALIGNMENT_MODE_UNALIGNED <<<br>
                                         SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT;<br>
 <br>
-               if (dqm->dev->device_info->asic_family == CHIP_ALDEBARAN) {<br>
+               if (KFD_GC_VERSION(dqm->dev) == IP_VERSION(9, 4, 2)) {<br>
                         /* Aldebaran can safely support different XNACK modes<br>
                          * per process<br>
                          */<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c<br>
index 3eea4edee355..afe72dd11325 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c<br>
@@ -935,8 +935,10 @@ void kfd_signal_iommu_event(struct kfd_dev *dev, u32 pasid,<br>
         /* Workaround on Raven to not kill the process when memory is freed<br>
          * before IOMMU is able to finish processing all the excessive PPRs<br>
          */<br>
-       if (dev->device_info->asic_family != CHIP_RAVEN &&<br>
-           dev->device_info->asic_family != CHIP_RENOIR) {<br>
+<br>
+       if (KFD_GC_VERSION(dev) != IP_VERSION(9, 1, 0) &&<br>
+           KFD_GC_VERSION(dev) != IP_VERSION(9, 2, 2) &&<br>
+           KFD_GC_VERSION(dev) != IP_VERSION(9, 3, 0)) {<br>
                 mutex_lock(&p->event_mutex);<br>
 <br>
                 /* Lookup events by type and signal them */<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<br>
index aeade32ec298..d59b73f69260 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<br>
@@ -940,7 +940,7 @@ int svm_migrate_init(struct amdgpu_device *adev)<br>
         void *r;<br>
 <br>
         /* Page migration works on Vega10 or newer */<br>
-       if (kfddev->device_info->asic_family < CHIP_VEGA10)<br>
+       if (!KFD_IS_SOC15(kfddev))<br>
                 return -EINVAL;<br>
 <br>
         pgmap = &kfddev->pgmap;<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
index fafc7b187fad..74c9323f32fc 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
@@ -1317,14 +1317,13 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)<br>
                  * support the SVM APIs and don't need to be considered<br>
                  * for the XNACK mode selection.<br>
                  */<br>
-               if (dev->device_info->asic_family < CHIP_VEGA10)<br>
+               if (!KFD_IS_SOC15(dev))<br>
                         continue;<br>
                 /* Aldebaran can always support XNACK because it can support<br>
                  * per-process XNACK mode selection. But let the dev->noretry<br>
                  * setting still influence the default XNACK mode.<br>
                  */<br>
-               if (supported &&<br>
-                   dev->device_info->asic_family == CHIP_ALDEBARAN)<br>
+               if (supported && KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2))<br>
                         continue;<br>
 <br>
                 /* GFXv10 and later GPUs do not support shader preemption<br>
@@ -1332,7 +1331,7 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported)<br>
                  * management and memory-manager-related preemptions or<br>
                  * even deadlocks.<br>
                  */<br>
-               if (dev->device_info->asic_family >= CHIP_NAVI10)<br>
+               if (KFD_GC_VERSION(dev) > IP_VERSION(10, 1, 1))<br>
                         return false;<br>
 <br>
                 if (dev->noretry)<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
index 77239b06b236..88360f23eb61 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
@@ -1051,8 +1051,8 @@ svm_range_get_pte_flags(struct amdgpu_device *adev, struct svm_range *prange,<br>
         if (domain == SVM_RANGE_VRAM_DOMAIN)<br>
                 bo_adev = amdgpu_ttm_adev(prange->svm_bo->bo->tbo.bdev);<br>
 <br>
-       switch (adev->asic_type) {<br>
-       case CHIP_ARCTURUS:<br>
+       switch (KFD_GC_VERSION(adev->kfd.dev)) {<br>
+       case IP_VERSION(9, 4, 1):<br>
                 if (domain == SVM_RANGE_VRAM_DOMAIN) {<br>
                         if (bo_adev == adev) {<br>
                                 mapping_flags |= coherent ?<br>
@@ -1068,7 +1068,7 @@ svm_range_get_pte_flags(struct amdgpu_device *adev, struct svm_range *prange,<br>
                                 AMDGPU_VM_MTYPE_UC : AMDGPU_VM_MTYPE_NC;<br>
                 }<br>
                 break;<br>
-       case CHIP_ALDEBARAN:<br>
+       case IP_VERSION(9, 4, 2):<br>
                 if (domain == SVM_RANGE_VRAM_DOMAIN) {<br>
                         if (bo_adev == adev) {<br>
                                 mapping_flags |= coherent ?<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c<br>
index a4c0c929444a..641e250dc95f 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c<br>
@@ -1239,7 +1239,7 @@ static void kfd_set_iolink_non_coherent(struct kfd_topology_device *to_dev,<br>
                  */<br>
                 if (inbound_link->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS ||<br>
                     (inbound_link->iolink_type == CRAT_IOLINK_TYPE_XGMI &&<br>
-                   to_dev->gpu->device_info->asic_family == CHIP_VEGA20)) {<br>
+                   KFD_GC_VERSION(to_dev->gpu) == IP_VERSION(9, 4, 0))) {<br>
                         outbound_link->flags |= CRAT_IOLINK_FLAGS_NON_COHERENT;<br>
                         inbound_link->flags |= CRAT_IOLINK_FLAGS_NON_COHERENT;<br>
                 }<br>
@@ -1463,7 +1463,7 @@ int kfd_topology_add_device(struct kfd_dev *gpu)<br>
                 ((dev->gpu->adev->ras_enabled & BIT(AMDGPU_RAS_BLOCK__UMC)) != 0) ?<br>
                 HSA_CAP_MEM_EDCSUPPORTED : 0;<br>
 <br>
-       if (dev->gpu->adev->asic_type != CHIP_VEGA10)<br>
+       if (KFD_GC_VERSION(dev->gpu) != IP_VERSION(9, 0, 1))<br>
                 dev->node_props.capability |= (dev->gpu->adev->ras_enabled != 0) ?<br>
                         HSA_CAP_RASEVENTNOTIFY : 0;<br>
 <br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>