Skip to contentSkip to conversation

drm/i915: Impletments dynamic WOPCM partitioning.

PATCH In review Jackie Li 5 participants 11 messages Nov 15, 2017 – Nov 29, 2017

Subsystems (2)
lore
Share & tools
lore

Jackie Li

author
#0 lore raw

PATCH v2 1/2 drm/i915: Impletments dynamic WOPCM partitioning.

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
- Removed intel_wopcm_init (Ville/Sagar/Joonas)
- Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
- Removed unnecessary function calls (Joonas)
- Init GuC WOPCM partition as soon as firmware fetching is completed

Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c |   4 +-
 drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--
 drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
 drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
 drivers/gpu/drm/i915/intel_huc.c        |   2 +-
 drivers/gpu/drm/i915/intel_uc.c         | 116 +++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
 7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +2 -2
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private *dev_priv,
 	ctx->desc_template =
 		default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
 
-	/* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not
+	/* GuC requires the ring to be placed above GuC WOPCM top. if GuC is not
 	 * present or not in use we still need a small bias as ring wraparound
 	 * at offset 0 sometimes hangs. No idea why.
 	 */
 	if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-		ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+		ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
 	else
 		ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
 
drivers/gpu/drm/i915/i915_guc_reg.h +14 -4
index bc1ae7d..567df12 100644
@@ -67,17 +67,27 @@
 #define DMA_GUC_WOPCM_OFFSET		_MMIO(0xc340)
 #define   HUC_LOADING_AGENT_VCR		  (0<<1)
 #define   HUC_LOADING_AGENT_GUC		  (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE	  0x80000	/* 512KB */
 #define GUC_MAX_IDLE_COUNT		_MMIO(0xC3E4)
 
 #define HUC_STATUS2             _MMIO(0xD3B0)
 #define   HUC_FW_VERIFIED       (1<<7)
 
 /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE		(0x1 << 20)
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE		(0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT		(0x4000)
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED	(0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED		(0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA		4
+#define GEN9_GUC_WOPCM_OFFSET		(0x24000)
+
 #define GUC_WOPCM_SIZE			_MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP			  (0x80 << 12)	/* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED	  (0x10 << 12)	/* 64KB  */
 
 /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
 #define GUC_GGTT_TOP			0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +16 -9
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private *dev_priv)
  * This is a wrapper to create an object for use with the GuC. In order to
  * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
  * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
  * range is reserved inside GuC.
  *
  * Return:	A i915_vma if successful, otherwise an ERR_PTR.
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
 		goto err;
 
 	ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-			   PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+			   PIN_GLOBAL | PIN_OFFSET_BIAS |
+			   dev_priv->guc.wopcm.top);
 	if (ret) {
 		vma = ERR_PTR(ret);
 		goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
 	return vma;
 }
 
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
 {
-	u32 wopcm_size = GUC_WOPCM_TOP;
-
-	/* On BXT, the top of WOPCM is reserved for RC6 context */
-	if (IS_GEN9_LP(dev_priv))
-		wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+	u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top;
+	u32 offset = i915_ggtt_offset(vma);
 
-	return wopcm_size;
+	GEM_BUG_ON(!guc_wopcm_top);
+	GEM_BUG_ON(offset < guc_wopcm_top);
+	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+	return offset;
 }
drivers/gpu/drm/i915/intel_guc.h +8 -17
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
 	struct intel_engine_cs *engine;
 };
 
+struct guc_wopcm_partition {
+	u32 offset;
+	u32 size;
+	u32 top;
+};
+
 /*
  * Top level structure of GuC. It handles firmware loading and manages client
  * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
  */
 struct intel_guc {
 	struct intel_uc_fw fw;
+	struct guc_wopcm_partition wopcm;
 	struct intel_guc_log log;
 	struct intel_guc_ct ct;
 
@@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)
 	guc->notify(guc);
 }
 
-/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-	u32 offset = i915_ggtt_offset(vma);
-
-	GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
-
-	return offset;
-}
-
 void intel_guc_init_early(struct intel_guc *guc);
 void intel_guc_init_send_regs(struct intel_guc *guc);
 void intel_guc_init_params(struct intel_guc *guc);
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
 int intel_guc_suspend(struct drm_i915_private *dev_priv);
 int intel_guc_resume(struct drm_i915_private *dev_priv);
 struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);
 
 #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
 		return;
 
 	vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-				PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+				PIN_OFFSET_BIAS | guc->wopcm.top);
 	if (IS_ERR(vma)) {
 		DRM_ERROR("failed to pin huc fw object %d\n",
 				(int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +114 -2

133 lines not on this page · raw message

drivers/gpu/drm/i915/intel_uc_fw.c +8 -3
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
 	uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
 	uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);
 
-	/* Header and uCode will be loaded to WOPCM */
+	/*
+	 * Header and uCode will be loaded to WOPCM
+	 * Only check the size against the overall available WOPCM here. Will
+	 * continue to check the size during WOPCM partition calculation.
+	 */
 	size = uc_fw->header_size + uc_fw->ucode_size;
-	if (size > intel_guc_wopcm_size(dev_priv)) {
+	if (size > WOPCM_DEFAULT_SIZE) {
 		DRM_WARN("%s: Firmware is too large to fit in WOPCM\n",
 			 intel_uc_fw_type_repr(uc_fw->type));
 		err = -E2BIG;
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
 		       int (*xfer)(struct intel_uc_fw *uc_fw,
 				   struct i915_vma *vma))
 {
+	struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
 	struct i915_vma *vma;
 	int err;
 
@@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
 	}
 
 	vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0,
-				       PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+				       PIN_OFFSET_BIAS | i915->guc.wopcm.top);
 	if (IS_ERR(vma)) {
 		err = PTR_ERR(vma);
 		DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

PATCH v2 2/2 HAX enable guc submission for CI

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 8 ++------
 drivers/gpu/drm/i915/i915_params.h  | 4 ++--
 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +2 -6
index 3c3a699..b56e785 100644
@@ -3590,17 +3590,13 @@ int i915_ggtt_enable_hw(struct drm_i915_private *dev_priv)
 
 void i915_ggtt_enable_guc(struct drm_i915_private *i915)
 {
-	GEM_BUG_ON(i915->ggtt.invalidate != gen6_ggtt_invalidate);
-
 	i915->ggtt.invalidate = guc_ggtt_invalidate;
 }
 
 void i915_ggtt_disable_guc(struct drm_i915_private *i915)
 {
-	/* We should only be called after i915_ggtt_enable_guc() */
-	GEM_BUG_ON(i915->ggtt.invalidate != guc_ggtt_invalidate);
-
-	i915->ggtt.invalidate = gen6_ggtt_invalidate;
+	if (i915->ggtt.invalidate == guc_ggtt_invalidate)
+		i915->ggtt.invalidate = gen6_ggtt_invalidate;
 }
 
 void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv)
drivers/gpu/drm/i915/i915_params.h +2 -2
index c729226..c38cef0 100644
@@ -44,8 +44,8 @@
 	param(int, disable_power_well, -1) \
 	param(int, enable_ips, 1) \
 	param(int, invert_brightness, 0) \
-	param(int, enable_guc_loading, 0) \
-	param(int, enable_guc_submission, 0) \
+	param(int, enable_guc_loading, 1) \
+	param(int, enable_guc_submission, 1) \
 	param(int, guc_log_level, -1) \
 	param(char *, guc_firmware_path, NULL) \
 	param(char *, huc_firmware_path, NULL) \
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

✗ Fi.CI.BAT: warning for series starting with [v2,1/2] drm/i915: Impletments dynamic WOPCM partitioning.

In reply to Jackie Li
== Series Details ==

== Series Details ==

Series: series starting with [v2,1/2] drm/i915: Impletments dynamic WOPCM partitioning.
URL : https://patchwork.freedesktop.org/series/33893/
State : warning

== Summary ==

Series 33893v1 series starting with [v2,1/2] drm/i915: Impletments dynamic WOPCM partitioning.
https://patchwork.freedesktop.org/api/1.0/series/33893/revisions/1/mbox/

Test drv_module_reload:

        Subgroup basic-reload:
                pass       -> DMESG-WARN (fi-glk-1)
        Subgroup basic-no-display:
                pass       -> DMESG-WARN (fi-glk-1)
        Subgroup basic-reload-inject:
                pass       -> DMESG-WARN (fi-glk-1)
fi-bdw-5557u     total:289  pass:268  dwarn:0   dfail:0   fail:0   skip:21  time:447s
fi-bdw-gvtdvm    total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:465s
fi-blb-e6850     total:289  pass:223  dwarn:1   dfail:0   fail:0   skip:65  time:380s
fi-bsw-n3050     total:289  pass:243  dwarn:0   dfail:0   fail:0   skip:46  time:544s
fi-bwr-2160      total:289  pass:183  dwarn:0   dfail:0   fail:0   skip:106 time:276s
fi-bxt-dsi       total:289  pass:259  dwarn:0   dfail:0   fail:0   skip:30  time:514s
fi-bxt-j4205     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:517s
fi-byt-j1900     total:289  pass:254  dwarn:0   dfail:0   fail:0   skip:35  time:505s
fi-byt-n2820     total:289  pass:250  dwarn:0   dfail:0   fail:0   skip:39  time:497s
fi-elk-e7500     total:289  pass:229  dwarn:0   dfail:0   fail:0   skip:60  time:426s
fi-gdg-551       total:289  pass:178  dwarn:1   dfail:0   fail:1   skip:109 time:264s
fi-glk-1         total:289  pass:258  dwarn:3   dfail:0   fail:0   skip:28  time:544s
fi-hsw-4770      total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:427s
fi-hsw-4770r     total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:440s
fi-ilk-650       total:289  pass:228  dwarn:0   dfail:0   fail:0   skip:61  time:432s
fi-ivb-3520m     total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:477s
fi-ivb-3770      total:289  pass:260  dwarn:0   dfail:0   fail:0   skip:29  time:462s
fi-kbl-7500u     total:289  pass:264  dwarn:1   dfail:0   fail:0   skip:24  time:479s
fi-kbl-7560u     total:289  pass:270  dwarn:0   dfail:0   fail:0   skip:19  time:534s
fi-kbl-7567u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:482s
fi-kbl-r         total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:535s
fi-pnv-d510      total:289  pass:222  dwarn:1   dfail:0   fail:0   skip:66  time:571s
fi-skl-6260u     total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:456s
fi-skl-6600u     total:289  pass:262  dwarn:0   dfail:0   fail:0   skip:27  time:548s
fi-skl-6700hq    total:289  pass:263  dwarn:0   dfail:0   fail:0   skip:26  time:565s
fi-skl-6700k     total:289  pass:265  dwarn:0   dfail:0   fail:0   skip:24  time:520s
fi-skl-6770hq    total:289  pass:269  dwarn:0   dfail:0   fail:0   skip:20  time:489s
fi-skl-gvtdvm    total:289  pass:266  dwarn:0   dfail:0   fail:0   skip:23  time:463s
fi-snb-2520m     total:289  pass:250  dwarn:0   dfail:0   fail:0   skip:39  time:557s
fi-snb-2600      total:289  pass:249  dwarn:0   dfail:0   fail:0   skip:40  time:421s

Blacklisted hosts:
fi-cfl-s total:289 pass:254 dwarn:3 dfail:0 fail:0 skip:32 time:539s

06718a287f282ad31264560c5dc18a38474cb562 drm-tip: 2017y-11m-15d-11h-36m-39s UTC integration manifest a036a54d3c2d HAX enable guc submission for CI
d509947288a9 drm/i915: Impletments dynamic WOPCM partitioning.

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7148/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Jackie Li

Quoting Jackie Li (2017-11-15 17:17:08)

Quoted 11 lines

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

Quoted 5 lines

v2:
- Removed intel_wopcm_init (Ville/Sagar/Joonas)
- Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
- Removed unnecessary function calls (Joonas)
- Init GuC WOPCM partition as soon as firmware fetching is completed

Fix your indenting. Use tabs, align to brackets etc.

Quoted 200 lines
Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem_context.c |   4 +-
 drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--
 drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
 drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
 drivers/gpu/drm/i915/intel_huc.c        |   2 +-
 drivers/gpu/drm/i915/intel_uc.c         | 116 +++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
 7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +2 -2
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private *dev_priv,
        ctx->desc_template =
                default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
 
-       /* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not
+       /* GuC requires the ring to be placed above GuC WOPCM top. if GuC is not
         * present or not in use we still need a small bias as ring wraparound
         * at offset 0 sometimes hangs. No idea why.
         */
        if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-               ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+               ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
        else
                ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
 
drivers/gpu/drm/i915/i915_guc_reg.h +14 -4
index bc1ae7d..567df12 100644
@@ -67,17 +67,27 @@
 #define DMA_GUC_WOPCM_OFFSET           _MMIO(0xc340)
 #define   HUC_LOADING_AGENT_VCR                  (0<<1)
 #define   HUC_LOADING_AGENT_GUC                  (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE         0x80000       /* 512KB */
 #define GUC_MAX_IDLE_COUNT             _MMIO(0xC3E4)
 
 #define HUC_STATUS2             _MMIO(0xD3B0)
 #define   HUC_FW_VERIFIED       (1<<7)
 
 /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE             (0x1 << 20)
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE            (0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT         (0x4000)
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED       (0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED         (0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA           4
+#define GEN9_GUC_WOPCM_OFFSET          (0x24000)
+
 #define GUC_WOPCM_SIZE                 _MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP                          (0x80 << 12)  /* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED     (0x10 << 12)  /* 64KB  */
 
 /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
 #define GUC_GGTT_TOP                   0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +16 -9
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private *dev_priv)
  * This is a wrapper to create an object for use with the GuC. In order to
  * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
  * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
  * range is reserved inside GuC.
  *
  * Return:     A i915_vma if successful, otherwise an ERR_PTR.
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
                goto err;
 
        ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-                          PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                          PIN_GLOBAL | PIN_OFFSET_BIAS |
+                          dev_priv->guc.wopcm.top);
        if (ret) {
                vma = ERR_PTR(ret);
                goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
        return vma;
 }
 
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
 {
-       u32 wopcm_size = GUC_WOPCM_TOP;
-
-       /* On BXT, the top of WOPCM is reserved for RC6 context */
-       if (IS_GEN9_LP(dev_priv))
-               wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+       u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top;
+       u32 offset = i915_ggtt_offset(vma);
 
-       return wopcm_size;
+       GEM_BUG_ON(!guc_wopcm_top);
+       GEM_BUG_ON(offset < guc_wopcm_top);
+       GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+       return offset;
 }
drivers/gpu/drm/i915/intel_guc.h +8 -17
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
        struct intel_engine_cs *engine;
 };
 
+struct guc_wopcm_partition {
+       u32 offset;
+       u32 size;
+       u32 top;
+};
+
 /*
  * Top level structure of GuC. It handles firmware loading and manages client
  * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
  */
 struct intel_guc {
        struct intel_uc_fw fw;
+       struct guc_wopcm_partition wopcm;
        struct intel_guc_log log;
        struct intel_guc_ct ct;
 
@@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)
        guc->notify(guc);
 }
 
-/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-       u32 offset = i915_ggtt_offset(vma);
-
-       GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-       GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
-
-       return offset;
-}
-
 void intel_guc_init_early(struct intel_guc *guc);
 void intel_guc_init_send_regs(struct intel_guc *guc);
 void intel_guc_init_params(struct intel_guc *guc);
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
 int intel_guc_suspend(struct drm_i915_private *dev_priv);
 int intel_guc_resume(struct drm_i915_private *dev_priv);
 struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);
 
 #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
                return;
 
        vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-                               PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                               PIN_OFFSET_BIAS | guc->wopcm.top);
        if (IS_ERR(vma)) {
                DRM_ERROR("failed to pin huc fw object %d\n",
                                (int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +1 -0
index aec2954..4f6fa67 100644
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct drm_i915_private *dev_priv)
        intel_guc_init_early(&dev_priv->guc);
 }
 
+static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 10 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+       /* On BXT, the top of WOPCM is reserved for RC6 context */
+       if (IS_GEN9_LP(i915))
+               return BXT_WOPCM_RC6_RESERVED;
+
+       return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32 offset,
+                              u32 reserved_size)

do ?

From that I was expecting action, talking to hw and excitement.

Pass in guc_wopcm_partition and call this

static int wocpm_partition_init(struct guc_wocpm_partition *wp,

				u32 offset, u32 size)
Quoted 80 lines
drivers/gpu/drm/i915/intel_uc.c +80 -0
+{
+       struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+       u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGNMENT);
+
+       if (offset >= WOPCM_DEFAULT_SIZE)
+               return -E2BIG;
+
+       if (reserved_size >= WOPCM_DEFAULT_SIZE)
+               return -E2BIG;
+
+       if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+               return -E2BIG;
+
+       wp->offset = aligned_offset;
+       wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+       wp->size = wp->top - reserved_size;
+
+       return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+       struct intel_uc_fw *guc_fw = &i915->guc.fw;
+       struct intel_uc_fw *huc_fw = &i915->huc.fw;
+       struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+       size_t huc_size, guc_size;
+       u32 offset;
+       u32 reserved;
+       u32 wopcm_base;
+       u32 delta;
+       int err;
+
+       if (!i915_modparams.enable_guc_loading)
+               return;
+
+       /* No need to do partition if failed to fetch both GuC and HuC FW */
+       if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS &&
+               huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
+               goto fail;
+
+       huc_size = 0;
+       guc_size = 0;
+       offset = WOPCM_RESERVED_SIZE;
+       reserved = reserved_wopcm_size(i915);
+
+       if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+               huc_size = huc_fw->header_size + huc_fw->ucode_size;
+
+       err = do_wopcm_partition(i915, offset + huc_size, reserved);
+       if (err) {
+               if (!huc_size)
+                       goto fail;
+
+               /* Partition without loading HuC FW. */
+               err = do_wopcm_partition(i915, offset, reserved);
+               if (err)
+                       goto fail;
+       }
+
+       /*
+        * Check hardware restriction on Gen9
+        * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM base due
+        * to hardware limitation on Gen9.
+        */
+       if (IS_GEN9(i915)) {
+               wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET;
+               if (unlikely(wopcm_base > wp->size))
+                       goto fail;
+
+               delta = wp->size - wopcm_base;
+               if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+                       goto fail;
+       }
+
+       if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+               guc_size = guc_fw->header_size + guc_fw->ucode_size;
+               /* Need 8K stack for GuC */
+               guc_size += GUC_WOPCM_STACK_RESERVED;
+       }
+

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 189

Quoted 10 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+       if (guc_size > wp->size)
+               goto fail;
+
+       DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
+               wp->offset >> 10, wp->size >> 10, wp->top >> 10);
+
+       return;
+
+fail:
+       DRM_ERROR("WOPCM partitioning failed. Falling back to execlist mode\n");

As CI tells you using DRM_ERROR() here is a no-no. Talk to Michal to determine the right message and when to present it to the *user*.

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 191

Quoted 2 lines
drivers/gpu/drm/i915/intel_uc.c +2 -0
+
+       intel_uc_fini_fw(i915);

This is not yours to fini.

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 197

Quoted 5 lines
drivers/gpu/drm/i915/intel_uc.c +5 -0
+       /* GuC submission won't work without valid GuC WOPCM partition */
+       if (i915_modparams.enable_guc_submission)
+               i915_modparams.enable_guc_submission = 0;
+
+       i915_modparams.enable_guc_loading = 0;

Also feels like a layering violation.

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 205

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +3 -0
+}
+
 void intel_uc_init_fw(struct drm_i915_private *dev_priv)
 {
        intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw);
        intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw);
+       guc_init_wopcm_partition(dev_priv);
 }

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#4 lore raw
Quoted 231 lines · Chris Wilson

Quoting Jackie Li (2017-11-15 17:17:08)

Quoted 11 lines

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

Quoted 5 lines

v2:
- Removed intel_wopcm_init (Ville/Sagar/Joonas)
- Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
- Removed unnecessary function calls (Joonas)
- Init GuC WOPCM partition as soon as firmware fetching is completed

Fix your indenting. Use tabs, align to brackets etc.

Quoted 200 lines
Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>
---
  drivers/gpu/drm/i915/i915_gem_context.c |   4 +-
  drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--
  drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
  drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
  drivers/gpu/drm/i915/intel_huc.c        |   2 +-
  drivers/gpu/drm/i915/intel_uc.c         | 116 +++++++++++++++++++++++++++++++-
  drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
  7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +2 -2
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private *dev_priv,
         ctx->desc_template =
                 default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
 
-       /* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not
+       /* GuC requires the ring to be placed above GuC WOPCM top. if GuC is not
          * present or not in use we still need a small bias as ring wraparound
          * at offset 0 sometimes hangs. No idea why.
          */
         if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-               ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+               ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
         else
                 ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
 
drivers/gpu/drm/i915/i915_guc_reg.h +14 -4
index bc1ae7d..567df12 100644
@@ -67,17 +67,27 @@
  #define DMA_GUC_WOPCM_OFFSET           _MMIO(0xc340)
  #define   HUC_LOADING_AGENT_VCR                  (0<<1)
  #define   HUC_LOADING_AGENT_GUC                  (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE         0x80000       /* 512KB */
  #define GUC_MAX_IDLE_COUNT             _MMIO(0xC3E4)
 
  #define HUC_STATUS2             _MMIO(0xD3B0)
  #define   HUC_FW_VERIFIED       (1<<7)
 
  /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE             (0x1 << 20)
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE            (0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT         (0x4000)
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED       (0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED         (0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA           4
+#define GEN9_GUC_WOPCM_OFFSET          (0x24000)
+
  #define GUC_WOPCM_SIZE                 _MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP                          (0x80 << 12)  /* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED     (0x10 << 12)  /* 64KB  */
 
  /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
  #define GUC_GGTT_TOP                   0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +16 -9
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private *dev_priv)
   * This is a wrapper to create an object for use with the GuC. In order to
   * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
   * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
   * range is reserved inside GuC.
   *
   * Return:     A i915_vma if successful, otherwise an ERR_PTR.
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
                 goto err;
 
         ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-                          PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                          PIN_GLOBAL | PIN_OFFSET_BIAS |
+                          dev_priv->guc.wopcm.top);
         if (ret) {
                 vma = ERR_PTR(ret);
                 goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
         return vma;
  }
 
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
  {
-       u32 wopcm_size = GUC_WOPCM_TOP;
-
-       /* On BXT, the top of WOPCM is reserved for RC6 context */
-       if (IS_GEN9_LP(dev_priv))
-               wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+       u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top;
+       u32 offset = i915_ggtt_offset(vma);
 
-       return wopcm_size;
+       GEM_BUG_ON(!guc_wopcm_top);
+       GEM_BUG_ON(offset < guc_wopcm_top);
+       GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+       return offset;
  }
drivers/gpu/drm/i915/intel_guc.h +8 -17
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
         struct intel_engine_cs *engine;
  };
 
+struct guc_wopcm_partition {
+       u32 offset;
+       u32 size;
+       u32 top;
+};
+
  /*
   * Top level structure of GuC. It handles firmware loading and manages client
   * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
   */
  struct intel_guc {
         struct intel_uc_fw fw;
+       struct guc_wopcm_partition wopcm;
         struct intel_guc_log log;
         struct intel_guc_ct ct;
 
@@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)
         guc->notify(guc);
  }
 
-/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-       u32 offset = i915_ggtt_offset(vma);
-
-       GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-       GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
-
-       return offset;
-}
-
  void intel_guc_init_early(struct intel_guc *guc);
  void intel_guc_init_send_regs(struct intel_guc *guc);
  void intel_guc_init_params(struct intel_guc *guc);
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
  int intel_guc_suspend(struct drm_i915_private *dev_priv);
  int intel_guc_resume(struct drm_i915_private *dev_priv);
  struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);
 
  #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
                 return;
 
         vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-                               PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                               PIN_OFFSET_BIAS | guc->wopcm.top);
         if (IS_ERR(vma)) {
                 DRM_ERROR("failed to pin huc fw object %d\n",
                                 (int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +1 -0
index aec2954..4f6fa67 100644
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct drm_i915_private *dev_priv)
         intel_guc_init_early(&dev_priv->guc);
  }
 
+static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 10 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+       /* On BXT, the top of WOPCM is reserved for RC6 context */
+       if (IS_GEN9_LP(i915))
+               return BXT_WOPCM_RC6_RESERVED;
+
+       return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32 offset,
+                              u32 reserved_size)

do ?

Quoted 7 lines

From that I was expecting action, talking to hw and excitement.

Pass in guc_wopcm_partition and call this

static int wocpm_partition_init(struct guc_wocpm_partition *wp,

				u32 offset, u32 size)

You are definitely right. will update it. Thanks!

Quoted 84 lines
Quoted 84 lines
drivers/gpu/drm/i915/intel_uc.c +84 -0
+{
+       struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+       u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGNMENT);
+
+       if (offset >= WOPCM_DEFAULT_SIZE)
+               return -E2BIG;
+
+       if (reserved_size >= WOPCM_DEFAULT_SIZE)
+               return -E2BIG;
+
+       if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+               return -E2BIG;
+
+       wp->offset = aligned_offset;
+       wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+       wp->size = wp->top - reserved_size;
+
+       return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+       struct intel_uc_fw *guc_fw = &i915->guc.fw;
+       struct intel_uc_fw *huc_fw = &i915->huc.fw;
+       struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+       size_t huc_size, guc_size;
+       u32 offset;
+       u32 reserved;
+       u32 wopcm_base;
+       u32 delta;
+       int err;
+
+       if (!i915_modparams.enable_guc_loading)
+               return;
+
+       /* No need to do partition if failed to fetch both GuC and HuC FW */
+       if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS &&
+               huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
+               goto fail;
+
+       huc_size = 0;
+       guc_size = 0;
+       offset = WOPCM_RESERVED_SIZE;
+       reserved = reserved_wopcm_size(i915);
+
+       if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+               huc_size = huc_fw->header_size + huc_fw->ucode_size;
+
+       err = do_wopcm_partition(i915, offset + huc_size, reserved);
+       if (err) {
+               if (!huc_size)
+                       goto fail;
+
+               /* Partition without loading HuC FW. */
+               err = do_wopcm_partition(i915, offset, reserved);
+               if (err)
+                       goto fail;
+       }
+
+       /*
+        * Check hardware restriction on Gen9
+        * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM base due
+        * to hardware limitation on Gen9.
+        */
+       if (IS_GEN9(i915)) {
+               wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET;
+               if (unlikely(wopcm_base > wp->size))
+                       goto fail;
+
+               delta = wp->size - wopcm_base;
+               if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+                       goto fail;
+       }
+
+       if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+               guc_size = guc_fw->header_size + guc_fw->ucode_size;
+               /* Need 8K stack for GuC */
+               guc_size += GUC_WOPCM_STACK_RESERVED;
+       }
+
+       if (guc_size > wp->size)
+               goto fail;
+
+       DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
Quoted 9 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 189

Quoted 6 lines
drivers/gpu/drm/i915/intel_uc.c +6 -0
+               wp->offset >> 10, wp->size >> 10, wp->top >> 10);
+
+       return;
+
+fail:
+       DRM_ERROR("WOPCM partitioning failed. Falling back to execlist mode\n");

As CI tells you using DRM_ERROR() here is a no-no. Talk to Michal to determine the right message and when to present it to the *user*.

will check on it. Thanks!

Quoted 3 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 191

Quoted 2 lines
drivers/gpu/drm/i915/intel_uc.c +2 -0
+
+       intel_uc_fini_fw(i915);

This is not yours to fini.

we should release the fw memories since they won't be used anymore. I understand this is driver level (at least uc level) call, but there's no other suitable candidates for releasing these memories.

Quoted 6 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 197

Quoted 5 lines
drivers/gpu/drm/i915/intel_uc.c +5 -0
+       /* GuC submission won't work without valid GuC WOPCM partition */
+       if (i915_modparams.enable_guc_submission)
+               i915_modparams.enable_guc_submission = 0;
+
+       i915_modparams.enable_guc_loading = 0;

Also feels like a layering violation.

Wanted to disable both guc loading and submission completely as long as we found no suitable wopcm partition for guc, so that we will know guc would be used while creating the kernel gem context.

One option might be moving these code into intel_uc_init_fw()?

Or removing these code and adding a check in __create_hw_context() to make sure the allocation of the kernel context won't use guc wopcm top on parritioning failure.

Quoted 8 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 205

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +3 -0
+}
+
  void intel_uc_init_fw(struct drm_i915_private *dev_priv)
  {
         intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw);
         intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw);
+       guc_init_wopcm_partition(dev_priv);
  }

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw
In reply to Jackie Li

Typo in the subject.
GLK showing failure to load GuC with this approach on CI.

Quoted 60 lines · Jackie Li

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
- Removed intel_wopcm_init (Ville/Sagar/Joonas)
- Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
- Removed unnecessary function calls (Joonas)
- Init GuC WOPCM partition as soon as firmware fetching is completed

Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>
---
  drivers/gpu/drm/i915/i915_gem_context.c |   4 +-
  drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--
  drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
  drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
  drivers/gpu/drm/i915/intel_huc.c        |   2 +-
  drivers/gpu/drm/i915/intel_uc.c         | 116 +++++++++++++++++++++++++++++++-
  drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
  7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +2 -2
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private *dev_priv,
  	ctx->desc_template =
  		default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
 
-	/* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not
+	/* GuC requires the ring to be placed above GuC WOPCM top. if GuC is not
  	 * present or not in use we still need a small bias as ring wraparound
  	 * at offset 0 sometimes hangs. No idea why.
  	 */
  	if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-		ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+		ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
  	else
  		ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
 
drivers/gpu/drm/i915/i915_guc_reg.h +0 -0
index bc1ae7d..567df12 100644
@@ -67,17 +67,27 @@
  #define DMA_GUC_WOPCM_OFFSET		_MMIO(0xc340)
  #define   HUC_LOADING_AGENT_VCR		  (0<<1)

drivers/gpu/drm/i915/i915_guc_reg.h line 77

Quoted 10 lines
drivers/gpu/drm/i915/i915_guc_reg.h +2 -1
  #define   HUC_LOADING_AGENT_GUC		  (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE	  0x80000	/* 512KB */
  #define GUC_MAX_IDLE_COUNT		_MMIO(0xC3E4)
 
  #define HUC_STATUS2             _MMIO(0xD3B0)
  #define   HUC_FW_VERIFIED       (1<<7)
 
  /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE		(0x1 << 20)

possible to get this size from register GEN6_STOLEN_RESERVED (ggtt->stolen_reserved_size)

drivers/gpu/drm/i915/i915_guc_reg.h line 81

Quoted 4 lines
drivers/gpu/drm/i915/i915_guc_reg.h +4 -0
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE		(0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT		(0x4000)

prefix this with GUC_ as it is specific to GuC in WOPCM

Quoted 114 lines
drivers/gpu/drm/i915/i915_guc_reg.h +8 -3
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED	(0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED		(0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA		4
+#define GEN9_GUC_WOPCM_OFFSET		(0x24000)
+
  #define GUC_WOPCM_SIZE			_MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP			  (0x80 << 12)	/* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED	  (0x10 << 12)	/* 64KB  */
 
  /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
  #define GUC_GGTT_TOP			0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +16 -9
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private *dev_priv)
   * This is a wrapper to create an object for use with the GuC. In order to
   * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
   * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
   * range is reserved inside GuC.
   *
   * Return:	A i915_vma if successful, otherwise an ERR_PTR.
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
  		goto err;
 
  	ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-			   PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+			   PIN_GLOBAL | PIN_OFFSET_BIAS |
+			   dev_priv->guc.wopcm.top);
  	if (ret) {
  		vma = ERR_PTR(ret);
  		goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
  	return vma;
  }
 
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
  {
-	u32 wopcm_size = GUC_WOPCM_TOP;
-
-	/* On BXT, the top of WOPCM is reserved for RC6 context */
-	if (IS_GEN9_LP(dev_priv))
-		wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+	u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top;
+	u32 offset = i915_ggtt_offset(vma);
 
-	return wopcm_size;
+	GEM_BUG_ON(!guc_wopcm_top);
+	GEM_BUG_ON(offset < guc_wopcm_top);
+	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+	return offset;
  }
drivers/gpu/drm/i915/intel_guc.h +7 -16
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
  	struct intel_engine_cs *engine;
  };
 
+struct guc_wopcm_partition {
+	u32 offset;
+	u32 size;
+	u32 top;
+};
+
  /*
   * Top level structure of GuC. It handles firmware loading and manages client
   * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
   */
  struct intel_guc {
  	struct intel_uc_fw fw;
+	struct guc_wopcm_partition wopcm;
  	struct intel_guc_log log;
  	struct intel_guc_ct ct;
 
@@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)
  	guc->notify(guc);
  }
 
-/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-	u32 offset = i915_ggtt_offset(vma);
-
-	GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
-
-	return offset;
-}
-
  void intel_guc_init_early(struct intel_guc *guc);
  void intel_guc_init_send_regs(struct intel_guc *guc);
  void intel_guc_init_params(struct intel_guc *guc);

drivers/gpu/drm/i915/intel_guc.h int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset); · line 120

Quoted 5 lines
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
  int intel_guc_suspend(struct drm_i915_private *dev_priv);
  int intel_guc_resume(struct drm_i915_private *dev_priv);
  struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);

Why are we exporting this function. If we have to export then name should be intel_guc_ggtt_offset also pass intel_guc struct as param.
Any function we export for GuC should have name prefixed "intel_guc" and intel_guc struct as param. suspend/resume functions above are to be updated in upcoming series.

Quoted 20 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
  #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
  		return;
 
  	vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-				PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+				PIN_OFFSET_BIAS | guc->wopcm.top);
  	if (IS_ERR(vma)) {
  		DRM_ERROR("failed to pin huc fw object %d\n",
  				(int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +0 -0
index aec2954..4f6fa67 100644

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 89

Quoted 4 lines
drivers/gpu/drm/i915/intel_uc.c +1 -0
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct drm_i915_private *dev_priv)
  	intel_guc_init_early(&dev_priv->guc);
  }
 
+static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

Can we make this wopcm_top_reserved_size.
there is reserved at the beginning (WOPCM_RESERVED_SIZE). Can name it WOPCM_BEGIN_RESERVED_SIZE.

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 10 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+	/* On BXT, the top of WOPCM is reserved for RC6 context */
+	if (IS_GEN9_LP(i915))
+		return BXT_WOPCM_RC6_RESERVED;
+
+	return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32 offset,
+			       u32 reserved_size)

This can be named guc_wopcm_partition_init as Chris suggested. and name caller as intel_guc_init_wopcm_partition.
These functions are GuC specific hence they should be defined in intel_guc.c.

Quoted 95 lines
drivers/gpu/drm/i915/intel_uc.c +95 -0
+{
+	struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+	u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGN	MENT);
+
+	if (offset >= WOPCM_DEFAULT_SIZE)
+		return -E2BIG;
+
+	if (reserved_size >= WOPCM_DEFAULT_SIZE)
+		return -E2BIG;
+
+	if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+		return -E2BIG;
+
+	wp->offset = aligned_offset;
+	wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+	wp->size = wp->top - reserved_size;
+
+	return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+	struct intel_uc_fw *guc_fw = &i915->guc.fw;
+	struct intel_uc_fw *huc_fw = &i915->huc.fw;
+	struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+	size_t huc_size, guc_size;
+	u32 offset;
+	u32 reserved;
+	u32 wopcm_base;
+	u32 delta;
+	int err;
+
+	if (!i915_modparams.enable_guc_loading)
+		return;
+
+	/* No need to do partition if failed to fetch both GuC and HuC FW */
+	if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS &&
+		huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
+		goto fail;
+
+	huc_size = 0;
+	guc_size = 0;
+	offset = WOPCM_RESERVED_SIZE;
+	reserved = reserved_wopcm_size(i915);
+
+	if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+		huc_size = huc_fw->header_size + huc_fw->ucode_size;
+
+	err = do_wopcm_partition(i915, offset + huc_size, reserved);
+	if (err) {
+		if (!huc_size)
+			goto fail;
+
+		/* Partition without loading HuC FW. */
+		err = do_wopcm_partition(i915, offset, reserved);
+		if (err)
+			goto fail;
+	}
+
+	/*
+	 * Check hardware restriction on Gen9
+	 * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM base due
+	 * to hardware limitation on Gen9.
+	 */
+	if (IS_GEN9(i915)) {
+		wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET;
+		if (unlikely(wopcm_base > wp->size))
+			goto fail;
+
+		delta = wp->size - wopcm_base;
+		if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+			goto fail;
+	}
+
+	if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+		guc_size = guc_fw->header_size + guc_fw->ucode_size;
+		/* Need 8K stack for GuC */
+		guc_size += GUC_WOPCM_STACK_RESERVED;
+	}
+
+	if (guc_size > wp->size)
+		goto fail;
+
+	DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
+		wp->offset >> 10, wp->size >> 10, wp->top >> 10);
+
+	return;
+
+fail:
+	DRM_ERROR("WOPCM partitioning failed. Falling back to execlist mode\n");
+
+	intel_uc_fini_fw(i915);
+
+	/* GuC submission won't work without valid GuC WOPCM partition */
+	if (i915_modparams.enable_guc_submission)

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 204

Quoted 10 lines
drivers/gpu/drm/i915/intel_uc.c +6 -0
+		i915_modparams.enable_guc_submission = 0;
+
+	i915_modparams.enable_guc_loading = 0;
+}
+
  void intel_uc_init_fw(struct drm_i915_private *dev_priv)
  {
  	intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw);
  	intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw);
+	guc_init_wopcm_partition(dev_priv);

Create intel_uc_init_wopcm_partition(dev_priv) and call intel_guc_init_wopcm_partition(guc) from there.

Quoted 44 lines
drivers/gpu/drm/i915/intel_uc.c +2 -2
  }
 
  void intel_uc_fini_fw(struct drm_i915_private *dev_priv)
@@ -174,9 +286,9 @@ int intel_uc_init_hw(struct drm_i915_private *dev_priv)
  	}
 
  	/* init WOPCM */
-	I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
+	I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size);
  	I915_WRITE(DMA_GUC_WOPCM_OFFSET,
-		   GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
+		   guc->wopcm.offset | HUC_LOADING_AGENT_GUC);
 
  	/* WaEnableuKernelHeaderValidFix:skl */
  	/* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
drivers/gpu/drm/i915/intel_uc_fw.c +7 -2
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
  	uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
  	uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);
 
-	/* Header and uCode will be loaded to WOPCM */
+	/*
+	 * Header and uCode will be loaded to WOPCM
+	 * Only check the size against the overall available WOPCM here. Will
+	 * continue to check the size during WOPCM partition calculation.
+	 */
  	size = uc_fw->header_size + uc_fw->ucode_size;
-	if (size > intel_guc_wopcm_size(dev_priv)) {
+	if (size > WOPCM_DEFAULT_SIZE) {
  		DRM_WARN("%s: Firmware is too large to fit in WOPCM\n",
  			 intel_uc_fw_type_repr(uc_fw->type));
  		err = -E2BIG;
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
  		       int (*xfer)(struct intel_uc_fw *uc_fw,
  				   struct i915_vma *vma))
  {
+	struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
  	struct i915_vma *vma;
  	int err;
 

drivers/gpu/drm/i915/intel_uc_fw.c int intel_uc_fw_upload(struct intel_uc_fw *uc_fw, · line 241

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc_fw.c +1 -1
@@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
  	}
 
  	vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0,
-				       PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+				       PIN_OFFSET_BIAS | i915->guc.wopcm.top);
  	if (IS_ERR(vma)) {
  		err = PTR_ERR(vma);
  		DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw
Quoted 82 lines · Sagar Arun Kamble

Typo in the subject.
GLK showing failure to load GuC with this approach on CI.

Quoted 62 lines · Jackie Li

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
- Removed intel_wopcm_init (Ville/Sagar/Joonas)
- Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
- Removed unnecessary function calls (Joonas)
- Init GuC WOPCM partition as soon as firmware fetching is completed

Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>
---
  drivers/gpu/drm/i915/i915_gem_context.c |   4 +-
  drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--
  drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
  drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
  drivers/gpu/drm/i915/intel_huc.c        |   2 +-
  drivers/gpu/drm/i915/intel_uc.c         | 116  
+++++++++++++++++++++++++++++++-
  drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
  7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private  
 *dev_priv,
  	ctx->desc_template =
  		default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
  -	/* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC  

is not

drivers/gpu/drm/i915/i915_gem_context.c +1 -0
+	/* GuC requires the ring to be placed above GuC WOPCM top. if GuC is  

not
* present or not in use we still need a small bias as ring
wraparound
* at offset 0 sometimes hangs. No idea why.
*/
if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)

drivers/gpu/drm/i915/i915_gem_context.c +1 -1
-		ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+		ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
  	else
  		ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
  diff --git a/drivers/gpu/drm/i915/i915_guc_reg.h  

b/drivers/gpu/drm/i915/i915_guc_reg.h
index bc1ae7d..567df12 100644

drivers/gpu/drm/i915/i915_guc_reg.h line 75

Quoted 10 lines
drivers/gpu/drm/i915/i915_guc_reg.h +2 -1
@@ -67,17 +67,27 @@
  #define DMA_GUC_WOPCM_OFFSET		_MMIO(0xc340)
  #define   HUC_LOADING_AGENT_VCR		  (0<<1)
  #define   HUC_LOADING_AGENT_GUC		  (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE	  0x80000	/* 512KB */
  #define GUC_MAX_IDLE_COUNT		_MMIO(0xC3E4)
    #define HUC_STATUS2             _MMIO(0xD3B0)
  #define   HUC_FW_VERIFIED       (1<<7)
    /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE		(0x1 << 20)

possible to get this size from register GEN6_STOLEN_RESERVED (ggtt->stolen_reserved_size)

drivers/gpu/drm/i915/i915_guc_reg.h line 81

Quoted 4 lines
drivers/gpu/drm/i915/i915_guc_reg.h +4 -0
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE		(0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT		(0x4000)

prefix this with GUC_ as it is specific to GuC in WOPCM

Quoted 7 lines

drivers/gpu/drm/i915/i915_guc_reg.h line 88

Quoted 7 lines
drivers/gpu/drm/i915/i915_guc_reg.h +7 -0
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED	(0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED		(0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA		4
+#define GEN9_GUC_WOPCM_OFFSET		(0x24000)

I'm not sure that definitions unrelated to register bits shall be defined here

Quoted 64 lines
Quoted 64 lines
drivers/gpu/drm/i915/i915_guc_reg.h +1 -3
+
  #define GUC_WOPCM_SIZE			_MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP			  (0x80 << 12)	/* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED	  (0x10 << 12)	/* 64KB  */
    /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT  
 */
  #define GUC_GGTT_TOP			0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +0 -0
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private  
 *dev_priv)
   * This is a wrapper to create an object for use with the GuC. In  

order to
* use it inside the GuC, an object needs to be pinned lifetime, so
we allocate
* both some backing storage and a range inside the Global GTT. We
must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
* range is reserved inside GuC.
*
* Return: A i915_vma if successful, otherwise an ERR_PTR.

drivers/gpu/drm/i915/intel_guc.c +6 -1
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct  
 intel_guc *guc, u32 size)
  		goto err;
    	ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-			   PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+			   PIN_GLOBAL | PIN_OFFSET_BIAS |
+			   dev_priv->guc.wopcm.top);
  	if (ret) {
  		vma = ERR_PTR(ret);
  		goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct  
 intel_guc *guc, u32 size)
  	return vma;
  }
  -u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along  

with
+ * top of WOPCM.
+ */

drivers/gpu/drm/i915/intel_guc.c +7 -5
+u32 guc_ggtt_offset(struct i915_vma *vma)
  {
-	u32 wopcm_size = GUC_WOPCM_TOP;
-
-	/* On BXT, the top of WOPCM is reserved for RC6 context */
-	if (IS_GEN9_LP(dev_priv))
-		wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+	u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top;
+	u32 offset = i915_ggtt_offset(vma);
  -	return wopcm_size;
+	GEM_BUG_ON(!guc_wopcm_top);
+	GEM_BUG_ON(offset < guc_wopcm_top);
+	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+	return offset;
  }
Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 41

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
  	struct intel_engine_cs *engine;
  };
  +struct guc_wopcm_partition {

s/guc_wopcm_partition/intel_guc_wopcm ?

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/intel_guc.h +5 -0
+	u32 offset;
+	u32 size;
+	u32 top;
+};
+
  /*
   * Top level structure of GuC. It handles firmware loading and  
Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 55

Quoted 8 lines

manages client
* pool and doorbells. intel_guc owns a i915_guc_client to replace
the legacy

drivers/gpu/drm/i915/intel_guc.h +1 -0
@@ -46,6 +52,7 @@ struct guc_preempt_work {
   */
  struct intel_guc {
  	struct intel_uc_fw fw;
+	struct guc_wopcm_partition wopcm;

hmm, or if we call it struct intel_wopcm then we could place it in drm_i915_private near guc/huc.

Quoted 64 lines
Quoted 29 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
  	struct intel_guc_log log;
  	struct intel_guc_ct ct;
  @@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct  

intel_guc *guc)
guc->notify(guc);
}
-/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */

drivers/gpu/drm/i915/intel_guc.h +0 -10
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-	u32 offset = i915_ggtt_offset(vma);
-
-	GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
-
-	return offset;
-}
-
  void intel_guc_init_early(struct intel_guc *guc);
  void intel_guc_init_send_regs(struct intel_guc *guc);
  void intel_guc_init_params(struct intel_guc *guc);

drivers/gpu/drm/i915/intel_guc.h int intel_guc_auth_huc(struct intel_guc *guc, u32 · line 122

Quoted 7 lines
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, u32  
 rsa_offset);
  int intel_guc_suspend(struct drm_i915_private *dev_priv);
  int intel_guc_resume(struct drm_i915_private *dev_priv);
  struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32  
 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);

Why are we exporting this function. If we have to export then name should be intel_guc_ggtt_offset also pass intel_guc struct as param.
Any function we export for GuC should have name prefixed "intel_guc" and intel_guc struct as param. suspend/resume functions above are to be updated in upcoming series.

Quoted 18 lines
    #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
  		return;
    	vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-				PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+				PIN_OFFSET_BIAS | guc->wopcm.top);
  	if (IS_ERR(vma)) {
  		DRM_ERROR("failed to pin huc fw object %d\n",
  				(int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +0 -0
index aec2954..4f6fa67 100644

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private · line 89

Quoted 4 lines
drivers/gpu/drm/i915/intel_uc.c +0 -0
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct drm_i915_private  
 *dev_priv)
  	intel_guc_init_early(&dev_priv->guc);
  }
  +static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

Can we make this wopcm_top_reserved_size.
there is reserved at the beginning (WOPCM_RESERVED_SIZE). Can name it WOPCM_BEGIN_RESERVED_SIZE.

Quoted 14 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 11 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+	/* On BXT, the top of WOPCM is reserved for RC6 context */
+	if (IS_GEN9_LP(i915))
+		return BXT_WOPCM_RC6_RESERVED;
+
+	return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32  
 offset,
+			       u32 reserved_size)

This can be named guc_wopcm_partition_init as Chris suggested. and name caller as intel_guc_init_wopcm_partition.
These functions are GuC specific hence they should be defined in intel_guc.c.

Hmm, as during wopcm partition we need to know HuC fw size, I'm not 100% sure that these functions shall be placed in intel_guc.c ... unless we try to pass fw sizes as params, or

Other option would be to create intel_[guc|uc]_wopcm.c|h

Quoted 39 lines
Quoted 39 lines
drivers/gpu/drm/i915/intel_uc.c +39 -0
+{
+	struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+	u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGN	MENT);
+
+	if (offset >= WOPCM_DEFAULT_SIZE)
+		return -E2BIG;
+
+	if (reserved_size >= WOPCM_DEFAULT_SIZE)
+		return -E2BIG;
+
+	if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+		return -E2BIG;
+
+	wp->offset = aligned_offset;
+	wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+	wp->size = wp->top - reserved_size;
+
+	return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+	struct intel_uc_fw *guc_fw = &i915->guc.fw;
+	struct intel_uc_fw *huc_fw = &i915->huc.fw;
+	struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+	size_t huc_size, guc_size;
+	u32 offset;
+	u32 reserved;
+	u32 wopcm_base;
+	u32 delta;
+	int err;
+
+	if (!i915_modparams.enable_guc_loading)
+		return;
+
+	/* No need to do partition if failed to fetch both GuC and HuC FW */
+	if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS &&
+		huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
+		goto fail;
Quoted 8 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 146

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +8 -0
+
+	huc_size = 0;
+	guc_size = 0;
+	offset = WOPCM_RESERVED_SIZE;
+	reserved = reserved_wopcm_size(i915);
+
+	if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+		huc_size = huc_fw->header_size + huc_fw->ucode_size;

maybe to reduce code duplication you can create inline in intel_uc_fw.h

static inline u32 intel_uc_fw_get_size(struct intel_uc_fw *uc_fw)

{
	if (uc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
		return 0;
	return uc_fw->header_size + uc_fw->ucode_size;
}
Quoted 52 lines
Quoted 52 lines
drivers/gpu/drm/i915/intel_uc.c +51 -0
+
+	err = do_wopcm_partition(i915, offset + huc_size, reserved);
+	if (err) {
+		if (!huc_size)
+			goto fail;
+
+		/* Partition without loading HuC FW. */
+		err = do_wopcm_partition(i915, offset, reserved);
+		if (err)
+			goto fail;
+	}
+
+	/*
+	 * Check hardware restriction on Gen9
+	 * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM base due
+	 * to hardware limitation on Gen9.
+	 */
+	if (IS_GEN9(i915)) {
+		wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET;
+		if (unlikely(wopcm_base > wp->size))
+			goto fail;
+
+		delta = wp->size - wopcm_base;
+		if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+			goto fail;
+	}
+
+	if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+		guc_size = guc_fw->header_size + guc_fw->ucode_size;
+		/* Need 8K stack for GuC */
+		guc_size += GUC_WOPCM_STACK_RESERVED;
+	}
+
+	if (guc_size > wp->size)
+		goto fail;
+
+	DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
+		wp->offset >> 10, wp->size >> 10, wp->top >> 10);
+
+	return;
+
+fail:
+	DRM_ERROR("WOPCM partitioning failed. Falling back to execlist  
 mode\n");
+
+	intel_uc_fini_fw(i915);
+
+	/* GuC submission won't work without valid GuC WOPCM partition */
+	if (i915_modparams.enable_guc_submission)
+		i915_modparams.enable_guc_submission = 0;
+
+	i915_modparams.enable_guc_loading = 0;
Quoted 8 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 204

Quoted 7 lines
drivers/gpu/drm/i915/intel_uc.c +3 -0
+}
+
  void intel_uc_init_fw(struct drm_i915_private *dev_priv)
  {
  	intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw);
  	intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw);
+	guc_init_wopcm_partition(dev_priv);

Create intel_uc_init_wopcm_partition(dev_priv) and call intel_guc_init_wopcm_partition(guc) from there.

hmm, I'm not sure what benefit you expect from this call chain ?

Quoted 41 lines
Quoted 41 lines
drivers/gpu/drm/i915/intel_uc.c +2 -2
  }
    void intel_uc_fini_fw(struct drm_i915_private *dev_priv)
@@ -174,9 +286,9 @@ int intel_uc_init_hw(struct drm_i915_private  
 *dev_priv)
  	}
    	/* init WOPCM */
-	I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
+	I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size);
  	I915_WRITE(DMA_GUC_WOPCM_OFFSET,
-		   GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
+		   guc->wopcm.offset | HUC_LOADING_AGENT_GUC);
    	/* WaEnableuKernelHeaderValidFix:skl */
  	/* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
drivers/gpu/drm/i915/intel_uc_fw.c +7 -1
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private  
 *dev_priv,
  	uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
  	uc_fw->ucode_size = (css->size_dw - css->header_size_dw) *  
 sizeof(u32);
  -	/* Header and uCode will be loaded to WOPCM */
+	/*
+	 * Header and uCode will be loaded to WOPCM
+	 * Only check the size against the overall available WOPCM here. Will
+	 * continue to check the size during WOPCM partition calculation.
+	 */
  	size = uc_fw->header_size + uc_fw->ucode_size;
-	if (size > intel_guc_wopcm_size(dev_priv)) {
+	if (size > WOPCM_DEFAULT_SIZE) {
  		DRM_WARN("%s: Firmware is too large to fit in WOPCM\n",
  			 intel_uc_fw_type_repr(uc_fw->type));
  		err = -E2BIG;
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
  		       int (*xfer)(struct intel_uc_fw *uc_fw,
  				   struct i915_vma *vma))
  {
+	struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
  	struct i915_vma *vma;
  	int err;
Quoted 8 lines

drivers/gpu/drm/i915/intel_uc_fw.c int intel_uc_fw_upload(struct intel_uc_fw *uc_fw, · line 241

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
  @@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,

}

    	vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0,
drivers/gpu/drm/i915/intel_uc_fw.c +1 -1
-				       PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+				       PIN_OFFSET_BIAS | i915->guc.wopcm.top);
  	if (IS_ERR(vma)) {
  		err = PTR_ERR(vma);
  		DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw
Quoted 164 lines · Michal Wajdeczko
Quoted 79 lines · Sagar Arun Kamble

Typo in the subject.
GLK showing failure to load GuC with this approach on CI.

Quoted 59 lines · Jackie Li

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is  set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
  - Removed intel_wopcm_init (Ville/Sagar/Joonas)
  - Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
  - Removed unnecessary function calls (Joonas)
  - Init GuC WOPCM partition as soon as firmware fetching is completed

Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>

---
  drivers/gpu/drm/i915/i915_gem_context.c |   4 +- drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--

  drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
  drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
  drivers/gpu/drm/i915/intel_huc.c        |   2 +-
  drivers/gpu/drm/i915/intel_uc.c         | 116 
+++++++++++++++++++++++++++++++-
  drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
  7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private 
 *dev_priv,

      ctx->desc_template =
          default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
  -    /* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not +    /* GuC requires the ring to be placed above GuC WOPCM top. if
GuC is not
       * present or not in use we still need a small bias as ring wraparound
       * at offset 0 sometimes hangs. No idea why.
       */
      if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-        ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+        ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
      else
          ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
  diff --git a/drivers/gpu/drm/i915/i915_guc_reg.h b/drivers/gpu/drm/i915/i915_guc_reg.h index bc1ae7d..567df12 100644

drivers/gpu/drm/i915/i915_guc_reg.h line 75

Quoted 10 lines
drivers/gpu/drm/i915/i915_guc_reg.h +2 -1
@@ -67,17 +67,27 @@
   #define DMA_GUC_WOPCM_OFFSET        _MMIO(0xc340)
   #define   HUC_LOADING_AGENT_VCR          (0<<1)
   #define   HUC_LOADING_AGENT_GUC          (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE      0x80000    /* 512KB */
   #define GUC_MAX_IDLE_COUNT        _MMIO(0xC3E4)
     #define HUC_STATUS2             _MMIO(0xD3B0)
   #define   HUC_FW_VERIFIED       (1<<7)
     /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE        (0x1 << 20)

possible to get this size from register GEN6_STOLEN_RESERVED (ggtt->stolen_reserved_size)

drivers/gpu/drm/i915/i915_guc_reg.h line 81

Quoted 4 lines
drivers/gpu/drm/i915/i915_guc_reg.h +4 -0
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE        (0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT        (0x4000)

prefix this with GUC_ as it is specific to GuC in WOPCM

Quoted 7 lines

drivers/gpu/drm/i915/i915_guc_reg.h line 88

Quoted 7 lines
drivers/gpu/drm/i915/i915_guc_reg.h +7 -0
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED    (0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED        (0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA        4
+#define GEN9_GUC_WOPCM_OFFSET        (0x24000)

I'm not sure that definitions unrelated to register bits shall be defined here

Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/i915_guc_reg.h +1 -3
+
   #define GUC_WOPCM_SIZE            _MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP              (0x80 << 12)    /* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED      (0x10 << 12)    /* 64KB  */
     /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
   #define GUC_GGTT_TOP            0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +0 -1
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private 
 *dev_priv)
    * This is a wrapper to create an object for use with the GuC. In order to
    * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
    * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) 

because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
   * range is reserved inside GuC.
   *
   * Return:    A i915_vma if successful, otherwise an ERR_PTR.

drivers/gpu/drm/i915/intel_guc.c +6 -1
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct 
 intel_guc *guc, u32 size)
           goto err;
         ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-               PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+               PIN_GLOBAL | PIN_OFFSET_BIAS |
+               dev_priv->guc.wopcm.top);
       if (ret) {
           vma = ERR_PTR(ret);
           goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct 
 intel_guc *guc, u32 size)
       return vma;
   }
   -u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along 

with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
  {
-    u32 wopcm_size = GUC_WOPCM_TOP;
-
-    /* On BXT, the top of WOPCM is reserved for RC6 context */ -    if (IS_GEN9_LP(dev_priv))
-        wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+    u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top; +    u32 offset = i915_ggtt_offset(vma);
  -    return wopcm_size;
+    GEM_BUG_ON(!guc_wopcm_top);
+    GEM_BUG_ON(offset < guc_wopcm_top);
+    GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+    return offset;
  }

Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 41

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
       struct intel_engine_cs *engine;
   };
   +struct guc_wopcm_partition {

s/guc_wopcm_partition/intel_guc_wopcm ?

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc.h +5 -0
+    u32 offset;
+    u32 size;
+    u32 top;
+};
+
Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 55

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +1 -0
   /*
    * Top level structure of GuC. It handles firmware loading and manages client
    * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
    */
   struct intel_guc {
       struct intel_uc_fw fw;
+    struct guc_wopcm_partition wopcm;

hmm, or if we call it struct intel_wopcm then we could place it in drm_i915_private near guc/huc.

Since this is currently GuC specific structure naming it intel_guc_wopcm and keeping it here is correct i think.

Quoted 80 lines
Quoted 65 lines
Quoted 31 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
       struct intel_guc_log log;
       struct intel_guc_ct ct;
   @@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)

      guc->notify(guc);
  }
  -/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */

drivers/gpu/drm/i915/intel_guc.h +0 -6
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-    u32 offset = i915_ggtt_offset(vma);
-
-    GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-    GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, 

GUC_GGTT_TOP));

drivers/gpu/drm/i915/intel_guc.h +0 -4
-
-    return offset;
-}
-

  void intel_guc_init_early(struct intel_guc *guc); void intel_guc_init_send_regs(struct intel_guc *guc); void intel_guc_init_params(struct intel_guc *guc);

drivers/gpu/drm/i915/intel_guc.h int intel_guc_auth_huc(struct intel_guc *guc, · line 121

Quoted 6 lines
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, 
 u32 rsa_offset);
   int intel_guc_suspend(struct drm_i915_private *dev_priv);
   int intel_guc_resume(struct drm_i915_private *dev_priv);
   struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);

Why are we exporting this function. If we have to export then name should be intel_guc_ggtt_offset also pass intel_guc struct as param.
Any function we export for GuC should have name prefixed "intel_guc" and intel_guc struct as param. suspend/resume functions above are to be updated in upcoming series.

Quoted 18 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
     #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
           return;
         vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-                PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                PIN_OFFSET_BIAS | guc->wopcm.top);
       if (IS_ERR(vma)) {
           DRM_ERROR("failed to pin huc fw object %d\n",
                   (int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +0 -0
index aec2954..4f6fa67 100644

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct · line 89

Quoted 4 lines
drivers/gpu/drm/i915/intel_uc.c +0 -0
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct 
 drm_i915_private *dev_priv)
       intel_guc_init_early(&dev_priv->guc);
   }
   +static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

Can we make this wopcm_top_reserved_size.
there is reserved at the beginning (WOPCM_RESERVED_SIZE). Can name it WOPCM_BEGIN_RESERVED_SIZE.

Quoted 14 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 11 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+    /* On BXT, the top of WOPCM is reserved for RC6 context */
+    if (IS_GEN9_LP(i915))
+        return BXT_WOPCM_RC6_RESERVED;
+
+    return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32 
 offset,
+                   u32 reserved_size)

This can be named guc_wopcm_partition_init as Chris suggested. and name caller as intel_guc_init_wopcm_partition.
These functions are GuC specific hence they should be defined in intel_guc.c.

Quoted 6 lines

Hmm, as during wopcm partition we need to know HuC fw size, I'm not 100% sure that these functions shall be placed in intel_guc.c ... unless we try to pass fw sizes as params, or

Other option would be to create intel_[guc|uc]_wopcm.c|h

I think this is similar to way we handle HuC auth via GuC where we have firmware tasks in specific functions. we could export a function to get the HuC FW size and then guc.c can call that.

Quoted 97 lines
Quoted 40 lines
Quoted 40 lines
drivers/gpu/drm/i915/intel_uc.c +36 -0
+{
+    struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+    u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGN MENT);
+
+    if (offset >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    if (reserved_size >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    wp->offset = aligned_offset;
+    wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+    wp->size = wp->top - reserved_size;
+
+    return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+    struct intel_uc_fw *guc_fw = &i915->guc.fw;
+    struct intel_uc_fw *huc_fw = &i915->huc.fw;
+    struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+    size_t huc_size, guc_size;
+    u32 offset;
+    u32 reserved;
+    u32 wopcm_base;
+    u32 delta;
+    int err;
+
+    if (!i915_modparams.enable_guc_loading)
+        return;
+
+    /* No need to do partition if failed to fetch both GuC and HuC 

FW */
+    if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS && +        huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) +        goto fail;

Quoted 8 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 146

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +8 -0
+
+    huc_size = 0;
+    guc_size = 0;
+    offset = WOPCM_RESERVED_SIZE;
+    reserved = reserved_wopcm_size(i915);
+
+    if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+        huc_size = huc_fw->header_size + huc_fw->ucode_size;

maybe to reduce code duplication you can create inline in intel_uc_fw.h

static inline u32 intel_uc_fw_get_size(struct intel_uc_fw *uc_fw) {
    if (uc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) return 0;
    return uc_fw->header_size + uc_fw->ucode_size;
}

Quoted 39 lines
Quoted 39 lines
drivers/gpu/drm/i915/intel_uc.c +15 -0
+
+    err = do_wopcm_partition(i915, offset + huc_size, reserved);
+    if (err) {
+        if (!huc_size)
+            goto fail;
+
+        /* Partition without loading HuC FW. */
+        err = do_wopcm_partition(i915, offset, reserved);
+        if (err)
+            goto fail;
+    }
+
+    /*
+     * Check hardware restriction on Gen9
+     * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM 

base due
+     * to hardware limitation on Gen9.
+     */
+    if (IS_GEN9(i915)) {
+        wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET; +        if (unlikely(wopcm_base > wp->size))
+            goto fail;

drivers/gpu/drm/i915/intel_uc.c +17 -0
+
+        delta = wp->size - wopcm_base;
+        if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+            goto fail;
+    }
+
+    if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+        guc_size = guc_fw->header_size + guc_fw->ucode_size;
+        /* Need 8K stack for GuC */
+        guc_size += GUC_WOPCM_STACK_RESERVED;
+    }
+
+    if (guc_size > wp->size)
+        goto fail;
+
+    DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
+        wp->offset >> 10, wp->size >> 10, wp->top >> 10);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +5 -0
+
+    return;
+
+fail:
+    DRM_ERROR("WOPCM partitioning failed. Falling back to execlist 

mode\n");
+
+    intel_uc_fini_fw(i915);

This is correct but should be handled from intel_uc_init_fw with this function returning status.

Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 198

Quoted 7 lines
drivers/gpu/drm/i915/intel_uc.c +7 -0
+
+    /* GuC submission won't work without valid GuC WOPCM partition */
+    if (i915_modparams.enable_guc_submission)
+        i915_modparams.enable_guc_submission = 0;
+
+    i915_modparams.enable_guc_loading = 0;
+}

This sanitization will be handled by intel_guc_fw_upload during intel_uc_init_hw so not needed.

Quoted 10 lines
Quoted 7 lines
Quoted 6 lines

+
  void intel_uc_init_fw(struct drm_i915_private *dev_priv) {
      intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw); intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw); +    guc_init_wopcm_partition(dev_priv);

Create intel_uc_init_wopcm_partition(dev_priv) and call intel_guc_init_wopcm_partition(guc) from there.

hmm, I'm not sure what benefit you expect from this call chain ?

wanted to avoid firmware specific calls from here but I was wrong as we are not expecting this function to be called from outside of intel_uc. sorry.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines

  }
    void intel_uc_fini_fw(struct drm_i915_private *dev_priv)

drivers/gpu/drm/i915/intel_uc.c +2 -2
@@ -174,9 +286,9 @@ int intel_uc_init_hw(struct drm_i915_private 
 *dev_priv)
       }
         /* init WOPCM */
-    I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
+    I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size);
       I915_WRITE(DMA_GUC_WOPCM_OFFSET,
-           GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
+           guc->wopcm.offset | HUC_LOADING_AGENT_GUC);
         /* WaEnableuKernelHeaderValidFix:skl */
       /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private 
 *dev_priv,
       uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
       uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);

  -    /* Header and uCode will be loaded to WOPCM */
+    /*
+     * Header and uCode will be loaded to WOPCM
+     * Only check the size against the overall available WOPCM here. Will
+     * continue to check the size during WOPCM partition calculation. +     */
      size = uc_fw->header_size + uc_fw->ucode_size;
-    if (size > intel_guc_wopcm_size(dev_priv)) {
+    if (size > WOPCM_DEFAULT_SIZE) {
          DRM_WARN("%s: Firmware is too large to fit in WOPCM\n", intel_uc_fw_type_repr(uc_fw->type));
          err = -E2BIG;

drivers/gpu/drm/i915/intel_uc_fw.c +1 -0
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
                  int (*xfer)(struct intel_uc_fw *uc_fw,
                      struct i915_vma *vma))
   {
+    struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
       struct i915_vma *vma;
       int err;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
   @@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,

      }
        vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0, -                       PIN_OFFSET_BIAS | GUC_WOPCM_TOP); +                       PIN_OFFSET_BIAS | i915->guc.wopcm.top); if (IS_ERR(vma)) {
          err = PTR_ERR(vma);
          DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#8 lore raw
Quoted 266 lines · Sagar Arun Kamble
Quoted 165 lines · Michal Wajdeczko
Quoted 79 lines · Sagar Arun Kamble

Typo in the subject.
GLK showing failure to load GuC with this approach on CI.

Quoted 59 lines · Jackie Li

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is  set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
  - Removed intel_wopcm_init (Ville/Sagar/Joonas)
  - Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
  - Removed unnecessary function calls (Joonas)
  - Init GuC WOPCM partition as soon as firmware fetching is completed

Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>

---
  drivers/gpu/drm/i915/i915_gem_context.c |   4 +- drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--

  drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
  drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
  drivers/gpu/drm/i915/intel_huc.c        |   2 +-
  drivers/gpu/drm/i915/intel_uc.c         | 116 
+++++++++++++++++++++++++++++++-
  drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
  7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private 
 *dev_priv,

      ctx->desc_template =
          default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
  -    /* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not +    /* GuC requires the ring to be placed above GuC WOPCM top. if
GuC is not
       * present or not in use we still need a small bias as ring wraparound
       * at offset 0 sometimes hangs. No idea why.
       */
      if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-        ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+        ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
      else
          ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
  diff --git a/drivers/gpu/drm/i915/i915_guc_reg.h b/drivers/gpu/drm/i915/i915_guc_reg.h index bc1ae7d..567df12 100644

drivers/gpu/drm/i915/i915_guc_reg.h line 75

Quoted 10 lines
drivers/gpu/drm/i915/i915_guc_reg.h +2 -1
@@ -67,17 +67,27 @@
   #define DMA_GUC_WOPCM_OFFSET        _MMIO(0xc340)
   #define   HUC_LOADING_AGENT_VCR          (0<<1)
   #define   HUC_LOADING_AGENT_GUC          (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE      0x80000    /* 512KB */
   #define GUC_MAX_IDLE_COUNT        _MMIO(0xC3E4)
     #define HUC_STATUS2             _MMIO(0xD3B0)
   #define   HUC_FW_VERIFIED       (1<<7)
     /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE        (0x1 << 20)

possible to get this size from register GEN6_STOLEN_RESERVED (ggtt->stolen_reserved_size)

drivers/gpu/drm/i915/i915_guc_reg.h line 81

Quoted 4 lines
drivers/gpu/drm/i915/i915_guc_reg.h +4 -0
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE        (0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT        (0x4000)

prefix this with GUC_ as it is specific to GuC in WOPCM

Quoted 7 lines

drivers/gpu/drm/i915/i915_guc_reg.h line 88

Quoted 7 lines
drivers/gpu/drm/i915/i915_guc_reg.h +7 -0
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED    (0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED        (0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA        4
+#define GEN9_GUC_WOPCM_OFFSET        (0x24000)

I'm not sure that definitions unrelated to register bits shall be defined here

Quoted 62 lines
Quoted 62 lines
drivers/gpu/drm/i915/i915_guc_reg.h +1 -3
+
   #define GUC_WOPCM_SIZE            _MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP              (0x80 << 12) /* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED      (0x10 << 12)    /* 64KB  */
     /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
   #define GUC_GGTT_TOP            0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +0 -1
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private 
 *dev_priv)
    * This is a wrapper to create an object for use with the GuC. In order to
    * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
    * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) 

because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
   * range is reserved inside GuC.
   *
   * Return:    A i915_vma if successful, otherwise an ERR_PTR.

drivers/gpu/drm/i915/intel_guc.c +5 -1
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct 
 intel_guc *guc, u32 size)
           goto err;
         ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-               PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+               PIN_GLOBAL | PIN_OFFSET_BIAS |
+               dev_priv->guc.wopcm.top);
       if (ret) {
           vma = ERR_PTR(ret);
           goto err;
@@ -371,13 +372,19 @@ struct i915_vma 
 *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
       return vma;
   }
   -u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and 

WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
  {
-    u32 wopcm_size = GUC_WOPCM_TOP;
-
-    /* On BXT, the top of WOPCM is reserved for RC6 context */ -    if (IS_GEN9_LP(dev_priv))
-        wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+    u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top; +    u32 offset = i915_ggtt_offset(vma);
  -    return wopcm_size;
+    GEM_BUG_ON(!guc_wopcm_top);
+    GEM_BUG_ON(offset < guc_wopcm_top);
+    GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+    return offset;
  }

Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 41

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
       struct intel_engine_cs *engine;
   };
   +struct guc_wopcm_partition {

s/guc_wopcm_partition/intel_guc_wopcm ?

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc.h +5 -0
+    u32 offset;
+    u32 size;
+    u32 top;
+};
+
Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 55

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +1 -0
   /*
    * Top level structure of GuC. It handles firmware loading and manages client
    * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
    */
   struct intel_guc {
       struct intel_uc_fw fw;
+    struct guc_wopcm_partition wopcm;

hmm, or if we call it struct intel_wopcm then we could place it in drm_i915_private near guc/huc.

Since this is currently GuC specific structure naming it intel_guc_wopcm and keeping it here is correct i think.

Quoted 80 lines
Quoted 79 lines
Quoted 31 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
       struct intel_guc_log log;
       struct intel_guc_ct ct;
   @@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)

      guc->notify(guc);
  }
  -/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */

drivers/gpu/drm/i915/intel_guc.h +0 -6
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-    u32 offset = i915_ggtt_offset(vma);
-
-    GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-    GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, 

GUC_GGTT_TOP));

drivers/gpu/drm/i915/intel_guc.h +0 -4
-
-    return offset;
-}
-

  void intel_guc_init_early(struct intel_guc *guc); void intel_guc_init_send_regs(struct intel_guc *guc); void intel_guc_init_params(struct intel_guc *guc);

drivers/gpu/drm/i915/intel_guc.h int intel_guc_auth_huc(struct intel_guc *guc, · line 121

Quoted 6 lines
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, 
 u32 rsa_offset);
   int intel_guc_suspend(struct drm_i915_private *dev_priv);
   int intel_guc_resume(struct drm_i915_private *dev_priv);
   struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);

Why are we exporting this function. If we have to export then name should be intel_guc_ggtt_offset also pass intel_guc struct as param.
Any function we export for GuC should have name prefixed "intel_guc" and intel_guc struct as param. suspend/resume functions above are to be updated in upcoming series.

Quoted 18 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
     #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
           return;
         vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-                PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                PIN_OFFSET_BIAS | guc->wopcm.top);
       if (IS_ERR(vma)) {
           DRM_ERROR("failed to pin huc fw object %d\n",
                   (int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +0 -0
index aec2954..4f6fa67 100644

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct · line 89

Quoted 4 lines
drivers/gpu/drm/i915/intel_uc.c +0 -0
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct 
 drm_i915_private *dev_priv)
       intel_guc_init_early(&dev_priv->guc);
   }
   +static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

Can we make this wopcm_top_reserved_size.
there is reserved at the beginning (WOPCM_RESERVED_SIZE). Can name it WOPCM_BEGIN_RESERVED_SIZE.

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 11 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+    /* On BXT, the top of WOPCM is reserved for RC6 context */
+    if (IS_GEN9_LP(i915))
+        return BXT_WOPCM_RC6_RESERVED;
+
+    return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32 
 offset,
+                   u32 reserved_size)

This can be named guc_wopcm_partition_init as Chris suggested. and name caller as intel_guc_init_wopcm_partition.
These functions are GuC specific hence they should be defined in intel_guc.c.

Quoted 8 lines
Quoted 6 lines

Hmm, as during wopcm partition we need to know HuC fw size, I'm not 100% sure that these functions shall be placed in intel_guc.c ... unless we try to pass fw sizes as params, or

Other option would be to create intel_[guc|uc]_wopcm.c|h

I think this is similar to way we handle HuC auth via GuC where we have firmware tasks in specific functions. we could export a function to get the HuC FW size and then guc.c can call that.

Another reason I put them in intel_uc.c is I want to call intel_uc_fini_fw() on the partitioning failure.

Quoted 98 lines
Quoted 98 lines
Quoted 40 lines
Quoted 40 lines
drivers/gpu/drm/i915/intel_uc.c +36 -0
+{
+    struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+    u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGN MENT);
+
+    if (offset >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    if (reserved_size >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    wp->offset = aligned_offset;
+    wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+    wp->size = wp->top - reserved_size;
+
+    return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+    struct intel_uc_fw *guc_fw = &i915->guc.fw;
+    struct intel_uc_fw *huc_fw = &i915->huc.fw;
+    struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+    size_t huc_size, guc_size;
+    u32 offset;
+    u32 reserved;
+    u32 wopcm_base;
+    u32 delta;
+    int err;
+
+    if (!i915_modparams.enable_guc_loading)
+        return;
+
+    /* No need to do partition if failed to fetch both GuC and HuC 

FW */
+    if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS && +        huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) +        goto fail;

Quoted 8 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 146

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +8 -0
+
+    huc_size = 0;
+    guc_size = 0;
+    offset = WOPCM_RESERVED_SIZE;
+    reserved = reserved_wopcm_size(i915);
+
+    if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+        huc_size = huc_fw->header_size + huc_fw->ucode_size;

maybe to reduce code duplication you can create inline in intel_uc_fw.h

static inline u32 intel_uc_fw_get_size(struct intel_uc_fw *uc_fw) {
    if (uc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) return 0;
    return uc_fw->header_size + uc_fw->ucode_size;
}

Quoted 40 lines
Quoted 40 lines
drivers/gpu/drm/i915/intel_uc.c +15 -0
+
+    err = do_wopcm_partition(i915, offset + huc_size, reserved);
+    if (err) {
+        if (!huc_size)
+            goto fail;
+
+        /* Partition without loading HuC FW. */
+        err = do_wopcm_partition(i915, offset, reserved);
+        if (err)
+            goto fail;
+    }
+
+    /*
+     * Check hardware restriction on Gen9
+     * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM 

base due
+     * to hardware limitation on Gen9.
+     */
+    if (IS_GEN9(i915)) {
+        wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET; +        if (unlikely(wopcm_base > wp->size))
+            goto fail;

drivers/gpu/drm/i915/intel_uc.c +18 -0
+
+        delta = wp->size - wopcm_base;
+        if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+            goto fail;
+    }
+
+    if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+        guc_size = guc_fw->header_size + guc_fw->ucode_size;
+        /* Need 8K stack for GuC */
+        guc_size += GUC_WOPCM_STACK_RESERVED;
+    }
+
+    if (guc_size > wp->size)
+        goto fail;
+
+    DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
+        wp->offset >> 10, wp->size >> 10, wp->top >> 10);
+
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

+    return;

drivers/gpu/drm/i915/intel_uc.c +3 -0
+
+fail:
+    DRM_ERROR("WOPCM partitioning failed. Falling back to execlist 

mode\n");
+
+    intel_uc_fini_fw(i915);

This is correct but should be handled from intel_uc_init_fw with this function returning status.

it's a good idea. I will do it.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 198

Quoted 7 lines
drivers/gpu/drm/i915/intel_uc.c +7 -0
+
+    /* GuC submission won't work without valid GuC WOPCM partition */
+    if (i915_modparams.enable_guc_submission)
+        i915_modparams.enable_guc_submission = 0;
+
+    i915_modparams.enable_guc_loading = 0;
+}

This sanitization will be handled by intel_guc_fw_upload during intel_uc_init_hw so not needed.

It's too late to do it until intel_uc_init_hw. what I wanted to guarantee here was guc submission would be disabled as long as the partitioning failed, so that we won't need to allocate the kernel context above guc wopcm top. we sure can ignore the partitioning failure can continue allocating the context above guc wopcm top, but the problem is we don't have a valid guc wopcm top value if the partitioning was failed. another benefit to disable the guc here is we won't even bother to call down into the logics in intel_uc_init_hw since we've already known for sure. I cannot enable guc submission on the partitioning failure.

Quoted 53 lines
Quoted 10 lines
Quoted 7 lines
Quoted 6 lines

+
  void intel_uc_init_fw(struct drm_i915_private *dev_priv) {
      intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw); intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw); +    guc_init_wopcm_partition(dev_priv);

Create intel_uc_init_wopcm_partition(dev_priv) and call intel_guc_init_wopcm_partition(guc) from there.

hmm, I'm not sure what benefit you expect from this call chain ?

wanted to avoid firmware specific calls from here but I was wrong as we are not expecting this function to be called from outside of intel_uc. sorry.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines

  }
    void intel_uc_fini_fw(struct drm_i915_private *dev_priv)

drivers/gpu/drm/i915/intel_uc.c +2 -2
@@ -174,9 +286,9 @@ int intel_uc_init_hw(struct drm_i915_private 
 *dev_priv)
       }
         /* init WOPCM */
-    I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
+    I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size);
       I915_WRITE(DMA_GUC_WOPCM_OFFSET,
-           GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
+           guc->wopcm.offset | HUC_LOADING_AGENT_GUC);
         /* WaEnableuKernelHeaderValidFix:skl */
       /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private 
 *dev_priv,
       uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
       uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);

  -    /* Header and uCode will be loaded to WOPCM */
+    /*
+     * Header and uCode will be loaded to WOPCM
+     * Only check the size against the overall available WOPCM here. Will
+     * continue to check the size during WOPCM partition calculation. +     */
      size = uc_fw->header_size + uc_fw->ucode_size;
-    if (size > intel_guc_wopcm_size(dev_priv)) {
+    if (size > WOPCM_DEFAULT_SIZE) {
          DRM_WARN("%s: Firmware is too large to fit in WOPCM\n", intel_uc_fw_type_repr(uc_fw->type));
          err = -E2BIG;

drivers/gpu/drm/i915/intel_uc_fw.c +1 -0
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
                  int (*xfer)(struct intel_uc_fw *uc_fw,
                      struct i915_vma *vma))
   {
+    struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
       struct i915_vma *vma;
       int err;
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
   @@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,

      }
        vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0, -                       PIN_OFFSET_BIAS | GUC_WOPCM_TOP); +                       PIN_OFFSET_BIAS | i915->guc.wopcm.top); if (IS_ERR(vma)) {
          err = PTR_ERR(vma);
          DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw
Quoted 28 lines · Yaodong Li
Quoted 27 lines · Sagar Arun Kamble
Quoted 24 lines · Michal Wajdeczko
Quoted 22 lines · Sagar Arun Kamble

Typo in the subject.
GLK showing failure to load GuC with this approach on CI.

Quoted 18 lines · Jackie Li

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is  set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
  - Removed intel_wopcm_init (Ville/Sagar/Joonas)
  - Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
  - Removed unnecessary function calls (Joonas)
  - Init GuC WOPCM partition as soon as firmware fetching is completed

<snip>

Quoted 47 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines

+    err = do_wopcm_partition(i915, offset + huc_size, reserved); +    if (err) {
+        if (!huc_size)
+            goto fail;

(quoted diff) +10 -0
+
+        /* Partition without loading HuC FW. */
+        err = do_wopcm_partition(i915, offset, reserved);
+        if (err)
+            goto fail;
+    }
+
+    /*
+     * Check hardware restriction on Gen9
+     * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM 

base due
+     * to hardware limitation on Gen9.
+     */
+    if (IS_GEN9(i915)) {
+        wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET; +        if (unlikely(wopcm_base > wp->size))
+            goto fail;

(quoted diff) +18 -0
+
+        delta = wp->size - wopcm_base;
+        if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+            goto fail;
+    }
+
+    if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+        guc_size = guc_fw->header_size + guc_fw->ucode_size;
+        /* Need 8K stack for GuC */
+        guc_size += GUC_WOPCM_STACK_RESERVED;
+    }
+
+    if (guc_size > wp->size)
+        goto fail;
+
+    DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n",
+        wp->offset >> 10, wp->size >> 10, wp->top >> 10);
+
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

+    return;

(quoted diff) +3 -0
+
+fail:
+    DRM_ERROR("WOPCM partitioning failed. Falling back to 

execlist mode\n");
+
+    intel_uc_fini_fw(i915);

This is correct but should be handled from intel_uc_init_fw with this function returning status.

Quoted 1 line

it's a good idea. I will do it.

Something like this will be good

drivers/gpu/drm/i915/intel_uc.c +0 -0
index 1e2a30a..04c45d0 100644
@@ -90,6 +90,15 @@ void intel_uc_init_fw(struct drm_i915_private *dev_priv)

 {
        intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw); intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw); +
+       ret = intel_uc_init_wopcm_partition(dev_priv); +       if (ret) {
+               intel_uc_fw_fini(&dev_priv->guc.fw); +               intel_uc_fw_fini(&dev_priv->huc.fw); +               i915_modparams.enable_guc_loading = 0; +               i915_modparams.enable_guc_submission = 0; +               i915_modparams.guc_log_level = -1; +       }
 }

Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines

+    /* GuC submission won't work without valid GuC WOPCM partition */
+    if (i915_modparams.enable_guc_submission)
+        i915_modparams.enable_guc_submission = 0;

(quoted diff) +3 -0
+
+    i915_modparams.enable_guc_loading = 0;
+}

This sanitization will be handled by intel_guc_fw_upload during intel_uc_init_hw so not needed.

It's too late to do it until intel_uc_init_hw.

Yes. Let us not do wopcm_init in uc_init_hw as wopcm_init is one time task. This modparam update is correct.

Quoted 7 lines

what I wanted to guarantee here was guc submission
would be disabled as long as the partitioning failed, so that we won't need to allocate the kernel context above guc wopcm top. we sure can ignore the partitioning failure can continue allocating the context above guc wopcm top, but the problem is we don't have a valid guc wopcm top value if the partitioning was failed. another benefit to disable the guc here is we won't even bother to call down into the logics in intel_uc_init_hw since we've already known for sure. I cannot enable guc submission on the partitioning failure.

Agree.

Quoted 55 lines
Quoted 55 lines
Quoted 10 lines
Quoted 7 lines
Quoted 6 lines

+
  void intel_uc_init_fw(struct drm_i915_private *dev_priv) {
      intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw); intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw); +    guc_init_wopcm_partition(dev_priv);

Create intel_uc_init_wopcm_partition(dev_priv) and call intel_guc_init_wopcm_partition(guc) from there.

hmm, I'm not sure what benefit you expect from this call chain ?

wanted to avoid firmware specific calls from here but I was wrong as we are not expecting this function to be called from outside of intel_uc. sorry.

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines

  }
    void intel_uc_fini_fw(struct drm_i915_private *dev_priv)

(quoted diff) +2 -2
@@ -174,9 +286,9 @@ int intel_uc_init_hw(struct drm_i915_private 
 *dev_priv)
       }
         /* init WOPCM */
-    I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
+    I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size);
       I915_WRITE(DMA_GUC_WOPCM_OFFSET,
-           GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
+           guc->wopcm.offset | HUC_LOADING_AGENT_GUC);
         /* WaEnableuKernelHeaderValidFix:skl */
       /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private 
 *dev_priv,
       uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
       uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);

  -    /* Header and uCode will be loaded to WOPCM */
+    /*
+     * Header and uCode will be loaded to WOPCM
+     * Only check the size against the overall available WOPCM here. Will
+     * continue to check the size during WOPCM partition calculation.
+     */
      size = uc_fw->header_size + uc_fw->ucode_size;
-    if (size > intel_guc_wopcm_size(dev_priv)) {
+    if (size > WOPCM_DEFAULT_SIZE) {
          DRM_WARN("%s: Firmware is too large to fit in WOPCM\n", intel_uc_fw_type_repr(uc_fw->type));
          err = -E2BIG;

drivers/gpu/drm/i915/intel_uc_fw.c +1 -0
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
                  int (*xfer)(struct intel_uc_fw *uc_fw,
                      struct i915_vma *vma))
   {
+    struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
       struct i915_vma *vma;
       int err;
   @@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

      }
        vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0, -                       PIN_OFFSET_BIAS | GUC_WOPCM_TOP); +                       PIN_OFFSET_BIAS | i915->guc.wopcm.top); if (IS_ERR(vma)) {
          err = PTR_ERR(vma);
          DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#10 lore raw
In reply to Michal Wajdeczko
Quoted 81 lines · Michal Wajdeczko
Quoted 79 lines · Sagar Arun Kamble

Typo in the subject.
GLK showing failure to load GuC with this approach on CI.

Quoted 59 lines · Jackie Li

Static WOPCM partitioning will lead to GuC loading failure if the GuC/HuC firmware size exceeded current static 512KB partition boundary.

This patch enables the dynamical calculation of the WOPCM aperture used by GuC/HuC firmware. GuC WOPCM offset is  set to
HuC size + reserved WOPCM size. GuC WOPCM size is set to total WOPCM size - GuC WOPCM offset - RC6CTX size. In this case, GuC WOPCM offset will be updated based on the size of HuC firmware while GuC WOPCM size will be set to use all the remaining WOPCM space.

v2:
  - Removed intel_wopcm_init (Ville/Sagar/Joonas)
  - Renamed and Moved the intel_wopcm_partition into intel_guc (Sagar)
  - Removed unnecessary function calls (Joonas)
  - Init GuC WOPCM partition as soon as firmware fetching is completed

Cc Michal Wajdeczko <[email protected]>
Cc Sagar Arun Kamble <[email protected]>
Cc Sujaritha Sundaresan <[email protected]>
Cc Daniele Ceraolo Spurio <[email protected]>
Cc John Spotswood <[email protected]>
Cc Oscar Mateo <[email protected]>

---
  drivers/gpu/drm/i915/i915_gem_context.c |   4 +- drivers/gpu/drm/i915/i915_guc_reg.h     |  18 +++--

  drivers/gpu/drm/i915/intel_guc.c        |  25 ++++---
  drivers/gpu/drm/i915/intel_guc.h        |  25 +++----
  drivers/gpu/drm/i915/intel_huc.c        |   2 +-
  drivers/gpu/drm/i915/intel_uc.c         | 116 
+++++++++++++++++++++++++++++++-
  drivers/gpu/drm/i915/intel_uc_fw.c      |  11 ++-
  7 files changed, 163 insertions(+), 38 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -0
index 2db0406..285c310 100644
@@ -312,12 +312,12 @@ __create_hw_context(struct drm_i915_private 
 *dev_priv,

      ctx->desc_template =
          default_desc_template(dev_priv, dev_priv->mm.aliasing_ppgtt);
  -    /* GuC requires the ring to be placed above GUC_WOPCM_TOP. If GuC is not +    /* GuC requires the ring to be placed above GuC WOPCM top. if
GuC is not
       * present or not in use we still need a small bias as ring wraparound
       * at offset 0 sometimes hangs. No idea why.
       */
      if (HAS_GUC(dev_priv) && i915_modparams.enable_guc_loading)
-        ctx->ggtt_offset_bias = GUC_WOPCM_TOP;
+        ctx->ggtt_offset_bias = dev_priv->guc.wopcm.top;
      else
          ctx->ggtt_offset_bias = I915_GTT_PAGE_SIZE;
  diff --git a/drivers/gpu/drm/i915/i915_guc_reg.h b/drivers/gpu/drm/i915/i915_guc_reg.h index bc1ae7d..567df12 100644

drivers/gpu/drm/i915/i915_guc_reg.h line 75

Quoted 10 lines
drivers/gpu/drm/i915/i915_guc_reg.h +2 -1
@@ -67,17 +67,27 @@
   #define DMA_GUC_WOPCM_OFFSET        _MMIO(0xc340)
   #define   HUC_LOADING_AGENT_VCR          (0<<1)
   #define   HUC_LOADING_AGENT_GUC          (1<<1)
-#define   GUC_WOPCM_OFFSET_VALUE      0x80000    /* 512KB */
   #define GUC_MAX_IDLE_COUNT        _MMIO(0xC3E4)
     #define HUC_STATUS2             _MMIO(0xD3B0)
   #define   HUC_FW_VERIFIED       (1<<7)
     /* Defines WOPCM space available to GuC firmware */
+/* Default WOPCM size 1MB */
+#define WOPCM_DEFAULT_SIZE        (0x1 << 20)

possible to get this size from register GEN6_STOLEN_RESERVED (ggtt->stolen_reserved_size)

drivers/gpu/drm/i915/i915_guc_reg.h line 81

Quoted 4 lines
drivers/gpu/drm/i915/i915_guc_reg.h +4 -0
+/* Reserved WOPCM size 16KB */
+#define WOPCM_RESERVED_SIZE        (0x4000)
+/* GUC WOPCM Offset need to be 16KB aligned */
+#define WOPCM_OFFSET_ALIGNMENT        (0x4000)

prefix this with GUC_ as it is specific to GuC in WOPCM

Quoted 11 lines
Quoted 7 lines

drivers/gpu/drm/i915/i915_guc_reg.h line 88

Quoted 7 lines
drivers/gpu/drm/i915/i915_guc_reg.h +7 -0
+/* 8KB stack reserved for GuC FW*/
+#define GUC_WOPCM_STACK_RESERVED    (0x2000)
+/* 24KB WOPCM reserved for RC6 CTX on BXT */
+#define BXT_WOPCM_RC6_RESERVED        (0x6000)
+
+#define GEN9_GUC_WOPCM_DELTA        4
+#define GEN9_GUC_WOPCM_OFFSET        (0x24000)

I'm not sure that definitions unrelated to register bits shall be defined here

I was trying to align with the current implementation. since we had
put definitions such as GUC_WOPCM _TOP, BXT_GUC_WOPCM_RC6_RESERVED here.
It's better to create a header file for wopcm related definitions if we want to keep it absolutely clean. I will think about it. Thanks for comments.

Quoted 72 lines
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/i915_guc_reg.h +1 -3
+
   #define GUC_WOPCM_SIZE            _MMIO(0xc050)
-/* GuC addresses below GUC_WOPCM_TOP don't map through the GTT */
-#define   GUC_WOPCM_TOP              (0x80 << 12)    /* 512KB */
-#define   BXT_GUC_WOPCM_RC6_RESERVED      (0x10 << 12)    /* 64KB  */
     /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
   #define GUC_GGTT_TOP            0xFEE00000
drivers/gpu/drm/i915/intel_guc.c +0 -1
index 9678630..0c6bd63 100644
@@ -337,7 +337,7 @@ int intel_guc_resume(struct drm_i915_private 
 *dev_priv)
    * This is a wrapper to create an object for use with the GuC. In order to
    * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
    * both some backing storage and a range inside the Global GTT. We must pin
- * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) 

because that
+ * it in the GGTT somewhere other than than [0, GuC WOPCM top) because that
   * range is reserved inside GuC.
   *
   * Return:    A i915_vma if successful, otherwise an ERR_PTR.

drivers/gpu/drm/i915/intel_guc.c +6 -1
@@ -358,7 +358,8 @@ struct i915_vma *intel_guc_allocate_vma(struct 
 intel_guc *guc, u32 size)
           goto err;
         ret = i915_vma_pin(vma, 0, PAGE_SIZE,
-               PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+               PIN_GLOBAL | PIN_OFFSET_BIAS |
+               dev_priv->guc.wopcm.top);
       if (ret) {
           vma = ERR_PTR(ret);
           goto err;
@@ -371,13 +372,19 @@ struct i915_vma *intel_guc_allocate_vma(struct 
 intel_guc *guc, u32 size)
       return vma;
   }
   -u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
+/*
+ * GuC does not allow any gfx GGTT address that falls into range
+ * [0, GuC WOPCM top), which is reserved for Boot ROM, SRAM and WOPCM.
+ * All gfx objects used by GuC is pinned with PIN_OFFSET_BIAS along 

with
+ * top of WOPCM.
+ */
+u32 guc_ggtt_offset(struct i915_vma *vma)
  {
-    u32 wopcm_size = GUC_WOPCM_TOP;
-
-    /* On BXT, the top of WOPCM is reserved for RC6 context */ -    if (IS_GEN9_LP(dev_priv))
-        wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
+    u32 guc_wopcm_top = vma->vm->i915->guc.wopcm.top; +    u32 offset = i915_ggtt_offset(vma);
  -    return wopcm_size;
+    GEM_BUG_ON(!guc_wopcm_top);
+    GEM_BUG_ON(offset < guc_wopcm_top);
+    GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
+    return offset;
  }

Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 41

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
index 607e025..77f619b 100644
@@ -39,6 +39,12 @@ struct guc_preempt_work {
       struct intel_engine_cs *engine;
   };
   +struct guc_wopcm_partition {

s/guc_wopcm_partition/intel_guc_wopcm ?

Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc.h +5 -0
+    u32 offset;
+    u32 size;
+    u32 top;
+};
+
Quoted 8 lines

drivers/gpu/drm/i915/intel_guc.h struct guc_preempt_work { · line 55

Quoted 8 lines
drivers/gpu/drm/i915/intel_guc.h +1 -0
   /*
    * Top level structure of GuC. It handles firmware loading and manages client
    * pool and doorbells. intel_guc owns a i915_guc_client to replace the legacy
@@ -46,6 +52,7 @@ struct guc_preempt_work {
    */
   struct intel_guc {
       struct intel_uc_fw fw;
+    struct guc_wopcm_partition wopcm;

hmm, or if we call it struct intel_wopcm then we could place it in drm_i915_private near guc/huc.

I had a struct called intel_wopcm originally which contains the overall wopcm info such as wopcm size, etc. but I think wopcm partition should be guc specific structure since we only need it when guc is active.

Quoted 79 lines
Quoted 64 lines
Quoted 30 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
       struct intel_guc_log log;
       struct intel_guc_ct ct;
   @@ -100,22 +107,6 @@ static inline void intel_guc_notify(struct intel_guc *guc)

      guc->notify(guc);
  }
  -/*
- * GuC does not allow any gfx GGTT address that falls into range [0, WOPCM_TOP),
- * which is reserved for Boot ROM, SRAM and WOPCM. Currently this top address is
- * 512K. In order to exclude 0-512K address space from GGTT, all gfx objects
- * used by GuC is pinned with PIN_OFFSET_BIAS along with size of WOPCM.
- */

drivers/gpu/drm/i915/intel_guc.h +0 -6
-static inline u32 guc_ggtt_offset(struct i915_vma *vma)
-{
-    u32 offset = i915_ggtt_offset(vma);
-
-    GEM_BUG_ON(offset < GUC_WOPCM_TOP);
-    GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, 

GUC_GGTT_TOP));

drivers/gpu/drm/i915/intel_guc.h +0 -4
-
-    return offset;
-}
-

  void intel_guc_init_early(struct intel_guc *guc); void intel_guc_init_send_regs(struct intel_guc *guc); void intel_guc_init_params(struct intel_guc *guc);

drivers/gpu/drm/i915/intel_guc.h int intel_guc_auth_huc(struct intel_guc *guc, · line 121

Quoted 6 lines
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -126,6 +117,6 @@ int intel_guc_auth_huc(struct intel_guc *guc, 
 u32 rsa_offset);
   int intel_guc_suspend(struct drm_i915_private *dev_priv);
   int intel_guc_resume(struct drm_i915_private *dev_priv);
   struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
-u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
+u32 guc_ggtt_offset(struct i915_vma *vma);

Why are we exporting this function. If we have to export then name should be intel_guc_ggtt_offset also pass intel_guc struct as param.
Any function we export for GuC should have name prefixed "intel_guc" and intel_guc struct as param. suspend/resume functions above are to be updated in upcoming series.

Quoted 18 lines
drivers/gpu/drm/i915/intel_guc.h +0 -0
     #endif
drivers/gpu/drm/i915/intel_huc.c +1 -1
index 98d1725..0baedc4 100644
@@ -202,7 +202,7 @@ void intel_huc_auth(struct intel_huc *huc)
           return;
         vma = i915_gem_object_ggtt_pin(huc->fw.obj, NULL, 0, 0,
-                PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
+                PIN_OFFSET_BIAS | guc->wopcm.top);
       if (IS_ERR(vma)) {
           DRM_ERROR("failed to pin huc fw object %d\n",
                   (int)PTR_ERR(vma));
drivers/gpu/drm/i915/intel_uc.c +0 -0
index aec2954..4f6fa67 100644

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct · line 89

Quoted 4 lines
drivers/gpu/drm/i915/intel_uc.c +0 -0
@@ -86,10 +86,122 @@ void intel_uc_init_early(struct 
 drm_i915_private *dev_priv)
       intel_guc_init_early(&dev_priv->guc);
   }
   +static inline u32 reserved_wopcm_size(struct drm_i915_private *i915)

Can we make this wopcm_top_reserved_size.
there is reserved at the beginning (WOPCM_RESERVED_SIZE). Can name it WOPCM_BEGIN_RESERVED_SIZE.

Quoted 14 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 99

Quoted 11 lines
drivers/gpu/drm/i915/intel_uc.c +10 -0
+{
+    /* On BXT, the top of WOPCM is reserved for RC6 context */
+    if (IS_GEN9_LP(i915))
+        return BXT_WOPCM_RC6_RESERVED;
+
+    return 0;
+}
+
+static int do_wopcm_partition(struct drm_i915_private *i915, u32 
 offset,
+                   u32 reserved_size)

This can be named guc_wopcm_partition_init as Chris suggested. and name caller as intel_guc_init_wopcm_partition.
These functions are GuC specific hence they should be defined in intel_guc.c.

Quoted 5 lines

Hmm, as during wopcm partition we need to know HuC fw size, I'm not 100% sure that these functions shall be placed in intel_guc.c ... unless we try to pass fw sizes as params, or

Other option would be to create intel_[guc|uc]_wopcm.c|h

Yes, that was reason I left them in intel_uc.c.

Quoted 52 lines
Quoted 41 lines
Quoted 41 lines
drivers/gpu/drm/i915/intel_uc.c +36 -0
+{
+    struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+    u32 aligned_offset = ALIGN(offset, WOPCM_OFFSET_ALIGN MENT);
+
+    if (offset >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    if (reserved_size >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    if ((aligned_offset + reserved_size) >= WOPCM_DEFAULT_SIZE)
+        return -E2BIG;
+
+    wp->offset = aligned_offset;
+    wp->top = WOPCM_DEFAULT_SIZE - wp->offset;
+    wp->size = wp->top - reserved_size;
+
+    return 0;
+}
+
+static void guc_init_wopcm_partition(struct drm_i915_private *i915)
+{
+    struct intel_uc_fw *guc_fw = &i915->guc.fw;
+    struct intel_uc_fw *huc_fw = &i915->huc.fw;
+    struct guc_wopcm_partition *wp = &i915->guc.wopcm;
+    size_t huc_size, guc_size;
+    u32 offset;
+    u32 reserved;
+    u32 wopcm_base;
+    u32 delta;
+    int err;
+
+    if (!i915_modparams.enable_guc_loading)
+        return;
+
+    /* No need to do partition if failed to fetch both GuC and HuC 

FW */
+    if (guc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS && +        huc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) +        goto fail;

Quoted 8 lines

drivers/gpu/drm/i915/intel_uc.c void intel_uc_init_early(struct drm_i915_private *dev_priv) · line 146

Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +8 -0
+
+    huc_size = 0;
+    guc_size = 0;
+    offset = WOPCM_RESERVED_SIZE;
+    reserved = reserved_wopcm_size(i915);
+
+    if (huc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS)
+        huc_size = huc_fw->header_size + huc_fw->ucode_size;

maybe to reduce code duplication you can create inline in intel_uc_fw.h

Quoted 7 lines

static inline u32 intel_uc_fw_get_size(struct intel_uc_fw *uc_fw) {
    if (uc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS) return 0;
    return uc_fw->header_size + uc_fw->ucode_size;
}

Will change it.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
drivers/gpu/drm/i915/intel_uc.c +15 -0
+
+    err = do_wopcm_partition(i915, offset + huc_size, reserved);
+    if (err) {
+        if (!huc_size)
+            goto fail;
+
+        /* Partition without loading HuC FW. */
+        err = do_wopcm_partition(i915, offset, reserved);
+        if (err)
+            goto fail;
+    }
+
+    /*
+     * Check hardware restriction on Gen9
+     * GuC WOPCM size is at least 4 bytes larger than GuC WOPCM 

base due
+     * to hardware limitation on Gen9.
+     */
+    if (IS_GEN9(i915)) {
+        wopcm_base = wp->offset + GEN9_GUC_WOPCM_OFFSET; +        if (unlikely(wopcm_base > wp->size))
+            goto fail;

drivers/gpu/drm/i915/intel_uc.c +15 -0
+
+        delta = wp->size - wopcm_base;
+        if (unlikely(delta < GEN9_GUC_WOPCM_DELTA))
+            goto fail;
+    }
+
+    if (guc_fw->fetch_status == INTEL_UC_FIRMWARE_SUCCESS) {
+        guc_size = guc_fw->header_size + guc_fw->ucode_size;
+        /* Need 8K stack for GuC */
+        guc_size += GUC_WOPCM_STACK_RESERVED;
+    }
+
+    if (guc_size > wp->size)
+        goto fail;
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+    DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n", +        wp->offset >> 10, wp->size >> 10, wp->top >> 10);

drivers/gpu/drm/i915/intel_uc.c +5 -0
+
+    return;
+
+fail:
+    DRM_ERROR("WOPCM partitioning failed. Falling back to execlist 

mode\n");

Do you have any suggestions about what should be printed here on the partitioning failure? should it be a error/warning/debug message?

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_uc.c +8 -0
+
+    intel_uc_fini_fw(i915);
+
+    /* GuC submission won't work without valid GuC WOPCM partition */
+    if (i915_modparams.enable_guc_submission)
+        i915_modparams.enable_guc_submission = 0;
+
+    i915_modparams.enable_guc_loading = 0;
Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/i915/intel_uc.c +2 -0
+}
+

  void intel_uc_init_fw(struct drm_i915_private *dev_priv) {
      intel_uc_fw_fetch(dev_priv, &dev_priv->huc.fw); intel_uc_fw_fetch(dev_priv, &dev_priv->guc.fw); +    guc_init_wopcm_partition(dev_priv);

Create intel_uc_init_wopcm_partition(dev_priv) and call intel_guc_init_wopcm_partition(guc) from there.

Quoted 2 lines

hmm, I'm not sure what benefit you expect from this call chain ?

probably, I should rename it back to intel_uc_init_wopcm_partition since it relies on both huc and guc fw size.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines

  }
    void intel_uc_fini_fw(struct drm_i915_private *dev_priv)

drivers/gpu/drm/i915/intel_uc.c +2 -2
@@ -174,9 +286,9 @@ int intel_uc_init_hw(struct drm_i915_private 
 *dev_priv)
       }
         /* init WOPCM */
-    I915_WRITE(GUC_WOPCM_SIZE, intel_guc_wopcm_size(dev_priv));
+    I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size);
       I915_WRITE(DMA_GUC_WOPCM_OFFSET,
-           GUC_WOPCM_OFFSET_VALUE | HUC_LOADING_AGENT_GUC);
+           guc->wopcm.offset | HUC_LOADING_AGENT_GUC);
         /* WaEnableuKernelHeaderValidFix:skl */
       /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
index 4bc82d3..34db2b1 100644
@@ -95,9 +95,13 @@ void intel_uc_fw_fetch(struct drm_i915_private 
 *dev_priv,
       uc_fw->ucode_offset = uc_fw->header_offset + uc_fw->header_size;
       uc_fw->ucode_size = (css->size_dw - css->header_size_dw) * sizeof(u32);

  -    /* Header and uCode will be loaded to WOPCM */
+    /*
+     * Header and uCode will be loaded to WOPCM
+     * Only check the size against the overall available WOPCM here. Will
+     * continue to check the size during WOPCM partition calculation. +     */
      size = uc_fw->header_size + uc_fw->ucode_size;
-    if (size > intel_guc_wopcm_size(dev_priv)) {
+    if (size > WOPCM_DEFAULT_SIZE) {
          DRM_WARN("%s: Firmware is too large to fit in WOPCM\n", intel_uc_fw_type_repr(uc_fw->type));
          err = -E2BIG;

drivers/gpu/drm/i915/intel_uc_fw.c +1 -0
@@ -207,6 +211,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
                  int (*xfer)(struct intel_uc_fw *uc_fw,
                      struct i915_vma *vma))
   {
+    struct drm_i915_private *i915 = to_i915(uc_fw->obj->base.dev);
       struct i915_vma *vma;
       int err;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_uc_fw.c +0 -0
   @@ -230,7 +235,7 @@ int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,

      }
        vma = i915_gem_object_ggtt_pin(uc_fw->obj, NULL, 0, 0, -                       PIN_OFFSET_BIAS | GUC_WOPCM_TOP); +                       PIN_OFFSET_BIAS | i915->guc.wopcm.top); if (IS_ERR(vma)) {
          err = PTR_ERR(vma);
          DRM_DEBUG_DRIVER("%s fw ggtt-pin err=%d\n",

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx