mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/5] drm/xe/heci: expose the DG2 HECI1 interface to mei
       [not found] <20261126205758.49845-1-arisa.snowbell@gmail.com>
@ 2026-11-26 20:57 ` Arisa Snowbell
  2026-11-26 20:57 ` [PATCH 2/5] mei: gsc: bind the xe HECI1 device Arisa Snowbell
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Arisa Snowbell @ 2026-11-26 20:57 UTC (permalink / raw)
  To: intel-xe
  Cc: dri-devel, Daniele Ceraolo Spurio, Arisa Snowbell, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Himal Prasad Ghimiray, Badal Nilawar, Nareshkumar Gollakoti,
	linux-kernel

On DG2 the HuC is loaded and authenticated by the GSC, through the PXP
client that lives on HECI1. Like i915 (intel_gsc.c), add HECI1 as the
"mei-gsc" auxiliary device with 4 MiB of VRAM as the GSC extended
operational memory, and route its interrupt (GSC_IRQ_INTF(0)).

HECI2 keeps its current setup; a HECI1 failure only leaves the HuC
unauthenticated and does not fail the probe.

Signed-off-by: Arisa Snowbell <arisa.snowbell@gmail.com>
---
 drivers/gpu/drm/xe/regs/xe_gsc_regs.h |   1 +
 drivers/gpu/drm/xe/xe_heci_gsc.c      | 171 +++++++++++++++++++-------
 drivers/gpu/drm/xe/xe_heci_gsc.h      |  27 +++-
 drivers/gpu/drm/xe/xe_irq.c           |   2 +
 4 files changed, 149 insertions(+), 52 deletions(-)

diff --git a/drivers/gpu/drm/xe/regs/xe_gsc_regs.h b/drivers/gpu/drm/xe/regs/xe_gsc_regs.h
index 180be8267..6b7551bcf 100644
--- a/drivers/gpu/drm/xe/regs/xe_gsc_regs.h
+++ b/drivers/gpu/drm/xe/regs/xe_gsc_regs.h
@@ -20,6 +20,7 @@
 
 #define DG1_GSC_HECI2_BASE	0x00259000
 #define PVC_GSC_HECI2_BASE	0x00285000
+#define DG2_GSC_HECI1_BASE	0x00373000
 #define DG2_GSC_HECI2_BASE	0x00374000
 
 #define HECI_H_CSR(base)	XE_REG((base) + 0x4)
diff --git a/drivers/gpu/drm/xe/xe_heci_gsc.c b/drivers/gpu/drm/xe/xe_heci_gsc.c
index 5af8903e1..d5e081d99 100644
--- a/drivers/gpu/drm/xe/xe_heci_gsc.c
+++ b/drivers/gpu/drm/xe/xe_heci_gsc.c
@@ -10,8 +10,11 @@
 
 #include <drm/drm_print.h>
 
+#include "xe_bo.h"
+#include "xe_device.h"
 #include "xe_device_types.h"
 #include "xe_heci_gsc.h"
+#include "xe_map.h"
 #include "regs/xe_gsc_regs.h"
 #include "xe_platform_types.h"
 #include "xe_survivability_mode.h"
@@ -50,6 +53,7 @@ static int heci_gsc_irq_init(int irq)
  * @bar_size: size of the mmio bar
  * @use_polling: indication of using polling mode for the device
  * @slow_firmware: indication of whether the device is slow (needs longer timeouts)
+ * @lmem_size: size of the extended operational memory the GSC needs, in VRAM
  */
 struct heci_gsc_def {
 	const char *name;
@@ -57,6 +61,7 @@ struct heci_gsc_def {
 	size_t bar_size;
 	bool use_polling;
 	bool slow_firmware;
+	size_t lmem_size;
 };
 
 /* gsc resources and definitions */
@@ -72,6 +77,14 @@ static const struct heci_gsc_def heci_gsc_def_dg2 = {
 	.bar_size = GSC_BAR_LENGTH,
 };
 
+/* HECI1 carries the PXP client that loads and authenticates the HuC on DG2 */
+static const struct heci_gsc_def heci_gsc_def_dg2_heci1 = {
+	.name = "mei-gsc",
+	.bar = DG2_GSC_HECI1_BASE,
+	.bar_size = GSC_BAR_LENGTH,
+	.lmem_size = SZ_4M,
+};
+
 static const struct heci_gsc_def heci_gsc_def_pvc = {
 	.name = "mei-gscfi",
 	.bar = PVC_GSC_HECI2_BASE,
@@ -87,54 +100,108 @@ static void heci_gsc_release_dev(struct device *dev)
 	kfree(adev);
 }
 
+static void heci_gsc_intf_fini(struct xe_heci_gsc_intf *intf)
+{
+	if (intf->adev) {
+		struct auxiliary_device *aux_dev = &intf->adev->aux_dev;
+
+		auxiliary_device_delete(aux_dev);
+		auxiliary_device_uninit(aux_dev);
+		intf->adev = NULL;
+	}
+
+	if (intf->irq >= 0) {
+		int irq = intf->irq;
+
+		/* the interrupt handler checks it first */
+		intf->irq = -1;
+		irq_free_desc(irq);
+	}
+
+	if (intf->ext_op_mem) {
+		xe_bo_unpin_map_no_vm(intf->ext_op_mem);
+		intf->ext_op_mem = NULL;
+	}
+}
+
 static void xe_heci_gsc_fini(void *arg)
 {
 	struct xe_heci_gsc *heci_gsc = arg;
 
-	if (heci_gsc->adev) {
-		struct auxiliary_device *aux_dev = &heci_gsc->adev->aux_dev;
-
-		auxiliary_device_delete(aux_dev);
-		auxiliary_device_uninit(aux_dev);
-		heci_gsc->adev = NULL;
-	}
-
-	if (heci_gsc->irq >= 0)
-		irq_free_desc(heci_gsc->irq);
-
-	heci_gsc->irq = -1;
+	heci_gsc_intf_fini(&heci_gsc->intf[XE_HECI1]);
+	heci_gsc_intf_fini(&heci_gsc->intf[XE_HECI2]);
 }
 
-static int heci_gsc_irq_setup(struct xe_device *xe)
+static int heci_gsc_irq_setup(struct xe_device *xe, struct xe_heci_gsc_intf *intf)
 {
-	struct xe_heci_gsc *heci_gsc = &xe->heci_gsc;
 	int ret;
 
-	heci_gsc->irq = irq_alloc_desc(0);
-	if (heci_gsc->irq < 0) {
-		drm_err(&xe->drm, "gsc irq error %d\n", heci_gsc->irq);
-		return heci_gsc->irq;
+	intf->irq = irq_alloc_desc(0);
+	if (intf->irq < 0) {
+		drm_err(&xe->drm, "gsc irq error %d\n", intf->irq);
+		return intf->irq;
 	}
 
-	ret = heci_gsc_irq_init(heci_gsc->irq);
+	ret = heci_gsc_irq_init(intf->irq);
 	if (ret < 0)
 		drm_err(&xe->drm, "gsc irq init failed %d\n", ret);
 
 	return ret;
 }
 
-static int heci_gsc_add_device(struct xe_device *xe, const struct heci_gsc_def *def)
+static int heci_gsc_ext_op_mem_alloc(struct xe_device *xe, struct xe_heci_gsc_intf *intf,
+				     struct mei_aux_device *adev, size_t size)
 {
-	struct xe_heci_gsc *heci_gsc = &xe->heci_gsc;
+	struct xe_tile *tile = xe_device_get_root_tile(xe);
+	struct xe_bo *bo;
+
+	/* pinned VRAM BOs are contiguous, the GSC only gets a base and a limit */
+	bo = xe_bo_create_pin_map_novm(xe, tile, size, ttm_bo_type_kernel,
+				       XE_BO_FLAG_VRAM_IF_DGFX(tile), false);
+	if (IS_ERR(bo))
+		return PTR_ERR(bo);
+
+	xe_map_memset(xe, &bo->vmap, 0, 0, size);
+	intf->ext_op_mem = bo;
+
+	adev->ext_op_mem.start = xe_bo_main_addr(bo, PAGE_SIZE);
+	adev->ext_op_mem.end = adev->ext_op_mem.start + size;
+
+	drm_dbg(&xe->drm, "GSC HECI1: extended operational memory at DPA %pa\n",
+		&adev->ext_op_mem.start);
+
+	return 0;
+}
+
+static int heci_gsc_add_device(struct xe_device *xe, const struct heci_gsc_def *def,
+			       enum xe_heci_intf intf_id)
+{
+	struct xe_heci_gsc_intf *intf = &xe->heci_gsc.intf[intf_id];
 	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
 	struct auxiliary_device *aux_dev;
 	struct mei_aux_device *adev;
 	int ret;
 
+	if (!def->use_polling && !xe_survivability_mode_is_boot_enabled(xe)) {
+		ret = heci_gsc_irq_setup(xe, intf);
+		if (ret)
+			return ret;
+	}
+
 	adev = kzalloc_obj(*adev);
 	if (!adev)
 		return -ENOMEM;
-	adev->irq = heci_gsc->irq;
+
+	if (def->lmem_size) {
+		ret = heci_gsc_ext_op_mem_alloc(xe, intf, adev, def->lmem_size);
+		if (ret) {
+			drm_err(&xe->drm, "gsc extended operational memory failed %d\n", ret);
+			kfree(adev);
+			return ret;
+		}
+	}
+
+	adev->irq = intf->irq;
 	adev->bar.parent = &pdev->resource[0];
 	adev->bar.start = def->bar + pdev->resource[0].start;
 	adev->bar.end = adev->bar.start + def->bar_size - 1;
@@ -156,11 +223,11 @@ static int heci_gsc_add_device(struct xe_device *xe, const struct heci_gsc_def *
 		return ret;
 	}
 
-	heci_gsc->adev = adev; /* needed by the notifier */
+	intf->adev = adev; /* needed by the notifier */
 	ret = auxiliary_device_add(aux_dev);
 	if (ret < 0) {
 		drm_err(&xe->drm, "gsc aux add failed %d\n", ret);
-		heci_gsc->adev = NULL;
+		intf->adev = NULL;
 
 		/* adev will be freed with the put_device() and .release sequence */
 		auxiliary_device_uninit(aux_dev);
@@ -177,7 +244,8 @@ int xe_heci_gsc_init(struct xe_device *xe)
 	if (!xe->info.has_heci_gscfi && !xe->info.has_heci_cscfi)
 		return 0;
 
-	heci_gsc->irq = -1;
+	heci_gsc->intf[XE_HECI1].irq = -1;
+	heci_gsc->intf[XE_HECI2].irq = -1;
 
 	if (xe->info.platform == XE_BATTLEMAGE) {
 		def = &heci_gsc_def_dg2;
@@ -198,20 +266,38 @@ int xe_heci_gsc_init(struct xe_device *xe)
 	if (ret)
 		return ret;
 
-	if (!def->use_polling && !xe_survivability_mode_is_boot_enabled(xe)) {
-		ret = heci_gsc_irq_setup(xe);
-		if (ret)
-			return ret;
+	ret = heci_gsc_add_device(xe, def, XE_HECI2);
+	if (ret)
+		return ret;
+
+	/*
+	 * HECI1 failing only costs the HuC (it stays unauthenticated), so it
+	 * must not fail the probe.
+	 */
+	if (xe->info.platform == XE_DG2 && !xe_survivability_mode_is_boot_enabled(xe) &&
+	    heci_gsc_add_device(xe, &heci_gsc_def_dg2_heci1, XE_HECI1)) {
+		drm_warn(&xe->drm, "GSC HECI1 not available, HuC will not be authenticated\n");
+		heci_gsc_intf_fini(&heci_gsc->intf[XE_HECI1]);
 	}
 
-	return heci_gsc_add_device(xe, def);
+	return 0;
+}
+
+static void heci_gsc_intf_irq(struct xe_device *xe, struct xe_heci_gsc_intf *intf)
+{
+	int ret;
+
+	if (intf->irq < 0)
+		return;
+
+	ret = generic_handle_irq_safe(intf->irq);
+	if (ret)
+		drm_err_ratelimited(&xe->drm, "error handling GSC irq: %d\n", ret);
 }
 
 void xe_heci_gsc_irq_handler(struct xe_device *xe, u32 iir)
 {
-	int ret;
-
-	if ((iir & GSC_IRQ_INTF(1)) == 0)
+	if ((iir & (GSC_IRQ_INTF(0) | GSC_IRQ_INTF(1))) == 0)
 		return;
 
 	if (!xe->info.has_heci_gscfi) {
@@ -219,18 +305,14 @@ void xe_heci_gsc_irq_handler(struct xe_device *xe, u32 iir)
 		return;
 	}
 
-	if (xe->heci_gsc.irq < 0)
-		return;
-
-	ret = generic_handle_irq_safe(xe->heci_gsc.irq);
-	if (ret)
-		drm_err_ratelimited(&xe->drm, "error handling GSC irq: %d\n", ret);
+	if (iir & GSC_IRQ_INTF(0))
+		heci_gsc_intf_irq(xe, &xe->heci_gsc.intf[XE_HECI1]);
+	if (iir & GSC_IRQ_INTF(1))
+		heci_gsc_intf_irq(xe, &xe->heci_gsc.intf[XE_HECI2]);
 }
 
 void xe_heci_csc_irq_handler(struct xe_device *xe, u32 iir)
 {
-	int ret;
-
 	if ((iir & CSC_IRQ_INTF(1)) == 0)
 		return;
 
@@ -239,10 +321,5 @@ void xe_heci_csc_irq_handler(struct xe_device *xe, u32 iir)
 		return;
 	}
 
-	if (xe->heci_gsc.irq < 0)
-		return;
-
-	ret = generic_handle_irq_safe(xe->heci_gsc.irq);
-	if (ret)
-		drm_err_ratelimited(&xe->drm, "error handling GSC irq: %d\n", ret);
+	heci_gsc_intf_irq(xe, &xe->heci_gsc.intf[XE_HECI2]);
 }
diff --git a/drivers/gpu/drm/xe/xe_heci_gsc.h b/drivers/gpu/drm/xe/xe_heci_gsc.h
index a76f4122b..947743827 100644
--- a/drivers/gpu/drm/xe/xe_heci_gsc.h
+++ b/drivers/gpu/drm/xe/xe_heci_gsc.h
@@ -7,6 +7,7 @@
 
 #include <linux/types.h>
 
+struct xe_bo;
 struct xe_device;
 struct mei_aux_device;
 
@@ -21,16 +22,32 @@ struct mei_aux_device;
  */
 #define CSC_IRQ_INTF(_x) BIT(9 + (_x))
 
+enum xe_heci_intf {
+	XE_HECI1,
+	XE_HECI2,
+	XE_HECI_COUNT,
+};
+
 /**
- * struct xe_heci_gsc - graphics security controller for xe, HECI interface
- *
- * @adev : pointer to mei auxiliary device structure
- * @irq : irq number
+ * struct xe_heci_gsc_intf - one HECI interface of the GSC
  *
+ * @adev: mei auxiliary device of the interface
+ * @irq: irq number, -1 when polled
+ * @ext_op_mem: VRAM the GSC uses as extended operational memory, if any
  */
-struct xe_heci_gsc {
+struct xe_heci_gsc_intf {
 	struct mei_aux_device *adev;
 	int irq;
+	struct xe_bo *ext_op_mem;
+};
+
+/**
+ * struct xe_heci_gsc - graphics security controller for xe, HECI interfaces
+ *
+ * @intf: HECI1 (DG2 PXP and HuC) and HECI2 (firmware interface)
+ */
+struct xe_heci_gsc {
+	struct xe_heci_gsc_intf intf[XE_HECI_COUNT];
 };
 
 int xe_heci_gsc_init(struct xe_device *xe);
diff --git a/drivers/gpu/drm/xe/xe_irq.c b/drivers/gpu/drm/xe/xe_irq.c
index 187140965..b8449bf80 100644
--- a/drivers/gpu/drm/xe/xe_irq.c
+++ b/drivers/gpu/drm/xe/xe_irq.c
@@ -247,6 +247,8 @@ void xe_irq_enable_hwe(struct xe_gt *gt)
 		if (other_fuse_mask) {
 			gsc_mask = common_mask | GSC_ER_COMPLETE;
 			heci_mask = GSC_IRQ_INTF(1);
+		} else if (xe->info.platform == XE_DG2) {
+			gsc_mask = GSC_IRQ_INTF(0) | GSC_IRQ_INTF(1);
 		} else if (xe->info.has_heci_gscfi) {
 			gsc_mask = GSC_IRQ_INTF(1);
 		}
-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/5] mei: gsc: bind the xe HECI1 device
       [not found] <20261126205758.49845-1-arisa.snowbell@gmail.com>
  2026-11-26 20:57 ` [PATCH 1/5] drm/xe/heci: expose the DG2 HECI1 interface to mei Arisa Snowbell
@ 2026-11-26 20:57 ` Arisa Snowbell
  2026-11-26 20:57 ` [PATCH 3/5] drm/xe/huc: load the DG2 HuC through the GSC via mei_pxp Arisa Snowbell
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Arisa Snowbell @ 2026-11-26 20:57 UTC (permalink / raw)
  To: intel-xe
  Cc: dri-devel, Daniele Ceraolo Spurio, Arisa Snowbell,
	Alexander Usyskin, Arnd Bergmann, Greg Kroah-Hartman,
	linux-kernel

xe now exposes the DG2 HECI1 interface as "xe.mei-gsc", the same
interface i915 exposes as "i915.mei-gsc".

Signed-off-by: Arisa Snowbell <arisa.snowbell@gmail.com>
---
 drivers/misc/mei/gsc-me.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/misc/mei/gsc-me.c b/drivers/misc/mei/gsc-me.c
index b38ddb04f..69019d5c4 100644
--- a/drivers/misc/mei/gsc-me.c
+++ b/drivers/misc/mei/gsc-me.c
@@ -276,6 +276,10 @@ static const struct auxiliary_device_id mei_gsc_id_table[] = {
 		.name = "xe.mei-gscfi",
 		.driver_data = MEI_ME_GSCFI_CFG,
 	},
+	{
+		.name = "xe.mei-gsc",
+		.driver_data = MEI_ME_GSC_CFG,
+	},
 	{
 		/* sentinel */
 	}
@@ -297,5 +301,6 @@ MODULE_AUTHOR("Intel Corporation");
 MODULE_ALIAS("auxiliary:i915.mei-gsc");
 MODULE_ALIAS("auxiliary:i915.mei-gscfi");
 MODULE_ALIAS("auxiliary:xe.mei-gscfi");
+MODULE_ALIAS("auxiliary:xe.mei-gsc");
 MODULE_DESCRIPTION("Intel(R) Graphics System Controller");
 MODULE_LICENSE("GPL");
-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/5] drm/xe/huc: load the DG2 HuC through the GSC via mei_pxp
       [not found] <20261126205758.49845-1-arisa.snowbell@gmail.com>
  2026-11-26 20:57 ` [PATCH 1/5] drm/xe/heci: expose the DG2 HECI1 interface to mei Arisa Snowbell
  2026-11-26 20:57 ` [PATCH 2/5] mei: gsc: bind the xe HECI1 device Arisa Snowbell
@ 2026-11-26 20:57 ` Arisa Snowbell
  2026-11-26 20:57 ` [PATCH 4/5] drm/xe: hold video decode work and HuC queries for a pending DG2 HuC load Arisa Snowbell
  2026-11-26 20:57 ` [PATCH 5/5] drm/xe/uc_fw: select the DG2 HuC blob for a load by the GSC Arisa Snowbell
  4 siblings, 0 replies; 5+ messages in thread
From: Arisa Snowbell @ 2026-11-26 20:57 UTC (permalink / raw)
  To: intel-xe
  Cc: dri-devel, Daniele Ceraolo Spurio, Arisa Snowbell, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Sumit Semwal, Christian König, Philipp Stanner,
	Nareshkumar Gollakoti, Badal Nilawar, Himal Prasad Ghimiray,
	linux-kernel, linux-media, linaro-mm-sig

On DG2 the GSC both loads and authenticates the HuC. Register as the
I915_COMPONENT_PXP component, as i915 does, so mei_pxp hands us its ops,
and send PXP43 START_HUC_AUTH with the DPA of the firmware in VRAM through
gsc_command(), whose request and reply live in a VRAM page. Leaving the
GSC to mei keeps two drivers from driving the same hardware.

The load is asynchronous. It runs from a worker after every uC load
(probe, GT reset, resume) and when mei binds; a stop before a reset, a
suspend or an FLR waits for a running load and drops a pending one. Each
load gets a fence that signals when it succeeded, failed or stopped
waiting for mei. If mei_pxp does not bind within 10 s the HuC stays
unloaded and later loads stop waiting for it until it binds, as i915's
INTEL_HUC_DELAYED_LOAD_ERROR does.

As on i915, the GSC must be the one loading the HuC (GSC_LOADS_HUC), and
a missing mei module or a failed setup only leaves the HuC unloaded.

A GSC command that never returns still holds up a stop, as on i915; a
mei reset ends it. Video decode does not wait on it past the 10 s.

Nothing selects a DG2 HuC blob yet, so this changes nothing on its own.

Signed-off-by: Arisa Snowbell <arisa.snowbell@gmail.com>
---
 drivers/gpu/drm/xe/Makefile           |   1 +
 drivers/gpu/drm/xe/regs/xe_guc_regs.h |   3 +
 drivers/gpu/drm/xe/xe_huc.c           |  16 +-
 drivers/gpu/drm/xe/xe_huc_mei.c       | 569 ++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_huc_mei.h       |  21 +
 drivers/gpu/drm/xe/xe_huc_types.h     |  57 +++
 drivers/gpu/drm/xe/xe_uc.c            |   7 +
 7 files changed, 673 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/xe/xe_huc_mei.c
 create mode 100644 drivers/gpu/drm/xe/xe_huc_mei.h

diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
index ad3ab8097..a974055fe 100644
--- a/drivers/gpu/drm/xe/Makefile
+++ b/drivers/gpu/drm/xe/Makefile
@@ -81,6 +81,7 @@ xe-y += xe_bb.o \
 	xe_guc_tlb_inval.o \
 	xe_heci_gsc.o \
 	xe_huc.o \
+	xe_huc_mei.o \
 	xe_hw_engine.o \
 	xe_hw_engine_class_sysfs.o \
 	xe_hw_engine_group.o \
diff --git a/drivers/gpu/drm/xe/regs/xe_guc_regs.h b/drivers/gpu/drm/xe/regs/xe_guc_regs.h
index 5a8a67eb3..520e2a15b 100644
--- a/drivers/gpu/drm/xe/regs/xe_guc_regs.h
+++ b/drivers/gpu/drm/xe/regs/xe_guc_regs.h
@@ -60,6 +60,9 @@
 #define   GUC_ENABLE_READ_CACHE_LOGIC		REG_BIT(1)
 #define   GUC_DISABLE_SRAM_INIT_TO_ZEROES	REG_BIT(0)
 
+#define GUC_SHIM_CONTROL2			XE_REG(0xc068)
+#define   GSC_LOADS_HUC				REG_BIT(30)
+
 #define SOFT_SCRATCH(n)				XE_REG(0xc180 + (n) * 4)
 #define SOFT_SCRATCH_COUNT			16
 
diff --git a/drivers/gpu/drm/xe/xe_huc.c b/drivers/gpu/drm/xe/xe_huc.c
index c73e1acbd..0a2f0688e 100644
--- a/drivers/gpu/drm/xe/xe_huc.c
+++ b/drivers/gpu/drm/xe/xe_huc.c
@@ -19,6 +19,7 @@
 #include "xe_gt.h"
 #include "xe_gt_printk.h"
 #include "xe_guc.h"
+#include "xe_huc_mei.h"
 #include "xe_map.h"
 #include "xe_mmio.h"
 #include "xe_sriov.h"
@@ -91,7 +92,8 @@ int xe_huc_init(struct xe_huc *huc)
 	if (IS_SRIOV_VF(xe))
 		return 0;
 
-	if (huc->fw.has_gsc_headers) {
+	/* on DG2 the GSC loads the HuC through mei, not via GSCCS packets */
+	if (huc->fw.has_gsc_headers && xe->info.platform != XE_DG2) {
 		ret = huc_alloc_gsc_pkt(huc);
 		if (ret)
 			goto out;
@@ -122,6 +124,8 @@ int xe_huc_init_post_hwconfig(struct xe_huc *huc)
 	if (ret)
 		return ret;
 
+	xe_huc_mei_init(huc);
+
 	return 0;
 }
 
@@ -129,6 +133,11 @@ int xe_huc_upload(struct xe_huc *huc)
 {
 	if (!xe_uc_fw_is_loadable(&huc->fw))
 		return 0;
+
+	/* the GSC loads it from VRAM itself */
+	if (xe_huc_mei_is_used(huc))
+		return 0;
+
 	return xe_uc_fw_upload(&huc->fw, 0, HUC_UKERNEL);
 }
 
@@ -244,6 +253,11 @@ int xe_huc_auth(struct xe_huc *huc, enum xe_huc_auth_types type)
 	if (!xe_uc_fw_is_loadable(&huc->fw))
 		return 0;
 
+	if (xe_huc_mei_is_used(huc)) {
+		xe_huc_mei_start(huc);
+		return 0;
+	}
+
 	/* On newer platforms the HuC survives reset, so no need to re-auth */
 	if (xe_huc_is_authenticated(huc, type)) {
 		xe_uc_fw_change_status(&huc->fw, XE_UC_FIRMWARE_RUNNING);
diff --git a/drivers/gpu/drm/xe/xe_huc_mei.c b/drivers/gpu/drm/xe/xe_huc_mei.c
new file mode 100644
index 000000000..595405c4a
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_huc_mei.c
@@ -0,0 +1,569 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2016-2022 Intel Corporation
+ * Copyright © 2026 Arisa Snowbell
+ */
+
+/*
+ * HuC load and authentication by the GSC, through mei (DG2).
+ *
+ * On DG2 the GSC both loads and authenticates the HuC. It is reached through
+ * the PXP client on HECI1, owned by mei; mei_pxp hands us its ops as an
+ * I915_COMPONENT_PXP component, as for i915 (intel_pxp_tee.c). Messages go
+ * through gsc_command(), which takes the request and the reply as a
+ * scatterlist in device memory.
+ *
+ * The load is asynchronous: mei binds some time after probe and again after
+ * every system resume, and the HuC is lost on every reset and suspend. While a
+ * load is pending, user submissions to the video decode engines wait for it on
+ * a fence, as on i915.
+ */
+
+#include <linux/component.h>
+#include <linux/dma-fence.h>
+#include <linux/scatterlist.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#include <drm/drm_managed.h>
+#include <drm/intel/i915_component.h>
+#include <drm/intel/i915_pxp_tee_interface.h>
+
+#include "abi/gsc_pxp_commands_abi.h"
+#include "regs/xe_guc_regs.h"
+#include "xe_bo.h"
+#include "xe_device.h"
+#include "xe_force_wake.h"
+#include "xe_gt_printk.h"
+#include "xe_huc.h"
+#include "xe_huc_mei.h"
+#include "xe_map.h"
+#include "xe_mmio.h"
+#include "xe_pm.h"
+#include "xe_uc_fw.h"
+
+#define PXP43_CMDID_START_HUC_AUTH 0x0000003A /* DG2 */
+
+/* PXP-Input-Packet: HuC load and authentication */
+struct pxp43_start_huc_auth_in {
+	struct pxp_cmd_header header;
+	__le64 huc_base_address;
+} __packed;
+
+/*
+ * mei binds a few seconds after probe and re-binds after a system resume; past
+ * this, media runs without HuC and later loads stop waiting for mei.
+ */
+#define HUC_MEI_COMPONENT_TIMEOUT_MS 10000
+
+/* The GSC loads the whole binary before it flags the authentication */
+#define HUC_MEI_AUTH_TIMEOUT_US 1000000
+
+/* A safety net: the deadline above always settles a pending load first */
+#define HUC_MEI_SETTLE_TIMEOUT_MS 15000
+
+static struct xe_huc *mei_to_huc(struct xe_huc_mei *mei)
+{
+	return container_of(mei, struct xe_huc, mei);
+}
+
+static struct xe_gt *huc_to_gt(struct xe_huc *huc)
+{
+	return container_of(huc, struct xe_gt, uc.huc);
+}
+
+static struct xe_gt *mei_to_gt(struct xe_huc_mei *mei)
+{
+	return huc_to_gt(mei_to_huc(mei));
+}
+
+static const char *huc_mei_fence_driver_name(struct dma_fence *fence)
+{
+	return "xe";
+}
+
+static const char *huc_mei_fence_timeline_name(struct dma_fence *fence)
+{
+	return "huc_load";
+}
+
+static const struct dma_fence_ops huc_mei_fence_ops = {
+	.get_driver_name = huc_mei_fence_driver_name,
+	.get_timeline_name = huc_mei_fence_timeline_name,
+};
+
+/* Its own lock: users of the fence may outlive the device */
+struct huc_mei_fence {
+	struct dma_fence base;
+	spinlock_t lock; /* the lock of @base */
+};
+
+/* start() runs in the reset and resume paths, which must not wait on reclaim */
+static struct dma_fence *huc_mei_fence_create(struct xe_huc_mei *mei)
+{
+	struct huc_mei_fence *fence = kzalloc_obj(*fence, GFP_NOWAIT | __GFP_NOWARN);
+
+	if (!fence)
+		return NULL;
+
+	spin_lock_init(&fence->lock);
+	dma_fence_init(&fence->base, &huc_mei_fence_ops, &fence->lock,
+		       mei->fence_context, atomic64_inc_return(&mei->seqno));
+
+	return &fence->base;
+}
+
+/**
+ * xe_huc_mei_is_used() - whether the GSC loads this HuC through mei
+ * @huc: the HuC
+ *
+ * Return: true on DG2 once its HuC is set up to load through the GSC.
+ */
+bool xe_huc_mei_is_used(struct xe_huc *huc)
+{
+	return huc->mei.state != XE_HUC_MEI_UNUSED;
+}
+
+static u32 huc_mei_load_info(struct xe_gt *gt)
+{
+	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
+	if (!fw_ref.domains)
+		return 0;
+
+	return xe_mmio_read32(&gt->mmio, HUC_KERNEL_LOAD_INFO);
+}
+
+/* Ends the wait of the current load */
+static void huc_mei_settle_locked(struct xe_huc_mei *mei)
+{
+	lockdep_assert_held(&mei->state_lock);
+
+	if (mei->state != XE_HUC_MEI_LOADING)
+		return;
+
+	mei->state = XE_HUC_MEI_SETTLED;
+	if (mei->load)
+		dma_fence_signal(mei->load);
+	cancel_delayed_work(&mei->deadline);
+}
+
+static int huc_mei_send_auth(struct xe_huc *huc, struct i915_pxp_component *pxp)
+{
+	struct xe_gt *gt = huc_to_gt(huc);
+	struct xe_device *xe = gt_to_xe(gt);
+	struct xe_bo *msg = huc->mei.msg;
+	struct pxp43_start_huc_auth_in in = {};
+	struct pxp43_huc_auth_out out = {};
+	struct scatterlist sg;
+	dma_addr_t huc_addr = xe_bo_main_addr(huc->fw.bo, PAGE_SIZE);
+	ssize_t ret;
+
+	in.header.api_version = PXP_APIVER(4, 3);
+	in.header.command_id = PXP43_CMDID_START_HUC_AUTH;
+	in.header.buffer_len = sizeof(in.huc_base_address);
+	in.huc_base_address = cpu_to_le64(huc_addr);
+
+	xe_map_memset(xe, &msg->vmap, 0, 0, PAGE_SIZE);
+	xe_map_memcpy_to(xe, &msg->vmap, 0, &in, sizeof(in));
+
+	/* the same page carries the request and the reply, as on i915 */
+	sg_init_table(&sg, 1);
+	sg.length = PAGE_SIZE;
+	sg_dma_address(&sg) = xe_bo_main_addr(msg, PAGE_SIZE);
+	sg_dma_len(&sg) = PAGE_SIZE;
+
+	xe_gt_dbg(gt, "HuC: asking the GSC to load %zu bytes at DPA %pad\n",
+		  xe_bo_size(huc->fw.bo), &huc_addr);
+
+	ret = pxp->ops->gsc_command(pxp->tee_dev, 0, 0, &sg, sizeof(in), &sg);
+	if (ret < 0) {
+		xe_gt_err(gt, "HuC: GSC command failed: %pe\n", ERR_PTR(ret));
+		return ret;
+	}
+	if (ret < (ssize_t)sizeof(out.header)) {
+		xe_gt_err(gt, "HuC: GSC reply too short: %zd bytes\n", ret);
+		return -EPROTO;
+	}
+
+	xe_map_memcpy_from(xe, &out, &msg->vmap, 0, sizeof(out));
+
+	/*
+	 * HuC can survive a shallow suspend, the GSC then refuses the load with
+	 * OP_NOT_PERMITTED; the status register check that follows still
+	 * catches a HuC that is not there.
+	 */
+	if (out.header.status != PXP_STATUS_SUCCESS &&
+	    out.header.status != PXP_STATUS_OP_NOT_PERMITTED) {
+		xe_gt_err(gt, "HuC: GSC refused the load: %#x\n", out.header.status);
+		return -EPROTO;
+	}
+
+	return 0;
+}
+
+static int huc_mei_load_and_auth(struct xe_huc *huc)
+{
+	struct xe_gt *gt = huc_to_gt(huc);
+	struct xe_huc_mei *mei = &huc->mei;
+	int ret;
+
+	if (huc_mei_load_info(gt) & HUC_LOAD_SUCCESSFUL)
+		return 0;
+
+	scoped_guard(mutex, &mei->lock) {
+		/* mei binds later; the bind queues this again */
+		if (!mei->pxp)
+			return -EAGAIN;
+
+		ret = huc_mei_send_auth(huc, mei->pxp);
+		if (ret)
+			return ret;
+	}
+
+	xe_uc_fw_change_status(&huc->fw, XE_UC_FIRMWARE_TRANSFERRED);
+
+	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
+	if (!fw_ref.domains)
+		return -ETIMEDOUT;
+
+	ret = xe_mmio_wait32(&gt->mmio, HUC_KERNEL_LOAD_INFO, HUC_LOAD_SUCCESSFUL,
+			     HUC_LOAD_SUCCESSFUL, HUC_MEI_AUTH_TIMEOUT_US, NULL, false);
+	if (ret)
+		xe_gt_err(gt, "HuC: not authenticated after the GSC load, status %#x\n",
+			  xe_mmio_read32(&gt->mmio, HUC_KERNEL_LOAD_INFO));
+
+	return ret;
+}
+
+/*
+ * The work runs on a runtime PM reference its queuer took: suspend flushes it,
+ * so it must never resume the device itself.
+ */
+static void huc_mei_queue(struct xe_huc_mei *mei)
+{
+	struct xe_device *xe = gt_to_xe(mei_to_gt(mei));
+
+	xe_pm_runtime_get_noresume(xe);
+	if (!queue_work(system_dfl_wq, &mei->auth))
+		xe_pm_runtime_put(xe);
+}
+
+/* Drops a queued but not yet started load along with its reference */
+static void huc_mei_cancel(struct xe_huc_mei *mei)
+{
+	if (cancel_work_sync(&mei->auth))
+		xe_pm_runtime_put(gt_to_xe(mei_to_gt(mei)));
+	cancel_delayed_work_sync(&mei->deadline);
+}
+
+static bool huc_mei_gt_up(struct xe_huc_mei *mei)
+{
+	guard(spinlock_irqsave)(&mei->state_lock);
+
+	return mei->state == XE_HUC_MEI_LOADING || mei->state == XE_HUC_MEI_SETTLED;
+}
+
+static void huc_mei_auth_work(struct work_struct *work)
+{
+	struct xe_huc_mei *mei = container_of(work, struct xe_huc_mei, auth);
+	struct xe_huc *huc = mei_to_huc(mei);
+	struct xe_gt *gt = huc_to_gt(huc);
+	int ret;
+
+	guard(xe_pm_runtime_release_only)(gt_to_xe(gt));
+
+	/* stop() cancels this work before the GT goes down */
+	if (!huc_mei_gt_up(mei))
+		return;
+
+	ret = huc_mei_load_and_auth(huc);
+	if (ret == -EAGAIN)
+		return;
+
+	if (ret) {
+		xe_gt_err(gt, "HuC: load and authentication via GSC failed: %pe\n", ERR_PTR(ret));
+		xe_uc_fw_change_status(&huc->fw, XE_UC_FIRMWARE_LOAD_FAIL);
+	} else {
+		if (!mei->announced)
+			xe_gt_info(gt, "HuC: authenticated via GSC (version %u.%u.%u)\n",
+				   huc->fw.versions.found[XE_UC_FW_VER_RELEASE].major,
+				   huc->fw.versions.found[XE_UC_FW_VER_RELEASE].minor,
+				   huc->fw.versions.found[XE_UC_FW_VER_RELEASE].patch);
+		mei->announced = true;
+		xe_uc_fw_change_status(&huc->fw, XE_UC_FIRMWARE_RUNNING);
+	}
+
+	scoped_guard(spinlock_irqsave, &mei->state_lock)
+		huc_mei_settle_locked(mei);
+}
+
+static void huc_mei_deadline_work(struct work_struct *work)
+{
+	struct xe_huc_mei *mei = container_of(work, struct xe_huc_mei, deadline.work);
+	struct xe_gt *gt = mei_to_gt(mei);
+
+	/* not @mei->lock: a GSC command that never returns holds it */
+	guard(spinlock_irqsave)(&mei->state_lock);
+	if (mei->state != XE_HUC_MEI_LOADING)
+		return;
+
+	if (mei->bound) {
+		xe_gt_warn(gt, "HuC: the GSC load takes over %u ms, media no longer waits for it\n",
+			   HUC_MEI_COMPONENT_TIMEOUT_MS);
+	} else {
+		xe_gt_notice(gt, "HuC: no mei PXP component after %u ms (is mei_pxp loaded?), media runs without HuC until it binds\n",
+			     HUC_MEI_COMPONENT_TIMEOUT_MS);
+		mei->absent = true;
+	}
+	huc_mei_settle_locked(mei);
+}
+
+static int huc_mei_component_bind(struct device *xe_kdev, struct device *tee_kdev, void *data)
+{
+	struct xe_device *xe = kdev_to_xe_device(xe_kdev);
+	struct xe_huc_mei *mei = &xe_root_mmio_gt(xe)->uc.huc.mei;
+	struct i915_pxp_component *pxp = data;
+
+	scoped_guard(mutex, &mei->lock) {
+		mei->pxp = pxp;
+		mei->pxp->tee_dev = tee_kdev;
+	}
+
+	scoped_guard(spinlock_irqsave, &mei->state_lock) {
+		mei->bound = true;
+		mei->absent = false;
+	}
+
+	xe_gt_dbg(mei_to_gt(mei), "HuC: mei PXP component bound (%s)\n", dev_name(tee_kdev));
+
+	/* a suspended device loads the HuC when start() runs at resume */
+	if (!xe_pm_runtime_get_if_active(xe))
+		return 0;
+
+	if (huc_mei_gt_up(mei))
+		huc_mei_queue(mei);
+	xe_pm_runtime_put(xe);
+
+	return 0;
+}
+
+static void huc_mei_component_unbind(struct device *xe_kdev, struct device *tee_kdev, void *data)
+{
+	struct xe_device *xe = kdev_to_xe_device(xe_kdev);
+	struct xe_huc_mei *mei = &xe_root_mmio_gt(xe)->uc.huc.mei;
+
+	scoped_guard(spinlock_irqsave, &mei->state_lock)
+		mei->bound = false;
+
+	scoped_guard(mutex, &mei->lock)
+		mei->pxp = NULL;
+}
+
+static const struct component_ops huc_mei_component_ops = {
+	.bind = huc_mei_component_bind,
+	.unbind = huc_mei_component_unbind,
+};
+
+static void huc_mei_go_down(struct xe_huc_mei *mei)
+{
+	struct dma_fence *load;
+
+	scoped_guard(spinlock_irqsave, &mei->state_lock) {
+		huc_mei_settle_locked(mei);
+		mei->state = XE_HUC_MEI_DOWN;
+		load = mei->load;
+		mei->load = NULL;
+	}
+	dma_fence_put(load);
+}
+
+static void huc_mei_fini(void *arg)
+{
+	struct xe_huc_mei *mei = arg;
+
+	huc_mei_go_down(mei);
+	component_del(gt_to_xe(mei_to_gt(mei))->drm.dev, &huc_mei_component_ops);
+	huc_mei_cancel(mei);
+}
+
+/* The DG2 blob is parsed for the GSC, it has no image to DMA */
+static int huc_mei_check_mode(struct xe_huc *huc)
+{
+	struct xe_gt *gt = huc_to_gt(huc);
+
+	CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT);
+	if (!fw_ref.domains)
+		return -ETIMEDOUT;
+
+	if (!(xe_mmio_read32(&gt->mmio, GUC_SHIM_CONTROL2) & GSC_LOADS_HUC)) {
+		xe_gt_err(gt, "HuC: HW in DMA mode, but the DG2 blob is GSC-only\n");
+		return -ENOEXEC;
+	}
+
+	return 0;
+}
+
+/**
+ * xe_huc_mei_init() - set up HuC loading through the GSC on DG2
+ * @huc: the HuC, its firmware already in VRAM
+ *
+ * A failure leaves the HuC unloaded and does not fail the probe.
+ */
+void xe_huc_mei_init(struct xe_huc *huc)
+{
+	struct xe_gt *gt = huc_to_gt(huc);
+	struct xe_device *xe = gt_to_xe(gt);
+	struct xe_tile *tile = gt_to_tile(gt);
+	struct xe_huc_mei *mei = &huc->mei;
+	struct xe_bo *bo;
+	int ret;
+
+	if (xe->info.platform != XE_DG2)
+		return;
+
+	if (!IS_ENABLED(CONFIG_INTEL_MEI_PXP) || !IS_ENABLED(CONFIG_INTEL_MEI_GSC)) {
+		xe_gt_notice(gt, "HuC: can't load without CONFIG_INTEL_MEI_PXP and CONFIG_INTEL_MEI_GSC\n");
+		xe_uc_fw_change_status(&huc->fw, XE_UC_FIRMWARE_INIT_FAIL);
+		return;
+	}
+
+	ret = huc_mei_check_mode(huc);
+	if (ret)
+		goto fail;
+
+	ret = drmm_mutex_init(&xe->drm, &mei->lock);
+	if (ret)
+		goto fail;
+
+	spin_lock_init(&mei->state_lock);
+	mei->fence_context = dma_fence_context_alloc(1);
+	INIT_WORK(&mei->auth, huc_mei_auth_work);
+	INIT_DELAYED_WORK(&mei->deadline, huc_mei_deadline_work);
+
+	/* pinned VRAM BOs are contiguous; the GSC reads the page by its DPA */
+	bo = xe_managed_bo_create_pin_map(xe, tile, PAGE_SIZE, XE_BO_FLAG_VRAM_IF_DGFX(tile));
+	if (IS_ERR(bo)) {
+		ret = PTR_ERR(bo);
+		goto fail;
+	}
+	mei->msg = bo;
+	mei->state = XE_HUC_MEI_DOWN;
+
+	ret = component_add_typed(xe->drm.dev, &huc_mei_component_ops, I915_COMPONENT_PXP);
+	if (ret) {
+		mei->state = XE_HUC_MEI_UNUSED;
+		goto fail;
+	}
+
+	ret = devm_add_action_or_reset(xe->drm.dev, huc_mei_fini, mei);
+	if (ret) {
+		mei->state = XE_HUC_MEI_UNUSED;
+		goto fail;
+	}
+
+	return;
+
+fail:
+	xe_gt_err(gt, "HuC: can't load through the GSC: %pe\n", ERR_PTR(ret));
+	/* not loadable: no DMA upload or GuC auth of a GSC-only blob either */
+	xe_uc_fw_change_status(&huc->fw, XE_UC_FIRMWARE_INIT_FAIL);
+}
+
+/**
+ * xe_huc_mei_start() - ask the GSC for the HuC once the GT runs
+ * @huc: the HuC
+ *
+ * Called at the end of every uC load (probe, GT reset, resume) with the device
+ * awake. The HuC does not survive those, the GSC must load it again; video
+ * decode submissions wait for it until it settles.
+ */
+void xe_huc_mei_start(struct xe_huc *huc)
+{
+	struct xe_huc_mei *mei = &huc->mei;
+	struct dma_fence *load, *old;
+	bool wait;
+
+	if (!xe_huc_mei_is_used(huc) || !xe_uc_fw_is_loadable(&huc->fw))
+		return;
+
+	scoped_guard(spinlock_irqsave, &mei->state_lock)
+		wait = !mei->absent;
+
+	/* without a fence submissions just don't wait */
+	load = wait ? huc_mei_fence_create(mei) : NULL;
+
+	scoped_guard(spinlock_irqsave, &mei->state_lock) {
+		huc_mei_settle_locked(mei);
+		old = mei->load;
+		mei->state = wait ? XE_HUC_MEI_LOADING : XE_HUC_MEI_SETTLED;
+		mei->load = load;
+	}
+	dma_fence_put(old);
+
+	if (wait)
+		mod_delayed_work(system_dfl_wq, &mei->deadline,
+				 msecs_to_jiffies(HUC_MEI_COMPONENT_TIMEOUT_MS));
+	huc_mei_queue(mei);
+}
+
+/**
+ * xe_huc_mei_stop() - forget the HuC before a reset, a suspend or an FLR
+ * @huc: the HuC
+ *
+ * Waits for a running load and drops a pending one; submissions stop waiting
+ * until the next start().
+ */
+void xe_huc_mei_stop(struct xe_huc *huc)
+{
+	struct xe_huc_mei *mei = &huc->mei;
+
+	if (!xe_huc_mei_is_used(huc))
+		return;
+
+	huc_mei_go_down(mei);
+	huc_mei_cancel(mei);
+}
+
+/**
+ * xe_huc_mei_load_fence() - the fence of a pending HuC load
+ * @huc: the HuC
+ *
+ * Return: a reference to the fence that signals when the pending load settles,
+ * or NULL when no load is pending.
+ */
+struct dma_fence *xe_huc_mei_load_fence(struct xe_huc *huc)
+{
+	struct xe_huc_mei *mei = &huc->mei;
+
+	if (!xe_huc_mei_is_used(huc))
+		return NULL;
+
+	guard(spinlock_irqsave)(&mei->state_lock);
+	if (mei->state != XE_HUC_MEI_LOADING || !mei->load)
+		return NULL;
+
+	return dma_fence_get(mei->load);
+}
+
+/**
+ * xe_huc_mei_wait() - wait until a pending HuC load settled
+ * @huc: the HuC
+ *
+ * A HuC query must not race the load that follows a probe or a resume, or
+ * userspace would see a HuC-less device.
+ *
+ * Return: 0 once settled or timed out, -ERESTARTSYS when interrupted.
+ */
+int xe_huc_mei_wait(struct xe_huc *huc)
+{
+	struct dma_fence *load = xe_huc_mei_load_fence(huc);
+	long ret;
+
+	if (!load)
+		return 0;
+
+	ret = dma_fence_wait_timeout(load, true, msecs_to_jiffies(HUC_MEI_SETTLE_TIMEOUT_MS));
+	dma_fence_put(load);
+
+	return ret < 0 ? ret : 0;
+}
diff --git a/drivers/gpu/drm/xe/xe_huc_mei.h b/drivers/gpu/drm/xe/xe_huc_mei.h
new file mode 100644
index 000000000..bdc68dcca
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_huc_mei.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2026 Arisa Snowbell
+ */
+
+#ifndef _XE_HUC_MEI_H_
+#define _XE_HUC_MEI_H_
+
+#include <linux/types.h>
+
+struct dma_fence;
+struct xe_huc;
+
+bool xe_huc_mei_is_used(struct xe_huc *huc);
+void xe_huc_mei_init(struct xe_huc *huc);
+void xe_huc_mei_start(struct xe_huc *huc);
+void xe_huc_mei_stop(struct xe_huc *huc);
+struct dma_fence *xe_huc_mei_load_fence(struct xe_huc *huc);
+int xe_huc_mei_wait(struct xe_huc *huc);
+
+#endif
diff --git a/drivers/gpu/drm/xe/xe_huc_types.h b/drivers/gpu/drm/xe/xe_huc_types.h
index cfbaa5e0d..d3dd36f72 100644
--- a/drivers/gpu/drm/xe/xe_huc_types.h
+++ b/drivers/gpu/drm/xe/xe_huc_types.h
@@ -6,10 +6,64 @@
 #ifndef _XE_HUC_TYPES_H_
 #define _XE_HUC_TYPES_H_
 
+#include <linux/atomic.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+
 #include "xe_uc_fw_types.h"
 
+struct dma_fence;
+struct i915_pxp_component;
 struct xe_bo;
 
+/**
+ * enum xe_huc_mei_state - where a HuC that the GSC loads through mei is
+ * @XE_HUC_MEI_UNUSED: not loaded through mei (not DG2, or its setup failed)
+ * @XE_HUC_MEI_DOWN: the GT is not running (before the first load, in a reset or
+ *	a suspend), there is nothing to load into
+ * @XE_HUC_MEI_LOADING: the GT runs and the GSC load is pending
+ * @XE_HUC_MEI_SETTLED: the load succeeded, failed or stopped waiting for mei
+ */
+enum xe_huc_mei_state {
+	XE_HUC_MEI_UNUSED,
+	XE_HUC_MEI_DOWN,
+	XE_HUC_MEI_LOADING,
+	XE_HUC_MEI_SETTLED,
+};
+
+/**
+ * struct xe_huc_mei - HuC loaded by the GSC through mei_pxp (DG2)
+ */
+struct xe_huc_mei {
+	/** @lock: protects @pxp, held across a GSC command */
+	struct mutex lock;
+	/** @pxp: the bound mei PXP component, NULL while unbound */
+	struct i915_pxp_component *pxp;
+	/** @msg: VRAM page for the GSC request and reply */
+	struct xe_bo *msg;
+	/** @auth: asks the GSC to load and authenticate the HuC */
+	struct work_struct auth;
+	/** @deadline: stops waiting for a mei that does not bind */
+	struct delayed_work deadline;
+	/** @state_lock: protects @state, @bound, @absent and @load */
+	spinlock_t state_lock;
+	/** @state: where the load is */
+	enum xe_huc_mei_state state;
+	/** @bound: the mei PXP component is bound */
+	bool bound;
+	/** @absent: mei did not bind in time, later loads don't wait for it */
+	bool absent;
+	/** @announced: the first successful load was logged */
+	bool announced;
+	/** @load: signalled when the pending load settles, NULL when none */
+	struct dma_fence *load;
+	/** @fence_context: dma-fence context of @load */
+	u64 fence_context;
+	/** @seqno: sequence number of the last @load */
+	atomic64_t seqno;
+};
+
 /**
  * struct xe_huc - HuC
  */
@@ -19,6 +73,9 @@ struct xe_huc {
 
 	/** @gsc_pkt: bo to store the packet for auth via GSC */
 	struct xe_bo *gsc_pkt;
+
+	/** @mei: loading by the GSC through mei (DG2) */
+	struct xe_huc_mei mei;
 };
 
 #endif
diff --git a/drivers/gpu/drm/xe/xe_uc.c b/drivers/gpu/drm/xe/xe_uc.c
index ff13f6e6c..69b632926 100644
--- a/drivers/gpu/drm/xe/xe_uc.c
+++ b/drivers/gpu/drm/xe/xe_uc.c
@@ -20,6 +20,7 @@
 #include "xe_guc_engine_activity.h"
 #include "xe_guc_submit.h"
 #include "xe_huc.h"
+#include "xe_huc_mei.h"
 #include "xe_mmio.h"
 #include "xe_sriov.h"
 #include "xe_tile.h"
@@ -374,6 +375,7 @@ int xe_uc_reset_prepare(struct xe_uc *uc)
 
 void xe_uc_stop_prepare(struct xe_uc *uc)
 {
+	xe_huc_mei_stop(&uc->huc);
 	xe_gsc_stop_prepare(&uc->gsc);
 	xe_guc_stop_prepare(&uc->guc);
 }
@@ -444,6 +446,7 @@ void xe_uc_flr_prepare(struct xe_uc *uc)
 	struct xe_uc_flr flr = { .uc = uc };
 	struct xe_gt *gt = uc_to_gt(uc);
 
+	xe_huc_mei_stop(&uc->huc);
 	xe_uc_reset_prepare(uc);
 
 	/*
@@ -485,6 +488,7 @@ int xe_uc_reinit(struct xe_uc *uc)
 
 void xe_uc_suspend_prepare(struct xe_uc *uc)
 {
+	xe_huc_mei_stop(&uc->huc);
 	xe_gsc_wait_for_worker_completion(&uc->gsc);
 	xe_guc_stop_prepare(&uc->guc);
 }
@@ -495,6 +499,9 @@ int xe_uc_suspend(struct xe_uc *uc)
 	if (!xe_device_uc_enabled(uc_to_xe(uc)))
 		return 0;
 
+	/* runtime D3cold gets here without xe_uc_suspend_prepare() */
+	xe_huc_mei_stop(&uc->huc);
+
 	uc_reset_wait(uc);
 
 	xe_uc_stop(uc);
-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/5] drm/xe: hold video decode work and HuC queries for a pending DG2 HuC load
       [not found] <20261126205758.49845-1-arisa.snowbell@gmail.com>
                   ` (2 preceding siblings ...)
  2026-11-26 20:57 ` [PATCH 3/5] drm/xe/huc: load the DG2 HuC through the GSC via mei_pxp Arisa Snowbell
@ 2026-11-26 20:57 ` Arisa Snowbell
  2026-11-26 20:57 ` [PATCH 5/5] drm/xe/uc_fw: select the DG2 HuC blob for a load by the GSC Arisa Snowbell
  4 siblings, 0 replies; 5+ messages in thread
From: Arisa Snowbell @ 2026-11-26 20:57 UTC (permalink / raw)
  To: intel-xe
  Cc: dri-devel, Daniele Ceraolo Spurio, Arisa Snowbell, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Sumit Semwal, Christian König, Philipp Stanner,
	linux-kernel, linux-media, linaro-mm-sig

On DG2 the HuC load by the GSC completes asynchronously after probe, a GT
reset or a resume. Media submitted before then would run without the HuC,
and userspace querying the HuC version (as Mesa and the media driver do at
init) would see a device without one.

Like i915 (i915_request_await_huc()), make video decode jobs depend on the
fence of the pending load. The HuC version query waits for it too,
interruptibly and bounded by the load's own 10 s deadline; document that.

Signed-off-by: Arisa Snowbell <arisa.snowbell@gmail.com>
---
 drivers/gpu/drm/xe/xe_exec.c  | 13 +++++++++++++
 drivers/gpu/drm/xe/xe_query.c |  5 +++++
 include/uapi/drm/xe_drm.h     |  5 +++++
 3 files changed, 23 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c
index f9b0fdb96..65e445205 100644
--- a/drivers/gpu/drm/xe/xe_exec.c
+++ b/drivers/gpu/drm/xe/xe_exec.c
@@ -14,6 +14,8 @@
 
 #include "xe_device.h"
 #include "xe_exec_queue.h"
+#include "xe_gt_types.h"
+#include "xe_huc_mei.h"
 #include "xe_hw_engine_group.h"
 #include "xe_macros.h"
 #include "xe_pm.h"
@@ -317,6 +319,17 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (err)
 		goto err_put_job;
 
+	/* as on i915, video decode must not run before a pending HuC load */
+	if (q->class == XE_ENGINE_CLASS_VIDEO_DECODE) {
+		struct dma_fence *huc_load = xe_huc_mei_load_fence(&q->gt->uc.huc);
+
+		if (huc_load) {
+			err = drm_sched_job_add_dependency(&job->drm, huc_load);
+			if (err)
+				goto err_put_job;
+		}
+	}
+
 	if (!xe_vm_in_lr_mode(vm)) {
 		err = xe_svm_notifier_lock_interruptible(vm);
 		if (err)
diff --git a/drivers/gpu/drm/xe/xe_query.c b/drivers/gpu/drm/xe/xe_query.c
index 9cc35fc83..696bae5ee 100644
--- a/drivers/gpu/drm/xe/xe_query.c
+++ b/drivers/gpu/drm/xe/xe_query.c
@@ -22,6 +22,7 @@
 #include "xe_gt.h"
 #include "xe_gt_topology.h"
 #include "xe_guc_hwconfig.h"
+#include "xe_huc_mei.h"
 #include "xe_macros.h"
 #include "xe_mmio.h"
 #include "xe_oa.h"
@@ -600,6 +601,7 @@ query_uc_fw_version(struct xe_device *xe, struct drm_xe_device_query *query)
 	case XE_QUERY_UC_TYPE_HUC: {
 		struct xe_gt *media_gt = NULL;
 		struct xe_huc *huc;
+		int ret;
 
 		if (MEDIA_VER(xe) >= 13) {
 			struct xe_tile *tile;
@@ -619,6 +621,9 @@ query_uc_fw_version(struct xe_device *xe, struct drm_xe_device_query *query)
 			break;
 
 		huc = &media_gt->uc.huc;
+		ret = xe_huc_mei_wait(huc);
+		if (ret)
+			return ret;
 		if (huc->fw.status == XE_UC_FIRMWARE_RUNNING)
 			version = &huc->fw.versions.found[XE_UC_FW_VER_RELEASE];
 		break;
diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
index 578f0c1eb..db893d041 100644
--- a/include/uapi/drm/xe_drm.h
+++ b/include/uapi/drm/xe_drm.h
@@ -628,6 +628,11 @@ struct drm_xe_query_engine_cycles {
  *
  * Given a uc_type this will return the branch, major, minor and patch version
  * of the micro-controller firmware.
+ *
+ * On platforms where the GSC loads the HuC (DG2), the load runs asynchronously
+ * after probe, reset and resume. A query of %XE_QUERY_UC_TYPE_HUC then waits
+ * (interruptibly, for at most 10 seconds) until a pending load settled, so
+ * that it does not report a HuC that is about to run as missing.
  */
 struct drm_xe_query_uc_fw_version {
 	/** @uc_type: The micro-controller type to query firmware version */
-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 5/5] drm/xe/uc_fw: select the DG2 HuC blob for a load by the GSC
       [not found] <20261126205758.49845-1-arisa.snowbell@gmail.com>
                   ` (3 preceding siblings ...)
  2026-11-26 20:57 ` [PATCH 4/5] drm/xe: hold video decode work and HuC queries for a pending DG2 HuC load Arisa Snowbell
@ 2026-11-26 20:57 ` Arisa Snowbell
  4 siblings, 0 replies; 5+ messages in thread
From: Arisa Snowbell @ 2026-11-26 20:57 UTC (permalink / raw)
  To: intel-xe
  Cc: dri-devel, Daniele Ceraolo Spurio, Arisa Snowbell, Matthew Brost,
	Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
	linux-kernel

The GSC loads the whole DG2 HuC binary (dg2_huc_gsc.bin, the one i915
uses), so there is no legacy CSS image to find in it for a DMA load: parse
the CPD header for the manifest version only.

This enables the HuC on DG2.

Signed-off-by: Arisa Snowbell <arisa.snowbell@gmail.com>
---
 drivers/gpu/drm/xe/xe_uc_fw.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_uc_fw.c b/drivers/gpu/drm/xe/xe_uc_fw.c
index d0ea05923..05f51378b 100644
--- a/drivers/gpu/drm/xe/xe_uc_fw.c
+++ b/drivers/gpu/drm/xe/xe_uc_fw.c
@@ -137,6 +137,7 @@ struct fw_blobs_by_type {
 	fw_def(BATTLEMAGE,	GT_TYPE_ANY,	no_ver(xe,	huc,		bmg))		\
 	fw_def(LUNARLAKE,	GT_TYPE_ANY,	no_ver(xe,	huc,		lnl))		\
 	fw_def(METEORLAKE,	GT_TYPE_ANY,	no_ver(i915,	huc_gsc,	mtl))		\
+	fw_def(DG2,		GT_TYPE_ANY,	no_ver(i915,	huc_gsc,	dg2))		\
 	fw_def(DG1,		GT_TYPE_ANY,	no_ver(i915,	huc,		dg1))		\
 	fw_def(ALDERLAKE_N,	GT_TYPE_ANY,	no_ver(i915,	huc,		tgl))		\
 	fw_def(ALDERLAKE_P,	GT_TYPE_ANY,	no_ver(i915,	huc,		tgl))		\
@@ -555,11 +556,7 @@ static int parse_cpd_header(struct xe_uc_fw *uc_fw, const void *data, size_t siz
 	if (css_entry) {
 		int ret;
 
-		/*
-		 * This section does not contain a CSS entry on DG2. We
-		 * don't support DG2 HuC right now, so no need to handle
-		 * it, just add a reminder in case that changes.
-		 */
+		/* The DG2 HuC has no CSS entry, its caller passes none */
 		xe_assert(xe, xe->info.platform != XE_DG2);
 
 		offset = entry_offset(header, css_entry);
@@ -661,6 +658,13 @@ static int parse_headers(struct xe_uc_fw *uc_fw, const struct firmware *fw)
 	case XE_UC_FW_TYPE_GSC:
 		return parse_gsc_layout(uc_fw, fw->data, fw->size);
 	case XE_UC_FW_TYPE_HUC:
+		/*
+		 * The GSC loads the whole DG2 binary itself, so there is no
+		 * legacy CSS image to find for a DMA load.
+		 */
+		if (uc_fw_to_xe(uc_fw)->info.platform == XE_DG2)
+			return parse_cpd_header(uc_fw, fw->data, fw->size, "HUCP.man", NULL);
+
 		ret = parse_cpd_header(uc_fw, fw->data, fw->size, "HUCP.man", "huc_fw");
 		if (!ret || ret != -ENOENT)
 			return ret;
-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26 20:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20261126205758.49845-1-arisa.snowbell@gmail.com>
2026-11-26 20:57 ` [PATCH 1/5] drm/xe/heci: expose the DG2 HECI1 interface to mei Arisa Snowbell
2026-11-26 20:57 ` [PATCH 2/5] mei: gsc: bind the xe HECI1 device Arisa Snowbell
2026-11-26 20:57 ` [PATCH 3/5] drm/xe/huc: load the DG2 HuC through the GSC via mei_pxp Arisa Snowbell
2026-11-26 20:57 ` [PATCH 4/5] drm/xe: hold video decode work and HuC queries for a pending DG2 HuC load Arisa Snowbell
2026-11-26 20:57 ` [PATCH 5/5] drm/xe/uc_fw: select the DG2 HuC blob for a load by the GSC Arisa Snowbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®