drm/i915/mtl: Add PTE encode functions
Subsystems (3)
cover drm/i915/mtl: Add PTE encode functions
From: Fei Yang <[email protected]>
Extract PTE patch from https://patchwork.freedesktop.org/series/116868/
to fix MTL boot issue caused by MOCS/PAT update.
Fei Yang (2):
drm/i915/mtl: Add PTE encode function drm/i915/mtl: workaround coherency issue for Media
drivers/gpu/drm/i915/display/intel_dpt.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 5 ++- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 45 +++++++++++++++++++---- drivers/gpu/drm/i915/gt/intel_ggtt.c | 36 ++++++++++++++++-- drivers/gpu/drm/i915/gt/intel_gtt.h | 13 ++++++- drivers/gpu/drm/i915/gt/uc/intel_gsc_fw.c | 13 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc.c | 7 ++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 +++ 8 files changed, 113 insertions(+), 14 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 drm/i915/mtl: Add PTE encode function
From: Fei Yang <[email protected]>
PTE encode functions are platform dependent. This patch implements PTE functions for MTL, and ensures the correct PTE encode function is used by calling pte_encode function pointer instead of the hardcoded gen8 version of PTE encode.
--- drivers/gpu/drm/i915/display/intel_dpt.c | 2 +- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 45 ++++++++++++++++++++---- drivers/gpu/drm/i915/gt/intel_ggtt.c | 36 +++++++++++++++++-- drivers/gpu/drm/i915/gt/intel_gtt.h | 13 +++++-- 4 files changed, 83 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/display/intel_dpt.c +1 -1
@@ -300,7 +300,7 @@ intel_dpt_create(struct intel_framebuffer *fb) vm->vma_ops.bind_vma = dpt_bind_vma; vm->vma_ops.unbind_vma = dpt_unbind_vma; - vm->pte_encode = gen8_ggtt_pte_encode; + vm->pte_encode = vm->gt->ggtt->vm.pte_encode; dpt->obj = dpt_obj; dpt->obj->is_dpt = true;
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +38 -7
87 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_ggtt.c +33 -3
@@ -220,6 +220,33 @@ static void guc_ggtt_invalidate(struct i915_ggtt *ggtt) } } +static u64 mtl_ggtt_pte_encode (dma_addr_t addr, +enum i915_cache_level level, +u32 flags) +{ +gen8_pte_t pte = addr |GEN8_PAGE_PRESENT ; + +WARN_ON_ONCE (addr & ~GEN12_GGTT_PTE_ADDR_MASK ); + +if (flags &PTE_LM ) + pte |=GEN12_GGTT_PTE_LM ; + +switch (level) { +case I915_CACHE_NONE : + pte |=MTL_GGTT_PTE_PAT1 ; +break ; +case I915_CACHE_LLC : +case I915_CACHE_L3_LLC : + pte |=MTL_GGTT_PTE_PAT0 |MTL_GGTT_PTE_PAT1 ; +break ; +case I915_CACHE_WT : + pte |=MTL_GGTT_PTE_PAT0 ; +break ; + } + +return pte; +} +u64 gen8_ggtt_pte_encode (dma_addr_t addr,enum i915_cache_level level,u32 flags)
@@ -247,7 +274,7 @@ static void gen8_ggtt_insert_page(struct i915_address_space *vm,gen8_pte_t __iomem *pte = (gen8_pte_t __iomem *)ggtt->gsm + offset /I915_GTT_PAGE_SIZE ; -gen8_set_pte (pte,gen8_ggtt_pte_encode (addr, level, flags)); +gen8_set_pte (pte, ggtt->vm.pte_encode (addr, level, flags)); ggtt->invalidate (ggtt); }
@@ -257,8 +284,8 @@ static void gen8_ggtt_insert_entries(struct i915_address_space *vm, enum i915_cache_level level, u32 flags) { -const gen8_pte_t pte_encode =gen8_ggtt_pte_encode (0 , level, flags);struct i915_ggtt *ggtt =i915_vm_to_ggtt (vm); +const gen8_pte_t pte_encode = ggtt->vm.pte_encode (0 , level, flags);gen8_pte_t __iomem *gte;gen8_pte_t __iomem *end;struct sgt_iter iter;
@@ -981,7 +1008,10 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt) ggtt->vm.vma_ops.bind_vma = intel_ggtt_bind_vma; ggtt->vm.vma_ops.unbind_vma = intel_ggtt_unbind_vma; - ggtt->vm.pte_encode = gen8_ggtt_pte_encode; +if (GRAPHICS_VER_FULL (i915) >=IP_VER (12 ,70 )) + ggtt->vm.pte_encode = mtl_ggtt_pte_encode; +else + ggtt->vm.pte_encode = gen8_ggtt_pte_encode;return ggtt_probe_common (ggtt, size); }
drivers/gpu/drm/i915/gt/intel_gtt.h +11 -2
@@ -88,9 +88,18 @@ typedef u64 gen8_pte_t;#define BYT_PTE_SNOOPED_BY_CPU_CACHES REG_BIT(2)#define BYT_PTE_WRITEABLE REG_BIT(1) +#define MTL_PPGTT_PTE_PAT3 BIT_ULL(62)#define GEN12_PPGTT_PTE_LM BIT_ULL(11) - -#define GEN12_GGTT_PTE_LM BIT_ULL(1) +#define GEN12_PPGTT_PTE_PAT2 BIT_ULL(7) +#define GEN12_PPGTT_PTE_NC BIT_ULL(5) +#define GEN12_PPGTT_PTE_PAT1 BIT_ULL(4) +#define GEN12_PPGTT_PTE_PAT0 BIT_ULL(3) + +#define GEN12_GGTT_PTE_LM BIT_ULL(1) +#define MTL_GGTT_PTE_PAT0 BIT_ULL(52) +#define MTL_GGTT_PTE_PAT1 BIT_ULL(53) +#define GEN12_GGTT_PTE_ADDR_MASK GENMASK_ULL(45, 12) +#define MTL_GGTT_PTE_PAT_MASK GENMASK_ULL(53, 52)#define GEN12_PDE_64K BIT(6)#define GEN12_PTE_PS64 BIT(8)
Signature · 1 line
2.25.1
PATCH 2/2 drm/i915/mtl: workaround coherency issue for Media
In reply to [email protected]From: Fei Yang <[email protected]>
This patch implements Wa_22016122933.
In MTL, memory writes initiated by the Media tile update the whole cache line, even for partial writes. This creates a coherency problem for cacheable memory if both CPU and GPU are writing data to different locations within a single cache line.
This patch circumvents the issue by making CPU/GPU shared memory uncacheable (WC on CPU side, and PAT index 2 for GPU). Additionally, it ensures that CPU writes are visible to the GPU with an intel_guc_write_barrier().
While fixing the CTB issue, we noticed some random GSC firmware loading failure because the share buffers are cacheable (WB) on CPU side but uncached on GPU side. To fix these issues we need to map such shared buffers as WC on CPU side. Since such allocations are not all done through GuC allocator, to avoid too many code changes, the i915_coherent_map_type() is now hard coded to return WC for MTL.
v2: Simplify the commit message(Matt).
BSpec: 45101
--- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 5 ++++- drivers/gpu/drm/i915/gt/uc/intel_gsc_fw.c | 13 +++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc.c | 7 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_pages.c +4 -1
@@ -469,7 +469,10 @@ enum i915_map_type i915_coherent_map_type(struct drm_i915_private *i915, struct drm_i915_gem_object *obj, bool always_coherent) { - if (i915_gem_object_is_lmem(obj)) +/* +* Wa_22016122933: always return I915_MAP_WC for MTL +*/ +if (i915_gem_object_is_lmem (obj) ||IS_METEORLAKE (i915))return I915_MAP_WC ;if (HAS_LLC (i915) || always_coherent)return I915_MAP_WB ;
drivers/gpu/drm/i915/gt/uc/intel_gsc_fw.c +13 -0
@@ -110,6 +110,13 @@ static int gsc_fw_load_prepare(struct intel_gsc_uc *gsc)if (obj->base.size < gsc->fw.size)return -ENOSPC ; +/* +* Wa_22016122933: For MTL the shared memory needs to be mapped +* as WC on CPU side and UC (PAT index 2) on GPU side +*/ +if (IS_METEORLAKE (i915)) +i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE ); + dst =i915_gem_object_pin_map_unlocked (obj,i915_coherent_map_type (i915, obj, true));if (IS_ERR (dst))
@@ -125,6 +132,12 @@ static int gsc_fw_load_prepare(struct intel_gsc_uc *gsc)memset (dst,0 , obj->base.size);memcpy (dst, src, gsc->fw.size); +/* +* Wa_22016122933: Making sure the data in dst is +* visible to GSC right away +*/ +intel_guc_write_barrier (>->uc.guc); +i915_gem_object_unpin_map (gsc->fw.obj);i915_gem_object_unpin_map (obj);
drivers/gpu/drm/i915/gt/uc/intel_guc.c +7 -0
@@ -744,6 +744,13 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)if (IS_ERR (obj))return ERR_CAST (obj); +/* +* Wa_22016122933: For MTL the shared memory needs to be mapped +* as WC on CPU side and UC (PAT index 2) on GPU side +*/ +if (IS_METEORLAKE (gt->i915)) +i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE ); + vma =i915_vma_instance (obj, >->ggtt->vm,NULL );if (IS_ERR (vma)) goto err;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6 -0
@@ -902,6 +902,12 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* now update descriptor */ WRITE_ONCE (desc->head, head); +/* +* Wa_22016122933: Making sure the head update is +* visible to GuC right away +*/ +intel_guc_write_barrier (ct_to_guc (ct)); +return available - len; corrupted:
Signature · 1 line
2.25.1