Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stuart Summers <stuart.summers@intel.com>
Cc: intel-xe@lists.freedesktop.org, thomas.hellstrom@linux.intel.com,
	rodrigo.vivi@intel.com, alan.previn.teres.alexis@intel.com,
	fei.yang@intel.com, anoop.c.vijay@intel.com,
	riana.tauro@intel.com, matthew.d.roper@intel.com,
	Stuart Summers <stuart.summers@intel.com>
Subject: [PATCH 2/2] drm/xe: Work around media 52-bit limitation on CRI
Date: Thu,  3 Dec 2026 23:29:00 +0000	[thread overview]
Message-ID: <20261203232859.321380-6-stuart.summers@intel.com> (raw)
In-Reply-To: <20261203232859.321380-4-stuart.summers@intel.com>

CRI media only supports 46-bit GPA. With the IOMMU handing out IOVAs
above 46 bits this shows up as ATS translation errors and a media
GuC load failure.

The workaround for this is broken into a couple of parts:
1) Media is now disabled by default on CRI.
2) When media is enabled, implement certain workarounds to
   ensure compute performance remains optimal and media accesses
   do not result in the above mentioned translation errors.

The first part of the workaround means for the customers who are
not interested in using media, they can retain the full 52-bit GPA
range for a broader PCIe installation without worrying about any
specific limitation to support the media workloads on this device.

Additionally, to ensure power is not consumed by media in this
configuration, a new interfaces is added between the KMD and the GFSP
firmware to bring media down into a low power state.

The second part of the workaround again is broken down into a few
parts:
1) The whole device is restricted to 46-bit GPA.
2) Disable address translation in the media block alone to allow
   faster translation for compute workloads with PCIe level address
   translation enabled while ensuring host accesses beyond 46-bits
   (e.g. coming from another 52-bit supporting device) are still
   limited to 46-bits for the CRI media.

Media needs every device DMA address to stay within 46 bits. With the
IOMMU translating device DMA that is guaranteed by the IOVA allocator
honoring the clamped mask. Without it, DMA addresses are host physical
addresses, so media stays enabled only when the architectural host
physical address limit fits in 46 bits (e.g. x86-64 with 4-level
paging). Beyond that the host can hand out an address media cannot
reach, so disable media.

In order to disable address translation for media, a certain register
programming which is not accessible from the host must be engaged. To
facilitate this, an additional new interface is added between the KMD
and the GFSP firmware to do this programming.

Media disable persists until a secondary bus reset, so it is only sent
at probe. Address translation disable is lost on power loss, so it is
sent again on resume from D3cold and system suspend.

HSDES: 14028632488

Signed-off-by: Stuart Summers <stuart.summers@intel.com>
Assisted-by: LLM
---
 drivers/gpu/drm/xe/xe_device.c                |  10 ++
 drivers/gpu/drm/xe/xe_device_wa_oob.rules     |   1 +
 drivers/gpu/drm/xe/xe_pci.c                   |  64 ++++++-
 drivers/gpu/drm/xe/xe_pm.c                    |   7 +-
 drivers/gpu/drm/xe/xe_sysctrl.c               | 164 ++++++++++++++++++
 drivers/gpu/drm/xe/xe_sysctrl.h               |   2 +
 drivers/gpu/drm/xe/xe_sysctrl_mailbox_types.h |  34 ++++
 drivers/gpu/drm/xe/xe_sysctrl_types.h         |   6 +
 8 files changed, 285 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index de89342f737e..1ef4908a7d69 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -1017,6 +1017,12 @@ int xe_device_probe(struct xe_device *xe)
 	if (err)
 		return err;
 
+	/*
+	 * Let the System Controller know how media is configured as early as
+	 * the mailbox allows, before any media GT is brought up.
+	 */
+	xe_sysctrl_media_probe(xe);
+
 	err = xe_ras_init(xe);
 	if (err)
 		return err;
@@ -1560,6 +1566,10 @@ int xe_device_resume(struct xe_device *xe, bool flr)
 
 	xe_sysctrl_pm_resume(xe);
 
+	err = xe_sysctrl_media_resume(xe);
+	if (err)
+		return err;
+
 	xe_irq_resume(xe);
 
 	for_each_gt(gt, xe, id) {
diff --git a/drivers/gpu/drm/xe/xe_device_wa_oob.rules b/drivers/gpu/drm/xe/xe_device_wa_oob.rules
index 300207596893..14308f90938e 100644
--- a/drivers/gpu/drm/xe/xe_device_wa_oob.rules
+++ b/drivers/gpu/drm/xe/xe_device_wa_oob.rules
@@ -8,3 +8,4 @@
 14026779378	PLATFORM(CRESCENTISLAND)
 14028586678	PLATFORM(CRESCENTISLAND)
 14028434957	PLATFORM(CRESCENTISLAND)
+14028632488	PLATFORM(CRESCENTISLAND)
diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
index 2771e1a60e47..d68f1050ee3d 100644
--- a/drivers/gpu/drm/xe/xe_pci.c
+++ b/drivers/gpu/drm/xe/xe_pci.c
@@ -7,6 +7,9 @@
 
 #include <kunit/static_stub.h>
 #include <linux/device/driver.h>
+#include <linux/dma-mapping.h>
+#include <linux/iommu.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/pm_runtime.h>
@@ -791,6 +794,54 @@ static int xe_probe_info_early(struct xe_device *xe,
 	return 0;
 }
 
+/*
+ * Number of address bits media is able to reach on CRI, where it has no
+ * address translation of its own.
+ */
+#define XE_CRI_MEDIA_ADDR_BITS	46
+
+static bool device_iommu_iova_backed(struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	return domain && domain->type != IOMMU_DOMAIN_IDENTITY;
+}
+
+/* Highest architectural physical address the host can produce */
+static u64 host_max_phys_addr(void)
+{
+#ifdef MAX_PHYSMEM_BITS
+	return DMA_BIT_MASK(MAX_PHYSMEM_BITS);
+#else
+	return (phys_addr_t)-1;
+#endif
+}
+
+/*
+ * Decide whether media can be used on CRI.  Media there cannot translate
+ * addresses, so it is only usable if device DMA is guaranteed to stay within
+ * XE_CRI_MEDIA_ADDR_BITS.  The IOMMU guarantees that by allocating IOVAs
+ * below the device dma mask.  Without it, DMA addresses are host physical
+ * addresses, so media is only usable when the host cannot produce an address
+ * wider than media can reach.
+ */
+static bool cri_media_addressable(struct xe_device *xe)
+{
+	u64 host_max_addr = host_max_phys_addr();
+
+	if (device_iommu_iova_backed(xe->drm.dev))
+		return true;
+
+	if (host_max_addr <= DMA_BIT_MASK(XE_CRI_MEDIA_ADDR_BITS))
+		return true;
+
+	drm_info(&xe->drm,
+		 "IOMMU is not translating device DMA and the host can produce %u bit physical addresses, media is limited to %u\n",
+		 fls64(host_max_addr), XE_CRI_MEDIA_ADDR_BITS);
+
+	return false;
+}
+
 /*
  * Whether the user wants media at all.  The default (-1) leaves the decision
  * to the driver.
@@ -798,7 +849,7 @@ static int xe_probe_info_early(struct xe_device *xe,
 static bool media_wanted(struct xe_device *xe)
 {
 	if (xe_modparam.enable_media < 0)
-		return true;
+		return !XE_DEVICE_WA(xe, 14028632488);
 
 	return xe_modparam.enable_media;
 }
@@ -830,9 +881,18 @@ static int xe_info_init_early(struct xe_device *xe,
 	xe_wa_process_device_oob(xe);
 
 	xe->info.media_allowed = media_wanted(xe) &&
-		xe_configfs_media_gt_allowed(to_pci_dev(xe->drm.dev));
+		xe_configfs_media_gt_allowed(to_pci_dev(xe->drm.dev)) &&
+		(!XE_DEVICE_WA(xe, 14028632488) || cri_media_addressable(xe));
 
 	xe->info.dma_mask_size = desc->dma_mask_size;
+	/*
+	 * Some device media blocks cannot address beyond 46 bits. Clamp the
+	 * dma_mask_size to reflect this.
+	 */
+	if (XE_DEVICE_WA(xe, 14028632488) && xe_device_media_allowed(xe))
+		xe->info.dma_mask_size = min_t(u8, xe->info.dma_mask_size,
+					       XE_CRI_MEDIA_ADDR_BITS);
+
 	xe->info.va_bits = desc->va_bits;
 	xe->info.vm_max_level = desc->vm_max_level;
 	xe->info.vram_flags = desc->vram_flags;
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index 51e020fbf9a6..1573fdd97b68 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -665,9 +665,14 @@ int xe_pm_runtime_resume(struct xe_device *xe)
 
 	xe_i2c_pm_resume(xe, xe->d3cold.allowed);
 
-	if (xe->d3cold.allowed)
+	if (xe->d3cold.allowed) {
 		xe_sysctrl_pm_resume(xe);
 
+		err = xe_sysctrl_media_resume(xe);
+		if (err)
+			goto out;
+	}
+
 	xe_display_pm_runtime_resume_early(xe);
 
 	xe_irq_resume(xe);
diff --git a/drivers/gpu/drm/xe/xe_sysctrl.c b/drivers/gpu/drm/xe/xe_sysctrl.c
index d362e8156fca..2fc4e35f3e25 100644
--- a/drivers/gpu/drm/xe/xe_sysctrl.c
+++ b/drivers/gpu/drm/xe/xe_sysctrl.c
@@ -5,9 +5,12 @@
 
 #include <linux/device.h>
 #include <linux/mutex.h>
+#include <linux/pci.h>
 
 #include <drm/drm_managed.h>
 
+#include <generated/xe_device_wa_oob.h>
+
 #include "regs/xe_irq_regs.h"
 #include "regs/xe_sysctrl_regs.h"
 #include "xe_device.h"
@@ -19,6 +22,7 @@
 #include "xe_sysctrl_mailbox.h"
 #include "xe_sysctrl_mailbox_types.h"
 #include "xe_sysctrl_types.h"
+#include "xe_wa.h"
 
 /**
  * DOC: System Controller (sysctrl)
@@ -103,6 +107,7 @@ int xe_sysctrl_init(struct xe_device *xe)
 
 	xe->soc_remapper.set_sysctrl_region(xe, SYSCTRL_MAILBOX_INDEX);
 	INIT_WORK(&sc->work, xe_sysctrl_work);
+	sc->has_media_feature_disable = true;
 
 	return devm_add_action_or_reset(xe->drm.dev, sysctrl_fini, xe);
 }
@@ -249,3 +254,162 @@ int xe_sysctrl_sdk_api_version(struct xe_device *xe, u16 *version)
 
 	return 0;
 }
+
+static int sysctrl_media_defeature(struct xe_device *xe, u8 feature)
+{
+	struct xe_sysctrl_media_defeature_req req = { .feature = feature };
+	struct xe_sysctrl_media_defeature_resp resp = {};
+	struct xe_sysctrl_mailbox_command cmd = {};
+	size_t out_len = 0;
+	int ret;
+
+	xe_sysctrl_create_command(&cmd, XE_SYSCTRL_GROUP_RUNTIME,
+				  XE_SYSCTRL_CMD_MEDIA_DEFEATURE,
+				  &req, sizeof(req), &resp, sizeof(resp));
+
+	ret = xe_sysctrl_send_command(&xe->sc, &cmd, &out_len);
+	if (ret)
+		return ret;
+
+	if (out_len != sizeof(resp)) {
+		xe_err(xe, "sysctrl: unexpected media defeature response length %zu (expected %zu)\n",
+		       out_len, sizeof(resp));
+		return -EPROTO;
+	}
+
+	return 0;
+}
+
+/* Check whether the ATS Enable bit is set in the PCI ATS Control register */
+static bool sysctrl_ats_enabled(struct xe_device *xe)
+{
+	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+	int ats_cap;
+	u16 ctrl;
+
+	ats_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
+	if (!ats_cap)
+		return false;
+
+	if (pci_read_config_word(pdev, ats_cap + PCI_ATS_CTRL, &ctrl))
+		return false;
+
+	return ctrl & PCI_ATS_CTRL_ENABLE;
+}
+
+/* Send the media defeature command, logging any failure */
+static int sysctrl_media_defeature_send(struct xe_device *xe, u8 feature)
+{
+	int ret;
+
+	ret = sysctrl_media_defeature(xe, feature);
+	if (ret)
+		xe_err(xe, "sysctrl: failed to defeature media (0x%02x): %pe\n",
+		       feature, ERR_PTR(ret));
+	else
+		xe_dbg(xe, "sysctrl: media defeature 0x%02x done\n", feature);
+
+	return ret;
+}
+
+/* Whether this platform needs the media defeature workaround at all */
+static bool sysctrl_media_defeature_needed(struct xe_device *xe)
+{
+	return XE_DEVICE_WA(xe, 14028632488) &&
+	       xe->info.has_soc_remapper_sysctrl &&
+	       xe->info.has_sysctrl &&
+	       xe->sc.has_media_feature_disable;
+}
+
+/**
+ * xe_sysctrl_media_resume() - Restore media address translation defeature
+ * @xe: xe device instance
+ *
+ * The media address translation defeature does not survive a power loss, so
+ * it must be requested again on resume from D3cold or system suspend whenever
+ * media is in use and ATS is enabled.  The media defeature sent at probe when
+ * media is not in use persists until a secondary bus reset, which cannot
+ * happen while the driver is bound, so it is not resent here.
+ *
+ * Return: 0 on success, error code on failure
+ */
+int xe_sysctrl_media_resume(struct xe_device *xe)
+{
+	if (!sysctrl_media_defeature_needed(xe) ||
+	    !xe_device_media_allowed(xe) || !sysctrl_ats_enabled(xe))
+		return 0;
+
+	return sysctrl_media_defeature_send(xe, XE_SYSCTRL_MEDIA_DEFEATURE_ATS_DISABLE);
+}
+
+/*
+ * Drop media from the device.  Only safe during probe, before the media GT is
+ * fully brought up.  The dma_mask_size cap derived from the early media
+ * decision is left in place, which is harmless since it is only more
+ * restrictive than needed.
+ */
+static void sysctrl_media_drop(struct xe_device *xe)
+{
+	struct xe_tile *tile;
+	u8 id;
+
+	xe->info.media_allowed = false;
+
+	for_each_tile(tile, xe, id) {
+		if (!tile->media_gt)
+			continue;
+
+		tile->media_gt = NULL;
+		xe->info.gt_count--;
+	}
+}
+
+/**
+ * xe_sysctrl_media_probe() - Configure media with the System Controller at probe
+ * @xe: xe device instance
+ *
+ * The driver and the System Controller must agree on the media configuration
+ * before media is used.  When media is in use and ATS is enabled, address
+ * translation for media is not supported and must be defeatured.  When media
+ * has been disabled, via either the enable_media modparam or the
+ * gt_types_allowed configfs attribute, media itself is defeatured so it does
+ * not consume power.
+ *
+ * Media cannot be used while the System Controller does not know how it is
+ * configured, so if address translation cannot be defeatured, media is
+ * defeatured and dropped instead and probe continues without it.  If that
+ * fails too, the System Controller is assumed not to support these requests
+ * and none are sent again.
+ *
+ * This is restricted to platforms that need this workaround and must be called
+ * before any media GT is brought up.
+ */
+void xe_sysctrl_media_probe(struct xe_device *xe)
+{
+	bool media_allowed = xe_device_media_allowed(xe);
+	int ret;
+
+	if (!sysctrl_media_defeature_needed(xe) || !xe->info.media_verx100)
+		return;
+
+	if (media_allowed) {
+		if (!sysctrl_ats_enabled(xe))
+			return;
+
+		if (!sysctrl_media_defeature_send(xe, XE_SYSCTRL_MEDIA_DEFEATURE_ATS_DISABLE)) {
+			xe_dbg(xe, "sysctrl: media address translation defeatured\n");
+			return;
+		}
+	}
+
+	ret = sysctrl_media_defeature_send(xe, XE_SYSCTRL_MEDIA_DEFEATURE_DISABLE);
+	if (ret)
+		xe->sc.has_media_feature_disable = false;
+	else
+		xe_dbg(xe, "sysctrl: media defeatured\n");
+
+	if (media_allowed) {
+		sysctrl_media_drop(xe);
+		xe_err(xe, "sysctrl: media configuration failed, continuing without media\n");
+	}
+}
diff --git a/drivers/gpu/drm/xe/xe_sysctrl.h b/drivers/gpu/drm/xe/xe_sysctrl.h
index c0b6d4330c88..f751986f7f84 100644
--- a/drivers/gpu/drm/xe/xe_sysctrl.h
+++ b/drivers/gpu/drm/xe/xe_sysctrl.h
@@ -18,6 +18,8 @@ static inline struct xe_device *sc_to_xe(struct xe_sysctrl *sc)
 
 void xe_sysctrl_event(struct xe_sysctrl *sc);
 int xe_sysctrl_init(struct xe_device *xe);
+void xe_sysctrl_media_probe(struct xe_device *xe);
+int xe_sysctrl_media_resume(struct xe_device *xe);
 void xe_sysctrl_irq_handler(struct xe_device *xe, u32 master_ctl);
 void xe_sysctrl_pm_resume(struct xe_device *xe);
 bool xe_sysctrl_is_oobmsm_fw_ready(struct xe_device *xe);
diff --git a/drivers/gpu/drm/xe/xe_sysctrl_mailbox_types.h b/drivers/gpu/drm/xe/xe_sysctrl_mailbox_types.h
index 50b1d9abaf1f..85ad92ffb2b1 100644
--- a/drivers/gpu/drm/xe/xe_sysctrl_mailbox_types.h
+++ b/drivers/gpu/drm/xe/xe_sysctrl_mailbox_types.h
@@ -15,11 +15,13 @@
  *
  * @XE_SYSCTRL_GROUP_GFSP: GFSP group
  * @XE_SYSCTRL_GROUP_DIAG: Diag group
+ * @XE_SYSCTRL_GROUP_RUNTIME: Runtime group
  * @XE_SYSCTRL_GROUP_CORE: Core group
  */
 enum xe_sysctrl_group {
 	XE_SYSCTRL_GROUP_GFSP			= 0x01,
 	XE_SYSCTRL_GROUP_DIAG			= 0x02,
+	XE_SYSCTRL_GROUP_RUNTIME		= 0x31,
 	XE_SYSCTRL_GROUP_CORE			= 0xFF,
 };
 
@@ -96,6 +98,38 @@ struct xe_sysctrl_diag_ras_err_inj_req {
 	u32 params;
 } __packed;
 
+/**
+ * enum xe_sysctrl_runtime_cmd - Commands supported by Runtime group
+ *
+ * @XE_SYSCTRL_CMD_MEDIA_DEFEATURE: Disable feature in media
+ */
+enum xe_sysctrl_runtime_cmd {
+	XE_SYSCTRL_CMD_MEDIA_DEFEATURE		= 0x11,
+};
+
+#define XE_SYSCTRL_MEDIA_DEFEATURE_DISABLE	0x01
+#define XE_SYSCTRL_MEDIA_DEFEATURE_ATS_DISABLE	0x02
+
+/**
+ * struct xe_sysctrl_media_defeature_req - Media defeature request
+ *
+ * @feature: Media feature to defeature, one of
+ *	XE_SYSCTRL_MEDIA_DEFEATURE_DISABLE or
+ *	XE_SYSCTRL_MEDIA_DEFEATURE_ATS_DISABLE
+ */
+struct xe_sysctrl_media_defeature_req {
+	u8 feature;
+} __packed;
+
+/**
+ * struct xe_sysctrl_media_defeature_resp - Media defeature response
+ *
+ * @flags: Firmware status flags
+ */
+struct xe_sysctrl_media_defeature_resp {
+	u32 flags;
+} __packed;
+
 /**
  * struct xe_sysctrl_app_status_req - Get application status request
  *
diff --git a/drivers/gpu/drm/xe/xe_sysctrl_types.h b/drivers/gpu/drm/xe/xe_sysctrl_types.h
index 605bdc62e0bf..1b44308b18b7 100644
--- a/drivers/gpu/drm/xe/xe_sysctrl_types.h
+++ b/drivers/gpu/drm/xe/xe_sysctrl_types.h
@@ -75,6 +75,12 @@ struct xe_sysctrl {
 	/** @event_lock: Mutex protecting pending events */
 	struct mutex event_lock;
 
+	/**
+	 * @has_media_feature_disable: The System Controller accepts media
+	 * defeature requests. Cleared only if they all fail at probe.
+	 */
+	bool has_media_feature_disable;
+
 	/** @debugfs: Debugfs entries */
 	struct {
 		/** @debugfs.root: Root debugfs directory */
-- 
2.43.0


  parent reply	other threads:[~2026-12-03 23:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 23:28 [PATCH 0/2] Work around 52-bit limitation in CRI media Stuart Summers
2026-12-03 23:28 ` [PATCH 1/2] drm/xe: Add enable_media module parameter Stuart Summers
2026-12-03 23:32   ` Summers, Stuart
2026-12-03 23:58   ` sashiko-bot
2026-12-03 23:29 ` Stuart Summers [this message]
2026-12-04  0:03   ` [PATCH 2/2] drm/xe: Work around media 52-bit limitation on CRI sashiko-bot
2026-12-04  0:52 ` ✗ CI.checkpatch: warning for Work around 52-bit limitation in CRI media (rev2) Patchwork
2026-12-04  0:54 ` ✓ CI.KUnit: success " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-12-03 19:09 [PATCH 0/2] Work around 52-bit limitation in CRI media Stuart Summers
2026-12-03 19:09 ` [PATCH 2/2] drm/xe: Work around media 52-bit limitation on CRI Stuart Summers
2026-12-03 19:31   ` sashiko-bot
2026-12-03 19:57     ` Summers, Stuart
2026-12-03 21:37   ` Rodrigo Vivi
2026-12-03 21:41     ` Summers, Stuart

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=20261203232859.321380-6-stuart.summers@intel.com \
    --to=stuart.summers@intel.com \
    --cc=alan.previn.teres.alexis@intel.com \
    --cc=anoop.c.vijay@intel.com \
    --cc=fei.yang@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.d.roper@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=thomas.hellstrom@linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox