drm/i915: Refactor PAT/cache handling
Subsystems (2)
RFC 1/1 drm/i915: Refactor PAT/cache handling
From: Tvrtko Ursulin <[email protected]>
Informal commit message for now.
I got a bit impatient and curious to see if the idea we discussed would work so sketched something out. I think it is what I was describing back then..
So high level idea is to teach the driver what caching modes are hidden behind PAT indices. Given you already had that in static tables, if we just turn the tables a bit around and add a driver abstraction of caching modes this is what happens:
* We can lose the ugly runtime i915_gem_get_pat_index.
* We can have a smarter i915_gem_object_has_cache_level, which now can use the above mentioned table to understand the caching modes and so does not have to pessimistically return true for _any_ input when user has set the PAT index. This may improve things even for MTL.
* We can simplify the debugfs printout to be platform agnostic.
* We are perhaps opening the door to un-regress the dodgy addition made to i915_gem_object_can_bypass_llc? See QQQ/FIXME in the patch.
I hope I did not forget anything, but anyway, please have a read and see what you think. I think it has potential.
Proper commit message can come later.
--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gem/i915_gem_domain.c | 34 ++--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 13 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 10 +- drivers/gpu/drm/i915/gem/i915_gem_object.c | 78 ++++------- drivers/gpu/drm/i915/gem/i915_gem_object.h | 18 ++- .../gpu/drm/i915/gem/i915_gem_object_types.h | 99 +------------- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 7 +- drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 26 ++-- .../gpu/drm/i915/gem/selftests/huge_pages.c | 2 +- drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 4 +- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 13 +- drivers/gpu/drm/i915/gt/intel_ggtt.c | 9 +- drivers/gpu/drm/i915/gt/intel_migrate.c | 11 +- drivers/gpu/drm/i915/gt/selftest_migrate.c | 9 +- drivers/gpu/drm/i915/gt/selftest_reset.c | 14 +- drivers/gpu/drm/i915/gt/selftest_timeline.c | 5 +- drivers/gpu/drm/i915/gt/selftest_tlb.c | 5 +- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 8 +- drivers/gpu/drm/i915/i915_cache.c | 59 ++++++++ drivers/gpu/drm/i915/i915_cache.h | 129 ++++++++++++++++++ drivers/gpu/drm/i915/i915_debugfs.c | 83 ++++++----- drivers/gpu/drm/i915/i915_driver.c | 3 + drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/i915_gem.c | 21 +-- drivers/gpu/drm/i915/i915_gpu_error.c | 7 +- drivers/gpu/drm/i915/i915_pci.c | 83 +++++------ drivers/gpu/drm/i915/intel_device_info.h | 6 +- drivers/gpu/drm/i915/selftests/i915_gem.c | 5 +- .../gpu/drm/i915/selftests/i915_gem_evict.c | 4 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 13 +- .../drm/i915/selftests/intel_memory_region.c | 4 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 10 +- 33 files changed, 415 insertions(+), 381 deletions(-) create mode 100644 drivers/gpu/drm/i915/i915_cache.c create mode 100644 drivers/gpu/drm/i915/i915_cache.h
drivers/gpu/drm/i915/Makefile +1 -0
@@ -30,6 +30,7 @@ subdir-ccflags-y += -I$(srctree)/$(src) # core driver code i915-y += i915_driver.o \ i915_drm_client.o \ + i915_cache.o \ i915_config.o \ i915_getparam.o \ i915_ioctl.o \
drivers/gpu/drm/i915/gem/i915_gem_domain.c +15 -19
@@ -8,6 +8,7 @@#include "display/intel_frontbuffer.h" #include "gt/intel_gt.h" +#include "i915_cache.h" #include "i915_drv.h" #include "i915_gem_clflush.h" #include "i915_gem_domain.h"
@@ -27,15 +28,8 @@ static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)if (IS_DGFX (i915))return false; -/* -* For objects created by userspace through GEM_CREATE with pat_index -* set by set_pat extension, i915_gem_object_has_cache_level() will -* always return true, because the coherency of such object is managed -* by userspace. Othereise the call here would fall back to checking -* whether the object is un-cached or write-through. -*/ -return !(i915_gem_object_has_cache_level (obj,I915_CACHE_NONE ) || -i915_gem_object_has_cache_level (obj,I915_CACHE_WT )); +return i915_gem_object_has_cache_mode (obj,I915_CACHE_MODE_UC ) !=1 && +i915_gem_object_has_cache_mode (obj,I915_CACHE_MODE_WT ) !=1 ; }bool i915_gem_cpu_write_needs_clflush (struct drm_i915_gem_object *obj)
@@ -272,15 +266,18 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)int i915_gem_object_set_cache_level (struct drm_i915_gem_object *obj,enum i915_cache_level cache_level) { +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +i915_cache_t mode;int ret; -/* -* For objects created by userspace through GEM_CREATE with pat_index -* set by set_pat extension, simply return 0 here without touching -* the cache setting, because such objects should have an immutable -* cache setting by desgin and always managed by userspace. -*/ -if (i915_gem_object_has_cache_level (obj, cache_level)) +if (obj->pat_set_by_user) +return -EINVAL ; + + ret =i915_cache_level_to_pat_and_mode (i915, cache_level, &mode); +if (ret <0 ) +return -EINVAL ; + +if (mode == obj->cache_mode)return 0 ; ret = i915_gem_object_wait(obj,
@@ -326,10 +323,9 @@ int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, goto out; } -if (i915_gem_object_has_cache_level (obj,I915_CACHE_LLC ) || -i915_gem_object_has_cache_level (obj,I915_CACHE_L3_LLC )) +if (i915_gem_object_has_cache_mode (obj,I915_CACHE_MODE_WB )) args->caching =I915_CACHING_CACHED ; -else if (i915_gem_object_has_cache_level (obj,I915_CACHE_WT )) +else if (i915_gem_object_has_cache_mode (obj,I915_CACHE_MODE_WT )) args->caching =I915_CACHING_DISPLAY ;else args->caching =I915_CACHING_NONE ;
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -11
@@ -640,15 +640,9 @@ static inline int use_cpu_reloc(const struct reloc_cache *cache,if (DBG_FORCE_RELOC ==FORCE_GTT_RELOC )return false; -/* -* For objects created by userspace through GEM_CREATE with pat_index -* set by set_pat extension, i915_gem_object_has_cache_level() always -* return true, otherwise the call would fall back to checking whether -* the object is un-cached. -*/ return (cache->has_llc || obj->cache_dirty || - !i915_gem_object_has_cache_level (obj,I915_CACHE_NONE )); +i915_gem_object_has_cache_mode (obj,I915_CACHE_MODE_UC ) !=1 ); } static int eb_reserve_vma(struct i915_execbuffer *eb,
@@ -1329,10 +1323,7 @@ static void *reloc_iomap(struct i915_vma *batch,if (drm_mm_node_allocated (&cache->node)) { ggtt->vm.insert_page (&ggtt->vm,i915_gem_object_get_dma_address (obj, page), - offset, -i915_gem_get_pat_index (ggtt->vm.i915, -I915_CACHE_NONE ), -0 ); + offset, eb->i915->pat_uc,0 ); }else { offset += page <<PAGE_SHIFT ; }
drivers/gpu/drm/i915/gem/i915_gem_mman.c +4 -6
@@ -386,13 +386,11 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)/* * For objects created by userspace through GEM_CREATE with pat_index * set by set_pat extension, coherency is managed by userspace, make -* sure we don't fail handling the vm fault by calling -* i915_gem_object_has_cache_level() which always return true for such -* objects. Otherwise this helper function would fall back to checking -* whether the object is un-cached. +* sure we don't fail handling the vm fault by making sure that we +* know the object is uncached or that we have LLC. */ -if (!(i915_gem_object_has_cache_level (obj,I915_CACHE_NONE ) || -HAS_LLC (i915))) { +if (i915_gem_object_has_cache_mode (obj,I915_CACHE_MODE_UC ) !=1 && + !HAS_LLC (i915)) { ret = -EFAULT ; goto err_unpin; }
drivers/gpu/drm/i915/gem/i915_gem_object.c +28 -50
111 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_object.h +14 -4
@@ -13,6 +13,7 @@#include "display/intel_frontbuffer.h" #include "intel_memory_region.h" +#include "i915_cache.h" #include "i915_gem_object_types.h" #include "i915_gem_gtt.h" #include "i915_gem_ww.h"
@@ -32,10 +33,18 @@ static inline bool i915_gem_object_size_2big(u64 size)return false; } -unsigned int i915_gem_get_pat_index (struct drm_i915_private *i915, -enum i915_cache_level level); -bool i915_gem_object_has_cache_level (const struct drm_i915_gem_object *obj, -enum i915_cache_level lvl); +static inline int +i915_gem_object_has_cache_mode (const struct drm_i915_gem_object *obj, +unsigned int mode) +{ +if (I915_CACHE_MODE (obj->cache_mode) == mode) +return 1 ; +else if (obj->pat_set_by_user) +return -1 ;/* Unknown, callers should assume no. */ +else +return 0 ; +} +void i915_gem_init__objects (struct drm_i915_private *i915);void i915_objects_module_exit (void );
@@ -764,6 +773,7 @@ int i915_gem_object_wait_moving_fence(struct drm_i915_gem_object *obj, bool intr);bool i915_gem_object_has_unknown_state (struct drm_i915_gem_object *obj); +void __i915_gem_object_update_coherency (struct drm_i915_gem_object *obj);void i915_gem_object_set_cache_coherency (struct drm_i915_gem_object *obj,unsigned int cache_level); void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj,
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6 -93
129 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +2 -5
@@ -563,11 +563,8 @@ static void dbg_poison(struct i915_ggtt *ggtt,while (size) {void __iomem *s; - ggtt->vm.insert_page (&ggtt->vm, addr, - ggtt->error_capture.start, -i915_gem_get_pat_index (ggtt->vm.i915, -I915_CACHE_NONE ), -0 ); + ggtt->vm.insert_page (&ggtt->vm, addr, ggtt->error_capture.start, + ggtt->vm.i915->pat_uc,0 );mb (); s = io_mapping_map_wc(&ggtt->iomap,
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +17 -9
@@ -58,6 +58,16 @@ i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res,I915_CACHE_NONE ; } +static unsigned int +i915_ttm_cache_pat (struct drm_i915_private *i915,struct ttm_resource *res, +struct ttm_tt *ttm) +{ +return ((HAS_LLC (i915) ||HAS_SNOOP (i915)) && + !i915_ttm_gtt_binds_lmem (res) && + ttm->caching == ttm_cached) ? i915->pat_wb : + i915->pat_uc; +} +static struct intel_memory_region *i915_ttm_region (struct ttm_device *bdev,int ttm_mem_type) {
@@ -196,7 +206,7 @@ static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo,struct drm_i915_gem_object *obj =i915_ttm_to_gem (bo);struct i915_request *rq;struct ttm_tt *src_ttm = bo->ttm; -enum i915_cache_level src_level, dst_level; +unsigned int src_pat, dst_pat;int ret;if (!to_gt (i915)->migrate.context ||intel_gt_is_wedged (to_gt (i915)))
@@ -206,16 +216,15 @@ static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo,if (I915_SELFTEST_ONLY (fail_gpu_migration)) clear = true; - dst_level =i915_ttm_cache_level (i915, dst_mem, dst_ttm); + dst_pat =i915_ttm_cache_pat (i915, dst_mem, dst_ttm);if (clear) {if (bo->type == ttm_bo_type_kernel && !I915_SELFTEST_ONLY (fail_gpu_migration))return ERR_PTR (-EINVAL );intel_engine_pm_get (to_gt (i915)->migrate.context->engine); - ret =intel_context_migrate_clear (to_gt (i915)->migrate.context, deps, - dst_st->sgl, -i915_gem_get_pat_index (i915, dst_level), + ret =intel_context_migrate_clear (to_gt (i915)->migrate.context, + deps, dst_st->sgl, dst_pat,i915_ttm_gtt_binds_lmem (dst_mem),0 , &rq); }else {
@@ -225,14 +234,13 @@ static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo,if (IS_ERR (src_rsgt))return ERR_CAST (src_rsgt); - src_level =i915_ttm_cache_level (i915, bo->resource, src_ttm); + src_pat =i915_ttm_cache_pat (i915, bo->resource, src_ttm);intel_engine_pm_get (to_gt (i915)->migrate.context->engine); ret =intel_context_migrate_copy (to_gt (i915)->migrate.context, deps, src_rsgt->table.sgl, -i915_gem_get_pat_index (i915, src_level), + src_pat,i915_ttm_gtt_binds_lmem (bo->resource), - dst_st->sgl, -i915_gem_get_pat_index (i915, dst_level), + dst_st->sgl, dst_pat,i915_ttm_gtt_binds_lmem (dst_mem), &rq);
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +1 -1
@@ -354,7 +354,7 @@ fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single) obj->write_domain =I915_GEM_DOMAIN_CPU ; obj->read_domains =I915_GEM_DOMAIN_CPU ; - obj->pat_index =i915_gem_get_pat_index (i915,I915_CACHE_NONE ); +i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE );return obj; }
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +1 -3
@@ -226,9 +226,7 @@ static int gen6_ppgtt_init_scratch(struct gen6_ppgtt *ppgtt)return ret; vm->scratch[0 ]->encode = - vm->pte_encode (px_dma (vm->scratch[0 ]), -i915_gem_get_pat_index (vm->i915, -I915_CACHE_NONE ), + vm->pte_encode (px_dma (vm->scratch[0 ]), vm->i915->pat_uc,PTE_READ_ONLY ); vm->scratch[1 ] = vm->alloc_pt_dma (vm,I915_GTT_PAGE_SIZE_4K );
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +3 -10
@@ -40,16 +40,11 @@ static u64 gen8_pte_encode(dma_addr_t addr,if (flags &PTE_LM ) pte |=GEN12_PPGTT_PTE_LM ; -/* -* For pre-gen12 platforms pat_index is the same as enum -* i915_cache_level, so the switch-case here is still valid. -* See translation table defined by LEGACY_CACHELEVEL. -*/ switch (pat_index) { -case I915_CACHE_NONE : +case 0 : pte |=PPAT_UNCACHED ;break ; -case I915_CACHE_WT : +case 3 : pte |=PPAT_DISPLAY_ELLC ;break ;default :
@@ -853,9 +848,7 @@ static int gen8_init_scratch(struct i915_address_space *vm) pte_flags |=PTE_LM ; vm->scratch[0 ]->encode = - vm->pte_encode (px_dma (vm->scratch[0 ]), -i915_gem_get_pat_index (vm->i915, -I915_CACHE_NONE ), + vm->pte_encode (px_dma (vm->scratch[0 ]), vm->i915->pat_uc, pte_flags);for (i =1 ; i <= vm->top; i++) {
drivers/gpu/drm/i915/gt/intel_ggtt.c +2 -7
@@ -921,9 +921,7 @@ static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size) pte_flags |=PTE_LM ; ggtt->vm.scratch[0 ]->encode = - ggtt->vm.pte_encode (px_dma (ggtt->vm.scratch[0 ]), -i915_gem_get_pat_index (i915, -I915_CACHE_NONE ), + ggtt->vm.pte_encode (px_dma (ggtt->vm.scratch[0 ]), i915->pat_uc, pte_flags);return 0 ;
@@ -1297,10 +1295,7 @@ bool i915_ggtt_resume_vm(struct i915_address_space *vm)* ptes to be repopulated. */ vma->resource->bound_flags =0 ; - vma->ops->bind_vma (vm,NULL , vma->resource, - obj ? obj->pat_index : -i915_gem_get_pat_index (vm->i915, -I915_CACHE_NONE ), + vma->ops->bind_vma (vm,NULL , vma->resource, obj->cache_mode, was_bound);if (obj) {/* only used during resume => exclusive access */
drivers/gpu/drm/i915/gt/intel_migrate.c +3 -8
@@ -45,9 +45,7 @@ static void xehpsdv_toggle_pdes(struct i915_address_space *vm,* Insert a dummy PTE into every PT that will map to LMEM to ensure * we have a correctly setup PDE structure for later use. */ - vm->insert_page (vm,0 , d->offset, -i915_gem_get_pat_index (vm->i915,I915_CACHE_NONE ), -PTE_LM ); + vm->insert_page (vm,0 , d->offset, vm->i915->pat_uc,PTE_LM );GEM_BUG_ON (!pt->is_compact); d->offset +=SZ_2M ; }
@@ -65,9 +63,7 @@ static void xehpsdv_insert_pte(struct i915_address_space *vm,* alignment is 64K underneath for the pt, and we are careful * not to access the space in the void. */ - vm->insert_page (vm,px_dma (pt), d->offset, -i915_gem_get_pat_index (vm->i915,I915_CACHE_NONE ), -PTE_LM ); + vm->insert_page (vm,px_dma (pt), d->offset, vm->i915->pat_uc,PTE_LM ); d->offset +=SZ_64K ; }
@@ -77,8 +73,7 @@ static void insert_pte(struct i915_address_space *vm, {struct insert_pte_data *d = data; - vm->insert_page (vm,px_dma (pt), d->offset, -i915_gem_get_pat_index (vm->i915,I915_CACHE_NONE ), + vm->insert_page (vm,px_dma (pt), d->offset, vm->i915->pat_uc,i915_gem_object_is_lmem (pt->base) ?PTE_LM :0 ); d->offset +=PAGE_SIZE ; }
drivers/gpu/drm/i915/gt/selftest_migrate.c +3 -6
@@ -904,8 +904,7 @@ static int perf_clear_blt(void *arg) err =__perf_clear_blt (gt->migrate.context, dst->mm.pages->sgl, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), + gt->i915->pat_uc,i915_gem_object_is_lmem (dst), sizes[i]);
@@ -995,12 +994,10 @@ static int perf_copy_blt(void *arg) err =__perf_copy_blt (gt->migrate.context, src->mm.pages->sgl, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), + gt->i915->pat_uc,i915_gem_object_is_lmem (src), dst->mm.pages->sgl, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), + gt->i915->pat_uc,i915_gem_object_is_lmem (dst), sz);
drivers/gpu/drm/i915/gt/selftest_reset.c +4 -10
@@ -84,11 +84,8 @@ __igt_reset_stolen(struct intel_gt *gt,void __iomem *s;void *in; - ggtt->vm.insert_page (&ggtt->vm, dma, - ggtt->error_capture.start, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), -0 ); + ggtt->vm.insert_page (&ggtt->vm, dma, ggtt->error_capture.start, + gt->i915->pat_uc,0 );mb (); s = io_mapping_map_wc(&ggtt->iomap,
@@ -127,11 +124,8 @@ __igt_reset_stolen(struct intel_gt *gt,void *in;u32 x; - ggtt->vm.insert_page (&ggtt->vm, dma, - ggtt->error_capture.start, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), -0 ); + ggtt->vm.insert_page (&ggtt->vm, dma, ggtt->error_capture.start, + gt->i915->pat_uc,0 );mb (); s = io_mapping_map_wc(&ggtt->iomap,
drivers/gpu/drm/i915/gt/selftest_timeline.c +4 -1
@@ -836,7 +836,10 @@ static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt,return PTR_ERR (obj);/* keep the same cache settings as timeline */ -i915_gem_object_set_pat_index (obj, tl->hwsp_ggtt->obj->pat_index); + obj->pat_index = tl->hwsp_ggtt->obj->pat_index; + obj->cache_mode = tl->hwsp_ggtt->obj->cache_mode; +__i915_gem_object_update_coherency (obj); + w->map =i915_gem_object_pin_map_unlocked (obj,page_unmask_bits (tl->hwsp_ggtt->obj->mm.mapping));if (IS_ERR (w->map)) {
drivers/gpu/drm/i915/gt/selftest_tlb.c +2 -3
@@ -36,8 +36,6 @@ pte_tlbinv(struct intel_context *ce,u64 length, struct rnd_state *prng) { -const unsigned int pat_index = -i915_gem_get_pat_index (ce->vm->i915,I915_CACHE_NONE ); struct drm_i915_gem_object *batch;struct drm_mm_node vb_node;struct i915_request *rq;
@@ -157,7 +155,8 @@ pte_tlbinv(struct intel_context *ce,/* Flip the PTE between A and B */ if (i915_gem_object_is_lmem (vb->obj)) pte_flags |=PTE_LM ; - ce->vm->insert_entries (ce->vm, &vb_res, pat_index, pte_flags); + ce->vm->insert_entries (ce->vm, &vb_res, ce->vm->i915->pat_uc, + pte_flags);/* Flush the PTE update to concurrent HW */ tlbinv (ce->vm, addr & -length, length);
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +2 -6
@@ -991,14 +991,10 @@ static void uc_fw_bind_ggtt(struct intel_uc_fw *uc_fw)if (ggtt->vm.raw_insert_entries) ggtt->vm.raw_insert_entries (&ggtt->vm, vma_res, -i915_gem_get_pat_index (ggtt->vm.i915, -I915_CACHE_NONE ), - pte_flags); + ggtt->vm.i915->pat_uc, pte_flags);else ggtt->vm.insert_entries (&ggtt->vm, vma_res, -i915_gem_get_pat_index (ggtt->vm.i915, -I915_CACHE_NONE ), - pte_flags); + ggtt->vm.i915->pat_uc, pte_flags); }static void uc_fw_unbind_ggtt (struct intel_uc_fw *uc_fw)
drivers/gpu/drm/i915/i915_cache.c new file +59 -0
59 lines not on this page · raw message
drivers/gpu/drm/i915/i915_cache.h new file +129 -0
129 lines not on this page · raw message
drivers/gpu/drm/i915/i915_debugfs.c +39 -44
104 lines not on this page · raw message
drivers/gpu/drm/i915/i915_driver.c +3 -0
@@ -80,6 +80,7 @@#include "soc/intel_dram.h" #include "soc/intel_gmch.h" +#include "i915_cache.h" #include "i915_debugfs.h" #include "i915_driver.h" #include "i915_drm_client.h"
@@ -267,6 +268,8 @@ static int i915_driver_early_probe(struct drm_i915_private *dev_priv)intel_detect_preproduction_hw (dev_priv); +i915_cache_init (dev_priv); +return 0 ; err_rootgt:
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -251,6 +251,9 @@ struct drm_i915_private {unsigned int hpll_freq;unsigned int czclk_freq; +unsigned int pat_uc; +unsigned int pat_wb; +/** * wq - Driver workqueue for GEM. *
drivers/gpu/drm/i915/i915_gem.c +2 -19
@@ -422,9 +422,7 @@ i915_gem_gtt_pread(struct drm_i915_gem_object *obj, ggtt->vm.insert_page (&ggtt->vm,i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), - node.start, -i915_gem_get_pat_index (i915, -I915_CACHE_NONE ),0 ); + node.start, i915->pat_uc,0 ); }else { page_base += offset &PAGE_MASK ; }
@@ -603,9 +601,7 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_gem_object *obj, ggtt->vm.insert_page (&ggtt->vm,i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), - node.start, -i915_gem_get_pat_index (i915, -I915_CACHE_NONE ),0 ); + node.start, i915->pat_uc,0 );wmb ();/* flush modifications to the GGTT (insert_page) */ }else { page_base += offset &PAGE_MASK ;
@@ -1148,19 +1144,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv)unsigned int i;int ret; -/* -* In the proccess of replacing cache_level with pat_index a tricky -* dependency is created on the definition of the enum i915_cache_level. -* in case this enum is changed, PTE encode would be broken. -* Add a WARNING here. And remove when we completely quit using this -* enum -*/ -BUILD_BUG_ON (I915_CACHE_NONE !=0 || -I915_CACHE_LLC !=1 || -I915_CACHE_L3_LLC !=2 || -I915_CACHE_WT !=3 || -I915_MAX_CACHE_LEVEL !=4 ); -/* We need to fallback to 4K pages if host doesn't support huge gtt. */ if (intel_vgpu_active (dev_priv) && !intel_vgpu_has_huge_gtt (dev_priv))RUNTIME_INFO (dev_priv)->page_sizes =I915_GTT_PAGE_SIZE_4K ;
drivers/gpu/drm/i915/i915_gpu_error.c +2 -5
@@ -1122,14 +1122,11 @@ i915_vma_coredump_create(const struct intel_gt *gt,mutex_lock (&ggtt->error_mutex);if (ggtt->vm.raw_insert_page) ggtt->vm.raw_insert_page (&ggtt->vm, dma, slot, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), + ggtt->vm.i915->pat_uc,0 );else ggtt->vm.insert_page (&ggtt->vm, dma, slot, -i915_gem_get_pat_index (gt->i915, -I915_CACHE_NONE ), -0 ); + ggtt->vm.i915->pat_uc,0 );mb (); s =io_mapping_map_wc (&ggtt->iomap, slot,PAGE_SIZE );
drivers/gpu/drm/i915/i915_pci.c +45 -38
185 lines not on this page · raw message
drivers/gpu/drm/i915/intel_device_info.h +4 -2
@@ -27,6 +27,8 @@#include <uapi/drm/i915_drm.h> +#include "i915_cache.h" +#include "intel_step.h" #include "display/intel_display_device.h"
@@ -248,8 +250,8 @@ struct intel_device_info {*/ const struct intel_runtime_info __runtime; -u32 cachelevel_to_pat[I915_MAX_CACHE_LEVEL ]; -u32 max_pat_index; +i915_cache_t cache_modes[9 ]; +unsigned int max_pat_index; };struct intel_driver_caps {
drivers/gpu/drm/i915/selftests/i915_gem.c +1 -4
@@ -57,10 +57,7 @@ static void trash_stolen(struct drm_i915_private *i915)u32 __iomem *s;int x; - ggtt->vm.insert_page (&ggtt->vm, dma, slot, -i915_gem_get_pat_index (i915, -I915_CACHE_NONE ), -0 ); + ggtt->vm.insert_page (&ggtt->vm, dma, slot, i915->pat_uc,0 ); s =io_mapping_map_atomic_wc (&ggtt->iomap, slot);for (x =0 ; x <PAGE_SIZE /sizeof (u32); x++) {
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +2 -2
@@ -246,7 +246,7 @@ static int igt_evict_for_cache_color(void *arg)struct drm_mm_node target = { .start =I915_GTT_PAGE_SIZE *2 , .size =I915_GTT_PAGE_SIZE , - .color =i915_gem_get_pat_index (gt->i915,I915_CACHE_LLC ), + .color =I915_CACHE (WB ), };struct drm_i915_gem_object *obj;struct i915_vma *vma;
@@ -309,7 +309,7 @@ static int igt_evict_for_cache_color(void *arg)/* Attempt to remove the first *pinned* vma, by removing the (empty) * neighbour -- this should fail. */ - target.color =i915_gem_get_pat_index (gt->i915,I915_CACHE_L3_LLC ); + target.color =_I915_CACHE (WB ,LLC );mutex_lock (&ggtt->vm.mutex); err =i915_gem_evict_for_node (&ggtt->vm,NULL , &target,0 );
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +4 -9
@@ -135,7 +135,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size) obj->write_domain =I915_GEM_DOMAIN_CPU ; obj->read_domains =I915_GEM_DOMAIN_CPU ; - obj->pat_index =i915_gem_get_pat_index (i915,I915_CACHE_NONE ); + obj->pat_index = i915->pat_uc;/* Preallocate the "backing storage" */ if (i915_gem_object_pin_pages_unlocked (obj))
@@ -358,10 +358,8 @@ static int lowlevel_hole(struct i915_address_space *vm, mock_vma_res->start = addr;with_intel_runtime_pm (vm->gt->uncore->rpm, wakeref) - vm->insert_entries(vm, mock_vma_res, -i915_gem_get_pat_index (vm->i915, -I915_CACHE_NONE ), -0 ); + vm->insert_entries(vm, mock_vma_res, + vm->i915->pat_uc,0 ); } count = n;
@@ -1379,10 +1377,7 @@ static int igt_ggtt_page(void *arg) ggtt->vm.insert_page (&ggtt->vm,i915_gem_object_get_dma_address (obj,0 ), - offset, -i915_gem_get_pat_index (i915, -I915_CACHE_NONE ), -0 ); + offset, ggtt->vm.i915->pat_uc,0 ); } order =i915_random_order (count, &prng);
drivers/gpu/drm/i915/selftests/intel_memory_region.c +1 -3
@@ -1070,9 +1070,7 @@ static int igt_lmem_write_cpu(void *arg)/* Put the pages into a known state -- from the gpu for added fun */ intel_engine_pm_get (engine); err =intel_context_migrate_clear (engine->gt->migrate.context,NULL , - obj->mm.pages->sgl, -i915_gem_get_pat_index (i915, -I915_CACHE_NONE ), + obj->mm.pages->sgl, i915->pat_uc, true,0xdeadbeaf , &rq);if (rq) { dma_resv_add_fence(obj->base.resv, &rq->fence,
drivers/gpu/drm/i915/selftests/mock_gem_device.c +7 -3
@@ -126,7 +126,12 @@ struct drm_i915_private *mock_gem_device(void)struct drm_i915_private *i915;struct intel_device_info *i915_info;struct pci_dev *pdev; -unsigned int i; +static const i915_cache_t legacy_cache_modes[] = { + [0 ] =I915_CACHE (UC ), + [1 ] =I915_CACHE (WB ), + [2 ] =_I915_CACHE (WB ,L3 ), + [3 ] =I915_CACHE (WT ), + };int ret; pdev =kzalloc (sizeof (*pdev),GFP_KERNEL );
@@ -187,8 +192,7 @@ struct drm_i915_private *mock_gem_device(void)/* simply use legacy cache level for mock device */ i915_info = (struct intel_device_info *)INTEL_INFO (i915); i915_info->max_pat_index =3 ; -for (i =0 ; i <I915_MAX_CACHE_LEVEL ; i++) - i915_info->cachelevel_to_pat[i] = i; +memcpy (i915_info->cache_modes, legacy_cache_modes,sizeof (legacy_cache_modes));intel_memory_regions_hw_probe (i915);
Signature · 1 line
2.39.2
Patchwork
CI[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Refactor PAT/cache handling
== Series Details ==
== Series Details ==
Series: drm/i915: Refactor PAT/cache handling
URL : https://patchwork.freedesktop.org/series/119982/
State : warning
== Summary ==
Error: dim checkpatch failedeb5f7c604fb7 drm/i915: Refactor PAT/cache handling
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:505: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #505: FILE: drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c:63:
+i915_ttm_cache_pat(struct drm_i915_private *i915, struct ttm_resource *res,
+ struct ttm_tt *ttm)
-:810: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #810:
new file mode 100644
-:815: WARNING:SPDX_LICENSE_TAG: Missing or malformed SPDX-License-Identifier tag in line 1 #815: FILE: drivers/gpu/drm/i915/i915_cache.c:1:
+/*
-:816: WARNING:SPDX_LICENSE_TAG: Misplaced SPDX-License-Identifier tag - use line 1 instead #816: FILE: drivers/gpu/drm/i915/i915_cache.c:2:
+ * SPDX-License-Identifier: MIT
-:894: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #894: FILE: drivers/gpu/drm/i915/i915_cache.h:15:
+#define I915_CACHE(mode) \
+ (i915_cache_t)(I915_CACHE_MODE_##mode)
-:897: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #897: FILE: drivers/gpu/drm/i915/i915_cache.h:18:
+#define _I915_CACHE(mode, flag) \
+ (i915_cache_t)((I915_CACHE_MODE_##mode) | ( BIT(8 + I915_CACHE_##flag)))
-:898: ERROR:SPACING: space prohibited after that open parenthesis '(' #898: FILE: drivers/gpu/drm/i915/i915_cache.h:19:
+ (i915_cache_t)((I915_CACHE_MODE_##mode) | ( BIT(8 + I915_CACHE_##flag)))
-:900: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #900: FILE: drivers/gpu/drm/i915/i915_cache.h:21:
+#define I915_CACHE_MODE(cache) \
+ (unsigned int)(((i915_cache_t)(cache)) & 0xff)
-:902: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #902: FILE: drivers/gpu/drm/i915/i915_cache.h:23:
+#define I915_CACHE_FLAGS(cache) \
+ (unsigned int)((((i915_cache_t)(cache) & 0xff00)) >> 16)
-:1055: WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #1055: FILE: drivers/gpu/drm/i915/i915_debugfs.c:147:
+ static const char *mode_str[] = {
-:1061: WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #1061: FILE: drivers/gpu/drm/i915/i915_debugfs.c:153:
+ static const char *flag_str[] = {
total: 5 errors, 5 warnings, 1 checks, 1319 lines checked
Patchwork
CI[Intel-gfx] ✗ Fi.CI.SPARSE: warning for drm/i915: Refactor PAT/cache handling
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: drm/i915: Refactor PAT/cache handling
URL : https://patchwork.freedesktop.org/series/119982/
State : warning
== Summary ==
Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: Refactor PAT/cache handling
In reply to Tvrtko Ursulin== Series Details ==
== Series Details ==
Series: drm/i915: Refactor PAT/cache handling
URL : https://patchwork.freedesktop.org/series/119982/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_13330 -> Patchwork_119982v1
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_119982v1 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_119982v1, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/index.html
Participating hosts (40 -> 39)
------------------------------
Additional (1): fi-kbl-soraka
Missing (2): fi-snb-2520m fi-pnv-d510
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_119982v1:
### IGT changes ###
#### Possible regressions ####
* igt@i915_module_load@load:
- fi-ivb-3770: [PASS][1] -> [ABORT][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-ivb-3770/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-ivb-3770/igt@[email protected]
* igt@i915_selftest@live@gem:
- fi-elk-e7500: [PASS][3] -> [ABORT][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-elk-e7500/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-elk-e7500/igt@i915_selftest@[email protected]
- fi-ilk-650: [PASS][5] -> [INCOMPLETE][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-ilk-650/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-ilk-650/igt@i915_selftest@[email protected]
- fi-blb-e6850: [PASS][7] -> [ABORT][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-blb-e6850/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-blb-e6850/igt@i915_selftest@[email protected]
* igt@prime_vgem@basic-fence-mmap:
- fi-elk-e7500: [PASS][9] -> [CRASH][10] +1 similar issue
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-elk-e7500/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-elk-e7500/igt@[email protected]
- fi-bsw-nick: [PASS][11] -> [CRASH][12] +1 similar issue
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-bsw-nick/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-bsw-nick/igt@[email protected]
- fi-ilk-650: [PASS][13] -> [CRASH][14] +1 similar issue
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-ilk-650/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-ilk-650/igt@[email protected]
* igt@prime_vgem@basic-gtt:
- fi-blb-e6850: [PASS][15] -> [CRASH][16] +1 similar issue
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-blb-e6850/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-blb-e6850/igt@[email protected]
- fi-bsw-n3050: [PASS][17] -> [CRASH][18] +1 similar issue
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-bsw-n3050/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-bsw-n3050/igt@[email protected]
- fi-apl-guc: [PASS][19] -> [CRASH][20] +1 similar issue
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-apl-guc/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-apl-guc/igt@[email protected]
- fi-glk-j4005: [PASS][21] -> [CRASH][22] +1 similar issue
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/fi-glk-j4005/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-glk-j4005/igt@[email protected]
Known issues
------------
Here are the changes found in Patchwork_119982v1 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@gem_huc_copy@huc-copy:
- fi-kbl-soraka: NOTRUN -> [SKIP][23] ([fdo#109271] / [i915#2190])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-kbl-soraka/igt@[email protected]
* igt@gem_lmem_swapping@basic:
- fi-kbl-soraka: NOTRUN -> [SKIP][24] ([fdo#109271] / [i915#4613]) +3 similar issues
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-kbl-soraka/igt@[email protected]
* igt@i915_module_load@load:
- bat-mtlp-8: [PASS][25] -> [ABORT][26] ([i915#8141])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/bat-mtlp-8/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-mtlp-8/igt@[email protected]
* igt@i915_selftest@live@gt_heartbeat:
- fi-kbl-soraka: NOTRUN -> [DMESG-FAIL][27] ([i915#5334] / [i915#7872])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-kbl-soraka/igt@i915_selftest@live@gt_heartbeat.html
* igt@i915_selftest@live@gt_pm:
- fi-kbl-soraka: NOTRUN -> [DMESG-FAIL][28] ([i915#1886] / [i915#7913])
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-kbl-soraka/igt@i915_selftest@live@gt_pm.html
* igt@i915_selftest@live@requests:
- bat-rpls-1: [PASS][29] -> [ABORT][30] ([i915#4983] / [i915#7911] / [i915#7920])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/bat-rpls-1/igt@i915_selftest@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-rpls-1/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@slpc:
- bat-rpls-2: NOTRUN -> [DMESG-WARN][31] ([i915#6367])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-rpls-2/igt@i915_selftest@[email protected]
* igt@i915_suspend@basic-s2idle-without-i915:
- bat-rpls-2: NOTRUN -> [ABORT][32] ([i915#6687] / [i915#8668])
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-rpls-2/igt@[email protected]
* igt@kms_chamelium_frames@hdmi-crc-fast:
- fi-kbl-soraka: NOTRUN -> [SKIP][33] ([fdo#109271]) +14 similar issues
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-kbl-soraka/igt@[email protected]
* igt@kms_chamelium_hpd@common-hpd-after-suspend:
- bat-dg2-11: NOTRUN -> [SKIP][34] ([i915#7828])
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-dg2-11/igt@[email protected]
* igt@kms_pipe_crc_basic@nonblocking-crc-frame-sequence:
- bat-dg2-11: NOTRUN -> [SKIP][35] ([i915#1845] / [i915#5354]) +2 similar issues
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-dg2-11/igt@[email protected]
* igt@kms_pipe_crc_basic@read-crc-frame-sequence@pipe-d-edp-1:
- bat-rplp-1: [PASS][36] -> [ABORT][37] ([i915#8442])
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/bat-rplp-1/igt@kms_pipe_crc_basic@[email protected]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-rplp-1/igt@kms_pipe_crc_basic@[email protected]
* igt@kms_setmode@basic-clone-single-crtc:
- fi-kbl-soraka: NOTRUN -> [SKIP][38] ([fdo#109271] / [i915#4579])
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/fi-kbl-soraka/igt@[email protected]
#### Possible fixes ####
* igt@i915_selftest@live@hangcheck:
- bat-dg2-11: [ABORT][39] ([i915#7913] / [i915#7979]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/bat-dg2-11/igt@i915_selftest@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-dg2-11/igt@i915_selftest@[email protected]
* igt@i915_selftest@live@reset:
- bat-rpls-2: [ABORT][41] ([i915#4983] / [i915#7461] / [i915#7913] / [i915#7981] / [i915#8347]) -> [PASS][42]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13330/bat-rpls-2/igt@i915_selftest@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/bat-rpls-2/igt@i915_selftest@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#1845]: https://gitlab.freedesktop.org/drm/intel/issues/1845
[i915#1886]: https://gitlab.freedesktop.org/drm/intel/issues/1886
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#4579]: https://gitlab.freedesktop.org/drm/intel/issues/4579
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983
[i915#5334]: https://gitlab.freedesktop.org/drm/intel/issues/5334
[i915#5354]: https://gitlab.freedesktop.org/drm/intel/issues/5354
[i915#6367]: https://gitlab.freedesktop.org/drm/intel/issues/6367
[i915#6687]: https://gitlab.freedesktop.org/drm/intel/issues/6687
[i915#7461]: https://gitlab.freedesktop.org/drm/intel/issues/7461
[i915#7828]: https://gitlab.freedesktop.org/drm/intel/issues/7828
[i915#7872]: https://gitlab.freedesktop.org/drm/intel/issues/7872
[i915#7911]: https://gitlab.freedesktop.org/drm/intel/issues/7911
[i915#7913]: https://gitlab.freedesktop.org/drm/intel/issues/7913
[i915#7920]: https://gitlab.freedesktop.org/drm/intel/issues/7920
[i915#7979]: https://gitlab.freedesktop.org/drm/intel/issues/7979
[i915#7981]: https://gitlab.freedesktop.org/drm/intel/issues/7981
[i915#8141]: https://gitlab.freedesktop.org/drm/intel/issues/8141
[i915#8347]: https://gitlab.freedesktop.org/drm/intel/issues/8347
[i915#8442]: https://gitlab.freedesktop.org/drm/intel/issues/8442
[i915#8668]: https://gitlab.freedesktop.org/drm/intel/issues/8668
Build changes
-------------
* Linux: CI_DRM_13330 -> Patchwork_119982v1
CI-20190529: 20190529
CI_DRM_13330: dd3ec2080383e2bf738c6640aca4183997cf2dde @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7353: cacdae5ad7cb92bdc26a79802fcdd244dadccd42 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_119982v1: dd3ec2080383e2bf738c6640aca4183997cf2dde @ git://anongit.freedesktop.org/gfx-ci/linux
### Linux commits
a2c3c5aa5650 drm/i915: Refactor PAT/cache handling
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v1/index.html
Quoted 7 lines
From: Tvrtko Ursulin <[email protected]>
Informal commit message for now.
I got a bit impatient and curious to see if the idea we discussed would work so sketched something out. I think it is what I was describing back then..
Oops, you beat me on this, shame on me.
Quoted 91 lines
So high level idea is to teach the driver what caching modes are hidden behind PAT indices. Given you already had that in static tables, if we just turn the tables a bit around and add a driver abstraction of caching modes this is what happens:
* We can lose the ugly runtime
i915_gem_get_pat_index.* We can have a smarter
i915_gem_object_has_cache_level, which now can use the above mentioned table to understand the caching modes and so does not have to pessimistically return true for _any_ input when user has set the PAT index. This may improve things even for MTL.* We can simplify the debugfs printout to be platform agnostic.
* We are perhaps opening the door to un-regress the dodgy addition made to
i915_gem_object_can_bypass_llc? See QQQ/FIXME in the patch.I hope I did not forget anything, but anyway, please have a read and see what you think. I think it has potential.
Proper commit message can come later.
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Fei Yang <[email protected]>--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gem/i915_gem_domain.c | 34 ++--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 13 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 10 +- drivers/gpu/drm/i915/gem/i915_gem_object.c | 78 ++++------- drivers/gpu/drm/i915/gem/i915_gem_object.h | 18 ++- .../gpu/drm/i915/gem/i915_gem_object_types.h | 99 +------------- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 7 +- drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 26 ++-- .../gpu/drm/i915/gem/selftests/huge_pages.c | 2 +- drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 4 +- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 13 +- drivers/gpu/drm/i915/gt/intel_ggtt.c | 9 +- drivers/gpu/drm/i915/gt/intel_migrate.c | 11 +- drivers/gpu/drm/i915/gt/selftest_migrate.c | 9 +- drivers/gpu/drm/i915/gt/selftest_reset.c | 14 +- drivers/gpu/drm/i915/gt/selftest_timeline.c | 5 +- drivers/gpu/drm/i915/gt/selftest_tlb.c | 5 +- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 8 +- drivers/gpu/drm/i915/i915_cache.c | 59 ++++++++ drivers/gpu/drm/i915/i915_cache.h | 129 ++++++++++++++++++ drivers/gpu/drm/i915/i915_debugfs.c | 83 ++++++----- drivers/gpu/drm/i915/i915_driver.c | 3 + drivers/gpu/drm/i915/i915_drv.h | 3 + drivers/gpu/drm/i915/i915_gem.c | 21 +-- drivers/gpu/drm/i915/i915_gpu_error.c | 7 +- drivers/gpu/drm/i915/i915_pci.c | 83 +++++------ drivers/gpu/drm/i915/intel_device_info.h | 6 +- drivers/gpu/drm/i915/selftests/i915_gem.c | 5 +- .../gpu/drm/i915/selftests/i915_gem_evict.c | 4 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 13 +- .../drm/i915/selftests/intel_memory_region.c | 4 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 10 +- 33 files changed, 415 insertions(+), 381 deletions(-) create mode 100644 drivers/gpu/drm/i915/i915_cache.c create mode 100644 drivers/gpu/drm/i915/i915_cache.hdrivers/gpu/drm/i915/Makefile +1
-0@@ -30,6 +30,7 @@ subdir-ccflags-y += -I$(srctree)/$(src) # core driver code i915-y += i915_driver.o \ i915_drm_client.o \ + i915_cache.o \ i915_config.o \ i915_getparam.o \ i915_ioctl.o \drivers/gpu/drm/i915/gem/i915_gem_domain.c +1
-1@@ -8,6 +8,7 @@#include "display/intel_frontbuffer.h" #include "gt/intel_gt.h" +#include "i915_cache.h" #include "i915_drv.h" #include "i915_gem_clflush.h" #include "i915_gem_domain.h" @@ -27,15 +28,8 @@ static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj) if (IS_DGFX(i915)) return false; - /*
drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj) · line 32
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-8-* For objects created by userspace through GEM_CREATE with pat_index -* set by set_pat extension, i915_gem_object_has_cache_level() will -* always return true, because the coherency of such object is managed -* by userspace. Othereise the call here would fall back to checking -* whether the object is un-cached or write-through. -*/ - return !(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) || - i915_gem_object_has_cache_level(obj, I915_CACHE_WT)); + return i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_UC) != 1 && + i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WT) != 1;
Why is it necessary to define I915_CACHE_MODE's while there is already i915_cache_level? I thought we wanted to get rid of such abstractions instead of adding more.
This patch also introduced INTEL_INFO(i915)->cache_modes, why don't we directly add the platform specific PAT there? For example, add the following for MTL,
INTEL_INFO(i915)->pat[] = {
[0] = MTL_PPAT_L4_0_WB, \
[1] = MTL_PPAT_L4_1_WT, \
[2] = MTL_PPAT_L4_3_UC, \
[3] = MTL_PPAT_L4_0_WB | MTL_2_COH_1W, \
[4] = MTL_PPAT_L4_0_WB | MTL_3_COH_2W, \
}
Everything here has already been defined, no need to introduce new macros.
This can also be used to initialize the PAT index registers, like in xelpg_setup_private_ppat() and xelpmp_setup_private_ppat().
drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 267
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0
-0}bool i915_gem_cpu_write_needs_clflush (struct drm_i915_gem_object *obj)@@ -272,15 +266,18 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)int i915_gem_object_set_cache_level (struct drm_i915_gem_object *obj, enum i915_cache_level cache_level)
s/enum i915_cache_level cache_level/unsigned int pat_index
This function is for KMD objects only, I don't think we even need to keep the i915_cache_level, simply passing in INTEL_INFO(i915)->pat_uc/wb/wt is good enough.
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-0{ + struct drm_i915_private *i915 = to_i915(obj->base.dev); + i915_cache_t mode; int ret;
drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 274
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-7- /* - * For objects created by userspace through GEM_CREATE with pat_index - * set by set_pat extension, simply return 0 here without touching - * the cache setting, because such objects should have an immutable - * cache setting by desgin and always managed by userspace. - */ - if (i915_gem_object_has_cache_level(obj, cache_level)) + if (obj->pat_set_by_user) + return -EINVAL;
I don't think this condition would ever be true, but okay to keep it.
drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 280
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5
-0+ ret = i915_cache_level_to_pat_and_mode(i915, cache_level, &mode); + if (ret < 0) + return -EINVAL; + + if (mode == obj->cache_mode)
The above lines can be just one line,
if (pat_index == obj->pat_index)
Quoted 77 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-3return 0; ret = i915_gem_object_wait(obj,@@ -326,10 +323,9 @@ int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, goto out; } - if (i915_gem_object_has_cache_level(obj, I915_CACHE_LLC) || - i915_gem_object_has_cache_level(obj, I915_CACHE_L3_LLC)) + if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WB)) args->caching = I915_CACHING_CACHED; - else if (i915_gem_object_has_cache_level(obj, I915_CACHE_WT)) + else if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WT)) args->caching = I915_CACHING_DISPLAY; else args->caching = I915_CACHING_NONE;drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2
-11@@ -640,15 +640,9 @@ static inline int use_cpu_reloc(const struct reloc_cache *cache, if (DBG_FORCE_RELOC == FORCE_GTT_RELOC) return false; - /* - * For objects created by userspace through GEM_CREATE with pat_index - * set by set_pat extension, i915_gem_object_has_cache_level() always - * return true, otherwise the call would fall back to checking whether - * the object is un-cached. - */ return (cache->has_llc || obj->cache_dirty || - !i915_gem_object_has_cache_level(obj, I915_CACHE_NONE)); + i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_UC) != 1); } static int eb_reserve_vma(struct i915_execbuffer *eb,@@ -1329,10 +1323,7 @@ static void *reloc_iomap(struct i915_vma *batch, if (drm_mm_node_allocated(&cache->node)) { ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj, page), - offset, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - 0); + offset, eb->i915->pat_uc, 0); } else { offset += page << PAGE_SHIFT; }drivers/gpu/drm/i915/gem/i915_gem_mman.c +4
-6@@ -386,13 +386,11 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf) /* * For objects created by userspace through GEM_CREATE with pat_index * set by set_pat extension, coherency is managed by userspace, make - * sure we don't fail handling the vm fault by calling - * i915_gem_object_has_cache_level() which always return true for such - * objects. Otherwise this helper function would fall back to checking - * whether the object is un-cached. + * sure we don't fail handling the vm fault by making sure that we + * know the object is uncached or that we have LLC. */ - if (!(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) || - HAS_LLC(i915))) { + if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_UC) != 1 && + !HAS_LLC(i915)) { ret = -EFAULT; goto err_unpin; }drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-0@@ -45,33 +45,6 @@ static struct kmem_cache *slab_objects;
drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects; · line 55
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-8static const struct drm_gem_object_funcs i915_gem_object_funcs; -unsigned int i915_gem_get_pat_index (struct drm_i915_private *i915, - enum i915_cache_level level) -{ - if (drm_WARN_ON(&i915->drm, level >= I915_MAX_CACHE_LEVEL)) - return 0; - - return INTEL_INFO(i915)->cachelevel_to_pat[level]; -}
Yes, this can be removed. INTEL_INFO(i915)->pat_uc/wb/wt should be sufficient,
drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects; · line 59
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-4- -bool i915_gem_object_has_cache_level (const struct drm_i915_gem_object *obj, - enum i915_cache_level lvl) -{
If we had INTEL_INFO(i915)->pat[] setup, it would be easier just to keep this function, because we can simply check the cache policy bit field in INTEL_INFO(i915)->pat[obj->pat_index] to see whether it is cached, uncached, or write-through.
See Bspec https://gfxspecs.intel.com/Predator/Home/Index/44235
For MTL check bit[3:2], for other gen12 platforms check bit[1:0]
Quoted 19 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-15- /* - * In case the pat_index is set by user space, this kernel mode - * driver should leave the coherency to be managed by user space, - * simply return true here. - */ - if (obj->pat_set_by_user) - return true; - - /* - * Otherwise the pat_index should have been converted from cache_level - * so that the following comparison is valid. - */ - return obj->pat_index == i915_gem_get_pat_index(obj_to_i915(obj), lvl); -} -struct drm_i915_gem_object *i915_gem_object_alloc (void ) { struct drm_i915_gem_object *obj;
drivers/gpu/drm/i915/gem/i915_gem_object.c void __i915_gem_object_fini(struct drm_i915_gem_object *obj) · line 123
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +4
-0@@ -144,6 +117,24 @@ void __i915_gem_object_fini(struct drm_i915_gem_object *obj) dma_resv_fini(&obj->base._resv); } +void __i915_gem_object_update_coherency (struct drm_i915_gem_object *obj) +{ + struct drm_i915_private *i915 = to_i915(obj->base.dev); + const unsigned int mode = I915_CACHE_MODE(obj->cache_mode);
obj->cache_mode seems to be redundant if we have INTEL_INFO(i915)->pat[] and obj->pat_index.
Quoted 618 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +24
-23+ + if (!(mode == I915_CACHE_MODE_UNKNOWN || mode == I915_CACHE_MODE_UC)) + obj->cache_coherent = (I915_BO_CACHE_COHERENT_FOR_READ | + I915_BO_CACHE_COHERENT_FOR_WRITE); + else if (mode != I915_CACHE_MODE_UNKNOWN && HAS_LLC(i915)) + obj->cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ; + else + obj->cache_coherent = 0; + + obj->cache_dirty = + !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) && + !IS_DGFX(i915); +} +/** * i915_gem_object_set_cache_coherency - Mark up the object's coherency levels * for a given cache_level @@ -154,20 +145,15 @@ void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj, unsigned int cache_level) { struct drm_i915_private *i915 = to_i915(obj->base.dev); + i915_cache_t mode; + int found; - obj->pat_index = i915_gem_get_pat_index(i915, cache_level); + found = i915_cache_level_to_pat_and_mode(i915, cache_level, &mode); + GEM_WARN_ON(found < 0); + obj->pat_index = found; + obj->cache_mode = mode; - if (cache_level != I915_CACHE_NONE) - obj->cache_coherent = (I915_BO_CACHE_COHERENT_FOR_READ | - I915_BO_CACHE_COHERENT_FOR_WRITE); - else if (HAS_LLC(i915)) - obj->cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ; - else - obj->cache_coherent = 0; - - obj->cache_dirty = - !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) && - !IS_DGFX(i915); + __i915_gem_object_update_coherency(obj); }/** @@ -187,18 +173,9 @@ void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj, return; obj->pat_index = pat_index; + obj->cache_mode = INTEL_INFO(i915)->cache_modes[pat_index]; - if (pat_index != i915_gem_get_pat_index(i915, I915_CACHE_NONE)) - obj->cache_coherent = (I915_BO_CACHE_COHERENT_FOR_READ | - I915_BO_CACHE_COHERENT_FOR_WRITE); - else if (HAS_LLC(i915)) - obj->cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ; - else - obj->cache_coherent = 0; - - obj->cache_dirty = - !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) && - !IS_DGFX(i915); + __i915_gem_object_update_coherency(obj); }bool i915_gem_object_can_bypass_llc (struct drm_i915_gem_object *obj)@@ -215,6 +192,7 @@ bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj) /* * Always flush cache for UMD objects at creation time. */ + /* QQQ/FIXME why? avoidable performance penalty? */ if (obj->pat_set_by_user) return true;drivers/gpu/drm/i915/gem/i915_gem_object.h +14
-4@@ -13,6 +13,7 @@#include "display/intel_frontbuffer.h" #include "intel_memory_region.h" +#include "i915_cache.h" #include "i915_gem_object_types.h" #include "i915_gem_gtt.h" #include "i915_gem_ww.h" @@ -32,10 +33,18 @@ static inline bool i915_gem_object_size_2big(u64 size) return false; } -unsigned int i915_gem_get_pat_index (struct drm_i915_private *i915, - enum i915_cache_level level); -bool i915_gem_object_has_cache_level (const struct drm_i915_gem_object *obj, - enum i915_cache_level lvl); +static inline int +i915_gem_object_has_cache_mode (const struct drm_i915_gem_object *obj, + unsigned int mode) +{ + if (I915_CACHE_MODE(obj->cache_mode) == mode) + return 1; + else if (obj->pat_set_by_user) + return -1; /* Unknown, callers should assume no. */ + else + return 0; +} +void i915_gem_init__objects (struct drm_i915_private *i915);void i915_objects_module_exit (void );@@ -764,6 +773,7 @@ int i915_gem_object_wait_moving_fence(struct drm_i915_gem_object *obj, bool intr);bool i915_gem_object_has_unknown_state (struct drm_i915_gem_object *obj); +void __i915_gem_object_update_coherency (struct drm_i915_gem_object *obj);void i915_gem_object_set_cache_coherency (struct drm_i915_gem_object *obj, unsigned int cache_level); void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj,drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6
-93@@ -14,6 +14,7 @@#include <uapi/drm/i915_drm.h> #include "i915_active.h" +#include "i915_cache.h" #include "i915_selftest.h" #include "i915_vma_resource.h" @@ -116,93 +117,6 @@ struct drm_i915_gem_object_ops { const char *name; /* friendly name for debug, e.g. lockdep classes */ }; -/** -* enum i915_cache_level - The supported GTT caching values for system memory -* pages. -* -* These translate to some special GTT PTE bits when binding pages into some -* address space. It also determines whether an object, or rather its pages are -* coherent with the GPU, when also reading or writing through the CPU cache -* with those pages. -* -* Userspace can also control this through struct drm_i915_gem_caching. -*/ -enum i915_cache_level { - /** - * @I915_CACHE_NONE: - * - * GPU access is not coherent with the CPU cache. If the cache is dirty - * and we need the underlying pages to be coherent with some later GPU - * access then we need to manually flush the pages. - * - * On shared LLC platforms reads and writes through the CPU cache are - * still coherent even with this setting. See also - * &drm_i915_gem_object.cache_coherent for more details. Due to this we - * should only ever use uncached for scanout surfaces, otherwise we end - * up over-flushing in some places. - * - * This is the default on non-LLC platforms. - */ - I915_CACHE_NONE = 0, - /** - * @I915_CACHE_LLC: - * - * GPU access is coherent with the CPU cache. If the cache is dirty, - * then the GPU will ensure that access remains coherent, when both - * reading and writing through the CPU cache. GPU writes can dirty the - * CPU cache. - * - * Not used for scanout surfaces. - * - * Applies to both platforms with shared LLC(HAS_LLC), and snooping - * based platforms(HAS_SNOOP). - * - * This is the default on shared LLC platforms. The only exception is - * scanout objects, where the display engine is not coherent with the - * CPU cache. For such objects I915_CACHE_NONE or I915_CACHE_WT is - * automatically applied by the kernel in pin_for_display, if userspace - * has not done so already. - */ - I915_CACHE_LLC, - /** - * @I915_CACHE_L3_LLC: - * - * Explicitly enable the Gfx L3 cache, with coherent LLC. - * - * The Gfx L3 sits between the domain specific caches, e.g - * sampler/render caches, and the larger LLC. LLC is coherent with the - * GPU, but L3 is only visible to the GPU, so likely needs to be flushed - * when the workload completes. - * - * Not used for scanout surfaces. - * - * Only exposed on some gen7 + GGTT. More recent hardware has dropped - * this explicit setting, where it should now be enabled by default. - */ - I915_CACHE_L3_LLC, - /** - * @I915_CACHE_WT: - * - * Write-through. Used for scanout surfaces. - * - * The GPU can utilise the caches, while still having the display engine - * be coherent with GPU writes, as a result we don't need to flush the - * CPU caches when moving out of the render domain. This is the default - * setting chosen by the kernel, if supported by the HW, otherwise we - * fallback to I915_CACHE_NONE. On the CPU side writes through the CPU - * cache still need to be flushed, to remain coherent with the display - * engine. - */ - I915_CACHE_WT, - /** - * @I915_MAX_CACHE_LEVEL: - * - * Mark the last entry in the enum. Used for defining cachelevel_to_pat - * array for cache_level to pat translation table. - */ - I915_MAX_CACHE_LEVEL, -}; -enum i915_map_type { I915_MAP_WB = 0, I915_MAP_WC,@@ -375,6 +289,9 @@ struct drm_i915_gem_object { unsigned int mem_flags;#define I915_BO_FLAG_STRUCT_PAGE BIT(0)/* Object backed by struct pages */ #define I915_BO_FLAG_IOMEM BIT(1)/* Object backed by IO memory */ + + i915_cache_t cache_mode; + /*** @pat_index: The desired PAT index. * @@ -409,9 +326,7 @@ struct drm_i915_gem_object { * Check for @pat_set_by_user to find out if an object has pat index set * by userspace. The ioctl's to change cache settings have also been * disabled for the objects with pat index set by userspace. Please don't - * assume @cache_coherent having the flags set as describe here. A helper - * function i915_gem_object_has_cache_level() provides one way to bypass - * the use of this field. + * assume @cache_coherent having the flags set as describe here. * * Track whether the pages are coherent with the GPU if reading or * writing through the CPU caches. The largely depends on the@@ -492,9 +407,7 @@ struct drm_i915_gem_object { * Check for @pat_set_by_user to find out if an object has pat index set * by userspace. The ioctl's to change cache settings have also been * disabled for the objects with pat_index set by userspace. Please don't - * assume @cache_dirty is set as describe here. Also see helper function - * i915_gem_object_has_cache_level() for possible ways to bypass the use - * of this field. + * assume @cache_dirty is set as describe here. * * Track if we are we dirty with writes through the CPU cache for this * object. As a result reading directly from main memory might yielddrivers/gpu/drm/i915/gem/i915_gem_stolen.c +2
-5@@ -563,11 +563,8 @@ static void dbg_poison(struct i915_ggtt *ggtt, while (size) { void __iomem *s; - ggtt->vm.insert_page(&ggtt->vm, addr, - ggtt->error_capture.start, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, addr, ggtt->error_capture.start, + ggtt->vm.i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap,drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +17
-9@@ -58,6 +58,16 @@ i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res, I915_CACHE_NONE; } +static unsigned int +i915_ttm_cache_pat (struct drm_i915_private *i915,struct ttm_resource *res, + struct ttm_tt *ttm) +{ + return ((HAS_LLC(i915) || HAS_SNOOP(i915)) && + !i915_ttm_gtt_binds_lmem(res) && + ttm->caching == ttm_cached) ? i915->pat_wb : + i915->pat_uc; +} +static struct intel_memory_region *i915_ttm_region (struct ttm_device *bdev,int ttm_mem_type) {@@ -196,7 +206,7 @@ static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo, struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); struct i915_request *rq; struct ttm_tt *src_ttm = bo->ttm; - enum i915_cache_level src_level, dst_level; + unsigned int src_pat, dst_pat; int ret; if (!to_gt(i915)->migrate.context || intel_gt_is_wedged(to_gt(i915)))@@ -206,16 +216,15 @@ static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo, if (I915_SELFTEST_ONLY(fail_gpu_migration)) clear = true; - dst_level = i915_ttm_cache_level(i915, dst_mem, dst_ttm); + dst_pat = i915_ttm_cache_pat(i915, dst_mem, dst_ttm); if (clear) { if (bo->type == ttm_bo_type_kernel && !I915_SELFTEST_ONLY(fail_gpu_migration)) return ERR_PTR(-EINVAL); intel_engine_pm_get(to_gt(i915)->migrate.context->engine); - ret = intel_context_migrate_clear(to_gt(i915)->migrate.context, deps, - dst_st->sgl, - i915_gem_get_pat_index(i915, dst_level), + ret = intel_context_migrate_clear(to_gt(i915)->migrate.context, + deps, dst_st->sgl, dst_pat, i915_ttm_gtt_binds_lmem(dst_mem), 0, &rq); } else {@@ -225,14 +234,13 @@ static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo, if (IS_ERR(src_rsgt)) return ERR_CAST(src_rsgt); - src_level = i915_ttm_cache_level(i915, bo->resource, src_ttm); + src_pat = i915_ttm_cache_pat(i915, bo->resource, src_ttm); intel_engine_pm_get(to_gt(i915)->migrate.context->engine); ret = intel_context_migrate_copy(to_gt(i915)->migrate.context, deps, src_rsgt->table.sgl, - i915_gem_get_pat_index(i915, src_level), + src_pat, i915_ttm_gtt_binds_lmem(bo->resource), - dst_st->sgl, - i915_gem_get_pat_index(i915, dst_level), + dst_st->sgl, dst_pat, i915_ttm_gtt_binds_lmem(dst_mem), &rq);drivers/gpu/drm/i915/gem/selftests/huge_pages.c +1
-1@@ -354,7 +354,7 @@ fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single) obj->write_domain = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU; - obj->pat_index = i915_gem_get_pat_index(i915, I915_CACHE_NONE); + i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE); return obj; }drivers/gpu/drm/i915/gt/gen6_ppgtt.c +1
-3@@ -226,9 +226,7 @@ static int gen6_ppgtt_init_scratch(struct gen6_ppgtt *ppgtt) return ret; vm->scratch[0]->encode = - vm->pte_encode(px_dma(vm->scratch[0]), - i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), + vm->pte_encode(px_dma(vm->scratch[0]), vm->i915->pat_uc, PTE_READ_ONLY); vm->scratch[1] = vm->alloc_pt_dma(vm, I915_GTT_PAGE_SIZE_4K);drivers/gpu/drm/i915/gt/gen8_ppgtt.c +3
-10@@ -40,16 +40,11 @@ static u64 gen8_pte_encode(dma_addr_t addr, if (flags & PTE_LM) pte |= GEN12_PPGTT_PTE_LM; - /* - * For pre-gen12 platforms pat_index is the same as enum - * i915_cache_level, so the switch-case here is still valid. - * See translation table defined by LEGACY_CACHELEVEL. - */ switch (pat_index) { - case I915_CACHE_NONE: + case 0: pte |= PPAT_UNCACHED; break; - case I915_CACHE_WT: + case 3: pte |= PPAT_DISPLAY_ELLC; break; default:@@ -853,9 +848,7 @@ static int gen8_init_scratch(struct i915_address_space *vm) pte_flags |= PTE_LM; vm->scratch[0]->encode = - vm->pte_encode(px_dma(vm->scratch[0]), - i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), + vm->pte_encode(px_dma(vm->scratch[0]), vm->i915->pat_uc, pte_flags); for (i = 1; i <= vm->top; i++) {drivers/gpu/drm/i915/gt/intel_ggtt.c +2
-7@@ -921,9 +921,7 @@ static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size) pte_flags |= PTE_LM; ggtt->vm.scratch[0]->encode = - ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]), - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), + ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]), i915->pat_uc, pte_flags); return 0;@@ -1297,10 +1295,7 @@ bool i915_ggtt_resume_vm(struct i915_address_space *vm)* ptes to be repopulated. */ vma->resource->bound_flags = 0; - vma->ops->bind_vma(vm, NULL, vma->resource, - obj ? obj->pat_index : - i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), + vma->ops->bind_vma(vm, NULL, vma->resource, obj->cache_mode, was_bound); if (obj) { /* only used during resume => exclusive access */drivers/gpu/drm/i915/gt/intel_migrate.c +3
-8@@ -45,9 +45,7 @@ static void xehpsdv_toggle_pdes(struct i915_address_space *vm,* Insert a dummy PTE into every PT that will map to LMEM to ensure * we have a correctly setup PDE structure for later use. */ - vm->insert_page(vm, 0, d->offset, - i915_gem_get_pat_index(vm->i915, I915_CACHE_NONE), - PTE_LM); + vm->insert_page(vm, 0, d->offset, vm->i915->pat_uc, PTE_LM); GEM_BUG_ON(!pt->is_compact); d->offset += SZ_2M; }@@ -65,9 +63,7 @@ static void xehpsdv_insert_pte(struct i915_address_space *vm,* alignment is 64K underneath for the pt, and we are careful * not to access the space in the void. */ - vm->insert_page(vm, px_dma(pt), d->offset, - i915_gem_get_pat_index(vm->i915, I915_CACHE_NONE), - PTE_LM); + vm->insert_page(vm, px_dma(pt), d->offset, vm->i915->pat_uc, PTE_LM); d->offset += SZ_64K; }@@ -77,8 +73,7 @@ static void insert_pte(struct i915_address_space *vm, { struct insert_pte_data *d = data; - vm->insert_page(vm, px_dma(pt), d->offset, - i915_gem_get_pat_index(vm->i915, I915_CACHE_NONE), + vm->insert_page(vm, px_dma(pt), d->offset, vm->i915->pat_uc, i915_gem_object_is_lmem(pt->base) ? PTE_LM : 0); d->offset += PAGE_SIZE; }drivers/gpu/drm/i915/gt/selftest_migrate.c +3
-6@@ -904,8 +904,7 @@ static int perf_clear_blt(void *arg) err = __perf_clear_blt(gt->migrate.context, dst->mm.pages->sgl, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + gt->i915->pat_uc, i915_gem_object_is_lmem(dst), sizes[i]);@@ -995,12 +994,10 @@ static int perf_copy_blt(void *arg) err = __perf_copy_blt(gt->migrate.context, src->mm.pages->sgl, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + gt->i915->pat_uc, i915_gem_object_is_lmem(src), dst->mm.pages->sgl, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + gt->i915->pat_uc, i915_gem_object_is_lmem(dst), sz);drivers/gpu/drm/i915/gt/selftest_reset.c +4
-10@@ -84,11 +84,8 @@ __igt_reset_stolen(struct intel_gt *gt, void __iomem *s; void *in; - ggtt->vm.insert_page(&ggtt->vm, dma, - ggtt->error_capture.start, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, dma, ggtt->error_capture.start, + gt->i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap,@@ -127,11 +124,8 @@ __igt_reset_stolen(struct intel_gt *gt, void *in; u32 x; - ggtt->vm.insert_page(&ggtt->vm, dma, - ggtt->error_capture.start, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, dma, ggtt->error_capture.start, + gt->i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap,drivers/gpu/drm/i915/gt/selftest_timeline.c +4
-1@@ -836,7 +836,10 @@ static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt, return PTR_ERR(obj); /* keep the same cache settings as timeline */ - i915_gem_object_set_pat_index(obj, tl->hwsp_ggtt->obj->pat_index); + obj->pat_index = tl->hwsp_ggtt->obj->pat_index; + obj->cache_mode = tl->hwsp_ggtt->obj->cache_mode; + __i915_gem_object_update_coherency(obj); + w->map = i915_gem_object_pin_map_unlocked(obj, page_unmask_bits(tl->hwsp_ggtt->obj->mm.mapping)); if (IS_ERR(w->map)) {drivers/gpu/drm/i915/gt/selftest_tlb.c +2
-3@@ -36,8 +36,6 @@ pte_tlbinv(struct intel_context *ce, u64 length, struct rnd_state *prng) { - const unsigned int pat_index = - i915_gem_get_pat_index(ce->vm->i915, I915_CACHE_NONE); struct drm_i915_gem_object *batch; struct drm_mm_node vb_node; struct i915_request *rq;@@ -157,7 +155,8 @@ pte_tlbinv(struct intel_context *ce, /* Flip the PTE between A and B */ if (i915_gem_object_is_lmem(vb->obj)) pte_flags |= PTE_LM; - ce->vm->insert_entries(ce->vm, &vb_res, pat_index, pte_flags); + ce->vm->insert_entries(ce->vm, &vb_res, ce->vm->i915->pat_uc, + pte_flags); /* Flush the PTE update to concurrent HW */ tlbinv(ce->vm, addr & -length, length);drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +2
-6@@ -991,14 +991,10 @@ static void uc_fw_bind_ggtt(struct intel_uc_fw *uc_fw) if (ggtt->vm.raw_insert_entries) ggtt->vm.raw_insert_entries(&ggtt->vm, vma_res, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - pte_flags); + ggtt->vm.i915->pat_uc, pte_flags); else ggtt->vm.insert_entries(&ggtt->vm, vma_res, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - pte_flags); + ggtt->vm.i915->pat_uc, pte_flags); }static void uc_fw_unbind_ggtt (struct intel_uc_fw *uc_fw)drivers/gpu/drm/i915/i915_cache.c new file +25
-0@@ -0,0 +1,59 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2023 Intel Corporation +*/ + +#include "i915_cache.h" +#include "i915_drv.h" + +static int find_pat (const struct intel_device_info *info,i915_cache_t mode) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(info->cache_modes); i++) { + if (info->cache_modes[i] == mode) + return i; + } + + return -1; +} + +void i915_cache_init (struct drm_i915_private *i915) +{ + int ret; +
drivers/gpu/drm/i915/i915_cache.c line 35
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.c new file +10
-0+ ret = find_pat(INTEL_INFO(i915), I915_CACHE(UC)); + WARN_ON(ret < 0); + drm_info(&i915->drm, "Using PAT index %u for uncached access\n", ret); + i915->pat_uc = ret; + + ret = find_pat(INTEL_INFO(i915), I915_CACHE(WB)); + WARN_ON(ret < 0); + drm_info(&i915->drm, "Using PAT index %u for write-back access\n", ret); + i915->pat_wb = ret; +}
I don't think we need the above two functions. Why don't we just hard code pat_uc and pat_wb in device_info? plus pat_wt too? These are predetermined, and used by KMD only.
Quoted 50 lines
drivers/gpu/drm/i915/i915_cache.c new file +23
-0+int i915_cache_level_to_pat_and_mode (struct drm_i915_private *i915, + unsigned int cache_level, + i915_cache_t *mode) +{ + const struct intel_device_info *info = INTEL_INFO(i915); + i915_cache_t level_to_mode[] = { + [I915_CACHE_NONE] = I915_CACHE(UC), + [I915_CACHE_WT] = I915_CACHE(WT), + [I915_CACHE_LLC] = I915_CACHE(WB), + }; + int ret; + + if (GRAPHICS_VER(i915) >= 12) + level_to_mode[I915_CACHE_L3_LLC] = I915_CACHE(WB); + else + level_to_mode[I915_CACHE_L3_LLC] = _I915_CACHE(WB, LLC); + + ret = find_pat(info, level_to_mode[cache_level]); + if (ret >= 0 && mode) + *mode = info->cache_modes[ret]; + + return ret; +}drivers/gpu/drm/i915/i915_cache.h new file +21
-0@@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef __I915_CACHE_H__ +#define __I915_CACHE_H__ + +#include <linux/types.h> + +struct drm_i915_private ; + +typedef u16 i915_cache_t ; + +#define I915_CACHE (mode) \ + (i915_cache_t)(I915_CACHE_MODE_##mode) + +#define _I915_CACHE (mode, flag) \ + (i915_cache_t)((I915_CACHE_MODE_##mode) | ( BIT(8 + I915_CACHE_##flag))) + +#define I915_CACHE_MODE (cache) \
drivers/gpu/drm/i915/i915_cache.h line 31
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h new file +10
-0+ (unsigned int)(((i915_cache_t)(cache)) & 0xff) +#define I915_CACHE_FLAGS (cache) \ + (unsigned int)((((i915_cache_t)(cache) & 0xff00)) >> 16) + +/* Cache mode values */ +#define I915_CACHE_MODE_UNKNOWN (0) +#define I915_CACHE_MODE_UC (1) +#define I915_CACHE_MODE_WB (2) +#define I915_CACHE_MODE_WT (3) +#define I915_CACHE_MODE_WC (4)
Why do you need these CACHE_MODE's? Aren't they the same as i915_cache_level, which need some sort of translation?
drivers/gpu/drm/i915/i915_cache.h line 38
Quoted 7 lines
drivers/gpu/drm/i915/i915_cache.h new file +7
-0+ +/* Mode flag bits */ +#define I915_CACHE_L3 (0) +#define I915_CACHE_COH1W (1) +#define I915_CACHE_COH2W (2) +#define I915_CACHE_CLOS1 (3) +#define I915_CACHE_CLOS2 (4)
These had been defined in drivers/gpu/drm/i915/gt/intel_gtt.h already, why add new ones? The CLOS ones are not needed in upstream unless we want to support PVC here.
Quoted 12 lines
drivers/gpu/drm/i915/i915_cache.h new file +12
-0+ +void i915_cache_init (struct drm_i915_private *i915); +int i915_cache_level_to_pat_and_mode (struct drm_i915_private *i915, + unsigned int cache_level, + i915_cache_t *mode); + +/* +* Legacy/kernel internal interface below: +*/ + +/** +* enum i915_cache_level - The supported GTT caching values for system memory
drivers/gpu/drm/i915/i915_cache.h line 60
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h new file +10
-0+* pages. +* +* These translate to some special GTT PTE bits when binding pages into some +* address space. It also determines whether an object, or rather its pages are +* coherent with the GPU, when also reading or writing through the CPU cache +* with those pages. +* +* Userspace can also control this through struct drm_i915_gem_caching. +*/ +enum i915_cache_level {
Shouldn't we completely get rid of this enum now? It should be replaced by INTEL_INFO(i915)->pat_uc/wb/wt.
Quoted 205 lines
drivers/gpu/drm/i915/i915_cache.h new file +69
-0+ /** + * @I915_CACHE_NONE: + * + * GPU access is not coherent with the CPU cache. If the cache is dirty + * and we need the underlying pages to be coherent with some later GPU + * access then we need to manually flush the pages. + * + * On shared LLC platforms reads and writes through the CPU cache are + * still coherent even with this setting. See also + * &drm_i915_gem_object.cache_coherent for more details. Due to this we + * should only ever use uncached for scanout surfaces, otherwise we end + * up over-flushing in some places. + * + * This is the default on non-LLC platforms. + */ + I915_CACHE_NONE = 0, + /** + * @I915_CACHE_LLC: + * + * GPU access is coherent with the CPU cache. If the cache is dirty, + * then the GPU will ensure that access remains coherent, when both + * reading and writing through the CPU cache. GPU writes can dirty the + * CPU cache. + * + * Not used for scanout surfaces. + * + * Applies to both platforms with shared LLC(HAS_LLC), and snooping + * based platforms(HAS_SNOOP). + * + * This is the default on shared LLC platforms. The only exception is + * scanout objects, where the display engine is not coherent with the + * CPU cache. For such objects I915_CACHE_NONE or I915_CACHE_WT is + * automatically applied by the kernel in pin_for_display, if userspace + * has not done so already. + */ + I915_CACHE_LLC, + /** + * @I915_CACHE_L3_LLC: + * + * Explicitly enable the Gfx L3 cache, with coherent LLC. + * + * The Gfx L3 sits between the domain specific caches, e.g + * sampler/render caches, and the larger LLC. LLC is coherent with the + * GPU, but L3 is only visible to the GPU, so likely needs to be flushed + * when the workload completes. + * + * Not used for scanout surfaces. + * + * Only exposed on some gen7 + GGTT. More recent hardware has dropped + * this explicit setting, where it should now be enabled by default. + */ + I915_CACHE_L3_LLC, + /** + * @I915_CACHE_WT: + * + * Write-through. Used for scanout surfaces. + * + * The GPU can utilise the caches, while still having the display engine + * be coherent with GPU writes, as a result we don't need to flush the + * CPU caches when moving out of the render domain. This is the default + * setting chosen by the kernel, if supported by the HW, otherwise we + * fallback to I915_CACHE_NONE. On the CPU side writes through the CPU + * cache still need to be flushed, to remain coherent with the display + * engine. + */ + I915_CACHE_WT, +}; + +#endif /* __I915_CACHE_H__ */ drivers/gpu/drm/i915/i915_debugfs.c +39
-44@@ -139,48 +139,37 @@ static const char *stringify_vma_type(const struct i915_vma *vma) return "ppgtt"; } -static const char *i915_cache_level_str (struct drm_i915_gem_object *obj) +static void obj_cache_str (struct seq_file *m,struct drm_i915_gem_object *obj) { - struct drm_i915_private *i915 = obj_to_i915(obj); + const i915_cache_t cache = obj->cache_mode; + const unsigned int mode = I915_CACHE_MODE(cache); + const unsigned long flags = I915_CACHE_FLAGS(cache); + static const char *mode_str[] = { + [I915_CACHE_MODE_UC] = "UC", + [I915_CACHE_MODE_WB] = "WB", + [I915_CACHE_MODE_WT] = "WT", + [I915_CACHE_MODE_WC] = "WC", + }; + static const char *flag_str[] = { + [I915_CACHE_L3] = "L3", + [I915_CACHE_COH1W] = "1-Way-Coherent", + [I915_CACHE_COH2W] = "2-Way-Coherent", + [I915_CACHE_CLOS1] = "CLOS1", + [I915_CACHE_CLOS2] = "CLOS2", + }; - if (IS_METEORLAKE(i915)) { - switch (obj->pat_index) { - case 0: return " WB"; - case 1: return " WT"; - case 2: return " UC"; - case 3: return " WB (1-Way Coh)"; - case 4: return " WB (2-Way Coh)"; - default: return " not defined"; - } - } else if (IS_PONTEVECCHIO(i915)) { - switch (obj->pat_index) { - case 0: return " UC"; - case 1: return " WC"; - case 2: return " WT"; - case 3: return " WB"; - case 4: return " WT (CLOS1)"; - case 5: return " WB (CLOS1)"; - case 6: return " WT (CLOS2)"; - case 7: return " WT (CLOS2)"; - default: return " not defined"; - } - } else if (GRAPHICS_VER(i915) >= 12) { - switch (obj->pat_index) { - case 0: return " WB"; - case 1: return " WC"; - case 2: return " WT"; - case 3: return " UC"; - default: return " not defined"; - } + if (mode == I915_CACHE_MODE_UNKNOWN || mode > ARRAY_SIZE(mode_str)) { + if (obj->pat_set_by_user) + seq_printf(m, " PAT-%u", obj->pat_index); + else + seq_printf(m, " PAT-%u-???", obj->pat_index); } else { - switch (obj->pat_index) { - case 0: return " UC"; - case 1: return HAS_LLC(i915) ? - " LLC" : " snooped"; - case 2: return " L3+LLC"; - case 3: return " WT"; - default: return " not defined"; - } + unsigned long bit; + + seq_printf(m, " %s", mode_str[mode]); + + for_each_set_bit(bit, &flags, sizeof(i915_cache_t)) + seq_printf(m, "-%s", flag_str[bit]); } }@@ -190,17 +179,23 @@ i915_debugfs_describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) struct i915_vma *vma; int pin_count = 0; - seq_printf(m, "%pK: %c%c%c %8zdKiB %02x %02x %s%s%s", + seq_printf(m, "%pK: %c%c%c %8zdKiB %02x %02x", &obj->base, get_tiling_flag(obj), get_global_flag(obj), get_pin_mapped_flag(obj), obj->base.size / 1024, obj->read_domains, - obj->write_domain, - i915_cache_level_str(obj), - obj->mm.dirty ? " dirty" : "", - obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : ""); + obj->write_domain); + + obj_cache_str(m, obj); + + if (obj->mm.dirty) + seq_puts(m, " dirty"); + + if (obj->mm.madv == I915_MADV_DONTNEED) + seq_puts(m, " purgeable"); + if (obj->base.name) seq_printf(m, " (name: %d)", obj->base.name);drivers/gpu/drm/i915/i915_driver.c +3
-0@@ -80,6 +80,7 @@#include "soc/intel_dram.h" #include "soc/intel_gmch.h" +#include "i915_cache.h" #include "i915_debugfs.h" #include "i915_driver.h" #include "i915_drm_client.h" @@ -267,6 +268,8 @@ static int i915_driver_early_probe(struct drm_i915_private *dev_priv) intel_detect_preproduction_hw(dev_priv); + i915_cache_init(dev_priv); + return 0; err_rootgt:drivers/gpu/drm/i915/i915_drv.h +0
-0
drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 255
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +2
-0@@ -251,6 +251,9 @@ struct drm_i915_private { unsigned int hpll_freq; unsigned int czclk_freq; + unsigned int pat_uc; + unsigned int pat_wb;
How about making these part of INTEL_INFO(i915)? They are predetermined, no need to be dynamic.
Quoted 85 lines
drivers/gpu/drm/i915/i915_drv.h +1
-0+ /*** wq - Driver workqueue for GEM. * drivers/gpu/drm/i915/i915_gem.c +2
-19@@ -422,9 +422,7 @@ i915_gem_gtt_pread(struct drm_i915_gem_object *obj, ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj, offset >> PAGE_SHIFT), - node.start, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), 0); + node.start, i915->pat_uc, 0); } else { page_base += offset & PAGE_MASK; }@@ -603,9 +601,7 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_gem_object *obj, ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj, offset >> PAGE_SHIFT), - node.start, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), 0); + node.start, i915->pat_uc, 0); wmb(); /* flush modifications to the GGTT (insert_page) */ } else { page_base += offset & PAGE_MASK;@@ -1148,19 +1144,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv) unsigned int i; int ret; - /* - * In the proccess of replacing cache_level with pat_index a tricky - * dependency is created on the definition of the enum i915_cache_level. - * in case this enum is changed, PTE encode would be broken. - * Add a WARNING here. And remove when we completely quit using this - * enum - */ - BUILD_BUG_ON(I915_CACHE_NONE != 0 || - I915_CACHE_LLC != 1 || - I915_CACHE_L3_LLC != 2 || - I915_CACHE_WT != 3 || - I915_MAX_CACHE_LEVEL != 4); - /* We need to fallback to 4K pages if host doesn't support huge gtt. */ if (intel_vgpu_active(dev_priv) && !intel_vgpu_has_huge_gtt(dev_priv)) RUNTIME_INFO(dev_priv)->page_sizes = I915_GTT_PAGE_SIZE_4K;drivers/gpu/drm/i915/i915_gpu_error.c +2
-5@@ -1122,14 +1122,11 @@ i915_vma_coredump_create(const struct intel_gt *gt, mutex_lock(&ggtt->error_mutex); if (ggtt->vm.raw_insert_page) ggtt->vm.raw_insert_page(&ggtt->vm, dma, slot, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + ggtt->vm.i915->pat_uc, 0); else ggtt->vm.insert_page(&ggtt->vm, dma, slot, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), - 0); + ggtt->vm.i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap, slot, PAGE_SIZE);drivers/gpu/drm/i915/i915_pci.c +1
-0@@ -32,6 +32,7 @@#include "gt/intel_sa_media.h" #include "gem/i915_gem_object_types.h" +#include "i915_cache.h" #include "i915_driver.h" #include "i915_drv.h" #include "i915_pci.h" @@ -46,36 +47,42 @@ __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); .__runtime.graphics.ip.ver = (x), \
drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); · line 51
Quoted 10 lines
drivers/gpu/drm/i915/i915_pci.c +2
-6.__runtime.media.ip.ver = (x) -#define LEGACY_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 0, \ - [I915_CACHE_LLC] = 1, \ - [I915_CACHE_L3_LLC] = 2, \ - [I915_CACHE_WT] = 3, \ +/* TODO/QQQ index 1 & 2 */ +#define LEGACY_CACHE_MODES \
I was thinking to just put the PAT settings here, instead of cache_modes, simply .pat = {\
GEN8_PPAT_WB, \
GEN8_PPAT_WC, \
GEN8_PPAT_WT, \
GEN8_PPAT_UC,
}
Quoted 28 lines
drivers/gpu/drm/i915/i915_pci.c +12
-12+ .cache_modes = { \ + [0] = I915_CACHE(UC), \ + [1] = I915_CACHE(WB), \ + [2] = _I915_CACHE(WB, L3), \ + [3] = I915_CACHE(WT), \ } -#define TGL_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 3, \ - [I915_CACHE_LLC] = 0, \ - [I915_CACHE_L3_LLC] = 0, \ - [I915_CACHE_WT] = 2, \ +#define GEN12_CACHE_MODES \ + .cache_modes = { \ + [0] = I915_CACHE(WB), \ + [1] = I915_CACHE(WC), \ + [2] = I915_CACHE(WT), \ + [3] = I915_CACHE(UC), \ } -#define PVC_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 0, \ - [I915_CACHE_LLC] = 3, \ - [I915_CACHE_L3_LLC] = 3, \ - [I915_CACHE_WT] = 2, \ +#define PVC_CACHE_MODES \
drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); · line 77
Quoted 10 lines
drivers/gpu/drm/i915/i915_pci.c +9
-0+ .cache_modes = { \ + [0] = I915_CACHE(UC), \ + [1] = I915_CACHE(WC), \ + [2] = I915_CACHE(WT), \ + [3] = I915_CACHE(WB), \ + [4] = _I915_CACHE(WT, CLOS1), \ + [5] = _I915_CACHE(WB, CLOS1), \ + [6] = _I915_CACHE(WT, CLOS2), \ + [7] = _I915_CACHE(WB, CLOS2), \ }
.pat = {\
GEN8_PPAT_UC, \
GEN8_PPAT_WC, \
GEN8_PPAT_WT, \
GEN8_PPAT_WB, \
GEN12_PPAT_CLOS(1) | GEN8_PPAT_WT, \ GEN12_PPAT_CLOS(1) | GEN8_PPAT_WB, \ GEN12_PPAT_CLOS(2) | GEN8_PPAT_WT, \ GEN12_PPAT_CLOS(2) | GEN8_PPAT_WB, \
}
Quoted 5 lines
drivers/gpu/drm/i915/i915_pci.c +0
-4-#define MTL_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 2, \ - [I915_CACHE_LLC] = 3, \
drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); · line 86
Quoted 10 lines
drivers/gpu/drm/i915/i915_pci.c +7
-2- [I915_CACHE_L3_LLC] = 3, \ - [I915_CACHE_WT] = 1, \ +#define MTL_CACHE_MODES \ + .cache_modes = { \ + [0] = I915_CACHE(WB), \ + [1] = I915_CACHE(WT), \ + [2] = I915_CACHE(UC), \ + [3] = _I915_CACHE(WB, COH1W), \ + [4] = _I915_CACHE(WB, COH2W), \ }
.pat = {\
MTL_PPAT_L4_0_WB, \
MTL_PPAT_L4_1_WT, \
MTL_PPAT_L4_3_UC, \
MTL_PPAT_L4_0_WB | MTL_2_COH_1W, \
MTL_PPAT_L4_0_WB | MTL_3_COH_2W, \
}
Quoted 141 lines
drivers/gpu/drm/i915/i915_pci.c +14
-14/* Keep in gen based order, and chronological order within a gen */ @@ -100,7 +107,7 @@ __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES#define I845_FEATURES \ GEN(2), \@@ -115,7 +122,7 @@ __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info i830_info = { I830_FEATURES,@@ -148,7 +155,7 @@ static const struct intel_device_info i865g_info = { .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info i915g_info = { GEN3_FEATURES,@@ -211,7 +218,7 @@ static const struct intel_device_info pnv_m_info = { .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info i965g_info = { GEN4_FEATURES,@@ -255,7 +262,7 @@ static const struct intel_device_info gm45_info = { .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info ilk_d_info = { GEN5_FEATURES,@@ -285,7 +292,7 @@ static const struct intel_device_info ilk_m_info = { .__runtime.ppgtt_size = 31, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES#define SNB_D_PLATFORM \ GEN6_FEATURES, \@@ -333,7 +340,7 @@ static const struct intel_device_info snb_m_gt2_info = { .__runtime.ppgtt_size = 31, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES#define IVB_D_PLATFORM \ GEN7_FEATURES, \@@ -390,7 +397,7 @@ static const struct intel_device_info vlv_info = { .__runtime.platform_engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), GEN_DEFAULT_PAGE_SIZES, GEN_DEFAULT_REGIONS, - LEGACY_CACHELEVEL, + LEGACY_CACHE_MODES };#define G75_FEATURES \@@ -476,7 +483,7 @@ static const struct intel_device_info chv_info = { .has_coherent_ggtt = false, GEN_DEFAULT_PAGE_SIZES, GEN_DEFAULT_REGIONS, - LEGACY_CACHELEVEL, + LEGACY_CACHE_MODES };#define GEN9_DEFAULT_PAGE_SIZES \@@ -539,7 +546,7 @@ static const struct intel_device_info skl_gt4_info = { .max_pat_index = 3, \ GEN9_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info bxt_info = { GEN9_LP_FEATURES,@@ -643,7 +650,7 @@ static const struct intel_device_info jsl_info = {#define GEN12_FEATURES \ GEN11_FEATURES, \ GEN(12), \ - TGL_CACHELEVEL, \ + GEN12_CACHE_MODES, \ .has_global_mocs = 1, \ .has_pxp = 1, \ .max_pat_index = 3@@ -711,7 +718,7 @@ static const struct intel_device_info adl_p_info = { .__runtime.graphics.ip.ver = 12, \ .__runtime.graphics.ip.rel = 50, \ XE_HP_PAGE_SIZES, \ - TGL_CACHELEVEL, \ + GEN12_CACHE_MODES, \ .dma_mask_size = 46, \ .has_3d_pipeline = 1, \ .has_64bit_reloc = 1, \@@ -806,7 +813,7 @@ static const struct intel_device_info pvc_info = { BIT(VCS0) | BIT(CCS0) | BIT(CCS1) | BIT(CCS2) | BIT(CCS3), .require_force_probe = 1, - PVC_CACHELEVEL, + PVC_CACHE_MODES };static const struct intel_gt_definition xelpmp_extra_gt[] = {@@ -841,7 +848,7 @@ static const struct intel_device_info mtl_info = { .__runtime.memory_regions = REGION_SMEM | REGION_STOLEN_LMEM, .__runtime.platform_engine_mask = BIT(RCS0) | BIT(BCS0) | BIT(CCS0), .require_force_probe = 1, - MTL_CACHELEVEL, + MTL_CACHE_MODES };#undef PLATFORMdrivers/gpu/drm/i915/intel_device_info.h +2
-0@@ -27,6 +27,8 @@#include <uapi/drm/i915_drm.h> +#include "i915_cache.h" +#include "intel_step.h" #include "display/intel_display_device.h"
drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 253
Quoted 6 lines
drivers/gpu/drm/i915/intel_device_info.h +1
-2@@ -248,8 +250,8 @@ struct intel_device_info {*/ const struct intel_runtime_info __runtime; - u32 cachelevel_to_pat[I915_MAX_CACHE_LEVEL]; - u32 max_pat_index; + i915_cache_t cache_modes[9];
u32 pat[16];
See https://gfxspecs.intel.com/Predator/Home/Index/63019, there are PAT[3..0]
-Fei
Quoted 125 lines
drivers/gpu/drm/i915/intel_device_info.h +1
-0+ unsigned int max_pat_index; };struct intel_driver_caps {drivers/gpu/drm/i915/selftests/i915_gem.c +1
-4@@ -57,10 +57,7 @@ static void trash_stolen(struct drm_i915_private *i915) u32 __iomem *s; int x; - ggtt->vm.insert_page(&ggtt->vm, dma, slot, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, dma, slot, i915->pat_uc, 0); s = io_mapping_map_atomic_wc(&ggtt->iomap, slot); for (x = 0; x < PAGE_SIZE / sizeof(u32); x++) {drivers/gpu/drm/i915/selftests/i915_gem_evict.c +2
-2@@ -246,7 +246,7 @@ static int igt_evict_for_cache_color(void *arg) struct drm_mm_node target = { .start = I915_GTT_PAGE_SIZE * 2, .size = I915_GTT_PAGE_SIZE, - .color = i915_gem_get_pat_index(gt->i915, I915_CACHE_LLC), + .color = I915_CACHE(WB), }; struct drm_i915_gem_object *obj; struct i915_vma *vma;@@ -309,7 +309,7 @@ static int igt_evict_for_cache_color(void *arg) /* Attempt to remove the first *pinned* vma, by removing the (empty) * neighbour -- this should fail. */ - target.color = i915_gem_get_pat_index(gt->i915, I915_CACHE_L3_LLC); + target.color = _I915_CACHE(WB, LLC); mutex_lock(&ggtt->vm.mutex); err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +4
-9@@ -135,7 +135,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size) obj->write_domain = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU; - obj->pat_index = i915_gem_get_pat_index(i915, I915_CACHE_NONE); + obj->pat_index = i915->pat_uc; /* Preallocate the "backing storage" */ if (i915_gem_object_pin_pages_unlocked(obj))@@ -358,10 +358,8 @@ static int lowlevel_hole(struct i915_address_space *vm, mock_vma_res->start = addr; with_intel_runtime_pm(vm->gt->uncore->rpm, wakeref) - vm->insert_entries(vm, mock_vma_res, - i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), - 0); + vm->insert_entries(vm, mock_vma_res, + vm->i915->pat_uc, 0); } count = n;@@ -1379,10 +1377,7 @@ static int igt_ggtt_page(void *arg) ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj, 0), - offset, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), - 0); + offset, ggtt->vm.i915->pat_uc, 0); } order = i915_random_order(count, &prng);drivers/gpu/drm/i915/selftests/intel_memory_region.c +1
-3@@ -1070,9 +1070,7 @@ static int igt_lmem_write_cpu(void *arg) /* Put the pages into a known state -- from the gpu for added fun */ intel_engine_pm_get(engine); err = intel_context_migrate_clear(engine->gt->migrate.context, NULL, - obj->mm.pages->sgl, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), + obj->mm.pages->sgl, i915->pat_uc, true, 0xdeadbeaf, &rq); if (rq) { dma_resv_add_fence(obj->base.resv, &rq->fence,drivers/gpu/drm/i915/selftests/mock_gem_device.c +7
-4@@ -126,7 +126,12 @@ struct drm_i915_private *mock_gem_device(void) struct drm_i915_private *i915; struct intel_device_info *i915_info; struct pci_dev *pdev; - unsigned int i; + static const i915_cache_t legacy_cache_modes[] = { + [0] = I915_CACHE(UC), + [1] = I915_CACHE(WB), + [2] = _I915_CACHE(WB, L3), + [3] = I915_CACHE(WT), + }; int ret; pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);@@ -187,8 +192,7 @@ struct drm_i915_private *mock_gem_device(void) /* simply use legacy cache level for mock device */ i915_info = (struct intel_device_info *)INTEL_INFO(i915); i915_info->max_pat_index = 3; - for (i = 0; i < I915_MAX_CACHE_LEVEL; i++) - i915_info->cachelevel_to_pat[i] = i; + memcpy(i915_info->cache_modes, legacy_cache_modes, sizeof(legacy_cache_modes)); intel_memory_regions_hw_probe(i915); --2.39.2
Quoted 9 lines · Fei
Quoted 7 lines
From: Tvrtko Ursulin <[email protected]>
Informal commit message for now.
I got a bit impatient and curious to see if the idea we discussed would work so sketched something out. I think it is what I was describing back then..
Oops, you beat me on this, shame on me.
Not at all, thanks for a detailed look into my attempt!
You were right with most of the observations and I think I've done most of them and now it even passes BAT (trybot).
Because I rushed the v1 to sketch out the idea, indeed the double caching abstraction and obj->cache_mode made no sense. It's all ripped out now.
Only thing I disagree with is to use hardware bits in the lookup table. Maybe in a different table, one which could be used for PAT index to hw bits lookup in the PTE encode functions. But for the higher level in the driver I need the abstracted view so driver can understand the modes and ask questions about them.
Let me go through the individual comments below to see if there is something more to cover.
Quoted 104 lines
Quoted 58 lines
So high level idea is to teach the driver what caching modes are hidden behind PAT indices. Given you already had that in static tables, if we just turn the tables a bit around and add a driver abstraction of caching modes this is what happens:
* We can lose the ugly runtime
i915_gem_get_pat_index.* We can have a smarter
i915_gem_object_has_cache_level, which now can use the above mentioned table to understand the caching modes and so does not have to pessimistically return true for _any_ input when user has set the PAT index. This may improve things even for MTL.* We can simplify the debugfs printout to be platform agnostic.
* We are perhaps opening the door to un-regress the dodgy addition made to
i915_gem_object_can_bypass_llc? See QQQ/FIXME in the patch.I hope I did not forget anything, but anyway, please have a read and see what you think. I think it has potential.
Proper commit message can come later.
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Fei Yang <[email protected]>---
drivers/gpu/drm/i915/Makefile | 1 +drivers/gpu/drm/i915/gem/i915_gem_domain.c| 34 ++---.../gpu/drm/i915/gem/i915_gem_execbuffer.c| 13 +-drivers/gpu/drm/i915/gem/i915_gem_mman.c| 10 +-drivers/gpu/drm/i915/gem/i915_gem_object.c| 78 ++++-------drivers/gpu/drm/i915/gem/i915_gem_object.h| 18 ++-.../gpu/drm/i915/gem/i915_gem_object_types.h| 99 +-------------drivers/gpu/drm/i915/gem/i915_gem_stolen.c| 7 +-drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c| 26 ++--.../gpu/drm/i915/gem/selftests/huge_pages.c| 2 +-drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 4 +- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 13 +- drivers/gpu/drm/i915/gt/intel_ggtt.c | 9 +-drivers/gpu/drm/i915/gt/intel_migrate.c | 11 +-
drivers/gpu/drm/i915/gt/selftest_migrate.c| 9 +-drivers/gpu/drm/i915/gt/selftest_reset.c| 14 +-drivers/gpu/drm/i915/gt/selftest_timeline.c| 5 +-drivers/gpu/drm/i915/gt/selftest_tlb.c| 5 +-drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c| 8 +-drivers/gpu/drm/i915/i915_cache.c| 59 ++++++++drivers/gpu/drm/i915/i915_cache.h| 129 ++++++++++++++++++drivers/gpu/drm/i915/i915_debugfs.c| 83 ++++++-----drivers/gpu/drm/i915/i915_driver.c| 3 +drivers/gpu/drm/i915/i915_drv.h| 3 +drivers/gpu/drm/i915/i915_gem.c| 21 +--drivers/gpu/drm/i915/i915_gpu_error.c| 7 +-drivers/gpu/drm/i915/i915_pci.c| 83 +++++------drivers/gpu/drm/i915/intel_device_info.h| 6 +-drivers/gpu/drm/i915/selftests/i915_gem.c| 5 +-.../gpu/drm/i915/selftests/i915_gem_evict.c| 4 +-drivers/gpu/drm/i915/selftests/i915_gem_gtt.c| 13 +-.../drm/i915/selftests/intel_memory_region.c| 4 +-.../gpu/drm/i915/selftests/mock_gem_device.c| 10 +-Review
Quoted 5 lines
33 files changed, 415 insertions(+), 381 deletions(-)create mode 100644
drivers/gpu/drm/i915/i915_cache.ccreate mode 100644drivers/gpu/drm/i915/i915_cache.h(quoted diff) +0
-0b/drivers/gpu/drm/i915/Makefile
Review
Quoted 12 lines
index
2be9dd960540..2c3da8f0c78e100644drivers/gpu/drm/i915/Makefile +1
-0@@ -30,6 +30,7 @@ subdir-ccflags-y += -I$(srctree)/$(src) # core driver code i915-y += i915_driver.o \ i915_drm_client.o \ + i915_cache.o \ i915_config.o \ i915_getparam.o \ i915_ioctl.o \(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_domain.cdrivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct
Quoted 12 lines
index
dfaaa8b66ac3..49bfae45390f100644drivers/gpu/drm/i915/gem/i915_gem_domain.c +1
-0@@ -8,6 +8,7 @@ #include "display/intel_frontbuffer.h" #include "gt/intel_gt.h" +#include "i915_cache.h" #include "i915_drv.h" #include "i915_gem_clflush.h" #include "i915_gem_domain.h"@@ -27,15 +28,8 @@ static bool gpu_write_needs_clflush(struct
drm_i915_gem_object*obj)drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0
-4if (IS_DGFX(i915)) return false; - /* -* For objects created by userspace through GEM_CREATE with pat_index -* set by set_pat extension, i915_gem_object_has_cache_level() will -* always return true, because the coherency of such object is managed
drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1
-5-* by userspace. Othereise the call here would fall back to checking -* whether the object is un-cached or write-through. -*/ - return !(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) || - i915_gem_object_has_cache_level(obj, I915_CACHE_WT)); + return i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_UC) !=
Quoted 5 lines
1 &&
drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj) · line 32
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1
-0+ i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WT) != 1;Why is it necessary to define I915_CACHE_MODE's while there is already
i915_cache_level? I thought we wanted to get rid of such abstractions instead of adding more.
Indeed. Dropped.
Quoted 12 lines
This patch also introduced INTEL_INFO(i915)->cache_modes, why don't we directly add the platform specific PAT there? For example, add the following for MTL,
INTEL_INFO(i915)->pat[] = {
[0] =MTL_PPAT_L4_0_WB, \
[1] =MTL_PPAT_L4_1_WT, \
[2] =MTL_PPAT_L4_3_UC, \
[3] =MTL_PPAT_L4_0_WB|MTL_2_COH_1W, \
[4] =MTL_PPAT_L4_0_WB|MTL_3_COH_2W, \
}
Quoted 4 lines
Everything here has already been defined, no need to introduce new macros.
This can also be used to initialize the PAT index registers, like in
xelpg_setup_private_ppat()andxelpmp_setup_private_ppat().
As exaplained above, I think a 2nd table could be used for this.
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0
-0} bool i915_gem_cpu_write_needs_clflush(struct drm_i915_gem_object *obj)@@ -272,15 +266,18 @@ i915_gem_object_set_to_gtt_domain(struct
drm_i915_gem_object*obj, bool write)
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 267
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0
-0int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, enum i915_cache_level cache_level)s/enum
i915_cache_levelcache_level/unsigned intpat_indexThis function is for KMD objects only, I don't think we even need to keep the
i915_cache_level, simply passing in INTEL_INFO(i915)->pat_uc/wb/wt is good enough.
Yep, it works on the new i915_cache_t in v2.
Quoted 15 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-0{ + struct drm_i915_private *i915 = to_i915(obj->base.dev); + i915_cache_t mode; int ret;drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 274
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-7- /* - * For objects created by userspace through GEM_CREATE with pat_index - * set by set_pat extension, simply return 0 here without touching - * the cache setting, because such objects should have an immutable - * cache setting by desgin and always managed by userspace. - */ - if (i915_gem_object_has_cache_level(obj, cache_level)) + if (obj->pat_set_by_user) + return -EINVAL;
Quoted 1 line
I don't think this condition would ever be true, but okay to keep it.
Could be that I got confused. Or it would be best to add a drm_err or drm_WARN_ON_ONCE just to guard against any surprises.
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) · line 280
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5
-0+ ret = i915_cache_level_to_pat_and_mode(i915, cache_level, &mode); + if (ret < 0) + return -EINVAL; + + if (mode == obj->cache_mode)The above lines can be just one line,
if (pat_index==obj->pat_index)
Yep done.
Quoted 102 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0
-0return 0; ret = i915_gem_object_wait(obj,@@ -326,10 +323,9 @@ int i915_gem_get_caching_ioctl(struct drm_device*dev, void *data,
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2
-3goto out; } - if (i915_gem_object_has_cache_level(obj, I915_CACHE_LLC) || - i915_gem_object_has_cache_level(obj, I915_CACHE_L3_LLC)) + if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WB)) args->caching = I915_CACHING_CACHED; - else if (i915_gem_object_has_cache_level(obj, I915_CACHE_WT)) + else if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WT)) args->caching = I915_CACHING_DISPLAY;else
args->caching =I915_CACHING_NONE;Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.cdrivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static inline int use_cpu_reloc(const struct
Quoted 4 lines
index
d3208a325614..ee85221fa6eb100644drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0
-0@@ -640,15 +640,9 @@ static inline int use_cpu_reloc(const struct
reloc_cache*cache,drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static inline int use_cpu_reloc(const struct reloc_cache *cache,
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0
-4if (DBG_FORCE_RELOC == FORCE_GTT_RELOC) return false; - /* -* For objects created by userspace through GEM_CREATE with pat_index -* set by set_pat extension, i915_gem_object_has_cache_level() always -* return true, otherwise the call would fall back to checking whether
Review
Quoted 22 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0
-2-* the object is un-cached. -*/ return (
cache->has_llc||
obj->cache_dirty ||
- !i915_gem_object_has_cache_level(obj,I915_CACHE_NONE)); + i915_gem_object_has_cache_mode(obj,I915_CACHE_MODE_UC) != 1); }static int eb_reserve_vma(struct
i915_execbuffer*eb,drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-4@@ -1329,10 +1323,7 @@ static void *reloc_iomap(struct i915_vma *batch, if (drm_mm_node_allocated(&cache->node)) { ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj, page), - offset, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - 0); + offset, eb->i915->pat_uc, 0); } else { offset += page << PAGE_SHIFT; }(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_mman.cdrivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault
Quoted 4 lines
index
aa4d842d4c5a..5e21aedb02d2100644drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -386,13 +386,11 @@ static vm_fault_t vm_fault_gtt(struct vm_fault*vmf)
drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-2/** For objects created by userspace through GEM_CREATE with pat_index * set by set_pat extension, coherency is managed by userspace, make -* sure we don't fail handling the vm fault by calling -* i915_gem_object_has_cache_level() which always return true for such
drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault · line 391
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-1- * objects. Otherwise this helper function would fall back tochecking
Review
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +4
-3-* whether the object is un-cached. +* sure we don't fail handling the vm fault by making sure that we +* know the object is uncached or that we have LLC. */ - if (!(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) || - HAS_LLC(i915))) { + if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_UC) != 1 && + !HAS_LLC(i915)) { ret = -EFAULT; goto err_unpin; }(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_object.cQuoted 5 lines
index
0004d5fa7cc2..52c6c5f09bdd100644drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-0@@ -45,33 +45,6 @@ static struct kmem_cache *slab_objects;drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects; · line 55
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-8static const struct drm_gem_object_funcs i915_gem_object_funcs; -unsigned int i915_gem_get_pat_index (struct drm_i915_private *i915, - enum i915_cache_level level) -{ - if (drm_WARN_ON(&i915->drm, level >= I915_MAX_CACHE_LEVEL)) - return 0; - - return INTEL_INFO(i915)->cachelevel_to_pat[level]; -}Yes, this can be removed. INTEL_INFO(i915)->pat_uc/wb/wt should be sufficient,
drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects; · line 57
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-2- -bool i915_gem_object_has_cache_level(const struct
drm_i915_gem_object*obj,
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects; · line 59
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-2- enum i915_cache_level lvl) -{If we had INTEL_INFO(i915)->pat[] setup, it would be easier just to keep this function, because we can simply check the cache policy bit field in INTEL_INFO(i915)->pat[obj->pat_index] to see whether it is cached, uncached, or write-through.
Yep, also done.
Quoted 28 lines
See Bspec https://gfxspecs.intel.com/Predator/Home/Index/44235
For MTL check bit[3:2], for other gen12 platforms check bit[1:0]drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects;
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-10- /* - * In case the pat_index is set by user space, this kernel mode - * driver should leave the coherency to be managed by user space, - * simply return true here. - */ - if (obj->pat_set_by_user) - return true; - - /* -* Otherwise the pat_index should have been converted from
cache_leveldrivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects;
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-3-* so that the following comparison is valid. -*/ - return obj->pat_index == i915_gem_get_pat_index(obj_to_i915(obj),lvl);
drivers/gpu/drm/i915/gem/i915_gem_object.c void __i915_gem_object_fini(struct
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-2-} - struct drm_i915_gem_object *i915_gem_object_alloc(void) { struct drm_i915_gem_object *obj;@@ -144,6 +117,24 @@ void __i915_gem_object_fini(struct
drm_i915_gem_object*obj)Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-0dma_resv_fini(&obj->base._resv); }
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c void __i915_gem_object_fini(struct drm_i915_gem_object *obj) · line 123
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +4
-0+void __i915_gem_object_update_coherency (struct drm_i915_gem_object *obj) +{ + struct drm_i915_private *i915 = to_i915(obj->base.dev); + const unsigned int mode = I915_CACHE_MODE(obj->cache_mode);
obj->cache_modeseems to be redundant if we have INTEL_INFO(i915)->pat[] andobj->pat_index.
Ditto.
Quoted 702 lines
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +6
-0+ + if (!(mode == I915_CACHE_MODE_UNKNOWN || mode == I915_CACHE_MODE_UC)) + obj->cache_coherent = (I915_BO_CACHE_COHERENT_FOR_READ | + I915_BO_CACHE_COHERENT_FOR_WRITE); + else if (mode != I915_CACHE_MODE_UNKNOWN && HAS_LLC(i915)) + obj->cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ;drivers/gpu/drm/i915/gem/i915_gem_object.c void __i915_gem_object_fini(struct drm_i915_gem_object *obj)
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +8
-0+ else + obj->cache_coherent = 0; + + obj->cache_dirty = + !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) && + !IS_DGFX(i915); +} + /*** i915_gem_object_set_cache_coherency - Mark up the object's coherency levels
drivers/gpu/drm/i915/gem/i915_gem_object.c void i915_gem_object_set_cache_coherency(struct
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0
-0* for a given cache_level@@ -154,20 +145,15 @@ void i915_gem_object_set_cache_coherency(struct
drm_i915_gem_object*obj,drivers/gpu/drm/i915/gem/i915_gem_object.c void i915_gem_object_set_pat_index(struct
Quoted 28 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +7
-12unsigned int cache_level) { struct drm_i915_private *i915 = to_i915(obj->base.dev); + i915_cache_t mode; + int found; - obj->pat_index = i915_gem_get_pat_index(i915, cache_level); + found = i915_cache_level_to_pat_and_mode(i915, cache_level, &mode); + GEM_WARN_ON(found < 0); + obj->pat_index = found; + obj->cache_mode = mode; - if (cache_level != I915_CACHE_NONE) - obj->cache_coherent = (I915_BO_CACHE_COHERENT_FOR_READ | - I915_BO_CACHE_COHERENT_FOR_WRITE); - else if (HAS_LLC(i915)) - obj->cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ; - else - obj->cache_coherent = 0; - - obj->cache_dirty = - !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) && - !IS_DGFX(i915); + __i915_gem_object_update_coherency(obj); } /**@@ -187,18 +173,9 @@ void i915_gem_object_set_pat_index(struct
drm_i915_gem_object*obj,drivers/gpu/drm/i915/gem/i915_gem_object.c bool i915_gem_object_can_bypass_llc(struct
Quoted 21 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +2
-11return; obj->pat_index = pat_index; + obj->cache_mode = INTEL_INFO(i915)->cache_modes[pat_index]; - if (pat_index != i915_gem_get_pat_index(i915, I915_CACHE_NONE)) - obj->cache_coherent = (I915_BO_CACHE_COHERENT_FOR_READ | - I915_BO_CACHE_COHERENT_FOR_WRITE); - else if (HAS_LLC(i915)) - obj->cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ; - else - obj->cache_coherent = 0; - - obj->cache_dirty = - !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) && - !IS_DGFX(i915); + __i915_gem_object_update_coherency(obj); } bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj)@@ -215,6 +192,7 @@ bool i915_gem_object_can_bypass_llc(struct
drm_i915_gem_object*obj)Review
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +1
-0/* * Always flush cache for UMD objects at creation time. */ + /* QQQ/FIXME why? avoidable performance penalty? */ if (obj->pat_set_by_user) return true;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_object.hdrivers/gpu/drm/i915/gem/i915_gem_object.h static inline bool i915_gem_object_size_2big(u64
Quoted 12 lines
index
884a17275b3a..f84f41e9f81f100644drivers/gpu/drm/i915/gem/i915_gem_object.h +1
-0@@ -13,6 +13,7 @@ #include "display/intel_frontbuffer.h" #include "intel_memory_region.h" +#include "i915_cache.h" #include "i915_gem_object_types.h" #include "i915_gem_gtt.h" #include "i915_gem_ww.h"@@ -32,10 +33,18 @@ static inline bool i915_gem_object_size_2big(u64size)
drivers/gpu/drm/i915/gem/i915_gem_object.h static inline bool i915_gem_object_size_2big(u64 size)
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +0
-3return false; } -unsigned int i915_gem_get_pat_index (struct drm_i915_private *i915, - enum i915_cache_level level); -bool i915_gem_object_has_cache_level(const struct
drm_i915_gem_object*obj,drivers/gpu/drm/i915/gem/i915_gem_object.h int i915_gem_object_wait_moving_fence(struct
Quoted 17 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +12
-1- enum i915_cache_level lvl); +static inline int +i915_gem_object_has_cache_mode (const struct drm_i915_gem_object *obj, + unsigned int mode) +{ + if (I915_CACHE_MODE(obj->cache_mode) == mode) + return 1; + else if (obj->pat_set_by_user) + return -1; /* Unknown, callers should assume no. */ + else + return 0; +} + void i915_gem_init__objects(struct drm_i915_private *i915); void i915_objects_module_exit(void);@@ -764,6 +773,7 @@ int i915_gem_object_wait_moving_fence(struct
drm_i915_gem_object*obj,drivers/gpu/drm/i915/gem/i915_gem_object.h int i915_gem_object_wait_moving_fence(struct drm_i915_gem_object *obj,
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +1
-0bool intr); bool i915_gem_object_has_unknown_state(struct drm_i915_gem_object *obj); +void __i915_gem_object_update_coherency(struct drm_i915_gem_object*obj);
Quoted 1 line
void i915_gem_object_set_cache_coherency(struct
drm_i915_gem_object*obj,
Review
Quoted 3 lines
unsigned int
cache_level); void i915_gem_object_set_pat_index(structdrm_i915_gem_object*obj,(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_object_types.hQuoted 15 lines
index
8de2b91b3edf..1f9fa28d07df100644drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1
-0@@ -14,6 +14,7 @@ #include <uapi/drm/i915_drm.h> #include "i915_active.h" +#include "i915_cache.h" #include "i915_selftest.h" #include "i915_vma_resource.h"@@ -116,93 +117,6 @@ struct drm_i915_gem_object_ops {const char *name; /* friendly name for debug, e.g. lockdep classes */ };
Quoted 2 lines
-/**
- * enumi915_cache_level- The supported GTT caching values forsystem memory
Quoted 3 lines
- * pages.
- *
- * These translate to some special GTT PTE bits when binding pagesinto some
Quoted 1 line
- * address space. It also determines whether an object, or rather
its pages are
Quoted 1 line
- * coherent with the GPU, when also reading or writing through the
CPU cache
Quoted 9 lines
- * with those pages.
- *
- * Userspace can also control this through structdrm_i915_gem_caching.
- */
-enumi915_cache_level{
- /**
- * @I915_CACHE_NONE:
- *
- * GPU access is not coherent with the CPU cache. If the cache isdirty
Quoted 1 line
- * and we need the underlying pages to be coherent with some
later GPU
Quoted 5 lines
- * access then we need to manually flush the pages.
- *
- * On shared LLC platforms reads and writes through the CPU cache are - * still coherent even with this setting. See also
- * &drm_i915_gem_object.cache_coherent for more details. Due tothis we
Quoted 1 line
- * should only ever use uncached for scanout surfaces, otherwise
we end
Quoted 11 lines
- * up over-flushing in some places.
- *
- * This is the default on non-LLC platforms.
- */
- I915_CACHE_NONE = 0,
- /**
- * @I915_CACHE_LLC:
- *
- * GPU access is coherent with the CPU cache. If the cache is dirty, - * then the GPU will ensure that access remains coherent, when both - * reading and writing through the CPU cache. GPU writes candirty the
Quoted 8 lines
- * CPU cache.
- *
- * Not used for scanout surfaces.
- *
- * Applies to both platforms with sharedLLC(HAS_LLC), and snooping - * basedplatforms(HAS_SNOOP).
- *
- * This is the default on shared LLC platforms. The onlyexception is
Quoted 3 lines
- * scanout objects, where the display engine is not coherent with the - * CPU cache. For such objects
I915_CACHE_NONEorI915_CACHE_WTis - * automatically applied by the kernel inpin_for_display, ifuserspace
Quoted 10 lines
- * has not done so already.
- */
- I915_CACHE_LLC,
- /**
- * @I915_CACHE_L3_LLC:
- *
- * Explicitly enable the Gfx L3 cache, with coherent LLC. - *
- * The Gfx L3 sits between the domain specific caches, e.g - * sampler/render caches, and the larger LLC. LLC is coherentwith the
Quoted 1 line
- * GPU, but L3 is only visible to the GPU, so likely needs to be
flushed
Quoted 6 lines
- * when the workload completes.
- *
- * Not used for scanout surfaces.
- *
- * Only exposed on some gen7 + GGTT. More recent hardware has dropped - * this explicit setting, where it should now be enabled by default.Quoted 8 lines
- */
- I915_CACHE_L3_LLC,
- /**
- * @I915_CACHE_WT:
- *
- * Write-through. Used for scanout surfaces.
- *
- * The GPU can utilise the caches, while still having the displayengine
Quoted 1 line
- * be coherent with GPU writes, as a result we don't need to
flush the
Quoted 1 line
- * CPU caches when moving out of the render domain. This is the
default
Quoted 2 lines
- * setting chosen by the kernel, if supported by the HW, otherwise we - * fallback to
I915_CACHE_NONE. On the CPU side writes throughthe CPU
Quoted 1 line
- * cache still need to be flushed, to remain coherent with the
display
Quoted 7 lines
- * engine.
- */
- I915_CACHE_WT,
- /**
- * @I915_MAX_CACHE_LEVEL:
- *
- * Mark the last entry in the enum. Used for defining
cachelevel_to_patdrivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 290
Quoted 11 lines
- * array for
cache_levelto pat translation table. - */
- I915_MAX_CACHE_LEVEL,drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-2-}; -enum
i915_map_type{
I915_MAP_WB = 0,
I915_MAP_WC,drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-0@@ -375,6 +289,9 @@ struct drm_i915_gem_object { unsigned int mem_flags; #define I915_BO_FLAG_STRUCT_PAGE BIT(0) /* Object backed by structpages */
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 326
Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +3
-0#define I915_BO_FLAG_IOMEM BIT(1) /* Object backed by IO memory */ + + i915_cache_t cache_mode; + /*** @pat_index: The desired PAT index. * @@ -409,9 +326,7 @@ struct drm_i915_gem_object { * Check for @pat_set_by_user to find out if an object has patindex set
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 328
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-0* by userspace. The ioctl's to change cache settings have also been * disabled for the objects with pat index set by userspace.Please don't
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 412
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-1- * assume @cache_coherent having the flags set as describe here.A helper
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 413
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-1- * function i915_gem_object_has_cache_level() provides one way tobypass
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 407
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1
-1- * the use of this field. + * assume @cache_coherent having the flags set as describe here. * * Track whether the pages are coherent with the GPU if reading or * writing through the CPU caches. The largely depends on the@@ -492,9 +407,7 @@ struct drm_i915_gem_object { * Check for @pat_set_by_user to find out if an object has patindex set
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 409
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-0* by userspace. The ioctl's to change cache settings have also been * disabled for the objects with pat_index set by userspace.Please don't
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 495
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-1- * assume @cache_dirty is set as describe here. Also see helperfunction
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 496
Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-1- * i915_gem_object_has_cache_level() for possible ways to bypassthe use
drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object {
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1
-1- * of this field. + * assume @cache_dirty is set as describe here. * * Track if we are we dirty with writes through the CPU cache forthis
Review
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0
-0* object. As a result reading directly from main memory might yield(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_stolen.cdrivers/gpu/drm/i915/gem/i915_gem_stolen.c static void dbg_poison(struct i915_ggtt *ggtt, · line 566
Quoted 13 lines
index
3b094d36a0b0..a7012f1a9c70100644drivers/gpu/drm/i915/gem/i915_gem_stolen.c +1
-5@@ -563,11 +563,8 @@ static void dbg_poison(struct i915_ggtt *ggtt, while (size) { void __iomem *s; - ggtt->vm.insert_page(&ggtt->vm, addr, - ggtt->error_capture.start, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, addr,
ggtt->error_capture.start,Review
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +1
-0+ ggtt->vm.i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap,(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.cdrivers/gpu/drm/i915/gem/i915_gem_ttm_move.c i915_ttm_cache_level(struct drm_i915_private
Quoted 4 lines
index
7078af2f8f79..e794bd2a7ccb100644drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0
-0@@ -58,6 +58,16 @@ i915_ttm_cache_level(struct drm_i915_private*i915, struct
ttm_resource*res,drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res,
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +2
-0I915_CACHE_NONE; } +static unsigned int +i915_ttm_cache_pat(struct drm_i915_private *i915, struct
ttm_resource*res,drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +8
-0+ struct ttm_tt *ttm) +{ + return ((HAS_LLC(i915) || HAS_SNOOP(i915)) && + !i915_ttm_gtt_binds_lmem(res) && + ttm->caching == ttm_cached) ? i915->pat_wb : + i915->pat_uc; +} +static struct
intel_memory_region*i915_ttm_region(struct ttm_device *bdev, int ttm_mem_type){drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0
-0@@ -196,7 +206,7 @@ static struct dma_fence*i915_ttm_accel_move(struct
ttm_buffer_object*bo,drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence
Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1
-1struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); struct i915_request *rq; struct ttm_tt *src_ttm = bo->ttm; - enum i915_cache_level src_level, dst_level; + unsigned int src_pat, dst_pat; int ret; if (!to_gt(i915)->migrate.context || intel_gt_is_wedged(to_gt(i915)))@@ -206,16 +216,15 @@ static struct dma_fence*i915_ttm_accel_move(struct
ttm_buffer_object*bo,Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1
-1if (I915_SELFTEST_ONLY(fail_gpu_migration)) clear = true; - dst_level = i915_ttm_cache_level(i915, dst_mem, dst_ttm); + dst_pat = i915_ttm_cache_pat(i915, dst_mem, dst_ttm); if (clear) {if (
bo->type==ttm_bo_type_kernel&& !I915_SELFTEST_ONLY(fail_gpu_migration)) returnERR_PTR(-EINVAL);Quoted 2 lines
intel_engine_pm_get(to_gt(i915)->migrate.context->engine); - ret =
intel_context_migrate_clear(to_gt(i915)->migrate.context, deps,
Quoted 2 lines
- dst_st->sgl,
- i915_gem_get_pat_index(i915,
dst_level),drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence
Quoted 6 lines
+ ret = intel_context_migrate_clear(to_gt(i915)->migrate.context, + deps,
dst_st->sgl,dst_pat,i915_ttm_gtt_binds_lmem(dst_mem), 0, &rq);
} else {drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0
-0@@ -225,14 +234,13 @@ static struct dma_fence*i915_ttm_accel_move(struct
ttm_buffer_object*bo,drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo,
Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1
-2if (IS_ERR(src_rsgt)) return ERR_CAST(src_rsgt); - src_level = i915_ttm_cache_level(i915, bo->resource, src_ttm); + src_pat = i915_ttm_cache_pat(i915, bo->resource, src_ttm); intel_engine_pm_get(to_gt(i915)->migrate.context->engine); ret = intel_context_migrate_copy(to_gt(i915)->migrate.context, deps, src_rsgt->table.sgl, - i915_gem_get_pat_index(i915,
src_level),drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence *i915_ttm_accel_move(struct ttm_buffer_object *bo,
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1
-2+ src_pat, i915_ttm_gtt_binds_lmem(bo->resource), - dst_st->sgl, - i915_gem_get_pat_index(i915,
dst_level),Review
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1
-0+ dst_st->sgl, dst_pat, i915_ttm_gtt_binds_lmem(dst_mem), &rq);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gem/selftests/huge_pages.cdrivers/gpu/drm/i915/gem/selftests/huge_pages.c fake_huge_pages_object(struct drm_i915_private
Quoted 4 lines
index
df6c9a84252c..c8925918784e100644drivers/gpu/drm/i915/gem/selftests/huge_pages.c +0
-0@@ -354,7 +354,7 @@ fake_huge_pages_object(struct drm_i915_private*i915, u64 size, bool single)
Review
Quoted 9 lines
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +1
-1obj->write_domain = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU; - obj->pat_index = i915_gem_get_pat_index(i915, I915_CACHE_NONE); + i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE); return obj; }(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/gen6_ppgtt.cdrivers/gpu/drm/i915/gt/gen6_ppgtt.c static int gen6_ppgtt_init_scratch(struct
Quoted 4 lines
index
c2bdc133c89a..fb69f667652a100644drivers/gpu/drm/i915/gt/gen6_ppgtt.c +0
-0@@ -226,9 +226,7 @@ static int gen6_ppgtt_init_scratch(struct
gen6_ppgtt*ppgtt)Review
Quoted 11 lines
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +0
-0return ret;vm->scratch[0]->encode =
- vm->pte_encode(px_dma(vm->scratch[0]),
- i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), + vm->pte_encode(px_dma(vm->scratch[0]),vm->i915->pat_uc,PTE_READ_ONLY);vm->scratch[1] =
vm->alloc_pt_dma(vm, I915_GTT_PAGE_SIZE_4K);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/gen8_ppgtt.cdrivers/gpu/drm/i915/gt/gen8_ppgtt.c static int gen8_init_scratch(struct
Quoted 23 lines
index
f948d33e5ec5..a6692ea1a91e100644drivers/gpu/drm/i915/gt/gen8_ppgtt.c +2
-7@@ -40,16 +40,11 @@ static u64 gen8_pte_encode(dma_addr_t addr, if (flags & PTE_LM) pte |= GEN12_PPGTT_PTE_LM; - /* - * For pre-gen12 platforms pat_index is the same as enum - * i915_cache_level, so the switch-case here is still valid. - * See translation table defined by LEGACY_CACHELEVEL. - */ switch (pat_index) { - case I915_CACHE_NONE: + case 0: pte |= PPAT_UNCACHED; break; - case I915_CACHE_WT: + case 3: pte |= PPAT_DISPLAY_ELLC; break;default:
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +0
-0@@ -853,9 +848,7 @@ static int gen8_init_scratch(struct
i915_address_space*vm)Review
Quoted 11 lines
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +0
-0pte_flags |= PTE_LM;vm->scratch[0]->encode =
- vm->pte_encode(px_dma(vm->scratch[0]),
- i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), + vm->pte_encode(px_dma(vm->scratch[0]),vm->i915->pat_uc,pte_flags);for (i = 1; i <=
vm->top; i++) {(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/intel_ggtt.cdrivers/gpu/drm/i915/gt/intel_ggtt.c static int ggtt_probe_common(struct i915_ggtt
Quoted 4 lines
index
dd0ed941441a..c97379cf8241100644drivers/gpu/drm/i915/gt/intel_ggtt.c +0
-0@@ -921,9 +921,7 @@ static int ggtt_probe_common(struct i915_ggtt*ggtt, u64 size)
drivers/gpu/drm/i915/gt/intel_ggtt.c bool i915_ggtt_resume_vm(struct
Quoted 11 lines
drivers/gpu/drm/i915/gt/intel_ggtt.c +0
-0pte_flags |= PTE_LM;ggtt->vm.scratch[0]->encode =
- ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]),
- i915_gem_get_pat_index(i915,
-I915_CACHE_NONE), + ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]),i915->pat_uc,pte_flags);return 0;
drivers/gpu/drm/i915/gt/intel_ggtt.c +0
-0@@ -1297,10 +1295,7 @@ bool i915_ggtt_resume_vm(struct
i915_address_space*vm)Quoted 11 lines
drivers/gpu/drm/i915/gt/intel_ggtt.c +1
-4* ptes to be repopulated. */ vma->resource->bound_flags = 0; - vma->ops->bind_vma(vm, NULL, vma->resource, - obj ? obj->pat_index : - i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), + vma->ops->bind_vma(vm, NULL, vma->resource, obj->cache_mode, was_bound);if (obj) { /* only used during resume => exclusive access */
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/intel_migrate.cdrivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_toggle_pdes(struct
Quoted 4 lines
index
6023288b0e2d..81f7834cc2db100644drivers/gpu/drm/i915/gt/intel_migrate.c +0
-0@@ -45,9 +45,7 @@ static void xehpsdv_toggle_pdes(struct
i915_address_space*vm,drivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_insert_pte(struct
Quoted 11 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +1
-3* Insert a dummy PTE into every PT that will map to LMEM to ensure * we have a correctly setup PDE structure for later use. */ - vm->insert_page(vm, 0, d->offset, - i915_gem_get_pat_index(vm->i915, I915_CACHE_NONE), - PTE_LM); + vm->insert_page(vm, 0, d->offset, vm->i915->pat_uc, PTE_LM); GEM_BUG_ON(!pt->is_compact); d->offset += SZ_2M; }@@ -65,9 +63,7 @@ static void xehpsdv_insert_pte(struct
i915_address_space*vm,Review
Quoted 21 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +2
-5* alignment is 64K underneath for the pt, and we are careful * not to access the space in the void. */ - vm->insert_page(vm, px_dma(pt), d->offset, - i915_gem_get_pat_index(vm->i915, I915_CACHE_NONE), - PTE_LM); + vm->insert_page(vm, px_dma(pt), d->offset, vm->i915->pat_uc, PTE_LM); d->offset += SZ_64K; }@@ -77,8 +73,7 @@ static void insert_pte(struct i915_address_space *vm, { struct insert_pte_data *d = data; - vm->insert_page(vm, px_dma(pt), d->offset, - i915_gem_get_pat_index(vm->i915, I915_CACHE_NONE), + vm->insert_page(vm, px_dma(pt), d->offset, vm->i915->pat_uc, i915_gem_object_is_lmem(pt->base) ? PTE_LM : 0); d->offset += PAGE_SIZE; }(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/selftest_migrate.cReview
Quoted 29 lines
index
3def5ca72dec..a67ede65d816100644drivers/gpu/drm/i915/gt/selftest_migrate.c +3
-6@@ -904,8 +904,7 @@ static int perf_clear_blt(void *arg) err = __perf_clear_blt(gt->migrate.context, dst->mm.pages->sgl, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + gt->i915->pat_uc, i915_gem_object_is_lmem(dst), sizes[i]);@@ -995,12 +994,10 @@ static int perf_copy_blt(void *arg) err = __perf_copy_blt(gt->migrate.context, src->mm.pages->sgl, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + gt->i915->pat_uc, i915_gem_object_is_lmem(src), dst->mm.pages->sgl, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), + gt->i915->pat_uc, i915_gem_object_is_lmem(dst), sz);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/selftest_reset.cReview
Quoted 32 lines
index
79aa6ac66ad2..327dc9294e0f100644drivers/gpu/drm/i915/gt/selftest_reset.c +4
-10@@ -84,11 +84,8 @@ __igt_reset_stolen(struct intel_gt *gt, void __iomem *s; void *in; - ggtt->vm.insert_page(&ggtt->vm, dma, - ggtt->error_capture.start, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, dma, ggtt->error_capture.start, + gt->i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap,@@ -127,11 +124,8 @@ __igt_reset_stolen(struct intel_gt *gt, void *in; u32 x; - ggtt->vm.insert_page(&ggtt->vm, dma, - ggtt->error_capture.start, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, dma, ggtt->error_capture.start, + gt->i915->pat_uc, 0); mb(); s = io_mapping_map_wc(&ggtt->iomap,(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/selftest_timeline.cdrivers/gpu/drm/i915/gt/selftest_timeline.c static int setup_watcher(struct hwsp_watcher *w,
Quoted 4 lines
index
39c3ec12df1a..db64dc7d3fce100644drivers/gpu/drm/i915/gt/selftest_timeline.c +0
-0@@ -836,7 +836,10 @@ static int setup_watcher(struct hwsp_watcher *w,struct
intel_gt*gt,Quoted 10 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +4
-1return PTR_ERR(obj); /* keep the same cache settings as timeline */ - i915_gem_object_set_pat_index(obj, tl->hwsp_ggtt->obj->pat_index); + obj->pat_index = tl->hwsp_ggtt->obj->pat_index; + obj->cache_mode = tl->hwsp_ggtt->obj->cache_mode; + __i915_gem_object_update_coherency(obj); + w->map = i915_gem_object_pin_map_unlocked(obj,page_unmask_bits(tl->hwsp_ggtt->obj->mm.mapping));
Review
Quoted 2 lines
if (
IS_ERR(w->map)) {(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/selftest_tlb.cReview
Quoted 23 lines
index
3bd6b540257b..6049f01be219100644drivers/gpu/drm/i915/gt/selftest_tlb.c +2
-3@@ -36,8 +36,6 @@ pte_tlbinv(struct intel_context *ce, u64 length, struct rnd_state *prng) { - const unsigned int pat_index = - i915_gem_get_pat_index(ce->vm->i915, I915_CACHE_NONE); struct drm_i915_gem_object *batch; struct drm_mm_node vb_node; struct i915_request *rq;@@ -157,7 +155,8 @@ pte_tlbinv(struct intel_context *ce, /* Flip the PTE between A and B */ if (i915_gem_object_is_lmem(vb->obj)) pte_flags |= PTE_LM; - ce->vm->insert_entries(ce->vm, &vb_res, pat_index, pte_flags); + ce->vm->insert_entries(ce->vm, &vb_res, ce->vm->i915->pat_uc, + pte_flags); /* Flush the PTE update to concurrent HW */ tlbinv(ce->vm, addr & -length, length);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.cdrivers/gpu/drm/i915/gt/uc/intel_uc_fw.c static void uc_fw_bind_ggtt(struct intel_uc_fw
Quoted 4 lines
index
d408856ae4c0..e099414d624d100644drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +0
-0@@ -991,14 +991,10 @@ static void uc_fw_bind_ggtt(struct intel_uc_fw
*uc_fw)Quoted 15 lines
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +1
-3if (ggtt->vm.raw_insert_entries) ggtt->vm.raw_insert_entries(&ggtt->vm, vma_res, - i915_gem_get_pat_index(ggtt->vm.i915, - I915_CACHE_NONE), - pte_flags); + ggtt->vm.i915->pat_uc, pte_flags);else
ggtt->vm.insert_entries(&ggtt->vm,vma_res,
- i915_gem_get_pat_index(ggtt->vm.i915, -I915_CACHE_NONE), - pte_flags);
+ ggtt->vm.i915->pat_uc,pte_flags); }Review
Quoted 2 lines
static void
uc_fw_unbind_ggtt(struct intel_uc_fw *uc_fw)(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_cache.cQuoted 5 lines
new file mode 100644
index 000000000000..7a8002ebd2ecdrivers/gpu/drm/i915/i915_cache.c line 10
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.c new file +10
-0@@ -0,0 +1,59 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2023 Intel Corporation +*/ + +#include "i915_cache.h" +#include "i915_drv.h" + +static int find_pat(const struct intel_device_info *info,
i915_cache_tmode)Quoted 8 lines
drivers/gpu/drm/i915/i915_cache.c new file +8
-0+{ + int i; + + for (i = 0; i < ARRAY_SIZE(info->cache_modes); i++) { + if (info->cache_modes[i] == mode) + return i; + } +drivers/gpu/drm/i915/i915_cache.c
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.c new file +10
-0+ return -1; +} + +void i915_cache_init (struct drm_i915_private *i915) +{ + int ret; + + ret = find_pat(INTEL_INFO(i915), I915_CACHE(UC)); + WARN_ON(ret < 0); + drm_info(&i915->drm, "Using PAT index %u for uncached access\n",ret);
drivers/gpu/drm/i915/i915_cache.c
Quoted 5 lines
drivers/gpu/drm/i915/i915_cache.c new file +5
-0+ i915->pat_uc = ret; + + ret = find_pat(INTEL_INFO(i915), I915_CACHE(WB)); + WARN_ON(ret < 0); + drm_info(&i915->drm, "Using PAT index %u for write-back
Quoted 7 lines
access\n", ret);
drivers/gpu/drm/i915/i915_cache.c line 35
Quoted 2 lines
drivers/gpu/drm/i915/i915_cache.c new file +2
-0+ i915->pat_wb = ret; +}I don't think we need the above two functions. Why don't we just hard code
pat_ucandpat_wbindevice_info? pluspat_wttoo? These are predetermined, and used by KMD only.
We could add a table of enum i915_cache_mode to pat index but since we only use two from within the driver I was a bit reluctant to add a set of tables with more entries. Just a slight preference at the moment, I guess I could be convinced we really should go the 2nd table route.
Quoted 50 lines
Review
Quoted 24 lines
drivers/gpu/drm/i915/i915_cache.c new file +23
-0+int i915_cache_level_to_pat_and_mode (struct drm_i915_private *i915, + unsigned int cache_level, + i915_cache_t *mode) +{ + const struct intel_device_info *info = INTEL_INFO(i915); + i915_cache_t level_to_mode[] = { + [I915_CACHE_NONE] = I915_CACHE(UC), + [I915_CACHE_WT] = I915_CACHE(WT), + [I915_CACHE_LLC] = I915_CACHE(WB), + }; + int ret; + + if (GRAPHICS_VER(i915) >= 12) + level_to_mode[I915_CACHE_L3_LLC] = I915_CACHE(WB); + else + level_to_mode[I915_CACHE_L3_LLC] = _I915_CACHE(WB, LLC); + + ret = find_pat(info, level_to_mode[cache_level]); + if (ret >= 0 && mode) + *mode = info->cache_modes[ret]; + + return ret; +}(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_cache.hQuoted 14 lines
new file mode 100644
index 000000000000..0df03f1f01efdrivers/gpu/drm/i915/i915_cache.h new file +9
-0@@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef __I915_CACHE_H__ +#define __I915_CACHE_H__ + +#include <linux/types.h> drivers/gpu/drm/i915/i915_cache.h line 19
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h new file +10
-0+ +struct drm_i915_private ; + +typedef u16 i915_cache_t ; + +#define I915_CACHE (mode) \ + (i915_cache_t)(I915_CACHE_MODE_##mode) + +#define _I915_CACHE (mode, flag) \ + (i915_cache_t)((I915_CACHE_MODE_##mode) | ( BIT(8 +I915_CACHE_##flag)))
Quoted 15 lines
drivers/gpu/drm/i915/i915_cache.h line 31
Quoted 12 lines
drivers/gpu/drm/i915/i915_cache.h new file +12
-0+ +#define I915_CACHE_MODE (cache) \ + (unsigned int)(((i915_cache_t)(cache)) & 0xff) +#define I915_CACHE_FLAGS (cache) \ + (unsigned int)((((i915_cache_t)(cache) & 0xff00)) >> 16) + +/* Cache mode values */ +#define I915_CACHE_MODE_UNKNOWN (0) +#define I915_CACHE_MODE_UC (1) +#define I915_CACHE_MODE_WB (2) +#define I915_CACHE_MODE_WT (3) +#define I915_CACHE_MODE_WC (4)Why do you need these CACHE_MODE's? Aren't they the same as
i915_cache_level, which need some sort of translation?
Yes, in v2 I dropped i915_cache_level instead.
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h line 38
Quoted 7 lines
drivers/gpu/drm/i915/i915_cache.h new file +7
-0+ +/* Mode flag bits */ +#define I915_CACHE_L3 (0) +#define I915_CACHE_COH1W (1) +#define I915_CACHE_COH2W (2) +#define I915_CACHE_CLOS1 (3) +#define I915_CACHE_CLOS2 (4)These had been defined in
drivers/gpu/drm/i915/gt/intel_gtt.halready, why add new ones? The CLOS ones are not needed in upstream unless we want to support PVC here.
I simply added entries for everything I could find currently in the driver. In parallel I am checking if we should/could remove all the PVC bits and pieces from the driver.
Quoted 20 lines
drivers/gpu/drm/i915/i915_cache.h
Quoted 11 lines
drivers/gpu/drm/i915/i915_cache.h new file +11
-0+void i915_cache_init (struct drm_i915_private *i915); +int i915_cache_level_to_pat_and_mode (struct drm_i915_private *i915, + unsigned int cache_level, + i915_cache_t *mode); + +/* +* Legacy/kernel internal interface below: +*/ + +/** +* enum i915_cache_level - The supported GTT caching values for system memory
drivers/gpu/drm/i915/i915_cache.h
Quoted 3 lines
drivers/gpu/drm/i915/i915_cache.h new file +3
-0+* pages. +* +* These translate to some special GTT PTE bits when binding pages into some
drivers/gpu/drm/i915/i915_cache.h line 53
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+* address space. It also determines whether an object, or rather its pages are
drivers/gpu/drm/i915/i915_cache.h line 54
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+* coherent with the GPU, when also reading or writing through the CPU cache
Quoted 8 lines
drivers/gpu/drm/i915/i915_cache.h line 60
Quoted 5 lines
drivers/gpu/drm/i915/i915_cache.h new file +5
-0+* with those pages. +* +* Userspace can also control this through struct drm_i915_gem_caching. +*/ +enum i915_cache_level {Shouldn't we completely get rid of this enum now? It should be replaced by INTEL_INFO(i915)->pat_uc/wb/wt.
Yep, done.
Quoted 229 lines
drivers/gpu/drm/i915/i915_cache.h
Quoted 4 lines
drivers/gpu/drm/i915/i915_cache.h new file +4
-0+ /** +* @I915_CACHE_NONE: +* +* GPU access is not coherent with the CPU cache. If the cache is dirty
drivers/gpu/drm/i915/i915_cache.h line 64
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+ * and we need the underlying pages to be coherent with somelater GPU
drivers/gpu/drm/i915/i915_cache.h
Quoted 5 lines
drivers/gpu/drm/i915/i915_cache.h new file +5
-0+ * access then we need to manually flush the pages. + * + * On shared LLC platforms reads and writes through the CPU cache are + * still coherent even with this setting. See also + * &drm_i915_gem_object.cache_coherent for more details. Due tothis we
drivers/gpu/drm/i915/i915_cache.h line 70
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+ * should only ever use uncached for scanout surfaces, otherwisewe end
drivers/gpu/drm/i915/i915_cache.h
Quoted 11 lines
drivers/gpu/drm/i915/i915_cache.h new file +11
-0+* up over-flushing in some places. +* +* This is the default on non-LLC platforms. +*/ + I915_CACHE_NONE = 0, + /** +* @I915_CACHE_LLC: +* +* GPU access is coherent with the CPU cache. If the cache is dirty, +* then the GPU will ensure that access remains coherent, when both +* reading and writing through the CPU cache. GPU writes can dirty the
drivers/gpu/drm/i915/i915_cache.h
Quoted 8 lines
drivers/gpu/drm/i915/i915_cache.h new file +8
-0+ * CPU cache. + * + * Not used for scanout surfaces. + * + * Applies to both platforms with shared LLC(HAS_LLC), and snooping + * based platforms(HAS_SNOOP). + * + * This is the default on shared LLC platforms. The onlyexception is
drivers/gpu/drm/i915/i915_cache.h
Quoted 3 lines
drivers/gpu/drm/i915/i915_cache.h new file +3
-0+ * scanout objects, where the display engine is not coherent with the + * CPU cache. For such objects I915_CACHE_NONE or I915_CACHE_WT is + * automatically applied by the kernel in pin_for_display, ifuserspace
drivers/gpu/drm/i915/i915_cache.h
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h new file +10
-0+* has not done so already. +*/ + I915_CACHE_LLC, + /** +* @I915_CACHE_L3_LLC: +* +* Explicitly enable the Gfx L3 cache, with coherent LLC. +* +* The Gfx L3 sits between the domain specific caches, e.g +* sampler/render caches, and the larger LLC. LLC is coherent with the
drivers/gpu/drm/i915/i915_cache.h line 103
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+ * GPU, but L3 is only visible to the GPU, so likely needs to beflushed
Quoted 4 lines
drivers/gpu/drm/i915/i915_cache.h new file +4
-0+ * when the workload completes. + * + * Not used for scanout surfaces. + *drivers/gpu/drm/i915/i915_cache.h
Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h new file +10
-0+* Only exposed on some gen7 + GGTT. More recent hardware has dropped +* this explicit setting, where it should now be enabled by default. +*/ + I915_CACHE_L3_LLC, + /** +* @I915_CACHE_WT: +* +* Write-through. Used for scanout surfaces. +* +* The GPU can utilise the caches, while still having the display engine
drivers/gpu/drm/i915/i915_cache.h line 118
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+ * be coherent with GPU writes, as a result we don't need toflush the
drivers/gpu/drm/i915/i915_cache.h line 119
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+ * CPU caches when moving out of the render domain. This is thedefault
drivers/gpu/drm/i915/i915_cache.h line 121
Quoted 2 lines
drivers/gpu/drm/i915/i915_cache.h new file +2
-0+ * setting chosen by the kernel, if supported by the HW, otherwise we + * fallback to I915_CACHE_NONE. On the CPU side writes throughthe CPU
drivers/gpu/drm/i915/i915_cache.h line 122
Quoted 1 line
drivers/gpu/drm/i915/i915_cache.h new file +1
-0+ * cache still need to be flushed, to remain coherent with thedisplay
Review
Quoted 7 lines
drivers/gpu/drm/i915/i915_cache.h new file +6
-0+* engine. +*/ + I915_CACHE_WT, +}; + +#endif /* __I915_CACHE_H__ */ (quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_debugfs.cdrivers/gpu/drm/i915/i915_debugfs.c static const char *stringify_vma_type(const
Quoted 4 lines
index
76ccd4e03e31..e2da57397770100644drivers/gpu/drm/i915/i915_debugfs.c +0
-0@@ -139,48 +139,37 @@ static const char *stringify_vma_type(conststruct
i915_vma*vma)drivers/gpu/drm/i915/i915_debugfs.c static const char *stringify_vma_type(const struct i915_vma *vma)
Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1return "ppgtt"; } -static const char *i915_cache_level_str (struct drm_i915_gem_object *obj) +static void obj_cache_str(struct seq_file *m, struct
drm_i915_gem_object*obj)drivers/gpu/drm/i915/i915_debugfs.c i915_debugfs_describe_obj(struct seq_file *m,
Quoted 72 lines
drivers/gpu/drm/i915/i915_debugfs.c +27
-38{ - struct drm_i915_private *i915 = obj_to_i915(obj); + const i915_cache_t cache = obj->cache_mode; + const unsigned int mode = I915_CACHE_MODE(cache); + const unsigned long flags = I915_CACHE_FLAGS(cache); + static const char *mode_str[] = { + [I915_CACHE_MODE_UC] = "UC", + [I915_CACHE_MODE_WB] = "WB", + [I915_CACHE_MODE_WT] = "WT", + [I915_CACHE_MODE_WC] = "WC", + }; + static const char *flag_str[] = { + [I915_CACHE_L3] = "L3", + [I915_CACHE_COH1W] = "1-Way-Coherent", + [I915_CACHE_COH2W] = "2-Way-Coherent", + [I915_CACHE_CLOS1] = "CLOS1", + [I915_CACHE_CLOS2] = "CLOS2", + }; - if (IS_METEORLAKE(i915)) { - switch (obj->pat_index) { - case 0: return " WB"; - case 1: return " WT"; - case 2: return " UC"; - case 3: return " WB (1-Way Coh)"; - case 4: return " WB (2-Way Coh)"; - default: return " not defined"; - } - } else if (IS_PONTEVECCHIO(i915)) { - switch (obj->pat_index) { - case 0: return " UC"; - case 1: return " WC"; - case 2: return " WT"; - case 3: return " WB"; - case 4: return " WT (CLOS1)"; - case 5: return " WB (CLOS1)"; - case 6: return " WT (CLOS2)"; - case 7: return " WT (CLOS2)"; - default: return " not defined"; - } - } else if (GRAPHICS_VER(i915) >= 12) { - switch (obj->pat_index) { - case 0: return " WB"; - case 1: return " WC"; - case 2: return " WT"; - case 3: return " UC"; - default: return " not defined"; - } + if (mode == I915_CACHE_MODE_UNKNOWN || mode > ARRAY_SIZE(mode_str)) { + if (obj->pat_set_by_user) + seq_printf(m, " PAT-%u", obj->pat_index); + else + seq_printf(m, " PAT-%u-???", obj->pat_index); } else { - switch (obj->pat_index) { - case 0: return " UC"; - case 1: return HAS_LLC(i915) ? - " LLC" : " snooped"; - case 2: return " L3+LLC"; - case 3: return " WT"; - default: return " not defined"; - } + unsigned long bit; + + seq_printf(m, " %s", mode_str[mode]); + + for_each_set_bit(bit, &flags, sizeof(i915_cache_t)) + seq_printf(m, "-%s", flag_str[bit]); } }@@ -190,17 +179,23 @@ i915_debugfs_describe_obj(struct seq_file *m,struct
drm_i915_gem_object*obj)Review
Quoted 29 lines
drivers/gpu/drm/i915/i915_debugfs.c +11
-5struct i915_vma *vma; int pin_count = 0; - seq_printf(m, "%pK: %c%c%c %8zdKiB %02x %02x %s%s%s", + seq_printf(m, "%pK: %c%c%c %8zdKiB %02x %02x", &obj->base, get_tiling_flag(obj), get_global_flag(obj), get_pin_mapped_flag(obj), obj->base.size / 1024, obj->read_domains, - obj->write_domain, - i915_cache_level_str(obj), - obj->mm.dirty ? " dirty" : "", - obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : ""); + obj->write_domain); + + obj_cache_str(m, obj); + + if (obj->mm.dirty) + seq_puts(m, " dirty"); + + if (obj->mm.madv == I915_MADV_DONTNEED) + seq_puts(m, " purgeable"); + if (obj->base.name) seq_printf(m, " (name: %d)", obj->base.name);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_driver.cdrivers/gpu/drm/i915/i915_driver.c static int i915_driver_early_probe(struct
Quoted 12 lines
index
222d0a1f3b55..deab26752ba4100644drivers/gpu/drm/i915/i915_driver.c +1
-0@@ -80,6 +80,7 @@ #include "soc/intel_dram.h" #include "soc/intel_gmch.h" +#include "i915_cache.h" #include "i915_debugfs.h" #include "i915_driver.h" #include "i915_drm_client.h"@@ -267,6 +268,8 @@ static int i915_driver_early_probe(struct
drm_i915_private*dev_priv)Review
Quoted 9 lines
drivers/gpu/drm/i915/i915_driver.c +2
-0intel_detect_preproduction_hw(dev_priv); + i915_cache_init(dev_priv); + return 0;err_rootgt:
(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_drv.hQuoted 7 lines
index
b4cf6f0f636d..cb1c0c9d98ef100644drivers/gpu/drm/i915/i915_drv.h +0
-0@@ -251,6 +251,9 @@ struct drm_i915_private { unsigned int hpll_freq; unsigned int czclk_freq;
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 255
Quoted 2 lines
drivers/gpu/drm/i915/i915_drv.h +2
-0+ unsigned int pat_uc; + unsigned int pat_wb;How about making these part of
INTEL_INFO(i915)? They are predetermined, no need to be dynamic.
Discussed somewhere above.
Quoted 102 lines
Review
Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.h +1
-0+ /*** wq - Driver workqueue for GEM. * (quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_gem.cQuoted 7 lines
index
7ae42f746cc2..9aae75862e6f100644drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -422,9 +422,7 @@ i915_gem_gtt_pread(struct drm_i915_gem_object *obj, ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj,offset >>
PAGE_SHIFT),drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct
Quoted 8 lines
- node.start,
- i915_gem_get_pat_index(i915, - I915_CACHE_NONE), 0); + node.start,i915->pat_uc, 0); } else {
page_base += offset &PAGE_MASK;
}drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -603,9 +601,7 @@ i915_gem_gtt_pwrite_fast(struct
drm_i915_gem_object*obj,Quoted 3 lines
drivers/gpu/drm/i915/i915_gem.c +0
-0ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj,offset >>
PAGE_SHIFT),Quoted 5 lines
- node.start,
- i915_gem_get_pat_index(i915, - I915_CACHE_NONE), 0); + node.start,i915->pat_uc, 0);wmb(); /* flush modifications to the GGTT(
insert_page) */drivers/gpu/drm/i915/i915_gem.c int i915_gem_init(struct drm_i915_private
Quoted 3 lines
} else {
page_base += offset &PAGE_MASK;drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -1148,19 +1144,6 @@ int i915_gem_init(struct drm_i915_private
*dev_priv)drivers/gpu/drm/i915/i915_gem.c int i915_gem_init(struct drm_i915_private *dev_priv)
Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +0
-3unsigned int i; int ret; - /* -* In the proccess of replacing cache_level with pat_index a tricky -* dependency is created on the definition of the enum
i915_cache_level.drivers/gpu/drm/i915/i915_gem.c int i915_gem_init(struct drm_i915_private *dev_priv)
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +0
-10-* in case this enum is changed, PTE encode would be broken. -* Add a WARNING here. And remove when we completely quit using this -* enum -*/ - BUILD_BUG_ON(I915_CACHE_NONE != 0 || - I915_CACHE_LLC != 1 || - I915_CACHE_L3_LLC != 2 || - I915_CACHE_WT != 3 || - I915_MAX_CACHE_LEVEL != 4); - /* We need to fallback to 4K pages if host doesn't support hugegtt. */
Quoted 1 line
if (
intel_vgpu_active(dev_priv)&&!intel_vgpu_has_huge_gtt(dev_priv))
Review
Quoted 2 lines
RUNTIME_INFO(dev_priv)->page_sizes =
I915_GTT_PAGE_SIZE_4K;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_gpu_error.cdrivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct
Quoted 4 lines
index
4749f99e6320..fad336a45699100644drivers/gpu/drm/i915/i915_gpu_error.c +0
-0@@ -1122,14 +1122,11 @@ i915_vma_coredump_create(const struct
intel_gt*gt,drivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct intel_gt *gt,
Quoted 5 lines
drivers/gpu/drm/i915/i915_gpu_error.c +0
-2mutex_lock(&ggtt->error_mutex); if (ggtt->vm.raw_insert_page) ggtt->vm.raw_insert_page(&ggtt->vm, dma, slot, - i915_gem_get_pat_index(gt->i915, -I915_CACHE_NONE),
Quoted 10 lines
drivers/gpu/drm/i915/i915_gpu_error.c +1
-0+ ggtt->vm.i915->pat_uc, 0);else
ggtt->vm.insert_page(&ggtt->vm, dma, slot, - i915_gem_get_pat_index(gt->i915, - I915_CACHE_NONE), - 0);
+ggtt->vm.i915->pat_uc, 0);mb();Review
Quoted 2 lines
s =
io_mapping_map_wc(&ggtt->iomap, slot, PAGE_SIZE);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_pci.cdrivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow
Quoted 12 lines
index
3d7a5db9833b..fbdce31afeb1100644drivers/gpu/drm/i915/i915_pci.c +1
-0@@ -32,6 +32,7 @@ #include "gt/intel_sa_media.h" #include "gem/i915_gem_object_types.h" +#include "i915_cache.h" #include "i915_driver.h" #include "i915_drv.h" #include "i915_pci.h"@@ -46,36 +47,42 @@ __diag_ignore_all("-Woverride-init", "Allowoverriding inherited members");
Quoted 3 lines
drivers/gpu/drm/i915/i915_pci.c +0
-0.__runtime.graphics.ip.ver = (x), \ .__runtime.media.ip.ver = (x)
Quoted 16 lines
drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); · line 51
Quoted 8 lines
drivers/gpu/drm/i915/i915_pci.c +2
-6-#define LEGACY_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 0, \ - [I915_CACHE_LLC] = 1, \ - [I915_CACHE_L3_LLC] = 2, \ - [I915_CACHE_WT] = 3, \ +/* TODO/QQQ index 1 & 2 */ +#define LEGACY_CACHE_MODES \I was thinking to just put the PAT settings here, instead of
cache_modes, simply .pat = {\
GEN8_PPAT_WB, \
GEN8_PPAT_WC, \
GEN8_PPAT_WT, \
GEN8_PPAT_UC,
}
Also discussed above - I want to be able to have a functioning platform agnostic "has cache mode" helper and I think this would not help.
Quoted 225 lines
Quoted 29 lines
drivers/gpu/drm/i915/i915_pci.c +12
-12+ .cache_modes = { \ + [0] = I915_CACHE(UC), \ + [1] = I915_CACHE(WB), \ + [2] = _I915_CACHE(WB, L3), \ + [3] = I915_CACHE(WT), \ } -#define TGL_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 3, \ - [I915_CACHE_LLC] = 0, \ - [I915_CACHE_L3_LLC] = 0, \ - [I915_CACHE_WT] = 2, \ +#define GEN12_CACHE_MODES \ + .cache_modes = { \ + [0] = I915_CACHE(WB), \ + [1] = I915_CACHE(WC), \ + [2] = I915_CACHE(WT), \ + [3] = I915_CACHE(UC), \ } -#define PVC_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 0, \ - [I915_CACHE_LLC] = 3, \ - [I915_CACHE_L3_LLC] = 3, \ - [I915_CACHE_WT] = 2, \ +#define PVC_CACHE_MODES \drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); · line 77
Quoted 10 lines
drivers/gpu/drm/i915/i915_pci.c +9
-0+ .cache_modes = { \ + [0] = I915_CACHE(UC), \ + [1] = I915_CACHE(WC), \ + [2] = I915_CACHE(WT), \ + [3] = I915_CACHE(WB), \ + [4] = _I915_CACHE(WT, CLOS1), \ + [5] = _I915_CACHE(WB, CLOS1), \ + [6] = _I915_CACHE(WT, CLOS2), \ + [7] = _I915_CACHE(WB, CLOS2), \ }.pat = {\
GEN8_PPAT_UC, \
GEN8_PPAT_WC, \
GEN8_PPAT_WT, \
GEN8_PPAT_WB, \GEN12_PPAT_CLOS(1) | GEN8_PPAT_WT, \ GEN12_PPAT_CLOS(1) | GEN8_PPAT_WB, \ GEN12_PPAT_CLOS(2) | GEN8_PPAT_WT, \ GEN12_PPAT_CLOS(2) | GEN8_PPAT_WB, \}
Quoted 5 lines
drivers/gpu/drm/i915/i915_pci.c +0
-4-#define MTL_CACHELEVEL \ - .cachelevel_to_pat = { \ - [I915_CACHE_NONE] = 2, \ - [I915_CACHE_LLC] = 3, \drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow overriding inherited members"); · line 86
Quoted 10 lines
drivers/gpu/drm/i915/i915_pci.c +7
-2- [I915_CACHE_L3_LLC] = 3, \ - [I915_CACHE_WT] = 1, \ +#define MTL_CACHE_MODES \ + .cache_modes = { \ + [0] = I915_CACHE(WB), \ + [1] = I915_CACHE(WT), \ + [2] = I915_CACHE(UC), \ + [3] = _I915_CACHE(WB, COH1W), \ + [4] = _I915_CACHE(WB, COH2W), \ }.pat = {\
MTL_PPAT_L4_0_WB, \
MTL_PPAT_L4_1_WT, \
MTL_PPAT_L4_3_UC, \
MTL_PPAT_L4_0_WB |MTL_2_COH_1W, \
MTL_PPAT_L4_0_WB |MTL_3_COH_2W, \
}drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow
Quoted 2 lines
drivers/gpu/drm/i915/i915_pci.c +0
-0/* Keep in gen based order, and chronological order within a gen */@@ -100,7 +107,7 @@ __diag_ignore_all("-Woverride-init", "Allowoverriding inherited members");
drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow
Quoted 9 lines
drivers/gpu/drm/i915/i915_pci.c +1
-1.max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES #define I845_FEATURES \ GEN(2), \@@ -115,7 +122,7 @@ __diag_ignore_all("-Woverride-init", "Allowoverriding inherited members");
drivers/gpu/drm/i915/i915_pci.c static const struct intel_device_info
Quoted 45 lines
drivers/gpu/drm/i915/i915_pci.c +5
-5.max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info i830_info = { I830_FEATURES,@@ -148,7 +155,7 @@ static const struct intel_device_info i865g_info = { .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info i915g_info = { GEN3_FEATURES,@@ -211,7 +218,7 @@ static const struct intel_device_info pnv_m_info = { .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info i965g_info = { GEN4_FEATURES,@@ -255,7 +262,7 @@ static const struct intel_device_info gm45_info = { .max_pat_index = 3, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info ilk_d_info = { GEN5_FEATURES,@@ -285,7 +292,7 @@ static const struct intel_device_info ilk_m_info = { .__runtime.ppgtt_size = 31, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES #define SNB_D_PLATFORM \ GEN6_FEATURES, \@@ -333,7 +340,7 @@ static const struct intel_device_info
snb_m_gt2_info= {drivers/gpu/drm/i915/i915_pci.c static const struct intel_device_info
Quoted 27 lines
drivers/gpu/drm/i915/i915_pci.c +3
-3.__runtime.ppgtt_size = 31, \ GEN_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES #define IVB_D_PLATFORM \ GEN7_FEATURES, \@@ -390,7 +397,7 @@ static const struct intel_device_info vlv_info = { .__runtime.platform_engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), GEN_DEFAULT_PAGE_SIZES, GEN_DEFAULT_REGIONS, - LEGACY_CACHELEVEL, + LEGACY_CACHE_MODES }; #define G75_FEATURES \@@ -476,7 +483,7 @@ static const struct intel_device_info chv_info = { .has_coherent_ggtt = false, GEN_DEFAULT_PAGE_SIZES, GEN_DEFAULT_REGIONS, - LEGACY_CACHELEVEL, + LEGACY_CACHE_MODES }; #define GEN9_DEFAULT_PAGE_SIZES \@@ -539,7 +546,7 @@ static const struct intel_device_info
skl_gt4_info= {Review
Quoted 45 lines
drivers/gpu/drm/i915/i915_pci.c +2
-2.max_pat_index = 3, \ GEN9_DEFAULT_PAGE_SIZES, \ GEN_DEFAULT_REGIONS, \ - LEGACY_CACHELEVEL + LEGACY_CACHE_MODES static const struct intel_device_info bxt_info = { GEN9_LP_FEATURES,@@ -643,7 +650,7 @@ static const struct intel_device_info jsl_info = { #define GEN12_FEATURES \ GEN11_FEATURES, \ GEN(12), \ - TGL_CACHELEVEL, \ + GEN12_CACHE_MODES, \ .has_global_mocs = 1, \ .has_pxp = 1, \.max_pat_index = 3
drivers/gpu/drm/i915/i915_pci.c +1
-1@@ -711,7 +718,7 @@ static const struct intel_device_info adl_p_info = { .__runtime.graphics.ip.ver = 12, \ .__runtime.graphics.ip.rel = 50, \ XE_HP_PAGE_SIZES, \ - TGL_CACHELEVEL, \ + GEN12_CACHE_MODES, \ .dma_mask_size = 46, \ .has_3d_pipeline = 1, \ .has_64bit_reloc = 1, \@@ -806,7 +813,7 @@ static const struct intel_device_info pvc_info = {BIT(VCS0) |
BIT(CCS0) | BIT(CCS1) | BIT(CCS2) | BIT(CCS3), .require_force_probe = 1,
- PVC_CACHELEVEL,
+ PVC_CACHE_MODES
};static const struct
intel_gt_definitionxelpmp_extra_gt[] = {drivers/gpu/drm/i915/i915_pci.c +1
-1@@ -841,7 +848,7 @@ static const struct intel_device_info mtl_info = { .__runtime.memory_regions = REGION_SMEM | REGION_STOLEN_LMEM, .__runtime.platform_engine_mask = BIT(RCS0) | BIT(BCS0) | BIT(CCS0), .require_force_probe = 1, - MTL_CACHELEVEL, + MTL_CACHE_MODES }; #undef PLATFORM(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_device_info.hQuoted 16 lines
index
069291b3bd37..5cbae7c2ee30100644drivers/gpu/drm/i915/intel_device_info.h +2
-0@@ -27,6 +27,8 @@ #include <uapi/drm/i915_drm.h> +#include "i915_cache.h" + #include "intel_step.h" #include "display/intel_display_device.h"@@ -248,8 +250,8 @@ struct intel_device_info {*/ const struct intel_runtime_info __runtime;
Quoted 7 lines
drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 253
Quoted 3 lines
drivers/gpu/drm/i915/intel_device_info.h +1
-2- u32 cachelevel_to_pat[I915_MAX_CACHE_LEVEL]; - u32 max_pat_index; + i915_cache_t cache_modes[9];u32 pat[16];
See https://gfxspecs.intel.com/Predator/Home/Index/63019, there are PAT[3..0]
What do you mean by this?
Anyway I am waiting for Jani to merge the mock_gem_device cleanup patch before I rebase and send v2 to intel-gfx. Until then you can have a peek on trybot.
Regards,
Tvrtko
Quoted 138 lines
-Fei
Review
Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +1
-0+ unsigned int max_pat_index; }; struct intel_driver_caps {(quoted diff) +0
-0
b/drivers/gpu/drm/i915/selftests/i915_gem.cdrivers/gpu/drm/i915/selftests/i915_gem.c static void trash_stolen(struct drm_i915_private
Quoted 4 lines
index
61da4ed9d521..e620f73793a5100644drivers/gpu/drm/i915/selftests/i915_gem.c +0
-0@@ -57,10 +57,7 @@ static void trash_stolen(struct drm_i915_private*i915)
Review
Quoted 12 lines
drivers/gpu/drm/i915/selftests/i915_gem.c +1
-4u32 __iomem *s; int x; - ggtt->vm.insert_page(&ggtt->vm, dma, slot, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), - 0); + ggtt->vm.insert_page(&ggtt->vm, dma, slot, i915->pat_uc, 0); s = io_mapping_map_atomic_wc(&ggtt->iomap, slot); for (x = 0; x < PAGE_SIZE / sizeof(u32); x++) {(quoted diff) +0
-0
b/drivers/gpu/drm/i915/selftests/i915_gem_evict.cReview
Quoted 22 lines
index
f8fe3681c3dc..658a5b59545e100644drivers/gpu/drm/i915/selftests/i915_gem_evict.c +2
-2@@ -246,7 +246,7 @@ static int igt_evict_for_cache_color(void *arg) struct drm_mm_node target = { .start = I915_GTT_PAGE_SIZE * 2, .size = I915_GTT_PAGE_SIZE, - .color = i915_gem_get_pat_index(gt->i915, I915_CACHE_LLC), + .color = I915_CACHE(WB), }; struct drm_i915_gem_object *obj; struct i915_vma *vma;@@ -309,7 +309,7 @@ static int igt_evict_for_cache_color(void *arg) /* Attempt to remove the first *pinned* vma, by removing the (empty) * neighbour -- this should fail. */ - target.color = i915_gem_get_pat_index(gt->i915, I915_CACHE_L3_LLC); + target.color = _I915_CACHE(WB, LLC); mutex_lock(&ggtt->vm.mutex); err = i915_gem_evict_for_node(&ggtt->vm, NULL, &target, 0);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.cdrivers/gpu/drm/i915/selftests/i915_gem_gtt.c fake_dma_object(struct drm_i915_private *i915,
Quoted 4 lines
index
5c397a2df70e..a24585784f75100644drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +0
-0@@ -135,7 +135,7 @@ fake_dma_object(struct drm_i915_private *i915,u64 size)
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c static int lowlevel_hole(struct
Quoted 9 lines
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1
-1obj->write_domain = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU; - obj->pat_index = i915_gem_get_pat_index(i915, I915_CACHE_NONE); + obj->pat_index = i915->pat_uc; /* Preallocate the "backing storage" */ if (i915_gem_object_pin_pages_unlocked(obj))@@ -358,10 +358,8 @@ static int lowlevel_hole(struct
i915_address_space*vm,Review
Quoted 25 lines
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +3
-8mock_vma_res->start = addr; with_intel_runtime_pm(vm->gt->uncore->rpm, wakeref) - vm->insert_entries(vm, mock_vma_res, - i915_gem_get_pat_index(vm->i915, - I915_CACHE_NONE), - 0); + vm->insert_entries(vm, mock_vma_res, + vm->i915->pat_uc, 0); } count = n;@@ -1379,10 +1377,7 @@ static int igt_ggtt_page(void *arg) ggtt->vm.insert_page(&ggtt->vm, i915_gem_object_get_dma_address(obj, 0), - offset, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), - 0); + offset, ggtt->vm.i915->pat_uc, 0); } order = i915_random_order(count, &prng);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/selftests/intel_memory_region.cReview
Quoted 15 lines
index
d985d9bae2e8..b82fe0ef8cd7100644drivers/gpu/drm/i915/selftests/intel_memory_region.c +1
-3@@ -1070,9 +1070,7 @@ static int igt_lmem_write_cpu(void *arg) /* Put the pages into a known state -- from the gpu for added fun */ intel_engine_pm_get(engine); err = intel_context_migrate_clear(engine->gt->migrate.context, NULL, - obj->mm.pages->sgl, - i915_gem_get_pat_index(i915, - I915_CACHE_NONE), + obj->mm.pages->sgl, i915->pat_uc, true, 0xdeadbeaf, &rq); if (rq) { dma_resv_add_fence(obj->base.resv, &rq->fence,(quoted diff) +0
-0
b/drivers/gpu/drm/i915/selftests/mock_gem_device.cQuoted 18 lines
index
09d4bbcdcdbf..ad778842cba2100644drivers/gpu/drm/i915/selftests/mock_gem_device.c +6
-1@@ -126,7 +126,12 @@ struct drm_i915_private *mock_gem_device(void) struct drm_i915_private *i915; struct intel_device_info *i915_info; struct pci_dev *pdev; - unsigned int i; + static const i915_cache_t legacy_cache_modes[] = { + [0] = I915_CACHE(UC), + [1] = I915_CACHE(WB), + [2] = _I915_CACHE(WB, L3), + [3] = I915_CACHE(WT), + }; int ret; pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);drivers/gpu/drm/i915/selftests/mock_gem_device.c struct drm_i915_private *mock_gem_device(void) · line 195
Quoted 6 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c +1
-2@@ -187,8 +192,7 @@ struct drm_i915_private *mock_gem_device(void) /* simply use legacy cache level for mock device */ i915_info = (struct intel_device_info *)INTEL_INFO(i915); i915_info->max_pat_index = 3; - for (i = 0; i < I915_MAX_CACHE_LEVEL; i++) - i915_info->cachelevel_to_pat[i] = i; + memcpy(i915_info->cache_modes, legacy_cache_modes,
sizeof(legacy_cache_modes));Quoted 5 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c +0
-1intel_memory_regions_hw_probe(i915); --2.39.2