On GFX 12.1 AID A0, extended-scope fine-grained local HBM must be
mapped MTYPE_UC when the device is in DPX, QPX or CPX compute partition
mode. In SPX mode the local MTYPE (MTYPE_NC by default) is kept.
Remote VRAM and system memory already use MTYPE_UC.

Signed-off-by: Mukul Joshi <[email protected]>
Reviewed-by: David Yat Sin <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 13 ++++++++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c   | 17 +++++++++++++----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
index e056eb80b3a3..57aac3a9a3b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
@@ -680,6 +680,7 @@ static void gmc_v12_1_get_coherence_flags(struct 
amdgpu_device *adev,
        unsigned int mtype, mtype_local, mtype_remote;
        bool snoop = false;
        bool is_local = false;
+       bool is_aid_a1, is_spx;
 
        switch (gc_ip_version) {
        case IP_VERSION(12, 1, 0):
@@ -690,7 +691,17 @@ static void gmc_v12_1_get_coherence_flags(struct 
amdgpu_device *adev,
                if (uncached) {
                        mtype = MTYPE_UC;
                } else if (ext_coherent) {
-                       mtype = is_local ? mtype_local : MTYPE_UC;
+                       is_aid_a1 = SOC_V1_0_DIE_REV_AID(adev->rev_id) == 1;
+                       is_spx = amdgpu_xcp_query_partition_mode(adev->xcp_mgr,
+                                                                
AMDGPU_XCP_FL_NONE) ==
+                                AMDGPU_SPX_PARTITION_MODE;
+                       /* AID A0 requires MTYPE_UC for extended-scope coherent
+                        * local memory in DPX/QPX/CPX modes.
+                        */
+                       if (is_local && (is_aid_a1 || is_spx))
+                               mtype = mtype_local;
+                       else
+                               mtype = MTYPE_UC;
                } else {
                        mtype = is_local ? mtype_local : mtype_remote;
                }
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index f99cb18e8e11..671193fb1203 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -1254,7 +1254,7 @@ svm_range_get_pte_flags(struct kfd_node *node, struct 
amdgpu_vm *vm,
        bool coherent = flags & (KFD_IOCTL_SVM_FLAG_COHERENT | 
KFD_IOCTL_SVM_FLAG_EXT_COHERENT);
        bool ext_coherent = flags & KFD_IOCTL_SVM_FLAG_EXT_COHERENT;
        unsigned int mtype_local, mtype_remote;
-       bool is_aid_a1, is_local;
+       bool is_aid_a1, is_local, is_spx;
 
        if (domain == SVM_RANGE_VRAM_DOMAIN)
                bo_node = prange->svm_bo->node;
@@ -1357,10 +1357,19 @@ svm_range_get_pte_flags(struct kfd_node *node, struct 
amdgpu_vm *vm,
                                AMDGPU_VM_MTYPE_UC;
                snoop = true;
 
-               if (is_local) /* local HBM  */ {
+               if (ext_coherent) {
+                       is_spx = 
amdgpu_xcp_query_partition_mode(node->adev->xcp_mgr,
+                                                                
AMDGPU_XCP_FL_NONE) ==
+                                AMDGPU_SPX_PARTITION_MODE;
+                       /* AID A0 requires MTYPE_UC for extended-scope coherent
+                        * local memory in DPX/QPX/CPX modes.
+                        */
+                       if (is_local && (is_aid_a1 || is_spx))
+                               mapping_flags |= mtype_local;
+                       else
+                               mapping_flags |= AMDGPU_VM_MTYPE_UC;
+               } else if (is_local) /* local HBM  */ {
                        mapping_flags |= mtype_local;
-               } else if (ext_coherent) {
-                       mapping_flags |= AMDGPU_VM_MTYPE_UC;
                } else {
                        /* system memory or remote VRAM */
                        mapping_flags |= mtype_remote;
-- 
2.55.0

Reply via email to