Skip to contentSkip to conversation

drm/amdgpu: Add SOC_V1_0_DIE_REV_AID() helper

PATCH New Mukul Joshi 1 participant 2 messages Sep 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: Add SOC_V1_0_DIE_REV_AID() helper

Add a helper to extract the AID revision from adev->rev_id, matching the existing SOC_V1_0_DIE_REV_XCD(), and use it instead of open-coded rev_id bit checks for AID A1 in gmc_v12_1 and kfd_svm.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/soc_v1_0.h  | 2 ++
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c   | 3 ++-
 3 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +2 -1
index 839d76183755..e056eb80b3a3 100644
@@ -23,6 +23,7 @@
 #include "amdgpu.h"
 #include "gmc_v12_1.h"
 #include "soc15_common.h"
+#include "soc_v1_0.h"
 #include "soc_v1_0_enum.h"
 #include "oss/osssys_7_1_0_offset.h"
 #include "oss/osssys_7_1_0_sh_mask.h"
@@ -627,7 +628,7 @@ static void gmc_v12_1_get_mtypes(struct amdgpu_device *adev,
 				 unsigned int *mtype_local,
 				 unsigned int *mtype_remote)
 {
-	bool is_aid_a1 = (adev->rev_id & 0x10);
+	bool is_aid_a1 = SOC_V1_0_DIE_REV_AID(adev->rev_id) == 1;
 
 	/* Local memory: ASIC default depends on the AID stepping. */
 	*mtype_local = is_aid_a1 ? MTYPE_RW : MTYPE_NC;
drivers/gpu/drm/amd/amdgpu/soc_v1_0.h +2 -0
index 9bff7cc60121..861862bd85b9 100644
@@ -46,6 +46,8 @@ extern const struct amdgpu_ip_block_version soc_v1_0_common_ip_block;
 	 ((xcd) << SOC_V1_0_DIE_REV_XCD__SHIFT))
 #define SOC_V1_0_DIE_REV_XCD(rev_id)          \
 	(((rev_id) & SOC_V1_0_DIE_REV_XCD__MASK) >> SOC_V1_0_DIE_REV_XCD__SHIFT)
+#define SOC_V1_0_DIE_REV_AID(rev_id)          \
+	(((rev_id) & SOC_V1_0_DIE_REV_AID__MASK) >> SOC_V1_0_DIE_REV_AID__SHIFT)
 
 void soc_v1_0_grbm_select(struct amdgpu_device *adev,
 			  u32 me, u32 pipe,
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -1
index a99dbedf3cd4..f99cb18e8e11 100644
@@ -34,6 +34,7 @@
 #include "amdgpu.h"
 #include "amdgpu_xgmi.h"
 #include "amdgpu_reset.h"
+#include "soc_v1_0.h"
 #include "kfd_priv.h"
 #include "kfd_svm.h"
 #include "kfd_migrate.h"
@@ -1341,7 +1342,7 @@ svm_range_get_pte_flags(struct kfd_node *node, struct amdgpu_vm *vm,
 		mapping_flags |= AMDGPU_VM_MTYPE_NC;
 		break;
 	case IP_VERSION(12, 1, 0):
-		is_aid_a1 = (node->adev->rev_id & 0x10);
+		is_aid_a1 = SOC_V1_0_DIE_REV_AID(node->adev->rev_id) == 1;
 		is_local = (domain == SVM_RANGE_VRAM_DOMAIN) &&
 				(bo_node->adev == node->adev);
 
Signature · 1 line
2.55.0
#1 lore raw

PATCH 2/2 drm/amdgpu: Use MTYPE_UC for ext-coherent local memory on AID A0 non-SPX

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.

---
 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(-)
drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c +12 -1
index e056eb80b3a3..57aac3a9a3b0 100644
@@ -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;
 		}
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +13 -4
index f99cb18e8e11..671193fb1203 100644
@@ -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;
Signature · 1 line
2.55.0