GuC WOPCM registers are write-once registers. Current driver code accesses these registers without checking the accessibility to these registers, this will lead unpredictable driver behaviors if these registers were touch by other components (such as faulty BIOS code). This patch moves the GuC WOPCM register updating operations into intel_guc_wopcm.c and adds checks before and after the write to GuC WOPCM registers to make sure the driver is in a known state before and after writing to these write-once registers. Cc: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx> Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx> Signed-off-by: Jackie Li <yaodong.li@xxxxxxxxx> --- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_reg.h | 1 + drivers/gpu/drm/i915/intel_guc_wopcm.c | 66 ++++++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/intel_guc_wopcm.h | 14 +++++++- drivers/gpu/drm/i915/intel_uc.c | 5 +-- 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h index ea35911..7ed0c17 100644 --- a/drivers/gpu/drm/i915/intel_guc.h +++ b/drivers/gpu/drm/i915/intel_guc.h @@ -118,7 +118,7 @@ static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc, { u32 offset = i915_ggtt_offset(vma); - GEM_BUG_ON(!guc->wopcm.valid); + GEM_BUG_ON(!(guc->wopcm.flags & INTEL_GUC_WOPCM_VALID)); GEM_BUG_ON(offset < guc->wopcm.top); GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP)); diff --git a/drivers/gpu/drm/i915/intel_guc_reg.h b/drivers/gpu/drm/i915/intel_guc_reg.h index 1f52fb8..4d52c6d 100644 --- a/drivers/gpu/drm/i915/intel_guc_reg.h +++ b/drivers/gpu/drm/i915/intel_guc_reg.h @@ -75,6 +75,7 @@ /* Defines WOPCM space available to GuC firmware */ #define GUC_WOPCM_SIZE _MMIO(0xc050) +#define GUC_WOPCM_REG_LOCKED (1<<0) /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */ #define GUC_GGTT_TOP 0xFEE00000 diff --git a/drivers/gpu/drm/i915/intel_guc_wopcm.c b/drivers/gpu/drm/i915/intel_guc_wopcm.c index 2523fef..59d5c35 100644 --- a/drivers/gpu/drm/i915/intel_guc_wopcm.c +++ b/drivers/gpu/drm/i915/intel_guc_wopcm.c @@ -89,6 +89,37 @@ static inline int guc_wopcm_size_check(struct intel_guc *guc) return 0; } +static inline bool __reg_locked(struct drm_i915_private *dev_priv, + i915_reg_t reg) +{ + return !!(I915_READ(reg) & GUC_WOPCM_REG_LOCKED); +} + +static inline bool guc_wopcm_locked(struct intel_guc *guc) +{ + struct drm_i915_private *i915 = guc_to_i915(guc); + bool size_reg_locked = __reg_locked(i915, GUC_WOPCM_SIZE); + bool offset_reg_locked = __reg_locked(i915, DMA_GUC_WOPCM_OFFSET); + + return size_reg_locked && offset_reg_locked; +} + +static inline void guc_wopcm_hw_update(struct intel_guc *guc) +{ + struct drm_i915_private *dev_priv = guc_to_i915(guc); + + /* GuC WOPCM registers should be unlocked at this point. */ + GEM_BUG_ON(__reg_locked(dev_priv, GUC_WOPCM_SIZE)); + GEM_BUG_ON(__reg_locked(dev_priv, DMA_GUC_WOPCM_OFFSET)); + + I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size); + I915_WRITE(DMA_GUC_WOPCM_OFFSET, + guc->wopcm.offset | HUC_LOADING_AGENT_GUC); + + GEM_BUG_ON(!__reg_locked(dev_priv, GUC_WOPCM_SIZE)); + GEM_BUG_ON(!__reg_locked(dev_priv, DMA_GUC_WOPCM_OFFSET)); +} + /* * intel_guc_wopcm_init() - Initialize the GuC WOPCM partition. * @guc: intel guc. @@ -107,8 +138,7 @@ int intel_guc_wopcm_init(struct intel_guc *guc, u32 guc_fw_size, u32 offset, size, top; int err; - if (guc->wopcm.valid) - return 0; + GEM_BUG_ON(guc->wopcm.flags & INTEL_GUC_WOPCM_VALID); if (!guc_fw_size) return -EINVAL; @@ -144,10 +174,40 @@ int intel_guc_wopcm_init(struct intel_guc *guc, u32 guc_fw_size, if (err) return err; - guc->wopcm.valid = true; + guc->wopcm.flags |= INTEL_GUC_WOPCM_VALID; DRM_DEBUG_DRIVER("GuC WOPCM offset %dKB, size %dKB, top %dKB\n", offset >> 10, size >> 10, top >> 10); return 0; } + +/* + * intel_guc_wopcm_init_hw() - Setup GuC WOPCM registers. + * @guc: intel guc. + * + * Setup the GuC WOPCM size and offset registers with the stored values. It will + * also check the registers locking status to determine whether these registers + * are unlocked and can be updated. + */ +void intel_guc_wopcm_init_hw(struct intel_guc *guc) +{ + u32 locked = guc_wopcm_locked(guc); + + GEM_BUG_ON(!(guc->wopcm.flags & INTEL_GUC_WOPCM_VALID)); + + /* + * Bug if driver hasn't updated the HW Registers and GuC WOPCM has been + * locked. Return directly if WOPCM was locked and we have updated + * the registers. + */ + if (locked) { + GEM_BUG_ON(!(guc->wopcm.flags & INTEL_GUC_WOPCM_HW_UPDATED)); + return; + } + + /* Always update registers when GuC WOPCM is not locked. */ + guc_wopcm_hw_update(guc); + + guc->wopcm.flags |= INTEL_GUC_WOPCM_HW_UPDATED; +} diff --git a/drivers/gpu/drm/i915/intel_guc_wopcm.h b/drivers/gpu/drm/i915/intel_guc_wopcm.h index 0ce31ee..dd62b6b 100644 --- a/drivers/gpu/drm/i915/intel_guc_wopcm.h +++ b/drivers/gpu/drm/i915/intel_guc_wopcm.h @@ -46,11 +46,22 @@ struct intel_guc; #define GEN9_GUC_WOPCM_OFFSET (0x24000) #define GEN10_GUC_WOPCM_OFFSET (0x4000) +/* GuC WOPCM flags*/ +#define INTEL_GUC_WOPCM_VALID BIT(0) +#define INTEL_GUC_WOPCM_HW_UPDATED BIT(1) + +/* + * intel_guc_wopcm - GuC WOPCM related settings. + * @offset: GuC WOPCM offset. + * @size: size of GuC WOPCM for GuC firmware. + * @top: start of Non GuC WOPCM memory. + * @flags: bitmap of INTEL_GUC_WOPCM_<foo>. + */ struct intel_guc_wopcm { u32 offset; u32 size; u32 top; - bool valid; + u32 flags; }; /* @@ -68,5 +79,6 @@ static inline void intel_guc_wopcm_init_early(struct intel_guc_wopcm *wopcm) } int intel_guc_wopcm_init(struct intel_guc *guc, u32 guc_size, u32 huc_size); +void intel_guc_wopcm_init_hw(struct intel_guc *guc); #endif diff --git a/drivers/gpu/drm/i915/intel_uc.c b/drivers/gpu/drm/i915/intel_uc.c index 70ed297..346ba03 100644 --- a/drivers/gpu/drm/i915/intel_uc.c +++ b/drivers/gpu/drm/i915/intel_uc.c @@ -280,10 +280,7 @@ int intel_uc_init_hw(struct drm_i915_private *dev_priv) guc_disable_communication(guc); gen9_reset_guc_interrupts(dev_priv); - /* init WOPCM */ - I915_WRITE(GUC_WOPCM_SIZE, guc->wopcm.size); - I915_WRITE(DMA_GUC_WOPCM_OFFSET, - guc->wopcm.offset | HUC_LOADING_AGENT_GUC); + intel_guc_wopcm_init_hw(guc); /* WaEnableuKernelHeaderValidFix:skl */ /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */ -- 2.7.4 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx