All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Andrzej Hajda <andrzej.hajda@intel.com>,
	Radhakrishna Sripada <radhakrishna.sripada@intel.com>,
	Nirmoy Das <nirmoy.das@intel.com>,
	Paz Zcharya <pazz@chromium.org>
Subject: [PATCH v4 04/16] drm/i915: Bypass LMEMBAR/GTTMMADR for MTL stolen memory access
Date: Sat,  3 Feb 2024 00:43:28 +0200	[thread overview]
Message-ID: <20240202224340.30647-5-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20240202224340.30647-1-ville.syrjala@linux.intel.com>

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

On MTL accessing stolen memory via the BARs is somehow borked,
and it can hang the machine. As a workaround let's bypass the
BARs and just go straight to DSMBASE/GSMBASE instead.

Note that on every other platform this itself would hang the
machine, but on MTL the system firmware is expected to relax
the access permission guarding stolen memory to enable this
workaround, and thus direct CPU accesses should be fine.

The raw stolen memory areas won't be passed to VMs so we'll
need to risk using the BAR there for the initial setup. Once
command submission is up we should switch to MI_UPDATE_GTT
which at least shouldn't hang the whole machine.

v2: Don't use direct GSM/DSM access on guests
    Add w/a number
v3: Check register 0x138914 to see if pcode did its job
    Add some debug prints

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Reviewed-by: Radhakrishna Sripada <radhakrishna.sripada@intel.com>
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>
Tested-by: Paz Zcharya <pazz@chromium.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c |  6 +++++-
 drivers/gpu/drm/i915/gt/intel_ggtt.c       | 10 +++++++++-
 drivers/gpu/drm/i915/i915_reg.h            |  3 +++
 drivers/gpu/drm/i915/i915_utils.c          | 17 +++++++++++++++++
 drivers/gpu/drm/i915/i915_utils.h          |  2 ++
 5 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
index ee237043c302..9ddcae9b3997 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
@@ -941,7 +941,11 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type,
 		dsm_size = ALIGN_DOWN(lmem_size - dsm_base, SZ_1M);
 	}
 
-	if (pci_resource_len(pdev, GEN12_LMEM_BAR) < lmem_size) {
+	if (i915_direct_stolen_access(i915)) {
+		drm_dbg(&i915->drm, "Using direct DSM access\n");
+		io_start = intel_uncore_read64(uncore, GEN12_DSMBASE) & GEN12_BDSM_MASK;
+		io_size = dsm_size;
+	} else if (pci_resource_len(pdev, GEN12_LMEM_BAR) < lmem_size) {
 		io_start = 0;
 		io_size = 0;
 	} else {
diff --git a/drivers/gpu/drm/i915/gt/intel_ggtt.c b/drivers/gpu/drm/i915/gt/intel_ggtt.c
index 21a7e3191c18..bce5d8025340 100644
--- a/drivers/gpu/drm/i915/gt/intel_ggtt.c
+++ b/drivers/gpu/drm/i915/gt/intel_ggtt.c
@@ -24,6 +24,7 @@
 #include "intel_ring.h"
 #include "i915_drv.h"
 #include "i915_pci.h"
+#include "i915_reg.h"
 #include "i915_request.h"
 #include "i915_scatterlist.h"
 #include "i915_utils.h"
@@ -1152,13 +1153,20 @@ static unsigned int gen6_gttadr_offset(struct drm_i915_private *i915)
 static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size)
 {
 	struct drm_i915_private *i915 = ggtt->vm.i915;
+	struct intel_uncore *uncore = ggtt->vm.gt->uncore;
 	struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
 	phys_addr_t phys_addr;
 	u32 pte_flags;
 	int ret;
 
 	GEM_WARN_ON(pci_resource_len(pdev, GEN4_GTTMMADR_BAR) != gen6_gttmmadr_size(i915));
-	phys_addr = pci_resource_start(pdev, GEN4_GTTMMADR_BAR) + gen6_gttadr_offset(i915);
+
+	if (i915_direct_stolen_access(i915)) {
+		drm_dbg(&i915->drm, "Using direct GSM access\n");
+		phys_addr = intel_uncore_read64(uncore, GEN12_GSMBASE) & GEN12_BDSM_MASK;
+	} else {
+		phys_addr = pci_resource_start(pdev, GEN4_GTTMMADR_BAR) + gen6_gttadr_offset(i915);
+	}
 
 	if (needs_wc_ggtt_mapping(i915))
 		ggtt->gsm = ioremap_wc(phys_addr, size);
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 0b9e018256c7..c1bf70d62ead 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -5414,6 +5414,9 @@
 #define   GEN6_PCODE_FREQ_RING_RATIO_SHIFT	16
 #define GEN6_PCODE_DATA1			_MMIO(0x13812C)
 
+#define MTL_PCODE_STOLEN_ACCESS			_MMIO(0x138914)
+#define   STOLEN_ACCESS_ALLOWED			0x1
+
 /* IVYBRIDGE DPF */
 #define GEN7_L3CDERRST1(slice)		_MMIO(0xB008 + (slice) * 0x200) /* L3CD Error Status 1 */
 #define   GEN7_L3CDERRST1_ROW_MASK	(0x7ff << 14)
diff --git a/drivers/gpu/drm/i915/i915_utils.c b/drivers/gpu/drm/i915/i915_utils.c
index 29fd02bf5ea8..6f9e7b354b54 100644
--- a/drivers/gpu/drm/i915/i915_utils.c
+++ b/drivers/gpu/drm/i915/i915_utils.c
@@ -8,6 +8,7 @@
 #include <drm/drm_drv.h>
 
 #include "i915_drv.h"
+#include "i915_reg.h"
 #include "i915_utils.h"
 
 #define FDO_BUG_MSG "Please file a bug on drm/i915; see " FDO_BUG_URL " for details."
@@ -125,3 +126,19 @@ bool i915_vtd_active(struct drm_i915_private *i915)
 	/* Running as a guest, we assume the host is enforcing VT'd */
 	return i915_run_as_guest();
 }
+
+bool i915_direct_stolen_access(struct drm_i915_private *i915)
+{
+	/*
+	 * Wa_22018444074
+	 *
+	 * Access via BAR can hang MTL, go directly to GSM/DSM,
+	 * except for VM guests which won't have access to it.
+	 *
+	 * Normally this would not work but on MTL the system firmware
+	 * should have relaxed the access permissions sufficiently.
+	 * 0x138914==0x1 indicates that the firmware has done its job.
+	 */
+	return IS_METEORLAKE(i915) && !i915_run_as_guest() &&
+		intel_uncore_read(&i915->uncore, MTL_PCODE_STOLEN_ACCESS) == STOLEN_ACCESS_ALLOWED;
+}
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
index f98577967b7f..b45ef0560611 100644
--- a/drivers/gpu/drm/i915/i915_utils.h
+++ b/drivers/gpu/drm/i915/i915_utils.h
@@ -391,4 +391,6 @@ static inline bool i915_run_as_guest(void)
 
 bool i915_vtd_active(struct drm_i915_private *i915);
 
+bool i915_direct_stolen_access(struct drm_i915_private *i915);
+
 #endif /* !__I915_UTILS_H */
-- 
2.43.0


  parent reply	other threads:[~2024-02-02 22:44 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 22:43 [PATCH v4 00/16] drm/i915: (stolen) memory region related fixes Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 01/16] drm/i915: Use struct resource for memory region IO as well Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 02/16] drm/i915: Print memory region info during probe Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 03/16] drm/i915: Remove ad-hoc lmem/stolen debugs Ville Syrjala
2024-02-02 22:43 ` Ville Syrjala [this message]
2024-02-02 22:43 ` [PATCH v4 05/16] drm/i915: Disable the "binder" Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 06/16] drm/i915: Rename the DSM/GSM registers Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 07/16] drm/i915: Fix PTE decode during initial plane readout Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 08/16] drm/i915: Fix region start " Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 09/16] drm/i915: Fix MTL " Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 10/16] drm/i915: s/phys_base/dma_addr/ Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 11/16] drm/i915: Split the smem and lmem plane readout apart Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 12/16] drm/i915: Simplify intel_initial_plane_config() calling convention Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 13/16] drm/i915/fbdev: Fix smem_start for LMEMBAR stolen objects Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 14/16] drm/i915: Tweak BIOS fb reuse check Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 15/16] drm/i915: Try to relocate the BIOS fb to the start of ggtt Ville Syrjala
2024-02-02 22:43 ` [PATCH v4 16/16] drm/i915: Annotate more of the BIOS fb takeover failure paths Ville Syrjala
2024-02-03  0:03 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: (stolen) memory region related fixes (rev11) Patchwork
2024-02-03  0:03 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-02-03  0:19 ` ✓ Fi.CI.BAT: success " Patchwork
2024-02-03  0:33 ` ✓ CI.Patch_applied: success for drm/i915: (stolen) memory region related fixes Patchwork
2024-02-03  0:33 ` ✗ CI.checkpatch: warning " Patchwork
2024-02-03  0:34 ` ✓ CI.KUnit: success " Patchwork
2024-02-03  0:41 ` ✓ CI.Build: " Patchwork
2024-02-03  0:42 ` ✓ CI.Hooks: " Patchwork
2024-02-03  0:43 ` ✗ CI.checksparse: warning " Patchwork
2024-02-03  1:07 ` ✓ CI.BAT: success " Patchwork
2024-02-03 10:13 ` ✗ Fi.CI.IGT: failure for drm/i915: (stolen) memory region related fixes (rev11) Patchwork
2024-02-05 11:38 ` [PATCH v4 00/16] drm/i915: (stolen) memory region related fixes Jani Nikula
2024-02-05 14:16   ` Lucas De Marchi
2024-02-05 14:37     ` Saarinen, Jani
2024-02-07  0:12     ` Ville Syrjälä
2024-02-05 22:40 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: (stolen) memory region related fixes (rev12) Patchwork
2024-02-05 22:40 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-02-05 22:58 ` ✓ Fi.CI.BAT: success " Patchwork
2024-02-06  4:19 ` ✗ Fi.CI.IGT: failure " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2024-01-16  7:56 [PATCH v3 04/16] drm/i915: Bypass LMEMBAR/GTTMMADR for MTL stolen memory access Ville Syrjala
2024-01-25 10:27 ` [PATCH v4 " Ville Syrjala
2024-01-30 23:19   ` Paz Zcharya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240202224340.30647-5-ville.syrjala@linux.intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=nirmoy.das@intel.com \
    --cc=pazz@chromium.org \
    --cc=radhakrishna.sripada@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.