Skip to contentSkip to conversation

drm/i915: Refactor PAT/cache handling

PATCH In review Tvrtko Ursulin 3 participants 10 messages Jun 29, 2023 – Jul 7, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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/display/intel_dpt.c      |   2 +-
 drivers/gpu/drm/i915/display/intel_fb_pin.c   |   2 +-
 .../drm/i915/display/intel_plane_initial.c    |   4 +-
 drivers/gpu/drm/i915/gem/i915_gem_domain.c    |  66 +++++-----
 drivers/gpu/drm/i915/gem/i915_gem_domain.h    |   7 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  13 +-
 drivers/gpu/drm/i915/gem/i915_gem_internal.c  |   6 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.c    | 116 +++++++++--------
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   9 +-
 .../gpu/drm/i915/gem/i915_gem_object_types.h  | 117 +++---------------
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |  13 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c  |  43 ++++---
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   2 +-
 .../drm/i915/gem/selftests/huge_gem_object.c  |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   8 +-
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   4 +-
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c          |  19 +--
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   2 +-
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |  33 ++---
 drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c     |   4 +-
 drivers/gpu/drm/i915/gt/intel_gtt.c           |   2 +-
 drivers/gpu/drm/i915/gt/intel_gtt.h           |   3 +-
 drivers/gpu/drm/i915/gt/intel_migrate.c       |  11 +-
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   6 +-
 .../gpu/drm/i915/gt/intel_ring_submission.c   |   2 +-
 drivers/gpu/drm/i915/gt/intel_timeline.c      |   2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |   2 +-
 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   |   1 +
 drivers/gpu/drm/i915/gt/selftest_tlb.c        |   5 +-
 .../gpu/drm/i915/gt/selftest_workarounds.c    |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c      |   8 +-
 drivers/gpu/drm/i915/i915_cache.c             |  72 +++++++++++
 drivers/gpu/drm/i915/i915_cache.h             |  49 ++++++++
 drivers/gpu/drm/i915/i915_debugfs.c           |  65 +++-------
 drivers/gpu/drm/i915/i915_driver.c            |   5 +
 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/i915_perf.c              |   2 +-
 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   |   8 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  13 +-
 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   2 +-
 .../drm/i915/selftests/intel_memory_region.c  |   4 +-
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  12 +-
 drivers/gpu/drm/i915/selftests/mock_region.c  |   2 +-
 54 files changed, 440 insertions(+), 485 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
index 2be9dd960540..2c3da8f0c78e 100644
@@ -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/display/intel_dpt.c +1 -1
index 7c5fddb203ba..5baf0d27a288 100644
@@ -268,7 +268,7 @@ intel_dpt_create(struct intel_framebuffer *fb)
 
 	ret = i915_gem_object_lock_interruptible(dpt_obj, NULL);
 	if (!ret) {
-		ret = i915_gem_object_set_cache_level(dpt_obj, I915_CACHE_NONE);
+		ret = i915_gem_object_set_cache(dpt_obj, I915_CACHE(UC));
 		i915_gem_object_unlock(dpt_obj);
 	}
 	if (ret) {
drivers/gpu/drm/i915/display/intel_fb_pin.c +1 -1
index fffd568070d4..dcf54b354a74 100644
@@ -66,7 +66,7 @@ intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
 				continue;
 		}
 
-		ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+		ret = i915_gem_object_set_cache(obj, I915_CACHE(UC));
 		if (ret)
 			continue;
 
drivers/gpu/drm/i915/display/intel_plane_initial.c +2 -2
index 736072a8b2b0..9988f6562392 100644
@@ -121,8 +121,8 @@ initial_plane_vma(struct drm_i915_private *i915,
 	 * cache_level during fbdev initialization. The
 	 * unbind there would get stuck waiting for rcu.
 	 */
-	i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
-					    I915_CACHE_WT : I915_CACHE_NONE);
+	i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ? I915_CACHE(WT) :
+								I915_CACHE(UC));
 
 	switch (plane_config->tiling) {
 	case I915_TILING_NONE:
drivers/gpu/drm/i915/gem/i915_gem_domain.c +34 -32

140 lines not on this page · raw message

drivers/gpu/drm/i915/gem/i915_gem_domain.h +4 -3
index 9622df962bfc..d07926758b36 100644
@@ -6,10 +6,11 @@
 #ifndef __I915_GEM_DOMAIN_H__
 #define __I915_GEM_DOMAIN_H__
 
+#include "i915_cache.h"
+
 struct drm_i915_gem_object;
-enum i915_cache_level;
 
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-				    enum i915_cache_level cache_level);
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+			      i915_cache_t cache);
 
 #endif /* __I915_GEM_DOMAIN_H__ */
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -11
index d3208a325614..ee85221fa6eb 100644
@@ -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_internal.c +3 -3
index 6bc26b4b06b8..7e7bfe7da76f 100644
@@ -142,7 +142,6 @@ __i915_gem_object_create_internal(struct drm_i915_private *i915,
 {
 	static struct lock_class_key lock_class;
 	struct drm_i915_gem_object *obj;
-	unsigned int cache_level;
 
 	GEM_BUG_ON(!size);
 	GEM_BUG_ON(!IS_ALIGNED(size, PAGE_SIZE));
@@ -170,8 +169,9 @@ __i915_gem_object_create_internal(struct drm_i915_private *i915,
 	obj->read_domains = I915_GEM_DOMAIN_CPU;
 	obj->write_domain = I915_GEM_DOMAIN_CPU;
 
-	cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-	i915_gem_object_set_cache_coherency(obj, cache_level);
+	i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+						 I915_CACHE(WB) :
+						 I915_CACHE(UC));
 
 	return obj;
 }
drivers/gpu/drm/i915/gem/i915_gem_mman.c +4 -6
index aa4d842d4c5a..5e21aedb02d2 100644
@@ -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 +62 -54

155 lines not on this page · raw message

drivers/gpu/drm/i915/gem/i915_gem_object.h +4 -5
index 884a17275b3a..c852e59aeef9 100644
@@ -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,6 @@ 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);
 void i915_gem_init__objects(struct drm_i915_private *i915);
 
 void i915_objects_module_exit(void);
@@ -764,8 +761,10 @@ 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);
 
+int i915_gem_object_has_cache_mode(const struct drm_i915_gem_object *obj,
+				   enum i915_cache_mode mode);
 void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
-					 unsigned int cache_level);
+					 i915_cache_t cache);
 void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj,
 				   unsigned int pat_index);
 bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj);
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +14 -103

188 lines not on this page · raw message

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +5 -5
index 33d5d5178103..538b3029de35 100644
@@ -375,7 +375,7 @@ __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,
 	 * On non-LLC igfx platforms, force the flush-on-acquire if this is ever
 	 * swapped-in. Our async flush path is not trust worthy enough yet(and
 	 * happens in the wrong order), and with some tricks it's conceivable
-	 * for userspace to change the cache-level to I915_CACHE_NONE after the
+	 * for userspace to change the cache-level to I915_CACHE(UC) after the
 	 * pages are swapped-in, and since execbuf binds the object before doing
 	 * the async flush, we have a race window.
 	 */
@@ -577,7 +577,7 @@ static int shmem_object_init(struct intel_memory_region *mem,
 	static struct lock_class_key lock_class;
 	struct drm_i915_private *i915 = mem->i915;
 	struct address_space *mapping;
-	unsigned int cache_level;
+	i915_cache_t cache;
 	gfp_t mask;
 	int ret;
 
@@ -621,11 +621,11 @@ static int shmem_object_init(struct intel_memory_region *mem,
 		 * However, we maintain the display planes as UC, and so
 		 * need to rebind when first used as such.
 		 */
-		cache_level = I915_CACHE_LLC;
+		cache = I915_CACHE(WB);
 	else
-		cache_level = I915_CACHE_NONE;
+		cache = I915_CACHE(UC);
 
-	i915_gem_object_set_cache_coherency(obj, cache_level);
+	i915_gem_object_set_cache_coherency(obj, cache);
 
 	i915_gem_object_init_memory_region(obj, mem);
 
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +5 -8
index 3b094d36a0b0..e3a3b824a536 100644
@@ -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,
@@ -679,7 +676,6 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,
 					   struct drm_mm_node *stolen)
 {
 	static struct lock_class_key lock_class;
-	unsigned int cache_level;
 	unsigned int flags;
 	int err;
 
@@ -694,8 +690,9 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,
 
 	obj->stolen = stolen;
 	obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
-	cache_level = HAS_LLC(mem->i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-	i915_gem_object_set_cache_coherency(obj, cache_level);
+	i915_gem_object_set_cache_coherency(obj, HAS_LLC(mem->i915) ?
+						 I915_CACHE(WB) :
+						 I915_CACHE(UC));
 
 	if (WARN_ON(!i915_gem_object_trylock(obj, NULL)))
 		return -EBUSY;
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +25 -18

104 lines not on this page · raw message

drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1 -1
index 1d3ebdf4069b..7d50d43dfbfa 100644
@@ -553,7 +553,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
 	obj->mem_flags = I915_BO_FLAG_STRUCT_PAGE;
 	obj->read_domains = I915_GEM_DOMAIN_CPU;
 	obj->write_domain = I915_GEM_DOMAIN_CPU;
-	i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
 	obj->userptr.ptr = args->user_ptr;
 	obj->userptr.notifier_seq = ULONG_MAX;
drivers/gpu/drm/i915/gem/selftests/huge_gem_object.c +3 -3
index bac957755068..ad7798d34c74 100644
@@ -104,7 +104,6 @@ huge_gem_object(struct drm_i915_private *i915,
 {
 	static struct lock_class_key lock_class;
 	struct drm_i915_gem_object *obj;
-	unsigned int cache_level;
 
 	GEM_BUG_ON(!phys_size || phys_size > dma_size);
 	GEM_BUG_ON(!IS_ALIGNED(phys_size, PAGE_SIZE));
@@ -123,8 +122,9 @@ huge_gem_object(struct drm_i915_private *i915,
 
 	obj->read_domains = I915_GEM_DOMAIN_CPU;
 	obj->write_domain = I915_GEM_DOMAIN_CPU;
-	cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-	i915_gem_object_set_cache_coherency(obj, cache_level);
+	i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+						 I915_CACHE(WB) :
+						 I915_CACHE(UC));
 	obj->scratch = phys_size;
 
 	return obj;
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +4 -4
index df6c9a84252c..060830c51c2f 100644
@@ -177,7 +177,6 @@ huge_pages_object(struct drm_i915_private *i915,
 {
 	static struct lock_class_key lock_class;
 	struct drm_i915_gem_object *obj;
-	unsigned int cache_level;
 
 	GEM_BUG_ON(!size);
 	GEM_BUG_ON(!IS_ALIGNED(size, BIT(__ffs(page_mask))));
@@ -200,8 +199,9 @@ huge_pages_object(struct drm_i915_private *i915,
 	obj->write_domain = I915_GEM_DOMAIN_CPU;
 	obj->read_domains = I915_GEM_DOMAIN_CPU;
 
-	cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-	i915_gem_object_set_cache_coherency(obj, cache_level);
+	i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+						 I915_CACHE(WB) :
+						 I915_CACHE(UC));
 
 	obj->mm.page_mask = page_mask;
 
@@ -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(UC));
 
 	return obj;
 }
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +1 -3
index c2bdc133c89a..fb69f667652a 100644
@@ -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 +6 -13
index f948d33e5ec5..bd5a7d295251 100644
@@ -16,11 +16,11 @@
 #include "intel_gtt.h"
 
 static u64 gen8_pde_encode(const dma_addr_t addr,
-			   const enum i915_cache_level level)
+			   const enum i915_cache_mode cache_mode)
 {
 	u64 pde = addr | GEN8_PAGE_PRESENT | GEN8_PAGE_RW;
 
-	if (level != I915_CACHE_NONE)
+	if (cache_mode != I915_CACHE_MODE_UC)
 		pde |= PPAT_CACHED_PDE;
 	else
 		pde |= PPAT_UNCACHED;
@@ -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++) {
@@ -874,7 +867,7 @@ static int gen8_init_scratch(struct i915_address_space *vm)
 		}
 
 		fill_px(obj, vm->scratch[i - 1]->encode);
-		obj->encode = gen8_pde_encode(px_dma(obj), I915_CACHE_NONE);
+		obj->encode = gen8_pde_encode(px_dma(obj), I915_CACHE_MODE_UC);
 
 		vm->scratch[i] = obj;
 	}
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -1
index 0aff5bb13c53..b1e846682cd9 100644
@@ -1103,7 +1103,7 @@ static int init_status_page(struct intel_engine_cs *engine)
 		return PTR_ERR(obj);
 	}
 
-	i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
 	vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
 	if (IS_ERR(vma)) {
drivers/gpu/drm/i915/gt/intel_ggtt.c +12 -21
index dd0ed941441a..05fafb076556 100644
@@ -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;
@@ -1013,11 +1011,6 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt)
 	return ggtt_probe_common(ggtt, size);
 }
 
-/*
- * For pre-gen8 platforms pat_index is the same as enum i915_cache_level,
- * so the switch-case statements in these PTE encode functions are still valid.
- * See translation table LEGACY_CACHELEVEL.
- */
 static u64 snb_pte_encode(dma_addr_t addr,
 			  unsigned int pat_index,
 			  u32 flags)
@@ -1025,11 +1018,11 @@ static u64 snb_pte_encode(dma_addr_t addr,
 	gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
 	switch (pat_index) {
-	case I915_CACHE_L3_LLC:
-	case I915_CACHE_LLC:
+	case 1:
+	case 2:
 		pte |= GEN6_PTE_CACHE_LLC;
 		break;
-	case I915_CACHE_NONE:
+	case 0:
 		pte |= GEN6_PTE_UNCACHED;
 		break;
 	default:
@@ -1046,13 +1039,13 @@ static u64 ivb_pte_encode(dma_addr_t addr,
 	gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
 	switch (pat_index) {
-	case I915_CACHE_L3_LLC:
+	case 2:
 		pte |= GEN7_PTE_CACHE_L3_LLC;
 		break;
-	case I915_CACHE_LLC:
+	case 1:
 		pte |= GEN6_PTE_CACHE_LLC;
 		break;
-	case I915_CACHE_NONE:
+	case 0:
 		pte |= GEN6_PTE_UNCACHED;
 		break;
 	default:
@@ -1071,7 +1064,7 @@ static u64 byt_pte_encode(dma_addr_t addr,
 	if (!(flags & PTE_READ_ONLY))
 		pte |= BYT_PTE_WRITEABLE;
 
-	if (pat_index != I915_CACHE_NONE)
+	if (pat_index)
 		pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES;
 
 	return pte;
@@ -1083,7 +1076,7 @@ static u64 hsw_pte_encode(dma_addr_t addr,
 {
 	gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
-	if (pat_index != I915_CACHE_NONE)
+	if (pat_index)
 		pte |= HSW_WB_LLC_AGE3;
 
 	return pte;
@@ -1096,9 +1089,9 @@ static u64 iris_pte_encode(dma_addr_t addr,
 	gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
 	switch (pat_index) {
-	case I915_CACHE_NONE:
+	case 0:
 		break;
-	case I915_CACHE_WT:
+	case 3:
 		pte |= HSW_WT_ELLC_LLC_AGE3;
 		break;
 	default:
@@ -1298,9 +1291,7 @@ bool i915_ggtt_resume_vm(struct i915_address_space *vm)
 		 */
 		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),
+				   obj ? obj->pat_index : vm->i915->pat_uc,
 				   was_bound);
 
 		if (obj) { /* only used during resume => exclusive access */
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c +2 -2
index 866c416afb73..fedf02c9ecb6 100644
@@ -21,7 +21,7 @@ static void gmch_ggtt_insert_page(struct i915_address_space *vm,
 				  unsigned int pat_index,
 				  u32 unused)
 {
-	unsigned int flags = (pat_index == I915_CACHE_NONE) ?
+	unsigned int flags = (pat_index == 0) ?
 		AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
 	intel_gmch_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags);
@@ -32,7 +32,7 @@ static void gmch_ggtt_insert_entries(struct i915_address_space *vm,
 				     unsigned int pat_index,
 				     u32 unused)
 {
-	unsigned int flags = (pat_index == I915_CACHE_NONE) ?
+	unsigned int flags = (pat_index == 0) ?
 		AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
 	intel_gmch_gtt_insert_sg_entries(vma_res->bi.pages, vma_res->start >> PAGE_SHIFT,
drivers/gpu/drm/i915/gt/intel_gtt.c +1 -1
index 126269a0d728..8729eb244d28 100644
@@ -676,7 +676,7 @@ __vm_create_scratch_for_read(struct i915_address_space *vm, unsigned long size)
 	if (IS_ERR(obj))
 		return ERR_CAST(obj);
 
-	i915_gem_object_set_cache_coherency(obj, I915_CACHING_CACHED);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
 	vma = i915_vma_instance(obj, vm, NULL);
 	if (IS_ERR(vma)) {
drivers/gpu/drm/i915/gt/intel_gtt.h +2 -1
index 7192a534a654..af4277c1d577 100644
@@ -636,7 +636,8 @@ void
 __set_pd_entry(struct i915_page_directory * const pd,
 	       const unsigned short idx,
 	       struct i915_page_table *pt,
-	       u64 (*encode)(const dma_addr_t, const enum i915_cache_level));
+	       u64 (*encode)(const dma_addr_t,
+			     const enum i915_cache_mode cache_mode));
 
 #define set_pd_entry(pd, idx, to) \
 	__set_pd_entry((pd), (idx), px_pt(to), gen8_pde_encode)
drivers/gpu/drm/i915/gt/intel_migrate.c +3 -8
index 6023288b0e2d..81f7834cc2db 100644
@@ -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/intel_ppgtt.c +4 -2
index 436756bfbb1a..3e461d4f3693 100644
@@ -98,14 +98,16 @@ void
 __set_pd_entry(struct i915_page_directory * const pd,
 	       const unsigned short idx,
 	       struct i915_page_table * const to,
-	       u64 (*encode)(const dma_addr_t, const enum i915_cache_level))
+	       u64 (*encode)(const dma_addr_t,
+			     const enum i915_cache_mode cache_mode))
 {
 	/* Each thread pre-pins the pd, and we may have a thread per pde. */
 	GEM_BUG_ON(atomic_read(px_used(pd)) > NALLOC * I915_PDES);
 
 	atomic_inc(px_used(pd));
 	pd->entry[idx] = to;
-	write_dma_entry(px_base(pd), idx, encode(px_dma(to), I915_CACHE_LLC));
+	write_dma_entry(px_base(pd), idx,
+			encode(px_dma(to), I915_CACHE_MODE_WB));
 }
 
 void
drivers/gpu/drm/i915/gt/intel_ring_submission.c +1 -1
index 3fd795c3263f..fc7781b47bbf 100644
@@ -551,7 +551,7 @@ alloc_context_vma(struct intel_engine_cs *engine)
 	 * later platforms don't have L3 control bits in the PTE.
 	 */
 	if (IS_IVYBRIDGE(i915))
-		i915_gem_object_set_cache_coherency(obj, I915_CACHE_L3_LLC);
+		i915_gem_object_set_cache_coherency(obj, _I915_CACHE(WB, L3));
 
 	vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
 	if (IS_ERR(vma)) {
drivers/gpu/drm/i915/gt/intel_timeline.c +1 -1
index b9640212d659..ceb2616fb8d9 100644
@@ -26,7 +26,7 @@ static struct i915_vma *hwsp_alloc(struct intel_gt *gt)
 	if (IS_ERR(obj))
 		return ERR_CAST(obj);
 
-	i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
 	vma = i915_vma_instance(obj, &gt->ggtt->vm, NULL);
 	if (IS_ERR(vma))
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
index 8b0d84f2aad2..f0baf86b6848 100644
@@ -64,7 +64,7 @@ static int hang_init(struct hang *h, struct intel_gt *gt)
 		goto err_hws;
 	}
 
-	i915_gem_object_set_cache_coherency(h->hws, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(h->hws, I915_CACHE(WB));
 	vaddr = i915_gem_object_pin_map_unlocked(h->hws, I915_MAP_WB);
 	if (IS_ERR(vaddr)) {
 		err = PTR_ERR(vaddr);
drivers/gpu/drm/i915/gt/selftest_migrate.c +3 -6
index 3def5ca72dec..a67ede65d816 100644
@@ -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
index 79aa6ac66ad2..327dc9294e0f 100644
@@ -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 +1 -0
index 39c3ec12df1a..87299158815f 100644
@@ -837,6 +837,7 @@ static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt,
 
 	/* keep the same cache settings as timeline */
 	i915_gem_object_set_pat_index(obj, tl->hwsp_ggtt->obj->pat_index);
+
 	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
index 3bd6b540257b..6049f01be219 100644
@@ -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/selftest_workarounds.c +1 -1
index 14a8b25b6204..900b4e19087f 100644
@@ -111,7 +111,7 @@ read_nonprivs(struct intel_context *ce)
 	if (IS_ERR(result))
 		return result;
 
-	i915_gem_object_set_cache_coherency(result, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(result, I915_CACHE(WB));
 
 	cs = i915_gem_object_pin_map_unlocked(result, I915_MAP_WB);
 	if (IS_ERR(cs)) {
drivers/gpu/drm/i915/gt/uc/intel_guc.c +1 -1
index 2eb891b270ae..3a862051423c 100644
@@ -749,7 +749,7 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
 	 * as WC on CPU side and UC (PAT index 2) on GPU side
 	 */
 	if (IS_METEORLAKE(gt->i915))
-		i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
+		i915_gem_object_set_cache_coherency(obj, I915_CACHE(UC));
 
 	vma = i915_vma_instance(obj, &gt->ggtt->vm, NULL);
 	if (IS_ERR(vma))
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +2 -6
index d408856ae4c0..e099414d624d 100644
@@ -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 +72 -0

72 lines not on this page · raw message

drivers/gpu/drm/i915/i915_cache.h new file +49 -0

49 lines not on this page · raw message

drivers/gpu/drm/i915/i915_debugfs.c +15 -50

83 lines not on this page · raw message

drivers/gpu/drm/i915/i915_driver.c +5 -0
index 294b022de22b..8663388a524f 100644
@@ -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"
@@ -240,6 +241,10 @@ static int i915_driver_early_probe(struct drm_i915_private *dev_priv)
 	i915_memcpy_init_early(dev_priv);
 	intel_runtime_pm_init_early(&dev_priv->runtime_pm);
 
+	ret = i915_cache_init(dev_priv);
+	if (ret < 0)
+		return ret;
+
 	ret = i915_workqueues_init(dev_priv);
 	if (ret < 0)
 		return ret;
drivers/gpu/drm/i915/i915_drv.h +3 -0
index a18013787c9f..462b076e2650 100644
@@ -250,6 +250,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
index b46d7a2dab1a..ef6d33c2c288 100644
@@ -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
index 92ca81f9feab..6a6f97aaec60 100644
@@ -1124,14 +1124,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/i915_perf.c +1 -1
index 0a111b281578..1b8e067f37dd 100644
@@ -1861,7 +1861,7 @@ static int alloc_oa_buffer(struct i915_perf_stream *stream)
 		return PTR_ERR(bo);
 	}
 
-	i915_gem_object_set_cache_coherency(bo, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(bo, I915_CACHE(WB));
 
 	/* PreHSW required 512K alignment, HSW requires 16M */
 	vma = i915_vma_instance(bo, &gt->ggtt->vm, NULL);
drivers/gpu/drm/i915/intel_device_info.h +4 -2
index dbfe6443457b..f48a21895a85 100644
@@ -27,6 +27,8 @@
 
 #include <uapi/drm/i915_drm.h>
 
+#include "i915_cache.h"
+
 #include "intel_step.h"
 
 #include "gt/intel_engine_types.h"
@@ -243,8 +245,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
index 61da4ed9d521..e620f73793a5 100644
@@ -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 +4 -4
index f8fe3681c3dc..862d3ba0e025 100644
@@ -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;
@@ -267,7 +267,7 @@ static int igt_evict_for_cache_color(void *arg)
 		err = PTR_ERR(obj);
 		goto cleanup;
 	}
-	i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 	quirk_add(obj, &objects);
 
 	vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
@@ -283,7 +283,7 @@ static int igt_evict_for_cache_color(void *arg)
 		err = PTR_ERR(obj);
 		goto cleanup;
 	}
-	i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 	quirk_add(obj, &objects);
 
 	/* Neighbouring; same colour - should fit */
@@ -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, L3);
 
 	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
index 5c397a2df70e..a24585784f75 100644
@@ -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/igt_spinner.c +1 -1
index 618d9386d554..d42d1bcffe21 100644
@@ -23,7 +23,7 @@ int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt)
 		err = PTR_ERR(spin->hws);
 		goto err;
 	}
-	i915_gem_object_set_cache_coherency(spin->hws, I915_CACHE_LLC);
+	i915_gem_object_set_cache_coherency(spin->hws, I915_CACHE(WB));
 
 	spin->obj = i915_gem_object_create_internal(gt->i915, PAGE_SIZE);
 	if (IS_ERR(spin->obj)) {
drivers/gpu/drm/i915/selftests/intel_memory_region.c +1 -3
index d985d9bae2e8..b82fe0ef8cd7 100644
@@ -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 +6 -6
index 12aa7fbb0748..f478a4102299 100644
@@ -126,13 +126,13 @@ static const struct intel_device_info mock_info = {
 	.memory_regions = REGION_SMEM,
 	.platform_engine_mask = BIT(0),
 
-	/* simply use legacy cache level for mock device */
+	/* Simply use legacy cache modes for the mock device. */
 	.max_pat_index = 3,
-	.cachelevel_to_pat = {
-		[I915_CACHE_NONE]   = 0,
-		[I915_CACHE_LLC]    = 1,
-		[I915_CACHE_L3_LLC] = 2,
-		[I915_CACHE_WT]     = 3,
+	.cache_modes = {
+		[0] = I915_CACHE(UC),
+		[1] = I915_CACHE(WB),
+		[2] = _I915_CACHE(WB, L3),
+		[3] = I915_CACHE(WT),
 	},
 };
 
drivers/gpu/drm/i915/selftests/mock_region.c +1 -1
index 6324eb32d4dd..8c16202e79cb 100644
@@ -77,7 +77,7 @@ static int mock_object_init(struct intel_memory_region *mem,
 
 	obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
 
-	i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
+	i915_gem_object_set_cache_coherency(obj, I915_CACHE(UC));
 
 	i915_gem_object_init_memory_region(obj, mem);
 
Signature · 1 line
2.39.2
#1 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Refactor PAT/cache handling (rev2)

== Series Details ==

== Series Details ==

Series: drm/i915: Refactor PAT/cache handling (rev2)
URL : https://patchwork.freedesktop.org/series/119982/
State : warning

== Summary ==

Error: dim checkpatch failed
bad38a5a74aa 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'
-:841: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #841: FILE: drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c:62:
+i915_ttm_cache_pat(struct drm_i915_private *i915, struct ttm_resource *res,
struct ttm_tt *ttm)

-:1481: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #1481:
new file mode 100644

-:1486: WARNING:SPDX_LICENSE_TAG: Missing or malformed SPDX-License-Identifier tag in line 1 #1486: FILE: drivers/gpu/drm/i915/i915_cache.c:1:
+/*

-:1487: WARNING:SPDX_LICENSE_TAG: Misplaced SPDX-License-Identifier tag - use line 1 instead #1487: FILE: drivers/gpu/drm/i915/i915_cache.c:2:
+ * SPDX-License-Identifier: MIT

-:1533: WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #1533: FILE: drivers/gpu/drm/i915/i915_cache.c:48:
+ static const char *mode_str[] = {

-:1539: WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #1539: FILE: drivers/gpu/drm/i915/i915_cache.c:54:
+ static const char *flag_str[] = {

-:1580: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #1580: FILE: drivers/gpu/drm/i915/i915_cache.h:17:
+#define I915_CACHE(mode) \
+ (i915_cache_t)(I915_CACHE_MODE_##mode)

-:1583: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #1583: FILE: drivers/gpu/drm/i915/i915_cache.h:20:
+#define _I915_CACHE(mode, flag) \
+ (i915_cache_t)((I915_CACHE_MODE_##mode) | \
+ (BIT(8 + I915_CACHE_FLAG_##flag)))

-:1587: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #1587: FILE: drivers/gpu/drm/i915/i915_cache.h:24:
+#define I915_CACHE_MODE(cache) \
+ (enum i915_cache_mode)(((i915_cache_t)(cache)) & 0xff)

-:1589: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #1589: FILE: drivers/gpu/drm/i915/i915_cache.h:26:
+#define I915_CACHE_FLAGS(cache) \
+ (unsigned int)((((i915_cache_t)(cache) & 0xff00)) >> 16)

-:1688: ERROR:CODE_INDENT: code indent should use tabs where possible #1688: FILE: drivers/gpu/drm/i915/i915_debugfs.c:160:
+ i915_cache_print(&p, INTEL_INFO(i915)->cache_modes[obj->pat_index]);$

-:1688: WARNING:LEADING_SPACE: please, no spaces at the start of a line #1688: FILE: drivers/gpu/drm/i915/i915_debugfs.c:160:
+ i915_cache_print(&p, INTEL_INFO(i915)->cache_modes[obj->pat_index]);$

total: 5 errors, 6 warnings, 1 checks, 1818 lines checked

#3 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915: Refactor PAT/cache handling (rev2)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: Refactor PAT/cache handling (rev2)
URL : https://patchwork.freedesktop.org/series/119982/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_13337 -> Patchwork_119982v2
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/index.html

Participating hosts (41 -> 40)
------------------------------

Missing (1): fi-snb-2520m

Known issues
------------

Here are the changes found in Patchwork_119982v2 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_module_load@load:
- bat-mtlp-6: [PASS][1] -> [ABORT][2] ([i915#8141])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/bat-mtlp-6/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/bat-mtlp-6/igt@[email protected]
- bat-mtlp-8: [PASS][3] -> [ABORT][4] ([i915#8141])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/bat-mtlp-8/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/bat-mtlp-8/igt@[email protected]

* igt@i915_selftest@live@execlists:
- fi-bsw-n3050: [PASS][5] -> [ABORT][6] ([i915#7911] / [i915#7913])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/fi-bsw-n3050/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/fi-bsw-n3050/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@migrate:
- bat-dg2-11: [PASS][7] -> [DMESG-WARN][8] ([i915#7699])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/bat-dg2-11/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/bat-dg2-11/igt@i915_selftest@[email protected]
- bat-atsm-1: [PASS][9] -> [DMESG-FAIL][10] ([i915#7699] / [i915#7913])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/bat-atsm-1/igt@i915_selftest@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/bat-atsm-1/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@reset:
- bat-rpls-2: [PASS][11] -> [ABORT][12] ([i915#4983] / [i915#7461] / [i915#7913] / [i915#8347])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/bat-rpls-2/igt@i915_selftest@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/bat-rpls-2/igt@i915_selftest@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc:
- fi-bsw-nick: NOTRUN -> [SKIP][13] ([fdo#109271]) +1 similar issue
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/fi-bsw-nick/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@execlists:
- fi-bsw-nick: [ABORT][14] ([i915#7913]) -> [PASS][15]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/fi-bsw-nick/igt@i915_selftest@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/fi-bsw-nick/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@gt_heartbeat:
- fi-apl-guc: [DMESG-FAIL][16] ([i915#5334]) -> [PASS][17]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/fi-apl-guc/igt@i915_selftest@live@gt_heartbeat.html
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/fi-apl-guc/igt@i915_selftest@live@gt_heartbeat.html

#### Warnings ####

* igt@kms_psr@primary_page_flip:
- bat-rplp-1: [SKIP][18] ([i915#1072]) -> [ABORT][19] ([i915#8442] / [i915#8668])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/bat-rplp-1/igt@kms_psr@primary_page_flip.html
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/bat-rplp-1/igt@kms_psr@primary_page_flip.html

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983
[i915#5334]: https://gitlab.freedesktop.org/drm/intel/issues/5334
[i915#7461]: https://gitlab.freedesktop.org/drm/intel/issues/7461
[i915#7699]: https://gitlab.freedesktop.org/drm/intel/issues/7699
[i915#7911]: https://gitlab.freedesktop.org/drm/intel/issues/7911
[i915#7913]: https://gitlab.freedesktop.org/drm/intel/issues/7913
[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_13337 -> Patchwork_119982v2

CI-20190529: 20190529
CI_DRM_13337: 6f8963ce33be65c67e53b16fa18325e12ab76861 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7356: 66452bb0118e8d3a78d054cef50a60a9858a00a9 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_119982v2: 6f8963ce33be65c67e53b16fa18325e12ab76861 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

ee038d013192 drm/i915: Refactor PAT/cache handling

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/index.html

#4 lore raw

[Intel-gfx] ✗ Fi.CI.IGT: failure for drm/i915: Refactor PAT/cache handling (rev2)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: Refactor PAT/cache handling (rev2)
URL : https://patchwork.freedesktop.org/series/119982/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_13337_full -> Patchwork_119982v2_full
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_119982v2_full absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_119982v2_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

Participating hosts (8 -> 9)
------------------------------

Additional (1): shard-rkl0

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_119982v2_full:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@mock@evict:
- shard-tglu: [PASS][1] -> [ABORT][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-tglu-5/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-tglu-7/igt@i915_selftest@[email protected]
- shard-glk: [PASS][3] -> [ABORT][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-glk3/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-glk9/igt@i915_selftest@[email protected]
- shard-dg2: [PASS][5] -> [ABORT][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-3/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-8/igt@i915_selftest@[email protected]
- shard-rkl: [PASS][7] -> [ABORT][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-rkl-2/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-3/igt@i915_selftest@[email protected]
- shard-apl: [PASS][9] -> [ABORT][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-apl2/igt@i915_selftest@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-apl7/igt@i915_selftest@[email protected]
- shard-snb: [PASS][11] -> [ABORT][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-snb1/igt@i915_selftest@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-snb6/igt@i915_selftest@[email protected]

* igt@syncobj_timeline@invalid-multi-wait-unsubmitted-signaled:
- shard-dg2: [PASS][13] -> [TIMEOUT][14] +1 similar issue
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-10/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-10/igt@[email protected]

#### Warnings ####

* igt@kms_ccs@pipe-a-random-ccs-data-y_tiled_gen12_mc_ccs:
- shard-dg2: [SKIP][15] ([i915#3689] / [i915#3886] / [i915#5354]) -> [TIMEOUT][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-10/igt@kms_ccs@pipe-a-random-ccs-data-y_tiled_gen12_mc_ccs.html
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-10/igt@kms_ccs@pipe-a-random-ccs-data-y_tiled_gen12_mc_ccs.html

* igt@kms_frontbuffer_tracking@fbc-2p-scndscrn-spr-indfb-draw-render:
- shard-dg2: [SKIP][17] ([i915#5354]) -> [TIMEOUT][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-10/igt@kms_frontbuffer_tracking@fbc-2p-scndscrn-spr-indfb-draw-render.html
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-10/igt@kms_frontbuffer_tracking@fbc-2p-scndscrn-spr-indfb-draw-render.html

#### Suppressed ####

The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.

* igt@i915_selftest@mock@evict:
- {shard-dg1}: [PASS][19] -> [ABORT][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg1-12/igt@i915_selftest@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg1-16/igt@i915_selftest@[email protected]

Known issues
------------

Here are the changes found in Patchwork_119982v2_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_barrier_race@remote-request@rcs0:
- shard-tglu: [PASS][21] -> [ABORT][22] ([i915#8178])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-tglu-4/igt@gem_barrier_race@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-tglu-5/igt@gem_barrier_race@[email protected]

* igt@gem_ctx_isolation@preservation-s3@vcs0:
- shard-apl: [PASS][23] -> [ABORT][24] ([i915#180])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-apl6/igt@gem_ctx_isolation@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-apl2/igt@gem_ctx_isolation@[email protected]

* igt@gem_exec_await@wide-contexts:
- shard-dg2: [PASS][25] -> [TIMEOUT][26] ([i915#5892])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-10/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-10/igt@[email protected]

* igt@gem_exec_balancer@full-pulse:
- shard-dg2: [PASS][27] -> [FAIL][28] ([i915#6032])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-8/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-10/igt@[email protected]

* igt@gem_exec_fair@basic-none@vcs0:
- shard-rkl: [PASS][29] -> [FAIL][30] ([i915#2842])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-rkl-1/igt@gem_exec_fair@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-2/igt@gem_exec_fair@[email protected]

* igt@gem_workarounds@suspend-resume:
- shard-dg2: [PASS][31] -> [FAIL][32] ([fdo#103375]) +1 similar issue
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-7/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-5/igt@[email protected]

* igt@i915_pm_lpsp@kms-lpsp@kms-lpsp-dp:
- shard-dg2: NOTRUN -> [SKIP][33] ([i915#1937] / [i915#4579])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-11/igt@i915_pm_lpsp@[email protected]

* igt@i915_pm_rpm@modeset-non-lpsp-stress-no-wait:
- shard-dg2: [PASS][34] -> [SKIP][35] ([i915#1397]) +2 similar issues
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-8/igt@[email protected]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-10/igt@[email protected]
- shard-rkl: [PASS][36] -> [SKIP][37] ([i915#1397])
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-rkl-6/igt@[email protected]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-7/igt@[email protected]

* igt@kms_cdclk@mode-transition@pipe-c-hdmi-a-3:
- shard-dg2: NOTRUN -> [SKIP][38] ([i915#4087]) +2 similar issues
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-1/igt@kms_cdclk@[email protected]

* igt@kms_cdclk@mode-transition@pipe-d-hdmi-a-3:
- shard-dg2: NOTRUN -> [SKIP][39] ([i915#4087] / [i915#4579])
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-1/igt@kms_cdclk@[email protected]

* igt@kms_color@deep-color:
- shard-dg2: NOTRUN -> [SKIP][40] ([i915#3555] / [i915#4579]) +1 similar issue
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-1/igt@[email protected]

* igt@kms_content_protection@srm@pipe-a-dp-2:
- shard-dg2: NOTRUN -> [TIMEOUT][41] ([i915#7173]) +1 similar issue
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-12/igt@kms_content_protection@[email protected]

* igt@kms_frontbuffer_tracking@fbc-stridechange:
- shard-dg2: [PASS][42] -> [FAIL][43] ([i915#6880]) +1 similar issue
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-7/igt@[email protected]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-11/igt@[email protected]

* igt@kms_hdr@bpc-switch-suspend:
- shard-rkl: NOTRUN -> [SKIP][44] ([i915#3555] / [i915#4579])
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-7/igt@[email protected]

* igt@kms_hdr@invalid-hdr:
- shard-rkl: NOTRUN -> [SKIP][45] ([i915#4579] / [i915#6953] / [i915#8228])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-1/igt@[email protected]

* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-nv12@pipe-a-hdmi-a-1:
- shard-snb: NOTRUN -> [SKIP][46] ([fdo#109271]) +11 similar issues
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-snb1/igt@kms_pipe_crc_basic@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc@pipe-a-dp-4:
- shard-dg2: NOTRUN -> [FAIL][47] ([fdo#103375])
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-11/igt@kms_pipe_crc_basic@[email protected]

* igt@kms_plane_scaling@plane-downscale-with-modifiers-factor-0-25@pipe-a-hdmi-a-2:
- shard-rkl: NOTRUN -> [SKIP][48] ([i915#5176]) +2 similar issues
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-6/igt@kms_plane_scaling@[email protected]

* igt@kms_plane_scaling@plane-downscale-with-modifiers-factor-0-25@pipe-b-hdmi-a-2:
- shard-rkl: NOTRUN -> [SKIP][49] ([i915#4579] / [i915#5176]) +2 similar issues
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-6/igt@kms_plane_scaling@[email protected]

* igt@kms_plane_scaling@plane-upscale-with-modifiers-20x20@pipe-b-hdmi-a-1:
- shard-snb: NOTRUN -> [SKIP][50] ([fdo#109271] / [i915#4579]) +6 similar issues
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-snb1/igt@kms_plane_scaling@[email protected]

* igt@kms_plane_scaling@planes-downscale-factor-0-25-unity-scaling@pipe-b-hdmi-a-3:
- shard-dg2: NOTRUN -> [SKIP][51] ([i915#5235]) +8 similar issues
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-8/igt@kms_plane_scaling@[email protected]

* igt@kms_plane_scaling@planes-downscale-factor-0-25@pipe-a-hdmi-a-1:
- shard-rkl: NOTRUN -> [SKIP][52] ([i915#5235])
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-7/igt@kms_plane_scaling@[email protected]

* igt@kms_plane_scaling@planes-downscale-factor-0-25@pipe-b-hdmi-a-1:
- shard-rkl: NOTRUN -> [SKIP][53] ([i915#4579] / [i915#5235])
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-7/igt@kms_plane_scaling@[email protected]

* igt@kms_plane_scaling@planes-upscale-20x20-downscale-factor-0-25@pipe-d-hdmi-a-3:
- shard-dg2: NOTRUN -> [SKIP][54] ([i915#4579] / [i915#5235]) +2 similar issues
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-1/igt@kms_plane_scaling@[email protected]

* igt@kms_sysfs_edid_timing:
- shard-dg2: [PASS][55] -> [FAIL][56] ([IGT#2])
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-11/igt@kms_sysfs_edid_timing.html
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-8/igt@kms_sysfs_edid_timing.html

* igt@perf@stress-open-close@0-rcs0:
- shard-glk: [PASS][57] -> [ABORT][58] ([i915#5213] / [i915#7941])
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-glk3/igt@perf@[email protected]
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-glk1/igt@perf@[email protected]

#### Possible fixes ####

* igt@drm_fdinfo@most-busy-idle-check-all@rcs0:
- shard-rkl: [FAIL][59] ([i915#7742]) -> [PASS][60] +1 similar issue
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-rkl-7/igt@drm_fdinfo@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-2/igt@drm_fdinfo@[email protected]

* igt@gem_barrier_race@remote-request@rcs0:
- {shard-dg1}: [ABORT][61] ([i915#7461] / [i915#8234]) -> [PASS][62]
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg1-18/igt@gem_barrier_race@[email protected]
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg1-12/igt@gem_barrier_race@[email protected]

* igt@gem_ctx_isolation@preservation-s3@vcs1:
- shard-dg2: [FAIL][63] ([fdo#103375]) -> [PASS][64] +3 similar issues
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-5/igt@gem_ctx_isolation@[email protected]
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-3/igt@gem_ctx_isolation@[email protected]

* igt@gem_eio@unwedge-stress:
- {shard-dg1}: [FAIL][65] ([i915#5784]) -> [PASS][66]
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg1-17/igt@[email protected]
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg1-13/igt@[email protected]

* igt@gem_exec_fair@basic-deadline:
- shard-glk: [FAIL][67] ([i915#2846]) -> [PASS][68]
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-glk4/igt@[email protected]
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-glk3/igt@[email protected]

* igt@gem_lmem_swapping@smem-oom@lmem0:
- shard-dg2: [TIMEOUT][69] ([i915#5493]) -> [PASS][70]
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-1/igt@gem_lmem_swapping@[email protected]
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-12/igt@gem_lmem_swapping@[email protected]

* igt@i915_pm_rc6_residency@rc6-idle@rcs0:
- {shard-dg1}: [FAIL][71] ([i915#3591]) -> [PASS][72] +1 similar issue
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg1-14/igt@i915_pm_rc6_residency@[email protected]
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg1-14/igt@i915_pm_rc6_residency@[email protected]

* igt@kms_flip@2x-flip-vs-expired-vblank@ac-hdmi-a1-hdmi-a2:
- shard-glk: [FAIL][73] ([i915#79]) -> [PASS][74]
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-glk9/igt@kms_flip@[email protected]
[74]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-glk7/igt@kms_flip@[email protected]

* igt@kms_frontbuffer_tracking@fbc-badstride:
- shard-dg2: [FAIL][75] ([i915#6880]) -> [PASS][76]
[75]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-10/igt@[email protected]
[76]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-11/igt@[email protected]

#### Warnings ####

* igt@kms_content_protection@type1:
- shard-dg2: [SKIP][77] ([i915#4579] / [i915#7118] / [i915#7162]) -> [SKIP][78] ([i915#4579] / [i915#7118])
[77]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-11/igt@[email protected]
[78]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-1/igt@[email protected]

* igt@kms_multipipe_modeset@basic-max-pipe-crc-check:
- shard-rkl: [SKIP][79] ([i915#4070] / [i915#4816]) -> [SKIP][80] ([i915#4816])
[79]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-rkl-2/igt@[email protected]
[80]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-rkl-3/igt@[email protected]

* igt@prime_mmap@test_aperture_limit@test_aperture_limit-smem:
- shard-dg2: [INCOMPLETE][81] ([i915#5493]) -> [CRASH][82] ([i915#7331])
[81]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13337/shard-dg2-3/igt@prime_mmap@test_aperture_limit@test_aperture_limit-smem.html
[82]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/shard-dg2-11/igt@prime_mmap@test_aperture_limit@test_aperture_limit-smem.html

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[IGT#2]: https://gitlab.freedesktop.org/drm/igt-gpu-tools/issues/2
[fdo#103375]: https://bugs.freedesktop.org/show_bug.cgi?id=103375
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#111615]: https://bugs.freedesktop.org/show_bug.cgi?id=111615
[fdo#111825]: https://bugs.freedesktop.org/show_bug.cgi?id=111825
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#1397]: https://gitlab.freedesktop.org/drm/intel/issues/1397
[i915#180]: https://gitlab.freedesktop.org/drm/intel/issues/180
[i915#1937]: https://gitlab.freedesktop.org/drm/intel/issues/1937
[i915#2842]: https://gitlab.freedesktop.org/drm/intel/issues/2842
[i915#2846]: https://gitlab.freedesktop.org/drm/intel/issues/2846
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3539]: https://gitlab.freedesktop.org/drm/intel/issues/3539
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3591]: https://gitlab.freedesktop.org/drm/intel/issues/3591
[i915#3689]: https://gitlab.freedesktop.org/drm/intel/issues/3689
[i915#3886]: https://gitlab.freedesktop.org/drm/intel/issues/3886
[i915#4070]: https://gitlab.freedesktop.org/drm/intel/issues/4070
[i915#4078]: https://gitlab.freedesktop.org/drm/intel/issues/4078
[i915#4079]: https://gitlab.freedesktop.org/drm/intel/issues/4079
[i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
[i915#4087]: https://gitlab.freedesktop.org/drm/intel/issues/4087
[i915#4579]: https://gitlab.freedesktop.org/drm/intel/issues/4579
[i915#4816]: https://gitlab.freedesktop.org/drm/intel/issues/4816
[i915#4852]: https://gitlab.freedesktop.org/drm/intel/issues/4852
[i915#5176]: https://gitlab.freedesktop.org/drm/intel/issues/5176
[i915#5213]: https://gitlab.freedesktop.org/drm/intel/issues/5213
[i915#5235]: https://gitlab.freedesktop.org/drm/intel/issues/5235
[i915#5289]: https://gitlab.freedesktop.org/drm/intel/issues/5289
[i915#5354]: https://gitlab.freedesktop.org/drm/intel/issues/5354
[i915#5493]: https://gitlab.freedesktop.org/drm/intel/issues/5493
[i915#5784]: https://gitlab.freedesktop.org/drm/intel/issues/5784
[i915#5892]: https://gitlab.freedesktop.org/drm/intel/issues/5892
[i915#6032]: https://gitlab.freedesktop.org/drm/intel/issues/6032
[i915#6095]: https://gitlab.freedesktop.org/drm/intel/issues/6095
[i915#6880]: https://gitlab.freedesktop.org/drm/intel/issues/6880
[i915#6953]: https://gitlab.freedesktop.org/drm/intel/issues/6953
[i915#7118]: https://gitlab.freedesktop.org/drm/intel/issues/7118
[i915#7162]: https://gitlab.freedesktop.org/drm/intel/issues/7162
[i915#7173]: https://gitlab.freedesktop.org/drm/intel/issues/7173
[i915#7331]: https://gitlab.freedesktop.org/drm/intel/issues/7331
[i915#7461]: https://gitlab.freedesktop.org/drm/intel/issues/7461
[i915#7742]: https://gitlab.freedesktop.org/drm/intel/issues/7742
[i915#7828]: https://gitlab.freedesktop.org/drm/intel/issues/7828
[i915#79]: https://gitlab.freedesktop.org/drm/intel/issues/79
[i915#7941]: https://gitlab.freedesktop.org/drm/intel/issues/7941
[i915#8178]: https://gitlab.freedesktop.org/drm/intel/issues/8178
[i915#8228]: https://gitlab.freedesktop.org/drm/intel/issues/8228
[i915#8234]: https://gitlab.freedesktop.org/drm/intel/issues/8234
[i915#8247]: https://gitlab.freedesktop.org/drm/intel/issues/8247
[i915#8708]: https://gitlab.freedesktop.org/drm/intel/issues/8708

Build changes
-------------

* Linux: CI_DRM_13337 -> Patchwork_119982v2

CI-20190529: 20190529
CI_DRM_13337: 6f8963ce33be65c67e53b16fa18325e12ab76861 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7356: 66452bb0118e8d3a78d054cef50a60a9858a00a9 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_119982v2: 6f8963ce33be65c67e53b16fa18325e12ab76861 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119982v2/index.html

#5 lore raw
In reply to Tvrtko Ursulin
Quoted 161 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..

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/display/intel_dpt.c      |   2 +-
 drivers/gpu/drm/i915/display/intel_fb_pin.c   |   2 +-
 .../drm/i915/display/intel_plane_initial.c    |   4 +-
 drivers/gpu/drm/i915/gem/i915_gem_domain.c    |  66 +++++-----
 drivers/gpu/drm/i915/gem/i915_gem_domain.h    |   7 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  13 +-
 drivers/gpu/drm/i915/gem/i915_gem_internal.c  |   6 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.c    | 116 +++++++++--------
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   9 +-
 .../gpu/drm/i915/gem/i915_gem_object_types.h  | 117 +++---------------
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |  13 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c  |  43 ++++---
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   2 +-
 .../drm/i915/gem/selftests/huge_gem_object.c  |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   8 +-
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   4 +-
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c          |  19 +--
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   2 +-
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |  33 ++---
 drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c     |   4 +-
 drivers/gpu/drm/i915/gt/intel_gtt.c           |   2 +-
 drivers/gpu/drm/i915/gt/intel_gtt.h           |   3 +-
 drivers/gpu/drm/i915/gt/intel_migrate.c       |  11 +-
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   6 +-
 .../gpu/drm/i915/gt/intel_ring_submission.c   |   2 +-
 drivers/gpu/drm/i915/gt/intel_timeline.c      |   2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |   2 +-
 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   |   1 +
 drivers/gpu/drm/i915/gt/selftest_tlb.c        |   5 +-
 .../gpu/drm/i915/gt/selftest_workarounds.c    |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c      |   8 +-
 drivers/gpu/drm/i915/i915_cache.c             |  72 +++++++++++
 drivers/gpu/drm/i915/i915_cache.h             |  49 ++++++++
 drivers/gpu/drm/i915/i915_debugfs.c           |  65 +++-------
 drivers/gpu/drm/i915/i915_driver.c            |   5 +
 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/i915_perf.c              |   2 +-
 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   |   8 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  13 +-
 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   2 +-
 .../drm/i915/selftests/intel_memory_region.c  |   4 +-
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  12 +-
 drivers/gpu/drm/i915/selftests/mock_region.c  |   2 +-
 54 files changed, 440 insertions(+), 485 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
index 2be9dd960540..2c3da8f0c78e 100644
@@ -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/display/intel_dpt.c +1 -1
index 7c5fddb203ba..5baf0d27a288 100644
@@ -268,7 +268,7 @@ intel_dpt_create(struct intel_framebuffer *fb)
 
         ret = i915_gem_object_lock_interruptible(dpt_obj, NULL);
         if (!ret) {
-               ret = i915_gem_object_set_cache_level(dpt_obj, I915_CACHE_NONE);
+               ret = i915_gem_object_set_cache(dpt_obj, I915_CACHE(UC));
                 i915_gem_object_unlock(dpt_obj);
         }
         if (ret) {
drivers/gpu/drm/i915/display/intel_fb_pin.c +1 -1
index fffd568070d4..dcf54b354a74 100644
@@ -66,7 +66,7 @@ intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
                                 continue;
                 }
 
-               ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+               ret = i915_gem_object_set_cache(obj, I915_CACHE(UC));
                 if (ret)
                         continue;
 
drivers/gpu/drm/i915/display/intel_plane_initial.c +2 -2
index 736072a8b2b0..9988f6562392 100644
@@ -121,8 +121,8 @@ initial_plane_vma(struct drm_i915_private *i915,
          * cache_level during fbdev initialization. The
          * unbind there would get stuck waiting for rcu.
          */
-       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
-                                           I915_CACHE_WT : I915_CACHE_NONE);
+       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ? I915_CACHE(WT) :
+                                                               I915_CACHE(UC));
 
         switch (plane_config->tiling) {
         case I915_TILING_NONE:
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
index dfaaa8b66ac3..f899da2c622a 100644
@@ -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;

This logic was changed for objects with pat index set by user here. It used to return false regardless the cache mode. But now it returns true if its cache mode is neither UC nor WT.

Quoted 35 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +6 -11
 }
 
 bool i915_gem_cpu_write_needs_clflush(struct drm_i915_gem_object *obj)
@@ -255,9 +249,9 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 }
 
 /**
- * i915_gem_object_set_cache_level - Changes the cache-level of an object across all VMA.
+ * i915_gem_object_set_cache - Changes the cache-level of an object across all VMA.
  * @obj: object to act on
- * @cache_level: new cache level to set for the object
+ * @cache: new caching mode to set for the object
  *
  * After this function returns, the object will be in the new cache-level
  * across all GTT and the contents of the backing storage will be coherent,
@@ -269,19 +263,28 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
  * cache coherency) and all non-MOCS GPU access will also be uncached so
  * that all direct access to the scanout remains coherent.
  */
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-                                   enum i915_cache_level cache_level)
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+                             i915_cache_t cache)
 {
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
         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))
+       ret = i915_cache_find_pat(i915, cache);

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 282

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +9 -0
+       if (ret < 0) {
+               struct drm_printer p =
+                       drm_err_printer("Attempting to use unknown caching mode ");
+
+               i915_cache_print(&p, cache);
+               drm_puts(&p, "!\n");
+
+               return -EINVAL;
+       } else if (ret == obj->pat_index) {
                 return 0;

We will have to do this conversion and checking again later in this function when calling i915_gem_object_set_cache_coherency().

My thought was to simply remove the use of cache_level/cache and replace it with pat_idex. Conversion from cache modes to pat index should be done before calling any function used to consume cache_level/cache.

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 283

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+       } else if (obj->pat_set_by_user) {

Shouldn't this if-statement be placed at the beginning of this function? the original i915_gem_object_has_cache_level() would return true if (obj->pat_set_by_user), so the function returns right away.

Quoted 17 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5 -1
+               drm_notice_once(&i915->drm,
+                               "Attempting to change caching mode on an object with fixed PAT!\n");
+               return -EINVAL;
+       }
 
         ret = i915_gem_object_wait(obj,
                                    I915_WAIT_INTERRUPTIBLE |
@@ -291,7 +294,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
                 return ret;
 
         /* Always invalidate stale cachelines */
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);
         obj->cache_dirty = true;
 
         /* The cache-level will be applied when each vma is rebound. */

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, · line 332

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -2
@@ -326,10 +329,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))

This looks wrong, at least for MTL. Prior to MTL the GPU automatically snoop CPU cache, but from MTL onward you have to specify if WB or WB + 1-WAY COH is needed. And for KMD, cacheable mode means WB + 1-WAY COH for MTL to keep the behavior consistent.

This used to be taken care of by i915_gem_get_pat_index() call. With that being replaced by i915_cache_find_pat(), you would need to do something there. But, without cachelevel_to_pat[], you might end up hard coding something directly in the function, and that is platform dependent. hmm..., I don't really like this idea.

That's why I commented in v1 that we should use INTEL_INFO(i915)->pat_uc/wb/wt instead of enum i915_cache_level or i915_cache_t.

Quoted 16 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -2
                 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;
@@ -344,7 +346,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
         struct drm_i915_private *i915 = to_i915(dev);
         struct drm_i915_gem_caching *args = data;
         struct drm_i915_gem_object *obj;
-       enum i915_cache_level level;
+       i915_cache_t cache;
         int ret = 0;
 
         if (IS_DGFX(i915))

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 360

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
@@ -355,7 +357,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 
         switch (args->caching) {
         case I915_CACHING_NONE:
-               level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);

For code like this, my thought was

- level = I915_CACHE_NONE;
+ pat_index = INTEL_INFO(i915)->pat_uc;

And later the set_cache call should take pat_index as argument instead of cache mode.

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 372

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                 break;
         case I915_CACHING_CACHED:
                 /*
@@ -367,10 +369,10 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
                 if (!HAS_LLC(i915) && !HAS_SNOOP(i915))
                         return -ENODEV;
 
-               level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);

- level = I915_CACHE_LLC;
+ pat_index = INTEL_INFO(i915)->pat_wb;

This should take care of the WB + 1-WAY COH issue for MTL mentioned above, assuming the i915_cache_init() set pat_wb properly, and the i915_gem_object_set_cache() consumes pat_index instead of cache mode.

Quoted 1,280 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5 -5
                 break;
         case I915_CACHING_DISPLAY:
-               level = HAS_WT(i915) ? I915_CACHE_WT : I915_CACHE_NONE;
+               cache = HAS_WT(i915) ? I915_CACHE(WT) : I915_CACHE(UC);
                 break;
         default:
                 return -EINVAL;
@@ -409,7 +411,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
         if (ret)
                 goto out;
 
-       ret = i915_gem_object_set_cache_level(obj, level);
+       ret = i915_gem_object_set_cache(obj, cache);
         i915_gem_object_unlock(obj);
 
 out:
@@ -448,9 +450,9 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
          * of uncaching, which would allow us to flush all the LLC-cached data
          * with that bit in the PTE to main memory with just one PIPE_CONTROL.
          */
-       ret = i915_gem_object_set_cache_level(obj,
-                                             HAS_WT(i915) ?
-                                             I915_CACHE_WT : I915_CACHE_NONE);
+       ret = i915_gem_object_set_cache(obj,
+                                       HAS_WT(i915) ?
+                                       I915_CACHE(WT) : I915_CACHE(UC));
         if (ret)
                 return ERR_PTR(ret);
 
drivers/gpu/drm/i915/gem/i915_gem_domain.h +4 -3
index 9622df962bfc..d07926758b36 100644
@@ -6,10 +6,11 @@
 #ifndef __I915_GEM_DOMAIN_H__
 #define __I915_GEM_DOMAIN_H__
 
+#include "i915_cache.h"
+
 struct drm_i915_gem_object;
-enum i915_cache_level;
 
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-                                   enum i915_cache_level cache_level);
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+                             i915_cache_t cache);
 
 #endif /* __I915_GEM_DOMAIN_H__ */
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -11
index d3208a325614..ee85221fa6eb 100644
@@ -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_internal.c +3 -3
index 6bc26b4b06b8..7e7bfe7da76f 100644
@@ -142,7 +142,6 @@ __i915_gem_object_create_internal(struct drm_i915_private *i915,
 {
         static struct lock_class_key lock_class;
         struct drm_i915_gem_object *obj;
-       unsigned int cache_level;
 
         GEM_BUG_ON(!size);
         GEM_BUG_ON(!IS_ALIGNED(size, PAGE_SIZE));
@@ -170,8 +169,9 @@ __i915_gem_object_create_internal(struct drm_i915_private *i915,
         obj->read_domains = I915_GEM_DOMAIN_CPU;
         obj->write_domain = I915_GEM_DOMAIN_CPU;
 
-       cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
 
         return obj;
 }
drivers/gpu/drm/i915/gem/i915_gem_mman.c +4 -6
index aa4d842d4c5a..5e21aedb02d2 100644
@@ -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 +62 -54
index d77a375871b7..2d3a58c62122 100644
@@ -45,33 +45,6 @@ static struct kmem_cache *slab_objects;
 
 static 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];
-}
-
-bool i915_gem_object_has_cache_level(const struct drm_i915_gem_object *obj,
-                                    enum i915_cache_level lvl)
-{
-       /*
-        * 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;
@@ -144,30 +117,70 @@ void __i915_gem_object_fini(struct drm_i915_gem_object *obj)
         dma_resv_fini(&obj->base._resv);
 }
 
+int i915_gem_object_has_cache_mode(const struct drm_i915_gem_object *obj,
+                                  enum i915_cache_mode mode)
+{
+       struct drm_i915_private *i915 = obj_to_i915(obj);
+       i915_cache_t cache = INTEL_INFO(i915)->cache_modes[obj->pat_index];
+
+       if (I915_CACHE_MODE(cache) == mode)
+               return 1;
+       else if (obj->pat_set_by_user)
+               return -1; /* Unknown, callers should assume no. */
+       else
+               return 0;
+}
+
+static void __i915_gem_object_update_coherency(struct drm_i915_gem_object *obj)
+{
+       struct drm_i915_private *i915 = obj_to_i915(obj);
+       i915_cache_t cache = INTEL_INFO(i915)->cache_modes[obj->pat_index];
+       unsigned int mode = I915_CACHE_MODE(cache);
+
+       if (mode == I915_CACHE_MODE_UNKNOWN) {
+               drm_notice_once(&i915->drm, "Undefined PAT index %u!\n",
+                               obj->pat_index);
+               obj->cache_coherent = 0;
+       } else  if (mode != I915_CACHE_MODE_UC) {
+               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_set_cache_coherency - Mark up the object's coherency levels
- * for a given cache_level
+ * for a given caching mode
  * @obj: #drm_i915_gem_object
- * @cache_level: cache level
+ * @cache: cache mode
  */
 void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
-                                        unsigned int cache_level)
+                                        i915_cache_t cache)
 {
-       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+       struct drm_i915_private *i915 = obj_to_i915(obj);
+       int found;
 
-       obj->pat_index = i915_gem_get_pat_index(i915, cache_level);
+       found = i915_cache_find_pat(i915, cache);
+       if (found < 0) {
+               struct drm_printer p =
+                       drm_err_printer("Unknown cache 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;
+               i915_cache_print(&p, cache);
+               drm_puts(&p, "!\n");
 
-       obj->cache_dirty =
-               !(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE) &&
-               !IS_DGFX(i915);
+               found = i915->pat_uc;
+       }
+
+       obj->pat_index = found;
+
+       __i915_gem_object_update_coherency(obj);
 }
 
 /**
@@ -181,24 +194,18 @@ void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
 void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj,
                                    unsigned int pat_index)
 {
-       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+       struct drm_i915_private *i915 = obj_to_i915(obj);
 
         if (obj->pat_index == pat_index)
                 return;
 
+       if (drm_WARN_ON_ONCE(&i915->drm,
+                            pat_index > INTEL_INFO(i915)->max_pat_index))
+               return;
+
         obj->pat_index = 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 +222,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 +4 -5
index 884a17275b3a..c852e59aeef9 100644
@@ -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,6 @@ 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);
 void i915_gem_init__objects(struct drm_i915_private *i915);
 
 void i915_objects_module_exit(void);
@@ -764,8 +761,10 @@ 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);
 
+int i915_gem_object_has_cache_mode(const struct drm_i915_gem_object *obj,
+                                  enum i915_cache_mode mode);
 void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
-                                        unsigned int cache_level);
+                                        i915_cache_t cache);
 void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj,
                                    unsigned int pat_index);
 bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj);
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +14 -103
index 8de2b91b3edf..a136d137b980 100644
@@ -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,
@@ -409,9 +323,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
@@ -426,7 +338,8 @@ struct drm_i915_gem_object {
          * i.e @cache_coherent is zero.
          *
          * On platforms that share the LLC with the CPU(HAS_LLC), all GT memory
-        * access will automatically snoop the CPU caches(even with CACHE_NONE).
+        * access will automatically snoop the CPU caches (even with
+        * I915_CACHE(UC)).
          * The one exception is when dealing with the display engine, like with
          * scanout surfaces. To handle this the kernel will always flush the
          * surface out of the CPU caches when preparing it for scanout.  Also
@@ -437,8 +350,8 @@ struct drm_i915_gem_object {
          * Something strange here is why @cache_coherent is not a simple
          * boolean, i.e coherent vs non-coherent. The reasoning for this is back
          * to the display engine not being fully coherent. As a result scanout
-        * surfaces will either be marked as I915_CACHE_NONE or I915_CACHE_WT.
-        * In the case of seeing I915_CACHE_NONE the kernel makes the assumption
+        * surfaces will either be marked as I915_CACHE(UC) or I915_CACHE(WT).
+        * In the case of seeing I915_CACHE(UC) the kernel makes the assumption
          * that this is likely a scanout surface, and will set @cache_coherent
          * as only I915_BO_CACHE_COHERENT_FOR_READ, on platforms with the shared
          * LLC. The kernel uses this to always flush writes through the CPU
@@ -447,7 +360,7 @@ struct drm_i915_gem_object {
          * flushing the surface just before doing the scanout.  This does mean
          * we might unnecessarily flush non-scanout objects in some places, but
          * the default assumption is that all normal objects should be using
-        * I915_CACHE_LLC, at least on platforms with the shared LLC.
+        * I915_CACHE(WB), at least on platforms with the shared LLC.
          *
          * Supported values:
          *
@@ -459,13 +372,13 @@ struct drm_i915_gem_object {
          * optimisation we try to flush any writes as early as possible to avoid
          * stalling later.
          *
-        * Thus for scanout surfaces using I915_CACHE_NONE, on shared LLC
+        * Thus for scanout surfaces using I915_CACHE(UC), on shared LLC
          * platforms, we use:
          *
          *       cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ
          *
          * While for normal objects that are fully coherent, including special
-        * scanout surfaces marked as I915_CACHE_WT, we use:
+        * scanout surfaces marked as I915_CACHE(WT), we use:
          *
          *       cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ |
          *                        I915_BO_CACHE_COHERENT_FOR_WRITE
@@ -492,9 +405,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 yield
@@ -517,7 +428,7 @@ struct drm_i915_gem_object {
          * for both reads and writes though the CPU cache.
          *
          * Note that on shared LLC platforms we still apply the heavy flush for
-        * I915_CACHE_NONE objects, under the assumption that this is going to
+        * I915_CACHE(UC) objects, under the assumption that this is going to
          * be used for scanout.
          *
          * Update: On some hardware there is now also the 'Bypass LLC' MOCS
@@ -530,15 +441,15 @@ struct drm_i915_gem_object {
          * information leak. The driver currently ensures:
          *
          *   1. All userspace objects, by default, have @cache_level set as
-        *   I915_CACHE_NONE. The only exception is userptr objects, where we
-        *   instead force I915_CACHE_LLC, but we also don't allow userspace to
+        *   I915_CACHE(UC). The only exception is userptr objects, where we
+        *   instead force I915_CACHE(WB), but we also don't allow userspace to
          *   ever change the @cache_level for such objects. Another special case
          *   is dma-buf, which doesn't rely on @cache_dirty,  but there we
          *   always do a forced flush when acquiring the pages, if there is a
          *   chance that the pages can be read directly from main memory with
          *   the GPU.
          *
-        *   2. All I915_CACHE_NONE objects have @cache_dirty initially true.
+        *   2. All I915_CACHE(UC) objects have @cache_dirty initially true.
          *
          *   3. All swapped-out objects(i.e shmem) have @cache_dirty set to
          *   true.
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +5 -5
index 33d5d5178103..538b3029de35 100644
@@ -375,7 +375,7 @@ __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,
          * On non-LLC igfx platforms, force the flush-on-acquire if this is ever
          * swapped-in. Our async flush path is not trust worthy enough yet(and
          * happens in the wrong order), and with some tricks it's conceivable
-        * for userspace to change the cache-level to I915_CACHE_NONE after the
+        * for userspace to change the cache-level to I915_CACHE(UC) after the
          * pages are swapped-in, and since execbuf binds the object before doing
          * the async flush, we have a race window.
          */
@@ -577,7 +577,7 @@ static int shmem_object_init(struct intel_memory_region *mem,
         static struct lock_class_key lock_class;
         struct drm_i915_private *i915 = mem->i915;
         struct address_space *mapping;
-       unsigned int cache_level;
+       i915_cache_t cache;
         gfp_t mask;
         int ret;
 
@@ -621,11 +621,11 @@ static int shmem_object_init(struct intel_memory_region *mem,
                  * However, we maintain the display planes as UC, and so
                  * need to rebind when first used as such.
                  */
-               cache_level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);
         else
-               cache_level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);
 
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);
 
         i915_gem_object_init_memory_region(obj, mem);
 
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +5 -8
index 3b094d36a0b0..e3a3b824a536 100644
@@ -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,
@@ -679,7 +676,6 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,
                                            struct drm_mm_node *stolen)
 {
         static struct lock_class_key lock_class;
-       unsigned int cache_level;
         unsigned int flags;
         int err;
 
@@ -694,8 +690,9 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,
 
         obj->stolen = stolen;
         obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
-       cache_level = HAS_LLC(mem->i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(mem->i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
 
         if (WARN_ON(!i915_gem_object_trylock(obj, NULL)))
                 return -EBUSY;
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +25 -18
index 7078af2f8f79..52c0273001b2 100644
@@ -48,14 +48,23 @@ void i915_ttm_migrate_set_ban_memcpy(bool ban)
 }
 #endif
 
-static enum i915_cache_level
-i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res,
+static i915_cache_t
+i915_ttm_cache(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_CACHE(WB) : I915_CACHE(UC);
+}
+
+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_CACHE_LLC :
-               I915_CACHE_NONE;
+               ttm->caching == ttm_cached) ? i915->pat_wb :
+               i915->pat_uc;
 }
 
 static struct intel_memory_region *
@@ -102,8 +111,8 @@ void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj)
 void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
 {
         struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
-       unsigned int cache_level;
         unsigned int mem_flags;
+       i915_cache_t cache;
         unsigned int i;
         int mem_type;
 
@@ -116,13 +125,13 @@ void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
         if (!bo->resource) {
                 mem_flags = I915_BO_FLAG_STRUCT_PAGE;
                 mem_type = I915_PL_SYSTEM;
-               cache_level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);
         } else {
                 mem_flags = i915_ttm_cpu_maps_iomem(bo->resource) ? I915_BO_FLAG_IOMEM :
                         I915_BO_FLAG_STRUCT_PAGE;
                 mem_type = bo->resource->mem_type;
-               cache_level = i915_ttm_cache_level(to_i915(bo->base.dev), bo->resource,
-                                                  bo->ttm);
+               cache = i915_ttm_cache(to_i915(bo->base.dev), bo->resource,
+                                      bo->ttm);
         }
 
         /*
@@ -147,7 +156,7 @@ void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
         obj->mem_flags &= ~(I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_IOMEM);
         obj->mem_flags |= mem_flags;
 
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);
 }
 
 /**
@@ -196,7 +205,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 +215,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 +233,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/i915_gem_userptr.c +1 -1
index 1d3ebdf4069b..7d50d43dfbfa 100644
@@ -553,7 +553,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
         obj->mem_flags = I915_BO_FLAG_STRUCT_PAGE;
         obj->read_domains = I915_GEM_DOMAIN_CPU;
         obj->write_domain = I915_GEM_DOMAIN_CPU;
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
         obj->userptr.ptr = args->user_ptr;
         obj->userptr.notifier_seq = ULONG_MAX;
drivers/gpu/drm/i915/gem/selftests/huge_gem_object.c +3 -3
index bac957755068..ad7798d34c74 100644
@@ -104,7 +104,6 @@ huge_gem_object(struct drm_i915_private *i915,
 {
         static struct lock_class_key lock_class;
         struct drm_i915_gem_object *obj;
-       unsigned int cache_level;
 
         GEM_BUG_ON(!phys_size || phys_size > dma_size);
         GEM_BUG_ON(!IS_ALIGNED(phys_size, PAGE_SIZE));
@@ -123,8 +122,9 @@ huge_gem_object(struct drm_i915_private *i915,
 
         obj->read_domains = I915_GEM_DOMAIN_CPU;
         obj->write_domain = I915_GEM_DOMAIN_CPU;
-       cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
         obj->scratch = phys_size;
 
         return obj;
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +4 -4
index df6c9a84252c..060830c51c2f 100644
@@ -177,7 +177,6 @@ huge_pages_object(struct drm_i915_private *i915,
 {
         static struct lock_class_key lock_class;
         struct drm_i915_gem_object *obj;
-       unsigned int cache_level;
 
         GEM_BUG_ON(!size);
         GEM_BUG_ON(!IS_ALIGNED(size, BIT(__ffs(page_mask))));
@@ -200,8 +199,9 @@ huge_pages_object(struct drm_i915_private *i915,
         obj->write_domain = I915_GEM_DOMAIN_CPU;
         obj->read_domains = I915_GEM_DOMAIN_CPU;
 
-       cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
 
         obj->mm.page_mask = page_mask;
 
@@ -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(UC));
 
         return obj;
 }
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +1 -3
index c2bdc133c89a..fb69f667652a 100644
@@ -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 +6 -13
index f948d33e5ec5..bd5a7d295251 100644
@@ -16,11 +16,11 @@
 #include "intel_gtt.h"
 
 static u64 gen8_pde_encode(const dma_addr_t addr,
-                          const enum i915_cache_level level)
+                          const enum i915_cache_mode cache_mode)
 {
         u64 pde = addr | GEN8_PAGE_PRESENT | GEN8_PAGE_RW;
 
-       if (level != I915_CACHE_NONE)
+       if (cache_mode != I915_CACHE_MODE_UC)
                 pde |= PPAT_CACHED_PDE;
         else
                 pde |= PPAT_UNCACHED;
@@ -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++) {
@@ -874,7 +867,7 @@ static int gen8_init_scratch(struct i915_address_space *vm)
                 }
 
                 fill_px(obj, vm->scratch[i - 1]->encode);
-               obj->encode = gen8_pde_encode(px_dma(obj), I915_CACHE_NONE);
+               obj->encode = gen8_pde_encode(px_dma(obj), I915_CACHE_MODE_UC);
 
                 vm->scratch[i] = obj;
         }
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -1
index 0aff5bb13c53..b1e846682cd9 100644
@@ -1103,7 +1103,7 @@ static int init_status_page(struct intel_engine_cs *engine)
                 return PTR_ERR(obj);
         }
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
         vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
         if (IS_ERR(vma)) {
drivers/gpu/drm/i915/gt/intel_ggtt.c +12 -21
index dd0ed941441a..05fafb076556 100644
@@ -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;
@@ -1013,11 +1011,6 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt)
         return ggtt_probe_common(ggtt, size);
 }
 
-/*
- * For pre-gen8 platforms pat_index is the same as enum i915_cache_level,
- * so the switch-case statements in these PTE encode functions are still valid.
- * See translation table LEGACY_CACHELEVEL.
- */
 static u64 snb_pte_encode(dma_addr_t addr,
                           unsigned int pat_index,
                           u32 flags)
@@ -1025,11 +1018,11 @@ static u64 snb_pte_encode(dma_addr_t addr,
         gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
         switch (pat_index) {
-       case I915_CACHE_L3_LLC:
-       case I915_CACHE_LLC:
+       case 1:
+       case 2:
                 pte |= GEN6_PTE_CACHE_LLC;
                 break;
-       case I915_CACHE_NONE:
+       case 0:
                 pte |= GEN6_PTE_UNCACHED;
                 break;
         default:
@@ -1046,13 +1039,13 @@ static u64 ivb_pte_encode(dma_addr_t addr,
         gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
         switch (pat_index) {
-       case I915_CACHE_L3_LLC:
+       case 2:
                 pte |= GEN7_PTE_CACHE_L3_LLC;
                 break;
-       case I915_CACHE_LLC:
+       case 1:
                 pte |= GEN6_PTE_CACHE_LLC;
                 break;
-       case I915_CACHE_NONE:
+       case 0:
                 pte |= GEN6_PTE_UNCACHED;
                 break;
         default:
@@ -1071,7 +1064,7 @@ static u64 byt_pte_encode(dma_addr_t addr,
         if (!(flags & PTE_READ_ONLY))
                 pte |= BYT_PTE_WRITEABLE;
 
-       if (pat_index != I915_CACHE_NONE)
+       if (pat_index)
                 pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES;
 
         return pte;
@@ -1083,7 +1076,7 @@ static u64 hsw_pte_encode(dma_addr_t addr,
 {
         gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
-       if (pat_index != I915_CACHE_NONE)
+       if (pat_index)
                 pte |= HSW_WB_LLC_AGE3;
 
         return pte;
@@ -1096,9 +1089,9 @@ static u64 iris_pte_encode(dma_addr_t addr,
         gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
         switch (pat_index) {
-       case I915_CACHE_NONE:
+       case 0:
                 break;
-       case I915_CACHE_WT:
+       case 3:
                 pte |= HSW_WT_ELLC_LLC_AGE3;
                 break;
         default:
@@ -1298,9 +1291,7 @@ bool i915_ggtt_resume_vm(struct i915_address_space *vm)
                  */
                 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),
+                                  obj ? obj->pat_index : vm->i915->pat_uc,
                                    was_bound);
 
                 if (obj) { /* only used during resume => exclusive access */
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c +2 -2
index 866c416afb73..fedf02c9ecb6 100644
@@ -21,7 +21,7 @@ static void gmch_ggtt_insert_page(struct i915_address_space *vm,
                                   unsigned int pat_index,
                                   u32 unused)
 {
-       unsigned int flags = (pat_index == I915_CACHE_NONE) ?
+       unsigned int flags = (pat_index == 0) ?
                 AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
         intel_gmch_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags);
@@ -32,7 +32,7 @@ static void gmch_ggtt_insert_entries(struct i915_address_space *vm,
                                      unsigned int pat_index,
                                      u32 unused)
 {
-       unsigned int flags = (pat_index == I915_CACHE_NONE) ?
+       unsigned int flags = (pat_index == 0) ?
                 AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
         intel_gmch_gtt_insert_sg_entries(vma_res->bi.pages, vma_res->start >> PAGE_SHIFT,
drivers/gpu/drm/i915/gt/intel_gtt.c +1 -1
index 126269a0d728..8729eb244d28 100644
@@ -676,7 +676,7 @@ __vm_create_scratch_for_read(struct i915_address_space *vm, unsigned long size)
         if (IS_ERR(obj))
                 return ERR_CAST(obj);
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHING_CACHED);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
         vma = i915_vma_instance(obj, vm, NULL);
         if (IS_ERR(vma)) {
drivers/gpu/drm/i915/gt/intel_gtt.h +2 -1
index 7192a534a654..af4277c1d577 100644
@@ -636,7 +636,8 @@ void
 __set_pd_entry(struct i915_page_directory * const pd,
                const unsigned short idx,
                struct i915_page_table *pt,
-              u64 (*encode)(const dma_addr_t, const enum i915_cache_level));
+              u64 (*encode)(const dma_addr_t,
+                            const enum i915_cache_mode cache_mode));
 
 #define set_pd_entry(pd, idx, to) \
         __set_pd_entry((pd), (idx), px_pt(to), gen8_pde_encode)
drivers/gpu/drm/i915/gt/intel_migrate.c +3 -8
index 6023288b0e2d..81f7834cc2db 100644
@@ -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/intel_ppgtt.c +4 -2
index 436756bfbb1a..3e461d4f3693 100644
@@ -98,14 +98,16 @@ void
 __set_pd_entry(struct i915_page_directory * const pd,
                const unsigned short idx,
                struct i915_page_table * const to,
-              u64 (*encode)(const dma_addr_t, const enum i915_cache_level))
+              u64 (*encode)(const dma_addr_t,
+                            const enum i915_cache_mode cache_mode))
 {
         /* Each thread pre-pins the pd, and we may have a thread per pde. */
         GEM_BUG_ON(atomic_read(px_used(pd)) > NALLOC * I915_PDES);
 
         atomic_inc(px_used(pd));
         pd->entry[idx] = to;
-       write_dma_entry(px_base(pd), idx, encode(px_dma(to), I915_CACHE_LLC));
+       write_dma_entry(px_base(pd), idx,
+                       encode(px_dma(to), I915_CACHE_MODE_WB));
 }
 
 void
drivers/gpu/drm/i915/gt/intel_ring_submission.c +1 -1
index 3fd795c3263f..fc7781b47bbf 100644
@@ -551,7 +551,7 @@ alloc_context_vma(struct intel_engine_cs *engine)
          * later platforms don't have L3 control bits in the PTE.
          */
         if (IS_IVYBRIDGE(i915))
-               i915_gem_object_set_cache_coherency(obj, I915_CACHE_L3_LLC);
+               i915_gem_object_set_cache_coherency(obj, _I915_CACHE(WB, L3));
 
         vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
         if (IS_ERR(vma)) {
drivers/gpu/drm/i915/gt/intel_timeline.c +1 -1
index b9640212d659..ceb2616fb8d9 100644
@@ -26,7 +26,7 @@ static struct i915_vma *hwsp_alloc(struct intel_gt *gt)
         if (IS_ERR(obj))
                 return ERR_CAST(obj);
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
         vma = i915_vma_instance(obj, &gt->ggtt->vm, NULL);
         if (IS_ERR(vma))
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
index 8b0d84f2aad2..f0baf86b6848 100644
@@ -64,7 +64,7 @@ static int hang_init(struct hang *h, struct intel_gt *gt)
                 goto err_hws;
         }
 
-       i915_gem_object_set_cache_coherency(h->hws, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(h->hws, I915_CACHE(WB));
         vaddr = i915_gem_object_pin_map_unlocked(h->hws, I915_MAP_WB);
         if (IS_ERR(vaddr)) {
                 err = PTR_ERR(vaddr);
drivers/gpu/drm/i915/gt/selftest_migrate.c +3 -6
index 3def5ca72dec..a67ede65d816 100644
@@ -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
index 79aa6ac66ad2..327dc9294e0f 100644
@@ -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 +1 -0
index 39c3ec12df1a..87299158815f 100644
@@ -837,6 +837,7 @@ static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt,
 
         /* keep the same cache settings as timeline */
         i915_gem_object_set_pat_index(obj, tl->hwsp_ggtt->obj->pat_index);
+
         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
index 3bd6b540257b..6049f01be219 100644
@@ -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/selftest_workarounds.c +1 -1
index 14a8b25b6204..900b4e19087f 100644
@@ -111,7 +111,7 @@ read_nonprivs(struct intel_context *ce)
         if (IS_ERR(result))
                 return result;
 
-       i915_gem_object_set_cache_coherency(result, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(result, I915_CACHE(WB));
 
         cs = i915_gem_object_pin_map_unlocked(result, I915_MAP_WB);
         if (IS_ERR(cs)) {
drivers/gpu/drm/i915/gt/uc/intel_guc.c +1 -1
index 2eb891b270ae..3a862051423c 100644
@@ -749,7 +749,7 @@ struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
          * as WC on CPU side and UC (PAT index 2) on GPU side
          */
         if (IS_METEORLAKE(gt->i915))
-               i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
+               i915_gem_object_set_cache_coherency(obj, I915_CACHE(UC));
 
         vma = i915_vma_instance(obj, &gt->ggtt->vm, NULL);
         if (IS_ERR(vma))
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +2 -6
index d408856ae4c0..e099414d624d 100644
@@ -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 +12 -0
new file mode 100644
index 000000000000..4d0033bf1658
@@ -0,0 +1,72 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_print.h>
+
+#include "i915_cache.h"
+#include "i915_drv.h"
+
+int i915_cache_init(struct drm_i915_private *i915)

drivers/gpu/drm/i915/i915_cache.c line 22

Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.c new file +10 -0
+{
+       int ret;
+
+       ret = i915_cache_find_pat(i915, I915_CACHE(UC));
+       if (ret < 0)
+               return -ENODEV;
+       drm_info(&i915->drm, "Using PAT index %u for uncached access\n", ret);
+       i915->pat_uc = ret;
+
+       ret = i915_cache_find_pat(i915, I915_CACHE(WB));

For MTL, this would find pat index 0, but KMD wants pat index 3.

Quoted 529 lines
drivers/gpu/drm/i915/i915_cache.c new file +50 -0
+       if (ret < 0)
+               return -ENODEV;
+       drm_info(&i915->drm, "Using PAT index %u for write-back access\n", ret);
+       i915->pat_wb = ret;
+
+       return 0;
+}
+
+int i915_cache_find_pat(struct drm_i915_private *i915, i915_cache_t cache)
+{
+       const struct intel_device_info *info = INTEL_INFO(i915);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(info->cache_modes); i++) {
+               if (info->cache_modes[i] == cache)
+                       return i;
+       }
+
+       return -1;
+}
+
+void i915_cache_print(struct drm_printer *p, i915_cache_t cache)
+{
+       const enum i915_cache_mode 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_FLAG_L3] = "L3",
+               [I915_CACHE_FLAG_COH1W] = "1-Way-Coherent",
+               [I915_CACHE_FLAG_COH2W] = "2-Way-Coherent",
+               [I915_CACHE_FLAG_CLOS1] = "CLOS1",
+               [I915_CACHE_FLAG_CLOS2] = "CLOS2",
+       };
+
+       if (mode == I915_CACHE_MODE_UNKNOWN || mode > ARRAY_SIZE(mode_str)) {
+               drm_printf(p, "0x%x", cache);
+       } else {
+               unsigned long bit;
+
+               drm_printf(p, "%s", mode_str[mode]);
+
+               for_each_set_bit(bit, &flags, sizeof(i915_cache_t))
+                       drm_printf(p, "-%s", flag_str[bit]);
+       }
+}
drivers/gpu/drm/i915/i915_cache.h new file +49 -0
new file mode 100644
index 000000000000..ffb621d8a8a0
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef __I915_CACHE_H__
+#define __I915_CACHE_H__
+
+#include <linux/types.h>
+
+struct drm_printer;
+
+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_##flag)))
+
+#define I915_CACHE_MODE(cache) \
+       (enum i915_cache_mode)(((i915_cache_t)(cache)) & 0xff)
+#define I915_CACHE_FLAGS(cache) \
+       (unsigned int)((((i915_cache_t)(cache) & 0xff00)) >> 16)
+
+/* Cache modes */
+enum i915_cache_mode {
+       I915_CACHE_MODE_UNKNOWN = 0,
+       I915_CACHE_MODE_UC,
+       I915_CACHE_MODE_WB,
+       I915_CACHE_MODE_WT,
+       I915_CACHE_MODE_WC
+};
+
+/* Cache mode flag bits */
+#define I915_CACHE_FLAG_L3     (0)
+#define I915_CACHE_FLAG_COH1W  (1)
+#define I915_CACHE_FLAG_COH2W  (2)
+#define I915_CACHE_FLAG_CLOS1  (3)
+#define I915_CACHE_FLAG_CLOS2  (4)
+
+int i915_cache_init(struct drm_i915_private *i915);
+int i915_cache_find_pat(struct drm_i915_private *i915, i915_cache_t cache);
+void i915_cache_print(struct drm_printer *p, i915_cache_t cache);
+
+#endif /* __I915_CACHE_H__ */
drivers/gpu/drm/i915/i915_debugfs.c +15 -50
index 4de44cf1026d..03d366e0bdf7 100644
@@ -140,68 +140,33 @@ 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)
-{
-       struct drm_i915_private *i915 = obj_to_i915(obj);
-
-       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";
-               }
-       } 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";
-               }
-       }
-}
-
 void
 i915_debugfs_describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
 {
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+       struct drm_printer p = drm_seq_file_printer(m);
         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);
+
+        i915_cache_print(&p, INTEL_INFO(i915)->cache_modes[obj->pat_index]);
+       if (obj->pat_set_by_user)
+               drm_puts(&p, "!");
+
+       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 +5 -0
index 294b022de22b..8663388a524f 100644
@@ -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"
@@ -240,6 +241,10 @@ static int i915_driver_early_probe(struct drm_i915_private *dev_priv)
         i915_memcpy_init_early(dev_priv);
         intel_runtime_pm_init_early(&dev_priv->runtime_pm);
 
+       ret = i915_cache_init(dev_priv);
+       if (ret < 0)
+               return ret;
+
         ret = i915_workqueues_init(dev_priv);
         if (ret < 0)
                 return ret;
drivers/gpu/drm/i915/i915_drv.h +3 -0
index a18013787c9f..462b076e2650 100644
@@ -250,6 +250,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
index b46d7a2dab1a..ef6d33c2c288 100644
@@ -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
index 92ca81f9feab..6a6f97aaec60 100644
@@ -1124,14 +1124,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
index dea3609fc496..c0c6248fbc78 100644
@@ -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), \
         .__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 \
+       .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 \
+       .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), \
         }
 
-#define MTL_CACHELEVEL \
-       .cachelevel_to_pat = { \
-               [I915_CACHE_NONE]   = 2, \
-               [I915_CACHE_LLC]    = 3, \
-               [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), \
         }
 
 /* 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 = {
         .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 = {
         .memory_regions = REGION_SMEM | REGION_STOLEN_LMEM,
         .platform_engine_mask = BIT(RCS0) | BIT(BCS0) | BIT(CCS0),
         .require_force_probe = 1,
-       MTL_CACHELEVEL,
+       MTL_CACHE_MODES
 };
 
 #undef PLATFORM
drivers/gpu/drm/i915/i915_perf.c +1 -1
index 0a111b281578..1b8e067f37dd 100644
@@ -1861,7 +1861,7 @@ static int alloc_oa_buffer(struct i915_perf_stream *stream)
                 return PTR_ERR(bo);
         }
 
-       i915_gem_object_set_cache_coherency(bo, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(bo, I915_CACHE(WB));
 
         /* PreHSW required 512K alignment, HSW requires 16M */
         vma = i915_vma_instance(bo, &gt->ggtt->vm, NULL);
drivers/gpu/drm/i915/intel_device_info.h +2 -0
index dbfe6443457b..f48a21895a85 100644
@@ -27,6 +27,8 @@
 
 #include <uapi/drm/i915_drm.h>
 
+#include "i915_cache.h"
+
 #include "intel_step.h"
 
 #include "gt/intel_engine_types.h"

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 248

Quoted 6 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -2
@@ -243,8 +245,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];

I was commenting on the array size here. It's probably better to make it 16 because there are 4 PAT index bits defined in the PTE. Indices above max_pat_index are not used, but theoretically new mode could be added. Well, it's up to you, not likely to happen anyway.

-Fei

Quoted 165 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
index 61da4ed9d521..e620f73793a5 100644
@@ -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 +4 -4
index f8fe3681c3dc..862d3ba0e025 100644
@@ -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;
@@ -267,7 +267,7 @@ static int igt_evict_for_cache_color(void *arg)
                 err = PTR_ERR(obj);
                 goto cleanup;
         }
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
         quirk_add(obj, &objects);
 
         vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0,
@@ -283,7 +283,7 @@ static int igt_evict_for_cache_color(void *arg)
                 err = PTR_ERR(obj);
                 goto cleanup;
         }
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
         quirk_add(obj, &objects);
 
         /* Neighbouring; same colour - should fit */
@@ -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, L3);
 
         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
index 5c397a2df70e..a24585784f75 100644
@@ -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/igt_spinner.c +1 -1
index 618d9386d554..d42d1bcffe21 100644
@@ -23,7 +23,7 @@ int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt)
                 err = PTR_ERR(spin->hws);
                 goto err;
         }
-       i915_gem_object_set_cache_coherency(spin->hws, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(spin->hws, I915_CACHE(WB));
 
         spin->obj = i915_gem_object_create_internal(gt->i915, PAGE_SIZE);
         if (IS_ERR(spin->obj)) {
drivers/gpu/drm/i915/selftests/intel_memory_region.c +1 -3
index d985d9bae2e8..b82fe0ef8cd7 100644
@@ -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 +6 -6
index 12aa7fbb0748..f478a4102299 100644
@@ -126,13 +126,13 @@ static const struct intel_device_info mock_info = {
         .memory_regions = REGION_SMEM,
         .platform_engine_mask = BIT(0),
 
-       /* simply use legacy cache level for mock device */
+       /* Simply use legacy cache modes for the mock device. */
         .max_pat_index = 3,
-       .cachelevel_to_pat = {
-               [I915_CACHE_NONE]   = 0,
-               [I915_CACHE_LLC]    = 1,
-               [I915_CACHE_L3_LLC] = 2,
-               [I915_CACHE_WT]     = 3,
+       .cache_modes = {
+               [0] = I915_CACHE(UC),
+               [1] = I915_CACHE(WB),
+               [2] = _I915_CACHE(WB, L3),
+               [3] = I915_CACHE(WT),
         },
 };
 
drivers/gpu/drm/i915/selftests/mock_region.c +1 -2
index 6324eb32d4dd..8c16202e79cb 100644
@@ -77,7 +77,7 @@ static int mock_object_init(struct intel_memory_region *mem,
 
         obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(UC));
 
         i915_gem_object_init_memory_region(obj, mem);
 
--

2.39.2

#6 lore raw
Quoted 185 lines · Fei
Quoted 88 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..

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/display/intel_dpt.c      |   2 +- drivers/gpu/drm/i915/display/intel_fb_pin.c   |   2 +-

 .../drm/i915/display/intel_plane_initial.c    |   4 +-
 drivers/gpu/drm/i915/gem/i915_gem_domain.c    |  66 +++++-----
 drivers/gpu/drm/i915/gem/i915_gem_domain.h    |   7 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  13 +-

 drivers/gpu/drm/i915/gem/i915_gem_internal.c  |   6 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  10 +- drivers/gpu/drm/i915/gem/i915_gem_object.c    | 116 +++++++++-------- drivers/gpu/drm/i915/gem/i915_gem_object.h    |   9 +- .../gpu/drm/i915/gem/i915_gem_object_types.h  | 117 +++--------------- drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  10 +- drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |  13 +-

 drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c  |  43 ++++---
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   2 +-
 .../drm/i915/gem/selftests/huge_gem_object.c  |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   8 +-

 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   4 +- drivers/gpu/drm/i915/gt/gen8_ppgtt.c          |  19 +-- drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   2 +- drivers/gpu/drm/i915/gt/intel_ggtt.c          |  33 ++--- drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c     |   4 +- drivers/gpu/drm/i915/gt/intel_gtt.c           |   2 +- drivers/gpu/drm/i915/gt/intel_gtt.h           |   3 +- drivers/gpu/drm/i915/gt/intel_migrate.c       |  11 +- drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   6 +- .../gpu/drm/i915/gt/intel_ring_submission.c   |   2 +- drivers/gpu/drm/i915/gt/intel_timeline.c      |   2 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |   2 +- 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   |   1 + drivers/gpu/drm/i915/gt/selftest_tlb.c        |   5 +- .../gpu/drm/i915/gt/selftest_workarounds.c    |   2 +- drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   2 +- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c      |   8 +- drivers/gpu/drm/i915/i915_cache.c             |  72 +++++++++++ drivers/gpu/drm/i915/i915_cache.h             |  49 ++++++++ drivers/gpu/drm/i915/i915_debugfs.c           |  65 +++------- drivers/gpu/drm/i915/i915_driver.c            |   5 + 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/i915_perf.c              |   2 +- 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   |   8 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  13 +-

 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   2 +-
 .../drm/i915/selftests/intel_memory_region.c  |   4 +-
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  12 +-
 drivers/gpu/drm/i915/selftests/mock_region.c  |   2 +-
 54 files changed, 440 insertions(+), 485 deletions(-)

Review

Quoted 4 lines

 create mode 100644 drivers/gpu/drm/i915/i915_cache.c create mode 100644 drivers/gpu/drm/i915/i915_cache.h

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile

Review

Quoted 12 lines

index 2be9dd960540..2c3da8f0c78e 100644

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 \
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/display/intel_dpt.c

drivers/gpu/drm/i915/display/intel_dpt.c intel_dpt_create(struct intel_framebuffer *fb) · line 271

Quoted 8 lines

index 7c5fddb203ba..5baf0d27a288 100644

drivers/gpu/drm/i915/display/intel_dpt.c +0 -1
@@ -268,7 +268,7 @@ intel_dpt_create(struct intel_framebuffer *fb)
 
          ret = i915_gem_object_lock_interruptible(dpt_obj, NULL);
          if (!ret) {
-               ret = i915_gem_object_set_cache_level(dpt_obj, 

I915_CACHE_NONE);

Review

Quoted 5 lines
drivers/gpu/drm/i915/display/intel_dpt.c +1 -0
+               ret = i915_gem_object_set_cache(dpt_obj, I915_CACHE(UC));
                  i915_gem_object_unlock(dpt_obj);
          }
          if (ret) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/display/intel_fb_pin.c

drivers/gpu/drm/i915/display/intel_fb_pin.c intel_pin_fb_obj_dpt(struct drm_framebuffer *fb, · line 69

Quoted 8 lines

index fffd568070d4..dcf54b354a74 100644

drivers/gpu/drm/i915/display/intel_fb_pin.c +0 -1
@@ -66,7 +66,7 @@ intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
                                  continue;
                  }
 
-               ret = i915_gem_object_set_cache_level(obj, 

I915_CACHE_NONE);

Review

Quoted 5 lines
drivers/gpu/drm/i915/display/intel_fb_pin.c +1 -0
+               ret = i915_gem_object_set_cache(obj, I915_CACHE(UC));
                  if (ret)
                          continue;
 
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/display/intel_plane_initial.c

drivers/gpu/drm/i915/display/intel_plane_initial.c initial_plane_vma(struct drm_i915_private *i915, · line 125

Quoted 9 lines

index 736072a8b2b0..9988f6562392 100644

drivers/gpu/drm/i915/display/intel_plane_initial.c +0 -2
@@ -121,8 +121,8 @@ initial_plane_vma(struct drm_i915_private *i915,
           * cache_level during fbdev initialization. The
           * unbind there would get stuck waiting for rcu.
           */
-       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
-                                           I915_CACHE_WT : 

I915_CACHE_NONE);

drivers/gpu/drm/i915/display/intel_plane_initial.c initial_plane_vma(struct drm_i915_private *i915, · line 124

Quoted 1 line
drivers/gpu/drm/i915/display/intel_plane_initial.c +1 -0
+       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ? 

I915_CACHE(WT) :

drivers/gpu/drm/i915/display/intel_plane_initial.c initial_plane_vma(struct drm_i915_private *i915, · line 125

Quoted 1 line
drivers/gpu/drm/i915/display/intel_plane_initial.c +1 -0
+                                                               

I915_CACHE(UC));

Review

Quoted 4 lines
drivers/gpu/drm/i915/display/intel_plane_initial.c +0 -0
          switch (plane_config->tiling) {

         case I915_TILING_NONE:

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_domain.c

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct

Quoted 12 lines

index dfaaa8b66ac3..f899da2c622a 100644

drivers/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 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -2
          if (IS_DGFX(i915))
                  return false;
 
-       /*
-        * For objects created by userspace through GEM_CREATE with 

pat_index

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · line 32

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * set by set_pat extension, 

i915_gem_object_has_cache_level() will

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · line 33

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * 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 · line 34

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * by userspace. Othereise the call here would fall back to 

checking

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -4
-        * 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, 
Quoted 6 lines

I915_CACHE_MODE_UC) != 1 &&

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · 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;

This logic was changed for objects with pat index set by user here. It used to return false regardless the cache mode. But now it returns true if its cache mode is neither UC nor WT.

Yes, that was half of the motivation of the refactory. Before the PAT index series code was like this:

       return !(obj->cache_level == I915_CACHE_NONE ||
                obj->cache_level == I915_CACHE_WT);

So kernel knew it needs to flush only if caching mode is neither UC or WT. With the PAT index series you changed it to:

       return !(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) ||
                i915_gem_object_has_cache_level(obj, I915_CACHE_WT));

And as i915_gem_object_has_cache_level was changed to always return true if PAT was set by user, that made the check meaningless for such objects.

With my refactoring it becomes meaningful again and restores to the original behaviour. That's the intent at least.

Quoted 46 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct

Quoted 2 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)
@@ -255,9 +249,9 @@ i915_gem_object_set_to_gtt_domain(struct 

drm_i915_gem_object *obj, bool write)

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 258

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
  }
 
  /**
- * i915_gem_object_set_cache_level - Changes the cache-level of an 

object across all VMA.

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 252

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+ * i915_gem_object_set_cache - Changes the cache-level of an object 

across all VMA.

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
   * @obj: object to act on
- * @cache_level: new cache level to set for the object
+ * @cache: new caching mode to set for the object
   *
   * After this function returns, the object will be in the new 

cache-level

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 257

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
   * across all GTT and the contents of the backing storage will be 

coherent,

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -269,19 +263,28 @@ i915_gem_object_set_to_gtt_domain(struct 

drm_i915_gem_object *obj, bool write)

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)

Quoted 13 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +3 -4
   * cache coherency) and all non-MOCS GPU access will also be uncached so
   * that all direct access to the scanout remains coherent.
   */
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-                                   enum i915_cache_level cache_level)
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+                             i915_cache_t cache)
  {
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
          int ret;
 
-       /*
-        * For objects created by userspace through GEM_CREATE with 

pat_index

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 279

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * set by set_pat extension, simply return 0 here without 

touching

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 280

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * the cache setting, because such objects should have an 

immutable

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +4 -3
-        * cache setting by desgin and always managed by userspace.
-        */
-       if (i915_gem_object_has_cache_level(obj, cache_level))
+       ret = i915_cache_find_pat(i915, cache);
+       if (ret < 0) {
+               struct drm_printer p =
+                       drm_err_printer("Attempting to use unknown 

caching mode ");

Quoted 10 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 282

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +6 -0
+
+               i915_cache_print(&p, cache);
+               drm_puts(&p, "!\n");
+
+               return -EINVAL;
+       } else if (ret == obj->pat_index) {
                  return 0;

We will have to do this conversion and checking again later in this function when calling i915_gem_object_set_cache_coherency().

Yes the double lookup part is a bit naff. It is not super required apart for validating internal callers (could be a debug build only feature perhaps) and to see if PAT index has changed and so whether it needs to call i915_gem_object_wait before proceeding to i915_gem_object_set_cache_coherency...

Quoted 3 lines

My thought was to simply remove the use of cache_level/cache and replace it with pat_idex. Conversion from cache modes to pat index should be done before calling any function used to consume cache_level/cache.

... I could probably call the setter which takes PAT index instead of i915_gem_object_set_cache_coherency few lines below. That would skip the double lookup and make you happy(-ier)?

Quoted 39 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 283

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+       } else if (obj->pat_set_by_user) {

Shouldn't this if-statement be placed at the beginning of this function? the original i915_gem_object_has_cache_level() would return true if (obj->pat_set_by_user), so the function returns right away.

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 285

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -0
+               drm_notice_once(&i915->drm,
+                               "Attempting to change caching mode on 

an object with fixed PAT!\n");

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_object_set_cache_level(struct

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -0
+               return -EINVAL;
+       }
 
          ret = i915_gem_object_wait(obj,

                                    I915_WAIT_INTERRUPTIBLE |

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -291,7 +294,7 @@ int i915_gem_object_set_cache_level(struct 

drm_i915_gem_object *obj,

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                  return ret;
 
          /* Always invalidate stale cachelines */
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);
          obj->cache_dirty = true;
 
          /* The cache-level will be applied when each vma is rebound. */
@@ -326,10 +329,9 @@ int i915_gem_get_caching_ioctl(struct drm_device 

*dev, void *data,

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, · line 332

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -2
                  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))

This looks wrong, at least for MTL. Prior to MTL the GPU automatically snoop CPU cache, but from MTL onward you have to specify if WB or WB + 1-WAY COH is needed. And for KMD, cacheable mode means WB + 1-WAY COH for MTL to keep the behavior consistent.

Quoted 7 lines

This used to be taken care of by i915_gem_get_pat_index() call. With that being replaced by i915_cache_find_pat(), you would need to do something there. But, without cachelevel_to_pat[], you might end up hard coding something directly in the function, and that is platform dependent. hmm..., I don't really like this idea.

That's why I commented in v1 that we should use INTEL_INFO(i915)->pat_uc/wb/wt instead of enum i915_cache_level or i915_cache_t.

I think I get it. I hope so.. So if I made the tables like this:

#define LEGACY_CACHE_MODES \
	.cache_modes = { \
		[0] = I915_CACHE(UC), \
		[1] = _I915_CACHE(WB, COH1W), \
		[2] = _I915_CACHE(WB, COH1W | L3), \ // 2way??
		[3] = I915_CACHE(WT), \

}

#define GEN12_CACHE_MODES \
	.cache_modes = { \
		[0] = _I915_CACHE(WB, COH1W), \
		[1] = I915_CACHE(WC), \
		[2] = I915_CACHE(WT), \
		[3] = I915_CACHE(UC), \

}

#define MTL_CACHE_MODES \
	.cache_modes = { \
		[0] = _I915_CACHE(WB, COH1W), \
		[1] = I915_CACHE(WT), \
		[2] = I915_CACHE(UC), \
		[3] = _I915_CACHE(WB, COH1W), \
		[4] = _I915_CACHE(WB, COH2W), \

And made i915->pat_wc look up _I915_CACHE(WB, COH1W) would that work? Hmm and also all "has cache level" call sites would need to look not just for WB but WB+COH1W.

Would it work? Too ugly?

Quoted 43 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                  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_domain.c +0 -0
@@ -344,7 +346,7 @@ int i915_gem_set_caching_ioctl(struct drm_device 

*dev, void *data,

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
          struct drm_i915_private *i915 = to_i915(dev);
          struct drm_i915_gem_caching *args = data;
          struct drm_i915_gem_object *obj;
-       enum i915_cache_level level;
+       i915_cache_t cache;
          int ret = 0;
 
          if (IS_DGFX(i915))
@@ -355,7 +357,7 @@ int i915_gem_set_caching_ioctl(struct drm_device 

*dev, void *data,

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
          switch (args->caching) {

         case I915_CACHING_NONE:
-               level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);

For code like this, my thought was

-               level = I915_CACHE_NONE;
+               pat_index = INTEL_INFO(i915)->pat_uc;

And later the set_cache call should take pat_index as argument instead of cache mode.

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct

Quoted 4 lines

                 break;
         case I915_CACHING_CACHED:
                 /*

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -367,10 +369,10 @@ int i915_gem_set_caching_ioctl(struct 

drm_device *dev, void *data,

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 372

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                  if (!HAS_LLC(i915) && !HAS_SNOOP(i915))
                          return -ENODEV;
 
-               level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);
Quoted 6 lines

-               level = I915_CACHE_LLC;
+               pat_index = INTEL_INFO(i915)->pat_wb;

This should take care of the WB + 1-WAY COH issue for MTL mentioned above, assuming the i915_cache_init() set pat_wb properly, and the i915_gem_object_set_cache() consumes pat_index instead of cache mode.

That works too yes.

Quoted 2,129 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
                  break;

         case I915_CACHING_DISPLAY:
-               level = HAS_WT(i915) ? I915_CACHE_WT : I915_CACHE_NONE;
+               cache = HAS_WT(i915) ? I915_CACHE(WT) : I915_CACHE(UC); break;
         default:
                 return -EINVAL;

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -409,7 +411,7 @@ int i915_gem_set_caching_ioctl(struct drm_device 

*dev, void *data,

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
          if (ret)
                  goto out;
 
-       ret = i915_gem_object_set_cache_level(obj, level);
+       ret = i915_gem_object_set_cache(obj, cache);
          i915_gem_object_unlock(obj);
 

 out:

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -448,9 +450,9 @@ i915_gem_object_pin_to_display_plane(struct 

drm_i915_gem_object *obj,

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct · line 450

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
           * of uncaching, which would allow us to flush all the 

LLC-cached data

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct · line 451

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
           * with that bit in the PTE to main memory with just one 

PIPE_CONTROL.

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -3
           */
-       ret = i915_gem_object_set_cache_level(obj,
-                                             HAS_WT(i915) ?
-                                             I915_CACHE_WT : 

I915_CACHE_NONE);

Review

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +3 -0
+       ret = i915_gem_object_set_cache(obj,
+                                       HAS_WT(i915) ?
+                                       I915_CACHE(WT) : I915_CACHE(UC));
          if (ret)
                  return ERR_PTR(ret);
 
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_domain.h

Review

Quoted 19 lines

index 9622df962bfc..d07926758b36 100644

drivers/gpu/drm/i915/gem/i915_gem_domain.h +4 -3
@@ -6,10 +6,11 @@
  #ifndef __I915_GEM_DOMAIN_H__
  #define __I915_GEM_DOMAIN_H__
 
+#include "i915_cache.h"
+
  struct drm_i915_gem_object;
-enum i915_cache_level;
 
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-                                   enum i915_cache_level cache_level);
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+                             i915_cache_t cache);
 
  #endif /* __I915_GEM_DOMAIN_H__ */
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static inline int use_cpu_reloc(const struct

Quoted 4 lines

index d3208a325614..ee85221fa6eb 100644

drivers/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 5 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0 -2
          if (DBG_FORCE_RELOC == FORCE_GTT_RELOC)
                  return false;
 
-       /*
-        * For objects created by userspace through GEM_CREATE with 

pat_index

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static inline int use_cpu_reloc(const struct · line 645

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0 -1
-        * set by set_pat extension, 

i915_gem_object_has_cache_level() always

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static inline int use_cpu_reloc(const struct · line 646

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0 -1
-        * return true, otherwise the call would fall back to 

checking whether

Quoted 6 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);

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static void *reloc_iomap(struct i915_vma *batch, · line 1325

Quoted 7 lines

 }

 static int eb_reserve_vma(struct i915_execbuffer *eb,

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0 -0
@@ -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),

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static void *reloc_iomap(struct i915_vma *batch, · line 1333

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0 -2
-                                    offset,
-                                   

 i915_gem_get_pat_index(ggtt->vm.i915,

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c static void *reloc_iomap(struct i915_vma *batch, · line 1334

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +0 -1
-                                                           

I915_CACHE_NONE),

Review

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
-                                    0);
+                                    offset, eb->i915->pat_uc, 0);
          } else {
                  offset += page << PAGE_SHIFT;
          }
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_internal.c

drivers/gpu/drm/i915/gem/i915_gem_internal.c __i915_gem_object_create_internal(struct

Quoted 4 lines

index 6bc26b4b06b8..7e7bfe7da76f 100644

drivers/gpu/drm/i915/gem/i915_gem_internal.c +0 -0
@@ -142,7 +142,6 @@ __i915_gem_object_create_internal(struct 

drm_i915_private *i915,

drivers/gpu/drm/i915/gem/i915_gem_internal.c __i915_gem_object_create_internal(struct

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_internal.c +0 -1
  {
          static struct lock_class_key lock_class;
          struct drm_i915_gem_object *obj;
-       unsigned int cache_level;
 
          GEM_BUG_ON(!size);
          GEM_BUG_ON(!IS_ALIGNED(size, PAGE_SIZE));
@@ -170,8 +169,9 @@ __i915_gem_object_create_internal(struct 

drm_i915_private *i915,

Review

Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_internal.c +3 -2
          obj->read_domains = I915_GEM_DOMAIN_CPU;
          obj->write_domain = I915_GEM_DOMAIN_CPU;
 
-       cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
 
          return obj;
  }
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_mman.c

drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault

Quoted 4 lines

index aa4d842d4c5a..5e21aedb02d2 100644

drivers/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 · line 387

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0 -0
          /*
           * For objects created by userspace through GEM_CREATE with 

pat_index

drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault · line 388

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0 -0
           * set by set_pat extension, coherency is managed by 

userspace, make

drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault · line 390

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0 -2
-        * 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 to 

checking

drivers/gpu/drm/i915/gem/i915_gem_mman.c static vm_fault_t vm_fault_gtt(struct vm_fault · line 389

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +1 -1
-        * whether the object is un-cached.
+        * sure we don't fail handling the vm fault by making sure 

that we

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 +2 -2
+        * 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 &&

Review

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +1 -0
+           !HAS_LLC(i915)) {
                  ret = -EFAULT;
                  goto err_unpin;
          }
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_object.c

Quoted 7 lines

index d77a375871b7..2d3a58c62122 100644

drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -0
@@ -45,33 +45,6 @@ static struct kmem_cache *slab_objects;
 
  static const struct drm_gem_object_funcs i915_gem_object_funcs;
 

drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects; · line 57

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -10
-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];
-}
-
-bool i915_gem_object_has_cache_level(const struct 

drm_i915_gem_object *obj,

drivers/gpu/drm/i915/gem/i915_gem_object.c static struct kmem_cache *slab_objects;

Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -12
-                                    enum i915_cache_level lvl)
-{
-       /*
-        * 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

drivers/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,30 +117,70 @@ void __i915_gem_object_fini(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)

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +1 -0
          dma_resv_fini(&obj->base._resv);
  }
 
+int i915_gem_object_has_cache_mode(const 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)

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +4 -0
+                                  enum i915_cache_mode mode)
+{
+       struct drm_i915_private *i915 = obj_to_i915(obj);
+       i915_cache_t cache = 

INTEL_INFO(i915)->cache_modes[obj->pat_index];

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 +10 -0
+
+       if (I915_CACHE_MODE(cache) == mode)
+               return 1;
+       else if (obj->pat_set_by_user)
+               return -1; /* Unknown, callers should assume no. */
+       else
+               return 0;
+}
+
+static void __i915_gem_object_update_coherency(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)

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +3 -0
+{
+       struct drm_i915_private *i915 = obj_to_i915(obj);
+       i915_cache_t cache = 

INTEL_INFO(i915)->cache_modes[obj->pat_index];

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +7 -0
+       unsigned int mode = I915_CACHE_MODE(cache);
+
+       if (mode == I915_CACHE_MODE_UNKNOWN) {
+               drm_notice_once(&i915->drm, "Undefined PAT index %u!\n",
+                               obj->pat_index);
+               obj->cache_coherent = 0;
+       } else  if (mode != I915_CACHE_MODE_UC) {

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 +10 -0
+               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) &&

drivers/gpu/drm/i915/gem/i915_gem_object.c void __i915_gem_object_fini(struct drm_i915_gem_object *obj)

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +3 -0
+               !IS_DGFX(i915);
+}
+
  /**
   * i915_gem_object_set_cache_coherency - Mark up the object's 

coherency levels

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +2 -2
- * for a given cache_level
+ * for a given caching mode
   * @obj: #drm_i915_gem_object
- * @cache_level: cache level
+ * @cache: cache mode
   */

 void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object

*obj,

Quoted 23 lines

-                                        unsigned int cache_level)
+                                        i915_cache_t cache) {
-       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+       struct drm_i915_private *i915 = obj_to_i915(obj);
+       int found;

-       obj->pat_index = i915_gem_get_pat_index(i915, cache_level);
+       found = i915_cache_find_pat(i915, cache);
+       if (found < 0) {
+               struct drm_printer p =
+                       drm_err_printer("Unknown cache 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;
+               i915_cache_print(&p, cache);
+               drm_puts(&p, "!\n");

Quoted 2 lines

-       obj->cache_dirty =
-               !(obj->cache_coherent &

I915_BO_CACHE_COHERENT_FOR_WRITE) &&

drivers/gpu/drm/i915/gem/i915_gem_object.c void i915_gem_object_set_cache_coherency(struct

Quoted 11 lines

-               !IS_DGFX(i915);
+               found = i915->pat_uc;
+       }

drivers/gpu/drm/i915/gem/i915_gem_object.c +4 -0
+
+       obj->pat_index = found;
+
+       __i915_gem_object_update_coherency(obj);

 }

 /**

drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -0
@@ -181,24 +194,18 @@ 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_cache_coherency(struct drm_i915_gem_object *obj,

Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +3 -1
  void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj,
                                     unsigned int pat_index)
  {
-       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+       struct drm_i915_private *i915 = obj_to_i915(obj);
 
          if (obj->pat_index == pat_index)
                  return;
 
+       if (drm_WARN_ON_ONCE(&i915->drm,
+                            pat_index > 

INTEL_INFO(i915)->max_pat_index))

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +2 -0
+               return;
+
          obj->pat_index = pat_index;
 

drivers/gpu/drm/i915/gem/i915_gem_object.c void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -10
-       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) &&

drivers/gpu/drm/i915/gem/i915_gem_object.c bool i915_gem_object_can_bypass_llc(struct

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +1 -1
-               !IS_DGFX(i915);
+       __i915_gem_object_update_coherency(obj);
  }
 
  bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj)
@@ -215,6 +222,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.h

Quoted 12 lines

index 884a17275b3a..c852e59aeef9 100644

drivers/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"

drivers/gpu/drm/i915/gem/i915_gem_object.h static inline bool i915_gem_object_size_2big(u64 size) · line 37

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -3
@@ -32,10 +33,6 @@ 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,

drivers/gpu/drm/i915/gem/i915_gem_object.h int i915_gem_object_wait_moving_fence(struct

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -1
-                                    enum i915_cache_level lvl);
  void i915_gem_init__objects(struct drm_i915_private *i915);
 
  void i915_objects_module_exit(void);
@@ -764,8 +761,10 @@ 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 -0
                                        bool intr);
  bool i915_gem_object_has_unknown_state(struct drm_i915_gem_object *obj);
 
+int i915_gem_object_has_cache_mode(const struct drm_i915_gem_object 

*obj,

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object.h +1 -0
+                                  enum i915_cache_mode mode);

 void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object

*obj,

Review

Quoted 6 lines

-                                        unsigned int cache_level);
+                                        i915_cache_t cache); void i915_gem_object_set_pat_index(struct drm_i915_gem_object *obj, unsigned int pat_index); bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj);

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h

Quoted 12 lines

index 8de2b91b3edf..a136d137b980 100644

drivers/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 {
Quoted 1 line

         const char *name; /* friendly name for debug, e.g. lockdep

classes */

Quoted 4 lines

 };

-/**
- * enum i915_cache_level - The supported GTT caching values for

system memory

Quoted 3 lines

- * pages.
- *
- * These translate to some special GTT PTE bits when binding pages

into 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 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

Quoted 1 line

-        * and we need the underlying pages to be coherent with some

later GPU

Quoted 3 lines

-        * access then we need to manually flush the pages.
-        *
-        * On shared LLC platforms reads and writes through the CPU

cache are

Quoted 2 lines

-        * still coherent even with this setting. See also
-        * &drm_i915_gem_object.cache_coherent for more details. Due

to this we

Quoted 1 line

-        * should only ever use uncached for scanout surfaces,

otherwise we end

Quoted 9 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,

Quoted 1 line

-        * then the GPU will ensure that access remains coherent,

when both

Quoted 1 line

-        * reading and writing through the CPU cache. GPU writes can

dirty the

Quoted 5 lines

-        * CPU cache.
-        *
-        * Not used for scanout surfaces.
-        *
-        * Applies to both platforms with shared LLC(HAS_LLC), and

snooping

Quoted 3 lines

-        * based platforms(HAS_SNOOP).
-        *
-        * This is the default on shared LLC platforms.  The only

exception is

Quoted 1 line

-        * scanout objects, where the display engine is not coherent

with the

Quoted 1 line

-        * CPU cache. For such objects I915_CACHE_NONE or

I915_CACHE_WT is

Quoted 1 line

-        * automatically applied by the kernel in pin_for_display, if

userspace

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 coherent

with the

Quoted 1 line

-        * GPU, but L3 is only visible to the GPU, so likely needs to

be flushed

Quoted 5 lines

-        * when the workload completes.
-        *
-        * Not used for scanout surfaces.
-        *
-        * Only exposed on some gen7 + GGTT. More recent hardware has

dropped

Quoted 1 line

-        * 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

display engine

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 1 line

-        * setting chosen by the kernel, if supported by the HW,

otherwise we

Quoted 1 line

-        * fallback to I915_CACHE_NONE. On the CPU side writes

through the 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_pat

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 323

Quoted 10 lines

-        * array for cache_level to 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
@@ -409,9 +323,7 @@ struct drm_i915_gem_object {
           * Check for @pat_set_by_user to find out if an object has 

pat index set

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 324

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * by userspace. The ioctl's to change cache settings have 

also been

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 325

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * 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 to bypass

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
-        * 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

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 340

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * writing through the CPU caches. The largely depends on the
@@ -426,7 +338,8 @@ struct drm_i915_gem_object {
           * i.e @cache_coherent is zero.
           *
           * On platforms that share the LLC with the CPU(HAS_LLC), 

all GT memory

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 429

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
-        * access will automatically snoop the CPU caches(even with 

CACHE_NONE).

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object {

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +2 -0
+        * access will automatically snoop the CPU caches (even with
+        * I915_CACHE(UC)).
           * The one exception is when dealing with the display 

engine, like with

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 344

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * scanout surfaces. To handle this the kernel will always 

flush the

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 345

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * surface out of the CPU caches when preparing it for 

scanout.  Also

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 351

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
@@ -437,8 +350,8 @@ struct drm_i915_gem_object {
           * Something strange here is why @cache_coherent is not a simple
           * boolean, i.e coherent vs non-coherent. The reasoning for 

this is back

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 352

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * to the display engine not being fully coherent. As a 

result scanout

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 440

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
-        * surfaces will either be marked as I915_CACHE_NONE or 

I915_CACHE_WT.

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 441

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
-        * In the case of seeing I915_CACHE_NONE the kernel makes the 

assumption

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 353

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -0
+        * surfaces will either be marked as I915_CACHE(UC) or 

I915_CACHE(WT).

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 354

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -0
+        * In the case of seeing I915_CACHE(UC) the kernel makes the 

assumption

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 355

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * that this is likely a scanout surface, and will set 

@cache_coherent

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 356

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * as only I915_BO_CACHE_COHERENT_FOR_READ, on platforms 

with the shared

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 357

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * LLC. The kernel uses this to always flush writes through 

the CPU

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 360

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
@@ -447,7 +360,7 @@ struct drm_i915_gem_object {
           * flushing the surface just before doing the scanout.  This 

does mean

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 361

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * we might unnecessarily flush non-scanout objects in some 

places, but

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 362

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * the default assumption is that all normal objects should 

be using

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 372

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -1
-        * I915_CACHE_LLC, at least on platforms with the shared LLC.
+        * I915_CACHE(WB), at least on platforms with the shared LLC.
           *
           * Supported values:
           *
@@ -459,13 +372,13 @@ struct drm_i915_gem_object {
           * optimisation we try to flush any writes as early as 

possible to avoid

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object {

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -1
           * stalling later.
           *
-        * Thus for scanout surfaces using I915_CACHE_NONE, on shared LLC
+        * Thus for scanout surfaces using I915_CACHE(UC), on shared LLC
           * platforms, we use:
           *
           *       cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ
           *
           * While for normal objects that are fully coherent, 

including special

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 405

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -1
-        * scanout surfaces marked as I915_CACHE_WT, we use:
+        * scanout surfaces marked as I915_CACHE(WT), we use:
           *
           *       cache_coherent = I915_BO_CACHE_COHERENT_FOR_READ |
           *                        I915_BO_CACHE_COHERENT_FOR_WRITE
@@ -492,9 +405,7 @@ struct drm_i915_gem_object {
           * Check for @pat_set_by_user to find out if an object has 

pat index set

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 406

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * by userspace. The ioctl's to change cache settings have 

also been

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 407

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * 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 

helper function

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 

bypass the 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 for this

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 411

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * object. As a result reading directly from main memory 

might yield

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 430

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
@@ -517,7 +428,7 @@ struct drm_i915_gem_object {
           * for both reads and writes though the CPU cache.
           *
           * Note that on shared LLC platforms we still apply the 

heavy flush for

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 520

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
-        * I915_CACHE_NONE objects, under the assumption that this is 

going to

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 431

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -0
+        * I915_CACHE(UC) objects, under the assumption that this is 

going to

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object {

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           * be used for scanout.
           *
           * Update: On some hardware there is now also the 'Bypass 

LLC' MOCS

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 443

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
@@ -530,15 +441,15 @@ struct drm_i915_gem_object {
           * information leak. The driver currently ensures:
           *
           *   1. All userspace objects, by default, have @cache_level 

set as

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 533

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
-        *   I915_CACHE_NONE. The only exception is userptr objects, 

where we

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 534

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
-        *   instead force I915_CACHE_LLC, but we also don't allow 

userspace to

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 444

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -0
+        *   I915_CACHE(UC). The only exception is userptr objects, 

where we

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 445

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -0
+        *   instead force I915_CACHE(WB), but we also don't allow 

userspace to

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 446

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           *   ever change the @cache_level for such objects. Another 

special case

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 447

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           *   is dma-buf, which doesn't rely on @cache_dirty,  but 

there we

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 448

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           *   always do a forced flush when acquiring the pages, if 

there is a

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 449

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           *   chance that the pages can be read directly from main 

memory with

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object {

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
           *   the GPU.
           *
-        *   2. All I915_CACHE_NONE objects have @cache_dirty 

initially true.

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 452

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +1 -0
+        *   2. All I915_CACHE(UC) objects have @cache_dirty 

initially true.

drivers/gpu/drm/i915/gem/i915_gem_object_types.h struct drm_i915_gem_object { · line 454

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           *
           *   3. All swapped-out objects(i.e shmem) have @cache_dirty 

set to

Review

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -0
           *   true.
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct

Quoted 4 lines

index 33d5d5178103..538b3029de35 100644

drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
@@ -375,7 +375,7 @@ __i915_gem_object_release_shmem(struct 

drm_i915_gem_object *obj,

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct · line 375

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
           * On non-LLC igfx platforms, force the flush-on-acquire if 

this is ever

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct · line 376

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
           * swapped-in. Our async flush path is not trust worthy 

enough yet(and

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct · line 377

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
           * happens in the wrong order), and with some tricks it's 

conceivable

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct · line 378

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -1
-        * for userspace to change the cache-level to I915_CACHE_NONE 

after the

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct · line 378

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +1 -0
+        * for userspace to change the cache-level to I915_CACHE(UC) 

after the

drivers/gpu/drm/i915/gem/i915_gem_shmem.c __i915_gem_object_release_shmem(struct · line 379

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
           * pages are swapped-in, and since execbuf binds the object 

before doing

drivers/gpu/drm/i915/gem/i915_gem_shmem.c static int shmem_object_init(struct

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0 -0
           * the async flush, we have a race window.
           */
@@ -577,7 +577,7 @@ static int shmem_object_init(struct 

intel_memory_region *mem,

drivers/gpu/drm/i915/gem/i915_gem_shmem.c static int shmem_object_init(struct

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +1 -1
          static struct lock_class_key lock_class;
          struct drm_i915_private *i915 = mem->i915;
          struct address_space *mapping;
-       unsigned int cache_level;
+       i915_cache_t cache;
          gfp_t mask;
          int ret;
 
@@ -621,11 +621,11 @@ static int shmem_object_init(struct 

intel_memory_region *mem,

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +1 -1
                   * However, we maintain the display planes as UC, and so
                   * need to rebind when first used as such.
                   */
-               cache_level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);

         else
-               cache_level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);

Review

Quoted 6 lines

-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);

         i915_gem_object_init_memory_region(obj, mem);

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c

drivers/gpu/drm/i915/gem/i915_gem_stolen.c static void dbg_poison(struct i915_ggtt *ggtt, · line 568

Quoted 10 lines

index 3b094d36a0b0..e3a3b824a536 100644

drivers/gpu/drm/i915/gem/i915_gem_stolen.c +0 -3
@@ -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,

drivers/gpu/drm/i915/gem/i915_gem_stolen.c static void dbg_poison(struct i915_ggtt *ggtt, · line 569

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +0 -1
-                                                           

I915_CACHE_NONE),

drivers/gpu/drm/i915/gem/i915_gem_stolen.c static void dbg_poison(struct i915_ggtt *ggtt, · line 566

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +1 -1
-                                    0);
+               ggtt->vm.insert_page(&ggtt->vm, addr, 

ggtt->error_capture.start,

drivers/gpu/drm/i915/gem/i915_gem_stolen.c static int __i915_gem_object_create_stolen(struct

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,
@@ -679,7 +676,6 @@ static int __i915_gem_object_create_stolen(struct 

intel_memory_region *mem,

drivers/gpu/drm/i915/gem/i915_gem_stolen.c static int __i915_gem_object_create_stolen(struct

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +0 -1
                                             struct drm_mm_node *stolen)
  {
          static struct lock_class_key lock_class;
-       unsigned int cache_level;
          unsigned int flags;
          int err;
 
@@ -694,8 +690,9 @@ static int __i915_gem_object_create_stolen(struct 

intel_memory_region *mem,

drivers/gpu/drm/i915/gem/i915_gem_stolen.c static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +0 -1
          obj->stolen = stolen;
          obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
-       cache_level = HAS_LLC(mem->i915) ? I915_CACHE_LLC : 

I915_CACHE_NONE;

Review

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +3 -1
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(mem->i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
 
          if (WARN_ON(!i915_gem_object_trylock(obj, NULL)))
                  return -EBUSY;
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c void i915_ttm_migrate_set_ban_memcpy(bool ban) · line 52

Quoted 9 lines

index 7078af2f8f79..52c0273001b2 100644

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -2
@@ -48,14 +48,23 @@ void i915_ttm_migrate_set_ban_memcpy(bool ban)
  }
  #endif
 
-static enum i915_cache_level
-i915_ttm_cache_level(struct drm_i915_private *i915, struct 

ttm_resource *res,

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c void i915_ttm_migrate_set_ban_memcpy(bool ban)

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +7 -0
+static i915_cache_t
+i915_ttm_cache(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_CACHE(WB) : 

I915_CACHE(UC);

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c void i915_ttm_migrate_set_ban_memcpy(bool ban)

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +4 -0
+}
+
+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 void i915_ttm_adjust_domains_after_move(struct

Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -0
                       struct ttm_tt *ttm)
  {

         return ((HAS_LLC(i915) || HAS_SNOOP(i915)) && !i915_ttm_gtt_binds_lmem(res) &&
-               ttm->caching == ttm_cached) ? I915_CACHE_LLC :
-               I915_CACHE_NONE;
+               ttm->caching == ttm_cached) ? i915->pat_wb :
+               i915->pat_uc;
 }

 static struct intel_memory_region *

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -0
@@ -102,8 +111,8 @@ void i915_ttm_adjust_domains_after_move(struct 

drm_i915_gem_object *obj)

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c void i915_ttm_adjust_gem_after_move(struct

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1 -1
  void i915_ttm_adjust_gem_after_move(struct drm_i915_gem_object *obj)
  {
          struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
-       unsigned int cache_level;
          unsigned int mem_flags;
+       i915_cache_t cache;
          unsigned int i;
          int mem_type;
 
@@ -116,13 +125,13 @@ void i915_ttm_adjust_gem_after_move(struct 

drm_i915_gem_object *obj)

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1 -1
          if (!bo->resource) {
                  mem_flags = I915_BO_FLAG_STRUCT_PAGE;
                  mem_type = I915_PL_SYSTEM;
-               cache_level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);
          } else {

                 mem_flags = i915_ttm_cpu_maps_iomem(bo->resource) ?

I915_BO_FLAG_IOMEM :

Quoted 3 lines

                         I915_BO_FLAG_STRUCT_PAGE; mem_type = bo->resource->mem_type;
-               cache_level =

i915_ttm_cache_level(to_i915(bo->base.dev), bo->resource,

Quoted 2 lines

-                                                  bo->ttm);
+               cache = i915_ttm_cache(to_i915(bo->base.dev),

bo->resource,

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c void i915_ttm_adjust_gem_after_move(struct

Quoted 5 lines

+                                      bo->ttm);
         }

         /*

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -0
@@ -147,7 +156,7 @@ void i915_ttm_adjust_gem_after_move(struct 

drm_i915_gem_object *obj)

Quoted 1 line

         obj->mem_flags &= ~(I915_BO_FLAG_STRUCT_PAGE |

I915_BO_FLAG_IOMEM);

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence

Quoted 8 lines

         obj->mem_flags |= mem_flags;

-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache); }

 /**

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -0
@@ -196,7 +205,7 @@ static struct dma_fence 

*i915_ttm_accel_move(struct ttm_buffer_object *bo,

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1 -1
          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)))

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -0
@@ -206,16 +215,15 @@ static struct dma_fence 

*i915_ttm_accel_move(struct ttm_buffer_object *bo,

Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1 -1
          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);

Quoted 1 line

-               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),

Quoted 1 line

+               ret =

intel_context_migrate_clear(to_gt(i915)->migrate.context,

Quoted 1 line

+                                                 deps, dst_st->sgl,

dst_pat,

Quoted 1 line

 i915_ttm_gtt_binds_lmem(dst_mem),

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence

Quoted 3 lines

                                                   0, &rq); } else {

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -0
@@ -225,14 +233,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 4 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0 -1
                  if (IS_ERR(src_rsgt))
                          return ERR_CAST(src_rsgt);
 
-               src_level = i915_ttm_cache_level(i915, bo->resource, 

src_ttm);

drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c static struct dma_fence · line 236

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1 -0
+               src_pat = i915_ttm_cache_pat(i915, bo->resource, 

src_ttm);

Quoted 1 line

 intel_engine_pm_get(to_gt(i915)->migrate.context->engine);

Quoted 1 line

                 ret =

intel_context_migrate_copy(to_gt(i915)->migrate.context,

Quoted 1 line

                                                  deps,

src_rsgt->table.sgl,

Quoted 1 line

-

 i915_gem_get_pat_index(i915, src_level),

Quoted 2 lines

+                                                src_pat,

i915_ttm_gtt_binds_lmem(bo->resource),

Quoted 2 lines

-                                                dst_st->sgl, -

 i915_gem_get_pat_index(i915, dst_level),

Quoted 2 lines

+                                                dst_st->sgl, dst_pat,

i915_ttm_gtt_binds_lmem(dst_mem),

Review

Quoted 3 lines

                                                  &rq);

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c

Review

Quoted 13 lines

index 1d3ebdf4069b..7d50d43dfbfa 100644

drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1 -1
@@ -553,7 +553,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
          obj->mem_flags = I915_BO_FLAG_STRUCT_PAGE;
          obj->read_domains = I915_GEM_DOMAIN_CPU;
          obj->write_domain = I915_GEM_DOMAIN_CPU;
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
          obj->userptr.ptr = args->user_ptr;
          obj->userptr.notifier_seq = ULONG_MAX;
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/selftests/huge_gem_object.c

Review

Quoted 24 lines

index bac957755068..ad7798d34c74 100644

drivers/gpu/drm/i915/gem/selftests/huge_gem_object.c +3 -3
@@ -104,7 +104,6 @@ huge_gem_object(struct drm_i915_private *i915,
  {
          static struct lock_class_key lock_class;
          struct drm_i915_gem_object *obj;
-       unsigned int cache_level;
 
          GEM_BUG_ON(!phys_size || phys_size > dma_size);
          GEM_BUG_ON(!IS_ALIGNED(phys_size, PAGE_SIZE));
@@ -123,8 +122,9 @@ huge_gem_object(struct drm_i915_private *i915,
 
          obj->read_domains = I915_GEM_DOMAIN_CPU;
          obj->write_domain = I915_GEM_DOMAIN_CPU;
-       cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
          obj->scratch = phys_size;
 
          return obj;
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c

drivers/gpu/drm/i915/gem/selftests/huge_pages.c fake_huge_pages_object(struct drm_i915_private

Quoted 24 lines

index df6c9a84252c..060830c51c2f 100644

drivers/gpu/drm/i915/gem/selftests/huge_pages.c +3 -3
@@ -177,7 +177,6 @@ huge_pages_object(struct drm_i915_private *i915,
  {
          static struct lock_class_key lock_class;
          struct drm_i915_gem_object *obj;
-       unsigned int cache_level;
 
          GEM_BUG_ON(!size);
          GEM_BUG_ON(!IS_ALIGNED(size, BIT(__ffs(page_mask))));
@@ -200,8 +199,9 @@ huge_pages_object(struct drm_i915_private *i915,
          obj->write_domain = I915_GEM_DOMAIN_CPU;
          obj->read_domains = I915_GEM_DOMAIN_CPU;
 
-       cache_level = HAS_LLC(i915) ? I915_CACHE_LLC : I915_CACHE_NONE;
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, HAS_LLC(i915) ?
+                                                I915_CACHE(WB) :
+                                                I915_CACHE(UC));
 
          obj->mm.page_mask = page_mask;
 
@@ -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 -1
          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(UC));
 
          return obj;
  }
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c

drivers/gpu/drm/i915/gt/gen6_ppgtt.c static int gen6_ppgtt_init_scratch(struct

Quoted 4 lines

index c2bdc133c89a..fb69f667652a 100644

drivers/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 -0
                  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);

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c

drivers/gpu/drm/i915/gt/gen8_ppgtt.c static int gen8_init_scratch(struct

Quoted 37 lines

index f948d33e5ec5..bd5a7d295251 100644

drivers/gpu/drm/i915/gt/gen8_ppgtt.c +2 -2
@@ -16,11 +16,11 @@
  #include "intel_gtt.h"
 
  static u64 gen8_pde_encode(const dma_addr_t addr,
-                          const enum i915_cache_level level)
+                          const enum i915_cache_mode cache_mode)
  {
          u64 pde = addr | GEN8_PAGE_PRESENT | GEN8_PAGE_RW;
 
-       if (level != I915_CACHE_NONE)
+       if (cache_mode != I915_CACHE_MODE_UC)
                  pde |= PPAT_CACHED_PDE;

         else
                 pde |= PPAT_UNCACHED;

drivers/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)

drivers/gpu/drm/i915/gt/gen8_ppgtt.c static int gen8_init_scratch(struct

Quoted 11 lines
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +0 -0
                  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/gen8_ppgtt.c +0 -0
@@ -874,7 +867,7 @@ static int gen8_init_scratch(struct 

i915_address_space *vm)

drivers/gpu/drm/i915/gt/gen8_ppgtt.c static int gen8_init_scratch(struct i915_address_space *vm)

Quoted 4 lines
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +0 -1
                  }
 
                  fill_px(obj, vm->scratch[i - 1]->encode);
-               obj->encode = gen8_pde_encode(px_dma(obj), 

I915_CACHE_NONE);

drivers/gpu/drm/i915/gt/gen8_ppgtt.c static int gen8_init_scratch(struct · line 870

Quoted 1 line
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +1 -0
+               obj->encode = gen8_pde_encode(px_dma(obj), 

I915_CACHE_MODE_UC);

Review

Quoted 4 lines
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +0 -0
                  vm->scratch[i] = obj;
          }
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_engine_cs.c

drivers/gpu/drm/i915/gt/intel_engine_cs.c static int init_status_page(struct

Quoted 4 lines

index 0aff5bb13c53..b1e846682cd9 100644

drivers/gpu/drm/i915/gt/intel_engine_cs.c +0 -0
@@ -1103,7 +1103,7 @@ static int init_status_page(struct 

intel_engine_cs *engine)

Review

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -1
                  return PTR_ERR(obj);
          }
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
          vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
          if (IS_ERR(vma)) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_ggtt.c

drivers/gpu/drm/i915/gt/intel_ggtt.c static int ggtt_probe_common(struct i915_ggtt

Quoted 4 lines

index dd0ed941441a..05fafb076556 100644

drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -0
@@ -921,9 +921,7 @@ static int ggtt_probe_common(struct i915_ggtt 

*ggtt, u64 size)

Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -0
                  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),

Quoted 1 line

+               ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]),

i915->pat_uc,

drivers/gpu/drm/i915/gt/intel_ggtt.c static int gen8_gmch_probe(struct i915_ggtt *ggtt) · line 1017

Quoted 9 lines

                                     pte_flags);

         return 0;

drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -2
@@ -1013,11 +1011,6 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt)
          return ggtt_probe_common(ggtt, size);
  }
 
-/*
- * For pre-gen8 platforms pat_index is the same as enum 

i915_cache_level,

drivers/gpu/drm/i915/gt/intel_ggtt.c static int gen8_gmch_probe(struct i915_ggtt *ggtt) · line 1018

Quoted 1 line
drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -1
- * so the switch-case statements in these PTE encode functions are 

still valid.

drivers/gpu/drm/i915/gt/intel_ggtt.c bool i915_ggtt_resume_vm(struct

Quoted 68 lines
drivers/gpu/drm/i915/gt/intel_ggtt.c +3 -5
- * See translation table LEGACY_CACHELEVEL.
- */
  static u64 snb_pte_encode(dma_addr_t addr,
                            unsigned int pat_index,
                            u32 flags)
@@ -1025,11 +1018,11 @@ static u64 snb_pte_encode(dma_addr_t addr,
          gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
          switch (pat_index) {
-       case I915_CACHE_L3_LLC:
-       case I915_CACHE_LLC:
+       case 1:
+       case 2:
                  pte |= GEN6_PTE_CACHE_LLC;
                  break;
-       case I915_CACHE_NONE:
+       case 0:
                  pte |= GEN6_PTE_UNCACHED;
                  break;

         default:

drivers/gpu/drm/i915/gt/intel_ggtt.c +3 -3
@@ -1046,13 +1039,13 @@ static u64 ivb_pte_encode(dma_addr_t addr,
          gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
          switch (pat_index) {
-       case I915_CACHE_L3_LLC:
+       case 2:
                  pte |= GEN7_PTE_CACHE_L3_LLC;
                  break;
-       case I915_CACHE_LLC:
+       case 1:
                  pte |= GEN6_PTE_CACHE_LLC;
                  break;
-       case I915_CACHE_NONE:
+       case 0:
                  pte |= GEN6_PTE_UNCACHED;
                  break;

         default:

drivers/gpu/drm/i915/gt/intel_ggtt.c +4 -4
@@ -1071,7 +1064,7 @@ static u64 byt_pte_encode(dma_addr_t addr,
          if (!(flags & PTE_READ_ONLY))
                  pte |= BYT_PTE_WRITEABLE;
 
-       if (pat_index != I915_CACHE_NONE)
+       if (pat_index)
                  pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES;
 
          return pte;
@@ -1083,7 +1076,7 @@ static u64 hsw_pte_encode(dma_addr_t addr,
  {
          gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
-       if (pat_index != I915_CACHE_NONE)
+       if (pat_index)
                  pte |= HSW_WB_LLC_AGE3;
 
          return pte;
@@ -1096,9 +1089,9 @@ static u64 iris_pte_encode(dma_addr_t addr,
          gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
 
          switch (pat_index) {
-       case I915_CACHE_NONE:
+       case 0:
                  break;
-       case I915_CACHE_WT:
+       case 3:
                  pte |= HSW_WT_ELLC_LLC_AGE3;
                  break;

         default:

drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -0
@@ -1298,9 +1291,7 @@ bool i915_ggtt_resume_vm(struct 

i915_address_space *vm)

drivers/gpu/drm/i915/gt/intel_ggtt.c bool i915_ggtt_resume_vm(struct i915_address_space *vm)

Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -3
                   */
                  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),

drivers/gpu/drm/i915/gt/intel_ggtt.c bool i915_ggtt_resume_vm(struct · line 1294

Quoted 1 line
drivers/gpu/drm/i915/gt/intel_ggtt.c +1 -0
+                                  obj ? obj->pat_index : 

vm->i915->pat_uc,

Quoted 3 lines
drivers/gpu/drm/i915/gt/intel_ggtt.c +0 -0
                                     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_ggtt_gmch.c

drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c static void gmch_ggtt_insert_page(struct

Quoted 4 lines

index 866c416afb73..fedf02c9ecb6 100644

drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c +0 -0
@@ -21,7 +21,7 @@ static void gmch_ggtt_insert_page(struct 

i915_address_space *vm,

drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c static void gmch_ggtt_insert_entries(struct

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c +1 -1
                                    unsigned int pat_index,
                                    u32 unused)
  {
-       unsigned int flags = (pat_index == I915_CACHE_NONE) ?
+       unsigned int flags = (pat_index == 0) ?
                  AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
          intel_gmch_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags);
@@ -32,7 +32,7 @@ static void gmch_ggtt_insert_entries(struct 

i915_address_space *vm,

drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c static void gmch_ggtt_insert_page(struct i915_address_space *vm,

Quoted 8 lines
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c +1 -1
                                       unsigned int pat_index,
                                       u32 unused)
  {
-       unsigned int flags = (pat_index == I915_CACHE_NONE) ?
+       unsigned int flags = (pat_index == 0) ?
                  AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
 
          intel_gmch_gtt_insert_sg_entries(vma_res->bi.pages, 

vma_res->start >> PAGE_SHIFT,

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_gtt.c

drivers/gpu/drm/i915/gt/intel_gtt.c __vm_create_scratch_for_read(struct

Quoted 4 lines

index 126269a0d728..8729eb244d28 100644

drivers/gpu/drm/i915/gt/intel_gtt.c +0 -0
@@ -676,7 +676,7 @@ __vm_create_scratch_for_read(struct 

i915_address_space *vm, unsigned long size)

Review

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gtt.c +1 -1
          if (IS_ERR(obj))
                  return ERR_CAST(obj);
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHING_CACHED);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
          vma = i915_vma_instance(obj, vm, NULL);
          if (IS_ERR(vma)) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_gtt.h

drivers/gpu/drm/i915/gt/intel_gtt.h void · line 639

Quoted 8 lines

index 7192a534a654..af4277c1d577 100644

drivers/gpu/drm/i915/gt/intel_gtt.h +0 -1
@@ -636,7 +636,8 @@ void
  __set_pd_entry(struct i915_page_directory * const pd,
                 const unsigned short idx,
                 struct i915_page_table *pt,
-              u64 (*encode)(const dma_addr_t, const enum 

i915_cache_level));

Review

Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_gtt.h +2 -0
+              u64 (*encode)(const dma_addr_t,
+                            const enum i915_cache_mode cache_mode));
 
  #define set_pd_entry(pd, idx, to) \
          __set_pd_entry((pd), (idx), px_pt(to), gen8_pde_encode)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_migrate.c

drivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_toggle_pdes(struct

Quoted 4 lines

index 6023288b0e2d..81f7834cc2db 100644

drivers/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_toggle_pdes(struct · line 45

Quoted 1 line
drivers/gpu/drm/i915/gt/intel_migrate.c +0 -0
           * Insert a dummy PTE into every PT that will map to LMEM to 

ensure

drivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_toggle_pdes(struct i915_address_space *vm,

Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +0 -2
           * 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),

drivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_insert_pte(struct

Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +1 -1
-                       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,

drivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_insert_pte(struct i915_address_space *vm,

Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +0 -2
           * 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),

drivers/gpu/drm/i915/gt/intel_migrate.c static void xehpsdv_insert_pte(struct · line 66

Quoted 2 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +1 -1
-                       PTE_LM);
+       vm->insert_page(vm, px_dma(pt), d->offset, vm->i915->pat_uc, 

PTE_LM);

drivers/gpu/drm/i915/gt/intel_migrate.c static void insert_pte(struct i915_address_space *vm, · line 81

Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +0 -2
          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),

Review

Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +1 -0
+       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/intel_ppgtt.c

drivers/gpu/drm/i915/gt/intel_ppgtt.c void · line 101

Quoted 8 lines

index 436756bfbb1a..3e461d4f3693 100644

drivers/gpu/drm/i915/gt/intel_ppgtt.c +0 -1
@@ -98,14 +98,16 @@ void
  __set_pd_entry(struct i915_page_directory * const pd,
                 const unsigned short idx,
                 struct i915_page_table * const to,
-              u64 (*encode)(const dma_addr_t, const enum 

i915_cache_level))

drivers/gpu/drm/i915/gt/intel_ppgtt.c void

Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_ppgtt.c +2 -0
+              u64 (*encode)(const dma_addr_t,
+                            const enum i915_cache_mode cache_mode))
  {
          /* Each thread pre-pins the pd, and we may have a thread per 

pde. */

drivers/gpu/drm/i915/gt/intel_ppgtt.c void

Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_ppgtt.c +0 -1
          GEM_BUG_ON(atomic_read(px_used(pd)) > NALLOC * I915_PDES);
 
          atomic_inc(px_used(pd));
          pd->entry[idx] = to;
-       write_dma_entry(px_base(pd), idx, encode(px_dma(to), 

I915_CACHE_LLC));

Review

Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_ppgtt.c +2 -0
+       write_dma_entry(px_base(pd), idx,
+                       encode(px_dma(to), I915_CACHE_MODE_WB));
  }
 

 void

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_ring_submission.c

drivers/gpu/drm/i915/gt/intel_ring_submission.c alloc_context_vma(struct intel_engine_cs *engine) · line 554

Quoted 8 lines

index 3fd795c3263f..fc7781b47bbf 100644

drivers/gpu/drm/i915/gt/intel_ring_submission.c +0 -1
@@ -551,7 +551,7 @@ alloc_context_vma(struct intel_engine_cs *engine)
           * later platforms don't have L3 control bits in the PTE.
           */
          if (IS_IVYBRIDGE(i915))
-               i915_gem_object_set_cache_coherency(obj, 

I915_CACHE_L3_LLC);

drivers/gpu/drm/i915/gt/intel_ring_submission.c alloc_context_vma(struct intel_engine_cs *engine) · line 554

Quoted 1 line
drivers/gpu/drm/i915/gt/intel_ring_submission.c +1 -0
+               i915_gem_object_set_cache_coherency(obj, 

_I915_CACHE(WB, L3));

Review

Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_ring_submission.c +0 -0
          vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
          if (IS_ERR(vma)) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_timeline.c

Review

Quoted 13 lines

index b9640212d659..ceb2616fb8d9 100644

drivers/gpu/drm/i915/gt/intel_timeline.c +1 -1
@@ -26,7 +26,7 @@ static struct i915_vma *hwsp_alloc(struct intel_gt *gt)
          if (IS_ERR(obj))
                  return ERR_CAST(obj);
 
-       i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(obj, I915_CACHE(WB));
 
          vma = i915_vma_instance(obj, &gt->ggtt->vm, NULL);
          if (IS_ERR(vma))
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c

drivers/gpu/drm/i915/gt/selftest_hangcheck.c static int hang_init(struct hang *h, struct

Quoted 4 lines

index 8b0d84f2aad2..f0baf86b6848 100644

drivers/gpu/drm/i915/gt/selftest_hangcheck.c +0 -0
@@ -64,7 +64,7 @@ static int hang_init(struct hang *h, struct 

intel_gt *gt)

Review

Quoted 9 lines
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +1 -1
                  goto err_hws;
          }
 
-       i915_gem_object_set_cache_coherency(h->hws, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(h->hws, I915_CACHE(WB));
          vaddr = i915_gem_object_pin_map_unlocked(h->hws, I915_MAP_WB);
          if (IS_ERR(vaddr)) {
                  err = PTR_ERR(vaddr);
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/selftest_migrate.c

drivers/gpu/drm/i915/gt/selftest_migrate.c static int perf_clear_blt(void *arg) · line 908

Quoted 9 lines

index 3def5ca72dec..a67ede65d816 100644

drivers/gpu/drm/i915/gt/selftest_migrate.c +0 -2
@@ -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),

drivers/gpu/drm/i915/gt/selftest_migrate.c static int perf_copy_blt(void *arg) · line 999

Quoted 10 lines
drivers/gpu/drm/i915/gt/selftest_migrate.c +1 -2
+                                      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),

drivers/gpu/drm/i915/gt/selftest_migrate.c static int perf_copy_blt(void *arg)

Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_migrate.c +1 -2
+                                     gt->i915->pat_uc,
                                        i915_gem_object_is_lmem(src),
                                        dst->mm.pages->sgl,
-                                     i915_gem_get_pat_index(gt->i915,
-                                                           

 I915_CACHE_NONE),

Review

Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_migrate.c +1 -0
+                                     gt->i915->pat_uc,
                                        i915_gem_object_is_lmem(dst),
                                        sz);
 
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/selftest_reset.c

drivers/gpu/drm/i915/gt/selftest_reset.c __igt_reset_stolen(struct intel_gt *gt, · line 90

Quoted 11 lines

index 79aa6ac66ad2..327dc9294e0f 100644

drivers/gpu/drm/i915/gt/selftest_reset.c +0 -4
@@ -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),

drivers/gpu/drm/i915/gt/selftest_reset.c __igt_reset_stolen(struct intel_gt *gt, · line 87

Quoted 2 lines
drivers/gpu/drm/i915/gt/selftest_reset.c +1 -1
-                                    0);
+               ggtt->vm.insert_page(&ggtt->vm, dma, 

ggtt->error_capture.start,

drivers/gpu/drm/i915/gt/selftest_reset.c __igt_reset_stolen(struct intel_gt *gt, · line 133

Quoted 12 lines
drivers/gpu/drm/i915/gt/selftest_reset.c +1 -4
+                                    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),

drivers/gpu/drm/i915/gt/selftest_reset.c __igt_reset_stolen(struct intel_gt *gt, · line 127

Quoted 2 lines
drivers/gpu/drm/i915/gt/selftest_reset.c +1 -1
-                                    0);
+               ggtt->vm.insert_page(&ggtt->vm, dma, 

ggtt->error_capture.start,

Review

Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_reset.c +1 -0
+                                    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.c

drivers/gpu/drm/i915/gt/selftest_timeline.c static int setup_watcher(struct hwsp_watcher *w,

Quoted 4 lines

index 39c3ec12df1a..87299158815f 100644

drivers/gpu/drm/i915/gt/selftest_timeline.c +0 -0
@@ -837,6 +837,7 @@ static int setup_watcher(struct hwsp_watcher *w, 

struct intel_gt *gt,

drivers/gpu/drm/i915/gt/selftest_timeline.c static int setup_watcher(struct hwsp_watcher *w, · line 838

Quoted 3 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +0 -0
          /* keep the same cache settings as timeline */
          i915_gem_object_set_pat_index(obj, 

tl->hwsp_ggtt->obj->pat_index);

drivers/gpu/drm/i915/gt/selftest_timeline.c static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt,

Quoted 3 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +1 -0
+
          w->map = i915_gem_object_pin_map_unlocked(obj,
 

 page_unmask_bits(tl->hwsp_ggtt->obj->mm.mapping));

Review

Quoted 2 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +0 -0
          if (IS_ERR(w->map)) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/selftest_tlb.c

Quoted 13 lines

index 3bd6b540257b..6049f01be219 100644

drivers/gpu/drm/i915/gt/selftest_tlb.c +0 -2
@@ -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;

drivers/gpu/drm/i915/gt/selftest_tlb.c pte_tlbinv(struct intel_context *ce, · line 160

Quoted 4 lines
drivers/gpu/drm/i915/gt/selftest_tlb.c +0 -1
@@ -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);

drivers/gpu/drm/i915/gt/selftest_tlb.c pte_tlbinv(struct intel_context *ce, · line 158

Quoted 1 line
drivers/gpu/drm/i915/gt/selftest_tlb.c +1 -0
+               ce->vm->insert_entries(ce->vm, &vb_res, 

ce->vm->i915->pat_uc,

Review

Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_tlb.c +1 -0
+                                      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/selftest_workarounds.c

Review

Quoted 13 lines

index 14a8b25b6204..900b4e19087f 100644

drivers/gpu/drm/i915/gt/selftest_workarounds.c +1 -1
@@ -111,7 +111,7 @@ read_nonprivs(struct intel_context *ce)
          if (IS_ERR(result))
                  return result;
 
-       i915_gem_object_set_cache_coherency(result, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(result, I915_CACHE(WB));
 
          cs = i915_gem_object_pin_map_unlocked(result, I915_MAP_WB);
          if (IS_ERR(cs)) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/uc/intel_guc.c

drivers/gpu/drm/i915/gt/uc/intel_guc.c struct i915_vma *intel_guc_allocate_vma(struct

Quoted 4 lines

index 2eb891b270ae..3a862051423c 100644

drivers/gpu/drm/i915/gt/uc/intel_guc.c +0 -0
@@ -749,7 +749,7 @@ struct i915_vma *intel_guc_allocate_vma(struct 

intel_guc *guc, u32 size)

drivers/gpu/drm/i915/gt/uc/intel_guc.c struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)

Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.c +0 -1
           * as WC on CPU side and UC (PAT index 2) on GPU side
           */
          if (IS_METEORLAKE(gt->i915))
-               i915_gem_object_set_cache_coherency(obj, 

I915_CACHE_NONE);

Review

Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.c +1 -0
+               i915_gem_object_set_cache_coherency(obj, I915_CACHE(UC));
 
          vma = i915_vma_instance(obj, &gt->ggtt->vm, NULL);
          if (IS_ERR(vma))
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c

drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c static void uc_fw_bind_ggtt(struct intel_uc_fw

Quoted 4 lines

index d408856ae4c0..e099414d624d 100644

drivers/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)

drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c static void uc_fw_bind_ggtt(struct intel_uc_fw *uc_fw)

Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +0 -1
          if (ggtt->vm.raw_insert_entries)
                  ggtt->vm.raw_insert_entries(&ggtt->vm, vma_res,
-                                           

i915_gem_get_pat_index(ggtt->vm.i915,

drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c static void uc_fw_bind_ggtt(struct intel_uc_fw · line 994

Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +0 -1
-                                                                 

 I915_CACHE_NONE),

drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c static void uc_fw_bind_ggtt(struct intel_uc_fw · line 993

Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +1 -1
-                                           pte_flags);
+                                           ggtt->vm.i915->pat_uc, 

pte_flags);

Quoted 3 lines

         else
                 ggtt->vm.insert_entries(&ggtt->vm, vma_res, -

i915_gem_get_pat_index(ggtt->vm.i915,

Quoted 1 line

-

 I915_CACHE_NONE),

Quoted 2 lines

-                                       pte_flags);
+                                       ggtt->vm.i915->pat_uc,

pte_flags);

Review

Quoted 4 lines

 }

 static void uc_fw_unbind_ggtt(struct intel_uc_fw *uc_fw)

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_cache.c

Quoted 14 lines

new file mode 100644
index 000000000000..4d0033bf1658

drivers/gpu/drm/i915/i915_cache.c new file +9 -0
@@ -0,0 +1,72 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_print.h>
+
+#include "i915_cache.h"

drivers/gpu/drm/i915/i915_cache.c line 19

Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.c new file +10 -0
+#include "i915_drv.h"
+
+int i915_cache_init(struct drm_i915_private *i915)
+{
+       int ret;
+
+       ret = i915_cache_find_pat(i915, I915_CACHE(UC));
+       if (ret < 0)
+               return -ENODEV;
+       drm_info(&i915->drm, "Using PAT index %u for uncached 

access\n", ret);

drivers/gpu/drm/i915/i915_cache.c line 22

Quoted 3 lines
drivers/gpu/drm/i915/i915_cache.c new file +3 -0
+       i915->pat_uc = ret;
+
+       ret = i915_cache_find_pat(i915, I915_CACHE(WB));

For MTL, this would find pat index 0, but KMD wants pat index 3.

drivers/gpu/drm/i915/i915_cache.c

Quoted 3 lines
drivers/gpu/drm/i915/i915_cache.c new file +3 -0
+       if (ret < 0)
+               return -ENODEV;
+       drm_info(&i915->drm, "Using PAT index %u for write-back 

access\n", ret);

drivers/gpu/drm/i915/i915_cache.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_cache.c new file +6 -0
+       i915->pat_wb = ret;
+
+       return 0;
+}
+
+int i915_cache_find_pat(struct drm_i915_private *i915, i915_cache_t 

cache)

Quoted 21 lines
drivers/gpu/drm/i915/i915_cache.c new file +21 -0
+{
+       const struct intel_device_info *info = INTEL_INFO(i915);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(info->cache_modes); i++) {
+               if (info->cache_modes[i] == cache)
+                       return i;
+       }
+
+       return -1;
+}
+
+void i915_cache_print(struct drm_printer *p, i915_cache_t cache)
+{
+       const enum i915_cache_mode 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",

drivers/gpu/drm/i915/i915_cache.c

Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.c new file +10 -0
+       };
+       static const char *flag_str[] = {
+               [I915_CACHE_FLAG_L3] = "L3",
+               [I915_CACHE_FLAG_COH1W] = "1-Way-Coherent",
+               [I915_CACHE_FLAG_COH2W] = "2-Way-Coherent",
+               [I915_CACHE_FLAG_CLOS1] = "CLOS1",
+               [I915_CACHE_FLAG_CLOS2] = "CLOS2",
+       };
+
+       if (mode == I915_CACHE_MODE_UNKNOWN || mode > 

ARRAY_SIZE(mode_str)) {

Review

Quoted 11 lines
drivers/gpu/drm/i915/i915_cache.c new file +10 -0
+               drm_printf(p, "0x%x", cache);
+       } else {
+               unsigned long bit;
+
+               drm_printf(p, "%s", mode_str[mode]);
+
+               for_each_set_bit(bit, &flags, sizeof(i915_cache_t))
+                       drm_printf(p, "-%s", flag_str[bit]);
+       }
+}
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_cache.h

Quoted 41 lines

new file mode 100644
index 000000000000..ffb621d8a8a0

drivers/gpu/drm/i915/i915_cache.h new file +36 -0
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef __I915_CACHE_H__
+#define __I915_CACHE_H__
+
+#include <linux/types.h>
+
+struct drm_printer;
+
+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_##flag)))
+
+#define I915_CACHE_MODE(cache) \
+       (enum i915_cache_mode)(((i915_cache_t)(cache)) & 0xff)
+#define I915_CACHE_FLAGS(cache) \
+       (unsigned int)((((i915_cache_t)(cache) & 0xff00)) >> 16)
+
+/* Cache modes */
+enum i915_cache_mode {
+       I915_CACHE_MODE_UNKNOWN = 0,
+       I915_CACHE_MODE_UC,
+       I915_CACHE_MODE_WB,
+       I915_CACHE_MODE_WT,
+       I915_CACHE_MODE_WC
+};

drivers/gpu/drm/i915/i915_cache.h line 46

Quoted 10 lines
drivers/gpu/drm/i915/i915_cache.h new file +10 -0
+
+/* Cache mode flag bits */
+#define I915_CACHE_FLAG_L3     (0)
+#define I915_CACHE_FLAG_COH1W  (1)
+#define I915_CACHE_FLAG_COH2W  (2)
+#define I915_CACHE_FLAG_CLOS1  (3)
+#define I915_CACHE_FLAG_CLOS2  (4)
+
+int i915_cache_init(struct drm_i915_private *i915);
+int i915_cache_find_pat(struct drm_i915_private *i915, i915_cache_t 

cache);

Review

Quoted 4 lines
drivers/gpu/drm/i915/i915_cache.h new file +3 -0
+void i915_cache_print(struct drm_printer *p, i915_cache_t cache);
+
+#endif /* __I915_CACHE_H__ */
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_debugfs.c

drivers/gpu/drm/i915/i915_debugfs.c static const char *stringify_vma_type(const

Quoted 4 lines

index 4de44cf1026d..03d366e0bdf7 100644

drivers/gpu/drm/i915/i915_debugfs.c +0 -0
@@ -140,68 +140,33 @@ static const char *stringify_vma_type(const 

struct i915_vma *vma)

Quoted 48 lines
drivers/gpu/drm/i915/i915_debugfs.c +0 -45
          return "ppgtt";
  }
 
-static const char *i915_cache_level_str(struct drm_i915_gem_object *obj)
-{
-       struct drm_i915_private *i915 = obj_to_i915(obj);
-
-       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";
-               }
-       } 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";
-               }
-       }
-}
-
Quoted 2 lines

 void
 i915_debugfs_describe_obj(struct seq_file *m, struct

drm_i915_gem_object *obj)

Quoted 6 lines

 {
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+       struct drm_printer p = drm_seq_file_printer(m); struct i915_vma *vma;
         int pin_count = 0;

Quoted 12 lines

-       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"

: "");

Quoted 3 lines

+                  obj->write_domain);
+
+        i915_cache_print(&p,

INTEL_INFO(i915)->cache_modes[obj->pat_index]);

Quoted 12 lines

+       if (obj->pat_set_by_user)
+               drm_puts(&p, "!");

drivers/gpu/drm/i915/i915_debugfs.c +7 -0
+
+       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);

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_driver.c

drivers/gpu/drm/i915/i915_driver.c static int i915_driver_early_probe(struct

Quoted 12 lines

index 294b022de22b..8663388a524f 100644

drivers/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"
@@ -240,6 +241,10 @@ static int i915_driver_early_probe(struct 

drm_i915_private *dev_priv)

Review

Quoted 11 lines
drivers/gpu/drm/i915/i915_driver.c +4 -0
          i915_memcpy_init_early(dev_priv);
          intel_runtime_pm_init_early(&dev_priv->runtime_pm);
 
+       ret = i915_cache_init(dev_priv);
+       if (ret < 0)
+               return ret;
+
          ret = i915_workqueues_init(dev_priv);
          if (ret < 0)
                  return ret;
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h

Review

Quoted 14 lines

index a18013787c9f..462b076e2650 100644

drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -250,6 +250,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.
           *
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_gem.c

drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pread(struct drm_i915_gem_object *obj, · line 423

Quoted 6 lines

index b46d7a2dab1a..ef6d33c2c288 100644

drivers/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,

Quoted 1 line

        offset >> PAGE_SHIFT),

Quoted 3 lines

-                                            node.start,
-                                            i915_gem_get_pat_index(i915, -

I915_CACHE_NONE), 0);

Quoted 1 line

+                                            node.start,

i915->pat_uc, 0);

drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct

Quoted 4 lines

                 } 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,

drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct · line 602

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +0 -0
                          ggtt->vm.insert_page(&ggtt->vm,
 

i915_gem_object_get_dma_address(obj,

Quoted 1 line

        offset >> PAGE_SHIFT),

Quoted 3 lines

-                                            node.start,
-                                            i915_gem_get_pat_index(i915, -

I915_CACHE_NONE), 0);

Quoted 1 line

+                                            node.start,

i915->pat_uc, 0);

Quoted 1 line

                         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 5 lines
drivers/gpu/drm/i915/i915_gem.c +0 -2
          unsigned int i;
          int ret;
 
-       /*
-        * In the proccess of replacing cache_level with pat_index a 

tricky

drivers/gpu/drm/i915/i915_gem.c int i915_gem_init(struct drm_i915_private · line 1153

Quoted 1 line
drivers/gpu/drm/i915/i915_gem.c +0 -1
-        * 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 · line 1155

Quoted 2 lines
drivers/gpu/drm/i915/i915_gem.c +0 -2
-        * in case this enum is changed, PTE encode would be broken.
-        * Add a WARNING here. And remove when we completely quit 

using this

drivers/gpu/drm/i915/i915_gem.c int i915_gem_init(struct drm_i915_private *dev_priv)

Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +0 -8
-        * 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. */

Quoted 1 line

         if (intel_vgpu_active(dev_priv) &&

!intel_vgpu_has_huge_gtt(dev_priv))

Quoted 1 line

                 RUNTIME_INFO(dev_priv)->page_sizes =

I915_GTT_PAGE_SIZE_4K;

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_gpu_error.c

drivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct

Quoted 4 lines

index 92ca81f9feab..6a6f97aaec60 100644

drivers/gpu/drm/i915/i915_gpu_error.c +0 -0
@@ -1124,14 +1124,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 3 lines
drivers/gpu/drm/i915/i915_gpu_error.c +0 -0
                          mutex_lock(&ggtt->error_mutex);
                          if (ggtt->vm.raw_insert_page)
                                  ggtt->vm.raw_insert_page(&ggtt->vm, 

dma, slot,

drivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct · line 1127

Quoted 1 line
drivers/gpu/drm/i915/i915_gpu_error.c +0 -1
-                                                       

 i915_gem_get_pat_index(gt->i915,

drivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct · line 1128

Quoted 1 line
drivers/gpu/drm/i915/i915_gpu_error.c +0 -1
-                                                                     

          I915_CACHE_NONE),

drivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct · line 1127

Quoted 1 line
drivers/gpu/drm/i915/i915_gpu_error.c +1 -0
+                                                       

 ggtt->vm.i915->pat_uc,

Quoted 3 lines
drivers/gpu/drm/i915/i915_gpu_error.c +0 -0
                                                           0);

                         else ggtt->vm.insert_page(&ggtt->vm, dma,

slot,

Quoted 1 line

-

 i915_gem_get_pat_index(gt->i915,

Quoted 1 line

-

      I915_CACHE_NONE),

Quoted 2 lines

-                                                    0); +

 ggtt->vm.i915->pat_uc, 0);

Quoted 3 lines

                         mb();

                         s = io_mapping_map_wc(&ggtt->iomap, slot,

PAGE_SIZE);

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_pci.c

drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow

Quoted 12 lines

index dea3609fc496..c0c6248fbc78 100644

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");

drivers/gpu/drm/i915/i915_pci.c __diag_ignore_all("-Woverride-init", "Allow

Quoted 67 lines
drivers/gpu/drm/i915/i915_pci.c +30 -24
          .__runtime.graphics.ip.ver = (x), \
          .__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 \
+       .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 \
+       .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), \
          }
 
-#define MTL_CACHELEVEL \
-       .cachelevel_to_pat = { \
-               [I915_CACHE_NONE]   = 2, \
-               [I915_CACHE_LLC]    = 3, \
-               [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), \
          }
 
  /* Keep in gen based order, and chronological order within a gen */
@@ -100,7 +107,7 @@ __diag_ignore_all("-Woverride-init", "Allow 

overriding 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", "Allow 

overriding 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 = {
          .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_definition xelpmp_extra_gt[] = {

drivers/gpu/drm/i915/i915_pci.c +1 -1
@@ -841,7 +848,7 @@ static const struct intel_device_info mtl_info = {
          .memory_regions = REGION_SMEM | REGION_STOLEN_LMEM,
          .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/i915_perf.c

drivers/gpu/drm/i915/i915_perf.c static int alloc_oa_buffer(struct

Quoted 4 lines

index 0a111b281578..1b8e067f37dd 100644

drivers/gpu/drm/i915/i915_perf.c +0 -0
@@ -1861,7 +1861,7 @@ static int alloc_oa_buffer(struct 

i915_perf_stream *stream)

Review

Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +1 -1
                  return PTR_ERR(bo);
          }
 
-       i915_gem_object_set_cache_coherency(bo, I915_CACHE_LLC);
+       i915_gem_object_set_cache_coherency(bo, I915_CACHE(WB));
 
          /* PreHSW required 512K alignment, HSW requires 16M */
          vma = i915_vma_instance(bo, &gt->ggtt->vm, NULL);
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/intel_device_info.h

Quoted 16 lines

index dbfe6443457b..f48a21895a85 100644

drivers/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 "gt/intel_engine_types.h"
@@ -243,8 +245,8 @@ struct intel_device_info {
           */
          const struct intel_runtime_info __runtime;
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 248

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];

I was commenting on the array size here. It's probably better to make it 16 because there are 4 PAT index bits defined in the PTE. Indices above max_pat_index are not used, but theoretically new mode could be added. Well, it's up to you, not likely to happen anyway.

Ah okay. I am not too concerned. Compiler will let us know if it happens.

Unrelated to this comment - what about i915_gem_object_can_bypass_llc? Could we do better (less pessimistic) with something like my approach and so maybe penalize MTL less?

Regards,

Tvrtko

#7 lore raw
Quoted 182 lines
Quoted 160 lines
Quoted 160 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..

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/display/intel_dpt.c      |   2 +-
 drivers/gpu/drm/i915/display/intel_fb_pin.c   |   2 +-
 .../drm/i915/display/intel_plane_initial.c    |   4 +-
 drivers/gpu/drm/i915/gem/i915_gem_domain.c    |  66 +++++-----
 drivers/gpu/drm/i915/gem/i915_gem_domain.h    |   7 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  13 +-
 drivers/gpu/drm/i915/gem/i915_gem_internal.c  |   6 +-
 drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.c    | 116 +++++++++--------
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |   9 +-
 .../gpu/drm/i915/gem/i915_gem_object_types.h  | 117 +++---------------
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  10 +-
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |  13 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c  |  43 ++++---
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   2 +-
 .../drm/i915/gem/selftests/huge_gem_object.c  |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   8 +-
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   4 +-
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c          |  19 +--
 drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   2 +-
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |  33 ++---
 drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c     |   4 +-
 drivers/gpu/drm/i915/gt/intel_gtt.c           |   2 +-
 drivers/gpu/drm/i915/gt/intel_gtt.h           |   3 +-
 drivers/gpu/drm/i915/gt/intel_migrate.c       |  11 +-
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   6 +-
 .../gpu/drm/i915/gt/intel_ring_submission.c   |   2 +-
 drivers/gpu/drm/i915/gt/intel_timeline.c      |   2 +-
 drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |   2 +-
 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   |   1 +
 drivers/gpu/drm/i915/gt/selftest_tlb.c        |   5 +-
 .../gpu/drm/i915/gt/selftest_workarounds.c    |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   2 +-
 drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c      |   8 +-
 drivers/gpu/drm/i915/i915_cache.c             |  72 +++++++++++
 drivers/gpu/drm/i915/i915_cache.h             |  49 ++++++++
 drivers/gpu/drm/i915/i915_debugfs.c           |  65 +++-------
 drivers/gpu/drm/i915/i915_driver.c            |   5 +
 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/i915_perf.c              |   2 +-
 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   |   8 +-
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  13 +-
 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   2 +-
 .../drm/i915/selftests/intel_memory_region.c  |   4 +-
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  12 +-
 drivers/gpu/drm/i915/selftests/mock_region.c  |   2 +-
 54 files changed, 440 insertions(+), 485 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
index 2be9dd960540..2c3da8f0c78e 100644
@@ -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/display/intel_dpt.c +1 -1
index 7c5fddb203ba..5baf0d27a288 100644
@@ -268,7 +268,7 @@ intel_dpt_create(struct intel_framebuffer *fb)
 
         ret = i915_gem_object_lock_interruptible(dpt_obj, NULL);
         if (!ret) {
-               ret = i915_gem_object_set_cache_level(dpt_obj, I915_CACHE_NONE);
+               ret = i915_gem_object_set_cache(dpt_obj, I915_CACHE(UC));
                 i915_gem_object_unlock(dpt_obj);
         }
         if (ret) {
drivers/gpu/drm/i915/display/intel_fb_pin.c +1 -1
index fffd568070d4..dcf54b354a74 100644
@@ -66,7 +66,7 @@ intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
                                 continue;
                 }
 
-               ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
+               ret = i915_gem_object_set_cache(obj, I915_CACHE(UC));
                 if (ret)
                         continue;
 
drivers/gpu/drm/i915/display/intel_plane_initial.c +2 -2
index 736072a8b2b0..9988f6562392 100644
@@ -121,8 +121,8 @@ initial_plane_vma(struct drm_i915_private *i915,
          * cache_level during fbdev initialization. The
          * unbind there would get stuck waiting for rcu.
          */
-       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
-                                           I915_CACHE_WT : I915_CACHE_NONE);
+       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ? I915_CACHE(WT) :
+                                                               I915_CACHE(UC));
 
         switch (plane_config->tiling) {
         case I915_TILING_NONE:
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
index dfaaa8b66ac3..f899da2c622a 100644
@@ -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;
 
Quoted 16 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj) · line 32

Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -9
-       /*
-        * 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;

This logic was changed for objects with pat index set by user here. It used to return false
regardless the cache mode. But now it returns true if its cache mode is neither UC nor WT.

Yes, that was half of the motivation of the refactory. Before the PAT index series code was like this:

       return !(obj->cache_level == I915_CACHE_NONE ||
                obj->cache_level == I915_CACHE_WT);
Quoted 6 lines

So kernel knew it needs to flush only if caching mode is neither UC or WT. With the PAT index series you changed it to:

       return !(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) ||
                i915_gem_object_has_cache_level(obj, I915_CACHE_WT));

And as i915_gem_object_has_cache_level was changed to always return true if PAT was set by user, that made the check meaningless for such objects.

But the point is that the KMD should not flush the cache for objects with PAT set by user because UMD is handling the cache conherency. That is the design. Well doing so wouldn't cause functional issue, but it's unecessary and might have performance impact.

Quoted 55 lines

With my refactoring it becomes meaningful again and restores to the original behaviour. That's the intent at least.

Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +11 -11
 bool i915_gem_cpu_write_needs_clflush(struct drm_i915_gem_object *obj)
@@ -255,9 +249,9 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 }
 
 /**
- * i915_gem_object_set_cache_level - Changes the cache-level of an object across all VMA.
+ * i915_gem_object_set_cache - Changes the cache-level of an object across all VMA.
  * @obj: object to act on
- * @cache_level: new cache level to set for the object
+ * @cache: new caching mode to set for the object
  *
  * After this function returns, the object will be in the new cache-level
  * across all GTT and the contents of the backing storage will be coherent,
@@ -269,19 +263,28 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
  * cache coherency) and all non-MOCS GPU access will also be uncached so
  * that all direct access to the scanout remains coherent.
  */
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-                                   enum i915_cache_level cache_level)
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+                             i915_cache_t cache)
 {
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
         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))
+       ret = i915_cache_find_pat(i915, cache);
+       if (ret < 0) {
+               struct drm_printer p =
+                       drm_err_printer("Attempting to use unknown caching mode ");
+
+               i915_cache_print(&p, cache);
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 282

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +4 -0
+               drm_puts(&p, "!\n");
+
+               return -EINVAL;
+       } else if (ret == obj->pat_index) {
                 return 0;

We will have to do this conversion and checking again later in this function when calling i915_gem_object_set_cache_coherency().

Yes the double lookup part is a bit naff. It is not super required apart for validating internal callers (could be a debug build only feature perhaps) and to see if PAT index has changed and so whether it needs to call i915_gem_object_wait before proceeding to i915_gem_object_set_cache_coherency...

Quoted 7 lines
Quoted 3 lines

My thought was to simply remove the use of cache_level/cache and replace it with pat_idex. Conversion from cache modes to pat index should be done before calling any function used to consume cache_level/cache.

... I could probably call the setter which takes PAT index instead of i915_gem_object_set_cache_coherency few lines below. That would skip the double lookup and make you happy(-ier)?

Do you see any problem just letting these functions take pat_index as the second argument? These functions are currently called with a constant cache_level/mode, if we have INTEL_INFO(i915)->pat_uc/wt/wb set properly, using pat index makes no difference, right?

Quoted 73 lines
Quoted 38 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 283

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+       } else if (obj->pat_set_by_user) {

Shouldn't this if-statement be placed at the beginning of this function? the original
i915_gem_object_has_cache_level() would return true if (obj->pat_set_by_user), so the
function returns right away.

Quoted 17 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5 -1
+               drm_notice_once(&i915->drm,
+                               "Attempting to change caching mode on an object with fixed PAT!\n");
+               return -EINVAL;
+       }
 
         ret = i915_gem_object_wait(obj,
                                    I915_WAIT_INTERRUPTIBLE |
@@ -291,7 +294,7 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
                 return ret;
 
         /* Always invalidate stale cachelines */
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);
         obj->cache_dirty = true;
 
         /* The cache-level will be applied when each vma is rebound. */

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, · line 332

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -2
@@ -326,10 +329,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))

This looks wrong, at least for MTL. Prior to MTL the GPU automatically snoop CPU cache, but from MTL onward you have to specify if WB or WB + 1-WAY COH is needed. And for KMD, cacheable mode means WB + 1-WAY COH for MTL to keep the behavior consistent.

Quoted 8 lines

This used to be taken care of by i915_gem_get_pat_index() call. With that being replaced by i915_cache_find_pat(), you would need to do something there. But, without cachelevel_to_pat[], you might end up hard coding something directly in the function, and that is platform dependent. hmm..., I don't really like this idea.

That's why I commented in v1 that we should use INTEL_INFO(i915)->pat_uc/wb/wt instead of enum i915_cache_level or i915_cache_t.

I think I get it. I hope so.. So if I made the tables like this:

#define LEGACY_CACHE_MODES \
       .cache_modes = { \
               [0] = I915_CACHE(UC), \
               [1] = _I915_CACHE(WB, COH1W), \
               [2] = _I915_CACHE(WB, COH1W | L3), \ // 2way??
               [3] = I915_CACHE(WT), \
        }
#define GEN12_CACHE_MODES \
       .cache_modes = { \
               [0] = _I915_CACHE(WB, COH1W), \
               [1] = I915_CACHE(WC), \
               [2] = I915_CACHE(WT), \
               [3] = I915_CACHE(UC), \
        }
#define MTL_CACHE_MODES \
       .cache_modes = { \
               [0] = _I915_CACHE(WB, COH1W), \
               [1] = I915_CACHE(WT), \
               [2] = I915_CACHE(UC), \
               [3] = _I915_CACHE(WB, COH1W), \
               [4] = _I915_CACHE(WB, COH2W), \
Quoted 5 lines

And made i915->pat_wc look up _I915_CACHE(WB, COH1W) would that work? Hmm and also all "has cache level" call sites would need to look not just for WB but WB+COH1W.

Would it work? Too ugly?

I don't think this would work. The cache_modes needs to be aligned with BSpec, otherwise checkings for INTEL_INFO(i915)->cache_modes[obj->pat_index] might become invalid. Also, COH1W/2W were not even there for platforms prior to MTL.

I still think setting INTEL_INFO(i915)->pat_uc/wt/wb is the best solution. With that we can also eliminate the use of I915_CACHE({UC|WT|WB}).

Quoted 80 lines
Quoted 44 lines
Quoted 17 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -2
                 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;
@@ -344,7 +346,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
         struct drm_i915_private *i915 = to_i915(dev);
         struct drm_i915_gem_caching *args = data;
         struct drm_i915_gem_object *obj;
-       enum i915_cache_level level;
+       i915_cache_t cache;
         int ret = 0;
 
         if (IS_DGFX(i915))

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 360

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
@@ -355,7 +357,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 
         switch (args->caching) {
         case I915_CACHING_NONE:
-               level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);

For code like this, my thought was

(quoted diff) +1 -1
-               level = I915_CACHE_NONE;
+               pat_index = INTEL_INFO(i915)->pat_uc;

And later the set_cache call should take pat_index as argument instead of cache mode.

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                 break;
         case I915_CACHING_CACHED:
                 /*
@@ -367,10 +369,10 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
                 if (!HAS_LLC(i915) && !HAS_SNOOP(i915))
                         return -ENODEV;
 
-               level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);
(quoted diff) +1 -1
-               level = I915_CACHE_LLC;
+               pat_index = INTEL_INFO(i915)->pat_wb;
Quoted 3 lines

This should take care of the WB + 1-WAY COH issue for MTL mentioned above, assuming the i915_cache_init() set pat_wb properly, and the i915_gem_object_set_cache() consumes pat_index instead of cache mode.

That works too yes.

Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5 -5
                 break;
         case I915_CACHING_DISPLAY:
-               level = HAS_WT(i915) ? I915_CACHE_WT : I915_CACHE_NONE;
+               cache = HAS_WT(i915) ? I915_CACHE(WT) : I915_CACHE(UC);
                 break;
         default:
                 return -EINVAL;
@@ -409,7 +411,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
         if (ret)
                 goto out;
 
-       ret = i915_gem_object_set_cache_level(obj, level);
+       ret = i915_gem_object_set_cache(obj, cache);
         i915_gem_object_unlock(obj);
 
 out:
@@ -448,9 +450,9 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
          * of uncaching, which would allow us to flush all the LLC-cached data
          * with that bit in the PTE to main memory with just one PIPE_CONTROL.
          */
-       ret = i915_gem_object_set_cache_level(obj,
-                                             HAS_WT(i915) ?
-                                             I915_CACHE_WT : I915_CACHE_NONE);
+       ret = i915_gem_object_set_cache(obj,
+                                       HAS_WT(i915) ?
+                                       I915_CACHE(WT) : I915_CACHE(UC));
         if (ret)
                 return ERR_PTR(ret);
 

[...]

Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj) · line 225

Quoted 7 lines

bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj)

drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
@@ -215,6 +222,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? */

This is needed because UMD's assume zero-initialized BO's are really zero'ed out before getting the handles to the BO's (See VLK-46522). Otherwise UMD's could read stale data, thus cause security issues.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
         if (obj->pat_set_by_user)
                 return true;
 

[...]

Quoted 28 lines
Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/i915/intel_device_info.h +2 -0
index dbfe6443457b..f48a21895a85 100644
@@ -27,6 +27,8 @@
 
 #include <uapi/drm/i915_drm.h>
 
+#include "i915_cache.h"
+
 #include "intel_step.h"
 
 #include "gt/intel_engine_types.h"
@@ -243,8 +245,8 @@ struct intel_device_info {
          */
         const struct intel_runtime_info __runtime;
 
Quoted 10 lines

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 248

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];

I was commenting on the array size here. It's probably better to make it 16 because there are 4 PAT index bits defined in the PTE. Indices above max_pat_index
are not used, but theoretically new mode could be added. Well, it's up to you,
not likely to happen anyway.

Quoted 5 lines

Ah okay. I am not too concerned. Compiler will let us know if it happens.

Unrelated to this comment - what about i915_gem_object_can_bypass_llc? Could we do better (less pessimistic) with something like my approach and so maybe penalize MTL less?

The problem is that, for the BO's managed by UMD's, the KMD doesn't know whether they are going to be mapped as cacheable or uncacheable on the CPU side. The PAT index controls GPU access only. That's why we make sure all BO's with PAT set by UMD (which means UMD will take control and managing the coherency) are clflush'ed.

-Fei

Quoted 3 lines

Regards,

Tvrtko

#8 lore raw
Quoted 212 lines · Fei
Quoted 6 lines
Quoted 6 lines
Quoted 6 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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

   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

Quoted 65 lines
Quoted 65 lines
Quoted 65 lines

what you think. I think it has potential.

Proper commit message can come later.

---
 drivers/gpu/drm/i915/Makefile                 |   1 + drivers/gpu/drm/i915/display/intel_dpt.c      |   2 +- drivers/gpu/drm/i915/display/intel_fb_pin.c   |   2 +-

 .../drm/i915/display/intel_plane_initial.c    |   4 +-
 drivers/gpu/drm/i915/gem/i915_gem_domain.c    |  66 +++++-----
 drivers/gpu/drm/i915/gem/i915_gem_domain.h    |   7 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    |  13 +-

 drivers/gpu/drm/i915/gem/i915_gem_internal.c  |   6 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c      |  10 +- drivers/gpu/drm/i915/gem/i915_gem_object.c    | 116 +++++++++-------- drivers/gpu/drm/i915/gem/i915_gem_object.h    |   9 +- .../gpu/drm/i915/gem/i915_gem_object_types.h  | 117 +++--------------- drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  10 +- drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |  13 +-

 drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c  |  43 ++++---
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   2 +-
 .../drm/i915/gem/selftests/huge_gem_object.c  |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   8 +-

 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   4 +- drivers/gpu/drm/i915/gt/gen8_ppgtt.c          |  19 +-- drivers/gpu/drm/i915/gt/intel_engine_cs.c     |   2 +- drivers/gpu/drm/i915/gt/intel_ggtt.c          |  33 ++--- drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c     |   4 +- drivers/gpu/drm/i915/gt/intel_gtt.c           |   2 +- drivers/gpu/drm/i915/gt/intel_gtt.h           |   3 +- drivers/gpu/drm/i915/gt/intel_migrate.c       |  11 +- drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   6 +- .../gpu/drm/i915/gt/intel_ring_submission.c   |   2 +- drivers/gpu/drm/i915/gt/intel_timeline.c      |   2 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c  |   2 +- 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   |   1 + drivers/gpu/drm/i915/gt/selftest_tlb.c        |   5 +- .../gpu/drm/i915/gt/selftest_workarounds.c    |   2 +- drivers/gpu/drm/i915/gt/uc/intel_guc.c        |   2 +- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c      |   8 +- drivers/gpu/drm/i915/i915_cache.c             |  72 +++++++++++ drivers/gpu/drm/i915/i915_cache.h             |  49 ++++++++ drivers/gpu/drm/i915/i915_debugfs.c           |  65 +++------- drivers/gpu/drm/i915/i915_driver.c            |   5 + 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/i915_perf.c              |   2 +- 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   |   8 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  13 +-

 drivers/gpu/drm/i915/selftests/igt_spinner.c  |   2 +-
 .../drm/i915/selftests/intel_memory_region.c  |   4 +-
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  12 +-
 drivers/gpu/drm/i915/selftests/mock_region.c  |   2 +-
 54 files changed, 440 insertions(+), 485 deletions(-)

 create mode 100644 drivers/gpu/drm/i915/i915_cache.c create mode 100644 drivers/gpu/drm/i915/i915_cache.h

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/Makefile

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index 2be9dd960540..2c3da8f0c78e 100644

drivers/gpu/drm/i915/Makefile +0 -0
@@ -30,6 +30,7 @@ subdir-ccflags-y += -I$(srctree)/$(src)
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
drivers/gpu/drm/i915/Makefile +1 -0
  # 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/display/intel_dpt.c

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/display/intel_dpt.c intel_dpt_create(struct intel_framebuffer *fb) · line 271

Quoted 8 lines

index 7c5fddb203ba..5baf0d27a288 100644

drivers/gpu/drm/i915/display/intel_dpt.c +0 -1
@@ -268,7 +268,7 @@ intel_dpt_create(struct intel_framebuffer *fb)
 
          ret = i915_gem_object_lock_interruptible(dpt_obj, NULL);
          if (!ret) {
-               ret = i915_gem_object_set_cache_level(dpt_obj, 

I915_CACHE_NONE);

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/display/intel_dpt.c intel_dpt_create(struct intel_framebuffer *fb) · line 271

Quoted 1 line
drivers/gpu/drm/i915/display/intel_dpt.c +1 -0
+               ret = i915_gem_object_set_cache(dpt_obj, 

I915_CACHE(UC));

Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
drivers/gpu/drm/i915/display/intel_dpt.c +0 -0
                  i915_gem_object_unlock(dpt_obj);
          }
          if (ret) {
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/display/intel_fb_pin.c

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/display/intel_fb_pin.c intel_pin_fb_obj_dpt(struct drm_framebuffer *fb, · line 69

Quoted 8 lines

index fffd568070d4..dcf54b354a74 100644

drivers/gpu/drm/i915/display/intel_fb_pin.c +0 -1
@@ -66,7 +66,7 @@ intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
                                  continue;
                  }
 
-               ret = i915_gem_object_set_cache_level(obj, 

I915_CACHE_NONE);

Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
drivers/gpu/drm/i915/display/intel_fb_pin.c +1 -0
+               ret = i915_gem_object_set_cache(obj, I915_CACHE(UC));
                  if (ret)
                          continue;
 
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/display/intel_plane_initial.c

Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/i915/display/intel_plane_initial.c initial_plane_vma(struct drm_i915_private *i915, · line 125

Quoted 9 lines

index 736072a8b2b0..9988f6562392 100644

drivers/gpu/drm/i915/display/intel_plane_initial.c +0 -2
@@ -121,8 +121,8 @@ initial_plane_vma(struct drm_i915_private *i915,
           * cache_level during fbdev initialization. The
           * unbind there would get stuck waiting for rcu.
           */
-       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
-                                           I915_CACHE_WT : 

I915_CACHE_NONE);

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/display/intel_plane_initial.c initial_plane_vma(struct drm_i915_private *i915, · line 124

Quoted 1 line
drivers/gpu/drm/i915/display/intel_plane_initial.c +1 -0
+       i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ? 

I915_CACHE(WT) :

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/display/intel_plane_initial.c initial_plane_vma(struct drm_i915_private *i915, · line 125

Quoted 1 line
drivers/gpu/drm/i915/display/intel_plane_initial.c +1 -0
+                                                               

I915_CACHE(UC));

Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
drivers/gpu/drm/i915/display/intel_plane_initial.c +0 -0
          switch (plane_config->tiling) {

         case I915_TILING_NONE:

(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gem/i915_gem_domain.c

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

index dfaaa8b66ac3..f899da2c622a 100644

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -8,6 +8,7 @@
  #include "display/intel_frontbuffer.h"
  #include "gt/intel_gt.h"
 
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+#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)

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -2
          if (IS_DGFX(i915))
                  return false;
 
-       /*
-        * For objects created by userspace through GEM_CREATE with 

pat_index

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · line 32

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * set by set_pat extension, 

i915_gem_object_has_cache_level() will

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · line 33

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * always return true, because the coherency of such object 

is managed

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · line 34

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * by userspace. Othereise the call here would fall back to 

checking

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -3
-        * whether the object is un-cached or write-through.
-        */
-       return !(i915_gem_object_has_cache_level(obj, 

I915_CACHE_NONE) ||

Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · line 31

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
-                i915_gem_object_has_cache_level(obj, I915_CACHE_WT));
+       return i915_gem_object_has_cache_mode(obj, 

I915_CACHE_MODE_UC) != 1 &&

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct · 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;

Quoted 7 lines
Quoted 5 lines

This logic was changed for objects with pat index set by user here. It used to return false
regardless the cache mode. But now it returns true if its cache mode is neither UC nor WT.

Yes, that was half of the motivation of the refactory. Before the PAT

index series code was like this:

Quoted 5 lines

       return !(obj->cache_level == I915_CACHE_NONE || obj->cache_level == I915_CACHE_WT);

So kernel knew it needs to flush only if caching mode is neither UC

or WT. With the PAT index series you changed it to:

Quoted 4 lines

       return !(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) || i915_gem_object_has_cache_level(obj, I915_CACHE_WT));

Quoted 7 lines
Quoted 1 line

And as i915_gem_object_has_cache_level was changed to always return

true if PAT was set by user, that made the check meaningless for such objects.

But the point is that the KMD should not flush the cache for objects with PAT set by user because UMD is handling the cache conherency. That is the design. Well doing so wouldn't cause functional issue, but it's unecessary and might have performance impact.

Not all i915_gem_object_has_cache_level() are even about flushing the cache and if the kernel doesn't know what is behind a PAT index (i915_gem_object_has_cache_level lies by always returning true) are we 100% sure everything is functionally correct?

flush_write_domain() for instance uses it to determine whether to set obj->cache_dirty after GPU activity. How does the UMD manage that?

Then use_cpu_reloc(). Another pointless/misleading question.

Finally vm_fault_gtt() rejects access based on it.

Perhaps the question is moot since the set pat extension is restricted to MTL so some other conditions used in the above checks, like HAS_LLC and such, make for no practical difference. Even if so, what if the extension was allowed on other platforms as it was the plan until it was discovered there is no userspace code for other platforms. Would the plan work on all platforms? And even if it would I think the implementation is very non-obvious.

Quoted 72 lines
Quoted 1 line

With my refactoring it becomes meaningful again and restores to the

original behaviour. That's the intent at least.

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct

Quoted 3 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)
@@ -255,9 +249,9 @@ i915_gem_object_set_to_gtt_domain(struct 

drm_i915_gem_object *obj, bool write)

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 258

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
  }
 
  /**
- * i915_gem_object_set_cache_level - Changes the cache-level of an 

object across all VMA.

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 252

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+ * i915_gem_object_set_cache - Changes the cache-level of an 

object across all VMA.

Quoted 5 lines
Quoted 5 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)

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
   * @obj: object to act on
- * @cache_level: new cache level to set for the object
+ * @cache: new caching mode to set for the object
   *
   * After this function returns, the object will be in the new 

cache-level

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 257

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
   * across all GTT and the contents of the backing storage will be 

coherent,

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -269,19 +263,28 @@ i915_gem_object_set_to_gtt_domain(struct 

drm_i915_gem_object *obj, bool write)

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 263

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
   * cache coherency) and all non-MOCS GPU access will also be 

uncached so

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +3 -2
   * that all direct access to the scanout remains coherent.
   */
-int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
-                                   enum i915_cache_level cache_level)
+int i915_gem_object_set_cache(struct drm_i915_gem_object *obj,
+                             i915_cache_t cache)
  {
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
          int ret;
 
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 278

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -2
-       /*
-        * For objects created by userspace through GEM_CREATE with 

pat_index

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 279

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * set by set_pat extension, simply return 0 here without 

touching

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_set_to_gtt_domain(struct · line 280

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -1
-        * the cache setting, because such objects should have an 

immutable

Quoted 7 lines
Quoted 7 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)

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +4 -3
-        * cache setting by desgin and always managed by userspace.
-        */
-       if (i915_gem_object_has_cache_level(obj, cache_level))
+       ret = i915_cache_find_pat(i915, cache);
+       if (ret < 0) {
+               struct drm_printer p =
+                       drm_err_printer("Attempting to use unknown 

caching mode ");

Quoted 11 lines
Quoted 10 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 282

Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +6 -0
+
+               i915_cache_print(&p, cache);
+               drm_puts(&p, "!\n");
+
+               return -EINVAL;
+       } else if (ret == obj->pat_index) {
                  return 0;

We will have to do this conversion and checking again later in this function when calling i915_gem_object_set_cache_coherency().

Quoted 8 lines

Yes the double lookup part is a bit naff. It is not super required apart for validating internal callers (could be a debug build only feature perhaps) and to see if PAT index has changed and so whether it needs to call i915_gem_object_wait before proceeding to i915_gem_object_set_cache_coherency...

Quoted 2 lines

My thought was to simply remove the use of cache_level/cache and replace it with pat_idex. Conversion from cache modes to pat index should be

done

Quoted 2 lines
Quoted 1 line

before calling any function used to consume cache_level/cache.

Quoted 8 lines
Quoted 3 lines

... I could probably call the setter which takes PAT index instead of i915_gem_object_set_cache_coherency few lines below. That would skip the double lookup and make you happy(-ier)?

Do you see any problem just letting these functions take pat_index as the second argument? These functions are currently called with a constant cache_level/mode, if we have INTEL_INFO(i915)->pat_uc/wt/wb set properly, using pat index makes no difference, right?

Which ones?

Quoted 47 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
+       } else if (obj->pat_set_by_user) {
Quoted 8 lines
Quoted 8 lines

Shouldn't this if-statement be placed at the beginning of this function? the original
i915_gem_object_has_cache_level() would return true if (obj->pat_set_by_user), so the
function returns right away.

Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -0
+               drm_notice_once(&i915->drm,
+                               "Attempting to change caching mode 

on an object with fixed PAT!\n");

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_object_set_cache_level(struct

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -0
+               return -EINVAL;
+       }
 
          ret = i915_gem_object_wait(obj,

                                    I915_WAIT_INTERRUPTIBLE |

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -291,7 +294,7 @@ int i915_gem_object_set_cache_level(struct 

drm_i915_gem_object *obj,

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                  return ret;
 
          /* Always invalidate stale cachelines */
-       i915_gem_object_set_cache_coherency(obj, cache_level);
+       i915_gem_object_set_cache_coherency(obj, cache);
          obj->cache_dirty = true;
 
          /* The cache-level will be applied when each vma is 

rebound. */

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -326,10 +329,9 @@ int i915_gem_get_caching_ioctl(struct 

drm_device *dev, void *data,

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data, · line 332

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -2
                  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))

This looks wrong, at least for MTL. Prior to MTL the GPU

automatically snoop

Quoted 2 lines
Quoted 2 lines

CPU cache, but from MTL onward you have to specify if WB or WB + 1-WAY COH is needed. And for KMD, cacheable mode means WB + 1-WAY COH for

MTL to keep the

Quoted 4 lines
Quoted 4 lines

behavior consistent.

This used to be taken care of by i915_gem_get_pat_index() call. With that being replaced by i915_cache_find_pat(), you would need to do

Quoted 31 lines

something there.

Quoted 2 lines
Quoted 2 lines

But, without cachelevel_to_pat[], you might end up hard coding something directly in the function, and that is platform dependent. hmm..., I

don't really

Quoted 3 lines
Quoted 3 lines

like this idea.

That's why I commented in v1 that we should use

INTEL_INFO(i915)->pat_uc/wb/wt

Quoted 23 lines
Quoted 1 line

instead of enum i915_cache_level or i915_cache_t.

I think I get it. I hope so.. So if I made the tables like this:

#define LEGACY_CACHE_MODES \
       .cache_modes = { \
               [0] = I915_CACHE(UC), \
               [1] = _I915_CACHE(WB, COH1W), \
               [2] = _I915_CACHE(WB, COH1W | L3), \ // 2way??
               [3] = I915_CACHE(WT), \
        }

#define GEN12_CACHE_MODES \
       .cache_modes = { \
               [0] = _I915_CACHE(WB, COH1W), \
               [1] = I915_CACHE(WC), \
               [2] = I915_CACHE(WT), \
               [3] = I915_CACHE(UC), \
        }

#define MTL_CACHE_MODES \
       .cache_modes = { \
               [0] = _I915_CACHE(WB, COH1W), \

This was a brain fart, should have just been WB.

Quoted 9 lines
Quoted 9 lines

               [1] = I915_CACHE(WT), \
               [2] = I915_CACHE(UC), \
               [3] = _I915_CACHE(WB, COH1W), \
               [4] = _I915_CACHE(WB, COH2W), \

And made i915->pat_wc look up _I915_CACHE(WB, COH1W) would that work? Hmm and also all "has cache level" call sites would need to look not just for WB but WB+COH1W.

Quoted 5 lines
Quoted 1 line

Would it work? Too ugly?

I don't think this would work. The cache_modes needs to be aligned with BSpec, otherwise checkings for INTEL_INFO(i915)->cache_modes[obj->pat_index] might become invalid. Also, COH1W/2W were not even there for platforms prior to MTL.

Not sure what would become invalid? COH1W/2W are perhaps names associated with MTL - but is Gen12 PAT 0 identical in behaviour to PAT 3 or PAT 4 on MTL? If yes then we can introduce an i915 specific name for that coherency mode and apply it to both platforms.

Quoted 2 lines

I still think setting INTEL_INFO(i915)->pat_uc/wt/wb is the best solution. With that we can also eliminate the use of I915_CACHE({UC|WT|WB}).

How for the call sites which are asking about caching mode characteristics? We can't ask if something has PAT index X from the source code since that is platform dependent.

Quoted 98 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                  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))

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
                  args->caching = I915_CACHING_DISPLAY;

         else
                 args->caching = I915_CACHING_NONE;

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -344,7 +346,7 @@ int i915_gem_set_caching_ioctl(struct 

drm_device *dev, void *data,

Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
          struct drm_i915_private *i915 = to_i915(dev);
          struct drm_i915_gem_caching *args = data;
          struct drm_i915_gem_object *obj;
-       enum i915_cache_level level;
+       i915_cache_t cache;
          int ret = 0;
 
          if (IS_DGFX(i915))
@@ -355,7 +357,7 @@ int i915_gem_set_caching_ioctl(struct 

drm_device *dev, void *data,

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
          switch (args->caching) {

         case I915_CACHING_NONE:
-               level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);

For code like this, my thought was

-               level = I915_CACHE_NONE;
+               pat_index = INTEL_INFO(i915)->pat_uc;

Quoted 7 lines
Quoted 7 lines

And later the set_cache call should take pat_index as argument instead of cache mode.

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct

Quoted 4 lines

                 break;
         case I915_CACHING_CACHED:
                 /*

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -367,10 +369,10 @@ int i915_gem_set_caching_ioctl(struct 

drm_device *dev, void *data,

Quoted 10 lines
Quoted 10 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 372

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                  if (!HAS_LLC(i915) && !HAS_SNOOP(i915))
                          return -ENODEV;
 
-               level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);

-               level = I915_CACHE_LLC;
+               pat_index = INTEL_INFO(i915)->pat_wb;

This should take care of the WB + 1-WAY COH issue for MTL mentioned

above,

Quoted 6 lines
Quoted 2 lines

assuming the i915_cache_init() set pat_wb properly, and the i915_gem_object_set_cache() consumes pat_index instead of cache mode.

That works too yes.

Quoted 1 line
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
                  break;

         case I915_CACHING_DISPLAY:
-               level = HAS_WT(i915) ? I915_CACHE_WT : I915_CACHE_NONE;
+               cache = HAS_WT(i915) ? I915_CACHE(WT) : I915_CACHE(UC); break;
         default:
                 return -EINVAL;

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -409,7 +411,7 @@ int i915_gem_set_caching_ioctl(struct 

drm_device *dev, void *data,

Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct

Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
          if (ret)
                  goto out;
 
-       ret = i915_gem_object_set_cache_level(obj, level);
+       ret = i915_gem_object_set_cache(obj, cache);
          i915_gem_object_unlock(obj);
 

 out:

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -448,9 +450,9 @@ i915_gem_object_pin_to_display_plane(struct 

drm_i915_gem_object *obj,

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct · line 450

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
           * of uncaching, which would allow us to flush all the 

LLC-cached data

Quoted 1 line
Quoted 1 line

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct · line 451

Quoted 1 line
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
           * with that bit in the PTE to main memory with just one 

PIPE_CONTROL.

Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -3
           */
-       ret = i915_gem_object_set_cache_level(obj,
-                                             HAS_WT(i915) ?
-                                             I915_CACHE_WT : 

I915_CACHE_NONE);

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,

Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +3 -0
+       ret = i915_gem_object_set_cache(obj,
+                                       HAS_WT(i915) ?
+                                       I915_CACHE(WT) : 

I915_CACHE(UC));

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
          if (ret)
                  return ERR_PTR(ret);
 

[...]

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c bool i915_gem_object_can_bypass_llc(struct

Quoted 3 lines

 bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj)

drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
@@ -215,6 +222,7 @@ bool i915_gem_object_can_bypass_llc(struct 

drm_i915_gem_object *obj)

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c bool i915_gem_object_can_bypass_llc(struct · line 225

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -0
          /*
           * Always flush cache for UMD objects at creation time.
           */
+       /* QQQ/FIXME why? avoidable performance penalty? */

This is needed because UMD's assume zero-initialized BO's are really zero'ed out before getting the handles to the BO's (See VLK-46522). Otherwise UMD's could read stale data, thus cause security issues.

Hah this comes exactly to my point from above. So it looks my propsal would exactly solve this. Because i915 would know the caching mode and know to flush if not coherent. And it would be better than flushing for every obj->pat_set_by_user because that approach pessimistically flushes even when it is not needed.

Regards,

Tvrtko

Quoted 55 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -0
          if (obj->pat_set_by_user)
                  return true;
 

[...]

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/intel_device_info.h

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

index dbfe6443457b..f48a21895a85 100644

drivers/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 "gt/intel_engine_types.h"
@@ -243,8 +245,8 @@ struct intel_device_info {
           */
          const struct intel_runtime_info __runtime;
 
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 248

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];

I was commenting on the array size here. It's probably better to

make it 16

Quoted 11 lines
Quoted 5 lines

because there are 4 PAT index bits defined in the PTE. Indices above max_pat_index
are not used, but theoretically new mode could be added. Well, it's up to you,
not likely to happen anyway.

Ah okay. I am not too concerned. Compiler will let us know if it happens.

Unrelated to this comment - what about i915_gem_object_can_bypass_llc? Could we do better (less pessimistic) with something like my approach and so maybe penalize MTL less?

The problem is that, for the BO's managed by UMD's, the KMD doesn't know whether they are going to be mapped as cacheable or uncacheable on the CPU side. The PAT index controls GPU access only. That's why we make sure all BO's with PAT set by UMD (which means UMD will take control and managing the coherency) are clflush'ed.

-Fei

Quoted 3 lines

Regards,

Tvrtko

#9 lore raw
Quoted 47 lines
Quoted 32 lines
Quoted 24 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +0 -7
@@ -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.
-        */
Quoted 8 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj) · line 32

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +2 -2
-       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;

This logic was changed for objects with pat index set by user here. It used to return false regardless the cache mode. But now it returns true if its cache mode is neither UC nor WT.

Yes, that was half of the motivation of the refactory. Before the PAT index series code was like this:

       return !(obj->cache_level == I915_CACHE_NONE ||
                obj->cache_level == I915_CACHE_WT);
Quoted 7 lines

So kernel knew it needs to flush only if caching mode is neither UC or WT. With the PAT index series you changed it to:

       return !(i915_gem_object_has_cache_level(obj, I915_CACHE_NONE) ||
                i915_gem_object_has_cache_level(obj, I915_CACHE_WT));

And as i915_gem_object_has_cache_level was changed to always return true if PAT was set by user, that made the check meaningless for such objects.

Quoted 4 lines

But the point is that the KMD should not flush the cache for objects with PAT set by user because UMD is handling the cache conherency. That is the design. Well doing so wouldn't cause functional issue, but it's unecessary and might have performance impact.

Not all i915_gem_object_has_cache_level() are even about flushing the cache and if the kernel doesn't know what is behind a PAT index (i915_gem_object_has_cache_level lies by always returning true) are we 100% sure everything is functionally correct?

flush_write_domain() for instance uses it to determine whether to set obj->cache_dirty after GPU activity. How does the UMD manage that?

Then use_cpu_reloc(). Another pointless/misleading question.

Quoted 9 lines

Finally vm_fault_gtt() rejects access based on it.

Perhaps the question is moot since the set pat extension is restricted to MTL so some other conditions used in the above checks, like HAS_LLC and such, make for no practical difference. Even if so, what if the extension was allowed on other platforms as it was the plan until it was discovered there is no userspace code for other platforms. Would the plan work on all platforms? And even if it would I think the implementation is very non-obvious.

Understand your point, perhaps we should let i915_gem_object_has_cache_mode() do what it supposed to do, and add a separate check for obj->pat_set_by_user in functions like gpu_write_needs_clflush(), use_cpu_reloc(), etc. Anyway, the design is to let UMD handle coherency for objects with pat set by user.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

With my refactoring it becomes meaningful again and restores to the original behaviour. That's the intent at least.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
 bool i915_gem_cpu_write_needs_clflush(struct drm_i915_gem_object *obj)
@@ -255,9 +249,9 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 }
 
 /**
- * i915_gem_object_set_cache_level - Changes the cache-level of an object across all VMA.
+ * i915_gem_object_set_cache - Changes the cache-level of an object across all VMA.

[...]

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5 -1
-       if (i915_gem_object_has_cache_level(obj, cache_level))
+       ret = i915_cache_find_pat(i915, cache);
+       if (ret < 0) {
+           struct drm_printer p =
+                drm_err_printer("Attempting to use unknown caching mode ");
+
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 282

Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +5 -0
+           i915_cache_print(&p, cache);
+           drm_puts(&p, "!\n");
+
+           return -EINVAL;
+       } else if (ret == obj->pat_index) {
            return 0;

We will have to do this conversion and checking again later in this function when calling i915_gem_object_set_cache_coherency().

Yes the double lookup part is a bit naff. It is not super required apart for validating internal callers (could be a debug build only feature perhaps) and to see if PAT index has changed and so whether it needs to call i915_gem_object_wait before proceeding to i915_gem_object_set_cache_coherency...

Quoted 3 lines

My thought was to simply remove the use of cache_level/cache and replace it with pat_idex. Conversion from cache modes to pat index should be done before calling any function used to consume cache_level/cache.

... I could probably call the setter which takes PAT index instead of i915_gem_object_set_cache_coherency few lines below. That would skip the double lookup and make you happy(-ier)?

Quoted 6 lines
Quoted 4 lines

Do you see any problem just letting these functions take pat_index as the second argument? These functions are currently called with a constant cache_level/mode, if we have INTEL_INFO(i915)->pat_uc/wt/wb set properly, using pat index makes no difference, right?

Which ones?

i915_gem_object_set_cache_level() and i915_gem_object_set_cache_coherency() are both being called with cache_level as of now. That is not necessary if platform specific INTEL_INFO(i915)->pat_uc/wt/wb are there. we can simply

s/I915_CACHE_NONE/INTEL_INFO(i915)->pat_uc
s/I915_CACHE_WT/INTEL_INFO(i915)->pat_wt
s/I915_CACHE_LLC/INTEL_INFO(i915)->pat_wb

[...]

Quoted 47 lines
Quoted 28 lines
Quoted 28 lines
Quoted 13 lines
Quoted 1 line

if (i915_gem_object_has_cache_mode(obj, I915_CACHE_MODE_WB))

This looks wrong, at least for MTL. Prior to MTL the GPU automatically snoop CPU cache, but from MTL onward you have to specify if WB or WB + 1-WAY COH is needed. And for KMD, cacheable mode means WB + 1-WAY COH for MTL to keep the behavior consistent.

This used to be taken care of by i915_gem_get_pat_index() call. With that being replaced by i915_cache_find_pat(), you would need to do something there.
But, without cachelevel_to_pat[], you might end up hard coding something directly in the function, and that is platform dependent. hmm..., I don't really like this idea.

Quoted 3 lines

That's why I commented in v1 that we should use INTEL_INFO(i915)->pat_uc/wb/wt instead of enum i915_cache_level or i915_cache_t.

I think I get it. I hope so.. So if I made the tables like this:

#define LEGACY_CACHE_MODES \
       .cache_modes = { \
               [0] = I915_CACHE(UC), \
               [1] = _I915_CACHE(WB, COH1W), \
               [2] = _I915_CACHE(WB, COH1W | L3), \ // 2way??
               [3] = I915_CACHE(WT), \
        }
#define GEN12_CACHE_MODES \
       .cache_modes = { \
Quoted 8 lines
Quoted 8 lines
               [0] = _I915_CACHE(WB, COH1W), \
               [1] = I915_CACHE(WC), \
               [2] = I915_CACHE(WT), \
               [3] = I915_CACHE(UC), \
        }
#define MTL_CACHE_MODES \
       .cache_modes = { \
               [0] = _I915_CACHE(WB, COH1W), \

This was a brain fart, should have just been WB.

Quoted 8 lines
Quoted 8 lines
               [1] = I915_CACHE(WT), \
               [2] = I915_CACHE(UC), \
               [3] = _I915_CACHE(WB, COH1W), \
               [4] = _I915_CACHE(WB, COH2W), \

And made i915->pat_wc look up _I915_CACHE(WB, COH1W) would that work? Hmm and also all "has cache level" call sites would need to look not just for WB but WB+COH1W.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Would it work? Too ugly?

I don't think this would work. The cache_modes needs to be aligned with BSpec, otherwise checkings for INTEL_INFO(i915)->cache_modes[obj->pat_index] might become invalid. Also, COH1W/2W were not even there for platforms prior to MTL.

Not sure what would become invalid?

What if we want to check for a particular pat_index whether it means cached or uncached, whether it's 1-way coherent or not? if the cache_modes[] misaligned with bspec, then we would fail such check.

Quoted 11 lines

COH1W/2W are perhaps names associated
with MTL - but is Gen12 PAT 0 identical in behaviour to PAT 3 or PAT 4 on MTL? If yes then we can introduce an i915 specific name for that coherency mode and apply it to both platforms.

Quoted 2 lines

I still think setting INTEL_INFO(i915)->pat_uc/wt/wb is the best solution. With that we can also eliminate the use of I915_CACHE({UC|WT|WB}).

How for the call sites which are asking about caching mode characteristics? We can't ask if something has PAT index X from the source code since that is platform dependent.

We can compare pat index directly for exact match. Even for the case we just want to distinguish cached or uncached, we can check the bit field of INTEL_INFO(i915)->cache_modes[obj->pat_index].

Quoted 52 lines
Quoted 41 lines
Quoted 37 lines
Quoted 23 lines

drivers/gpu/drm/i915/gem/i915_gem_domain.c int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, · line 360

Quoted 5 lines

+357,7 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,

         switch (args->caching) {
         case I915_CACHING_NONE:
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
-               level = I915_CACHE_NONE;
+               cache = I915_CACHE(UC);

For code like this, my thought was

(quoted diff) +1 -1
-               level = I915_CACHE_NONE;
+               pat_index = INTEL_INFO(i915)->pat_uc;

And later the set_cache call should take pat_index as argument instead of cache mode.

Quoted 8 lines
                 break;
         case I915_CACHING_CACHED:
                 /*
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
@@ -367,10 +369,10 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
                if (!HAS_LLC(i915) && !HAS_SNOOP(i915))
                    return -ENODEV;
-               level = I915_CACHE_LLC;
+               cache = I915_CACHE(WB);
(quoted diff) +1 -1
-               level = I915_CACHE_LLC;
+               pat_index = INTEL_INFO(i915)->pat_wb;
Quoted 3 lines

This should take care of the WB + 1-WAY COH issue for MTL mentioned above, assuming the i915_cache_init() set pat_wb properly, and the i915_gem_object_set_cache() consumes pat_index instead of cache mode.

That works too yes.

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +1 -1
                 break;
         case I915_CACHING_DISPLAY:
-               level = HAS_WT(i915) ? I915_CACHE_WT : I915_CACHE_NONE;
+               cache = HAS_WT(i915) ? I915_CACHE(WT) : I915_CACHE(UC);
                break;
         default:
                return -EINVAL;

[...]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/i915/gem/i915_gem_object.c bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj) · line 225

Quoted 6 lines

bool i915_gem_object_can_bypass_llc(struct drm_i915_gem_object *obj)

drivers/gpu/drm/i915/gem/i915_gem_object.c +1 -0
@@ -215,6 +222,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? */

This is needed because UMD's assume zero-initialized BO's are really zero'ed out before getting the handles to the BO's (See VLK-46522). Otherwise UMD's could read stale data, thus cause security issues.

Quoted 5 lines

Hah this comes exactly to my point from above. So it looks my propsal would exactly solve this. Because i915 would know the caching mode and know to flush if not coherent. And it would be better than flushing for every obj->pat_set_by_user because that approach pessimistically flushes even when it is not needed.

hmm..., This is only called at BO creation time. We do need to clflush all objects with pat_set_by_user, otherwise the user would get access to stale data.

-Fei

Quoted 52 lines

Regards,

Tvrtko

Quoted 48 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -0
         if (obj->pat_set_by_user)
             return true;
 

[...]

Quoted 23 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/i915/intel_device_info.h +2 -0
index dbfe6443457b..f48a21895a85 100644
@@ -27,6 +27,8 @@
 
 #include <uapi/drm/i915_drm.h>
 
+#include "i915_cache.h"
+
 #include "intel_step.h"
 
Quoted 10 lines

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { >>> */ · line 246

Quoted 6 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -2
 #include "gt/intel_engine_types.h"
@@ -243,8 +245,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];

I was commenting on the array size here. It's probably better to make it 16 because there are 4 PAT index bits defined in the PTE. Indices above max_pat_index are not used, but theoretically new mode could be added. Well, it's up to you, not likely to happen anyway.

Quoted 5 lines

Ah okay. I am not too concerned. Compiler will let us know if it happens.

Unrelated to this comment - what about i915_gem_object_can_bypass_llc? Could we do better (less pessimistic) with something like my approach and so maybe penalize MTL less?

The problem is that, for the BO's managed by UMD's, the KMD doesn't know whether they are going to be mapped as cacheable or uncacheable on the CPU side. The PAT index controls GPU access only. That's why we make sure all BO's with PAT set by UMD (which means UMD will take control and managing the
coherency) are clflush'ed.

-Fei

Quoted 3 lines

Regards,

Tvrtko