From: Mukul Joshi <[email protected]>

Add an amdgpu_mtype_remote module parameter so the MTYPE used for remote
memory accesses can be overridden. For now only MTYPE_NC and MTYPE_UC
are selectable (0 = MTYPE_NC, 1 = MTYPE_UC); it defaults to the
ASIC-dependent value. Currently, it is used only for GFX 12.1.

The MTYPEs resolved for both local and remote memory are logged once.

Signed-off-by: Mukul Joshi <[email protected]>
Reviewed-by: Felix Kuehling <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  7 +++++
 drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c  | 34 +++++++++++++------------
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c    |  8 ++++--
 4 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index f619d95a5ccfe..79b69d74eb2e5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -223,6 +223,7 @@ extern int amdgpu_force_asic_type;
 extern int amdgpu_smartshift_bias;
 extern int amdgpu_use_xgmi_p2p;
 extern int amdgpu_mtype_local;
+extern int amdgpu_mtype_remote;
 extern int amdgpu_enforce_isolation;
 extern uint amdgpu_debug_mask;
 #ifdef CONFIG_HSA_AMD
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 9c2ff3e147d17..287c9455969b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -845,6 +845,13 @@ int amdgpu_mtype_local = -1;
 MODULE_PARM_DESC(mtype_local, "MTYPE for local memory (default: ASIC 
dependent, 0 = MTYPE_RW, 1 = MTYPE_NC, 2 = MTYPE_CC)");
 module_param_named_unsafe(mtype_local, amdgpu_mtype_local, int, 0444);
 
+/**
+ * DOC: mtype_remote (int)
+ */
+int amdgpu_mtype_remote = -1;
+MODULE_PARM_DESC(mtype_remote, "MTYPE for remote memory (default: ASIC 
dependent, 0 = MTYPE_NC, 1 = MTYPE_UC)");
+module_param_named_unsafe(mtype_remote, amdgpu_mtype_remote, int, 0444);
+
 /**
  * DOC: pcie_p2p (bool)
  * Enable PCIe P2P (requires large-BAR). Default value: true (on)
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
index a3b7e240abaed..4e7b6e2c87ab5 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
@@ -618,8 +618,8 @@ static void gmc_v12_1_get_npa_flags(struct amdgpu_device 
*adev,
 
 /*
  * Resolve the MTYPEs used for local and remote memory accesses on GFX 12.1.
- * Remote memory always uses MTYPE_UC; local memory depends on the AID stepping
- * and the amdgpu_mtype_local module parameter.
+ * Both default to an ASIC-dependent value that can be overridden through the
+ * amdgpu_mtype_local and amdgpu_mtype_remote module parameters.
  */
 static void gmc_v12_1_get_mtypes(struct amdgpu_device *adev,
                                 unsigned int *mtype_local,
@@ -627,23 +627,25 @@ static void gmc_v12_1_get_mtypes(struct amdgpu_device 
*adev,
 {
        bool is_aid_a1 = (adev->rev_id & 0x10);
 
+       /* Local memory: ASIC default depends on the AID stepping. */
        *mtype_local = is_aid_a1 ? MTYPE_RW : MTYPE_NC;
-       /* Remote memory always uses MTYPE_UC on GFX 12.1. */
-       *mtype_remote = MTYPE_UC;
-
-       if (amdgpu_mtype_local == 0) {
-               DRM_INFO_ONCE("Using MTYPE_RW for local memory\n");
+       if (amdgpu_mtype_local == 0)
                *mtype_local = MTYPE_RW;
-       } else if (amdgpu_mtype_local == 1) {
-               DRM_INFO_ONCE("Using MTYPE_NC for local memory\n");
+       else if (amdgpu_mtype_local == 1)
                *mtype_local = MTYPE_NC;
-       } else if (amdgpu_mtype_local == 2) {
-               DRM_INFO_ONCE("MTYPE_CC not supported, using %s for local 
memory\n",
-                             is_aid_a1 ? "MTYPE_RW" : "MTYPE_NC");
-       } else {
-               DRM_INFO_ONCE("Using %s for local memory and MTYPE_UC for 
remote memory\n",
-                             is_aid_a1 ? "MTYPE_RW" : "MTYPE_NC");
-       }
+       else if (amdgpu_mtype_local == 2)
+               DRM_INFO_ONCE("MTYPE_CC not supported for local memory\n");
+
+       /* Remote memory defaults to MTYPE_UC on GFX 12.1. */
+       *mtype_remote = MTYPE_UC;
+       if (amdgpu_mtype_remote == 0)
+               *mtype_remote = MTYPE_NC;
+       else if (amdgpu_mtype_remote == 1)
+               *mtype_remote = MTYPE_UC;
+
+       DRM_INFO_ONCE("Using %s for local memory and %s for remote memory\n",
+                     *mtype_local == MTYPE_RW ? "MTYPE_RW" : "MTYPE_NC",
+                     *mtype_remote == MTYPE_NC ? "MTYPE_NC" : "MTYPE_UC");
 }
 
 /*
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 64fb38400bd1a..c521ec07bf3c0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -1348,8 +1348,12 @@ svm_range_get_pte_flags(struct kfd_node *node, struct 
amdgpu_vm *vm,
                mtype_local = amdgpu_mtype_local == 0 ? AMDGPU_VM_MTYPE_RW :
                                amdgpu_mtype_local == 1 ? AMDGPU_VM_MTYPE_NC :
                                is_aid_a1 ? AMDGPU_VM_MTYPE_RW : 
AMDGPU_VM_MTYPE_NC;
-               /* Remote memory always uses MTYPE_UC on GFX 12.1. */
-               mtype_remote = AMDGPU_VM_MTYPE_UC;
+               /* Remote memory defaults to MTYPE_UC on GFX 12.1 and can be
+                * overridden through the amdgpu_mtype_remote module parameter
+                * (0 = MTYPE_NC, 1 = MTYPE_UC).
+                */
+               mtype_remote = amdgpu_mtype_remote == 0 ? AMDGPU_VM_MTYPE_NC :
+                               AMDGPU_VM_MTYPE_UC;
                snoop = true;
 
                if (is_local) /* local HBM  */ {
-- 
2.55.0

Reply via email to